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