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