blob: 9f41b8d3019b7a11183f8dc76c4d4c0eec67c4dc [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 }
414 }
415
416 if (partNumber != nullptr)
417 {
418 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
419 }
420
421 if (sparePartNumber != nullptr && !sparePartNumber->empty())
422 {
423 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
424 }
425 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500426}
427
Ed Tanousac106bf2023-06-07 09:24:59 -0700428inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500429 const std::string& service,
430 const std::string& objPath)
431{
Ed Tanous62598e32023-07-17 17:06:25 -0700432 BMCWEB_LOG_DEBUG("Get Cpu Revision Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800433 dbus::utility::getAllProperties(
434 service, objPath, "xyz.openbmc_project.Inventory.Decorator.Revision",
Ed Tanousac106bf2023-06-07 09:24:59 -0700435 [objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800436 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200437 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400438 if (ec)
439 {
440 BMCWEB_LOG_DEBUG("DBUS response error");
441 messages::internalError(asyncResp->res);
442 return;
443 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500444
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400445 const std::string* version = nullptr;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200446
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400447 const bool success = sdbusplus::unpackPropertiesNoThrow(
448 dbus_utils::UnpackErrorPrinter(), properties, "Version",
449 version);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200450
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400451 if (!success)
452 {
453 messages::internalError(asyncResp->res);
454 return;
455 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200456
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400457 if (version != nullptr)
458 {
459 asyncResp->res.jsonValue["Version"] = *version;
460 }
461 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500462}
463
zhanghch058d1b46d2021-04-01 11:18:24 +0800464inline void getAcceleratorDataByService(
Ed Tanousac106bf2023-06-07 09:24:59 -0700465 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& acclrtrId,
zhanghch058d1b46d2021-04-01 11:18:24 +0800466 const std::string& service, const std::string& objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500467{
Ed Tanous62598e32023-07-17 17:06:25 -0700468 BMCWEB_LOG_DEBUG("Get available system Accelerator resources by service.");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800469 dbus::utility::getAllProperties(
470 service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700471 [acclrtrId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800472 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200473 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400474 if (ec)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500475 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400476 BMCWEB_LOG_DEBUG("DBUS response error");
477 messages::internalError(asyncResp->res);
478 return;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500479 }
480
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400481 const bool* functional = nullptr;
482 const bool* present = nullptr;
483
484 const bool success = sdbusplus::unpackPropertiesNoThrow(
485 dbus_utils::UnpackErrorPrinter(), properties, "Functional",
486 functional, "Present", present);
487
488 if (!success)
489 {
490 messages::internalError(asyncResp->res);
491 return;
492 }
493
494 std::string state = "Enabled";
495 std::string health = "OK";
496
497 if (present != nullptr && !*present)
498 {
499 state = "Absent";
500 }
501
502 if (functional != nullptr && !*functional)
503 {
504 if (state == "Enabled")
505 {
506 health = "Critical";
507 }
508 }
509
510 asyncResp->res.jsonValue["Id"] = acclrtrId;
511 asyncResp->res.jsonValue["Name"] = "Processor";
512 asyncResp->res.jsonValue["Status"]["State"] = state;
513 asyncResp->res.jsonValue["Status"]["Health"] = health;
514 asyncResp->res.jsonValue["ProcessorType"] =
515 processor::ProcessorType::Accelerator;
516 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500517}
518
Jonathan Domandba0c292020-12-02 15:34:13 -0800519// OperatingConfig D-Bus Types
520using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>;
521using BaseSpeedPrioritySettingsProperty =
522 std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>;
523// uint32_t and size_t may or may not be the same type, requiring a dedup'd
524// variant
Jonathan Domandba0c292020-12-02 15:34:13 -0800525
526/**
527 * Fill out the HighSpeedCoreIDs in a Processor resource from the given
528 * OperatingConfig D-Bus property.
529 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700530 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800531 * @param[in] baseSpeedSettings Full list of base speed priority groups,
532 * to use to determine the list of high
533 * speed cores.
534 */
535inline void highSpeedCoreIdsHandler(
Ed Tanousac106bf2023-06-07 09:24:59 -0700536 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Domandba0c292020-12-02 15:34:13 -0800537 const BaseSpeedPrioritySettingsProperty& baseSpeedSettings)
538{
539 // The D-Bus property does not indicate which bucket is the "high
540 // priority" group, so let's discern that by looking for the one with
541 // highest base frequency.
542 auto highPriorityGroup = baseSpeedSettings.cend();
543 uint32_t highestBaseSpeed = 0;
544 for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend();
545 ++it)
546 {
547 const uint32_t baseFreq = std::get<uint32_t>(*it);
548 if (baseFreq > highestBaseSpeed)
549 {
550 highestBaseSpeed = baseFreq;
551 highPriorityGroup = it;
552 }
553 }
554
Ed Tanousac106bf2023-06-07 09:24:59 -0700555 nlohmann::json& jsonCoreIds = asyncResp->res.jsonValue["HighSpeedCoreIDs"];
Jonathan Domandba0c292020-12-02 15:34:13 -0800556 jsonCoreIds = nlohmann::json::array();
557
558 // There may not be any entries in the D-Bus property, so only populate
559 // if there was actually something there.
560 if (highPriorityGroup != baseSpeedSettings.cend())
561 {
562 jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup);
563 }
564}
565
566/**
567 * Fill out OperatingConfig related items in a Processor resource by requesting
568 * data from the given D-Bus object.
569 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700570 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800571 * @param[in] cpuId CPU D-Bus name.
572 * @param[in] service D-Bus service to query.
573 * @param[in] objPath D-Bus object to query.
574 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500575inline void getCpuConfigData(
576 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
577 const std::string& cpuId, const std::string& service,
578 const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800579{
Ed Tanous62598e32023-07-17 17:06:25 -0700580 BMCWEB_LOG_INFO("Getting CPU operating configs for {}", cpuId);
Jonathan Domandba0c292020-12-02 15:34:13 -0800581
582 // First, GetAll CurrentOperatingConfig properties on the object
Ed Tanousdeae6a72024-11-11 21:58:57 -0800583 dbus::utility::getAllProperties(
584 service, objPath,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200585 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700586 [asyncResp, cpuId,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800587 service](const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200588 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400589 if (ec)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200590 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400591 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
Ed Tanousac106bf2023-06-07 09:24:59 -0700592 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200593 return;
594 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200595
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400596 nlohmann::json& json = asyncResp->res.jsonValue;
597
598 const sdbusplus::message::object_path* appliedConfig = nullptr;
599 const bool* baseSpeedPriorityEnabled = nullptr;
600
601 const bool success = sdbusplus::unpackPropertiesNoThrow(
602 dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig",
603 appliedConfig, "BaseSpeedPriorityEnabled",
604 baseSpeedPriorityEnabled);
605
606 if (!success)
607 {
608 messages::internalError(asyncResp->res);
609 return;
610 }
611
612 if (appliedConfig != nullptr)
613 {
614 const std::string& dbusPath = appliedConfig->str;
615 nlohmann::json::object_t operatingConfig;
616 operatingConfig["@odata.id"] = boost::urls::format(
617 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
618 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId);
619 json["OperatingConfigs"] = std::move(operatingConfig);
620
621 // Reuse the D-Bus config object name for the Redfish
622 // URI
623 size_t baseNamePos = dbusPath.rfind('/');
624 if (baseNamePos == std::string::npos ||
625 baseNamePos == (dbusPath.size() - 1))
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200626 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400627 // If the AppliedConfig was somehow not a valid path,
628 // skip adding any more properties, since everything
629 // else is tied to this applied config.
Ed Tanousac106bf2023-06-07 09:24:59 -0700630 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200631 return;
632 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400633 nlohmann::json::object_t appliedOperatingConfig;
634 appliedOperatingConfig["@odata.id"] = boost::urls::format(
635 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
636 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId,
637 dbusPath.substr(baseNamePos + 1));
638 json["AppliedOperatingConfig"] =
639 std::move(appliedOperatingConfig);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200640
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400641 // Once we found the current applied config, queue another
642 // request to read the base freq core ids out of that
643 // config.
Ed Tanousdeae6a72024-11-11 21:58:57 -0800644 dbus::utility::getProperty<BaseSpeedPrioritySettingsProperty>(
645 service, dbusPath,
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400646 "xyz.openbmc_project.Inventory.Item.Cpu."
647 "OperatingConfig",
648 "BaseSpeedPrioritySettings",
649 [asyncResp](const boost::system::error_code& ec2,
650 const BaseSpeedPrioritySettingsProperty&
651 baseSpeedList) {
652 if (ec2)
653 {
654 BMCWEB_LOG_WARNING("D-Bus Property Get error: {}",
655 ec2);
656 messages::internalError(asyncResp->res);
657 return;
658 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200659
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400660 highSpeedCoreIdsHandler(asyncResp, baseSpeedList);
661 });
662 }
663
664 if (baseSpeedPriorityEnabled != nullptr)
665 {
666 json["BaseSpeedPriorityState"] =
667 *baseSpeedPriorityEnabled ? "Enabled" : "Disabled";
668 }
669 });
Jonathan Domandba0c292020-12-02 15:34:13 -0800670}
671
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600672/**
673 * @brief Fill out location info of a processor by
674 * requesting data from the given D-Bus object.
675 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700676 * @param[in,out] asyncResp Async HTTP response.
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600677 * @param[in] service D-Bus service to query.
678 * @param[in] objPath D-Bus object to query.
679 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700680inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600681 const std::string& service,
682 const std::string& objPath)
683{
Ed Tanous62598e32023-07-17 17:06:25 -0700684 BMCWEB_LOG_DEBUG("Get Cpu Location Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800685 dbus::utility::getProperty<std::string>(
686 service, objPath,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700687 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700688 [objPath, asyncResp{std::move(asyncResp)}](
689 const boost::system::error_code& ec, const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400690 if (ec)
691 {
692 BMCWEB_LOG_DEBUG("DBUS response error");
693 messages::internalError(asyncResp->res);
694 return;
695 }
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600696
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400697 asyncResp->res
698 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
699 property;
700 });
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600701}
702
Jonathan Domanc9514482021-02-24 09:20:51 -0800703/**
Jonathan Doman49e429c2021-03-03 13:11:44 -0800704 * Populate the unique identifier in a Processor resource by requesting data
705 * from the given D-Bus object.
706 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700707 * @param[in,out] asyncResp Async HTTP response.
Jonathan Doman49e429c2021-03-03 13:11:44 -0800708 * @param[in] service D-Bus service to query.
709 * @param[in] objPath D-Bus object to query.
710 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700711inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Doman49e429c2021-03-03 13:11:44 -0800712 const std::string& service,
713 const std::string& objectPath)
714{
Ed Tanous62598e32023-07-17 17:06:25 -0700715 BMCWEB_LOG_DEBUG("Get CPU UniqueIdentifier");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800716 dbus::utility::getProperty<std::string>(
717 service, objectPath,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700718 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
719 "UniqueIdentifier",
Ed Tanousac106bf2023-06-07 09:24:59 -0700720 [asyncResp](const boost::system::error_code& ec,
721 const std::string& id) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400722 if (ec)
723 {
724 BMCWEB_LOG_ERROR("Failed to read cpu unique id: {}", ec);
725 messages::internalError(asyncResp->res);
726 return;
727 }
728 asyncResp->res
729 .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id;
730 });
Jonathan Doman49e429c2021-03-03 13:11:44 -0800731}
732
George Liu98eafce2020-10-03 16:46:04 +0800733inline void handleProcessorSubtree(
734 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
735 const std::string& processorId,
736 const std::function<
737 void(const std::string& objectPath,
738 const dbus::utility::MapperServiceMap& serviceMap)>& callback,
739 const boost::system::error_code& ec,
740 const dbus::utility::MapperGetSubTreeResponse& subtree)
741{
742 if (ec)
743 {
744 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
745 messages::internalError(asyncResp->res);
746 return;
747 }
748 for (const auto& [objectPath, serviceMap] : subtree)
749 {
750 // Ignore any objects which don't end with our desired cpu name
751 sdbusplus::message::object_path path(objectPath);
752 if (path.filename() == processorId)
753 {
754 // Filter out objects that don't have the CPU-specific
755 // interfaces to make sure we can return 404 on non-CPUs
756 // (e.g. /redfish/../Processors/dimm0)
757 for (const auto& [serviceName, interfaceList] : serviceMap)
758 {
759 if (std::ranges::find_first_of(interfaceList,
760 processorInterfaces) !=
761 interfaceList.end())
762 {
763 // Process the first object which matches cpu name and
764 // required interfaces, and potentially ignore any other
765 // matching objects. Assume all interfaces we want to
766 // process must be on the same object path.
767
768 callback(objectPath, serviceMap);
769 return;
770 }
771 }
772 }
773 }
774 messages::resourceNotFound(asyncResp->res, "Processor", processorId);
775}
776
Jonathan Doman49e429c2021-03-03 13:11:44 -0800777/**
Jonathan Domanc9514482021-02-24 09:20:51 -0800778 * Find the D-Bus object representing the requested Processor, and call the
779 * handler with the results. If matching object is not found, add 404 error to
780 * response and don't call the handler.
781 *
George Liu98eafce2020-10-03 16:46:04 +0800782 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domanc9514482021-02-24 09:20:51 -0800783 * @param[in] processorId Redfish Processor Id.
George Liu98eafce2020-10-03 16:46:04 +0800784 * @param[in] callback Callback to continue processing request upon
Jonathan Domanc9514482021-02-24 09:20:51 -0800785 * successfully finding object.
786 */
George Liu98eafce2020-10-03 16:46:04 +0800787inline void getProcessorObject(
788 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
789 const std::string& processorId,
790 std::function<void(const std::string& objectPath,
791 const dbus::utility::MapperServiceMap& serviceMap)>&&
792 callback)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500793{
Ed Tanous62598e32023-07-17 17:06:25 -0700794 BMCWEB_LOG_DEBUG("Get available system processor resources.");
Gunnar Millsac6a4442020-10-14 14:55:29 -0500795
Jonathan Domanc9514482021-02-24 09:20:51 -0800796 // GetSubTree on all interfaces which provide info about a Processor
Chris Caindfbf7de2023-04-13 16:01:04 -0500797 constexpr std::array<std::string_view, 9> interfaces = {
George Liue99073f2022-12-09 11:06:16 +0800798 "xyz.openbmc_project.Common.UUID",
799 "xyz.openbmc_project.Inventory.Decorator.Asset",
800 "xyz.openbmc_project.Inventory.Decorator.Revision",
801 "xyz.openbmc_project.Inventory.Item.Cpu",
802 "xyz.openbmc_project.Inventory.Decorator.LocationCode",
803 "xyz.openbmc_project.Inventory.Item.Accelerator",
804 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Chris Caindfbf7de2023-04-13 16:01:04 -0500805 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
806 "xyz.openbmc_project.Control.Power.Throttle"};
George Liue99073f2022-12-09 11:06:16 +0800807 dbus::utility::getSubTree(
808 "/xyz/openbmc_project/inventory", 0, interfaces,
George Liu98eafce2020-10-03 16:46:04 +0800809 [asyncResp, processorId, callback{std::move(callback)}](
George Liue99073f2022-12-09 11:06:16 +0800810 const boost::system::error_code& ec,
811 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liu98eafce2020-10-03 16:46:04 +0800812 handleProcessorSubtree(asyncResp, processorId, callback, ec,
813 subtree);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400814 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500815}
816
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400817inline void getProcessorData(
818 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
819 const std::string& processorId, const std::string& objectPath,
820 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Domanc9514482021-02-24 09:20:51 -0800821{
George Liu98eafce2020-10-03 16:46:04 +0800822 asyncResp->res.addHeader(
823 boost::beast::http::field::link,
824 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
825 asyncResp->res.jsonValue["@odata.type"] = "#Processor.v1_18_0.Processor";
826 asyncResp->res.jsonValue["@odata.id"] =
827 boost::urls::format("/redfish/v1/Systems/{}/Processors/{}",
828 BMCWEB_REDFISH_SYSTEM_URI_NAME, processorId);
829
Jonathan Domanc9514482021-02-24 09:20:51 -0800830 for (const auto& [serviceName, interfaceList] : serviceMap)
831 {
832 for (const auto& interface : interfaceList)
833 {
834 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
835 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700836 getCpuAssetData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800837 }
George Liu0fda0f12021-11-16 10:06:17 +0800838 else if (interface ==
839 "xyz.openbmc_project.Inventory.Decorator.Revision")
Jonathan Domanc9514482021-02-24 09:20:51 -0800840 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700841 getCpuRevisionData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800842 }
843 else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu")
844 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700845 getCpuDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800846 objectPath);
847 }
George Liu0fda0f12021-11-16 10:06:17 +0800848 else if (interface ==
849 "xyz.openbmc_project.Inventory.Item.Accelerator")
Jonathan Domanc9514482021-02-24 09:20:51 -0800850 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700851 getAcceleratorDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800852 objectPath);
853 }
George Liu0fda0f12021-11-16 10:06:17 +0800854 else if (
855 interface ==
856 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig")
Jonathan Domanc9514482021-02-24 09:20:51 -0800857 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700858 getCpuConfigData(asyncResp, processorId, serviceName,
859 objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800860 }
George Liu0fda0f12021-11-16 10:06:17 +0800861 else if (interface ==
862 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
Jonathan Domanc9514482021-02-24 09:20:51 -0800863 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700864 getCpuLocationCode(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800865 }
Sharad Yadav71b82f22021-05-10 15:11:39 +0530866 else if (interface == "xyz.openbmc_project.Common.UUID")
867 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700868 getProcessorUUID(asyncResp, serviceName, objectPath);
Sharad Yadav71b82f22021-05-10 15:11:39 +0530869 }
George Liu0fda0f12021-11-16 10:06:17 +0800870 else if (interface ==
871 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier")
Jonathan Doman49e429c2021-03-03 13:11:44 -0800872 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700873 getCpuUniqueId(asyncResp, serviceName, objectPath);
Jonathan Doman49e429c2021-03-03 13:11:44 -0800874 }
Chris Caindfbf7de2023-04-13 16:01:04 -0500875 else if (interface == "xyz.openbmc_project.Control.Power.Throttle")
876 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700877 getThrottleProperties(asyncResp, serviceName, objectPath);
Chris Caindfbf7de2023-04-13 16:01:04 -0500878 }
George Liu98eafce2020-10-03 16:46:04 +0800879 else if (interface == "xyz.openbmc_project.Association.Definitions")
880 {
881 getLocationIndicatorActive(asyncResp, objectPath);
882 }
Jonathan Domanc9514482021-02-24 09:20:51 -0800883 }
884 }
885}
886
Jonathan Domandba0c292020-12-02 15:34:13 -0800887/**
888 * Request all the properties for the given D-Bus object and fill out the
889 * related entries in the Redfish OperatingConfig response.
890 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700891 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800892 * @param[in] service D-Bus service name to query.
893 * @param[in] objPath D-Bus object to query.
894 */
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400895inline void getOperatingConfigData(
896 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
897 const std::string& service, const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800898{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800899 dbus::utility::getAllProperties(
900 service, objPath,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200901 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700902 [asyncResp](const boost::system::error_code& ec,
903 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400904 if (ec)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200905 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400906 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
907 messages::internalError(asyncResp->res);
908 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700909 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200910
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400911 const size_t* availableCoreCount = nullptr;
912 const uint32_t* baseSpeed = nullptr;
913 const uint32_t* maxJunctionTemperature = nullptr;
914 const uint32_t* maxSpeed = nullptr;
915 const uint32_t* powerLimit = nullptr;
916 const TurboProfileProperty* turboProfile = nullptr;
917 const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings =
918 nullptr;
919
920 const bool success = sdbusplus::unpackPropertiesNoThrow(
921 dbus_utils::UnpackErrorPrinter(), properties,
922 "AvailableCoreCount", availableCoreCount, "BaseSpeed",
923 baseSpeed, "MaxJunctionTemperature", maxJunctionTemperature,
924 "MaxSpeed", maxSpeed, "PowerLimit", powerLimit, "TurboProfile",
925 turboProfile, "BaseSpeedPrioritySettings",
926 baseSpeedPrioritySettings);
927
928 if (!success)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200929 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400930 messages::internalError(asyncResp->res);
931 return;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200932 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400933
934 nlohmann::json& json = asyncResp->res.jsonValue;
935
936 if (availableCoreCount != nullptr)
937 {
938 json["TotalAvailableCoreCount"] = *availableCoreCount;
939 }
940
941 if (baseSpeed != nullptr)
942 {
943 json["BaseSpeedMHz"] = *baseSpeed;
944 }
945
946 if (maxJunctionTemperature != nullptr)
947 {
948 json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature;
949 }
950
951 if (maxSpeed != nullptr)
952 {
953 json["MaxSpeedMHz"] = *maxSpeed;
954 }
955
956 if (powerLimit != nullptr)
957 {
958 json["TDPWatts"] = *powerLimit;
959 }
960
961 if (turboProfile != nullptr)
962 {
963 nlohmann::json& turboArray = json["TurboProfile"];
964 turboArray = nlohmann::json::array();
965 for (const auto& [turboSpeed, coreCount] : *turboProfile)
966 {
967 nlohmann::json::object_t turbo;
968 turbo["ActiveCoreCount"] = coreCount;
969 turbo["MaxSpeedMHz"] = turboSpeed;
970 turboArray.emplace_back(std::move(turbo));
971 }
972 }
973
974 if (baseSpeedPrioritySettings != nullptr)
975 {
976 nlohmann::json& baseSpeedArray =
977 json["BaseSpeedPrioritySettings"];
978 baseSpeedArray = nlohmann::json::array();
979 for (const auto& [baseSpeedMhz, coreList] :
980 *baseSpeedPrioritySettings)
981 {
982 nlohmann::json::object_t speed;
983 speed["CoreCount"] = coreList.size();
984 speed["CoreIDs"] = coreList;
985 speed["BaseSpeedMHz"] = baseSpeedMhz;
986 baseSpeedArray.emplace_back(std::move(speed));
987 }
988 }
989 });
Jonathan Domandba0c292020-12-02 15:34:13 -0800990}
991
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800992/**
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800993 * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic
994 * validation of the input data, and then set the D-Bus property.
995 *
996 * @param[in,out] resp Async HTTP response.
997 * @param[in] processorId Processor's Id.
998 * @param[in] appliedConfigUri New property value to apply.
999 * @param[in] cpuObjectPath Path of CPU object to modify.
1000 * @param[in] serviceMap Service map for CPU object.
1001 */
1002inline void patchAppliedOperatingConfig(
1003 const std::shared_ptr<bmcweb::AsyncResp>& resp,
1004 const std::string& processorId, const std::string& appliedConfigUri,
Shantappa Teekappanavar5df6eda2022-01-18 12:29:28 -06001005 const std::string& cpuObjectPath,
1006 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001007{
1008 // Check that the property even exists by checking for the interface
1009 const std::string* controlService = nullptr;
1010 for (const auto& [serviceName, interfaceList] : serviceMap)
1011 {
Ed Tanous3544d2a2023-08-06 18:12:20 -07001012 if (std::ranges::find(interfaceList,
1013 "xyz.openbmc_project.Control.Processor."
1014 "CurrentOperatingConfig") != interfaceList.end())
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001015 {
1016 controlService = &serviceName;
1017 break;
1018 }
1019 }
1020
1021 if (controlService == nullptr)
1022 {
1023 messages::internalError(resp->res);
1024 return;
1025 }
1026
1027 // Check that the config URI is a child of the cpu URI being patched.
Ed Tanous253f11b2024-05-16 09:38:31 -07001028 std::string expectedPrefix(std::format("/redfish/v1/Systems/{}/Processors/",
1029 BMCWEB_REDFISH_SYSTEM_URI_NAME));
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001030 expectedPrefix += processorId;
1031 expectedPrefix += "/OperatingConfigs/";
Ed Tanous11ba3972022-07-11 09:50:41 -07001032 if (!appliedConfigUri.starts_with(expectedPrefix) ||
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001033 expectedPrefix.size() == appliedConfigUri.size())
1034 {
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001035 messages::propertyValueIncorrect(resp->res, "AppliedOperatingConfig",
1036 appliedConfigUri);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001037 return;
1038 }
1039
1040 // Generate the D-Bus path of the OperatingConfig object, by assuming it's a
1041 // direct child of the CPU object.
1042 // Strip the expectedPrefix from the config URI to get the "filename", and
1043 // append to the CPU's path.
1044 std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size());
1045 sdbusplus::message::object_path configPath(cpuObjectPath);
1046 configPath /= configBaseName;
1047
Ed Tanous62598e32023-07-17 17:06:25 -07001048 BMCWEB_LOG_INFO("Setting config to {}", configPath.str);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001049
1050 // Set the property, with handler to check error responses
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001051 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301052 resp, "AppliedOperatingConfig", *controlService, cpuObjectPath,
George Liu9ae226f2023-06-21 17:56:46 +08001053 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ginu Georgee93abac2024-06-14 17:35:27 +05301054 "AppliedConfig", configPath);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001055}
1056
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001057inline void handleProcessorHead(
1058 crow::App& app, const crow::Request& req,
1059 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1060 const std::string& /* systemName */, const std::string& /* processorId */)
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001061{
Ed Tanousac106bf2023-06-07 09:24:59 -07001062 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001063 {
1064 return;
1065 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001066 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001067 boost::beast::http::field::link,
1068 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1069}
1070
1071inline void handleProcessorCollectionHead(
1072 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -07001073 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001074 const std::string& /* systemName */)
1075{
Ed Tanousac106bf2023-06-07 09:24:59 -07001076 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001077 {
1078 return;
1079 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001080 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001081 boost::beast::http::field::link,
1082 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1083}
1084
George Liu98eafce2020-10-03 16:46:04 +08001085inline void handleProcessorGet(
1086 App& app, const crow::Request& req,
1087 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1088 const std::string& systemName, const std::string& processorId)
1089{
1090 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1091 {
1092 return;
1093 }
1094 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1095 {
1096 // Option currently returns no systems. TBD
1097 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1098 systemName);
1099 return;
1100 }
1101 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1102 {
1103 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1104 systemName);
1105 return;
1106 }
1107
1108 getProcessorObject(
1109 asyncResp, processorId,
1110 std::bind_front(getProcessorData, asyncResp, processorId));
1111}
1112
1113inline void doPatchProcessor(
1114 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1115 const std::string& processorId,
1116 const std::optional<std::string>& appliedConfigUri,
1117 std::optional<bool> locationIndicatorActive, const std::string& objectPath,
1118 const dbus::utility::MapperServiceMap& serviceMap)
1119{
1120 if (appliedConfigUri)
1121 {
1122 patchAppliedOperatingConfig(asyncResp, processorId, *appliedConfigUri,
1123 objectPath, serviceMap);
1124 }
1125
1126 if (locationIndicatorActive)
1127 {
1128 // Utility function handles reporting errors
1129 setLocationIndicatorActive(asyncResp, objectPath,
1130 *locationIndicatorActive);
1131 }
1132}
1133
1134inline void handleProcessorPatch(
1135 App& app, const crow::Request& req,
1136 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1137 const std::string& systemName, const std::string& processorId)
1138{
1139 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1140 {
1141 return;
1142 }
1143 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1144 {
1145 // Option currently returns no systems. TBD
1146 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1147 systemName);
1148 return;
1149 }
1150 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1151 {
1152 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1153 systemName);
1154 return;
1155 }
1156
1157 std::optional<std::string> appliedConfigUri;
1158 std::optional<bool> locationIndicatorActive;
1159 if (!json_util::readJsonPatch(
1160 req, asyncResp->res, //
1161 "AppliedOperatingConfig/@odata.id", appliedConfigUri, //
1162 "LocationIndicatorActive", locationIndicatorActive //
1163 ))
1164 {
1165 return;
1166 }
1167
1168 // Check for 404 and find matching D-Bus object, then run
1169 // property patch handlers if that all succeeds.
1170 getProcessorObject(
1171 asyncResp, processorId,
1172 std::bind_front(doPatchProcessor, asyncResp, processorId,
1173 appliedConfigUri, locationIndicatorActive));
1174}
1175
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001176inline void requestRoutesOperatingConfigCollection(App& app)
Jonathan Domandba0c292020-12-02 15:34:13 -08001177{
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001178 BMCWEB_ROUTE(app,
1179 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/")
Ed Tanoused398212021-06-09 17:05:54 -07001180 .privileges(redfish::privileges::getOperatingConfigCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001181 .methods(
1182 boost::beast::http::verb::
1183 get)([&app](const crow::Request& req,
1184 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1185 const std::string& systemName,
1186 const std::string& cpuName) {
1187 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001188 {
1189 return;
1190 }
Jonathan Domandba0c292020-12-02 15:34:13 -08001191
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001192 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07001193 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001194 // Option currently returns no systems. TBD
1195 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1196 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001197 return;
1198 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001199
1200 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1201 {
1202 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1203 systemName);
1204 return;
1205 }
1206 asyncResp->res.jsonValue["@odata.type"] =
1207 "#OperatingConfigCollection.OperatingConfigCollection";
1208 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1209 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1210 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName);
1211 asyncResp->res.jsonValue["Name"] = "Operating Config Collection";
1212
1213 // First find the matching CPU object so we know how to
1214 // constrain our search for related Config objects.
1215 const std::array<std::string_view, 1> interfaces = {
1216 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"};
1217 dbus::utility::getSubTreePaths(
1218 "/xyz/openbmc_project/inventory", 0, interfaces,
1219 [asyncResp,
1220 cpuName](const boost::system::error_code& ec,
1221 const dbus::utility::MapperGetSubTreePathsResponse&
1222 objects) {
1223 if (ec)
1224 {
1225 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec,
1226 ec.message());
1227 messages::internalError(asyncResp->res);
1228 return;
1229 }
1230
1231 for (const std::string& object : objects)
1232 {
1233 if (!object.ends_with(cpuName))
1234 {
1235 continue;
1236 }
1237
1238 // Not expected that there will be multiple matching
1239 // CPU objects, but if there are just use the first
1240 // one.
1241
1242 // Use the common search routine to construct the
1243 // Collection of all Config objects under this CPU.
1244 constexpr std::array<std::string_view, 1> interface{
1245 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1246 collection_util::getCollectionMembers(
1247 asyncResp,
1248 boost::urls::format(
1249 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1250 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName),
1251 interface, object);
1252 return;
1253 }
1254 });
George Liu0fda0f12021-11-16 10:06:17 +08001255 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001256}
1257
1258inline void requestRoutesOperatingConfig(App& app)
1259{
1260 BMCWEB_ROUTE(
1261 app,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001262 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001263 .privileges(redfish::privileges::getOperatingConfig)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001264 .methods(
1265 boost::beast::http::verb::
1266 get)([&app](const crow::Request& req,
1267 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1268 const std::string& systemName,
1269 const std::string& cpuName,
1270 const std::string& configName) {
1271 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001272 {
1273 return;
1274 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001275 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07001276 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001277 // Option currently returns no systems. TBD
1278 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1279 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001280 return;
1281 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001282
1283 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1284 {
1285 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1286 systemName);
1287 return;
1288 }
1289 // Ask for all objects implementing OperatingConfig so we can search
1290 // for one with a matching name
1291 constexpr std::array<std::string_view, 1> interfaces = {
1292 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1293 dbus::utility::getSubTree(
1294 "/xyz/openbmc_project/inventory", 0, interfaces,
1295 [asyncResp, cpuName, configName](
1296 const boost::system::error_code& ec,
1297 const dbus::utility::MapperGetSubTreeResponse& subtree) {
1298 if (ec)
1299 {
1300 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec,
1301 ec.message());
1302 messages::internalError(asyncResp->res);
1303 return;
1304 }
1305 const std::string expectedEnding =
1306 cpuName + '/' + configName;
1307 for (const auto& [objectPath, serviceMap] : subtree)
1308 {
1309 // Ignore any configs without matching cpuX/configY
1310 if (!objectPath.ends_with(expectedEnding) ||
1311 serviceMap.empty())
1312 {
1313 continue;
1314 }
1315
1316 nlohmann::json& json = asyncResp->res.jsonValue;
1317 json["@odata.type"] =
1318 "#OperatingConfig.v1_0_0.OperatingConfig";
1319 json["@odata.id"] = boost::urls::format(
1320 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
1321 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName,
1322 configName);
1323 json["Name"] = "Processor Profile";
1324 json["Id"] = configName;
1325
1326 // Just use the first implementation of the object - not
1327 // expected that there would be multiple matching
1328 // services
1329 getOperatingConfigData(
1330 asyncResp, serviceMap.begin()->first, objectPath);
1331 return;
1332 }
1333 messages::resourceNotFound(asyncResp->res,
1334 "OperatingConfig", configName);
1335 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001336 });
1337}
Jonathan Domandba0c292020-12-02 15:34:13 -08001338
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001339inline void requestRoutesProcessorCollection(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001340{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001341 /**
1342 * Functions triggers appropriate requests on DBus
1343 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001344 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001345 .privileges(redfish::privileges::headProcessorCollection)
1346 .methods(boost::beast::http::verb::head)(
1347 std::bind_front(handleProcessorCollectionHead, std::ref(app)));
1348
1349 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Ed Tanoused398212021-06-09 17:05:54 -07001350 .privileges(redfish::privileges::getProcessorCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001351 .methods(
1352 boost::beast::http::verb::
1353 get)([&app](const crow::Request& req,
1354 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1355 const std::string& systemName) {
1356 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1357 {
1358 return;
1359 }
1360 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1361 {
1362 // Option currently returns no systems. TBD
1363 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1364 systemName);
1365 return;
1366 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001367
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001368 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1369 {
1370 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1371 systemName);
1372 return;
1373 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001374
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001375 asyncResp->res.addHeader(
1376 boost::beast::http::field::link,
1377 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001378
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001379 asyncResp->res.jsonValue["@odata.type"] =
1380 "#ProcessorCollection.ProcessorCollection";
1381 asyncResp->res.jsonValue["Name"] = "Processor Collection";
Gunnar Millsac6a4442020-10-14 14:55:29 -05001382
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001383 asyncResp->res.jsonValue["@odata.id"] =
1384 std::format("/redfish/v1/Systems/{}/Processors",
1385 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Gunnar Millsac6a4442020-10-14 14:55:29 -05001386
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001387 collection_util::getCollectionMembers(
1388 asyncResp,
1389 boost::urls::format("/redfish/v1/Systems/{}/Processors",
1390 BMCWEB_REDFISH_SYSTEM_URI_NAME),
1391 processorInterfaces, "/xyz/openbmc_project/inventory");
1392 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001393}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001394
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001395inline void requestRoutesProcessor(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001396{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001397 /**
1398 * Functions triggers appropriate requests on DBus
1399 */
Gunnar Millsac6a4442020-10-14 14:55:29 -05001400
Ed Tanous22d268c2022-05-19 09:39:07 -07001401 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001402 .privileges(redfish::privileges::headProcessor)
1403 .methods(boost::beast::http::verb::head)(
1404 std::bind_front(handleProcessorHead, std::ref(app)));
1405
1406 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001407 .privileges(redfish::privileges::getProcessor)
George Liu98eafce2020-10-03 16:46:04 +08001408 .methods(boost::beast::http::verb::get)(
1409 std::bind_front(handleProcessorGet, std::ref(app)));
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001410
Ed Tanous22d268c2022-05-19 09:39:07 -07001411 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001412 .privileges(redfish::privileges::patchProcessor)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001413 .methods(boost::beast::http::verb::patch)(
George Liu98eafce2020-10-03 16:46:04 +08001414 std::bind_front(handleProcessorPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001415}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001416
1417} // namespace redfish