blob: d4afd3dd59b24020dfef602bc85c98111509767b [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 Liu7a1dbc42022-12-07 16:03:22 +080010#include "dbus_utility.hpp"
Jonathan Doman1e1e5982021-06-11 09:36:17 -070011#include "error_messages.hpp"
Chris Caindfbf7de2023-04-13 16:01:04 -050012#include "generated/enums/processor.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070013#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080014#include "http_request.hpp"
15#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080016#include "query.hpp"
17#include "registries/privilege_registry.hpp"
18#include "utils/collection.hpp"
19#include "utils/dbus_utils.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080020#include "utils/hex_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080021#include "utils/json_utils.hpp"
Gunnar Millsac6a4442020-10-14 14:55:29 -050022
Ed Tanousd7857202025-01-28 15:32:26 -080023#include <boost/beast/http/field.hpp>
24#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080025#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070026#include <boost/url/format.hpp>
Jonathan Domandba0c292020-12-02 15:34:13 -080027#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelny351053f2022-07-28 15:44:22 +020028#include <sdbusplus/unpack_properties.hpp>
Gunnar Millsac6a4442020-10-14 14:55:29 -050029
Ed Tanousd7857202025-01-28 15:32:26 -080030#include <algorithm>
George Liu7a1dbc42022-12-07 16:03:22 +080031#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080032#include <cstddef>
33#include <cstdint>
34#include <format>
35#include <functional>
Michael Shenb9d679d2023-02-13 02:29:04 +000036#include <limits>
Ed Tanousd7857202025-01-28 15:32:26 -080037#include <memory>
38#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070039#include <ranges>
Ed Tanous3c569212024-03-06 14:46:18 -080040#include <string>
George Liu7a1dbc42022-12-07 16:03:22 +080041#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080042#include <tuple>
43#include <utility>
44#include <variant>
45#include <vector>
George Liu7a1dbc42022-12-07 16:03:22 +080046
Gunnar Millsac6a4442020-10-14 14:55:29 -050047namespace redfish
48{
49
Jonathan Domanc9514482021-02-24 09:20:51 -080050// Interfaces which imply a D-Bus object represents a Processor
George Liu7a1dbc42022-12-07 16:03:22 +080051constexpr std::array<std::string_view, 2> processorInterfaces = {
Jonathan Domanc9514482021-02-24 09:20:51 -080052 "xyz.openbmc_project.Inventory.Item.Cpu",
53 "xyz.openbmc_project.Inventory.Item.Accelerator"};
Jonathan Doman2bab9832020-12-02 15:27:40 -080054
Sharad Yadav71b82f22021-05-10 15:11:39 +053055/**
56 * @brief Fill out uuid info of a processor by
57 * requesting data from the given D-Bus object.
58 *
Ed Tanousac106bf2023-06-07 09:24:59 -070059 * @param[in,out] asyncResp Async HTTP response.
Sharad Yadav71b82f22021-05-10 15:11:39 +053060 * @param[in] service D-Bus service to query.
61 * @param[in] objPath D-Bus object to query.
62 */
Ed Tanousac106bf2023-06-07 09:24:59 -070063inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Sharad Yadav71b82f22021-05-10 15:11:39 +053064 const std::string& service,
65 const std::string& objPath)
66{
Ed Tanous62598e32023-07-17 17:06:25 -070067 BMCWEB_LOG_DEBUG("Get Processor UUID");
Ed Tanousdeae6a72024-11-11 21:58:57 -080068 dbus::utility::getProperty<std::string>(
69 service, objPath, "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanousac106bf2023-06-07 09:24:59 -070070 [objPath, asyncResp{std::move(asyncResp)}](
71 const boost::system::error_code& ec, const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040072 if (ec)
73 {
74 BMCWEB_LOG_DEBUG("DBUS response error");
75 messages::internalError(asyncResp->res);
76 return;
77 }
78 asyncResp->res.jsonValue["UUID"] = property;
79 });
Sharad Yadav71b82f22021-05-10 15:11:39 +053080}
81
Ed Tanous711ac7a2021-12-20 09:34:41 -080082inline void getCpuDataByInterface(
Ed Tanousac106bf2023-06-07 09:24:59 -070083 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Michael Shen80f79a42023-08-24 13:41:53 +000084 const dbus::utility::DBusInterfacesMap& cpuInterfacesProperties)
Gunnar Millsac6a4442020-10-14 14:55:29 -050085{
Ed Tanous62598e32023-07-17 17:06:25 -070086 BMCWEB_LOG_DEBUG("Get CPU resources by interface.");
Gunnar Millsac6a4442020-10-14 14:55:29 -050087
Chicago Duana1649ec2021-03-30 16:54:58 +080088 // Set the default value of state
Ed Tanous539d8c62024-06-19 14:38:27 -070089 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
90 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Gunnar Millsac6a4442020-10-14 14:55:29 -050091
92 for (const auto& interface : cpuInterfacesProperties)
93 {
94 for (const auto& property : interface.second)
95 {
Chicago Duana1649ec2021-03-30 16:54:58 +080096 if (property.first == "Present")
Gunnar Millsac6a4442020-10-14 14:55:29 -050097 {
Chicago Duana1649ec2021-03-30 16:54:58 +080098 const bool* cpuPresent = std::get_if<bool>(&property.second);
99 if (cpuPresent == nullptr)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500100 {
101 // Important property not in desired type
Ed Tanousac106bf2023-06-07 09:24:59 -0700102 messages::internalError(asyncResp->res);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500103 return;
104 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800105 if (!*cpuPresent)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500106 {
Chicago Duana1649ec2021-03-30 16:54:58 +0800107 // Slot is not populated
Ed Tanous539d8c62024-06-19 14:38:27 -0700108 asyncResp->res.jsonValue["Status"]["State"] =
109 resource::State::Absent;
Chicago Duana1649ec2021-03-30 16:54:58 +0800110 }
111 }
112 else if (property.first == "Functional")
113 {
114 const bool* cpuFunctional = std::get_if<bool>(&property.second);
115 if (cpuFunctional == nullptr)
116 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700117 messages::internalError(asyncResp->res);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500118 return;
119 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800120 if (!*cpuFunctional)
Chicago Duana1649ec2021-03-30 16:54:58 +0800121 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700122 asyncResp->res.jsonValue["Status"]["Health"] =
123 resource::Health::Critical;
Chicago Duana1649ec2021-03-30 16:54:58 +0800124 }
125 }
126 else if (property.first == "CoreCount")
127 {
128 const uint16_t* coresCount =
129 std::get_if<uint16_t>(&property.second);
130 if (coresCount == nullptr)
131 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700132 messages::internalError(asyncResp->res);
Chicago Duana1649ec2021-03-30 16:54:58 +0800133 return;
134 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700135 asyncResp->res.jsonValue["TotalCores"] = *coresCount;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500136 }
Jonathan Domandc3fa662020-10-26 23:10:24 -0700137 else if (property.first == "MaxSpeedInMhz")
138 {
139 const uint32_t* value = std::get_if<uint32_t>(&property.second);
140 if (value != nullptr)
141 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700142 asyncResp->res.jsonValue["MaxSpeedMHz"] = *value;
Jonathan Domandc3fa662020-10-26 23:10:24 -0700143 }
144 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500145 else if (property.first == "Socket")
146 {
147 const std::string* value =
148 std::get_if<std::string>(&property.second);
149 if (value != nullptr)
150 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700151 asyncResp->res.jsonValue["Socket"] = *value;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500152 }
153 }
154 else if (property.first == "ThreadCount")
155 {
Jonathan Domandc3fa662020-10-26 23:10:24 -0700156 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500157 if (value != nullptr)
158 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700159 asyncResp->res.jsonValue["TotalThreads"] = *value;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500160 }
161 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700162 else if (property.first == "EffectiveFamily")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500163 {
Brandon Kim1930fbd2021-09-14 17:52:51 -0700164 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Brad Bishop6169de22022-09-14 13:08:32 -0400165 if (value != nullptr && *value != 2)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500166 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700167 asyncResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800168 "0x" + intToHexString(*value, 4);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500169 }
170 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700171 else if (property.first == "EffectiveModel")
172 {
173 const uint16_t* value = std::get_if<uint16_t>(&property.second);
174 if (value == nullptr)
175 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700176 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700177 return;
178 }
Brad Bishop6169de22022-09-14 13:08:32 -0400179 if (*value != 0)
180 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700181 asyncResp->res.jsonValue["ProcessorId"]["EffectiveModel"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400182 "0x" + intToHexString(*value, 4);
183 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700184 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500185 else if (property.first == "Id")
186 {
187 const uint64_t* value = std::get_if<uint64_t>(&property.second);
188 if (value != nullptr && *value != 0)
189 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700190 asyncResp->res
Gunnar Millsac6a4442020-10-14 14:55:29 -0500191 .jsonValue["ProcessorId"]["IdentificationRegisters"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800192 "0x" + intToHexString(*value, 16);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500193 }
194 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700195 else if (property.first == "Microcode")
196 {
197 const uint32_t* value = std::get_if<uint32_t>(&property.second);
198 if (value == nullptr)
199 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700200 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700201 return;
202 }
Brad Bishop6169de22022-09-14 13:08:32 -0400203 if (*value != 0)
204 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700205 asyncResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400206 "0x" + intToHexString(*value, 8);
207 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700208 }
209 else if (property.first == "Step")
210 {
211 const uint16_t* value = std::get_if<uint16_t>(&property.second);
212 if (value == nullptr)
213 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700214 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700215 return;
216 }
Michael Shenb9d679d2023-02-13 02:29:04 +0000217 if (*value != std::numeric_limits<uint16_t>::max())
Brad Bishop6169de22022-09-14 13:08:32 -0400218 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700219 asyncResp->res.jsonValue["ProcessorId"]["Step"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400220 "0x" + intToHexString(*value, 4);
221 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700222 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500223 }
224 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500225}
226
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400227inline void getCpuDataByService(
228 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& cpuId,
229 const std::string& service, const std::string& objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500230{
Ed Tanous62598e32023-07-17 17:06:25 -0700231 BMCWEB_LOG_DEBUG("Get available system cpu resources by service.");
Gunnar Millsac6a4442020-10-14 14:55:29 -0500232
George Liu5eb468d2023-06-20 17:03:24 +0800233 sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
234 dbus::utility::getManagedObjects(
235 service, path,
Ed Tanousac106bf2023-06-07 09:24:59 -0700236 [cpuId, service, objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800237 const boost::system::error_code& ec,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500238 const dbus::utility::ManagedObjectType& dbusData) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400239 if (ec)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500240 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400241 BMCWEB_LOG_DEBUG("DBUS response error");
242 messages::internalError(asyncResp->res);
243 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700244 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400245 asyncResp->res.jsonValue["Id"] = cpuId;
246 asyncResp->res.jsonValue["Name"] = "Processor";
247 asyncResp->res.jsonValue["ProcessorType"] =
248 processor::ProcessorType::CPU;
249
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400250 for (const auto& object : dbusData)
Ed Tanous002d39b2022-05-31 08:59:27 -0700251 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400252 if (object.first.str == objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500253 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400254 getCpuDataByInterface(asyncResp, object.second);
255 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400256 }
257 return;
258 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500259}
260
Chris Caindfbf7de2023-04-13 16:01:04 -0500261/**
262 * @brief Translates throttle cause DBUS property to redfish.
263 *
264 * @param[in] dbusSource The throttle cause from DBUS
265 *
266 * @return Returns as a string, the throttle cause in Redfish terms. If
267 * translation cannot be done, returns "Unknown" throttle reason.
268 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500269inline processor::ThrottleCause dbusToRfThrottleCause(
270 const std::string& dbusSource)
Chris Caindfbf7de2023-04-13 16:01:04 -0500271{
272 if (dbusSource ==
273 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ClockLimit")
274 {
275 return processor::ThrottleCause::ClockLimit;
276 }
277 if (dbusSource ==
278 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ManagementDetectedFault")
279 {
280 return processor::ThrottleCause::ManagementDetectedFault;
281 }
282 if (dbusSource ==
283 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.PowerLimit")
284 {
285 return processor::ThrottleCause::PowerLimit;
286 }
287 if (dbusSource ==
288 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ThermalLimit")
289 {
290 return processor::ThrottleCause::ThermalLimit;
291 }
292 if (dbusSource ==
293 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.Unknown")
294 {
295 return processor::ThrottleCause::Unknown;
296 }
297 return processor::ThrottleCause::Invalid;
298}
299
Patrick Williams504af5a2025-02-03 14:29:03 -0500300inline void readThrottleProperties(
301 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
302 const boost::system::error_code& ec,
303 const dbus::utility::DBusPropertiesMap& properties)
Chris Caindfbf7de2023-04-13 16:01:04 -0500304{
305 if (ec)
306 {
Ed Tanous62598e32023-07-17 17:06:25 -0700307 BMCWEB_LOG_ERROR("Processor Throttle getAllProperties error {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -0700308 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500309 return;
310 }
311
312 const bool* status = nullptr;
313 const std::vector<std::string>* causes = nullptr;
314
315 if (!sdbusplus::unpackPropertiesNoThrow(dbus_utils::UnpackErrorPrinter(),
316 properties, "Throttled", status,
317 "ThrottleCauses", causes))
318 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700319 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500320 return;
321 }
322
Ed Tanousac106bf2023-06-07 09:24:59 -0700323 asyncResp->res.jsonValue["Throttled"] = *status;
Chris Caindfbf7de2023-04-13 16:01:04 -0500324 nlohmann::json::array_t rCauses;
325 for (const std::string& cause : *causes)
326 {
327 processor::ThrottleCause rfCause = dbusToRfThrottleCause(cause);
328 if (rfCause == processor::ThrottleCause::Invalid)
329 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700330 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500331 return;
332 }
333
334 rCauses.emplace_back(rfCause);
335 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700336 asyncResp->res.jsonValue["ThrottleCauses"] = std::move(rCauses);
Chris Caindfbf7de2023-04-13 16:01:04 -0500337}
338
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400339inline void getThrottleProperties(
340 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
341 const std::string& service, const std::string& objectPath)
Chris Caindfbf7de2023-04-13 16:01:04 -0500342{
Ed Tanous62598e32023-07-17 17:06:25 -0700343 BMCWEB_LOG_DEBUG("Get processor throttle resources");
Chris Caindfbf7de2023-04-13 16:01:04 -0500344
Ed Tanousdeae6a72024-11-11 21:58:57 -0800345 dbus::utility::getAllProperties(
346 service, objectPath, "xyz.openbmc_project.Control.Power.Throttle",
Ed Tanousac106bf2023-06-07 09:24:59 -0700347 [asyncResp](const boost::system::error_code& ec,
348 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400349 readThrottleProperties(asyncResp, ec, properties);
350 });
Chris Caindfbf7de2023-04-13 16:01:04 -0500351}
352
Ed Tanousac106bf2023-06-07 09:24:59 -0700353inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500354 const std::string& service,
355 const std::string& objPath)
356{
Ed Tanous62598e32023-07-17 17:06:25 -0700357 BMCWEB_LOG_DEBUG("Get Cpu Asset Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800358 dbus::utility::getAllProperties(
359 service, objPath, "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanousac106bf2023-06-07 09:24:59 -0700360 [objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800361 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200362 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400363 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700364 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400365 BMCWEB_LOG_DEBUG("DBUS response error");
366 messages::internalError(asyncResp->res);
367 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700368 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400369
370 const std::string* serialNumber = nullptr;
371 const std::string* model = nullptr;
372 const std::string* manufacturer = nullptr;
373 const std::string* partNumber = nullptr;
374 const std::string* sparePartNumber = nullptr;
375
376 const bool success = sdbusplus::unpackPropertiesNoThrow(
377 dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber",
378 serialNumber, "Model", model, "Manufacturer", manufacturer,
379 "PartNumber", partNumber, "SparePartNumber", sparePartNumber);
380
381 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700382 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400383 messages::internalError(asyncResp->res);
384 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700385 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200386
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400387 if (serialNumber != nullptr && !serialNumber->empty())
388 {
389 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
390 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200391
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400392 if ((model != nullptr) && !model->empty())
393 {
394 asyncResp->res.jsonValue["Model"] = *model;
395 }
396
397 if (manufacturer != nullptr)
398 {
399 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
400
401 // Otherwise would be unexpected.
402 if (manufacturer->find("Intel") != std::string::npos)
403 {
404 asyncResp->res.jsonValue["ProcessorArchitecture"] = "x86";
405 asyncResp->res.jsonValue["InstructionSet"] = "x86-64";
406 }
407 else if (manufacturer->find("IBM") != std::string::npos)
408 {
409 asyncResp->res.jsonValue["ProcessorArchitecture"] = "Power";
410 asyncResp->res.jsonValue["InstructionSet"] = "PowerISA";
411 }
412 }
413
414 if (partNumber != nullptr)
415 {
416 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
417 }
418
419 if (sparePartNumber != nullptr && !sparePartNumber->empty())
420 {
421 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
422 }
423 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500424}
425
Ed Tanousac106bf2023-06-07 09:24:59 -0700426inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500427 const std::string& service,
428 const std::string& objPath)
429{
Ed Tanous62598e32023-07-17 17:06:25 -0700430 BMCWEB_LOG_DEBUG("Get Cpu Revision Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800431 dbus::utility::getAllProperties(
432 service, objPath, "xyz.openbmc_project.Inventory.Decorator.Revision",
Ed Tanousac106bf2023-06-07 09:24:59 -0700433 [objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800434 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200435 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400436 if (ec)
437 {
438 BMCWEB_LOG_DEBUG("DBUS response error");
439 messages::internalError(asyncResp->res);
440 return;
441 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500442
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400443 const std::string* version = nullptr;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200444
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400445 const bool success = sdbusplus::unpackPropertiesNoThrow(
446 dbus_utils::UnpackErrorPrinter(), properties, "Version",
447 version);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200448
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400449 if (!success)
450 {
451 messages::internalError(asyncResp->res);
452 return;
453 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200454
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400455 if (version != nullptr)
456 {
457 asyncResp->res.jsonValue["Version"] = *version;
458 }
459 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500460}
461
zhanghch058d1b46d2021-04-01 11:18:24 +0800462inline void getAcceleratorDataByService(
Ed Tanousac106bf2023-06-07 09:24:59 -0700463 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& acclrtrId,
zhanghch058d1b46d2021-04-01 11:18:24 +0800464 const std::string& service, const std::string& objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500465{
Ed Tanous62598e32023-07-17 17:06:25 -0700466 BMCWEB_LOG_DEBUG("Get available system Accelerator resources by service.");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800467 dbus::utility::getAllProperties(
468 service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700469 [acclrtrId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800470 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200471 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400472 if (ec)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500473 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400474 BMCWEB_LOG_DEBUG("DBUS response error");
475 messages::internalError(asyncResp->res);
476 return;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500477 }
478
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400479 const bool* functional = nullptr;
480 const bool* present = nullptr;
481
482 const bool success = sdbusplus::unpackPropertiesNoThrow(
483 dbus_utils::UnpackErrorPrinter(), properties, "Functional",
484 functional, "Present", present);
485
486 if (!success)
487 {
488 messages::internalError(asyncResp->res);
489 return;
490 }
491
492 std::string state = "Enabled";
493 std::string health = "OK";
494
495 if (present != nullptr && !*present)
496 {
497 state = "Absent";
498 }
499
500 if (functional != nullptr && !*functional)
501 {
502 if (state == "Enabled")
503 {
504 health = "Critical";
505 }
506 }
507
508 asyncResp->res.jsonValue["Id"] = acclrtrId;
509 asyncResp->res.jsonValue["Name"] = "Processor";
510 asyncResp->res.jsonValue["Status"]["State"] = state;
511 asyncResp->res.jsonValue["Status"]["Health"] = health;
512 asyncResp->res.jsonValue["ProcessorType"] =
513 processor::ProcessorType::Accelerator;
514 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500515}
516
Jonathan Domandba0c292020-12-02 15:34:13 -0800517// OperatingConfig D-Bus Types
518using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>;
519using BaseSpeedPrioritySettingsProperty =
520 std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>;
521// uint32_t and size_t may or may not be the same type, requiring a dedup'd
522// variant
Jonathan Domandba0c292020-12-02 15:34:13 -0800523
524/**
525 * Fill out the HighSpeedCoreIDs in a Processor resource from the given
526 * OperatingConfig D-Bus property.
527 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700528 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800529 * @param[in] baseSpeedSettings Full list of base speed priority groups,
530 * to use to determine the list of high
531 * speed cores.
532 */
533inline void highSpeedCoreIdsHandler(
Ed Tanousac106bf2023-06-07 09:24:59 -0700534 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Domandba0c292020-12-02 15:34:13 -0800535 const BaseSpeedPrioritySettingsProperty& baseSpeedSettings)
536{
537 // The D-Bus property does not indicate which bucket is the "high
538 // priority" group, so let's discern that by looking for the one with
539 // highest base frequency.
540 auto highPriorityGroup = baseSpeedSettings.cend();
541 uint32_t highestBaseSpeed = 0;
542 for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend();
543 ++it)
544 {
545 const uint32_t baseFreq = std::get<uint32_t>(*it);
546 if (baseFreq > highestBaseSpeed)
547 {
548 highestBaseSpeed = baseFreq;
549 highPriorityGroup = it;
550 }
551 }
552
Ed Tanousac106bf2023-06-07 09:24:59 -0700553 nlohmann::json& jsonCoreIds = asyncResp->res.jsonValue["HighSpeedCoreIDs"];
Jonathan Domandba0c292020-12-02 15:34:13 -0800554 jsonCoreIds = nlohmann::json::array();
555
556 // There may not be any entries in the D-Bus property, so only populate
557 // if there was actually something there.
558 if (highPriorityGroup != baseSpeedSettings.cend())
559 {
560 jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup);
561 }
562}
563
564/**
565 * Fill out OperatingConfig related items in a Processor resource by requesting
566 * data from the given D-Bus object.
567 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700568 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800569 * @param[in] cpuId CPU D-Bus name.
570 * @param[in] service D-Bus service to query.
571 * @param[in] objPath D-Bus object to query.
572 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500573inline void getCpuConfigData(
574 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
575 const std::string& cpuId, const std::string& service,
576 const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800577{
Ed Tanous62598e32023-07-17 17:06:25 -0700578 BMCWEB_LOG_INFO("Getting CPU operating configs for {}", cpuId);
Jonathan Domandba0c292020-12-02 15:34:13 -0800579
580 // First, GetAll CurrentOperatingConfig properties on the object
Ed Tanousdeae6a72024-11-11 21:58:57 -0800581 dbus::utility::getAllProperties(
582 service, objPath,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200583 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700584 [asyncResp, cpuId,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800585 service](const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200586 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400587 if (ec)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200588 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400589 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
Ed Tanousac106bf2023-06-07 09:24:59 -0700590 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200591 return;
592 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200593
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400594 nlohmann::json& json = asyncResp->res.jsonValue;
595
596 const sdbusplus::message::object_path* appliedConfig = nullptr;
597 const bool* baseSpeedPriorityEnabled = nullptr;
598
599 const bool success = sdbusplus::unpackPropertiesNoThrow(
600 dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig",
601 appliedConfig, "BaseSpeedPriorityEnabled",
602 baseSpeedPriorityEnabled);
603
604 if (!success)
605 {
606 messages::internalError(asyncResp->res);
607 return;
608 }
609
610 if (appliedConfig != nullptr)
611 {
612 const std::string& dbusPath = appliedConfig->str;
613 nlohmann::json::object_t operatingConfig;
614 operatingConfig["@odata.id"] = boost::urls::format(
615 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
616 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId);
617 json["OperatingConfigs"] = std::move(operatingConfig);
618
619 // Reuse the D-Bus config object name for the Redfish
620 // URI
621 size_t baseNamePos = dbusPath.rfind('/');
622 if (baseNamePos == std::string::npos ||
623 baseNamePos == (dbusPath.size() - 1))
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200624 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400625 // If the AppliedConfig was somehow not a valid path,
626 // skip adding any more properties, since everything
627 // else is tied to this applied config.
Ed Tanousac106bf2023-06-07 09:24:59 -0700628 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200629 return;
630 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400631 nlohmann::json::object_t appliedOperatingConfig;
632 appliedOperatingConfig["@odata.id"] = boost::urls::format(
633 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
634 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId,
635 dbusPath.substr(baseNamePos + 1));
636 json["AppliedOperatingConfig"] =
637 std::move(appliedOperatingConfig);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200638
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400639 // Once we found the current applied config, queue another
640 // request to read the base freq core ids out of that
641 // config.
Ed Tanousdeae6a72024-11-11 21:58:57 -0800642 dbus::utility::getProperty<BaseSpeedPrioritySettingsProperty>(
643 service, dbusPath,
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400644 "xyz.openbmc_project.Inventory.Item.Cpu."
645 "OperatingConfig",
646 "BaseSpeedPrioritySettings",
647 [asyncResp](const boost::system::error_code& ec2,
648 const BaseSpeedPrioritySettingsProperty&
649 baseSpeedList) {
650 if (ec2)
651 {
652 BMCWEB_LOG_WARNING("D-Bus Property Get error: {}",
653 ec2);
654 messages::internalError(asyncResp->res);
655 return;
656 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200657
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400658 highSpeedCoreIdsHandler(asyncResp, baseSpeedList);
659 });
660 }
661
662 if (baseSpeedPriorityEnabled != nullptr)
663 {
664 json["BaseSpeedPriorityState"] =
665 *baseSpeedPriorityEnabled ? "Enabled" : "Disabled";
666 }
667 });
Jonathan Domandba0c292020-12-02 15:34:13 -0800668}
669
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600670/**
671 * @brief Fill out location info of a processor by
672 * requesting data from the given D-Bus object.
673 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700674 * @param[in,out] asyncResp Async HTTP response.
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600675 * @param[in] service D-Bus service to query.
676 * @param[in] objPath D-Bus object to query.
677 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700678inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600679 const std::string& service,
680 const std::string& objPath)
681{
Ed Tanous62598e32023-07-17 17:06:25 -0700682 BMCWEB_LOG_DEBUG("Get Cpu Location Data");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800683 dbus::utility::getProperty<std::string>(
684 service, objPath,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700685 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700686 [objPath, asyncResp{std::move(asyncResp)}](
687 const boost::system::error_code& ec, const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400688 if (ec)
689 {
690 BMCWEB_LOG_DEBUG("DBUS response error");
691 messages::internalError(asyncResp->res);
692 return;
693 }
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600694
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400695 asyncResp->res
696 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
697 property;
698 });
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600699}
700
Jonathan Domanc9514482021-02-24 09:20:51 -0800701/**
Jonathan Doman49e429c2021-03-03 13:11:44 -0800702 * Populate the unique identifier in a Processor resource by requesting data
703 * from the given D-Bus object.
704 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700705 * @param[in,out] asyncResp Async HTTP response.
Jonathan Doman49e429c2021-03-03 13:11:44 -0800706 * @param[in] service D-Bus service to query.
707 * @param[in] objPath D-Bus object to query.
708 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700709inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Doman49e429c2021-03-03 13:11:44 -0800710 const std::string& service,
711 const std::string& objectPath)
712{
Ed Tanous62598e32023-07-17 17:06:25 -0700713 BMCWEB_LOG_DEBUG("Get CPU UniqueIdentifier");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800714 dbus::utility::getProperty<std::string>(
715 service, objectPath,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700716 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
717 "UniqueIdentifier",
Ed Tanousac106bf2023-06-07 09:24:59 -0700718 [asyncResp](const boost::system::error_code& ec,
719 const std::string& id) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400720 if (ec)
721 {
722 BMCWEB_LOG_ERROR("Failed to read cpu unique id: {}", ec);
723 messages::internalError(asyncResp->res);
724 return;
725 }
726 asyncResp->res
727 .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id;
728 });
Jonathan Doman49e429c2021-03-03 13:11:44 -0800729}
730
731/**
Jonathan Domanc9514482021-02-24 09:20:51 -0800732 * Find the D-Bus object representing the requested Processor, and call the
733 * handler with the results. If matching object is not found, add 404 error to
734 * response and don't call the handler.
735 *
736 * @param[in,out] resp Async HTTP response.
737 * @param[in] processorId Redfish Processor Id.
738 * @param[in] handler Callback to continue processing request upon
739 * successfully finding object.
740 */
741template <typename Handler>
zhanghch058d1b46d2021-04-01 11:18:24 +0800742inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp,
Jonathan Domanc9514482021-02-24 09:20:51 -0800743 const std::string& processorId,
744 Handler&& handler)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500745{
Ed Tanous62598e32023-07-17 17:06:25 -0700746 BMCWEB_LOG_DEBUG("Get available system processor resources.");
Gunnar Millsac6a4442020-10-14 14:55:29 -0500747
Jonathan Domanc9514482021-02-24 09:20:51 -0800748 // GetSubTree on all interfaces which provide info about a Processor
Chris Caindfbf7de2023-04-13 16:01:04 -0500749 constexpr std::array<std::string_view, 9> interfaces = {
George Liue99073f2022-12-09 11:06:16 +0800750 "xyz.openbmc_project.Common.UUID",
751 "xyz.openbmc_project.Inventory.Decorator.Asset",
752 "xyz.openbmc_project.Inventory.Decorator.Revision",
753 "xyz.openbmc_project.Inventory.Item.Cpu",
754 "xyz.openbmc_project.Inventory.Decorator.LocationCode",
755 "xyz.openbmc_project.Inventory.Item.Accelerator",
756 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Chris Caindfbf7de2023-04-13 16:01:04 -0500757 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
758 "xyz.openbmc_project.Control.Power.Throttle"};
George Liue99073f2022-12-09 11:06:16 +0800759 dbus::utility::getSubTree(
760 "/xyz/openbmc_project/inventory", 0, interfaces,
Jonathan Domanc9514482021-02-24 09:20:51 -0800761 [resp, processorId, handler = std::forward<Handler>(handler)](
George Liue99073f2022-12-09 11:06:16 +0800762 const boost::system::error_code& ec,
763 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400764 if (ec)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500765 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400766 BMCWEB_LOG_DEBUG("DBUS response error: {}", ec);
767 messages::internalError(resp->res);
768 return;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500769 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400770 for (const auto& [objectPath, serviceMap] : subtree)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500771 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400772 // Ignore any objects which don't end with our desired cpu name
773 if (!objectPath.ends_with(processorId))
Gunnar Millsac6a4442020-10-14 14:55:29 -0500774 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400775 continue;
Jonathan Doman2bab9832020-12-02 15:27:40 -0800776 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400777
778 bool found = false;
779 // Filter out objects that don't have the CPU-specific
780 // interfaces to make sure we can return 404 on non-CPUs
781 // (e.g. /redfish/../Processors/dimm0)
782 for (const auto& [serviceName, interfaceList] : serviceMap)
783 {
784 if (std::ranges::find_first_of(interfaceList,
785 processorInterfaces) !=
786 std::end(interfaceList))
787 {
788 found = true;
789 break;
790 }
791 }
792
793 if (!found)
794 {
795 continue;
796 }
797
798 // Process the first object which does match our cpu name and
799 // required interfaces, and potentially ignore any other
800 // matching objects. Assume all interfaces we want to process
801 // must be on the same object path.
802
803 handler(objectPath, serviceMap);
804 return;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500805 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400806 messages::resourceNotFound(resp->res, "Processor", processorId);
807 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500808}
809
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400810inline void getProcessorData(
811 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
812 const std::string& processorId, const std::string& objectPath,
813 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Domanc9514482021-02-24 09:20:51 -0800814{
815 for (const auto& [serviceName, interfaceList] : serviceMap)
816 {
817 for (const auto& interface : interfaceList)
818 {
819 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
820 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700821 getCpuAssetData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800822 }
George Liu0fda0f12021-11-16 10:06:17 +0800823 else if (interface ==
824 "xyz.openbmc_project.Inventory.Decorator.Revision")
Jonathan Domanc9514482021-02-24 09:20:51 -0800825 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700826 getCpuRevisionData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800827 }
828 else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu")
829 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700830 getCpuDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800831 objectPath);
832 }
George Liu0fda0f12021-11-16 10:06:17 +0800833 else if (interface ==
834 "xyz.openbmc_project.Inventory.Item.Accelerator")
Jonathan Domanc9514482021-02-24 09:20:51 -0800835 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700836 getAcceleratorDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800837 objectPath);
838 }
George Liu0fda0f12021-11-16 10:06:17 +0800839 else if (
840 interface ==
841 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig")
Jonathan Domanc9514482021-02-24 09:20:51 -0800842 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700843 getCpuConfigData(asyncResp, processorId, serviceName,
844 objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800845 }
George Liu0fda0f12021-11-16 10:06:17 +0800846 else if (interface ==
847 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
Jonathan Domanc9514482021-02-24 09:20:51 -0800848 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700849 getCpuLocationCode(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800850 }
Sharad Yadav71b82f22021-05-10 15:11:39 +0530851 else if (interface == "xyz.openbmc_project.Common.UUID")
852 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700853 getProcessorUUID(asyncResp, serviceName, objectPath);
Sharad Yadav71b82f22021-05-10 15:11:39 +0530854 }
George Liu0fda0f12021-11-16 10:06:17 +0800855 else if (interface ==
856 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier")
Jonathan Doman49e429c2021-03-03 13:11:44 -0800857 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700858 getCpuUniqueId(asyncResp, serviceName, objectPath);
Jonathan Doman49e429c2021-03-03 13:11:44 -0800859 }
Chris Caindfbf7de2023-04-13 16:01:04 -0500860 else if (interface == "xyz.openbmc_project.Control.Power.Throttle")
861 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700862 getThrottleProperties(asyncResp, serviceName, objectPath);
Chris Caindfbf7de2023-04-13 16:01:04 -0500863 }
Jonathan Domanc9514482021-02-24 09:20:51 -0800864 }
865 }
866}
867
Jonathan Domandba0c292020-12-02 15:34:13 -0800868/**
869 * Request all the properties for the given D-Bus object and fill out the
870 * related entries in the Redfish OperatingConfig response.
871 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700872 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800873 * @param[in] service D-Bus service name to query.
874 * @param[in] objPath D-Bus object to query.
875 */
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400876inline void getOperatingConfigData(
877 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
878 const std::string& service, const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800879{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800880 dbus::utility::getAllProperties(
881 service, objPath,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200882 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700883 [asyncResp](const boost::system::error_code& ec,
884 const dbus::utility::DBusPropertiesMap& properties) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400885 if (ec)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200886 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400887 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
888 messages::internalError(asyncResp->res);
889 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700890 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200891
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400892 const size_t* availableCoreCount = nullptr;
893 const uint32_t* baseSpeed = nullptr;
894 const uint32_t* maxJunctionTemperature = nullptr;
895 const uint32_t* maxSpeed = nullptr;
896 const uint32_t* powerLimit = nullptr;
897 const TurboProfileProperty* turboProfile = nullptr;
898 const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings =
899 nullptr;
900
901 const bool success = sdbusplus::unpackPropertiesNoThrow(
902 dbus_utils::UnpackErrorPrinter(), properties,
903 "AvailableCoreCount", availableCoreCount, "BaseSpeed",
904 baseSpeed, "MaxJunctionTemperature", maxJunctionTemperature,
905 "MaxSpeed", maxSpeed, "PowerLimit", powerLimit, "TurboProfile",
906 turboProfile, "BaseSpeedPrioritySettings",
907 baseSpeedPrioritySettings);
908
909 if (!success)
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200910 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400911 messages::internalError(asyncResp->res);
912 return;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200913 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400914
915 nlohmann::json& json = asyncResp->res.jsonValue;
916
917 if (availableCoreCount != nullptr)
918 {
919 json["TotalAvailableCoreCount"] = *availableCoreCount;
920 }
921
922 if (baseSpeed != nullptr)
923 {
924 json["BaseSpeedMHz"] = *baseSpeed;
925 }
926
927 if (maxJunctionTemperature != nullptr)
928 {
929 json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature;
930 }
931
932 if (maxSpeed != nullptr)
933 {
934 json["MaxSpeedMHz"] = *maxSpeed;
935 }
936
937 if (powerLimit != nullptr)
938 {
939 json["TDPWatts"] = *powerLimit;
940 }
941
942 if (turboProfile != nullptr)
943 {
944 nlohmann::json& turboArray = json["TurboProfile"];
945 turboArray = nlohmann::json::array();
946 for (const auto& [turboSpeed, coreCount] : *turboProfile)
947 {
948 nlohmann::json::object_t turbo;
949 turbo["ActiveCoreCount"] = coreCount;
950 turbo["MaxSpeedMHz"] = turboSpeed;
951 turboArray.emplace_back(std::move(turbo));
952 }
953 }
954
955 if (baseSpeedPrioritySettings != nullptr)
956 {
957 nlohmann::json& baseSpeedArray =
958 json["BaseSpeedPrioritySettings"];
959 baseSpeedArray = nlohmann::json::array();
960 for (const auto& [baseSpeedMhz, coreList] :
961 *baseSpeedPrioritySettings)
962 {
963 nlohmann::json::object_t speed;
964 speed["CoreCount"] = coreList.size();
965 speed["CoreIDs"] = coreList;
966 speed["BaseSpeedMHz"] = baseSpeedMhz;
967 baseSpeedArray.emplace_back(std::move(speed));
968 }
969 }
970 });
Jonathan Domandba0c292020-12-02 15:34:13 -0800971}
972
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800973/**
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800974 * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic
975 * validation of the input data, and then set the D-Bus property.
976 *
977 * @param[in,out] resp Async HTTP response.
978 * @param[in] processorId Processor's Id.
979 * @param[in] appliedConfigUri New property value to apply.
980 * @param[in] cpuObjectPath Path of CPU object to modify.
981 * @param[in] serviceMap Service map for CPU object.
982 */
983inline void patchAppliedOperatingConfig(
984 const std::shared_ptr<bmcweb::AsyncResp>& resp,
985 const std::string& processorId, const std::string& appliedConfigUri,
Shantappa Teekappanavar5df6eda2022-01-18 12:29:28 -0600986 const std::string& cpuObjectPath,
987 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800988{
989 // Check that the property even exists by checking for the interface
990 const std::string* controlService = nullptr;
991 for (const auto& [serviceName, interfaceList] : serviceMap)
992 {
Ed Tanous3544d2a2023-08-06 18:12:20 -0700993 if (std::ranges::find(interfaceList,
994 "xyz.openbmc_project.Control.Processor."
995 "CurrentOperatingConfig") != interfaceList.end())
Jonathan Doman3cde86f2020-12-02 14:50:45 -0800996 {
997 controlService = &serviceName;
998 break;
999 }
1000 }
1001
1002 if (controlService == nullptr)
1003 {
1004 messages::internalError(resp->res);
1005 return;
1006 }
1007
1008 // Check that the config URI is a child of the cpu URI being patched.
Ed Tanous253f11b2024-05-16 09:38:31 -07001009 std::string expectedPrefix(std::format("/redfish/v1/Systems/{}/Processors/",
1010 BMCWEB_REDFISH_SYSTEM_URI_NAME));
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001011 expectedPrefix += processorId;
1012 expectedPrefix += "/OperatingConfigs/";
Ed Tanous11ba3972022-07-11 09:50:41 -07001013 if (!appliedConfigUri.starts_with(expectedPrefix) ||
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001014 expectedPrefix.size() == appliedConfigUri.size())
1015 {
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001016 messages::propertyValueIncorrect(resp->res, "AppliedOperatingConfig",
1017 appliedConfigUri);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001018 return;
1019 }
1020
1021 // Generate the D-Bus path of the OperatingConfig object, by assuming it's a
1022 // direct child of the CPU object.
1023 // Strip the expectedPrefix from the config URI to get the "filename", and
1024 // append to the CPU's path.
1025 std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size());
1026 sdbusplus::message::object_path configPath(cpuObjectPath);
1027 configPath /= configBaseName;
1028
Ed Tanous62598e32023-07-17 17:06:25 -07001029 BMCWEB_LOG_INFO("Setting config to {}", configPath.str);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001030
1031 // Set the property, with handler to check error responses
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001032 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301033 resp, "AppliedOperatingConfig", *controlService, cpuObjectPath,
George Liu9ae226f2023-06-21 17:56:46 +08001034 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ginu Georgee93abac2024-06-14 17:35:27 +05301035 "AppliedConfig", configPath);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001036}
1037
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001038inline void handleProcessorHead(
1039 crow::App& app, const crow::Request& req,
1040 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1041 const std::string& /* systemName */, const std::string& /* processorId */)
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001042{
Ed Tanousac106bf2023-06-07 09:24:59 -07001043 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001044 {
1045 return;
1046 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001047 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001048 boost::beast::http::field::link,
1049 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1050}
1051
1052inline void handleProcessorCollectionHead(
1053 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -07001054 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001055 const std::string& /* systemName */)
1056{
Ed Tanousac106bf2023-06-07 09:24:59 -07001057 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001058 {
1059 return;
1060 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001061 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001062 boost::beast::http::field::link,
1063 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1064}
1065
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001066inline void requestRoutesOperatingConfigCollection(App& app)
Jonathan Domandba0c292020-12-02 15:34:13 -08001067{
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001068 BMCWEB_ROUTE(app,
1069 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/")
Ed Tanoused398212021-06-09 17:05:54 -07001070 .privileges(redfish::privileges::getOperatingConfigCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001071 .methods(
1072 boost::beast::http::verb::
1073 get)([&app](const crow::Request& req,
1074 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1075 const std::string& systemName,
1076 const std::string& cpuName) {
1077 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001078 {
1079 return;
1080 }
Jonathan Domandba0c292020-12-02 15:34:13 -08001081
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001082 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07001083 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001084 // Option currently returns no systems. TBD
1085 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1086 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001087 return;
1088 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001089
1090 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1091 {
1092 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1093 systemName);
1094 return;
1095 }
1096 asyncResp->res.jsonValue["@odata.type"] =
1097 "#OperatingConfigCollection.OperatingConfigCollection";
1098 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1099 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1100 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName);
1101 asyncResp->res.jsonValue["Name"] = "Operating Config Collection";
1102
1103 // First find the matching CPU object so we know how to
1104 // constrain our search for related Config objects.
1105 const std::array<std::string_view, 1> interfaces = {
1106 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"};
1107 dbus::utility::getSubTreePaths(
1108 "/xyz/openbmc_project/inventory", 0, interfaces,
1109 [asyncResp,
1110 cpuName](const boost::system::error_code& ec,
1111 const dbus::utility::MapperGetSubTreePathsResponse&
1112 objects) {
1113 if (ec)
1114 {
1115 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec,
1116 ec.message());
1117 messages::internalError(asyncResp->res);
1118 return;
1119 }
1120
1121 for (const std::string& object : objects)
1122 {
1123 if (!object.ends_with(cpuName))
1124 {
1125 continue;
1126 }
1127
1128 // Not expected that there will be multiple matching
1129 // CPU objects, but if there are just use the first
1130 // one.
1131
1132 // Use the common search routine to construct the
1133 // Collection of all Config objects under this CPU.
1134 constexpr std::array<std::string_view, 1> interface{
1135 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1136 collection_util::getCollectionMembers(
1137 asyncResp,
1138 boost::urls::format(
1139 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1140 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName),
1141 interface, object);
1142 return;
1143 }
1144 });
George Liu0fda0f12021-11-16 10:06:17 +08001145 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001146}
1147
1148inline void requestRoutesOperatingConfig(App& app)
1149{
1150 BMCWEB_ROUTE(
1151 app,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001152 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001153 .privileges(redfish::privileges::getOperatingConfig)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001154 .methods(
1155 boost::beast::http::verb::
1156 get)([&app](const crow::Request& req,
1157 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1158 const std::string& systemName,
1159 const std::string& cpuName,
1160 const std::string& configName) {
1161 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -07001162 {
1163 return;
1164 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001165 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous002d39b2022-05-31 08:59:27 -07001166 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001167 // Option currently returns no systems. TBD
1168 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1169 systemName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001170 return;
1171 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001172
1173 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1174 {
1175 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1176 systemName);
1177 return;
1178 }
1179 // Ask for all objects implementing OperatingConfig so we can search
1180 // for one with a matching name
1181 constexpr std::array<std::string_view, 1> interfaces = {
1182 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1183 dbus::utility::getSubTree(
1184 "/xyz/openbmc_project/inventory", 0, interfaces,
1185 [asyncResp, cpuName, configName](
1186 const boost::system::error_code& ec,
1187 const dbus::utility::MapperGetSubTreeResponse& subtree) {
1188 if (ec)
1189 {
1190 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec,
1191 ec.message());
1192 messages::internalError(asyncResp->res);
1193 return;
1194 }
1195 const std::string expectedEnding =
1196 cpuName + '/' + configName;
1197 for (const auto& [objectPath, serviceMap] : subtree)
1198 {
1199 // Ignore any configs without matching cpuX/configY
1200 if (!objectPath.ends_with(expectedEnding) ||
1201 serviceMap.empty())
1202 {
1203 continue;
1204 }
1205
1206 nlohmann::json& json = asyncResp->res.jsonValue;
1207 json["@odata.type"] =
1208 "#OperatingConfig.v1_0_0.OperatingConfig";
1209 json["@odata.id"] = boost::urls::format(
1210 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
1211 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName,
1212 configName);
1213 json["Name"] = "Processor Profile";
1214 json["Id"] = configName;
1215
1216 // Just use the first implementation of the object - not
1217 // expected that there would be multiple matching
1218 // services
1219 getOperatingConfigData(
1220 asyncResp, serviceMap.begin()->first, objectPath);
1221 return;
1222 }
1223 messages::resourceNotFound(asyncResp->res,
1224 "OperatingConfig", configName);
1225 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001226 });
1227}
Jonathan Domandba0c292020-12-02 15:34:13 -08001228
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001229inline void requestRoutesProcessorCollection(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001230{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001231 /**
1232 * Functions triggers appropriate requests on DBus
1233 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001234 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001235 .privileges(redfish::privileges::headProcessorCollection)
1236 .methods(boost::beast::http::verb::head)(
1237 std::bind_front(handleProcessorCollectionHead, std::ref(app)));
1238
1239 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Ed Tanoused398212021-06-09 17:05:54 -07001240 .privileges(redfish::privileges::getProcessorCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001241 .methods(
1242 boost::beast::http::verb::
1243 get)([&app](const crow::Request& req,
1244 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1245 const std::string& systemName) {
1246 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1247 {
1248 return;
1249 }
1250 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1251 {
1252 // Option currently returns no systems. TBD
1253 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1254 systemName);
1255 return;
1256 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001257
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001258 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1259 {
1260 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1261 systemName);
1262 return;
1263 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001264
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001265 asyncResp->res.addHeader(
1266 boost::beast::http::field::link,
1267 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001268
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001269 asyncResp->res.jsonValue["@odata.type"] =
1270 "#ProcessorCollection.ProcessorCollection";
1271 asyncResp->res.jsonValue["Name"] = "Processor Collection";
Gunnar Millsac6a4442020-10-14 14:55:29 -05001272
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001273 asyncResp->res.jsonValue["@odata.id"] =
1274 std::format("/redfish/v1/Systems/{}/Processors",
1275 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Gunnar Millsac6a4442020-10-14 14:55:29 -05001276
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001277 collection_util::getCollectionMembers(
1278 asyncResp,
1279 boost::urls::format("/redfish/v1/Systems/{}/Processors",
1280 BMCWEB_REDFISH_SYSTEM_URI_NAME),
1281 processorInterfaces, "/xyz/openbmc_project/inventory");
1282 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001283}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001284
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001285inline void requestRoutesProcessor(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001286{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001287 /**
1288 * Functions triggers appropriate requests on DBus
1289 */
Gunnar Millsac6a4442020-10-14 14:55:29 -05001290
Ed Tanous22d268c2022-05-19 09:39:07 -07001291 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001292 .privileges(redfish::privileges::headProcessor)
1293 .methods(boost::beast::http::verb::head)(
1294 std::bind_front(handleProcessorHead, std::ref(app)));
1295
1296 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001297 .privileges(redfish::privileges::getProcessor)
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001298 .methods(
1299 boost::beast::http::verb::
1300 get)([&app](const crow::Request& req,
1301 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1302 const std::string& systemName,
1303 const std::string& processorId) {
1304 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1305 {
1306 return;
1307 }
1308 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1309 {
1310 // Option currently returns no systems. TBD
1311 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1312 systemName);
1313 return;
1314 }
1315 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1316 {
1317 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1318 systemName);
1319 return;
1320 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001321
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001322 asyncResp->res.addHeader(
1323 boost::beast::http::field::link,
1324 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1325 asyncResp->res.jsonValue["@odata.type"] =
1326 "#Processor.v1_18_0.Processor";
1327 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1328 "/redfish/v1/Systems/{}/Processors/{}",
1329 BMCWEB_REDFISH_SYSTEM_URI_NAME, processorId);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001330
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001331 getProcessorObject(
1332 asyncResp, processorId,
1333 std::bind_front(getProcessorData, asyncResp, processorId));
1334 });
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001335
Ed Tanous22d268c2022-05-19 09:39:07 -07001336 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001337 .privileges(redfish::privileges::patchProcessor)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001338 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001339 [&app](const crow::Request& req,
1340 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001341 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001342 const std::string& processorId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001343 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1344 {
1345 return;
1346 }
1347 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
1348 {
1349 // Option currently returns no systems. TBD
1350 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1351 systemName);
1352 return;
1353 }
1354 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
1355 {
1356 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1357 systemName);
1358 return;
1359 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001360
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001361 std::optional<std::string> appliedConfigUri;
1362 if (!json_util::readJsonPatch(
Patrick Williams504af5a2025-02-03 14:29:03 -05001363 req, asyncResp->res, //
Myung Baeafc474a2024-10-09 00:53:29 -07001364 "AppliedOperatingConfig/@odata.id", appliedConfigUri //
1365 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001366 {
1367 return;
1368 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001369
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001370 if (appliedConfigUri)
1371 {
1372 // Check for 404 and find matching D-Bus object, then run
1373 // property patch handlers if that all succeeds.
1374 getProcessorObject(
1375 asyncResp, processorId,
1376 std::bind_front(patchAppliedOperatingConfig, asyncResp,
1377 processorId, *appliedConfigUri));
1378 }
1379 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001380}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001381
1382} // namespace redfish