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