blob: b49f13b169b46f52e99edf150bd91a2fdd8ad472 [file] [log] [blame]
Gunnar Millsac6a4442020-10-14 14:55:29 -05001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
Jonathan Doman1e1e5982021-06-11 09:36:17 -070019#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080020#include "dbus_utility.hpp"
Jonathan Doman1e1e5982021-06-11 09:36:17 -070021#include "error_messages.hpp"
Chris Caindfbf7de2023-04-13 16:01:04 -050022#include "generated/enums/processor.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070023#include "generated/enums/resource.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080024#include "query.hpp"
25#include "registries/privilege_registry.hpp"
26#include "utils/collection.hpp"
27#include "utils/dbus_utils.hpp"
28#include "utils/json_utils.hpp"
Gunnar Millsac6a4442020-10-14 14:55:29 -050029
30#include <boost/container/flat_map.hpp>
George Liue99073f2022-12-09 11:06:16 +080031#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070032#include <boost/url/format.hpp>
Jonathan Doman1e1e5982021-06-11 09:36:17 -070033#include <sdbusplus/asio/property.hpp>
Jonathan Domandba0c292020-12-02 15:34:13 -080034#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelny351053f2022-07-28 15:44:22 +020035#include <sdbusplus/unpack_properties.hpp>
Jonathan Domandba0c292020-12-02 15:34:13 -080036#include <sdbusplus/utility/dedup_variant.hpp>
Gunnar Millsac6a4442020-10-14 14:55:29 -050037
George Liu7a1dbc42022-12-07 16:03:22 +080038#include <array>
Michael Shenb9d679d2023-02-13 02:29:04 +000039#include <limits>
Ed Tanous3544d2a2023-08-06 18:12:20 -070040#include <ranges>
Ed Tanous3c569212024-03-06 14:46:18 -080041#include <string>
George Liu7a1dbc42022-12-07 16:03:22 +080042#include <string_view>
43
Gunnar Millsac6a4442020-10-14 14:55:29 -050044namespace redfish
45{
46
Jonathan Domanc9514482021-02-24 09:20:51 -080047// Interfaces which imply a D-Bus object represents a Processor
George Liu7a1dbc42022-12-07 16:03:22 +080048constexpr std::array<std::string_view, 2> processorInterfaces = {
Jonathan Domanc9514482021-02-24 09:20:51 -080049 "xyz.openbmc_project.Inventory.Item.Cpu",
50 "xyz.openbmc_project.Inventory.Item.Accelerator"};
Jonathan Doman2bab9832020-12-02 15:27:40 -080051
Sharad Yadav71b82f22021-05-10 15:11:39 +053052/**
53 * @brief Fill out uuid info of a processor by
54 * requesting data from the given D-Bus object.
55 *
Ed Tanousac106bf2023-06-07 09:24:59 -070056 * @param[in,out] asyncResp Async HTTP response.
Sharad Yadav71b82f22021-05-10 15:11:39 +053057 * @param[in] service D-Bus service to query.
58 * @param[in] objPath D-Bus object to query.
59 */
Ed Tanousac106bf2023-06-07 09:24:59 -070060inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Sharad Yadav71b82f22021-05-10 15:11:39 +053061 const std::string& service,
62 const std::string& objPath)
63{
Ed Tanous62598e32023-07-17 17:06:25 -070064 BMCWEB_LOG_DEBUG("Get Processor UUID");
Jonathan Doman1e1e5982021-06-11 09:36:17 -070065 sdbusplus::asio::getProperty<std::string>(
66 *crow::connections::systemBus, service, objPath,
67 "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanousac106bf2023-06-07 09:24:59 -070068 [objPath, asyncResp{std::move(asyncResp)}](
69 const boost::system::error_code& ec, const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -070070 if (ec)
71 {
Ed Tanous62598e32023-07-17 17:06:25 -070072 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -070073 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -070074 return;
75 }
Ed Tanousac106bf2023-06-07 09:24:59 -070076 asyncResp->res.jsonValue["UUID"] = property;
Patrick Williams5a39f772023-10-20 11:20:21 -050077 });
Sharad Yadav71b82f22021-05-10 15:11:39 +053078}
79
Ed Tanous711ac7a2021-12-20 09:34:41 -080080inline void getCpuDataByInterface(
Ed Tanousac106bf2023-06-07 09:24:59 -070081 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Michael Shen80f79a42023-08-24 13:41:53 +000082 const dbus::utility::DBusInterfacesMap& cpuInterfacesProperties)
Gunnar Millsac6a4442020-10-14 14:55:29 -050083{
Ed Tanous62598e32023-07-17 17:06:25 -070084 BMCWEB_LOG_DEBUG("Get CPU resources by interface.");
Gunnar Millsac6a4442020-10-14 14:55:29 -050085
Chicago Duana1649ec2021-03-30 16:54:58 +080086 // Set the default value of state
Ed Tanous539d8c62024-06-19 14:38:27 -070087 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
88 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Gunnar Millsac6a4442020-10-14 14:55:29 -050089
90 for (const auto& interface : cpuInterfacesProperties)
91 {
92 for (const auto& property : interface.second)
93 {
Chicago Duana1649ec2021-03-30 16:54:58 +080094 if (property.first == "Present")
Gunnar Millsac6a4442020-10-14 14:55:29 -050095 {
Chicago Duana1649ec2021-03-30 16:54:58 +080096 const bool* cpuPresent = std::get_if<bool>(&property.second);
97 if (cpuPresent == nullptr)
Gunnar Millsac6a4442020-10-14 14:55:29 -050098 {
99 // Important property not in desired type
Ed Tanousac106bf2023-06-07 09:24:59 -0700100 messages::internalError(asyncResp->res);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500101 return;
102 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800103 if (!*cpuPresent)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500104 {
Chicago Duana1649ec2021-03-30 16:54:58 +0800105 // Slot is not populated
Ed Tanous539d8c62024-06-19 14:38:27 -0700106 asyncResp->res.jsonValue["Status"]["State"] =
107 resource::State::Absent;
Chicago Duana1649ec2021-03-30 16:54:58 +0800108 }
109 }
110 else if (property.first == "Functional")
111 {
112 const bool* cpuFunctional = std::get_if<bool>(&property.second);
113 if (cpuFunctional == nullptr)
114 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700115 messages::internalError(asyncResp->res);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500116 return;
117 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800118 if (!*cpuFunctional)
Chicago Duana1649ec2021-03-30 16:54:58 +0800119 {
Ed Tanous539d8c62024-06-19 14:38:27 -0700120 asyncResp->res.jsonValue["Status"]["Health"] =
121 resource::Health::Critical;
Chicago Duana1649ec2021-03-30 16:54:58 +0800122 }
123 }
124 else if (property.first == "CoreCount")
125 {
126 const uint16_t* coresCount =
127 std::get_if<uint16_t>(&property.second);
128 if (coresCount == nullptr)
129 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700130 messages::internalError(asyncResp->res);
Chicago Duana1649ec2021-03-30 16:54:58 +0800131 return;
132 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700133 asyncResp->res.jsonValue["TotalCores"] = *coresCount;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500134 }
Jonathan Domandc3fa662020-10-26 23:10:24 -0700135 else if (property.first == "MaxSpeedInMhz")
136 {
137 const uint32_t* value = std::get_if<uint32_t>(&property.second);
138 if (value != nullptr)
139 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700140 asyncResp->res.jsonValue["MaxSpeedMHz"] = *value;
Jonathan Domandc3fa662020-10-26 23:10:24 -0700141 }
142 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500143 else if (property.first == "Socket")
144 {
145 const std::string* value =
146 std::get_if<std::string>(&property.second);
147 if (value != nullptr)
148 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700149 asyncResp->res.jsonValue["Socket"] = *value;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500150 }
151 }
152 else if (property.first == "ThreadCount")
153 {
Jonathan Domandc3fa662020-10-26 23:10:24 -0700154 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500155 if (value != nullptr)
156 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700157 asyncResp->res.jsonValue["TotalThreads"] = *value;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500158 }
159 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700160 else if (property.first == "EffectiveFamily")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500161 {
Brandon Kim1930fbd2021-09-14 17:52:51 -0700162 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Brad Bishop6169de22022-09-14 13:08:32 -0400163 if (value != nullptr && *value != 2)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500164 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700165 asyncResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800166 "0x" + intToHexString(*value, 4);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500167 }
168 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700169 else if (property.first == "EffectiveModel")
170 {
171 const uint16_t* value = std::get_if<uint16_t>(&property.second);
172 if (value == nullptr)
173 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700174 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700175 return;
176 }
Brad Bishop6169de22022-09-14 13:08:32 -0400177 if (*value != 0)
178 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700179 asyncResp->res.jsonValue["ProcessorId"]["EffectiveModel"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400180 "0x" + intToHexString(*value, 4);
181 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700182 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500183 else if (property.first == "Id")
184 {
185 const uint64_t* value = std::get_if<uint64_t>(&property.second);
186 if (value != nullptr && *value != 0)
187 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700188 asyncResp->res
Gunnar Millsac6a4442020-10-14 14:55:29 -0500189 .jsonValue["ProcessorId"]["IdentificationRegisters"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800190 "0x" + intToHexString(*value, 16);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500191 }
192 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700193 else if (property.first == "Microcode")
194 {
195 const uint32_t* value = std::get_if<uint32_t>(&property.second);
196 if (value == nullptr)
197 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700198 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700199 return;
200 }
Brad Bishop6169de22022-09-14 13:08:32 -0400201 if (*value != 0)
202 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700203 asyncResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400204 "0x" + intToHexString(*value, 8);
205 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700206 }
207 else if (property.first == "Step")
208 {
209 const uint16_t* value = std::get_if<uint16_t>(&property.second);
210 if (value == nullptr)
211 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700212 messages::internalError(asyncResp->res);
Brandon Kim1930fbd2021-09-14 17:52:51 -0700213 return;
214 }
Michael Shenb9d679d2023-02-13 02:29:04 +0000215 if (*value != std::numeric_limits<uint16_t>::max())
Brad Bishop6169de22022-09-14 13:08:32 -0400216 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700217 asyncResp->res.jsonValue["ProcessorId"]["Step"] =
Brad Bishop6169de22022-09-14 13:08:32 -0400218 "0x" + intToHexString(*value, 4);
219 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700220 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500221 }
222 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500223}
224
Ed Tanousac106bf2023-06-07 09:24:59 -0700225inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500226 const std::string& cpuId,
227 const std::string& service,
228 const std::string& objPath)
229{
Ed Tanous62598e32023-07-17 17:06:25 -0700230 BMCWEB_LOG_DEBUG("Get available system cpu resources by service.");
Gunnar Millsac6a4442020-10-14 14:55:29 -0500231
George Liu5eb468d2023-06-20 17:03:24 +0800232 sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
233 dbus::utility::getManagedObjects(
234 service, path,
Ed Tanousac106bf2023-06-07 09:24:59 -0700235 [cpuId, service, objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800236 const boost::system::error_code& ec,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500237 const dbus::utility::ManagedObjectType& dbusData) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700238 if (ec)
239 {
Ed Tanous62598e32023-07-17 17:06:25 -0700240 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700241 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700242 return;
243 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700244 asyncResp->res.jsonValue["Id"] = cpuId;
245 asyncResp->res.jsonValue["Name"] = "Processor";
Ed Tanous539d8c62024-06-19 14:38:27 -0700246 asyncResp->res.jsonValue["ProcessorType"] =
247 processor::ProcessorType::CPU;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500248
Ed Tanous002d39b2022-05-31 08:59:27 -0700249 bool slotPresent = false;
250 std::string corePath = objPath + "/core";
251 size_t totalCores = 0;
252 for (const auto& object : dbusData)
253 {
254 if (object.first.str == objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500255 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700256 getCpuDataByInterface(asyncResp, object.second);
Ed Tanous002d39b2022-05-31 08:59:27 -0700257 }
Ed Tanous11ba3972022-07-11 09:50:41 -0700258 else if (object.first.str.starts_with(corePath))
Ed Tanous002d39b2022-05-31 08:59:27 -0700259 {
260 for (const auto& interface : object.second)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500261 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700262 if (interface.first == "xyz.openbmc_project.Inventory.Item")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500263 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700264 for (const auto& property : interface.second)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500265 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700266 if (property.first == "Present")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500267 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700268 const bool* present =
269 std::get_if<bool>(&property.second);
270 if (present != nullptr)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500271 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700272 if (*present)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500273 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700274 slotPresent = true;
275 totalCores++;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500276 }
277 }
278 }
279 }
280 }
281 }
282 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700283 }
284 // In getCpuDataByInterface(), state and health are set
285 // based on the present and functional status. If core
286 // count is zero, then it has a higher precedence.
287 if (slotPresent)
288 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700289 asyncResp->res.jsonValue["TotalCores"] = totalCores;
Ed Tanous002d39b2022-05-31 08:59:27 -0700290 }
291 return;
Patrick Williams5a39f772023-10-20 11:20:21 -0500292 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500293}
294
Chris Caindfbf7de2023-04-13 16:01:04 -0500295/**
296 * @brief Translates throttle cause DBUS property to redfish.
297 *
298 * @param[in] dbusSource The throttle cause from DBUS
299 *
300 * @return Returns as a string, the throttle cause in Redfish terms. If
301 * translation cannot be done, returns "Unknown" throttle reason.
302 */
303inline processor::ThrottleCause
304 dbusToRfThrottleCause(const std::string& dbusSource)
305{
306 if (dbusSource ==
307 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ClockLimit")
308 {
309 return processor::ThrottleCause::ClockLimit;
310 }
311 if (dbusSource ==
312 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ManagementDetectedFault")
313 {
314 return processor::ThrottleCause::ManagementDetectedFault;
315 }
316 if (dbusSource ==
317 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.PowerLimit")
318 {
319 return processor::ThrottleCause::PowerLimit;
320 }
321 if (dbusSource ==
322 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ThermalLimit")
323 {
324 return processor::ThrottleCause::ThermalLimit;
325 }
326 if (dbusSource ==
327 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.Unknown")
328 {
329 return processor::ThrottleCause::Unknown;
330 }
331 return processor::ThrottleCause::Invalid;
332}
333
334inline void
Ed Tanousac106bf2023-06-07 09:24:59 -0700335 readThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Chris Caindfbf7de2023-04-13 16:01:04 -0500336 const boost::system::error_code& ec,
337 const dbus::utility::DBusPropertiesMap& properties)
338{
339 if (ec)
340 {
Ed Tanous62598e32023-07-17 17:06:25 -0700341 BMCWEB_LOG_ERROR("Processor Throttle getAllProperties error {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -0700342 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500343 return;
344 }
345
346 const bool* status = nullptr;
347 const std::vector<std::string>* causes = nullptr;
348
349 if (!sdbusplus::unpackPropertiesNoThrow(dbus_utils::UnpackErrorPrinter(),
350 properties, "Throttled", status,
351 "ThrottleCauses", causes))
352 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700353 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500354 return;
355 }
356
Ed Tanousac106bf2023-06-07 09:24:59 -0700357 asyncResp->res.jsonValue["Throttled"] = *status;
Chris Caindfbf7de2023-04-13 16:01:04 -0500358 nlohmann::json::array_t rCauses;
359 for (const std::string& cause : *causes)
360 {
361 processor::ThrottleCause rfCause = dbusToRfThrottleCause(cause);
362 if (rfCause == processor::ThrottleCause::Invalid)
363 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700364 messages::internalError(asyncResp->res);
Chris Caindfbf7de2023-04-13 16:01:04 -0500365 return;
366 }
367
368 rCauses.emplace_back(rfCause);
369 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700370 asyncResp->res.jsonValue["ThrottleCauses"] = std::move(rCauses);
Chris Caindfbf7de2023-04-13 16:01:04 -0500371}
372
373inline void
Ed Tanousac106bf2023-06-07 09:24:59 -0700374 getThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Chris Caindfbf7de2023-04-13 16:01:04 -0500375 const std::string& service,
376 const std::string& objectPath)
377{
Ed Tanous62598e32023-07-17 17:06:25 -0700378 BMCWEB_LOG_DEBUG("Get processor throttle resources");
Chris Caindfbf7de2023-04-13 16:01:04 -0500379
380 sdbusplus::asio::getAllProperties(
381 *crow::connections::systemBus, service, objectPath,
382 "xyz.openbmc_project.Control.Power.Throttle",
Ed Tanousac106bf2023-06-07 09:24:59 -0700383 [asyncResp](const boost::system::error_code& ec,
384 const dbus::utility::DBusPropertiesMap& properties) {
385 readThrottleProperties(asyncResp, ec, properties);
Patrick Williams5a39f772023-10-20 11:20:21 -0500386 });
Chris Caindfbf7de2023-04-13 16:01:04 -0500387}
388
Ed Tanousac106bf2023-06-07 09:24:59 -0700389inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500390 const std::string& service,
391 const std::string& objPath)
392{
Ed Tanous62598e32023-07-17 17:06:25 -0700393 BMCWEB_LOG_DEBUG("Get Cpu Asset Data");
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200394 sdbusplus::asio::getAllProperties(
395 *crow::connections::systemBus, service, objPath,
396 "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanousac106bf2023-06-07 09:24:59 -0700397 [objPath, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800398 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200399 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700400 if (ec)
401 {
Ed Tanous62598e32023-07-17 17:06:25 -0700402 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700403 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700404 return;
405 }
406
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200407 const std::string* serialNumber = nullptr;
408 const std::string* model = nullptr;
409 const std::string* manufacturer = nullptr;
410 const std::string* partNumber = nullptr;
411 const std::string* sparePartNumber = nullptr;
412
413 const bool success = sdbusplus::unpackPropertiesNoThrow(
414 dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber",
415 serialNumber, "Model", model, "Manufacturer", manufacturer,
416 "PartNumber", partNumber, "SparePartNumber", sparePartNumber);
417
418 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700419 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700420 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200421 return;
422 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700423
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200424 if (serialNumber != nullptr && !serialNumber->empty())
425 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700426 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200427 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700428
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200429 if ((model != nullptr) && !model->empty())
430 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700431 asyncResp->res.jsonValue["Model"] = *model;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200432 }
433
434 if (manufacturer != nullptr)
435 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700436 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200437
438 // Otherwise would be unexpected.
439 if (manufacturer->find("Intel") != std::string::npos)
Ed Tanous002d39b2022-05-31 08:59:27 -0700440 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700441 asyncResp->res.jsonValue["ProcessorArchitecture"] = "x86";
442 asyncResp->res.jsonValue["InstructionSet"] = "x86-64";
Ed Tanous002d39b2022-05-31 08:59:27 -0700443 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200444 else if (manufacturer->find("IBM") != std::string::npos)
Ed Tanous002d39b2022-05-31 08:59:27 -0700445 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700446 asyncResp->res.jsonValue["ProcessorArchitecture"] = "Power";
447 asyncResp->res.jsonValue["InstructionSet"] = "PowerISA";
Ed Tanous002d39b2022-05-31 08:59:27 -0700448 }
449 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200450
451 if (partNumber != nullptr)
452 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700453 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200454 }
455
Brad Bishop6169de22022-09-14 13:08:32 -0400456 if (sparePartNumber != nullptr && !sparePartNumber->empty())
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200457 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700458 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200459 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500460 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500461}
462
Ed Tanousac106bf2023-06-07 09:24:59 -0700463inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500464 const std::string& service,
465 const std::string& objPath)
466{
Ed Tanous62598e32023-07-17 17:06:25 -0700467 BMCWEB_LOG_DEBUG("Get Cpu Revision Data");
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200468 sdbusplus::asio::getAllProperties(
469 *crow::connections::systemBus, service, objPath,
470 "xyz.openbmc_project.Inventory.Decorator.Revision",
Ed Tanousac106bf2023-06-07 09:24:59 -0700471 [objPath, 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) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700474 if (ec)
475 {
Ed Tanous62598e32023-07-17 17:06:25 -0700476 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700477 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700478 return;
479 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500480
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200481 const std::string* version = nullptr;
482
483 const bool success = sdbusplus::unpackPropertiesNoThrow(
484 dbus_utils::UnpackErrorPrinter(), properties, "Version", version);
485
486 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700487 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700488 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200489 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700490 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200491
492 if (version != nullptr)
493 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700494 asyncResp->res.jsonValue["Version"] = *version;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200495 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500496 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500497}
498
zhanghch058d1b46d2021-04-01 11:18:24 +0800499inline void getAcceleratorDataByService(
Ed Tanousac106bf2023-06-07 09:24:59 -0700500 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& acclrtrId,
zhanghch058d1b46d2021-04-01 11:18:24 +0800501 const std::string& service, const std::string& objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500502{
Ed Tanous62598e32023-07-17 17:06:25 -0700503 BMCWEB_LOG_DEBUG("Get available system Accelerator resources by service.");
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200504 sdbusplus::asio::getAllProperties(
505 *crow::connections::systemBus, service, objPath, "",
Ed Tanousac106bf2023-06-07 09:24:59 -0700506 [acclrtrId, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800507 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200508 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700509 if (ec)
510 {
Ed Tanous62598e32023-07-17 17:06:25 -0700511 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700512 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700513 return;
514 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700515
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200516 const bool* functional = nullptr;
517 const bool* present = nullptr;
518
519 const bool success = sdbusplus::unpackPropertiesNoThrow(
520 dbus_utils::UnpackErrorPrinter(), properties, "Functional",
521 functional, "Present", present);
522
523 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700524 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700525 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200526 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700527 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500528
Ed Tanous002d39b2022-05-31 08:59:27 -0700529 std::string state = "Enabled";
530 std::string health = "OK";
Gunnar Millsac6a4442020-10-14 14:55:29 -0500531
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200532 if (present != nullptr && !*present)
Ed Tanous002d39b2022-05-31 08:59:27 -0700533 {
534 state = "Absent";
535 }
536
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200537 if (functional != nullptr && !*functional)
Ed Tanous002d39b2022-05-31 08:59:27 -0700538 {
539 if (state == "Enabled")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500540 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700541 health = "Critical";
Gunnar Millsac6a4442020-10-14 14:55:29 -0500542 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700543 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500544
Ed Tanousac106bf2023-06-07 09:24:59 -0700545 asyncResp->res.jsonValue["Id"] = acclrtrId;
546 asyncResp->res.jsonValue["Name"] = "Processor";
547 asyncResp->res.jsonValue["Status"]["State"] = state;
548 asyncResp->res.jsonValue["Status"]["Health"] = health;
Ed Tanous539d8c62024-06-19 14:38:27 -0700549 asyncResp->res.jsonValue["ProcessorType"] =
550 processor::ProcessorType::Accelerator;
Patrick Williams5a39f772023-10-20 11:20:21 -0500551 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500552}
553
Jonathan Domandba0c292020-12-02 15:34:13 -0800554// OperatingConfig D-Bus Types
555using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>;
556using BaseSpeedPrioritySettingsProperty =
557 std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>;
558// uint32_t and size_t may or may not be the same type, requiring a dedup'd
559// variant
Jonathan Domandba0c292020-12-02 15:34:13 -0800560
561/**
562 * Fill out the HighSpeedCoreIDs in a Processor resource from the given
563 * OperatingConfig D-Bus property.
564 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700565 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800566 * @param[in] baseSpeedSettings Full list of base speed priority groups,
567 * to use to determine the list of high
568 * speed cores.
569 */
570inline void highSpeedCoreIdsHandler(
Ed Tanousac106bf2023-06-07 09:24:59 -0700571 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Domandba0c292020-12-02 15:34:13 -0800572 const BaseSpeedPrioritySettingsProperty& baseSpeedSettings)
573{
574 // The D-Bus property does not indicate which bucket is the "high
575 // priority" group, so let's discern that by looking for the one with
576 // highest base frequency.
577 auto highPriorityGroup = baseSpeedSettings.cend();
578 uint32_t highestBaseSpeed = 0;
579 for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend();
580 ++it)
581 {
582 const uint32_t baseFreq = std::get<uint32_t>(*it);
583 if (baseFreq > highestBaseSpeed)
584 {
585 highestBaseSpeed = baseFreq;
586 highPriorityGroup = it;
587 }
588 }
589
Ed Tanousac106bf2023-06-07 09:24:59 -0700590 nlohmann::json& jsonCoreIds = asyncResp->res.jsonValue["HighSpeedCoreIDs"];
Jonathan Domandba0c292020-12-02 15:34:13 -0800591 jsonCoreIds = nlohmann::json::array();
592
593 // There may not be any entries in the D-Bus property, so only populate
594 // if there was actually something there.
595 if (highPriorityGroup != baseSpeedSettings.cend())
596 {
597 jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup);
598 }
599}
600
601/**
602 * Fill out OperatingConfig related items in a Processor resource by requesting
603 * data from the given D-Bus object.
604 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700605 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800606 * @param[in] cpuId CPU D-Bus name.
607 * @param[in] service D-Bus service to query.
608 * @param[in] objPath D-Bus object to query.
609 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700610inline void
611 getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
612 const std::string& cpuId, const std::string& service,
613 const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800614{
Ed Tanous62598e32023-07-17 17:06:25 -0700615 BMCWEB_LOG_INFO("Getting CPU operating configs for {}", cpuId);
Jonathan Domandba0c292020-12-02 15:34:13 -0800616
617 // First, GetAll CurrentOperatingConfig properties on the object
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200618 sdbusplus::asio::getAllProperties(
619 *crow::connections::systemBus, service, objPath,
620 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700621 [asyncResp, cpuId,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800622 service](const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200623 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700624 if (ec)
625 {
Ed Tanous62598e32023-07-17 17:06:25 -0700626 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
Ed Tanousac106bf2023-06-07 09:24:59 -0700627 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700628 return;
629 }
Jonathan Domandba0c292020-12-02 15:34:13 -0800630
Ed Tanousac106bf2023-06-07 09:24:59 -0700631 nlohmann::json& json = asyncResp->res.jsonValue;
Jonathan Domandba0c292020-12-02 15:34:13 -0800632
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200633 const sdbusplus::message::object_path* appliedConfig = nullptr;
634 const bool* baseSpeedPriorityEnabled = nullptr;
635
636 const bool success = sdbusplus::unpackPropertiesNoThrow(
637 dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig",
638 appliedConfig, "BaseSpeedPriorityEnabled",
639 baseSpeedPriorityEnabled);
640
641 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700642 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700643 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200644 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700645 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200646
647 if (appliedConfig != nullptr)
648 {
649 const std::string& dbusPath = appliedConfig->str;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200650 nlohmann::json::object_t operatingConfig;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700651 operatingConfig["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -0700652 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
653 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200654 json["OperatingConfigs"] = std::move(operatingConfig);
655
656 // Reuse the D-Bus config object name for the Redfish
657 // URI
658 size_t baseNamePos = dbusPath.rfind('/');
659 if (baseNamePos == std::string::npos ||
660 baseNamePos == (dbusPath.size() - 1))
661 {
662 // If the AppliedConfig was somehow not a valid path,
663 // skip adding any more properties, since everything
664 // else is tied to this applied config.
Ed Tanousac106bf2023-06-07 09:24:59 -0700665 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200666 return;
667 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200668 nlohmann::json::object_t appliedOperatingConfig;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700669 appliedOperatingConfig["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -0700670 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
671 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuId,
672 dbusPath.substr(baseNamePos + 1));
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200673 json["AppliedOperatingConfig"] = std::move(appliedOperatingConfig);
674
675 // Once we found the current applied config, queue another
676 // request to read the base freq core ids out of that
677 // config.
678 sdbusplus::asio::getProperty<BaseSpeedPrioritySettingsProperty>(
679 *crow::connections::systemBus, service, dbusPath,
680 "xyz.openbmc_project.Inventory.Item.Cpu."
681 "OperatingConfig",
682 "BaseSpeedPrioritySettings",
Ed Tanousac106bf2023-06-07 09:24:59 -0700683 [asyncResp](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800684 const boost::system::error_code& ec2,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200685 const BaseSpeedPrioritySettingsProperty& baseSpeedList) {
686 if (ec2)
687 {
Ed Tanous62598e32023-07-17 17:06:25 -0700688 BMCWEB_LOG_WARNING("D-Bus Property Get error: {}", ec2);
Ed Tanousac106bf2023-06-07 09:24:59 -0700689 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200690 return;
691 }
692
Ed Tanousac106bf2023-06-07 09:24:59 -0700693 highSpeedCoreIdsHandler(asyncResp, baseSpeedList);
Patrick Williams5a39f772023-10-20 11:20:21 -0500694 });
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200695 }
696
697 if (baseSpeedPriorityEnabled != nullptr)
698 {
699 json["BaseSpeedPriorityState"] =
700 *baseSpeedPriorityEnabled ? "Enabled" : "Disabled";
701 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500702 });
Jonathan Domandba0c292020-12-02 15:34:13 -0800703}
704
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600705/**
706 * @brief Fill out location info of a processor by
707 * requesting data from the given D-Bus object.
708 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700709 * @param[in,out] asyncResp Async HTTP response.
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600710 * @param[in] service D-Bus service to query.
711 * @param[in] objPath D-Bus object to query.
712 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700713inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600714 const std::string& service,
715 const std::string& objPath)
716{
Ed Tanous62598e32023-07-17 17:06:25 -0700717 BMCWEB_LOG_DEBUG("Get Cpu Location Data");
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700718 sdbusplus::asio::getProperty<std::string>(
719 *crow::connections::systemBus, service, objPath,
720 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700721 [objPath, asyncResp{std::move(asyncResp)}](
722 const boost::system::error_code& ec, const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700723 if (ec)
724 {
Ed Tanous62598e32023-07-17 17:06:25 -0700725 BMCWEB_LOG_DEBUG("DBUS response error");
Ed Tanousac106bf2023-06-07 09:24:59 -0700726 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700727 return;
728 }
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600729
Ed Tanousac106bf2023-06-07 09:24:59 -0700730 asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
Ed Tanous002d39b2022-05-31 08:59:27 -0700731 property;
Patrick Williams5a39f772023-10-20 11:20:21 -0500732 });
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600733}
734
Jonathan Domanc9514482021-02-24 09:20:51 -0800735/**
Jonathan Doman49e429c2021-03-03 13:11:44 -0800736 * Populate the unique identifier in a Processor resource by requesting data
737 * from the given D-Bus object.
738 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700739 * @param[in,out] asyncResp Async HTTP response.
Jonathan Doman49e429c2021-03-03 13:11:44 -0800740 * @param[in] service D-Bus service to query.
741 * @param[in] objPath D-Bus object to query.
742 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700743inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Jonathan Doman49e429c2021-03-03 13:11:44 -0800744 const std::string& service,
745 const std::string& objectPath)
746{
Ed Tanous62598e32023-07-17 17:06:25 -0700747 BMCWEB_LOG_DEBUG("Get CPU UniqueIdentifier");
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700748 sdbusplus::asio::getProperty<std::string>(
749 *crow::connections::systemBus, service, objectPath,
750 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
751 "UniqueIdentifier",
Ed Tanousac106bf2023-06-07 09:24:59 -0700752 [asyncResp](const boost::system::error_code& ec,
753 const std::string& id) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700754 if (ec)
755 {
Ed Tanous62598e32023-07-17 17:06:25 -0700756 BMCWEB_LOG_ERROR("Failed to read cpu unique id: {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -0700757 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700758 return;
759 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700760 asyncResp->res
761 .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id;
Patrick Williams5a39f772023-10-20 11:20:21 -0500762 });
Jonathan Doman49e429c2021-03-03 13:11:44 -0800763}
764
765/**
Jonathan Domanc9514482021-02-24 09:20:51 -0800766 * Find the D-Bus object representing the requested Processor, and call the
767 * handler with the results. If matching object is not found, add 404 error to
768 * response and don't call the handler.
769 *
770 * @param[in,out] resp Async HTTP response.
771 * @param[in] processorId Redfish Processor Id.
772 * @param[in] handler Callback to continue processing request upon
773 * successfully finding object.
774 */
775template <typename Handler>
zhanghch058d1b46d2021-04-01 11:18:24 +0800776inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp,
Jonathan Domanc9514482021-02-24 09:20:51 -0800777 const std::string& processorId,
778 Handler&& handler)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500779{
Ed Tanous62598e32023-07-17 17:06:25 -0700780 BMCWEB_LOG_DEBUG("Get available system processor resources.");
Gunnar Millsac6a4442020-10-14 14:55:29 -0500781
Jonathan Domanc9514482021-02-24 09:20:51 -0800782 // GetSubTree on all interfaces which provide info about a Processor
Chris Caindfbf7de2023-04-13 16:01:04 -0500783 constexpr std::array<std::string_view, 9> interfaces = {
George Liue99073f2022-12-09 11:06:16 +0800784 "xyz.openbmc_project.Common.UUID",
785 "xyz.openbmc_project.Inventory.Decorator.Asset",
786 "xyz.openbmc_project.Inventory.Decorator.Revision",
787 "xyz.openbmc_project.Inventory.Item.Cpu",
788 "xyz.openbmc_project.Inventory.Decorator.LocationCode",
789 "xyz.openbmc_project.Inventory.Item.Accelerator",
790 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Chris Caindfbf7de2023-04-13 16:01:04 -0500791 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
792 "xyz.openbmc_project.Control.Power.Throttle"};
George Liue99073f2022-12-09 11:06:16 +0800793 dbus::utility::getSubTree(
794 "/xyz/openbmc_project/inventory", 0, interfaces,
Jonathan Domanc9514482021-02-24 09:20:51 -0800795 [resp, processorId, handler = std::forward<Handler>(handler)](
George Liue99073f2022-12-09 11:06:16 +0800796 const boost::system::error_code& ec,
797 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700798 if (ec)
799 {
Ed Tanous62598e32023-07-17 17:06:25 -0700800 BMCWEB_LOG_DEBUG("DBUS response error: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700801 messages::internalError(resp->res);
802 return;
803 }
804 for (const auto& [objectPath, serviceMap] : subtree)
805 {
806 // Ignore any objects which don't end with our desired cpu name
Ed Tanous11ba3972022-07-11 09:50:41 -0700807 if (!objectPath.ends_with(processorId))
Gunnar Millsac6a4442020-10-14 14:55:29 -0500808 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700809 continue;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500810 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700811
812 bool found = false;
813 // Filter out objects that don't have the CPU-specific
814 // interfaces to make sure we can return 404 on non-CPUs
815 // (e.g. /redfish/../Processors/dimm0)
816 for (const auto& [serviceName, interfaceList] : serviceMap)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500817 {
Ed Tanous3544d2a2023-08-06 18:12:20 -0700818 if (std::ranges::find_first_of(interfaceList,
819 processorInterfaces) !=
820 std::end(interfaceList))
Gunnar Millsac6a4442020-10-14 14:55:29 -0500821 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700822 found = true;
823 break;
Jonathan Doman2bab9832020-12-02 15:27:40 -0800824 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500825 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700826
827 if (!found)
828 {
829 continue;
830 }
831
832 // Process the first object which does match our cpu name and
833 // required interfaces, and potentially ignore any other
834 // matching objects. Assume all interfaces we want to process
835 // must be on the same object path.
836
Ed Tanous8a592812022-06-04 09:06:59 -0700837 handler(objectPath, serviceMap);
Ed Tanous002d39b2022-05-31 08:59:27 -0700838 return;
839 }
840 messages::resourceNotFound(resp->res, "Processor", processorId);
Patrick Williams5a39f772023-10-20 11:20:21 -0500841 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500842}
843
Ed Tanousac106bf2023-06-07 09:24:59 -0700844inline void
845 getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
846 const std::string& processorId,
847 const std::string& objectPath,
848 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Domanc9514482021-02-24 09:20:51 -0800849{
850 for (const auto& [serviceName, interfaceList] : serviceMap)
851 {
852 for (const auto& interface : interfaceList)
853 {
854 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
855 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700856 getCpuAssetData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800857 }
George Liu0fda0f12021-11-16 10:06:17 +0800858 else if (interface ==
859 "xyz.openbmc_project.Inventory.Decorator.Revision")
Jonathan Domanc9514482021-02-24 09:20:51 -0800860 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700861 getCpuRevisionData(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800862 }
863 else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu")
864 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700865 getCpuDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800866 objectPath);
867 }
George Liu0fda0f12021-11-16 10:06:17 +0800868 else if (interface ==
869 "xyz.openbmc_project.Inventory.Item.Accelerator")
Jonathan Domanc9514482021-02-24 09:20:51 -0800870 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700871 getAcceleratorDataByService(asyncResp, processorId, serviceName,
Jonathan Domanc9514482021-02-24 09:20:51 -0800872 objectPath);
873 }
George Liu0fda0f12021-11-16 10:06:17 +0800874 else if (
875 interface ==
876 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig")
Jonathan Domanc9514482021-02-24 09:20:51 -0800877 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700878 getCpuConfigData(asyncResp, processorId, serviceName,
879 objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800880 }
George Liu0fda0f12021-11-16 10:06:17 +0800881 else if (interface ==
882 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
Jonathan Domanc9514482021-02-24 09:20:51 -0800883 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700884 getCpuLocationCode(asyncResp, serviceName, objectPath);
Jonathan Domanc9514482021-02-24 09:20:51 -0800885 }
Sharad Yadav71b82f22021-05-10 15:11:39 +0530886 else if (interface == "xyz.openbmc_project.Common.UUID")
887 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700888 getProcessorUUID(asyncResp, serviceName, objectPath);
Sharad Yadav71b82f22021-05-10 15:11:39 +0530889 }
George Liu0fda0f12021-11-16 10:06:17 +0800890 else if (interface ==
891 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier")
Jonathan Doman49e429c2021-03-03 13:11:44 -0800892 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700893 getCpuUniqueId(asyncResp, serviceName, objectPath);
Jonathan Doman49e429c2021-03-03 13:11:44 -0800894 }
Chris Caindfbf7de2023-04-13 16:01:04 -0500895 else if (interface == "xyz.openbmc_project.Control.Power.Throttle")
896 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700897 getThrottleProperties(asyncResp, serviceName, objectPath);
Chris Caindfbf7de2023-04-13 16:01:04 -0500898 }
Jonathan Domanc9514482021-02-24 09:20:51 -0800899 }
900 }
901}
902
Jonathan Domandba0c292020-12-02 15:34:13 -0800903/**
904 * Request all the properties for the given D-Bus object and fill out the
905 * related entries in the Redfish OperatingConfig response.
906 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700907 * @param[in,out] asyncResp Async HTTP response.
Jonathan Domandba0c292020-12-02 15:34:13 -0800908 * @param[in] service D-Bus service name to query.
909 * @param[in] objPath D-Bus object to query.
910 */
zhanghch058d1b46d2021-04-01 11:18:24 +0800911inline void
Ed Tanousac106bf2023-06-07 09:24:59 -0700912 getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800913 const std::string& service,
914 const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800915{
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200916 sdbusplus::asio::getAllProperties(
917 *crow::connections::systemBus, service, objPath,
918 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
Ed Tanousac106bf2023-06-07 09:24:59 -0700919 [asyncResp](const boost::system::error_code& ec,
920 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700921 if (ec)
922 {
Ed Tanous62598e32023-07-17 17:06:25 -0700923 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
Ed Tanousac106bf2023-06-07 09:24:59 -0700924 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700925 return;
926 }
927
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200928 const size_t* availableCoreCount = nullptr;
929 const uint32_t* baseSpeed = nullptr;
930 const uint32_t* maxJunctionTemperature = nullptr;
931 const uint32_t* maxSpeed = nullptr;
932 const uint32_t* powerLimit = nullptr;
933 const TurboProfileProperty* turboProfile = nullptr;
934 const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings =
935 nullptr;
936
937 const bool success = sdbusplus::unpackPropertiesNoThrow(
938 dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount",
939 availableCoreCount, "BaseSpeed", baseSpeed,
940 "MaxJunctionTemperature", maxJunctionTemperature, "MaxSpeed",
941 maxSpeed, "PowerLimit", powerLimit, "TurboProfile", turboProfile,
942 "BaseSpeedPrioritySettings", baseSpeedPrioritySettings);
943
944 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700945 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700946 messages::internalError(asyncResp->res);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200947 return;
948 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700949
Ed Tanousac106bf2023-06-07 09:24:59 -0700950 nlohmann::json& json = asyncResp->res.jsonValue;
Ed Tanous002d39b2022-05-31 08:59:27 -0700951
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200952 if (availableCoreCount != nullptr)
953 {
954 json["TotalAvailableCoreCount"] = *availableCoreCount;
955 }
956
957 if (baseSpeed != nullptr)
958 {
959 json["BaseSpeedMHz"] = *baseSpeed;
960 }
961
962 if (maxJunctionTemperature != nullptr)
963 {
964 json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature;
965 }
966
967 if (maxSpeed != nullptr)
968 {
969 json["MaxSpeedMHz"] = *maxSpeed;
970 }
971
972 if (powerLimit != nullptr)
973 {
974 json["TDPWatts"] = *powerLimit;
975 }
976
977 if (turboProfile != nullptr)
978 {
979 nlohmann::json& turboArray = json["TurboProfile"];
980 turboArray = nlohmann::json::array();
981 for (const auto& [turboSpeed, coreCount] : *turboProfile)
982 {
983 nlohmann::json::object_t turbo;
984 turbo["ActiveCoreCount"] = coreCount;
985 turbo["MaxSpeedMHz"] = turboSpeed;
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500986 turboArray.emplace_back(std::move(turbo));
Ed Tanous002d39b2022-05-31 08:59:27 -0700987 }
988 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200989
990 if (baseSpeedPrioritySettings != nullptr)
991 {
992 nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"];
993 baseSpeedArray = nlohmann::json::array();
994 for (const auto& [baseSpeedMhz, coreList] :
995 *baseSpeedPrioritySettings)
996 {
997 nlohmann::json::object_t speed;
998 speed["CoreCount"] = coreList.size();
999 speed["CoreIDs"] = coreList;
1000 speed["BaseSpeedMHz"] = baseSpeedMhz;
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001001 baseSpeedArray.emplace_back(std::move(speed));
Krzysztof Grobelny351053f2022-07-28 15:44:22 +02001002 }
1003 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001004 });
Jonathan Domandba0c292020-12-02 15:34:13 -08001005}
1006
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001007/**
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001008 * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic
1009 * validation of the input data, and then set the D-Bus property.
1010 *
1011 * @param[in,out] resp Async HTTP response.
1012 * @param[in] processorId Processor's Id.
1013 * @param[in] appliedConfigUri New property value to apply.
1014 * @param[in] cpuObjectPath Path of CPU object to modify.
1015 * @param[in] serviceMap Service map for CPU object.
1016 */
1017inline void patchAppliedOperatingConfig(
1018 const std::shared_ptr<bmcweb::AsyncResp>& resp,
1019 const std::string& processorId, const std::string& appliedConfigUri,
Shantappa Teekappanavar5df6eda2022-01-18 12:29:28 -06001020 const std::string& cpuObjectPath,
1021 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001022{
1023 // Check that the property even exists by checking for the interface
1024 const std::string* controlService = nullptr;
1025 for (const auto& [serviceName, interfaceList] : serviceMap)
1026 {
Ed Tanous3544d2a2023-08-06 18:12:20 -07001027 if (std::ranges::find(interfaceList,
1028 "xyz.openbmc_project.Control.Processor."
1029 "CurrentOperatingConfig") != interfaceList.end())
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001030 {
1031 controlService = &serviceName;
1032 break;
1033 }
1034 }
1035
1036 if (controlService == nullptr)
1037 {
1038 messages::internalError(resp->res);
1039 return;
1040 }
1041
1042 // Check that the config URI is a child of the cpu URI being patched.
Ed Tanous253f11b2024-05-16 09:38:31 -07001043 std::string expectedPrefix(std::format("/redfish/v1/Systems/{}/Processors/",
1044 BMCWEB_REDFISH_SYSTEM_URI_NAME));
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001045 expectedPrefix += processorId;
1046 expectedPrefix += "/OperatingConfigs/";
Ed Tanous11ba3972022-07-11 09:50:41 -07001047 if (!appliedConfigUri.starts_with(expectedPrefix) ||
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001048 expectedPrefix.size() == appliedConfigUri.size())
1049 {
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001050 messages::propertyValueIncorrect(resp->res, "AppliedOperatingConfig",
1051 appliedConfigUri);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001052 return;
1053 }
1054
1055 // Generate the D-Bus path of the OperatingConfig object, by assuming it's a
1056 // direct child of the CPU object.
1057 // Strip the expectedPrefix from the config URI to get the "filename", and
1058 // append to the CPU's path.
1059 std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size());
1060 sdbusplus::message::object_path configPath(cpuObjectPath);
1061 configPath /= configBaseName;
1062
Ed Tanous62598e32023-07-17 17:06:25 -07001063 BMCWEB_LOG_INFO("Setting config to {}", configPath.str);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001064
1065 // Set the property, with handler to check error responses
Asmitha Karunanithi87c44962024-04-04 18:28:33 +00001066 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301067 resp, "AppliedOperatingConfig", *controlService, cpuObjectPath,
George Liu9ae226f2023-06-21 17:56:46 +08001068 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ginu Georgee93abac2024-06-14 17:35:27 +05301069 "AppliedConfig", configPath);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001070}
1071
Ed Tanousac106bf2023-06-07 09:24:59 -07001072inline void
1073 handleProcessorHead(crow::App& app, const crow::Request& req,
1074 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1075 const std::string& /* systemName */,
1076 const std::string& /* processorId */)
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001077{
Ed Tanousac106bf2023-06-07 09:24:59 -07001078 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001079 {
1080 return;
1081 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001082 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001083 boost::beast::http::field::link,
1084 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1085}
1086
1087inline void handleProcessorCollectionHead(
1088 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -07001089 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001090 const std::string& /* systemName */)
1091{
Ed Tanousac106bf2023-06-07 09:24:59 -07001092 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001093 {
1094 return;
1095 }
Ed Tanousac106bf2023-06-07 09:24:59 -07001096 asyncResp->res.addHeader(
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001097 boost::beast::http::field::link,
1098 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1099}
1100
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001101inline void requestRoutesOperatingConfigCollection(App& app)
Jonathan Domandba0c292020-12-02 15:34:13 -08001102{
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001103 BMCWEB_ROUTE(app,
1104 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/")
Ed Tanoused398212021-06-09 17:05:54 -07001105 .privileges(redfish::privileges::getOperatingConfigCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001106 .methods(boost::beast::http::verb::get)(
1107 [&app](const crow::Request& req,
1108 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001109 const std::string& systemName, const std::string& cpuName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001110 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001111 {
1112 return;
1113 }
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001114
Ed Tanous25b54db2024-04-17 15:40:31 -07001115 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001116 {
1117 // Option currently returns no systems. TBD
1118 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1119 systemName);
1120 return;
1121 }
1122
Ed Tanous253f11b2024-05-16 09:38:31 -07001123 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001124 {
1125 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1126 systemName);
1127 return;
1128 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001129 asyncResp->res.jsonValue["@odata.type"] =
1130 "#OperatingConfigCollection.OperatingConfigCollection";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001131 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001132 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1133 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001134 asyncResp->res.jsonValue["Name"] = "Operating Config Collection";
1135
1136 // First find the matching CPU object so we know how to
1137 // constrain our search for related Config objects.
George Liu7a1dbc42022-12-07 16:03:22 +08001138 const std::array<std::string_view, 1> interfaces = {
1139 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"};
1140 dbus::utility::getSubTreePaths(
1141 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -07001142 [asyncResp, cpuName](
George Liu7a1dbc42022-12-07 16:03:22 +08001143 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001144 const dbus::utility::MapperGetSubTreePathsResponse& objects) {
1145 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001146 {
Ed Tanous62598e32023-07-17 17:06:25 -07001147 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07001148 messages::internalError(asyncResp->res);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001149 return;
1150 }
Jonathan Domandba0c292020-12-02 15:34:13 -08001151
Ed Tanous002d39b2022-05-31 08:59:27 -07001152 for (const std::string& object : objects)
1153 {
Ed Tanous11ba3972022-07-11 09:50:41 -07001154 if (!object.ends_with(cpuName))
Ed Tanous002d39b2022-05-31 08:59:27 -07001155 {
1156 continue;
1157 }
George Liu0fda0f12021-11-16 10:06:17 +08001158
Ed Tanous002d39b2022-05-31 08:59:27 -07001159 // Not expected that there will be multiple matching
1160 // CPU objects, but if there are just use the first
1161 // one.
Jonathan Domandba0c292020-12-02 15:34:13 -08001162
Ed Tanous002d39b2022-05-31 08:59:27 -07001163 // Use the common search routine to construct the
1164 // Collection of all Config objects under this CPU.
Patrick Williams5a39f772023-10-20 11:20:21 -05001165 constexpr std::array<std::string_view, 1> interface{
1166 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
Ed Tanous002d39b2022-05-31 08:59:27 -07001167 collection_util::getCollectionMembers(
1168 asyncResp,
Ed Tanousef4c65b2023-04-24 15:28:50 -07001169 boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001170 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
1171 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName),
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -05001172 interface, object);
Ed Tanous002d39b2022-05-31 08:59:27 -07001173 return;
1174 }
George Liu0fda0f12021-11-16 10:06:17 +08001175 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001176 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001177}
1178
1179inline void requestRoutesOperatingConfig(App& app)
1180{
1181 BMCWEB_ROUTE(
1182 app,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001183 "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001184 .privileges(redfish::privileges::getOperatingConfig)
Ed Tanous002d39b2022-05-31 08:59:27 -07001185 .methods(boost::beast::http::verb::get)(
1186 [&app](const crow::Request& req,
1187 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001188 const std::string& systemName, const std::string& cpuName,
1189 const std::string& configName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001190 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001191 {
1192 return;
1193 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001194 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001195 {
1196 // Option currently returns no systems. TBD
1197 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1198 systemName);
1199 return;
1200 }
1201
Ed Tanous253f11b2024-05-16 09:38:31 -07001202 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001203 {
1204 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1205 systemName);
1206 return;
1207 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001208 // Ask for all objects implementing OperatingConfig so we can search
1209 // for one with a matching name
George Liue99073f2022-12-09 11:06:16 +08001210 constexpr std::array<std::string_view, 1> interfaces = {
1211 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1212 dbus::utility::getSubTree(
1213 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous39662a32023-02-06 15:09:46 -08001214 [asyncResp, cpuName, configName](
George Liue99073f2022-12-09 11:06:16 +08001215 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001216 const dbus::utility::MapperGetSubTreeResponse& subtree) {
1217 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001218 {
Ed Tanous62598e32023-07-17 17:06:25 -07001219 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
Ed Tanous002d39b2022-05-31 08:59:27 -07001220 messages::internalError(asyncResp->res);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001221 return;
1222 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001223 const std::string expectedEnding = cpuName + '/' + configName;
1224 for (const auto& [objectPath, serviceMap] : subtree)
1225 {
1226 // Ignore any configs without matching cpuX/configY
Ed Tanous11ba3972022-07-11 09:50:41 -07001227 if (!objectPath.ends_with(expectedEnding) || serviceMap.empty())
Ed Tanous002d39b2022-05-31 08:59:27 -07001228 {
1229 continue;
1230 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001231
Ed Tanous002d39b2022-05-31 08:59:27 -07001232 nlohmann::json& json = asyncResp->res.jsonValue;
1233 json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001234 json["@odata.id"] = boost::urls::format(
Ed Tanous253f11b2024-05-16 09:38:31 -07001235 "/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
1236 BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName, configName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001237 json["Name"] = "Processor Profile";
1238 json["Id"] = configName;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001239
Ed Tanous002d39b2022-05-31 08:59:27 -07001240 // Just use the first implementation of the object - not
1241 // expected that there would be multiple matching
1242 // services
1243 getOperatingConfigData(asyncResp, serviceMap.begin()->first,
1244 objectPath);
1245 return;
1246 }
1247 messages::resourceNotFound(asyncResp->res, "OperatingConfig",
1248 configName);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001249 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001250 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001251}
Jonathan Domandba0c292020-12-02 15:34:13 -08001252
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001253inline void requestRoutesProcessorCollection(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001254{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001255 /**
1256 * Functions triggers appropriate requests on DBus
1257 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001258 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001259 .privileges(redfish::privileges::headProcessorCollection)
1260 .methods(boost::beast::http::verb::head)(
1261 std::bind_front(handleProcessorCollectionHead, std::ref(app)));
1262
1263 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Ed Tanoused398212021-06-09 17:05:54 -07001264 .privileges(redfish::privileges::getProcessorCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001265 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001266 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001267 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1268 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001269 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001270 {
1271 return;
1272 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001273 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001274 {
1275 // Option currently returns no systems. TBD
1276 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1277 systemName);
1278 return;
1279 }
1280
Ed Tanous253f11b2024-05-16 09:38:31 -07001281 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001282 {
1283 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1284 systemName);
1285 return;
1286 }
1287
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001288 asyncResp->res.addHeader(
1289 boost::beast::http::field::link,
1290 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1291
Ed Tanous002d39b2022-05-31 08:59:27 -07001292 asyncResp->res.jsonValue["@odata.type"] =
1293 "#ProcessorCollection.ProcessorCollection";
1294 asyncResp->res.jsonValue["Name"] = "Processor Collection";
Gunnar Millsac6a4442020-10-14 14:55:29 -05001295
Ed Tanous002d39b2022-05-31 08:59:27 -07001296 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001297 std::format("/redfish/v1/Systems/{}/Processors",
1298 BMCWEB_REDFISH_SYSTEM_URI_NAME);
Gunnar Millsac6a4442020-10-14 14:55:29 -05001299
Ed Tanous002d39b2022-05-31 08:59:27 -07001300 collection_util::getCollectionMembers(
Willy Tuae9031f2022-09-27 05:48:07 +00001301 asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07001302 boost::urls::format("/redfish/v1/Systems/{}/Processors",
1303 BMCWEB_REDFISH_SYSTEM_URI_NAME),
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -05001304 processorInterfaces, "/xyz/openbmc_project/inventory");
Patrick Williams5a39f772023-10-20 11:20:21 -05001305 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001306}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001307
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001308inline void requestRoutesProcessor(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001309{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001310 /**
1311 * Functions triggers appropriate requests on DBus
1312 */
Gunnar Millsac6a4442020-10-14 14:55:29 -05001313
Ed Tanous22d268c2022-05-19 09:39:07 -07001314 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001315 .privileges(redfish::privileges::headProcessor)
1316 .methods(boost::beast::http::verb::head)(
1317 std::bind_front(handleProcessorHead, std::ref(app)));
1318
1319 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001320 .privileges(redfish::privileges::getProcessor)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001321 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001322 [&app](const crow::Request& req,
1323 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001324 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001325 const std::string& processorId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001326 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001327 {
1328 return;
1329 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001330 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001331 {
1332 // Option currently returns no systems. TBD
1333 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1334 systemName);
1335 return;
1336 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001337 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001338 {
1339 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1340 systemName);
1341 return;
1342 }
1343
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001344 asyncResp->res.addHeader(
1345 boost::beast::http::field::link,
1346 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
Ed Tanous002d39b2022-05-31 08:59:27 -07001347 asyncResp->res.jsonValue["@odata.type"] =
Chris Caindfbf7de2023-04-13 16:01:04 -05001348 "#Processor.v1_18_0.Processor";
Ed Tanous253f11b2024-05-16 09:38:31 -07001349 asyncResp->res.jsonValue["@odata.id"] =
1350 boost::urls::format("/redfish/v1/Systems/{}/Processors/{}",
1351 BMCWEB_REDFISH_SYSTEM_URI_NAME, processorId);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001352
Ed Tanous8a592812022-06-04 09:06:59 -07001353 getProcessorObject(
1354 asyncResp, processorId,
1355 std::bind_front(getProcessorData, asyncResp, processorId));
Patrick Williams5a39f772023-10-20 11:20:21 -05001356 });
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001357
Ed Tanous22d268c2022-05-19 09:39:07 -07001358 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001359 .privileges(redfish::privileges::patchProcessor)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001360 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001361 [&app](const crow::Request& req,
1362 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001363 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001364 const std::string& processorId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001365 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001366 {
1367 return;
1368 }
Ed Tanous25b54db2024-04-17 15:40:31 -07001369 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -08001370 {
1371 // Option currently returns no systems. TBD
1372 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1373 systemName);
1374 return;
1375 }
Ed Tanous253f11b2024-05-16 09:38:31 -07001376 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -07001377 {
1378 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1379 systemName);
1380 return;
1381 }
1382
Ed Tanous3c569212024-03-06 14:46:18 -08001383 std::optional<std::string> appliedConfigUri;
Ed Tanous002d39b2022-05-31 08:59:27 -07001384 if (!json_util::readJsonPatch(req, asyncResp->res,
Ed Tanous3c569212024-03-06 14:46:18 -08001385 "AppliedOperatingConfig/@odata.id",
1386 appliedConfigUri))
Ed Tanous002d39b2022-05-31 08:59:27 -07001387 {
1388 return;
1389 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001390
Ed Tanous3c569212024-03-06 14:46:18 -08001391 if (appliedConfigUri)
Ed Tanous002d39b2022-05-31 08:59:27 -07001392 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001393 // Check for 404 and find matching D-Bus object, then run
1394 // property patch handlers if that all succeeds.
Ed Tanous8a592812022-06-04 09:06:59 -07001395 getProcessorObject(asyncResp, processorId,
1396 std::bind_front(patchAppliedOperatingConfig,
1397 asyncResp, processorId,
Ed Tanous3c569212024-03-06 14:46:18 -08001398 *appliedConfigUri));
Ed Tanous002d39b2022-05-31 08:59:27 -07001399 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001400 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001401}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001402
1403} // namespace redfish