Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1 | /* |
Ed Tanous | 6be832e | 2024-09-10 11:44:48 -0700 | [diff] [blame^] | 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. |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 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) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 70 | if (ec) |
| 71 | { |
| 72 | BMCWEB_LOG_DEBUG("DBUS response error"); |
| 73 | messages::internalError(asyncResp->res); |
| 74 | return; |
| 75 | } |
| 76 | asyncResp->res.jsonValue["UUID"] = property; |
| 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 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 225 | inline void getCpuDataByService( |
| 226 | std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& cpuId, |
| 227 | const std::string& service, const std::string& objPath) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 228 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 229 | BMCWEB_LOG_DEBUG("Get available system cpu resources by service."); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 230 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 231 | sdbusplus::message::object_path path("/xyz/openbmc_project/inventory"); |
| 232 | dbus::utility::getManagedObjects( |
| 233 | service, path, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 234 | [cpuId, service, objPath, asyncResp{std::move(asyncResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 235 | const boost::system::error_code& ec, |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 236 | const dbus::utility::ManagedObjectType& dbusData) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 237 | if (ec) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 238 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 239 | BMCWEB_LOG_DEBUG("DBUS response error"); |
| 240 | messages::internalError(asyncResp->res); |
| 241 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 242 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 243 | asyncResp->res.jsonValue["Id"] = cpuId; |
| 244 | asyncResp->res.jsonValue["Name"] = "Processor"; |
| 245 | asyncResp->res.jsonValue["ProcessorType"] = |
| 246 | processor::ProcessorType::CPU; |
| 247 | |
| 248 | bool slotPresent = false; |
| 249 | std::string corePath = objPath + "/core"; |
| 250 | size_t totalCores = 0; |
| 251 | for (const auto& object : dbusData) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 252 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 253 | if (object.first.str == objPath) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 254 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 255 | getCpuDataByInterface(asyncResp, object.second); |
| 256 | } |
| 257 | else if (object.first.str.starts_with(corePath)) |
| 258 | { |
| 259 | for (const auto& interface : object.second) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 260 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 261 | if (interface.first == |
| 262 | "xyz.openbmc_project.Inventory.Item") |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 263 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 264 | for (const auto& property : interface.second) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 265 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 266 | if (property.first == "Present") |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 267 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [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 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 272 | if (*present) |
| 273 | { |
| 274 | slotPresent = true; |
| 275 | totalCores++; |
| 276 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 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 | { |
| 289 | asyncResp->res.jsonValue["TotalCores"] = totalCores; |
| 290 | } |
| 291 | return; |
| 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 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 373 | inline void getThrottleProperties( |
| 374 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 375 | const std::string& service, const std::string& objectPath) |
Chris Cain | dfbf7de | 2023-04-13 16:01:04 -0500 | [diff] [blame] | 376 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 377 | BMCWEB_LOG_DEBUG("Get processor throttle resources"); |
Chris Cain | dfbf7de | 2023-04-13 16:01:04 -0500 | [diff] [blame] | 378 | |
| 379 | sdbusplus::asio::getAllProperties( |
| 380 | *crow::connections::systemBus, service, objectPath, |
| 381 | "xyz.openbmc_project.Control.Power.Throttle", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 382 | [asyncResp](const boost::system::error_code& ec, |
| 383 | const dbus::utility::DBusPropertiesMap& properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 384 | readThrottleProperties(asyncResp, ec, properties); |
| 385 | }); |
Chris Cain | dfbf7de | 2023-04-13 16:01:04 -0500 | [diff] [blame] | 386 | } |
| 387 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 388 | inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> asyncResp, |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 389 | const std::string& service, |
| 390 | const std::string& objPath) |
| 391 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 392 | BMCWEB_LOG_DEBUG("Get Cpu Asset Data"); |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 393 | sdbusplus::asio::getAllProperties( |
| 394 | *crow::connections::systemBus, service, objPath, |
| 395 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 396 | [objPath, asyncResp{std::move(asyncResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 397 | const boost::system::error_code& ec, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 398 | const dbus::utility::DBusPropertiesMap& properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 399 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 400 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 401 | BMCWEB_LOG_DEBUG("DBUS response error"); |
| 402 | messages::internalError(asyncResp->res); |
| 403 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 404 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 405 | |
| 406 | const std::string* serialNumber = nullptr; |
| 407 | const std::string* model = nullptr; |
| 408 | const std::string* manufacturer = nullptr; |
| 409 | const std::string* partNumber = nullptr; |
| 410 | const std::string* sparePartNumber = nullptr; |
| 411 | |
| 412 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 413 | dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber", |
| 414 | serialNumber, "Model", model, "Manufacturer", manufacturer, |
| 415 | "PartNumber", partNumber, "SparePartNumber", sparePartNumber); |
| 416 | |
| 417 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 418 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 419 | messages::internalError(asyncResp->res); |
| 420 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 421 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 422 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 423 | if (serialNumber != nullptr && !serialNumber->empty()) |
| 424 | { |
| 425 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 426 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 427 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 428 | if ((model != nullptr) && !model->empty()) |
| 429 | { |
| 430 | asyncResp->res.jsonValue["Model"] = *model; |
| 431 | } |
| 432 | |
| 433 | if (manufacturer != nullptr) |
| 434 | { |
| 435 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 436 | |
| 437 | // Otherwise would be unexpected. |
| 438 | if (manufacturer->find("Intel") != std::string::npos) |
| 439 | { |
| 440 | asyncResp->res.jsonValue["ProcessorArchitecture"] = "x86"; |
| 441 | asyncResp->res.jsonValue["InstructionSet"] = "x86-64"; |
| 442 | } |
| 443 | else if (manufacturer->find("IBM") != std::string::npos) |
| 444 | { |
| 445 | asyncResp->res.jsonValue["ProcessorArchitecture"] = "Power"; |
| 446 | asyncResp->res.jsonValue["InstructionSet"] = "PowerISA"; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if (partNumber != nullptr) |
| 451 | { |
| 452 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 453 | } |
| 454 | |
| 455 | if (sparePartNumber != nullptr && !sparePartNumber->empty()) |
| 456 | { |
| 457 | asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; |
| 458 | } |
| 459 | }); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 460 | } |
| 461 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 462 | inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp, |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 463 | const std::string& service, |
| 464 | const std::string& objPath) |
| 465 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 466 | BMCWEB_LOG_DEBUG("Get Cpu Revision Data"); |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 467 | sdbusplus::asio::getAllProperties( |
| 468 | *crow::connections::systemBus, service, objPath, |
| 469 | "xyz.openbmc_project.Inventory.Decorator.Revision", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 470 | [objPath, asyncResp{std::move(asyncResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 471 | const boost::system::error_code& ec, |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 472 | const dbus::utility::DBusPropertiesMap& properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 473 | if (ec) |
| 474 | { |
| 475 | BMCWEB_LOG_DEBUG("DBUS response error"); |
| 476 | messages::internalError(asyncResp->res); |
| 477 | return; |
| 478 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 479 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 480 | const std::string* version = nullptr; |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 481 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 482 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 483 | dbus_utils::UnpackErrorPrinter(), properties, "Version", |
| 484 | version); |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 485 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 486 | if (!success) |
| 487 | { |
| 488 | messages::internalError(asyncResp->res); |
| 489 | return; |
| 490 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 491 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 492 | if (version != nullptr) |
| 493 | { |
| 494 | asyncResp->res.jsonValue["Version"] = *version; |
| 495 | } |
| 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) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 509 | if (ec) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 510 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 511 | BMCWEB_LOG_DEBUG("DBUS response error"); |
| 512 | messages::internalError(asyncResp->res); |
| 513 | return; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 514 | } |
| 515 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [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) |
| 524 | { |
| 525 | messages::internalError(asyncResp->res); |
| 526 | return; |
| 527 | } |
| 528 | |
| 529 | std::string state = "Enabled"; |
| 530 | std::string health = "OK"; |
| 531 | |
| 532 | if (present != nullptr && !*present) |
| 533 | { |
| 534 | state = "Absent"; |
| 535 | } |
| 536 | |
| 537 | if (functional != nullptr && !*functional) |
| 538 | { |
| 539 | if (state == "Enabled") |
| 540 | { |
| 541 | health = "Critical"; |
| 542 | } |
| 543 | } |
| 544 | |
| 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; |
| 549 | asyncResp->res.jsonValue["ProcessorType"] = |
| 550 | processor::ProcessorType::Accelerator; |
| 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) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 624 | if (ec) |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 625 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [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); |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 628 | return; |
| 629 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 630 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 631 | nlohmann::json& json = asyncResp->res.jsonValue; |
| 632 | |
| 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) |
| 642 | { |
| 643 | messages::internalError(asyncResp->res); |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | if (appliedConfig != nullptr) |
| 648 | { |
| 649 | const std::string& dbusPath = appliedConfig->str; |
| 650 | nlohmann::json::object_t operatingConfig; |
| 651 | operatingConfig["@odata.id"] = boost::urls::format( |
| 652 | "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs", |
| 653 | BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId); |
| 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)) |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 661 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 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 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 668 | nlohmann::json::object_t appliedOperatingConfig; |
| 669 | appliedOperatingConfig["@odata.id"] = boost::urls::format( |
| 670 | "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}", |
| 671 | BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId, |
| 672 | dbusPath.substr(baseNamePos + 1)); |
| 673 | json["AppliedOperatingConfig"] = |
| 674 | std::move(appliedOperatingConfig); |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 675 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 676 | // Once we found the current applied config, queue another |
| 677 | // request to read the base freq core ids out of that |
| 678 | // config. |
| 679 | sdbusplus::asio::getProperty<BaseSpeedPrioritySettingsProperty>( |
| 680 | *crow::connections::systemBus, service, dbusPath, |
| 681 | "xyz.openbmc_project.Inventory.Item.Cpu." |
| 682 | "OperatingConfig", |
| 683 | "BaseSpeedPrioritySettings", |
| 684 | [asyncResp](const boost::system::error_code& ec2, |
| 685 | const BaseSpeedPrioritySettingsProperty& |
| 686 | baseSpeedList) { |
| 687 | if (ec2) |
| 688 | { |
| 689 | BMCWEB_LOG_WARNING("D-Bus Property Get error: {}", |
| 690 | ec2); |
| 691 | messages::internalError(asyncResp->res); |
| 692 | return; |
| 693 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 694 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 695 | highSpeedCoreIdsHandler(asyncResp, baseSpeedList); |
| 696 | }); |
| 697 | } |
| 698 | |
| 699 | if (baseSpeedPriorityEnabled != nullptr) |
| 700 | { |
| 701 | json["BaseSpeedPriorityState"] = |
| 702 | *baseSpeedPriorityEnabled ? "Enabled" : "Disabled"; |
| 703 | } |
| 704 | }); |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 705 | } |
| 706 | |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 707 | /** |
| 708 | * @brief Fill out location info of a processor by |
| 709 | * requesting data from the given D-Bus object. |
| 710 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 711 | * @param[in,out] asyncResp Async HTTP response. |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 712 | * @param[in] service D-Bus service to query. |
| 713 | * @param[in] objPath D-Bus object to query. |
| 714 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 715 | inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> asyncResp, |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 716 | const std::string& service, |
| 717 | const std::string& objPath) |
| 718 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 719 | BMCWEB_LOG_DEBUG("Get Cpu Location Data"); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 720 | sdbusplus::asio::getProperty<std::string>( |
| 721 | *crow::connections::systemBus, service, objPath, |
| 722 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 723 | [objPath, asyncResp{std::move(asyncResp)}]( |
| 724 | const boost::system::error_code& ec, const std::string& property) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 725 | if (ec) |
| 726 | { |
| 727 | BMCWEB_LOG_DEBUG("DBUS response error"); |
| 728 | messages::internalError(asyncResp->res); |
| 729 | return; |
| 730 | } |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 731 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 732 | asyncResp->res |
| 733 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 734 | property; |
| 735 | }); |
SunnySrivastava1984 | cba4f44 | 2021-01-07 12:48:16 -0600 | [diff] [blame] | 736 | } |
| 737 | |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 738 | /** |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 739 | * Populate the unique identifier in a Processor resource by requesting data |
| 740 | * from the given D-Bus object. |
| 741 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 742 | * @param[in,out] asyncResp Async HTTP response. |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 743 | * @param[in] service D-Bus service to query. |
| 744 | * @param[in] objPath D-Bus object to query. |
| 745 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 746 | inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 747 | const std::string& service, |
| 748 | const std::string& objectPath) |
| 749 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 750 | BMCWEB_LOG_DEBUG("Get CPU UniqueIdentifier"); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 751 | sdbusplus::asio::getProperty<std::string>( |
| 752 | *crow::connections::systemBus, service, objectPath, |
| 753 | "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", |
| 754 | "UniqueIdentifier", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 755 | [asyncResp](const boost::system::error_code& ec, |
| 756 | const std::string& id) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 757 | if (ec) |
| 758 | { |
| 759 | BMCWEB_LOG_ERROR("Failed to read cpu unique id: {}", ec); |
| 760 | messages::internalError(asyncResp->res); |
| 761 | return; |
| 762 | } |
| 763 | asyncResp->res |
| 764 | .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id; |
| 765 | }); |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /** |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 769 | * Find the D-Bus object representing the requested Processor, and call the |
| 770 | * handler with the results. If matching object is not found, add 404 error to |
| 771 | * response and don't call the handler. |
| 772 | * |
| 773 | * @param[in,out] resp Async HTTP response. |
| 774 | * @param[in] processorId Redfish Processor Id. |
| 775 | * @param[in] handler Callback to continue processing request upon |
| 776 | * successfully finding object. |
| 777 | */ |
| 778 | template <typename Handler> |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 779 | inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp, |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 780 | const std::string& processorId, |
| 781 | Handler&& handler) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 782 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 783 | BMCWEB_LOG_DEBUG("Get available system processor resources."); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 784 | |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 785 | // GetSubTree on all interfaces which provide info about a Processor |
Chris Cain | dfbf7de | 2023-04-13 16:01:04 -0500 | [diff] [blame] | 786 | constexpr std::array<std::string_view, 9> interfaces = { |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 787 | "xyz.openbmc_project.Common.UUID", |
| 788 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 789 | "xyz.openbmc_project.Inventory.Decorator.Revision", |
| 790 | "xyz.openbmc_project.Inventory.Item.Cpu", |
| 791 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", |
| 792 | "xyz.openbmc_project.Inventory.Item.Accelerator", |
| 793 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", |
Chris Cain | dfbf7de | 2023-04-13 16:01:04 -0500 | [diff] [blame] | 794 | "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", |
| 795 | "xyz.openbmc_project.Control.Power.Throttle"}; |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 796 | dbus::utility::getSubTree( |
| 797 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 798 | [resp, processorId, handler = std::forward<Handler>(handler)]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 799 | const boost::system::error_code& ec, |
| 800 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 801 | if (ec) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 802 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 803 | BMCWEB_LOG_DEBUG("DBUS response error: {}", ec); |
| 804 | messages::internalError(resp->res); |
| 805 | return; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 806 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 807 | for (const auto& [objectPath, serviceMap] : subtree) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 808 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 809 | // Ignore any objects which don't end with our desired cpu name |
| 810 | if (!objectPath.ends_with(processorId)) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 811 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 812 | continue; |
Jonathan Doman | 2bab983 | 2020-12-02 15:27:40 -0800 | [diff] [blame] | 813 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 814 | |
| 815 | bool found = false; |
| 816 | // Filter out objects that don't have the CPU-specific |
| 817 | // interfaces to make sure we can return 404 on non-CPUs |
| 818 | // (e.g. /redfish/../Processors/dimm0) |
| 819 | for (const auto& [serviceName, interfaceList] : serviceMap) |
| 820 | { |
| 821 | if (std::ranges::find_first_of(interfaceList, |
| 822 | processorInterfaces) != |
| 823 | std::end(interfaceList)) |
| 824 | { |
| 825 | found = true; |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if (!found) |
| 831 | { |
| 832 | continue; |
| 833 | } |
| 834 | |
| 835 | // Process the first object which does match our cpu name and |
| 836 | // required interfaces, and potentially ignore any other |
| 837 | // matching objects. Assume all interfaces we want to process |
| 838 | // must be on the same object path. |
| 839 | |
| 840 | handler(objectPath, serviceMap); |
| 841 | return; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 842 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 843 | messages::resourceNotFound(resp->res, "Processor", processorId); |
| 844 | }); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 845 | } |
| 846 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 847 | inline void getProcessorData( |
| 848 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 849 | const std::string& processorId, const std::string& objectPath, |
| 850 | const dbus::utility::MapperServiceMap& serviceMap) |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 851 | { |
| 852 | for (const auto& [serviceName, interfaceList] : serviceMap) |
| 853 | { |
| 854 | for (const auto& interface : interfaceList) |
| 855 | { |
| 856 | if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") |
| 857 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 858 | getCpuAssetData(asyncResp, serviceName, objectPath); |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 859 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 860 | else if (interface == |
| 861 | "xyz.openbmc_project.Inventory.Decorator.Revision") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 862 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 863 | getCpuRevisionData(asyncResp, serviceName, objectPath); |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 864 | } |
| 865 | else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu") |
| 866 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 867 | getCpuDataByService(asyncResp, processorId, serviceName, |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 868 | objectPath); |
| 869 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 870 | else if (interface == |
| 871 | "xyz.openbmc_project.Inventory.Item.Accelerator") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 872 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 873 | getAcceleratorDataByService(asyncResp, processorId, serviceName, |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 874 | objectPath); |
| 875 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 876 | else if ( |
| 877 | interface == |
| 878 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 879 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 880 | getCpuConfigData(asyncResp, processorId, serviceName, |
| 881 | objectPath); |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 882 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 883 | else if (interface == |
| 884 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 885 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 886 | getCpuLocationCode(asyncResp, serviceName, objectPath); |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 887 | } |
Sharad Yadav | 71b82f2 | 2021-05-10 15:11:39 +0530 | [diff] [blame] | 888 | else if (interface == "xyz.openbmc_project.Common.UUID") |
| 889 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 890 | getProcessorUUID(asyncResp, serviceName, objectPath); |
Sharad Yadav | 71b82f2 | 2021-05-10 15:11:39 +0530 | [diff] [blame] | 891 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 892 | else if (interface == |
| 893 | "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier") |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 894 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 895 | getCpuUniqueId(asyncResp, serviceName, objectPath); |
Jonathan Doman | 49e429c | 2021-03-03 13:11:44 -0800 | [diff] [blame] | 896 | } |
Chris Cain | dfbf7de | 2023-04-13 16:01:04 -0500 | [diff] [blame] | 897 | else if (interface == "xyz.openbmc_project.Control.Power.Throttle") |
| 898 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 899 | getThrottleProperties(asyncResp, serviceName, objectPath); |
Chris Cain | dfbf7de | 2023-04-13 16:01:04 -0500 | [diff] [blame] | 900 | } |
Jonathan Doman | c951448 | 2021-02-24 09:20:51 -0800 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | } |
| 904 | |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 905 | /** |
| 906 | * Request all the properties for the given D-Bus object and fill out the |
| 907 | * related entries in the Redfish OperatingConfig response. |
| 908 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 909 | * @param[in,out] asyncResp Async HTTP response. |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 910 | * @param[in] service D-Bus service name to query. |
| 911 | * @param[in] objPath D-Bus object to query. |
| 912 | */ |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 913 | inline void getOperatingConfigData( |
| 914 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 915 | const std::string& service, const std::string& objPath) |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 916 | { |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 917 | sdbusplus::asio::getAllProperties( |
| 918 | *crow::connections::systemBus, service, objPath, |
| 919 | "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 920 | [asyncResp](const boost::system::error_code& ec, |
| 921 | const dbus::utility::DBusPropertiesMap& properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 922 | if (ec) |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 923 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 924 | BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message()); |
| 925 | messages::internalError(asyncResp->res); |
| 926 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 927 | } |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 928 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 929 | const size_t* availableCoreCount = nullptr; |
| 930 | const uint32_t* baseSpeed = nullptr; |
| 931 | const uint32_t* maxJunctionTemperature = nullptr; |
| 932 | const uint32_t* maxSpeed = nullptr; |
| 933 | const uint32_t* powerLimit = nullptr; |
| 934 | const TurboProfileProperty* turboProfile = nullptr; |
| 935 | const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings = |
| 936 | nullptr; |
| 937 | |
| 938 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 939 | dbus_utils::UnpackErrorPrinter(), properties, |
| 940 | "AvailableCoreCount", availableCoreCount, "BaseSpeed", |
| 941 | baseSpeed, "MaxJunctionTemperature", maxJunctionTemperature, |
| 942 | "MaxSpeed", maxSpeed, "PowerLimit", powerLimit, "TurboProfile", |
| 943 | turboProfile, "BaseSpeedPrioritySettings", |
| 944 | baseSpeedPrioritySettings); |
| 945 | |
| 946 | if (!success) |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 947 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 948 | messages::internalError(asyncResp->res); |
| 949 | return; |
Krzysztof Grobelny | 351053f | 2022-07-28 15:44:22 +0200 | [diff] [blame] | 950 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 951 | |
| 952 | nlohmann::json& json = asyncResp->res.jsonValue; |
| 953 | |
| 954 | if (availableCoreCount != nullptr) |
| 955 | { |
| 956 | json["TotalAvailableCoreCount"] = *availableCoreCount; |
| 957 | } |
| 958 | |
| 959 | if (baseSpeed != nullptr) |
| 960 | { |
| 961 | json["BaseSpeedMHz"] = *baseSpeed; |
| 962 | } |
| 963 | |
| 964 | if (maxJunctionTemperature != nullptr) |
| 965 | { |
| 966 | json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature; |
| 967 | } |
| 968 | |
| 969 | if (maxSpeed != nullptr) |
| 970 | { |
| 971 | json["MaxSpeedMHz"] = *maxSpeed; |
| 972 | } |
| 973 | |
| 974 | if (powerLimit != nullptr) |
| 975 | { |
| 976 | json["TDPWatts"] = *powerLimit; |
| 977 | } |
| 978 | |
| 979 | if (turboProfile != nullptr) |
| 980 | { |
| 981 | nlohmann::json& turboArray = json["TurboProfile"]; |
| 982 | turboArray = nlohmann::json::array(); |
| 983 | for (const auto& [turboSpeed, coreCount] : *turboProfile) |
| 984 | { |
| 985 | nlohmann::json::object_t turbo; |
| 986 | turbo["ActiveCoreCount"] = coreCount; |
| 987 | turbo["MaxSpeedMHz"] = turboSpeed; |
| 988 | turboArray.emplace_back(std::move(turbo)); |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | if (baseSpeedPrioritySettings != nullptr) |
| 993 | { |
| 994 | nlohmann::json& baseSpeedArray = |
| 995 | json["BaseSpeedPrioritySettings"]; |
| 996 | baseSpeedArray = nlohmann::json::array(); |
| 997 | for (const auto& [baseSpeedMhz, coreList] : |
| 998 | *baseSpeedPrioritySettings) |
| 999 | { |
| 1000 | nlohmann::json::object_t speed; |
| 1001 | speed["CoreCount"] = coreList.size(); |
| 1002 | speed["CoreIDs"] = coreList; |
| 1003 | speed["BaseSpeedMHz"] = baseSpeedMhz; |
| 1004 | baseSpeedArray.emplace_back(std::move(speed)); |
| 1005 | } |
| 1006 | } |
| 1007 | }); |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1010 | /** |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1011 | * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic |
| 1012 | * validation of the input data, and then set the D-Bus property. |
| 1013 | * |
| 1014 | * @param[in,out] resp Async HTTP response. |
| 1015 | * @param[in] processorId Processor's Id. |
| 1016 | * @param[in] appliedConfigUri New property value to apply. |
| 1017 | * @param[in] cpuObjectPath Path of CPU object to modify. |
| 1018 | * @param[in] serviceMap Service map for CPU object. |
| 1019 | */ |
| 1020 | inline void patchAppliedOperatingConfig( |
| 1021 | const std::shared_ptr<bmcweb::AsyncResp>& resp, |
| 1022 | const std::string& processorId, const std::string& appliedConfigUri, |
Shantappa Teekappanavar | 5df6eda | 2022-01-18 12:29:28 -0600 | [diff] [blame] | 1023 | const std::string& cpuObjectPath, |
| 1024 | const dbus::utility::MapperServiceMap& serviceMap) |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1025 | { |
| 1026 | // Check that the property even exists by checking for the interface |
| 1027 | const std::string* controlService = nullptr; |
| 1028 | for (const auto& [serviceName, interfaceList] : serviceMap) |
| 1029 | { |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 1030 | if (std::ranges::find(interfaceList, |
| 1031 | "xyz.openbmc_project.Control.Processor." |
| 1032 | "CurrentOperatingConfig") != interfaceList.end()) |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1033 | { |
| 1034 | controlService = &serviceName; |
| 1035 | break; |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | if (controlService == nullptr) |
| 1040 | { |
| 1041 | messages::internalError(resp->res); |
| 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | // 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] | 1046 | std::string expectedPrefix(std::format("/redfish/v1/Systems/{}/Processors/", |
| 1047 | BMCWEB_REDFISH_SYSTEM_URI_NAME)); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1048 | expectedPrefix += processorId; |
| 1049 | expectedPrefix += "/OperatingConfigs/"; |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 1050 | if (!appliedConfigUri.starts_with(expectedPrefix) || |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1051 | expectedPrefix.size() == appliedConfigUri.size()) |
| 1052 | { |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1053 | messages::propertyValueIncorrect(resp->res, "AppliedOperatingConfig", |
| 1054 | appliedConfigUri); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | // Generate the D-Bus path of the OperatingConfig object, by assuming it's a |
| 1059 | // direct child of the CPU object. |
| 1060 | // Strip the expectedPrefix from the config URI to get the "filename", and |
| 1061 | // append to the CPU's path. |
| 1062 | std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size()); |
| 1063 | sdbusplus::message::object_path configPath(cpuObjectPath); |
| 1064 | configPath /= configBaseName; |
| 1065 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1066 | BMCWEB_LOG_INFO("Setting config to {}", configPath.str); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1067 | |
| 1068 | // Set the property, with handler to check error responses |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1069 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1070 | resp, "AppliedOperatingConfig", *controlService, cpuObjectPath, |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1071 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1072 | "AppliedConfig", configPath); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1073 | } |
| 1074 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1075 | inline void handleProcessorHead( |
| 1076 | crow::App& app, const crow::Request& req, |
| 1077 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1078 | const std::string& /* systemName */, const std::string& /* processorId */) |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1079 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1080 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1081 | { |
| 1082 | return; |
| 1083 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1084 | asyncResp->res.addHeader( |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1085 | boost::beast::http::field::link, |
| 1086 | "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); |
| 1087 | } |
| 1088 | |
| 1089 | inline void handleProcessorCollectionHead( |
| 1090 | crow::App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1091 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1092 | const std::string& /* systemName */) |
| 1093 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1094 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1095 | { |
| 1096 | return; |
| 1097 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1098 | asyncResp->res.addHeader( |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1099 | boost::beast::http::field::link, |
| 1100 | "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); |
| 1101 | } |
| 1102 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1103 | inline void requestRoutesOperatingConfigCollection(App& app) |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1104 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1105 | BMCWEB_ROUTE(app, |
| 1106 | "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1107 | .privileges(redfish::privileges::getOperatingConfigCollection) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1108 | .methods( |
| 1109 | boost::beast::http::verb:: |
| 1110 | get)([&app](const crow::Request& req, |
| 1111 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1112 | const std::string& systemName, |
| 1113 | const std::string& cpuName) { |
| 1114 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1115 | { |
| 1116 | return; |
| 1117 | } |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1118 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1119 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1120 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1121 | // Option currently returns no systems. TBD |
| 1122 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1123 | systemName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1124 | return; |
| 1125 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1126 | |
| 1127 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1128 | { |
| 1129 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1130 | systemName); |
| 1131 | return; |
| 1132 | } |
| 1133 | asyncResp->res.jsonValue["@odata.type"] = |
| 1134 | "#OperatingConfigCollection.OperatingConfigCollection"; |
| 1135 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 1136 | "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs", |
| 1137 | BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName); |
| 1138 | asyncResp->res.jsonValue["Name"] = "Operating Config Collection"; |
| 1139 | |
| 1140 | // First find the matching CPU object so we know how to |
| 1141 | // constrain our search for related Config objects. |
| 1142 | const std::array<std::string_view, 1> interfaces = { |
| 1143 | "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"}; |
| 1144 | dbus::utility::getSubTreePaths( |
| 1145 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 1146 | [asyncResp, |
| 1147 | cpuName](const boost::system::error_code& ec, |
| 1148 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1149 | objects) { |
| 1150 | if (ec) |
| 1151 | { |
| 1152 | BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, |
| 1153 | ec.message()); |
| 1154 | messages::internalError(asyncResp->res); |
| 1155 | return; |
| 1156 | } |
| 1157 | |
| 1158 | for (const std::string& object : objects) |
| 1159 | { |
| 1160 | if (!object.ends_with(cpuName)) |
| 1161 | { |
| 1162 | continue; |
| 1163 | } |
| 1164 | |
| 1165 | // Not expected that there will be multiple matching |
| 1166 | // CPU objects, but if there are just use the first |
| 1167 | // one. |
| 1168 | |
| 1169 | // Use the common search routine to construct the |
| 1170 | // Collection of all Config objects under this CPU. |
| 1171 | constexpr std::array<std::string_view, 1> interface{ |
| 1172 | "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}; |
| 1173 | collection_util::getCollectionMembers( |
| 1174 | asyncResp, |
| 1175 | boost::urls::format( |
| 1176 | "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs", |
| 1177 | BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName), |
| 1178 | interface, object); |
| 1179 | return; |
| 1180 | } |
| 1181 | }); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1182 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | inline void requestRoutesOperatingConfig(App& app) |
| 1186 | { |
| 1187 | BMCWEB_ROUTE( |
| 1188 | app, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1189 | "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1190 | .privileges(redfish::privileges::getOperatingConfig) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1191 | .methods( |
| 1192 | boost::beast::http::verb:: |
| 1193 | get)([&app](const crow::Request& req, |
| 1194 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1195 | const std::string& systemName, |
| 1196 | const std::string& cpuName, |
| 1197 | const std::string& configName) { |
| 1198 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1199 | { |
| 1200 | return; |
| 1201 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1202 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1203 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1204 | // Option currently returns no systems. TBD |
| 1205 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1206 | systemName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1207 | return; |
| 1208 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1209 | |
| 1210 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1211 | { |
| 1212 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1213 | systemName); |
| 1214 | return; |
| 1215 | } |
| 1216 | // Ask for all objects implementing OperatingConfig so we can search |
| 1217 | // for one with a matching name |
| 1218 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1219 | "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}; |
| 1220 | dbus::utility::getSubTree( |
| 1221 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 1222 | [asyncResp, cpuName, configName]( |
| 1223 | const boost::system::error_code& ec, |
| 1224 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 1225 | if (ec) |
| 1226 | { |
| 1227 | BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, |
| 1228 | ec.message()); |
| 1229 | messages::internalError(asyncResp->res); |
| 1230 | return; |
| 1231 | } |
| 1232 | const std::string expectedEnding = |
| 1233 | cpuName + '/' + configName; |
| 1234 | for (const auto& [objectPath, serviceMap] : subtree) |
| 1235 | { |
| 1236 | // Ignore any configs without matching cpuX/configY |
| 1237 | if (!objectPath.ends_with(expectedEnding) || |
| 1238 | serviceMap.empty()) |
| 1239 | { |
| 1240 | continue; |
| 1241 | } |
| 1242 | |
| 1243 | nlohmann::json& json = asyncResp->res.jsonValue; |
| 1244 | json["@odata.type"] = |
| 1245 | "#OperatingConfig.v1_0_0.OperatingConfig"; |
| 1246 | json["@odata.id"] = boost::urls::format( |
| 1247 | "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}", |
| 1248 | BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName, |
| 1249 | configName); |
| 1250 | json["Name"] = "Processor Profile"; |
| 1251 | json["Id"] = configName; |
| 1252 | |
| 1253 | // Just use the first implementation of the object - not |
| 1254 | // expected that there would be multiple matching |
| 1255 | // services |
| 1256 | getOperatingConfigData( |
| 1257 | asyncResp, serviceMap.begin()->first, objectPath); |
| 1258 | return; |
| 1259 | } |
| 1260 | messages::resourceNotFound(asyncResp->res, |
| 1261 | "OperatingConfig", configName); |
| 1262 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1263 | }); |
| 1264 | } |
Jonathan Doman | dba0c29 | 2020-12-02 15:34:13 -0800 | [diff] [blame] | 1265 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1266 | inline void requestRoutesProcessorCollection(App& app) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1267 | { |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1268 | /** |
| 1269 | * Functions triggers appropriate requests on DBus |
| 1270 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1271 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1272 | .privileges(redfish::privileges::headProcessorCollection) |
| 1273 | .methods(boost::beast::http::verb::head)( |
| 1274 | std::bind_front(handleProcessorCollectionHead, std::ref(app))); |
| 1275 | |
| 1276 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1277 | .privileges(redfish::privileges::getProcessorCollection) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1278 | .methods( |
| 1279 | boost::beast::http::verb:: |
| 1280 | get)([&app](const crow::Request& req, |
| 1281 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1282 | const std::string& systemName) { |
| 1283 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1284 | { |
| 1285 | return; |
| 1286 | } |
| 1287 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1288 | { |
| 1289 | // Option currently returns no systems. TBD |
| 1290 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1291 | systemName); |
| 1292 | return; |
| 1293 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 1294 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1295 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1296 | { |
| 1297 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1298 | systemName); |
| 1299 | return; |
| 1300 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1301 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1302 | asyncResp->res.addHeader( |
| 1303 | boost::beast::http::field::link, |
| 1304 | "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1305 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1306 | asyncResp->res.jsonValue["@odata.type"] = |
| 1307 | "#ProcessorCollection.ProcessorCollection"; |
| 1308 | asyncResp->res.jsonValue["Name"] = "Processor Collection"; |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1309 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1310 | asyncResp->res.jsonValue["@odata.id"] = |
| 1311 | std::format("/redfish/v1/Systems/{}/Processors", |
| 1312 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1313 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1314 | collection_util::getCollectionMembers( |
| 1315 | asyncResp, |
| 1316 | boost::urls::format("/redfish/v1/Systems/{}/Processors", |
| 1317 | BMCWEB_REDFISH_SYSTEM_URI_NAME), |
| 1318 | processorInterfaces, "/xyz/openbmc_project/inventory"); |
| 1319 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1320 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1321 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1322 | inline void requestRoutesProcessor(App& app) |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1323 | { |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1324 | /** |
| 1325 | * Functions triggers appropriate requests on DBus |
| 1326 | */ |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1327 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1328 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") |
Nikhil Namjoshi | 71a24ca | 2022-11-11 01:52:32 +0000 | [diff] [blame] | 1329 | .privileges(redfish::privileges::headProcessor) |
| 1330 | .methods(boost::beast::http::verb::head)( |
| 1331 | std::bind_front(handleProcessorHead, std::ref(app))); |
| 1332 | |
| 1333 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1334 | .privileges(redfish::privileges::getProcessor) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1335 | .methods( |
| 1336 | boost::beast::http::verb:: |
| 1337 | get)([&app](const crow::Request& req, |
| 1338 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1339 | const std::string& systemName, |
| 1340 | const std::string& processorId) { |
| 1341 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1342 | { |
| 1343 | return; |
| 1344 | } |
| 1345 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1346 | { |
| 1347 | // Option currently returns no systems. TBD |
| 1348 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1349 | systemName); |
| 1350 | return; |
| 1351 | } |
| 1352 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1353 | { |
| 1354 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1355 | systemName); |
| 1356 | return; |
| 1357 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1358 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1359 | asyncResp->res.addHeader( |
| 1360 | boost::beast::http::field::link, |
| 1361 | "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); |
| 1362 | asyncResp->res.jsonValue["@odata.type"] = |
| 1363 | "#Processor.v1_18_0.Processor"; |
| 1364 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 1365 | "/redfish/v1/Systems/{}/Processors/{}", |
| 1366 | BMCWEB_REDFISH_SYSTEM_URI_NAME, processorId); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1367 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1368 | getProcessorObject( |
| 1369 | asyncResp, processorId, |
| 1370 | std::bind_front(getProcessorData, asyncResp, processorId)); |
| 1371 | }); |
Jonathan Doman | 3cde86f | 2020-12-02 14:50:45 -0800 | [diff] [blame] | 1372 | |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1373 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1374 | .privileges(redfish::privileges::patchProcessor) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1375 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1376 | [&app](const crow::Request& req, |
| 1377 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1378 | const std::string& systemName, |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1379 | const std::string& processorId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1380 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1381 | { |
| 1382 | return; |
| 1383 | } |
| 1384 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1385 | { |
| 1386 | // Option currently returns no systems. TBD |
| 1387 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1388 | systemName); |
| 1389 | return; |
| 1390 | } |
| 1391 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 1392 | { |
| 1393 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1394 | systemName); |
| 1395 | return; |
| 1396 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 1397 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1398 | std::optional<std::string> appliedConfigUri; |
| 1399 | if (!json_util::readJsonPatch( |
| 1400 | req, asyncResp->res, "AppliedOperatingConfig/@odata.id", |
| 1401 | appliedConfigUri)) |
| 1402 | { |
| 1403 | return; |
| 1404 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1405 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1406 | if (appliedConfigUri) |
| 1407 | { |
| 1408 | // Check for 404 and find matching D-Bus object, then run |
| 1409 | // property patch handlers if that all succeeds. |
| 1410 | getProcessorObject( |
| 1411 | asyncResp, processorId, |
| 1412 | std::bind_front(patchAppliedOperatingConfig, asyncResp, |
| 1413 | processorId, *appliedConfigUri)); |
| 1414 | } |
| 1415 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1416 | } |
Gunnar Mills | ac6a444 | 2020-10-14 14:55:29 -0500 | [diff] [blame] | 1417 | |
| 1418 | } // namespace redfish |