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