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