blob: feb223664ebac93df7bcffe92657354b65865ca1 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Gunnar Millsac6a4442020-10-14 14:55:29 -05004#pragma once
5
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "bmcweb_config.h"
7
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "async_resp.hpp"
George Liu98eafce2020-10-03 16:46:04 +080010#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080011#include "dbus_utility.hpp"
Jonathan Doman1e1e5982021-06-11 09:36:17 -070012#include "error_messages.hpp"
Chris Caindfbf7de2023-04-13 16:01:04 -050013#include "generated/enums/processor.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070014#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080015#include "http_request.hpp"
George Liu98eafce2020-10-03 16:46:04 +080016#include "led.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080017#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "query.hpp"
19#include "registries/privilege_registry.hpp"
20#include "utils/collection.hpp"
21#include "utils/dbus_utils.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080022#include "utils/hex_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "utils/json_utils.hpp"
Gunnar Millsac6a4442020-10-14 14:55:29 -050024
Ed Tanousd7857202025-01-28 15:32:26 -080025#include <boost/beast/http/field.hpp>
26#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080027#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070028#include <boost/url/format.hpp>
Jonathan Domandba0c292020-12-02 15:34:13 -080029#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelny351053f2022-07-28 15:44:22 +020030#include <sdbusplus/unpack_properties.hpp>
Gunnar Millsac6a4442020-10-14 14:55:29 -050031
Ed Tanousd7857202025-01-28 15:32:26 -080032#include <algorithm>
George Liu7a1dbc42022-12-07 16:03:22 +080033#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080034#include <cstddef>
35#include <cstdint>
36#include <format>
37#include <functional>
Michael Shenb9d679d2023-02-13 02:29:04 +000038#include <limits>
Ed Tanousd7857202025-01-28 15:32:26 -080039#include <memory>
40#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070041#include <ranges>
Ed Tanous3c569212024-03-06 14:46:18 -080042#include <string>
George Liu7a1dbc42022-12-07 16:03:22 +080043#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080044#include <tuple>
45#include <utility>
46#include <variant>
47#include <vector>
George Liu7a1dbc42022-12-07 16:03:22 +080048
Gunnar Millsac6a4442020-10-14 14:55:29 -050049namespace redfish
50{
51
Jonathan Domanc9514482021-02-24 09:20:51 -080052// Interfaces which imply a D-Bus object represents a Processor
George Liu7a1dbc42022-12-07 16:03:22 +080053constexpr std::array<std::string_view, 2> processorInterfaces = {
Jonathan Domanc9514482021-02-24 09:20:51 -080054 "xyz.openbmc_project.Inventory.Item.Cpu",
55 "xyz.openbmc_project.Inventory.Item.Accelerator"};
Jonathan Doman2bab9832020-12-02 15:27:40 -080056
Sharad Yadav71b82f22021-05-10 15:11:39 +053057/**
58 * @brief Fill out uuid info of a processor by
59 * requesting data from the given D-Bus object.
60 *
Ed Tanousac106bf2023-06-07 09:24:59 -070061 * @param[in,out] asyncResp Async HTTP response.
Sharad Yadav71b82f22021-05-10 15:11:39 +053062 * @param[in] service D-Bus service to query.
63 * @param[in] objPath D-Bus object to query.
64 */
Ed Tanousac106bf2023-06-07 09:24:59 -070065inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Sharad Yadav71b82f22021-05-10 15:11:39 +053066 const std::string& service,
67 const std::string& objPath)
68{
Ed Tanous62598e32023-07-17 17:06:25 -070069 BMCWEB_LOG_DEBUG("Get Processor UUID");
Ed Tanousdeae6a72024-11-11 21:58:57 -080070 dbus::utility::getProperty<std::string>(
71 service, objPath, "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanousac106bf2023-06-07 09:24:59 -070072 [objPath, asyncResp{std::move(asyncResp)}](
73 const boost::system::error_code& ec, const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040074 if (ec)
75 {
76 BMCWEB_LOG_DEBUG("DBUS response error");
77 messages::internalError(asyncResp->res);
78 return;
79 }
80 asyncResp->res.jsonValue["UUID"] = property;
81 });
Sharad Yadav71b82f22021-05-10 15:11:39 +053082}
83
Ed Tanous711ac7a2021-12-20 09:34:41 -080084inline void getCpuDataByInterface(
Ed Tanousac106bf2023-06-07 09:24:59 -070085 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Michael Shen80f79a42023-08-24 13:41:53 +000086 const dbus::utility::DBusInterfacesMap& cpuInterfacesProperties)
Gunnar Millsac6a4442020-10-14 14:55:29 -050087{
Ed Tanous62598e32023-07-17 17:06:25 -070088 BMCWEB_LOG_DEBUG("Get CPU resources by interface.");
Gunnar Millsac6a4442020-10-14 14:55:29 -050089
Chicago Duana1649ec2021-03-30 16:54:58 +080090 // Set the default value of state
Ed Tanous539d8c62024-06-19 14:38:27 -070091 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
92 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Gunnar Millsac6a4442020-10-14 14:55:29 -050093
94 for (const auto& interface : cpuInterfacesProperties)
95 {
96 for (const auto& property : interface.second)
97 {
Chicago Duana1649ec2021-03-30 16:54:58 +080098 if (property.first == "Present")
Gunnar Millsac6a4442020-10-14 14:55:29 -050099 {
Chicago Duana1649ec2021-03-30 16:54:58 +0800100 const bool* cpuPresent = std::get_if<bool>(&property.second);
101 if (cpuPresent == nullptr)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500102 {
103 // Important property not in desired type
Ed Tanousac106bf2023-06-07 09:24:59 -0700104 messages::internalError(asyncResp->res);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500105 return;
106 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800107 if (!*cpuPresent)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500108 {
Chicago Duana1649ec2021-03-30 16:54:58 +0800109 // Slot is not populated
Ed Tanous539d8c62024-06-19 14:38:27 -0700110 asyncResp->res.jsonValue["Status"]["State"] =
111 resource::State::Absent;
Chicago Duana1649ec2021-03-30 16:54:58 +0800112 }
113 }
114 else if (property.first == "Functional")
115 {
116 const bool* cpuFunctional = std::get_if<bool>(&property.second);
117 if (cpuFunctional == nullptr)
118 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700119 messages::internalError(asyncResp->res);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500120 return;
121 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800122 if (!*cpuFunctional)
Chicago Duana1649ec2021-03-30 16:54:58 +0800123 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700124 asyncResp->res.jsonValue["Status"]["Health"] =
125 resource::Health::Critical;
Chicago Duana1649ec2021-03-30 16:54:58 +0800126 }
127 }
128 else if (property.first == "CoreCount")
129 {
130 const uint16_t* coresCount =
131 std::get_if<uint16_t>(&property.second);
132 if (coresCount == nullptr)
133 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700134 messages::internalError(asyncResp->res);
Chicago Duana1649ec2021-03-30 16:54:58 +0800135 return;
136 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700137 asyncResp->res.jsonValue["TotalCores"] = *coresCount;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500138 }
Jonathan Domandc3fa662020-10-26 23:10:24 -0700139 else if (property.first == "MaxSpeedInMhz")
140 {
141 const uint32_t* value = std::get_if<uint32_t>(&property.second);
142 if (value != nullptr)
143 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700144 asyncResp->res.jsonValue["MaxSpeedMHz"] = *value;
Jonathan Domandc3fa662020-10-26 23:10:24 -0700145 }
146 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500147 else if (property.first == "Socket")
148 {
149 const std::string* value =
150 std::get_if<std::string>(&property.second);
151 if (value != nullptr)
152 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700153 asyncResp->res.jsonValue["Socket"] = *value;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500154 }
155 }
156 else if (property.first == "ThreadCount")
157 {
Jonathan Domandc3fa662020-10-26 23:10:24 -0700158 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500159 if (value != nullptr)
160 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700161 asyncResp->res.jsonValue["TotalThreads"] = *value;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500162 }
163 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700164 else if (property.first == "EffectiveFamily")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500165 {
Brandon Kim1930fbd2021-09-14 17:52:51 -0700166 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Brad Bishop6169de22022-09-14 13:08:32 -0400167 if (value != nullptr && *value != 2)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500168 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700169 asyncResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800170 "0x" + intToHexString(*value, 4);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500171 }
172 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700173 else if (property.first == "EffectiveModel")
174 {
175 const uint16_t* value = std::get_if<uint16_t>(&property.second);
176 if (value == nullptr)
177 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700178 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700179 return;
180 }
Brad Bishop6169de22022-09-14 13:08:32 -0400181 if (*value != 0)
182 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700183 asyncResp->res.jsonValue["ProcessorId"]["EffectiveModel"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400184 "0x" + intToHexString(*value, 4);
185 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700186 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500187 else if (property.first == "Id")
188 {
189 const uint64_t* value = std::get_if<uint64_t>(&property.second);
190 if (value != nullptr && *value != 0)
191 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700192 asyncResp->res
Gunnar Millsac6a4442020-10-14 14:55:29 -0500193 .jsonValue["ProcessorId"]["IdentificationRegisters"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800194 "0x" + intToHexString(*value, 16);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500195 }
196 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700197 else if (property.first == "Microcode")
198 {
199 const uint32_t* value = std::get_if<uint32_t>(&property.second);
200 if (value == nullptr)
201 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700202 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700203 return;
204 }
Brad Bishop6169de22022-09-14 13:08:32 -0400205 if (*value != 0)
206 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700207 asyncResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400208 "0x" + intToHexString(*value, 8);
209 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700210 }
211 else if (property.first == "Step")
212 {
213 const uint16_t* value = std::get_if<uint16_t>(&property.second);
214 if (value == nullptr)
215 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700216 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700217 return;
218 }
Michael Shenb9d679d2023-02-13 02:29:04 +0000219 if (*value != std::numeric_limits<uint16_t>::max())
Brad Bishop6169de22022-09-14 13:08:32 -0400220 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700221 asyncResp->res.jsonValue["ProcessorId"]["Step"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400222 "0x" + intToHexString(*value, 4);
223 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700224 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500225 }
226 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500227}
228
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400229inline void getCpuDataByService(
230 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& cpuId,
231 const std::string& service, const std::string& objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500232{
Ed Tanous62598e32023-07-17 17:06:25 -0700233 BMCWEB_LOG_DEBUG("Get available system cpu resources by service.");
Gunnar Millsac6a4442020-10-14 14:55:29 -0500234
George Liu5eb468d2023-06-20 17:03:24 +0800235 sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
236 dbus::utility::getManagedObjects(
237 service, path,
Ed Tanousac106bf2023-06-07 09:24:59 -0700238 [cpuId, service, objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800239 const boost::system::error_code& ec,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500240 const dbus::utility::ManagedObjectType& dbusData) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400241 if (ec)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500242 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400243 BMCWEB_LOG_DEBUG("DBUS response error");
244 messages::internalError(asyncResp->res);
245 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700246 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400247 asyncResp->res.jsonValue["Id"] = cpuId;
248 asyncResp->res.jsonValue["Name"] = "Processor";
249 asyncResp->res.jsonValue["ProcessorType"] =
250 processor::ProcessorType::CPU;
251
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400252 for (const auto& object : dbusData)
Ed Tanous002d39b2022-05-31 08:59:27 -0700253 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400254 if (object.first.str == objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500255 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400256 getCpuDataByInterface(asyncResp, object.second);
257 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400258 }
259 return;
260 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500261}
262
Chris Caindfbf7de2023-04-13 16:01:04 -0500263/**
264 * @brief Translates throttle cause DBUS property to redfish.
265 *
266 * @param[in] dbusSource The throttle cause from DBUS
267 *
268 * @return Returns as a string, the throttle cause in Redfish terms. If
269 * translation cannot be done, returns "Unknown" throttle reason.
270 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500271inline processor::ThrottleCause dbusToRfThrottleCause(
272 const std::string& dbusSource)
Chris Caindfbf7de2023-04-13 16:01:04 -0500273{
274 if (dbusSource ==
275 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ClockLimit")
276 {
277 return processor::ThrottleCause::ClockLimit;
278 }
279 if (dbusSource ==
280 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ManagementDetectedFault")
281 {
282 return processor::ThrottleCause::ManagementDetectedFault;
283 }
284 if (dbusSource ==
285 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.PowerLimit")
286 {
287 return processor::ThrottleCause::PowerLimit;
288 }
289 if (dbusSource ==
290 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ThermalLimit")
291 {
292 return processor::ThrottleCause::ThermalLimit;
293 }
294 if (dbusSource ==
295 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.Unknown")
296 {
297 return processor::ThrottleCause::Unknown;
298 }
299 return processor::ThrottleCause::Invalid;
300}
301
Patrick Williams504af5a2025-02-03 14:29:03 -0500302inline void readThrottleProperties(
303 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
304 const boost::system::error_code& ec,
305 const dbus::utility::DBusPropertiesMap& properties)
Chris Caindfbf7de2023-04-13 16:01:04 -0500306{
307 if (ec)
308 {
Ed Tanous62598e32023-07-17 17:06:25 -0700309 BMCWEB_LOG_ERROR("Processor Throttle getAllProperties error {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -0700310 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500311 return;
312 }
313
314 const bool* status = nullptr;
315 const std::vector<std::string>* causes = nullptr;
316
317 if (!sdbusplus::unpackPropertiesNoThrow(dbus_utils::UnpackErrorPrinter(),
318 properties, "Throttled", status,
319 "ThrottleCauses", causes))
320 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700321 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500322 return;
323 }
324
Ed Tanousac106bf2023-06-07 09:24:59 -0700325 asyncResp->res.jsonValue["Throttled"] = *status;
Chris Caindfbf7de2023-04-13 16:01:04 -0500326 nlohmann::json::array_t rCauses;
327 for (const std::string& cause : *causes)
328 {
329 processor::ThrottleCause rfCause = dbusToRfThrottleCause(cause);
330 if (rfCause == processor::ThrottleCause::Invalid)
331 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700332 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500333 return;
334 }
335
336 rCauses.emplace_back(rfCause);
337 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700338 asyncResp->res.jsonValue["ThrottleCauses"] = std::move(rCauses);
Chris Caindfbf7de2023-04-13 16:01:04 -0500339}
340
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400341inline void getThrottleProperties(
342 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
343 const std::string& service, const std::string& objectPath)
Chris Caindfbf7de2023-04-13 16:01:04 -0500344{
Ed Tanous62598e32023-07-17 17:06:25 -0700345 BMCWEB_LOG_DEBUG("Get processor throttle resources");
Chris Caindfbf7de2023-04-13 16:01:04 -0500346
Ed Tanousdeae6a72024-11-11 21:58:57 -0800347 dbus::utility::getAllProperties(
348 service, objectPath, "xyz.openbmc_project.Control.Power.Throttle",
Ed Tanousac106bf2023-06-07 09:24:59 -0700349 [asyncResp](const boost::system::error_code& ec,
350 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400351 readThrottleProperties(asyncResp, ec, properties);
352 });
Chris Caindfbf7de2023-04-13 16:01:04 -0500353}
354
Ed Tanousac106bf2023-06-07 09:24:59 -0700355inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500356 const std::string& service,
357 const std::string& objPath)
358{
Ed Tanous62598e32023-07-17 17:06:25 -0700359 BMCWEB_LOG_DEBUG("Get Cpu Asset Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800360 dbus::utility::getAllProperties(
361 service, objPath, "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanousac106bf2023-06-07 09:24:59 -0700362 [objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800363 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200364 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400365 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700366 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400367 BMCWEB_LOG_DEBUG("DBUS response error");
368 messages::internalError(asyncResp->res);
369 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700370 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400371
372 const std::string* serialNumber = nullptr;
373 const std::string* model = nullptr;
374 const std::string* manufacturer = nullptr;
375 const std::string* partNumber = nullptr;
376 const std::string* sparePartNumber = nullptr;
377
378 const bool success = sdbusplus::unpackPropertiesNoThrow(
379 dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber",
380 serialNumber, "Model", model, "Manufacturer", manufacturer,
381 "PartNumber", partNumber, "SparePartNumber", sparePartNumber);
382
383 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700384 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400385 messages::internalError(asyncResp->res);
386 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700387 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200388
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400389 if (serialNumber != nullptr && !serialNumber->empty())
390 {
391 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
392 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200393
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400394 if ((model != nullptr) && !model->empty())
395 {
396 asyncResp->res.jsonValue["Model"] = *model;
397 }
398
399 if (manufacturer != nullptr)
400 {
401 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
402
403 // Otherwise would be unexpected.
404 if (manufacturer->find("Intel") != std::string::npos)
405 {
406 asyncResp->res.jsonValue["ProcessorArchitecture"] = "x86";
407 asyncResp->res.jsonValue["InstructionSet"] = "x86-64";
408 }
409 else if (manufacturer->find("IBM") != std::string::npos)
410 {
411 asyncResp->res.jsonValue["ProcessorArchitecture"] = "Power";
412 asyncResp->res.jsonValue["InstructionSet"] = "PowerISA";
413 }
Rebecca Cran4d0c0c42025-08-11 14:33:12 -0600414 else if (manufacturer->find("Ampere") != std::string::npos)
415 {
416 asyncResp->res.jsonValue["ProcessorArchitecture"] = "ARM";
417 asyncResp->res.jsonValue["InstructionSet"] = "ARM-A64";
418 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400419 }
420
421 if (partNumber != nullptr)
422 {
423 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
424 }
425
426 if (sparePartNumber != nullptr && !sparePartNumber->empty())
427 {
428 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
429 }
430 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500431}
432
Ed Tanousac106bf2023-06-07 09:24:59 -0700433inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500434 const std::string& service,
435 const std::string& objPath)
436{
Ed Tanous62598e32023-07-17 17:06:25 -0700437 BMCWEB_LOG_DEBUG("Get Cpu Revision Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800438 dbus::utility::getAllProperties(
439 service, objPath, "xyz.openbmc_project.Inventory.Decorator.Revision",
Ed Tanousac106bf2023-06-07 09:24:59 -0700440 [objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800441 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200442 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400443 if (ec)
444 {
445 BMCWEB_LOG_DEBUG("DBUS response error");
446 messages::internalError(asyncResp->res);
447 return;
448 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500449
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400450 const std::string* version = nullptr;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200451
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400452 const bool success = sdbusplus::unpackPropertiesNoThrow(
453 dbus_utils::UnpackErrorPrinter(), properties, "Version",
454 version);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200455
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400456 if (!success)
457 {
458 messages::internalError(asyncResp->res);
459 return;
460 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200461
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400462 if (version != nullptr)
463 {
464 asyncResp->res.jsonValue["Version"] = *version;
465 }
466 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500467}
468
zhanghch058d1b46d2021-04-01 11:18:24 +0800469inline void getAcceleratorDataByService(
Ed Tanousac106bf2023-06-07 09:24:59 -0700470 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& acclrtrId,
zhanghch058d1b46d2021-04-01 11:18:24 +0800471 const std::string& service, const std::string& objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500472{
Ed Tanous62598e32023-07-17 17:06:25 -0700473 BMCWEB_LOG_DEBUG("Get available system Accelerator resources by service.");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800474 dbus::utility::getAllProperties(
475 service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700476 [acclrtrId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800477 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200478 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400479 if (ec)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500480 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400481 BMCWEB_LOG_DEBUG("DBUS response error");
482 messages::internalError(asyncResp->res);
483 return;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500484 }
485
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400486 const bool* functional = nullptr;
487 const bool* present = nullptr;
488
489 const bool success = sdbusplus::unpackPropertiesNoThrow(
490 dbus_utils::UnpackErrorPrinter(), properties, "Functional",
491 functional, "Present", present);
492
493 if (!success)
494 {
495 messages::internalError(asyncResp->res);
496 return;
497 }
498
499 std::string state = "Enabled";
500 std::string health = "OK";
501
502 if (present != nullptr && !*present)
503 {
504 state = "Absent";
505 }
506
507 if (functional != nullptr && !*functional)
508 {
509 if (state == "Enabled")
510 {
511 health = "Critical";
512 }
513 }
514
515 asyncResp->res.jsonValue["Id"] = acclrtrId;
516 asyncResp->res.jsonValue["Name"] = "Processor";
517 asyncResp->res.jsonValue["Status"]["State"] = state;
518 asyncResp->res.jsonValue["Status"]["Health"] = health;
519 asyncResp->res.jsonValue["ProcessorType"] =
520 processor::ProcessorType::Accelerator;
521 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500522}
523
Jonathan Domandba0c292020-12-02 15:34:13 -0800524// OperatingConfig D-Bus Types
525using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>;
526using BaseSpeedPrioritySettingsProperty =
527 std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>;
528// uint32_t and size_t may or may not be the same type, requiring a dedup'd
529// variant
Jonathan Domandba0c292020-12-02 15:34:13 -0800530
531/**
532 * Fill out the HighSpeedCoreIDs in a Processor resource from the given
533 * OperatingConfig D-Bus property.
534 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700535 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800536 * @param[in] baseSpeedSettings Full list of base speed priority groups,
537 * to use to determine the list of high
538 * speed cores.
539 */
540inline void highSpeedCoreIdsHandler(
Ed Tanousac106bf2023-06-07 09:24:59 -0700541 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Domandba0c292020-12-02 15:34:13 -0800542 const BaseSpeedPrioritySettingsProperty& baseSpeedSettings)
543{
544 // The D-Bus property does not indicate which bucket is the "high
545 // priority" group, so let's discern that by looking for the one with
546 // highest base frequency.
547 auto highPriorityGroup = baseSpeedSettings.cend();
548 uint32_t highestBaseSpeed = 0;
549 for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend();
550 ++it)
551 {
552 const uint32_t baseFreq = std::get<uint32_t>(*it);
553 if (baseFreq > highestBaseSpeed)
554 {
555 highestBaseSpeed = baseFreq;
556 highPriorityGroup = it;
557 }
558 }
559
Ed Tanousac106bf2023-06-07 09:24:59 -0700560 nlohmann::json& jsonCoreIds = asyncResp->res.jsonValue["HighSpeedCoreIDs"];
Jonathan Domandba0c292020-12-02 15:34:13 -0800561 jsonCoreIds = nlohmann::json::array();
562
563 // There may not be any entries in the D-Bus property, so only populate
564 // if there was actually something there.
565 if (highPriorityGroup != baseSpeedSettings.cend())
566 {
567 jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup);
568 }
569}
570
571/**
572 * Fill out OperatingConfig related items in a Processor resource by requesting
573 * data from the given D-Bus object.
574 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700575 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800576 * @param[in] cpuId CPU D-Bus name.
577 * @param[in] service D-Bus service to query.
578 * @param[in] objPath D-Bus object to query.
579 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500580inline void getCpuConfigData(
581 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
582 const std::string& cpuId, const std::string& service,
583 const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800584{
Ed Tanous62598e32023-07-17 17:06:25 -0700585 BMCWEB_LOG_INFO("Getting CPU operating configs for {}", cpuId);
Jonathan Domandba0c292020-12-02 15:34:13 -0800586
587 // First, GetAll CurrentOperatingConfig properties on the object
Ed Tanousdeae6a72024-11-11 21:58:57 -0800588 dbus::utility::getAllProperties(
589 service, objPath,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200590 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700591 [asyncResp, cpuId,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800592 service](const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200593 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400594 if (ec)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200595 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400596 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
Ed Tanousac106bf2023-06-07 09:24:59 -0700597 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200598 return;
599 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200600
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400601 nlohmann::json& json = asyncResp->res.jsonValue;
602
603 const sdbusplus::message::object_path* appliedConfig = nullptr;
604 const bool* baseSpeedPriorityEnabled = nullptr;
605
606 const bool success = sdbusplus::unpackPropertiesNoThrow(
607 dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig",
608 appliedConfig, "BaseSpeedPriorityEnabled",
609 baseSpeedPriorityEnabled);
610
611 if (!success)
612 {
613 messages::internalError(asyncResp->res);
614 return;
615 }
616
617 if (appliedConfig != nullptr)
618 {
619 const std::string& dbusPath = appliedConfig->str;
620 nlohmann::json::object_t operatingConfig;
621 operatingConfig["@odata.id"] = boost::urls::format(
622 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
623 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId);
624 json["OperatingConfigs"] = std::move(operatingConfig);
625
626 // Reuse the D-Bus config object name for the Redfish
627 // URI
628 size_t baseNamePos = dbusPath.rfind('/');
629 if (baseNamePos == std::string::npos ||
630 baseNamePos == (dbusPath.size() - 1))
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200631 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400632 // If the AppliedConfig was somehow not a valid path,
633 // skip adding any more properties, since everything
634 // else is tied to this applied config.
Ed Tanousac106bf2023-06-07 09:24:59 -0700635 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200636 return;
637 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400638 nlohmann::json::object_t appliedOperatingConfig;
639 appliedOperatingConfig["@odata.id"] = boost::urls::format(
640 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
641 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId,
642 dbusPath.substr(baseNamePos + 1));
643 json["AppliedOperatingConfig"] =
644 std::move(appliedOperatingConfig);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200645
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400646 // Once we found the current applied config, queue another
647 // request to read the base freq core ids out of that
648 // config.
Ed Tanousdeae6a72024-11-11 21:58:57 -0800649 dbus::utility::getProperty<BaseSpeedPrioritySettingsProperty>(
650 service, dbusPath,
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400651 "xyz.openbmc_project.Inventory.Item.Cpu."
652 "OperatingConfig",
653 "BaseSpeedPrioritySettings",
654 [asyncResp](const boost::system::error_code& ec2,
655 const BaseSpeedPrioritySettingsProperty&
656 baseSpeedList) {
657 if (ec2)
658 {
659 BMCWEB_LOG_WARNING("D-Bus Property Get error: {}",
660 ec2);
661 messages::internalError(asyncResp->res);
662 return;
663 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200664
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400665 highSpeedCoreIdsHandler(asyncResp, baseSpeedList);
666 });
667 }
668
669 if (baseSpeedPriorityEnabled != nullptr)
670 {
671 json["BaseSpeedPriorityState"] =
672 *baseSpeedPriorityEnabled ? "Enabled" : "Disabled";
673 }
674 });
Jonathan Domandba0c292020-12-02 15:34:13 -0800675}
676
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600677/**
678 * @brief Fill out location info of a processor by
679 * requesting data from the given D-Bus object.
680 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700681 * @param[in,out] asyncResp Async HTTP response.
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600682 * @param[in] service D-Bus service to query.
683 * @param[in] objPath D-Bus object to query.
684 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700685inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600686 const std::string& service,
687 const std::string& objPath)
688{
Ed Tanous62598e32023-07-17 17:06:25 -0700689 BMCWEB_LOG_DEBUG("Get Cpu Location Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800690 dbus::utility::getProperty<std::string>(
691 service, objPath,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700692 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700693 [objPath, asyncResp{std::move(asyncResp)}](
694 const boost::system::error_code& ec, const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400695 if (ec)
696 {
697 BMCWEB_LOG_DEBUG("DBUS response error");
698 messages::internalError(asyncResp->res);
699 return;
700 }
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600701
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400702 asyncResp->res
703 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
704 property;
705 });
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600706}
707
Jonathan Domanc9514482021-02-24 09:20:51 -0800708/**
Jonathan Doman49e429c2021-03-03 13:11:44 -0800709 * Populate the unique identifier in a Processor resource by requesting data
710 * from the given D-Bus object.
711 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700712 * @param[in,out] asyncResp Async HTTP response.
Jonathan Doman49e429c2021-03-03 13:11:44 -0800713 * @param[in] service D-Bus service to query.
714 * @param[in] objPath D-Bus object to query.
715 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700716inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Doman49e429c2021-03-03 13:11:44 -0800717 const std::string& service,
718 const std::string& objectPath)
719{
Ed Tanous62598e32023-07-17 17:06:25 -0700720 BMCWEB_LOG_DEBUG("Get CPU UniqueIdentifier");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800721 dbus::utility::getProperty<std::string>(
722 service, objectPath,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700723 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
724 "UniqueIdentifier",
Ed Tanousac106bf2023-06-07 09:24:59 -0700725 [asyncResp](const boost::system::error_code& ec,
726 const std::string& id) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400727 if (ec)
728 {
729 BMCWEB_LOG_ERROR("Failed to read cpu unique id: {}", ec);
730 messages::internalError(asyncResp->res);
731 return;
732 }
733 asyncResp->res
734 .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id;
735 });
Jonathan Doman49e429c2021-03-03 13:11:44 -0800736}
737
George Liu98eafce2020-10-03 16:46:04 +0800738inline void handleProcessorSubtree(
739 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
740 const std::string& processorId,
741 const std::function<
742 void(const std::string& objectPath,
743 const dbus::utility::MapperServiceMap& serviceMap)>& callback,
744 const boost::system::error_code& ec,
745 const dbus::utility::MapperGetSubTreeResponse& subtree)
746{
747 if (ec)
748 {
749 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
750 messages::internalError(asyncResp->res);
751 return;
752 }
753 for (const auto& [objectPath, serviceMap] : subtree)
754 {
755 // Ignore any objects which don't end with our desired cpu name
756 sdbusplus::message::object_path path(objectPath);
757 if (path.filename() == processorId)
758 {
759 // Filter out objects that don't have the CPU-specific
760 // interfaces to make sure we can return 404 on non-CPUs
761 // (e.g. /redfish/../Processors/dimm0)
762 for (const auto& [serviceName, interfaceList] : serviceMap)
763 {
764 if (std::ranges::find_first_of(interfaceList,
765 processorInterfaces) !=
766 interfaceList.end())
767 {
768 // Process the first object which matches cpu name and
769 // required interfaces, and potentially ignore any other
770 // matching objects. Assume all interfaces we want to
771 // process must be on the same object path.
772
773 callback(objectPath, serviceMap);
774 return;
775 }
776 }
777 }
778 }
779 messages::resourceNotFound(asyncResp->res, "Processor", processorId);
780}
781
Jonathan Doman49e429c2021-03-03 13:11:44 -0800782/**
Jonathan Domanc9514482021-02-24 09:20:51 -0800783 * Find the D-Bus object representing the requested Processor, and call the
784 * handler with the results. If matching object is not found, add 404 error to
785 * response and don't call the handler.
786 *
George Liu98eafce2020-10-03 16:46:04 +0800787 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domanc9514482021-02-24 09:20:51 -0800788 * @param[in] processorId Redfish Processor Id.
George Liu98eafce2020-10-03 16:46:04 +0800789 * @param[in] callback Callback to continue processing request upon
Jonathan Domanc9514482021-02-24 09:20:51 -0800790 * successfully finding object.
791 */
George Liu98eafce2020-10-03 16:46:04 +0800792inline void getProcessorObject(
793 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
794 const std::string& processorId,
795 std::function<void(const std::string& objectPath,
796 const dbus::utility::MapperServiceMap& serviceMap)>&&
797 callback)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500798{
Ed Tanous62598e32023-07-17 17:06:25 -0700799 BMCWEB_LOG_DEBUG("Get available system processor resources.");
Gunnar Millsac6a4442020-10-14 14:55:29 -0500800
Jonathan Domanc9514482021-02-24 09:20:51 -0800801 // GetSubTree on all interfaces which provide info about a Processor
Chris Caindfbf7de2023-04-13 16:01:04 -0500802 constexpr std::array<std::string_view, 9> interfaces = {
George Liue99073f2022-12-09 11:06:16 +0800803 "xyz.openbmc_project.Common.UUID",
804 "xyz.openbmc_project.Inventory.Decorator.Asset",
805 "xyz.openbmc_project.Inventory.Decorator.Revision",
806 "xyz.openbmc_project.Inventory.Item.Cpu",
807 "xyz.openbmc_project.Inventory.Decorator.LocationCode",
808 "xyz.openbmc_project.Inventory.Item.Accelerator",
809 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Chris Caindfbf7de2023-04-13 16:01:04 -0500810 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
811 "xyz.openbmc_project.Control.Power.Throttle"};
George Liue99073f2022-12-09 11:06:16 +0800812 dbus::utility::getSubTree(
813 "/xyz/openbmc_project/inventory", 0, interfaces,
George Liu98eafce2020-10-03 16:46:04 +0800814 [asyncResp, processorId, callback{std::move(callback)}](
George Liue99073f2022-12-09 11:06:16 +0800815 const boost::system::error_code& ec,
816 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liu98eafce2020-10-03 16:46:04 +0800817 handleProcessorSubtree(asyncResp, processorId, callback, ec,
818 subtree);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400819 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500820}
821
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400822inline void getProcessorData(
823 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
824 const std::string& processorId, const std::string& objectPath,
825 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Domanc9514482021-02-24 09:20:51 -0800826{
George Liu98eafce2020-10-03 16:46:04 +0800827 asyncResp->res.addHeader(
828 boost::beast::http::field::link,
829 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
830 asyncResp->res.jsonValue["@odata.type"] = "#Processor.v1_18_0.Processor";
831 asyncResp->res.jsonValue["@odata.id"] =
832 boost::urls::format("/redfish/v1/Systems/{}/Processors/{}",
833 BMCWEB_REDFISH_SYSTEM_URI_NAME, processorId);
834
Jonathan Domanc9514482021-02-24 09:20:51 -0800835 for (const auto& [serviceName, interfaceList] : serviceMap)
836 {
837 for (const auto& interface : interfaceList)
838 {
839 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
840 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700841 getCpuAssetData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800842 }
George Liu0fda0f12021-11-16 10:06:17 +0800843 else if (interface ==
844 "xyz.openbmc_project.Inventory.Decorator.Revision")
Jonathan Domanc9514482021-02-24 09:20:51 -0800845 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700846 getCpuRevisionData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800847 }
848 else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu")
849 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700850 getCpuDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800851 objectPath);
852 }
George Liu0fda0f12021-11-16 10:06:17 +0800853 else if (interface ==
854 "xyz.openbmc_project.Inventory.Item.Accelerator")
Jonathan Domanc9514482021-02-24 09:20:51 -0800855 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700856 getAcceleratorDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800857 objectPath);
858 }
George Liu0fda0f12021-11-16 10:06:17 +0800859 else if (
860 interface ==
861 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig")
Jonathan Domanc9514482021-02-24 09:20:51 -0800862 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700863 getCpuConfigData(asyncResp, processorId, serviceName,
864 objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800865 }
George Liu0fda0f12021-11-16 10:06:17 +0800866 else if (interface ==
867 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
Jonathan Domanc9514482021-02-24 09:20:51 -0800868 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700869 getCpuLocationCode(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800870 }
Sharad Yadav71b82f22021-05-10 15:11:39 +0530871 else if (interface == "xyz.openbmc_project.Common.UUID")
872 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700873 getProcessorUUID(asyncResp, serviceName, objectPath);
Sharad Yadav71b82f22021-05-10 15:11:39 +0530874 }
George Liu0fda0f12021-11-16 10:06:17 +0800875 else if (interface ==
876 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier")
Jonathan Doman49e429c2021-03-03 13:11:44 -0800877 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700878 getCpuUniqueId(asyncResp, serviceName, objectPath);
Jonathan Doman49e429c2021-03-03 13:11:44 -0800879 }
Chris Caindfbf7de2023-04-13 16:01:04 -0500880 else if (interface == "xyz.openbmc_project.Control.Power.Throttle")
881 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700882 getThrottleProperties(asyncResp, serviceName, objectPath);
Chris Caindfbf7de2023-04-13 16:01:04 -0500883 }
George Liu98eafce2020-10-03 16:46:04 +0800884 else if (interface == "xyz.openbmc_project.Association.Definitions")
885 {
886 getLocationIndicatorActive(asyncResp, objectPath);
887 }
Jonathan Domanc9514482021-02-24 09:20:51 -0800888 }
889 }
890}
891
Jonathan Domandba0c292020-12-02 15:34:13 -0800892/**
893 * Request all the properties for the given D-Bus object and fill out the
894 * related entries in the Redfish OperatingConfig response.
895 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700896 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800897 * @param[in] service D-Bus service name to query.
898 * @param[in] objPath D-Bus object to query.
899 */
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400900inline void getOperatingConfigData(
901 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
902 const std::string& service, const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800903{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800904 dbus::utility::getAllProperties(
905 service, objPath,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200906 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700907 [asyncResp](const boost::system::error_code& ec,
908 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400909 if (ec)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200910 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400911 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
912 messages::internalError(asyncResp->res);
913 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700914 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200915
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400916 const size_t* availableCoreCount = nullptr;
917 const uint32_t* baseSpeed = nullptr;
918 const uint32_t* maxJunctionTemperature = nullptr;
919 const uint32_t* maxSpeed = nullptr;
920 const uint32_t* powerLimit = nullptr;
921 const TurboProfileProperty* turboProfile = nullptr;
922 const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings =
923 nullptr;
924
925 const bool success = sdbusplus::unpackPropertiesNoThrow(
926 dbus_utils::UnpackErrorPrinter(), properties,
927 "AvailableCoreCount", availableCoreCount, "BaseSpeed",
928 baseSpeed, "MaxJunctionTemperature", maxJunctionTemperature,
929 "MaxSpeed", maxSpeed, "PowerLimit", powerLimit, "TurboProfile",
930 turboProfile, "BaseSpeedPrioritySettings",
931 baseSpeedPrioritySettings);
932
933 if (!success)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200934 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400935 messages::internalError(asyncResp->res);
936 return;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200937 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400938
939 nlohmann::json& json = asyncResp->res.jsonValue;
940
941 if (availableCoreCount != nullptr)
942 {
943 json["TotalAvailableCoreCount"] = *availableCoreCount;
944 }
945
946 if (baseSpeed != nullptr)
947 {
948 json["BaseSpeedMHz"] = *baseSpeed;
949 }
950
951 if (maxJunctionTemperature != nullptr)
952 {
953 json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature;
954 }
955
956 if (maxSpeed != nullptr)
957 {
958 json["MaxSpeedMHz"] = *maxSpeed;
959 }
960
961 if (powerLimit != nullptr)
962 {
963 json["TDPWatts"] = *powerLimit;
964 }
965
966 if (turboProfile != nullptr)
967 {
968 nlohmann::json& turboArray = json["TurboProfile"];
969 turboArray = nlohmann::json::array();
970 for (const auto& [turboSpeed, coreCount] : *turboProfile)
971 {
972 nlohmann::json::object_t turbo;
973 turbo["ActiveCoreCount"] = coreCount;
974 turbo["MaxSpeedMHz"] = turboSpeed;
975 turboArray.emplace_back(std::move(turbo));
976 }
977 }
978
979 if (baseSpeedPrioritySettings != nullptr)
980 {
981 nlohmann::json& baseSpeedArray =
982 json["BaseSpeedPrioritySettings"];
983 baseSpeedArray = nlohmann::json::array();
984 for (const auto& [baseSpeedMhz, coreList] :
985 *baseSpeedPrioritySettings)
986 {
987 nlohmann::json::object_t speed;
988 speed["CoreCount"] = coreList.size();
989 speed["CoreIDs"] = coreList;
990 speed["BaseSpeedMHz"] = baseSpeedMhz;
991 baseSpeedArray.emplace_back(std::move(speed));
992 }
993 }
994 });
Jonathan Domandba0c292020-12-02 15:34:13 -0800995}
996
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800997/**
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800998 * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic
999 * validation of the input data, and then set the D-Bus property.
1000 *
1001 * @param[in,out] resp Async HTTP response.
1002 * @param[in] processorId Processor's Id.
1003 * @param[in] appliedConfigUri New property value to apply.
1004 * @param[in] cpuObjectPath Path of CPU object to modify.
1005 * @param[in] serviceMap Service map for CPU object.
1006 */
1007inline void patchAppliedOperatingConfig(
1008 const std::shared_ptr<bmcweb::AsyncResp>& resp,
1009 const std::string& processorId, const std::string& appliedConfigUri,
Shantappa Teekappanavar5df6eda2022-01-18 12:29:28 -06001010 const std::string& cpuObjectPath,
1011 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001012{
1013 // Check that the property even exists by checking for the interface
1014 const std::string* controlService = nullptr;
1015 for (const auto& [serviceName, interfaceList] : serviceMap)
1016 {
Ed Tanous3544d2a2023-08-06 18:12:20 -07001017 if (std::ranges::find(interfaceList,
1018 "xyz.openbmc_project.Control.Processor."
1019 "CurrentOperatingConfig") != interfaceList.end())
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001020 {
1021 controlService = &serviceName;
1022 break;
1023 }
1024 }
1025
1026 if (controlService == nullptr)
1027 {
1028 messages::internalError(resp->res);
1029 return;
1030 }
1031
1032 // Check that the config URI is a child of the cpu URI being patched.
Ed Tanous253f11b2024-05-16 09:38:31 -07001033 std::string expectedPrefix(std::format("/redfish/v1/Systems/{}/Processors/",
1034 BMCWEB_REDFISH_SYSTEM_URI_NAME));
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001035 expectedPrefix += processorId;
1036 expectedPrefix += "/OperatingConfigs/";
Ed Tanous11ba3972022-07-11 09:50:41 -07001037 if (!appliedConfigUri.starts_with(expectedPrefix) ||
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001038 expectedPrefix.size() == appliedConfigUri.size())
1039 {
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001040 messages::propertyValueIncorrect(resp->res, "AppliedOperatingConfig",
1041 appliedConfigUri);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001042 return;
1043 }
1044
1045 // Generate the D-Bus path of the OperatingConfig object, by assuming it's a
1046 // direct child of the CPU object.
1047 // Strip the expectedPrefix from the config URI to get the "filename", and
1048 // append to the CPU's path.
1049 std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size());
1050 sdbusplus::message::object_path configPath(cpuObjectPath);
1051 configPath /= configBaseName;
1052
Ed Tanous62598e32023-07-17 17:06:25 -07001053 BMCWEB_LOG_INFO("Setting config to {}", configPath.str);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001054
1055 // Set the property, with handler to check error responses
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001056 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301057 resp, "AppliedOperatingConfig", *controlService, cpuObjectPath,
George Liu9ae226f2023-06-21 17:56:46 +08001058 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ginu Georgee93abac2024-06-14 17:35:27 +05301059 "AppliedConfig", configPath);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001060}
1061
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001062inline void handleProcessorHead(
1063 crow::App& app, const crow::Request& req,
1064 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1065 const std::string& /* systemName */, const std::string& /* processorId */)
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001066{
Ed Tanousac106bf2023-06-07 09:24:59 -07001067 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001068 {
1069 return;
1070 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001071 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001072 boost::beast::http::field::link,
1073 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1074}
1075
1076inline void handleProcessorCollectionHead(
1077 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -07001078 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001079 const std::string& /* systemName */)
1080{
Ed Tanousac106bf2023-06-07 09:24:59 -07001081 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001082 {
1083 return;
1084 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001085 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001086 boost::beast::http::field::link,
1087 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1088}
1089
George Liu98eafce2020-10-03 16:46:04 +08001090inline void handleProcessorGet(
1091 App& app, const crow::Request& req,
1092 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1093 const std::string& systemName, const std::string& processorId)
1094{
1095 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1096 {
1097 return;
1098 }
1099 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1100 {
1101 // Option currently returns no systems. TBD
1102 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1103 systemName);
1104 return;
1105 }
1106 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1107 {
1108 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1109 systemName);
1110 return;
1111 }
1112
1113 getProcessorObject(
1114 asyncResp, processorId,
1115 std::bind_front(getProcessorData, asyncResp, processorId));
1116}
1117
1118inline void doPatchProcessor(
1119 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1120 const std::string& processorId,
1121 const std::optional<std::string>& appliedConfigUri,
1122 std::optional<bool> locationIndicatorActive, const std::string& objectPath,
1123 const dbus::utility::MapperServiceMap& serviceMap)
1124{
1125 if (appliedConfigUri)
1126 {
1127 patchAppliedOperatingConfig(asyncResp, processorId, *appliedConfigUri,
1128 objectPath, serviceMap);
1129 }
1130
1131 if (locationIndicatorActive)
1132 {
1133 // Utility function handles reporting errors
1134 setLocationIndicatorActive(asyncResp, objectPath,
1135 *locationIndicatorActive);
1136 }
1137}
1138
1139inline void handleProcessorPatch(
1140 App& app, const crow::Request& req,
1141 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1142 const std::string& systemName, const std::string& processorId)
1143{
1144 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1145 {
1146 return;
1147 }
1148 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1149 {
1150 // Option currently returns no systems. TBD
1151 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1152 systemName);
1153 return;
1154 }
1155 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1156 {
1157 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1158 systemName);
1159 return;
1160 }
1161
1162 std::optional<std::string> appliedConfigUri;
1163 std::optional<bool> locationIndicatorActive;
1164 if (!json_util::readJsonPatch(
1165 req, asyncResp->res, //
1166 "AppliedOperatingConfig/@odata.id", appliedConfigUri, //
1167 "LocationIndicatorActive", locationIndicatorActive //
1168 ))
1169 {
1170 return;
1171 }
1172
1173 // Check for 404 and find matching D-Bus object, then run
1174 // property patch handlers if that all succeeds.
1175 getProcessorObject(
1176 asyncResp, processorId,
1177 std::bind_front(doPatchProcessor, asyncResp, processorId,
1178 appliedConfigUri, locationIndicatorActive));
1179}
1180
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001181inline void requestRoutesOperatingConfigCollection(App& app)
Jonathan Domandba0c292020-12-02 15:34:13 -08001182{
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001183 BMCWEB_ROUTE(app,
1184 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/")
Ed Tanoused398212021-06-09 17:05:54 -07001185 .privileges(redfish::privileges::getOperatingConfigCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001186 .methods(
1187 boost::beast::http::verb::
1188 get)([&app](const crow::Request& req,
1189 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1190 const std::string& systemName,
1191 const std::string& cpuName) {
1192 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001193 {
1194 return;
1195 }
Jonathan Domandba0c292020-12-02 15:34:13 -08001196
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001197 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07001198 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001199 // Option currently returns no systems. TBD
1200 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1201 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001202 return;
1203 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001204
1205 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1206 {
1207 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1208 systemName);
1209 return;
1210 }
1211 asyncResp->res.jsonValue["@odata.type"] =
1212 "#OperatingConfigCollection.OperatingConfigCollection";
1213 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1214 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1215 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName);
1216 asyncResp->res.jsonValue["Name"] = "Operating Config Collection";
1217
1218 // First find the matching CPU object so we know how to
1219 // constrain our search for related Config objects.
1220 const std::array<std::string_view, 1> interfaces = {
1221 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"};
1222 dbus::utility::getSubTreePaths(
1223 "/xyz/openbmc_project/inventory", 0, interfaces,
1224 [asyncResp,
1225 cpuName](const boost::system::error_code& ec,
1226 const dbus::utility::MapperGetSubTreePathsResponse&
1227 objects) {
1228 if (ec)
1229 {
1230 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec,
1231 ec.message());
1232 messages::internalError(asyncResp->res);
1233 return;
1234 }
1235
1236 for (const std::string& object : objects)
1237 {
1238 if (!object.ends_with(cpuName))
1239 {
1240 continue;
1241 }
1242
1243 // Not expected that there will be multiple matching
1244 // CPU objects, but if there are just use the first
1245 // one.
1246
1247 // Use the common search routine to construct the
1248 // Collection of all Config objects under this CPU.
1249 constexpr std::array<std::string_view, 1> interface{
1250 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1251 collection_util::getCollectionMembers(
1252 asyncResp,
1253 boost::urls::format(
1254 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1255 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName),
1256 interface, object);
1257 return;
1258 }
1259 });
George Liu0fda0f12021-11-16 10:06:17 +08001260 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001261}
1262
1263inline void requestRoutesOperatingConfig(App& app)
1264{
1265 BMCWEB_ROUTE(
1266 app,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001267 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001268 .privileges(redfish::privileges::getOperatingConfig)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001269 .methods(
1270 boost::beast::http::verb::
1271 get)([&app](const crow::Request& req,
1272 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1273 const std::string& systemName,
1274 const std::string& cpuName,
1275 const std::string& configName) {
1276 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001277 {
1278 return;
1279 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001280 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07001281 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001282 // Option currently returns no systems. TBD
1283 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1284 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001285 return;
1286 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001287
1288 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1289 {
1290 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1291 systemName);
1292 return;
1293 }
1294 // Ask for all objects implementing OperatingConfig so we can search
1295 // for one with a matching name
1296 constexpr std::array<std::string_view, 1> interfaces = {
1297 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1298 dbus::utility::getSubTree(
1299 "/xyz/openbmc_project/inventory", 0, interfaces,
1300 [asyncResp, cpuName, configName](
1301 const boost::system::error_code& ec,
1302 const dbus::utility::MapperGetSubTreeResponse& subtree) {
1303 if (ec)
1304 {
1305 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec,
1306 ec.message());
1307 messages::internalError(asyncResp->res);
1308 return;
1309 }
1310 const std::string expectedEnding =
1311 cpuName + '/' + configName;
1312 for (const auto& [objectPath, serviceMap] : subtree)
1313 {
1314 // Ignore any configs without matching cpuX/configY
1315 if (!objectPath.ends_with(expectedEnding) ||
1316 serviceMap.empty())
1317 {
1318 continue;
1319 }
1320
1321 nlohmann::json& json = asyncResp->res.jsonValue;
1322 json["@odata.type"] =
1323 "#OperatingConfig.v1_0_0.OperatingConfig";
1324 json["@odata.id"] = boost::urls::format(
1325 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
1326 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName,
1327 configName);
1328 json["Name"] = "Processor Profile";
1329 json["Id"] = configName;
1330
1331 // Just use the first implementation of the object - not
1332 // expected that there would be multiple matching
1333 // services
1334 getOperatingConfigData(
1335 asyncResp, serviceMap.begin()->first, objectPath);
1336 return;
1337 }
1338 messages::resourceNotFound(asyncResp->res,
1339 "OperatingConfig", configName);
1340 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001341 });
1342}
Jonathan Domandba0c292020-12-02 15:34:13 -08001343
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001344inline void requestRoutesProcessorCollection(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001345{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001346 /**
1347 * Functions triggers appropriate requests on DBus
1348 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001349 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001350 .privileges(redfish::privileges::headProcessorCollection)
1351 .methods(boost::beast::http::verb::head)(
1352 std::bind_front(handleProcessorCollectionHead, std::ref(app)));
1353
1354 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Ed Tanoused398212021-06-09 17:05:54 -07001355 .privileges(redfish::privileges::getProcessorCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001356 .methods(
1357 boost::beast::http::verb::
1358 get)([&app](const crow::Request& req,
1359 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1360 const std::string& systemName) {
1361 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1362 {
1363 return;
1364 }
1365 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1366 {
1367 // Option currently returns no systems. TBD
1368 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1369 systemName);
1370 return;
1371 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001372
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001373 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1374 {
1375 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1376 systemName);
1377 return;
1378 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001379
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001380 asyncResp->res.addHeader(
1381 boost::beast::http::field::link,
1382 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001383
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001384 asyncResp->res.jsonValue["@odata.type"] =
1385 "#ProcessorCollection.ProcessorCollection";
1386 asyncResp->res.jsonValue["Name"] = "Processor Collection";
Gunnar Millsac6a4442020-10-14 14:55:29 -05001387
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001388 asyncResp->res.jsonValue["@odata.id"] =
1389 std::format("/redfish/v1/Systems/{}/Processors",
1390 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Gunnar Millsac6a4442020-10-14 14:55:29 -05001391
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001392 collection_util::getCollectionMembers(
1393 asyncResp,
1394 boost::urls::format("/redfish/v1/Systems/{}/Processors",
1395 BMCWEB_REDFISH_SYSTEM_URI_NAME),
1396 processorInterfaces, "/xyz/openbmc_project/inventory");
1397 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001398}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001399
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001400inline void requestRoutesProcessor(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001401{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001402 /**
1403 * Functions triggers appropriate requests on DBus
1404 */
Gunnar Millsac6a4442020-10-14 14:55:29 -05001405
Ed Tanous22d268c2022-05-19 09:39:07 -07001406 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001407 .privileges(redfish::privileges::headProcessor)
1408 .methods(boost::beast::http::verb::head)(
1409 std::bind_front(handleProcessorHead, std::ref(app)));
1410
1411 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001412 .privileges(redfish::privileges::getProcessor)
George Liu98eafce2020-10-03 16:46:04 +08001413 .methods(boost::beast::http::verb::get)(
1414 std::bind_front(handleProcessorGet, std::ref(app)));
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001415
Ed Tanous22d268c2022-05-19 09:39:07 -07001416 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001417 .privileges(redfish::privileges::patchProcessor)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001418 .methods(boost::beast::http::verb::patch)(
George Liu98eafce2020-10-03 16:46:04 +08001419 std::bind_front(handleProcessorPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001420}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001421
1422} // namespace redfish