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