Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "app.hpp" |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 19 | #include "dbus_singleton.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 20 | #include "dbus_utility.hpp" |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 21 | #include "error_messages.hpp" |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 22 | #include "health.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 23 | #include "query.hpp" |
| 24 | #include "registries/privilege_registry.hpp" |
| 25 | #include "utils/collection.hpp" |
| 26 | #include "utils/dbus_utils.hpp" |
| 27 | #include "utils/json_utils.hpp" |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 28 | |
| 29 | #include <boost/container/flat_map.hpp> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 30 | #include <boost/system/error_code.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 31 | #include <sdbusplus/asio/property.hpp> |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 32 | #include <sdbusplus/message/native_types.hpp> |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 33 | #include <sdbusplus/unpack_properties.hpp> |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 34 | #include <sdbusplus/utility/dedup_variant.hpp> |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 35 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 36 | #include <array> |
Michael Shen | b9d679d | 2023-02-13 02:29:04 +0000 | [diff] [blame] | 37 | #include <limits> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 38 | #include <string_view> |
| 39 | |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 40 | namespace redfish |
| 41 | { |
| 42 | |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 43 | // Interfaces which imply a D-Bus object represents a Processor |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 44 | constexpr std::array<std::string_view, 2> processorInterfaces = { |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 45 | "xyz.openbmc_project.Inventory.Item.Cpu", |
| 46 | "xyz.openbmc_project.Inventory.Item.Accelerator"}; |
Jonathan Doman | 2bab983 | 2020-12-02 15:27:40 -0800 | [diff] [blame] | 47 | |
Sharad Yadav | 71b82f2 | 2021-05-10 15:11:39 +0530 | [diff] [blame] | 48 | /** |
| 49 | * @brief Fill out uuid info of a processor by |
| 50 | * requesting data from the given D-Bus object. |
| 51 | * |
| 52 | * @param[in,out] aResp Async HTTP response. |
| 53 | * @param[in] service D-Bus service to query. |
| 54 | * @param[in] objPath D-Bus object to query. |
| 55 | */ |
| 56 | inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp, |
| 57 | const std::string& service, |
| 58 | const std::string& objPath) |
| 59 | { |
| 60 | BMCWEB_LOG_DEBUG << "Get Processor UUID"; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 61 | sdbusplus::asio::getProperty<std::string>( |
| 62 | *crow::connections::systemBus, service, objPath, |
| 63 | "xyz.openbmc_project.Common.UUID", "UUID", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 64 | [objPath, aResp{std::move(aResp)}](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 65 | const std::string& property) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 66 | if (ec) |
| 67 | { |
| 68 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 69 | messages::internalError(aResp->res); |
| 70 | return; |
| 71 | } |
| 72 | aResp->res.jsonValue["UUID"] = property; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 73 | }); |
Sharad Yadav | 71b82f2 | 2021-05-10 15:11:39 +0530 | [diff] [blame] | 74 | } |
| 75 | |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 76 | inline void getCpuDataByInterface( |
| 77 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 78 | const dbus::utility::DBusInteracesMap& cpuInterfacesProperties) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 79 | { |
| 80 | BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; |
| 81 | |
Chicago Duan | a1649ec | 2021-03-30 16:54:58 +0800 | [diff] [blame] | 82 | // Set the default value of state |
| 83 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 84 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 85 | |
| 86 | for (const auto& interface : cpuInterfacesProperties) |
| 87 | { |
| 88 | for (const auto& property : interface.second) |
| 89 | { |
Chicago Duan | a1649ec | 2021-03-30 16:54:58 +0800 | [diff] [blame] | 90 | if (property.first == "Present") |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 91 | { |
Chicago Duan | a1649ec | 2021-03-30 16:54:58 +0800 | [diff] [blame] | 92 | const bool* cpuPresent = std::get_if<bool>(&property.second); |
| 93 | if (cpuPresent == nullptr) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 94 | { |
| 95 | // Important property not in desired type |
| 96 | messages::internalError(aResp->res); |
| 97 | return; |
| 98 | } |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 99 | if (!*cpuPresent) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 100 | { |
Chicago Duan | a1649ec | 2021-03-30 16:54:58 +0800 | [diff] [blame] | 101 | // Slot is not populated |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 102 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
Chicago Duan | a1649ec | 2021-03-30 16:54:58 +0800 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | else if (property.first == "Functional") |
| 106 | { |
| 107 | const bool* cpuFunctional = std::get_if<bool>(&property.second); |
| 108 | if (cpuFunctional == nullptr) |
| 109 | { |
| 110 | messages::internalError(aResp->res); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 111 | return; |
| 112 | } |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 113 | if (!*cpuFunctional) |
Chicago Duan | a1649ec | 2021-03-30 16:54:58 +0800 | [diff] [blame] | 114 | { |
| 115 | aResp->res.jsonValue["Status"]["Health"] = "Critical"; |
| 116 | } |
| 117 | } |
| 118 | else if (property.first == "CoreCount") |
| 119 | { |
| 120 | const uint16_t* coresCount = |
| 121 | std::get_if<uint16_t>(&property.second); |
| 122 | if (coresCount == nullptr) |
| 123 | { |
| 124 | messages::internalError(aResp->res); |
| 125 | return; |
| 126 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 127 | aResp->res.jsonValue["TotalCores"] = *coresCount; |
| 128 | } |
Jonathan Doman | dc3fa66 | 2020-10-26 23:10:24 -0700 | [diff] [blame] | 129 | else if (property.first == "MaxSpeedInMhz") |
| 130 | { |
| 131 | const uint32_t* value = std::get_if<uint32_t>(&property.second); |
| 132 | if (value != nullptr) |
| 133 | { |
| 134 | aResp->res.jsonValue["MaxSpeedMHz"] = *value; |
| 135 | } |
| 136 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 137 | else if (property.first == "Socket") |
| 138 | { |
| 139 | const std::string* value = |
| 140 | std::get_if<std::string>(&property.second); |
| 141 | if (value != nullptr) |
| 142 | { |
| 143 | aResp->res.jsonValue["Socket"] = *value; |
| 144 | } |
| 145 | } |
| 146 | else if (property.first == "ThreadCount") |
| 147 | { |
Jonathan Doman | dc3fa66 | 2020-10-26 23:10:24 -0700 | [diff] [blame] | 148 | const uint16_t* value = std::get_if<uint16_t>(&property.second); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 149 | if (value != nullptr) |
| 150 | { |
| 151 | aResp->res.jsonValue["TotalThreads"] = *value; |
| 152 | } |
| 153 | } |
Brandon Kim | 1930fbd | 2021-09-14 17:52:51 -0700 | [diff] [blame] | 154 | else if (property.first == "EffectiveFamily") |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 155 | { |
Brandon Kim | 1930fbd | 2021-09-14 17:52:51 -0700 | [diff] [blame] | 156 | const uint16_t* value = std::get_if<uint16_t>(&property.second); |
Brad Bishop | 6169de2 | 2022-09-14 13:08:32 -0400 | [diff] [blame] | 157 | if (value != nullptr && *value != 2) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 158 | { |
| 159 | aResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] = |
Ed Tanous | 866e486 | 2022-02-17 11:40:25 -0800 | [diff] [blame] | 160 | "0x" + intToHexString(*value, 4); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 161 | } |
| 162 | } |
Brandon Kim | 1930fbd | 2021-09-14 17:52:51 -0700 | [diff] [blame] | 163 | else if (property.first == "EffectiveModel") |
| 164 | { |
| 165 | const uint16_t* value = std::get_if<uint16_t>(&property.second); |
| 166 | if (value == nullptr) |
| 167 | { |
| 168 | messages::internalError(aResp->res); |
| 169 | return; |
| 170 | } |
Brad Bishop | 6169de2 | 2022-09-14 13:08:32 -0400 | [diff] [blame] | 171 | if (*value != 0) |
| 172 | { |
| 173 | aResp->res.jsonValue["ProcessorId"]["EffectiveModel"] = |
| 174 | "0x" + intToHexString(*value, 4); |
| 175 | } |
Brandon Kim | 1930fbd | 2021-09-14 17:52:51 -0700 | [diff] [blame] | 176 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 177 | else if (property.first == "Id") |
| 178 | { |
| 179 | const uint64_t* value = std::get_if<uint64_t>(&property.second); |
| 180 | if (value != nullptr && *value != 0) |
| 181 | { |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 182 | aResp->res |
| 183 | .jsonValue["ProcessorId"]["IdentificationRegisters"] = |
Ed Tanous | 866e486 | 2022-02-17 11:40:25 -0800 | [diff] [blame] | 184 | "0x" + intToHexString(*value, 16); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 185 | } |
| 186 | } |
Brandon Kim | 1930fbd | 2021-09-14 17:52:51 -0700 | [diff] [blame] | 187 | else if (property.first == "Microcode") |
| 188 | { |
| 189 | const uint32_t* value = std::get_if<uint32_t>(&property.second); |
| 190 | if (value == nullptr) |
| 191 | { |
| 192 | messages::internalError(aResp->res); |
| 193 | return; |
| 194 | } |
Brad Bishop | 6169de2 | 2022-09-14 13:08:32 -0400 | [diff] [blame] | 195 | if (*value != 0) |
| 196 | { |
| 197 | aResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] = |
| 198 | "0x" + intToHexString(*value, 8); |
| 199 | } |
Brandon Kim | 1930fbd | 2021-09-14 17:52:51 -0700 | [diff] [blame] | 200 | } |
| 201 | else if (property.first == "Step") |
| 202 | { |
| 203 | const uint16_t* value = std::get_if<uint16_t>(&property.second); |
| 204 | if (value == nullptr) |
| 205 | { |
| 206 | messages::internalError(aResp->res); |
| 207 | return; |
| 208 | } |
Michael Shen | b9d679d | 2023-02-13 02:29:04 +0000 | [diff] [blame] | 209 | if (*value != std::numeric_limits<uint16_t>::max()) |
Brad Bishop | 6169de2 | 2022-09-14 13:08:32 -0400 | [diff] [blame] | 210 | { |
| 211 | aResp->res.jsonValue["ProcessorId"]["Step"] = |
| 212 | "0x" + intToHexString(*value, 4); |
| 213 | } |
Brandon Kim | 1930fbd | 2021-09-14 17:52:51 -0700 | [diff] [blame] | 214 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 215 | } |
| 216 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 217 | } |
| 218 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 219 | inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 220 | const std::string& cpuId, |
| 221 | const std::string& service, |
| 222 | const std::string& objPath) |
| 223 | { |
| 224 | BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; |
| 225 | |
| 226 | crow::connections::systemBus->async_method_call( |
| 227 | [cpuId, service, objPath, aResp{std::move(aResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 228 | const boost::system::error_code& ec, |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 229 | const dbus::utility::ManagedObjectType& dbusData) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 230 | if (ec) |
| 231 | { |
| 232 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 233 | messages::internalError(aResp->res); |
| 234 | return; |
| 235 | } |
| 236 | aResp->res.jsonValue["Id"] = cpuId; |
| 237 | aResp->res.jsonValue["Name"] = "Processor"; |
| 238 | aResp->res.jsonValue["ProcessorType"] = "CPU"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 239 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 240 | bool slotPresent = false; |
| 241 | std::string corePath = objPath + "/core"; |
| 242 | size_t totalCores = 0; |
| 243 | for (const auto& object : dbusData) |
| 244 | { |
| 245 | if (object.first.str == objPath) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 246 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 247 | getCpuDataByInterface(aResp, object.second); |
| 248 | } |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 249 | else if (object.first.str.starts_with(corePath)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 250 | { |
| 251 | for (const auto& interface : object.second) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 252 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 253 | if (interface.first == "xyz.openbmc_project.Inventory.Item") |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 254 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 255 | for (const auto& property : interface.second) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 256 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 257 | if (property.first == "Present") |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 258 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 259 | const bool* present = |
| 260 | std::get_if<bool>(&property.second); |
| 261 | if (present != nullptr) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 262 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 263 | if (*present) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 264 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 265 | slotPresent = true; |
| 266 | totalCores++; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 274 | } |
| 275 | // In getCpuDataByInterface(), state and health are set |
| 276 | // based on the present and functional status. If core |
| 277 | // count is zero, then it has a higher precedence. |
| 278 | if (slotPresent) |
| 279 | { |
| 280 | if (totalCores == 0) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 281 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 282 | // Slot is not populated, set status end return |
| 283 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 284 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 285 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 286 | aResp->res.jsonValue["TotalCores"] = totalCores; |
| 287 | } |
| 288 | return; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 289 | }, |
| 290 | service, "/xyz/openbmc_project/inventory", |
| 291 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 292 | } |
| 293 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 294 | inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 295 | const std::string& service, |
| 296 | const std::string& objPath) |
| 297 | { |
| 298 | BMCWEB_LOG_DEBUG << "Get Cpu Asset Data"; |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 299 | sdbusplus::asio::getAllProperties( |
| 300 | *crow::connections::systemBus, service, objPath, |
| 301 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 302 | [objPath, aResp{std::move(aResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 303 | const boost::system::error_code& ec, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 304 | const dbus::utility::DBusPropertiesMap& properties) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 305 | if (ec) |
| 306 | { |
| 307 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 308 | messages::internalError(aResp->res); |
| 309 | return; |
| 310 | } |
| 311 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 312 | const std::string* serialNumber = nullptr; |
| 313 | const std::string* model = nullptr; |
| 314 | const std::string* manufacturer = nullptr; |
| 315 | const std::string* partNumber = nullptr; |
| 316 | const std::string* sparePartNumber = nullptr; |
| 317 | |
| 318 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 319 | dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber", |
| 320 | serialNumber, "Model", model, "Manufacturer", manufacturer, |
| 321 | "PartNumber", partNumber, "SparePartNumber", sparePartNumber); |
| 322 | |
| 323 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 324 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 325 | messages::internalError(aResp->res); |
| 326 | return; |
| 327 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 328 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 329 | if (serialNumber != nullptr && !serialNumber->empty()) |
| 330 | { |
| 331 | aResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 332 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 333 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 334 | if ((model != nullptr) && !model->empty()) |
| 335 | { |
| 336 | aResp->res.jsonValue["Model"] = *model; |
| 337 | } |
| 338 | |
| 339 | if (manufacturer != nullptr) |
| 340 | { |
| 341 | aResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 342 | |
| 343 | // Otherwise would be unexpected. |
| 344 | if (manufacturer->find("Intel") != std::string::npos) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 345 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 346 | aResp->res.jsonValue["ProcessorArchitecture"] = "x86"; |
| 347 | aResp->res.jsonValue["InstructionSet"] = "x86-64"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 348 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 349 | else if (manufacturer->find("IBM") != std::string::npos) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 350 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 351 | aResp->res.jsonValue["ProcessorArchitecture"] = "Power"; |
| 352 | aResp->res.jsonValue["InstructionSet"] = "PowerISA"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 355 | |
| 356 | if (partNumber != nullptr) |
| 357 | { |
| 358 | aResp->res.jsonValue["PartNumber"] = *partNumber; |
| 359 | } |
| 360 | |
Brad Bishop | 6169de2 | 2022-09-14 13:08:32 -0400 | [diff] [blame] | 361 | if (sparePartNumber != nullptr && !sparePartNumber->empty()) |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 362 | { |
| 363 | aResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; |
| 364 | } |
| 365 | }); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 366 | } |
| 367 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 368 | inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 369 | const std::string& service, |
| 370 | const std::string& objPath) |
| 371 | { |
| 372 | BMCWEB_LOG_DEBUG << "Get Cpu Revision Data"; |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 373 | sdbusplus::asio::getAllProperties( |
| 374 | *crow::connections::systemBus, service, objPath, |
| 375 | "xyz.openbmc_project.Inventory.Decorator.Revision", |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 376 | [objPath, aResp{std::move(aResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 377 | const boost::system::error_code& ec, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 378 | const dbus::utility::DBusPropertiesMap& properties) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 379 | if (ec) |
| 380 | { |
| 381 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 382 | messages::internalError(aResp->res); |
| 383 | return; |
| 384 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 385 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 386 | const std::string* version = nullptr; |
| 387 | |
| 388 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 389 | dbus_utils::UnpackErrorPrinter(), properties, "Version", version); |
| 390 | |
| 391 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 392 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 393 | messages::internalError(aResp->res); |
| 394 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 395 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 396 | |
| 397 | if (version != nullptr) |
| 398 | { |
| 399 | aResp->res.jsonValue["Version"] = *version; |
| 400 | } |
| 401 | }); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 402 | } |
| 403 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 404 | inline void getAcceleratorDataByService( |
| 405 | std::shared_ptr<bmcweb::AsyncResp> aResp, const std::string& acclrtrId, |
| 406 | const std::string& service, const std::string& objPath) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 407 | { |
| 408 | BMCWEB_LOG_DEBUG |
| 409 | << "Get available system Accelerator resources by service."; |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 410 | sdbusplus::asio::getAllProperties( |
| 411 | *crow::connections::systemBus, service, objPath, "", |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 412 | [acclrtrId, aResp{std::move(aResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 413 | const boost::system::error_code& ec, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 414 | const dbus::utility::DBusPropertiesMap& properties) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 415 | if (ec) |
| 416 | { |
| 417 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 418 | messages::internalError(aResp->res); |
| 419 | return; |
| 420 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 421 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 422 | const bool* functional = nullptr; |
| 423 | const bool* present = nullptr; |
| 424 | |
| 425 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 426 | dbus_utils::UnpackErrorPrinter(), properties, "Functional", |
| 427 | functional, "Present", present); |
| 428 | |
| 429 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 430 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 431 | messages::internalError(aResp->res); |
| 432 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 433 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 434 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 435 | std::string state = "Enabled"; |
| 436 | std::string health = "OK"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 437 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 438 | if (present != nullptr && !*present) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 439 | { |
| 440 | state = "Absent"; |
| 441 | } |
| 442 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 443 | if (functional != nullptr && !*functional) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 444 | { |
| 445 | if (state == "Enabled") |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 446 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 447 | health = "Critical"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 448 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 449 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 450 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 451 | aResp->res.jsonValue["Id"] = acclrtrId; |
| 452 | aResp->res.jsonValue["Name"] = "Processor"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 453 | aResp->res.jsonValue["Status"]["State"] = state; |
| 454 | aResp->res.jsonValue["Status"]["Health"] = health; |
| 455 | aResp->res.jsonValue["ProcessorType"] = "Accelerator"; |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 456 | }); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 457 | } |
| 458 | |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 459 | // OperatingConfig D-Bus Types |
| 460 | using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>; |
| 461 | using BaseSpeedPrioritySettingsProperty = |
| 462 | std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>; |
| 463 | // uint32_t and size_t may or may not be the same type, requiring a dedup'd |
| 464 | // variant |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 465 | |
| 466 | /** |
| 467 | * Fill out the HighSpeedCoreIDs in a Processor resource from the given |
| 468 | * OperatingConfig D-Bus property. |
| 469 | * |
| 470 | * @param[in,out] aResp Async HTTP response. |
| 471 | * @param[in] baseSpeedSettings Full list of base speed priority groups, |
| 472 | * to use to determine the list of high |
| 473 | * speed cores. |
| 474 | */ |
| 475 | inline void highSpeedCoreIdsHandler( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 476 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 477 | const BaseSpeedPrioritySettingsProperty& baseSpeedSettings) |
| 478 | { |
| 479 | // The D-Bus property does not indicate which bucket is the "high |
| 480 | // priority" group, so let's discern that by looking for the one with |
| 481 | // highest base frequency. |
| 482 | auto highPriorityGroup = baseSpeedSettings.cend(); |
| 483 | uint32_t highestBaseSpeed = 0; |
| 484 | for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend(); |
| 485 | ++it) |
| 486 | { |
| 487 | const uint32_t baseFreq = std::get<uint32_t>(*it); |
| 488 | if (baseFreq > highestBaseSpeed) |
| 489 | { |
| 490 | highestBaseSpeed = baseFreq; |
| 491 | highPriorityGroup = it; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | nlohmann::json& jsonCoreIds = aResp->res.jsonValue["HighSpeedCoreIDs"]; |
| 496 | jsonCoreIds = nlohmann::json::array(); |
| 497 | |
| 498 | // There may not be any entries in the D-Bus property, so only populate |
| 499 | // if there was actually something there. |
| 500 | if (highPriorityGroup != baseSpeedSettings.cend()) |
| 501 | { |
| 502 | jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Fill out OperatingConfig related items in a Processor resource by requesting |
| 508 | * data from the given D-Bus object. |
| 509 | * |
| 510 | * @param[in,out] aResp Async HTTP response. |
| 511 | * @param[in] cpuId CPU D-Bus name. |
| 512 | * @param[in] service D-Bus service to query. |
| 513 | * @param[in] objPath D-Bus object to query. |
| 514 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 515 | inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 516 | const std::string& cpuId, |
| 517 | const std::string& service, |
| 518 | const std::string& objPath) |
| 519 | { |
| 520 | BMCWEB_LOG_INFO << "Getting CPU operating configs for " << cpuId; |
| 521 | |
| 522 | // First, GetAll CurrentOperatingConfig properties on the object |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 523 | sdbusplus::asio::getAllProperties( |
| 524 | *crow::connections::systemBus, service, objPath, |
| 525 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", |
| 526 | [aResp, cpuId, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 527 | service](const boost::system::error_code& ec, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 528 | const dbus::utility::DBusPropertiesMap& properties) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 529 | if (ec) |
| 530 | { |
| 531 | BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message(); |
| 532 | messages::internalError(aResp->res); |
| 533 | return; |
| 534 | } |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 535 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 536 | nlohmann::json& json = aResp->res.jsonValue; |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 537 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 538 | const sdbusplus::message::object_path* appliedConfig = nullptr; |
| 539 | const bool* baseSpeedPriorityEnabled = nullptr; |
| 540 | |
| 541 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 542 | dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig", |
| 543 | appliedConfig, "BaseSpeedPriorityEnabled", |
| 544 | baseSpeedPriorityEnabled); |
| 545 | |
| 546 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 547 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 548 | messages::internalError(aResp->res); |
| 549 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 550 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 551 | |
| 552 | if (appliedConfig != nullptr) |
| 553 | { |
| 554 | const std::string& dbusPath = appliedConfig->str; |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 555 | nlohmann::json::object_t operatingConfig; |
Willy Tu | eddfc43 | 2022-09-26 16:46:38 +0000 | [diff] [blame] | 556 | operatingConfig["@odata.id"] = crow::utility::urlFromPieces( |
| 557 | "redfish", "v1", "Systems", "system", "Processors", cpuId, |
| 558 | "OperatingConfigs"); |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 559 | json["OperatingConfigs"] = std::move(operatingConfig); |
| 560 | |
| 561 | // Reuse the D-Bus config object name for the Redfish |
| 562 | // URI |
| 563 | size_t baseNamePos = dbusPath.rfind('/'); |
| 564 | if (baseNamePos == std::string::npos || |
| 565 | baseNamePos == (dbusPath.size() - 1)) |
| 566 | { |
| 567 | // If the AppliedConfig was somehow not a valid path, |
| 568 | // skip adding any more properties, since everything |
| 569 | // else is tied to this applied config. |
| 570 | messages::internalError(aResp->res); |
| 571 | return; |
| 572 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 573 | nlohmann::json::object_t appliedOperatingConfig; |
Willy Tu | eddfc43 | 2022-09-26 16:46:38 +0000 | [diff] [blame] | 574 | appliedOperatingConfig["@odata.id"] = crow::utility::urlFromPieces( |
| 575 | "redfish", "v1", "Systems", "system", "Processors", cpuId, |
| 576 | "OperatingConfigs", dbusPath.substr(baseNamePos + 1)); |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 577 | json["AppliedOperatingConfig"] = std::move(appliedOperatingConfig); |
| 578 | |
| 579 | // Once we found the current applied config, queue another |
| 580 | // request to read the base freq core ids out of that |
| 581 | // config. |
| 582 | sdbusplus::asio::getProperty<BaseSpeedPrioritySettingsProperty>( |
| 583 | *crow::connections::systemBus, service, dbusPath, |
| 584 | "xyz.openbmc_project.Inventory.Item.Cpu." |
| 585 | "OperatingConfig", |
| 586 | "BaseSpeedPrioritySettings", |
| 587 | [aResp]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 588 | const boost::system::error_code& ec2, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 589 | const BaseSpeedPrioritySettingsProperty& baseSpeedList) { |
| 590 | if (ec2) |
| 591 | { |
| 592 | BMCWEB_LOG_WARNING << "D-Bus Property Get error: " << ec2; |
| 593 | messages::internalError(aResp->res); |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | highSpeedCoreIdsHandler(aResp, baseSpeedList); |
| 598 | }); |
| 599 | } |
| 600 | |
| 601 | if (baseSpeedPriorityEnabled != nullptr) |
| 602 | { |
| 603 | json["BaseSpeedPriorityState"] = |
| 604 | *baseSpeedPriorityEnabled ? "Enabled" : "Disabled"; |
| 605 | } |
| 606 | }); |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 607 | } |
| 608 | |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 609 | /** |
| 610 | * @brief Fill out location info of a processor by |
| 611 | * requesting data from the given D-Bus object. |
| 612 | * |
| 613 | * @param[in,out] aResp Async HTTP response. |
| 614 | * @param[in] service D-Bus service to query. |
| 615 | * @param[in] objPath D-Bus object to query. |
| 616 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 617 | inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp, |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 618 | const std::string& service, |
| 619 | const std::string& objPath) |
| 620 | { |
| 621 | BMCWEB_LOG_DEBUG << "Get Cpu Location Data"; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 622 | sdbusplus::asio::getProperty<std::string>( |
| 623 | *crow::connections::systemBus, service, objPath, |
| 624 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 625 | [objPath, aResp{std::move(aResp)}](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 626 | const std::string& property) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 627 | if (ec) |
| 628 | { |
| 629 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 630 | messages::internalError(aResp->res); |
| 631 | return; |
| 632 | } |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 633 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 634 | aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 635 | property; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 636 | }); |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 637 | } |
| 638 | |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 639 | /** |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 640 | * Populate the unique identifier in a Processor resource by requesting data |
| 641 | * from the given D-Bus object. |
| 642 | * |
| 643 | * @param[in,out] aResp Async HTTP response. |
| 644 | * @param[in] service D-Bus service to query. |
| 645 | * @param[in] objPath D-Bus object to query. |
| 646 | */ |
| 647 | inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 648 | const std::string& service, |
| 649 | const std::string& objectPath) |
| 650 | { |
| 651 | BMCWEB_LOG_DEBUG << "Get CPU UniqueIdentifier"; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 652 | sdbusplus::asio::getProperty<std::string>( |
| 653 | *crow::connections::systemBus, service, objectPath, |
| 654 | "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", |
| 655 | "UniqueIdentifier", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 656 | [aResp](const boost::system::error_code& ec, const std::string& id) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 657 | if (ec) |
| 658 | { |
| 659 | BMCWEB_LOG_ERROR << "Failed to read cpu unique id: " << ec; |
| 660 | messages::internalError(aResp->res); |
| 661 | return; |
| 662 | } |
| 663 | aResp->res.jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = |
| 664 | id; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 665 | }); |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /** |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 669 | * Find the D-Bus object representing the requested Processor, and call the |
| 670 | * handler with the results. If matching object is not found, add 404 error to |
| 671 | * response and don't call the handler. |
| 672 | * |
| 673 | * @param[in,out] resp Async HTTP response. |
| 674 | * @param[in] processorId Redfish Processor Id. |
| 675 | * @param[in] handler Callback to continue processing request upon |
| 676 | * successfully finding object. |
| 677 | */ |
| 678 | template <typename Handler> |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 679 | inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp, |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 680 | const std::string& processorId, |
| 681 | Handler&& handler) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 682 | { |
| 683 | BMCWEB_LOG_DEBUG << "Get available system processor resources."; |
| 684 | |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 685 | // GetSubTree on all interfaces which provide info about a Processor |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 686 | constexpr std::array<std::string_view, 8> interfaces = { |
| 687 | "xyz.openbmc_project.Common.UUID", |
| 688 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 689 | "xyz.openbmc_project.Inventory.Decorator.Revision", |
| 690 | "xyz.openbmc_project.Inventory.Item.Cpu", |
| 691 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", |
| 692 | "xyz.openbmc_project.Inventory.Item.Accelerator", |
| 693 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", |
| 694 | "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier"}; |
| 695 | dbus::utility::getSubTree( |
| 696 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 697 | [resp, processorId, handler = std::forward<Handler>(handler)]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 698 | const boost::system::error_code& ec, |
| 699 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 700 | if (ec) |
| 701 | { |
| 702 | BMCWEB_LOG_DEBUG << "DBUS response error: " << ec; |
| 703 | messages::internalError(resp->res); |
| 704 | return; |
| 705 | } |
| 706 | for (const auto& [objectPath, serviceMap] : subtree) |
| 707 | { |
| 708 | // Ignore any objects which don't end with our desired cpu name |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 709 | if (!objectPath.ends_with(processorId)) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 710 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 711 | continue; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 712 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 713 | |
| 714 | bool found = false; |
| 715 | // Filter out objects that don't have the CPU-specific |
| 716 | // interfaces to make sure we can return 404 on non-CPUs |
| 717 | // (e.g. /redfish/../Processors/dimm0) |
| 718 | for (const auto& [serviceName, interfaceList] : serviceMap) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 719 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 720 | if (std::find_first_of( |
| 721 | interfaceList.begin(), interfaceList.end(), |
| 722 | processorInterfaces.begin(), |
| 723 | processorInterfaces.end()) != interfaceList.end()) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 724 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 725 | found = true; |
| 726 | break; |
Jonathan Doman | 2bab983 | 2020-12-02 15:27:40 -0800 | [diff] [blame] | 727 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 728 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 729 | |
| 730 | if (!found) |
| 731 | { |
| 732 | continue; |
| 733 | } |
| 734 | |
| 735 | // Process the first object which does match our cpu name and |
| 736 | // required interfaces, and potentially ignore any other |
| 737 | // matching objects. Assume all interfaces we want to process |
| 738 | // must be on the same object path. |
| 739 | |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 740 | handler(objectPath, serviceMap); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 741 | return; |
| 742 | } |
| 743 | messages::resourceNotFound(resp->res, "Processor", processorId); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 744 | }); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 745 | } |
| 746 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 747 | inline void getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 748 | const std::string& processorId, |
| 749 | const std::string& objectPath, |
Shantappa Teekappanavar | 5df6eda | 2022-01-18 12:29:28 -0600 | [diff] [blame] | 750 | const dbus::utility::MapperServiceMap& serviceMap) |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 751 | { |
| 752 | for (const auto& [serviceName, interfaceList] : serviceMap) |
| 753 | { |
| 754 | for (const auto& interface : interfaceList) |
| 755 | { |
| 756 | if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") |
| 757 | { |
| 758 | getCpuAssetData(aResp, serviceName, objectPath); |
| 759 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 760 | else if (interface == |
| 761 | "xyz.openbmc_project.Inventory.Decorator.Revision") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 762 | { |
| 763 | getCpuRevisionData(aResp, serviceName, objectPath); |
| 764 | } |
| 765 | else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu") |
| 766 | { |
| 767 | getCpuDataByService(aResp, processorId, serviceName, |
| 768 | objectPath); |
| 769 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 770 | else if (interface == |
| 771 | "xyz.openbmc_project.Inventory.Item.Accelerator") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 772 | { |
| 773 | getAcceleratorDataByService(aResp, processorId, serviceName, |
| 774 | objectPath); |
| 775 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 776 | else if ( |
| 777 | interface == |
| 778 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 779 | { |
| 780 | getCpuConfigData(aResp, processorId, serviceName, objectPath); |
| 781 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 782 | else if (interface == |
| 783 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 784 | { |
| 785 | getCpuLocationCode(aResp, serviceName, objectPath); |
| 786 | } |
Sharad Yadav | 71b82f2 | 2021-05-10 15:11:39 +0530 | [diff] [blame] | 787 | else if (interface == "xyz.openbmc_project.Common.UUID") |
| 788 | { |
| 789 | getProcessorUUID(aResp, serviceName, objectPath); |
| 790 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 791 | else if (interface == |
| 792 | "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier") |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 793 | { |
| 794 | getCpuUniqueId(aResp, serviceName, objectPath); |
| 795 | } |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 800 | /** |
| 801 | * Request all the properties for the given D-Bus object and fill out the |
| 802 | * related entries in the Redfish OperatingConfig response. |
| 803 | * |
| 804 | * @param[in,out] aResp Async HTTP response. |
| 805 | * @param[in] service D-Bus service name to query. |
| 806 | * @param[in] objPath D-Bus object to query. |
| 807 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 808 | inline void |
| 809 | getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 810 | const std::string& service, |
| 811 | const std::string& objPath) |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 812 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 813 | sdbusplus::asio::getAllProperties( |
| 814 | *crow::connections::systemBus, service, objPath, |
| 815 | "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 816 | [aResp](const boost::system::error_code& ec, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 817 | const dbus::utility::DBusPropertiesMap& properties) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 818 | if (ec) |
| 819 | { |
| 820 | BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message(); |
| 821 | messages::internalError(aResp->res); |
| 822 | return; |
| 823 | } |
| 824 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 825 | const size_t* availableCoreCount = nullptr; |
| 826 | const uint32_t* baseSpeed = nullptr; |
| 827 | const uint32_t* maxJunctionTemperature = nullptr; |
| 828 | const uint32_t* maxSpeed = nullptr; |
| 829 | const uint32_t* powerLimit = nullptr; |
| 830 | const TurboProfileProperty* turboProfile = nullptr; |
| 831 | const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings = |
| 832 | nullptr; |
| 833 | |
| 834 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 835 | dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount", |
| 836 | availableCoreCount, "BaseSpeed", baseSpeed, |
| 837 | "MaxJunctionTemperature", maxJunctionTemperature, "MaxSpeed", |
| 838 | maxSpeed, "PowerLimit", powerLimit, "TurboProfile", turboProfile, |
| 839 | "BaseSpeedPrioritySettings", baseSpeedPrioritySettings); |
| 840 | |
| 841 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 842 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 843 | messages::internalError(aResp->res); |
| 844 | return; |
| 845 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 846 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 847 | nlohmann::json& json = aResp->res.jsonValue; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 848 | |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 849 | if (availableCoreCount != nullptr) |
| 850 | { |
| 851 | json["TotalAvailableCoreCount"] = *availableCoreCount; |
| 852 | } |
| 853 | |
| 854 | if (baseSpeed != nullptr) |
| 855 | { |
| 856 | json["BaseSpeedMHz"] = *baseSpeed; |
| 857 | } |
| 858 | |
| 859 | if (maxJunctionTemperature != nullptr) |
| 860 | { |
| 861 | json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature; |
| 862 | } |
| 863 | |
| 864 | if (maxSpeed != nullptr) |
| 865 | { |
| 866 | json["MaxSpeedMHz"] = *maxSpeed; |
| 867 | } |
| 868 | |
| 869 | if (powerLimit != nullptr) |
| 870 | { |
| 871 | json["TDPWatts"] = *powerLimit; |
| 872 | } |
| 873 | |
| 874 | if (turboProfile != nullptr) |
| 875 | { |
| 876 | nlohmann::json& turboArray = json["TurboProfile"]; |
| 877 | turboArray = nlohmann::json::array(); |
| 878 | for (const auto& [turboSpeed, coreCount] : *turboProfile) |
| 879 | { |
| 880 | nlohmann::json::object_t turbo; |
| 881 | turbo["ActiveCoreCount"] = coreCount; |
| 882 | turbo["MaxSpeedMHz"] = turboSpeed; |
| 883 | turboArray.push_back(std::move(turbo)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 884 | } |
| 885 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 886 | |
| 887 | if (baseSpeedPrioritySettings != nullptr) |
| 888 | { |
| 889 | nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"]; |
| 890 | baseSpeedArray = nlohmann::json::array(); |
| 891 | for (const auto& [baseSpeedMhz, coreList] : |
| 892 | *baseSpeedPrioritySettings) |
| 893 | { |
| 894 | nlohmann::json::object_t speed; |
| 895 | speed["CoreCount"] = coreList.size(); |
| 896 | speed["CoreIDs"] = coreList; |
| 897 | speed["BaseSpeedMHz"] = baseSpeedMhz; |
| 898 | baseSpeedArray.push_back(std::move(speed)); |
| 899 | } |
| 900 | } |
| 901 | }); |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 902 | } |
| 903 | |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 904 | /** |
| 905 | * Handle the D-Bus response from attempting to set the CPU's AppliedConfig |
| 906 | * property. Main task is to translate error messages into Redfish errors. |
| 907 | * |
| 908 | * @param[in,out] resp HTTP response. |
| 909 | * @param[in] setPropVal Value which we attempted to set. |
| 910 | * @param[in] ec D-Bus response error code. |
| 911 | * @param[in] msg D-Bus response message. |
| 912 | */ |
| 913 | inline void |
| 914 | handleAppliedConfigResponse(const std::shared_ptr<bmcweb::AsyncResp>& resp, |
| 915 | const std::string& setPropVal, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 916 | const boost::system::error_code& ec, |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 917 | const sdbusplus::message_t& msg) |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 918 | { |
| 919 | if (!ec) |
| 920 | { |
| 921 | BMCWEB_LOG_DEBUG << "Set Property succeeded"; |
| 922 | return; |
| 923 | } |
| 924 | |
| 925 | BMCWEB_LOG_DEBUG << "Set Property failed: " << ec; |
| 926 | |
| 927 | const sd_bus_error* dbusError = msg.get_error(); |
| 928 | if (dbusError == nullptr) |
| 929 | { |
| 930 | messages::internalError(resp->res); |
| 931 | return; |
| 932 | } |
| 933 | |
| 934 | // The asio error code doesn't know about our custom errors, so we have to |
| 935 | // parse the error string. Some of these D-Bus -> Redfish translations are a |
| 936 | // stretch, but it's good to try to communicate something vaguely useful. |
| 937 | if (strcmp(dbusError->name, |
| 938 | "xyz.openbmc_project.Common.Error.InvalidArgument") == 0) |
| 939 | { |
| 940 | // Service did not like the object_path we tried to set. |
| 941 | messages::propertyValueIncorrect( |
| 942 | resp->res, "AppliedOperatingConfig/@odata.id", setPropVal); |
| 943 | } |
| 944 | else if (strcmp(dbusError->name, |
| 945 | "xyz.openbmc_project.Common.Error.NotAllowed") == 0) |
| 946 | { |
| 947 | // Service indicates we can never change the config for this processor. |
| 948 | messages::propertyNotWritable(resp->res, "AppliedOperatingConfig"); |
| 949 | } |
| 950 | else if (strcmp(dbusError->name, |
| 951 | "xyz.openbmc_project.Common.Error.Unavailable") == 0) |
| 952 | { |
| 953 | // Service indicates the config cannot be changed right now, but maybe |
| 954 | // in a different system state. |
| 955 | messages::resourceInStandby(resp->res); |
| 956 | } |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 957 | else |
| 958 | { |
| 959 | messages::internalError(resp->res); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic |
| 965 | * validation of the input data, and then set the D-Bus property. |
| 966 | * |
| 967 | * @param[in,out] resp Async HTTP response. |
| 968 | * @param[in] processorId Processor's Id. |
| 969 | * @param[in] appliedConfigUri New property value to apply. |
| 970 | * @param[in] cpuObjectPath Path of CPU object to modify. |
| 971 | * @param[in] serviceMap Service map for CPU object. |
| 972 | */ |
| 973 | inline void patchAppliedOperatingConfig( |
| 974 | const std::shared_ptr<bmcweb::AsyncResp>& resp, |
| 975 | const std::string& processorId, const std::string& appliedConfigUri, |
Shantappa Teekappanavar | 5df6eda | 2022-01-18 12:29:28 -0600 | [diff] [blame] | 976 | const std::string& cpuObjectPath, |
| 977 | const dbus::utility::MapperServiceMap& serviceMap) |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 978 | { |
| 979 | // Check that the property even exists by checking for the interface |
| 980 | const std::string* controlService = nullptr; |
| 981 | for (const auto& [serviceName, interfaceList] : serviceMap) |
| 982 | { |
| 983 | if (std::find(interfaceList.begin(), interfaceList.end(), |
| 984 | "xyz.openbmc_project.Control.Processor." |
| 985 | "CurrentOperatingConfig") != interfaceList.end()) |
| 986 | { |
| 987 | controlService = &serviceName; |
| 988 | break; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | if (controlService == nullptr) |
| 993 | { |
| 994 | messages::internalError(resp->res); |
| 995 | return; |
| 996 | } |
| 997 | |
| 998 | // Check that the config URI is a child of the cpu URI being patched. |
| 999 | std::string expectedPrefix("/redfish/v1/Systems/system/Processors/"); |
| 1000 | expectedPrefix += processorId; |
| 1001 | expectedPrefix += "/OperatingConfigs/"; |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 1002 | if (!appliedConfigUri.starts_with(expectedPrefix) || |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1003 | expectedPrefix.size() == appliedConfigUri.size()) |
| 1004 | { |
| 1005 | messages::propertyValueIncorrect( |
| 1006 | resp->res, "AppliedOperatingConfig/@odata.id", appliedConfigUri); |
| 1007 | return; |
| 1008 | } |
| 1009 | |
| 1010 | // Generate the D-Bus path of the OperatingConfig object, by assuming it's a |
| 1011 | // direct child of the CPU object. |
| 1012 | // Strip the expectedPrefix from the config URI to get the "filename", and |
| 1013 | // append to the CPU's path. |
| 1014 | std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size()); |
| 1015 | sdbusplus::message::object_path configPath(cpuObjectPath); |
| 1016 | configPath /= configBaseName; |
| 1017 | |
| 1018 | BMCWEB_LOG_INFO << "Setting config to " << configPath.str; |
| 1019 | |
| 1020 | // Set the property, with handler to check error responses |
| 1021 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1022 | [resp, appliedConfigUri](const boost::system::error_code& ec, |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 1023 | const sdbusplus::message_t& msg) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1024 | handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1025 | }, |
| 1026 | *controlService, cpuObjectPath, "org.freedesktop.DBus.Properties", |
| 1027 | "Set", "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1028 | "AppliedConfig", dbus::utility::DbusVariantType(std::move(configPath))); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1031 | inline void handleProcessorHead(crow::App& app, const crow::Request& req, |
| 1032 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 1033 | const std::string& /* systemName */, |
| 1034 | const std::string& /* processorId */) |
| 1035 | { |
| 1036 | if (!redfish::setUpRedfishRoute(app, req, aResp)) |
| 1037 | { |
| 1038 | return; |
| 1039 | } |
| 1040 | aResp->res.addHeader( |
| 1041 | boost::beast::http::field::link, |
| 1042 | "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); |
| 1043 | } |
| 1044 | |
| 1045 | inline void handleProcessorCollectionHead( |
| 1046 | crow::App& app, const crow::Request& req, |
| 1047 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 1048 | const std::string& /* systemName */) |
| 1049 | { |
| 1050 | if (!redfish::setUpRedfishRoute(app, req, aResp)) |
| 1051 | { |
| 1052 | return; |
| 1053 | } |
| 1054 | aResp->res.addHeader( |
| 1055 | boost::beast::http::field::link, |
| 1056 | "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); |
| 1057 | } |
| 1058 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1059 | inline void requestRoutesOperatingConfigCollection(App& app) |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1060 | { |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1061 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1062 | BMCWEB_ROUTE( |
| 1063 | app, "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1064 | .privileges(redfish::privileges::getOperatingConfigCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1065 | .methods(boost::beast::http::verb::get)( |
| 1066 | [&app](const crow::Request& req, |
| 1067 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1068 | const std::string& cpuName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1069 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1070 | { |
| 1071 | return; |
| 1072 | } |
| 1073 | asyncResp->res.jsonValue["@odata.type"] = |
| 1074 | "#OperatingConfigCollection.OperatingConfigCollection"; |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame^] | 1075 | asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( |
| 1076 | "redfish", "v1", "Systems", "system", "Processors", cpuName, |
| 1077 | "OperatingConfigs"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1078 | asyncResp->res.jsonValue["Name"] = "Operating Config Collection"; |
| 1079 | |
| 1080 | // First find the matching CPU object so we know how to |
| 1081 | // constrain our search for related Config objects. |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1082 | const std::array<std::string_view, 1> interfaces = { |
| 1083 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"}; |
| 1084 | dbus::utility::getSubTreePaths( |
| 1085 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1086 | [asyncResp, cpuName]( |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1087 | const boost::system::error_code& ec, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1088 | const dbus::utility::MapperGetSubTreePathsResponse& objects) { |
| 1089 | if (ec) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1090 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1091 | BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " |
| 1092 | << ec.message(); |
| 1093 | messages::internalError(asyncResp->res); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1094 | return; |
| 1095 | } |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1096 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1097 | for (const std::string& object : objects) |
| 1098 | { |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 1099 | if (!object.ends_with(cpuName)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1100 | { |
| 1101 | continue; |
| 1102 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1103 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1104 | // Not expected that there will be multiple matching |
| 1105 | // CPU objects, but if there are just use the first |
| 1106 | // one. |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1107 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1108 | // Use the common search routine to construct the |
| 1109 | // Collection of all Config objects under this CPU. |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1110 | constexpr std::array<std::string_view, 1> interface { |
| 1111 | "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig" |
| 1112 | }; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1113 | collection_util::getCollectionMembers( |
| 1114 | asyncResp, |
Willy Tu | ae9031f | 2022-09-27 05:48:07 +0000 | [diff] [blame] | 1115 | crow::utility::urlFromPieces("redfish", "v1", "Systems", |
| 1116 | "system", "Processors", |
| 1117 | cpuName, "OperatingConfigs"), |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1118 | interface, object.c_str()); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1119 | return; |
| 1120 | } |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1121 | }); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1122 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | inline void requestRoutesOperatingConfig(App& app) |
| 1126 | { |
| 1127 | BMCWEB_ROUTE( |
| 1128 | app, |
| 1129 | "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1130 | .privileges(redfish::privileges::getOperatingConfig) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1131 | .methods(boost::beast::http::verb::get)( |
| 1132 | [&app](const crow::Request& req, |
| 1133 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1134 | const std::string& cpuName, const std::string& configName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1135 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1136 | { |
| 1137 | return; |
| 1138 | } |
| 1139 | // Ask for all objects implementing OperatingConfig so we can search |
| 1140 | // for one with a matching name |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1141 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1142 | "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}; |
| 1143 | dbus::utility::getSubTree( |
| 1144 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame^] | 1145 | [asyncResp, cpuName, configName]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1146 | const boost::system::error_code& ec, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1147 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 1148 | if (ec) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1149 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1150 | BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " |
| 1151 | << ec.message(); |
| 1152 | messages::internalError(asyncResp->res); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1153 | return; |
| 1154 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1155 | const std::string expectedEnding = cpuName + '/' + configName; |
| 1156 | for (const auto& [objectPath, serviceMap] : subtree) |
| 1157 | { |
| 1158 | // Ignore any configs without matching cpuX/configY |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 1159 | if (!objectPath.ends_with(expectedEnding) || serviceMap.empty()) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1160 | { |
| 1161 | continue; |
| 1162 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1163 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1164 | nlohmann::json& json = asyncResp->res.jsonValue; |
| 1165 | json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig"; |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame^] | 1166 | json["@odata.id"] = crow::utility::urlFromPieces( |
| 1167 | "redfish", "v1", "Systems", "system", "Processors", cpuName, |
| 1168 | "OperatingConfigs", configName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1169 | json["Name"] = "Processor Profile"; |
| 1170 | json["Id"] = configName; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1171 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1172 | // Just use the first implementation of the object - not |
| 1173 | // expected that there would be multiple matching |
| 1174 | // services |
| 1175 | getOperatingConfigData(asyncResp, serviceMap.begin()->first, |
| 1176 | objectPath); |
| 1177 | return; |
| 1178 | } |
| 1179 | messages::resourceNotFound(asyncResp->res, "OperatingConfig", |
| 1180 | configName); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1181 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1182 | }); |
| 1183 | } |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1184 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1185 | inline void requestRoutesProcessorCollection(App& app) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1186 | { |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1187 | /** |
| 1188 | * Functions triggers appropriate requests on DBus |
| 1189 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1190 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1191 | .privileges(redfish::privileges::headProcessorCollection) |
| 1192 | .methods(boost::beast::http::verb::head)( |
| 1193 | std::bind_front(handleProcessorCollectionHead, std::ref(app))); |
| 1194 | |
| 1195 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1196 | .privileges(redfish::privileges::getProcessorCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1197 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1198 | [&app](const crow::Request& req, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1199 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1200 | const std::string& systemName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1201 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1202 | { |
| 1203 | return; |
| 1204 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1205 | if (systemName != "system") |
| 1206 | { |
| 1207 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1208 | systemName); |
| 1209 | return; |
| 1210 | } |
| 1211 | |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1212 | asyncResp->res.addHeader( |
| 1213 | boost::beast::http::field::link, |
| 1214 | "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); |
| 1215 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1216 | asyncResp->res.jsonValue["@odata.type"] = |
| 1217 | "#ProcessorCollection.ProcessorCollection"; |
| 1218 | asyncResp->res.jsonValue["Name"] = "Processor Collection"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1219 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1220 | asyncResp->res.jsonValue["@odata.id"] = |
| 1221 | "/redfish/v1/Systems/system/Processors"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1222 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1223 | collection_util::getCollectionMembers( |
Willy Tu | ae9031f | 2022-09-27 05:48:07 +0000 | [diff] [blame] | 1224 | asyncResp, |
| 1225 | boost::urls::url("/redfish/v1/Systems/system/Processors"), |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1226 | processorInterfaces); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1227 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1228 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1229 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1230 | inline void requestRoutesProcessor(App& app) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1231 | { |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1232 | /** |
| 1233 | * Functions triggers appropriate requests on DBus |
| 1234 | */ |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1235 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1236 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1237 | .privileges(redfish::privileges::headProcessor) |
| 1238 | .methods(boost::beast::http::verb::head)( |
| 1239 | std::bind_front(handleProcessorHead, std::ref(app))); |
| 1240 | |
| 1241 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1242 | .privileges(redfish::privileges::getProcessor) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1243 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1244 | [&app](const crow::Request& req, |
| 1245 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1246 | const std::string& systemName, |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1247 | const std::string& processorId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1248 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1249 | { |
| 1250 | return; |
| 1251 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1252 | if (systemName != "system") |
| 1253 | { |
| 1254 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1255 | systemName); |
| 1256 | return; |
| 1257 | } |
| 1258 | |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1259 | asyncResp->res.addHeader( |
| 1260 | boost::beast::http::field::link, |
| 1261 | "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1262 | asyncResp->res.jsonValue["@odata.type"] = |
| 1263 | "#Processor.v1_11_0.Processor"; |
Willy Tu | eddfc43 | 2022-09-26 16:46:38 +0000 | [diff] [blame] | 1264 | asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( |
| 1265 | "redfish", "v1", "Systems", "system", "Processors", processorId); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1266 | |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 1267 | getProcessorObject( |
| 1268 | asyncResp, processorId, |
| 1269 | std::bind_front(getProcessorData, asyncResp, processorId)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1270 | }); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1271 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1272 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1273 | .privileges(redfish::privileges::patchProcessor) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1274 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1275 | [&app](const crow::Request& req, |
| 1276 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1277 | const std::string& systemName, |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1278 | const std::string& processorId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1279 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1280 | { |
| 1281 | return; |
| 1282 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1283 | if (systemName != "system") |
| 1284 | { |
| 1285 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1286 | systemName); |
| 1287 | return; |
| 1288 | } |
| 1289 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1290 | std::optional<nlohmann::json> appliedConfigJson; |
| 1291 | if (!json_util::readJsonPatch(req, asyncResp->res, |
| 1292 | "AppliedOperatingConfig", |
| 1293 | appliedConfigJson)) |
| 1294 | { |
| 1295 | return; |
| 1296 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1297 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1298 | if (appliedConfigJson) |
| 1299 | { |
Ed Tanous | f8fe53e | 2022-06-30 15:55:45 -0700 | [diff] [blame] | 1300 | std::string appliedConfigUri; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1301 | if (!json_util::readJson(*appliedConfigJson, asyncResp->res, |
| 1302 | "@odata.id", appliedConfigUri)) |
| 1303 | { |
| 1304 | return; |
| 1305 | } |
| 1306 | // Check for 404 and find matching D-Bus object, then run |
| 1307 | // property patch handlers if that all succeeds. |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 1308 | getProcessorObject(asyncResp, processorId, |
| 1309 | std::bind_front(patchAppliedOperatingConfig, |
| 1310 | asyncResp, processorId, |
| 1311 | appliedConfigUri)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1312 | } |
| 1313 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1314 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1315 | |
| 1316 | } // namespace redfish |