blob: 90938c9d25cfcbb06f3c13e3f0b372ceff490373 [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"
Gunnar Millsac6a4442020-10-14 14:55:29 -050023#include "health.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>
George Liu7a1dbc42022-12-07 16:03:22 +080040#include <string_view>
41
Gunnar Millsac6a4442020-10-14 14:55:29 -050042namespace redfish
43{
44
Jonathan Domanc9514482021-02-24 09:20:51 -080045// Interfaces which imply a D-Bus object represents a Processor
George Liu7a1dbc42022-12-07 16:03:22 +080046constexpr std::array<std::string_view, 2> processorInterfaces = {
Jonathan Domanc9514482021-02-24 09:20:51 -080047 "xyz.openbmc_project.Inventory.Item.Cpu",
48 "xyz.openbmc_project.Inventory.Item.Accelerator"};
Jonathan Doman2bab9832020-12-02 15:27:40 -080049
Sharad Yadav71b82f22021-05-10 15:11:39 +053050/**
51 * @brief Fill out uuid info of a processor by
52 * requesting data from the given D-Bus object.
53 *
54 * @param[in,out] aResp Async HTTP response.
55 * @param[in] service D-Bus service to query.
56 * @param[in] objPath D-Bus object to query.
57 */
58inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp,
59 const std::string& service,
60 const std::string& objPath)
61{
62 BMCWEB_LOG_DEBUG << "Get Processor UUID";
Jonathan Doman1e1e5982021-06-11 09:36:17 -070063 sdbusplus::asio::getProperty<std::string>(
64 *crow::connections::systemBus, service, objPath,
65 "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080066 [objPath, aResp{std::move(aResp)}](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -070067 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -070068 if (ec)
69 {
70 BMCWEB_LOG_DEBUG << "DBUS response error";
71 messages::internalError(aResp->res);
72 return;
73 }
74 aResp->res.jsonValue["UUID"] = property;
Jonathan Doman1e1e5982021-06-11 09:36:17 -070075 });
Sharad Yadav71b82f22021-05-10 15:11:39 +053076}
77
Ed Tanous711ac7a2021-12-20 09:34:41 -080078inline void getCpuDataByInterface(
79 const std::shared_ptr<bmcweb::AsyncResp>& aResp,
80 const dbus::utility::DBusInteracesMap& cpuInterfacesProperties)
Gunnar Millsac6a4442020-10-14 14:55:29 -050081{
82 BMCWEB_LOG_DEBUG << "Get CPU resources by interface.";
83
Chicago Duana1649ec2021-03-30 16:54:58 +080084 // Set the default value of state
85 aResp->res.jsonValue["Status"]["State"] = "Enabled";
86 aResp->res.jsonValue["Status"]["Health"] = "OK";
Gunnar Millsac6a4442020-10-14 14:55:29 -050087
88 for (const auto& interface : cpuInterfacesProperties)
89 {
90 for (const auto& property : interface.second)
91 {
Chicago Duana1649ec2021-03-30 16:54:58 +080092 if (property.first == "Present")
Gunnar Millsac6a4442020-10-14 14:55:29 -050093 {
Chicago Duana1649ec2021-03-30 16:54:58 +080094 const bool* cpuPresent = std::get_if<bool>(&property.second);
95 if (cpuPresent == nullptr)
Gunnar Millsac6a4442020-10-14 14:55:29 -050096 {
97 // Important property not in desired type
98 messages::internalError(aResp->res);
99 return;
100 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800101 if (!*cpuPresent)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500102 {
Chicago Duana1649ec2021-03-30 16:54:58 +0800103 // Slot is not populated
Gunnar Millsac6a4442020-10-14 14:55:29 -0500104 aResp->res.jsonValue["Status"]["State"] = "Absent";
Chicago Duana1649ec2021-03-30 16:54:58 +0800105 }
106 }
107 else if (property.first == "Functional")
108 {
109 const bool* cpuFunctional = std::get_if<bool>(&property.second);
110 if (cpuFunctional == nullptr)
111 {
112 messages::internalError(aResp->res);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500113 return;
114 }
Ed Tanouse05aec52022-01-25 10:28:56 -0800115 if (!*cpuFunctional)
Chicago Duana1649ec2021-03-30 16:54:58 +0800116 {
117 aResp->res.jsonValue["Status"]["Health"] = "Critical";
118 }
119 }
120 else if (property.first == "CoreCount")
121 {
122 const uint16_t* coresCount =
123 std::get_if<uint16_t>(&property.second);
124 if (coresCount == nullptr)
125 {
126 messages::internalError(aResp->res);
127 return;
128 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500129 aResp->res.jsonValue["TotalCores"] = *coresCount;
130 }
Jonathan Domandc3fa662020-10-26 23:10:24 -0700131 else if (property.first == "MaxSpeedInMhz")
132 {
133 const uint32_t* value = std::get_if<uint32_t>(&property.second);
134 if (value != nullptr)
135 {
136 aResp->res.jsonValue["MaxSpeedMHz"] = *value;
137 }
138 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500139 else if (property.first == "Socket")
140 {
141 const std::string* value =
142 std::get_if<std::string>(&property.second);
143 if (value != nullptr)
144 {
145 aResp->res.jsonValue["Socket"] = *value;
146 }
147 }
148 else if (property.first == "ThreadCount")
149 {
Jonathan Domandc3fa662020-10-26 23:10:24 -0700150 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500151 if (value != nullptr)
152 {
153 aResp->res.jsonValue["TotalThreads"] = *value;
154 }
155 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700156 else if (property.first == "EffectiveFamily")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500157 {
Brandon Kim1930fbd2021-09-14 17:52:51 -0700158 const uint16_t* value = std::get_if<uint16_t>(&property.second);
Brad Bishop6169de22022-09-14 13:08:32 -0400159 if (value != nullptr && *value != 2)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500160 {
161 aResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800162 "0x" + intToHexString(*value, 4);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500163 }
164 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700165 else if (property.first == "EffectiveModel")
166 {
167 const uint16_t* value = std::get_if<uint16_t>(&property.second);
168 if (value == nullptr)
169 {
170 messages::internalError(aResp->res);
171 return;
172 }
Brad Bishop6169de22022-09-14 13:08:32 -0400173 if (*value != 0)
174 {
175 aResp->res.jsonValue["ProcessorId"]["EffectiveModel"] =
176 "0x" + intToHexString(*value, 4);
177 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700178 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500179 else if (property.first == "Id")
180 {
181 const uint64_t* value = std::get_if<uint64_t>(&property.second);
182 if (value != nullptr && *value != 0)
183 {
Gunnar Millsac6a4442020-10-14 14:55:29 -0500184 aResp->res
185 .jsonValue["ProcessorId"]["IdentificationRegisters"] =
Ed Tanous866e4862022-02-17 11:40:25 -0800186 "0x" + intToHexString(*value, 16);
Gunnar Millsac6a4442020-10-14 14:55:29 -0500187 }
188 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700189 else if (property.first == "Microcode")
190 {
191 const uint32_t* value = std::get_if<uint32_t>(&property.second);
192 if (value == nullptr)
193 {
194 messages::internalError(aResp->res);
195 return;
196 }
Brad Bishop6169de22022-09-14 13:08:32 -0400197 if (*value != 0)
198 {
199 aResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] =
200 "0x" + intToHexString(*value, 8);
201 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700202 }
203 else if (property.first == "Step")
204 {
205 const uint16_t* value = std::get_if<uint16_t>(&property.second);
206 if (value == nullptr)
207 {
208 messages::internalError(aResp->res);
209 return;
210 }
Michael Shenb9d679d2023-02-13 02:29:04 +0000211 if (*value != std::numeric_limits<uint16_t>::max())
Brad Bishop6169de22022-09-14 13:08:32 -0400212 {
213 aResp->res.jsonValue["ProcessorId"]["Step"] =
214 "0x" + intToHexString(*value, 4);
215 }
Brandon Kim1930fbd2021-09-14 17:52:51 -0700216 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500217 }
218 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500219}
220
zhanghch058d1b46d2021-04-01 11:18:24 +0800221inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500222 const std::string& cpuId,
223 const std::string& service,
224 const std::string& objPath)
225{
226 BMCWEB_LOG_DEBUG << "Get available system cpu resources by service.";
227
228 crow::connections::systemBus->async_method_call(
229 [cpuId, service, objPath, aResp{std::move(aResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800230 const boost::system::error_code& ec,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500231 const dbus::utility::ManagedObjectType& dbusData) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700232 if (ec)
233 {
234 BMCWEB_LOG_DEBUG << "DBUS response error";
235 messages::internalError(aResp->res);
236 return;
237 }
238 aResp->res.jsonValue["Id"] = cpuId;
239 aResp->res.jsonValue["Name"] = "Processor";
240 aResp->res.jsonValue["ProcessorType"] = "CPU";
Gunnar Millsac6a4442020-10-14 14:55:29 -0500241
Ed Tanous002d39b2022-05-31 08:59:27 -0700242 bool slotPresent = false;
243 std::string corePath = objPath + "/core";
244 size_t totalCores = 0;
245 for (const auto& object : dbusData)
246 {
247 if (object.first.str == objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500248 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700249 getCpuDataByInterface(aResp, object.second);
250 }
Ed Tanous11ba3972022-07-11 09:50:41 -0700251 else if (object.first.str.starts_with(corePath))
Ed Tanous002d39b2022-05-31 08:59:27 -0700252 {
253 for (const auto& interface : object.second)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500254 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700255 if (interface.first == "xyz.openbmc_project.Inventory.Item")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500256 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700257 for (const auto& property : interface.second)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500258 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700259 if (property.first == "Present")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500260 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700261 const bool* present =
262 std::get_if<bool>(&property.second);
263 if (present != nullptr)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500264 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700265 if (*present)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500266 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700267 slotPresent = true;
268 totalCores++;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500269 }
270 }
271 }
272 }
273 }
274 }
275 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700276 }
277 // In getCpuDataByInterface(), state and health are set
278 // based on the present and functional status. If core
279 // count is zero, then it has a higher precedence.
280 if (slotPresent)
281 {
282 if (totalCores == 0)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500283 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700284 // Slot is not populated, set status end return
285 aResp->res.jsonValue["Status"]["State"] = "Absent";
286 aResp->res.jsonValue["Status"]["Health"] = "OK";
Gunnar Millsac6a4442020-10-14 14:55:29 -0500287 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700288 aResp->res.jsonValue["TotalCores"] = totalCores;
289 }
290 return;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500291 },
292 service, "/xyz/openbmc_project/inventory",
293 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
294}
295
Chris Caindfbf7de2023-04-13 16:01:04 -0500296/**
297 * @brief Translates throttle cause DBUS property to redfish.
298 *
299 * @param[in] dbusSource The throttle cause from DBUS
300 *
301 * @return Returns as a string, the throttle cause in Redfish terms. If
302 * translation cannot be done, returns "Unknown" throttle reason.
303 */
304inline processor::ThrottleCause
305 dbusToRfThrottleCause(const std::string& dbusSource)
306{
307 if (dbusSource ==
308 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ClockLimit")
309 {
310 return processor::ThrottleCause::ClockLimit;
311 }
312 if (dbusSource ==
313 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ManagementDetectedFault")
314 {
315 return processor::ThrottleCause::ManagementDetectedFault;
316 }
317 if (dbusSource ==
318 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.PowerLimit")
319 {
320 return processor::ThrottleCause::PowerLimit;
321 }
322 if (dbusSource ==
323 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ThermalLimit")
324 {
325 return processor::ThrottleCause::ThermalLimit;
326 }
327 if (dbusSource ==
328 "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.Unknown")
329 {
330 return processor::ThrottleCause::Unknown;
331 }
332 return processor::ThrottleCause::Invalid;
333}
334
335inline void
336 readThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
337 const boost::system::error_code& ec,
338 const dbus::utility::DBusPropertiesMap& properties)
339{
340 if (ec)
341 {
342 BMCWEB_LOG_ERROR << "Processor Throttle getAllProperties error " << ec;
343 messages::internalError(aResp->res);
344 return;
345 }
346
347 const bool* status = nullptr;
348 const std::vector<std::string>* causes = nullptr;
349
350 if (!sdbusplus::unpackPropertiesNoThrow(dbus_utils::UnpackErrorPrinter(),
351 properties, "Throttled", status,
352 "ThrottleCauses", causes))
353 {
354 messages::internalError(aResp->res);
355 return;
356 }
357
358 aResp->res.jsonValue["Throttled"] = *status;
359 nlohmann::json::array_t rCauses;
360 for (const std::string& cause : *causes)
361 {
362 processor::ThrottleCause rfCause = dbusToRfThrottleCause(cause);
363 if (rfCause == processor::ThrottleCause::Invalid)
364 {
365 messages::internalError(aResp->res);
366 return;
367 }
368
369 rCauses.emplace_back(rfCause);
370 }
371 aResp->res.jsonValue["ThrottleCauses"] = std::move(rCauses);
372}
373
374inline void
375 getThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
376 const std::string& service,
377 const std::string& objectPath)
378{
379 BMCWEB_LOG_DEBUG << "Get processor throttle resources";
380
381 sdbusplus::asio::getAllProperties(
382 *crow::connections::systemBus, service, objectPath,
383 "xyz.openbmc_project.Control.Power.Throttle",
384 [aResp](const boost::system::error_code& ec,
385 const dbus::utility::DBusPropertiesMap& properties) {
386 readThrottleProperties(aResp, ec, properties);
387 });
388}
389
zhanghch058d1b46d2021-04-01 11:18:24 +0800390inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> aResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500391 const std::string& service,
392 const std::string& objPath)
393{
394 BMCWEB_LOG_DEBUG << "Get Cpu Asset Data";
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200395 sdbusplus::asio::getAllProperties(
396 *crow::connections::systemBus, service, objPath,
397 "xyz.openbmc_project.Inventory.Decorator.Asset",
Gunnar Millsac6a4442020-10-14 14:55:29 -0500398 [objPath, aResp{std::move(aResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800399 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200400 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700401 if (ec)
402 {
403 BMCWEB_LOG_DEBUG << "DBUS response error";
404 messages::internalError(aResp->res);
405 return;
406 }
407
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200408 const std::string* serialNumber = nullptr;
409 const std::string* model = nullptr;
410 const std::string* manufacturer = nullptr;
411 const std::string* partNumber = nullptr;
412 const std::string* sparePartNumber = nullptr;
413
414 const bool success = sdbusplus::unpackPropertiesNoThrow(
415 dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber",
416 serialNumber, "Model", model, "Manufacturer", manufacturer,
417 "PartNumber", partNumber, "SparePartNumber", sparePartNumber);
418
419 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700420 {
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200421 messages::internalError(aResp->res);
422 return;
423 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700424
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200425 if (serialNumber != nullptr && !serialNumber->empty())
426 {
427 aResp->res.jsonValue["SerialNumber"] = *serialNumber;
428 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700429
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200430 if ((model != nullptr) && !model->empty())
431 {
432 aResp->res.jsonValue["Model"] = *model;
433 }
434
435 if (manufacturer != nullptr)
436 {
437 aResp->res.jsonValue["Manufacturer"] = *manufacturer;
438
439 // Otherwise would be unexpected.
440 if (manufacturer->find("Intel") != std::string::npos)
Ed Tanous002d39b2022-05-31 08:59:27 -0700441 {
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200442 aResp->res.jsonValue["ProcessorArchitecture"] = "x86";
443 aResp->res.jsonValue["InstructionSet"] = "x86-64";
Ed Tanous002d39b2022-05-31 08:59:27 -0700444 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200445 else if (manufacturer->find("IBM") != std::string::npos)
Ed Tanous002d39b2022-05-31 08:59:27 -0700446 {
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200447 aResp->res.jsonValue["ProcessorArchitecture"] = "Power";
448 aResp->res.jsonValue["InstructionSet"] = "PowerISA";
Ed Tanous002d39b2022-05-31 08:59:27 -0700449 }
450 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200451
452 if (partNumber != nullptr)
453 {
454 aResp->res.jsonValue["PartNumber"] = *partNumber;
455 }
456
Brad Bishop6169de22022-09-14 13:08:32 -0400457 if (sparePartNumber != nullptr && !sparePartNumber->empty())
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200458 {
459 aResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
460 }
461 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500462}
463
zhanghch058d1b46d2021-04-01 11:18:24 +0800464inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> aResp,
Gunnar Millsac6a4442020-10-14 14:55:29 -0500465 const std::string& service,
466 const std::string& objPath)
467{
468 BMCWEB_LOG_DEBUG << "Get Cpu Revision Data";
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200469 sdbusplus::asio::getAllProperties(
470 *crow::connections::systemBus, service, objPath,
471 "xyz.openbmc_project.Inventory.Decorator.Revision",
Gunnar Millsac6a4442020-10-14 14:55:29 -0500472 [objPath, aResp{std::move(aResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800473 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200474 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700475 if (ec)
476 {
477 BMCWEB_LOG_DEBUG << "DBUS response error";
478 messages::internalError(aResp->res);
479 return;
480 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500481
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200482 const std::string* version = nullptr;
483
484 const bool success = sdbusplus::unpackPropertiesNoThrow(
485 dbus_utils::UnpackErrorPrinter(), properties, "Version", version);
486
487 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700488 {
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200489 messages::internalError(aResp->res);
490 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700491 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200492
493 if (version != nullptr)
494 {
495 aResp->res.jsonValue["Version"] = *version;
496 }
497 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500498}
499
zhanghch058d1b46d2021-04-01 11:18:24 +0800500inline void getAcceleratorDataByService(
501 std::shared_ptr<bmcweb::AsyncResp> aResp, const std::string& acclrtrId,
502 const std::string& service, const std::string& objPath)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500503{
504 BMCWEB_LOG_DEBUG
505 << "Get available system Accelerator resources by service.";
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200506 sdbusplus::asio::getAllProperties(
507 *crow::connections::systemBus, service, objPath, "",
Gunnar Millsac6a4442020-10-14 14:55:29 -0500508 [acclrtrId, aResp{std::move(aResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800509 const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200510 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700511 if (ec)
512 {
513 BMCWEB_LOG_DEBUG << "DBUS response error";
514 messages::internalError(aResp->res);
515 return;
516 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700517
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200518 const bool* functional = nullptr;
519 const bool* present = nullptr;
520
521 const bool success = sdbusplus::unpackPropertiesNoThrow(
522 dbus_utils::UnpackErrorPrinter(), properties, "Functional",
523 functional, "Present", present);
524
525 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700526 {
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200527 messages::internalError(aResp->res);
528 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700529 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500530
Ed Tanous002d39b2022-05-31 08:59:27 -0700531 std::string state = "Enabled";
532 std::string health = "OK";
Gunnar Millsac6a4442020-10-14 14:55:29 -0500533
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200534 if (present != nullptr && !*present)
Ed Tanous002d39b2022-05-31 08:59:27 -0700535 {
536 state = "Absent";
537 }
538
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200539 if (functional != nullptr && !*functional)
Ed Tanous002d39b2022-05-31 08:59:27 -0700540 {
541 if (state == "Enabled")
Gunnar Millsac6a4442020-10-14 14:55:29 -0500542 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700543 health = "Critical";
Gunnar Millsac6a4442020-10-14 14:55:29 -0500544 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700545 }
Gunnar Millsac6a4442020-10-14 14:55:29 -0500546
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200547 aResp->res.jsonValue["Id"] = acclrtrId;
548 aResp->res.jsonValue["Name"] = "Processor";
Ed Tanous002d39b2022-05-31 08:59:27 -0700549 aResp->res.jsonValue["Status"]["State"] = state;
550 aResp->res.jsonValue["Status"]["Health"] = health;
551 aResp->res.jsonValue["ProcessorType"] = "Accelerator";
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200552 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500553}
554
Jonathan Domandba0c292020-12-02 15:34:13 -0800555// OperatingConfig D-Bus Types
556using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>;
557using BaseSpeedPrioritySettingsProperty =
558 std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>;
559// uint32_t and size_t may or may not be the same type, requiring a dedup'd
560// variant
Jonathan Domandba0c292020-12-02 15:34:13 -0800561
562/**
563 * Fill out the HighSpeedCoreIDs in a Processor resource from the given
564 * OperatingConfig D-Bus property.
565 *
566 * @param[in,out] aResp Async HTTP response.
567 * @param[in] baseSpeedSettings Full list of base speed priority groups,
568 * to use to determine the list of high
569 * speed cores.
570 */
571inline void highSpeedCoreIdsHandler(
zhanghch058d1b46d2021-04-01 11:18:24 +0800572 const std::shared_ptr<bmcweb::AsyncResp>& aResp,
Jonathan Domandba0c292020-12-02 15:34:13 -0800573 const BaseSpeedPrioritySettingsProperty& baseSpeedSettings)
574{
575 // The D-Bus property does not indicate which bucket is the "high
576 // priority" group, so let's discern that by looking for the one with
577 // highest base frequency.
578 auto highPriorityGroup = baseSpeedSettings.cend();
579 uint32_t highestBaseSpeed = 0;
580 for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend();
581 ++it)
582 {
583 const uint32_t baseFreq = std::get<uint32_t>(*it);
584 if (baseFreq > highestBaseSpeed)
585 {
586 highestBaseSpeed = baseFreq;
587 highPriorityGroup = it;
588 }
589 }
590
591 nlohmann::json& jsonCoreIds = aResp->res.jsonValue["HighSpeedCoreIDs"];
592 jsonCoreIds = nlohmann::json::array();
593
594 // There may not be any entries in the D-Bus property, so only populate
595 // if there was actually something there.
596 if (highPriorityGroup != baseSpeedSettings.cend())
597 {
598 jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup);
599 }
600}
601
602/**
603 * Fill out OperatingConfig related items in a Processor resource by requesting
604 * data from the given D-Bus object.
605 *
606 * @param[in,out] aResp Async HTTP response.
607 * @param[in] cpuId CPU D-Bus name.
608 * @param[in] service D-Bus service to query.
609 * @param[in] objPath D-Bus object to query.
610 */
zhanghch058d1b46d2021-04-01 11:18:24 +0800611inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
Jonathan Domandba0c292020-12-02 15:34:13 -0800612 const std::string& cpuId,
613 const std::string& service,
614 const std::string& objPath)
615{
616 BMCWEB_LOG_INFO << "Getting CPU operating configs for " << cpuId;
617
618 // First, GetAll CurrentOperatingConfig properties on the object
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200619 sdbusplus::asio::getAllProperties(
620 *crow::connections::systemBus, service, objPath,
621 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
622 [aResp, cpuId,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800623 service](const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200624 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700625 if (ec)
626 {
627 BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message();
628 messages::internalError(aResp->res);
629 return;
630 }
Jonathan Domandba0c292020-12-02 15:34:13 -0800631
Ed Tanous002d39b2022-05-31 08:59:27 -0700632 nlohmann::json& json = aResp->res.jsonValue;
Jonathan Domandba0c292020-12-02 15:34:13 -0800633
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200634 const sdbusplus::message::object_path* appliedConfig = nullptr;
635 const bool* baseSpeedPriorityEnabled = nullptr;
636
637 const bool success = sdbusplus::unpackPropertiesNoThrow(
638 dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig",
639 appliedConfig, "BaseSpeedPriorityEnabled",
640 baseSpeedPriorityEnabled);
641
642 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700643 {
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200644 messages::internalError(aResp->res);
645 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700646 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200647
648 if (appliedConfig != nullptr)
649 {
650 const std::string& dbusPath = appliedConfig->str;
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200651 nlohmann::json::object_t operatingConfig;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700652 operatingConfig["@odata.id"] = boost::urls::format(
653 "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs",
654 cpuId);
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200655 json["OperatingConfigs"] = std::move(operatingConfig);
656
657 // Reuse the D-Bus config object name for the Redfish
658 // URI
659 size_t baseNamePos = dbusPath.rfind('/');
660 if (baseNamePos == std::string::npos ||
661 baseNamePos == (dbusPath.size() - 1))
662 {
663 // If the AppliedConfig was somehow not a valid path,
664 // skip adding any more properties, since everything
665 // else is tied to this applied config.
666 messages::internalError(aResp->res);
667 return;
668 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200669 nlohmann::json::object_t appliedOperatingConfig;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700670 appliedOperatingConfig["@odata.id"] = boost::urls::format(
671 "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs/{}",
672 cpuId, 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",
683 [aResp](
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 {
688 BMCWEB_LOG_WARNING << "D-Bus Property Get error: " << ec2;
689 messages::internalError(aResp->res);
690 return;
691 }
692
693 highSpeedCoreIdsHandler(aResp, baseSpeedList);
694 });
695 }
696
697 if (baseSpeedPriorityEnabled != nullptr)
698 {
699 json["BaseSpeedPriorityState"] =
700 *baseSpeedPriorityEnabled ? "Enabled" : "Disabled";
701 }
702 });
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 *
709 * @param[in,out] aResp Async HTTP response.
710 * @param[in] service D-Bus service to query.
711 * @param[in] objPath D-Bus object to query.
712 */
zhanghch058d1b46d2021-04-01 11:18:24 +0800713inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp,
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600714 const std::string& service,
715 const std::string& objPath)
716{
717 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 Tanous5e7e2dc2023-02-16 10:37:01 -0800721 [objPath, aResp{std::move(aResp)}](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700722 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700723 if (ec)
724 {
725 BMCWEB_LOG_DEBUG << "DBUS response error";
726 messages::internalError(aResp->res);
727 return;
728 }
SunnySrivastava1984cba4f442021-01-07 12:48:16 -0600729
Ed Tanous002d39b2022-05-31 08:59:27 -0700730 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
731 property;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700732 });
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 *
739 * @param[in,out] aResp Async HTTP response.
740 * @param[in] service D-Bus service to query.
741 * @param[in] objPath D-Bus object to query.
742 */
743inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
744 const std::string& service,
745 const std::string& objectPath)
746{
747 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 Tanous5e7e2dc2023-02-16 10:37:01 -0800752 [aResp](const boost::system::error_code& ec, const std::string& id) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700753 if (ec)
754 {
755 BMCWEB_LOG_ERROR << "Failed to read cpu unique id: " << ec;
756 messages::internalError(aResp->res);
757 return;
758 }
759 aResp->res.jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] =
760 id;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700761 });
Jonathan Doman49e429c2021-03-03 13:11:44 -0800762}
763
764/**
Jonathan Domanc9514482021-02-24 09:20:51 -0800765 * Find the D-Bus object representing the requested Processor, and call the
766 * handler with the results. If matching object is not found, add 404 error to
767 * response and don't call the handler.
768 *
769 * @param[in,out] resp Async HTTP response.
770 * @param[in] processorId Redfish Processor Id.
771 * @param[in] handler Callback to continue processing request upon
772 * successfully finding object.
773 */
774template <typename Handler>
zhanghch058d1b46d2021-04-01 11:18:24 +0800775inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp,
Jonathan Domanc9514482021-02-24 09:20:51 -0800776 const std::string& processorId,
777 Handler&& handler)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500778{
779 BMCWEB_LOG_DEBUG << "Get available system processor resources.";
780
Jonathan Domanc9514482021-02-24 09:20:51 -0800781 // GetSubTree on all interfaces which provide info about a Processor
Chris Caindfbf7de2023-04-13 16:01:04 -0500782 constexpr std::array<std::string_view, 9> interfaces = {
George Liue99073f2022-12-09 11:06:16 +0800783 "xyz.openbmc_project.Common.UUID",
784 "xyz.openbmc_project.Inventory.Decorator.Asset",
785 "xyz.openbmc_project.Inventory.Decorator.Revision",
786 "xyz.openbmc_project.Inventory.Item.Cpu",
787 "xyz.openbmc_project.Inventory.Decorator.LocationCode",
788 "xyz.openbmc_project.Inventory.Item.Accelerator",
789 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Chris Caindfbf7de2023-04-13 16:01:04 -0500790 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
791 "xyz.openbmc_project.Control.Power.Throttle"};
George Liue99073f2022-12-09 11:06:16 +0800792 dbus::utility::getSubTree(
793 "/xyz/openbmc_project/inventory", 0, interfaces,
Jonathan Domanc9514482021-02-24 09:20:51 -0800794 [resp, processorId, handler = std::forward<Handler>(handler)](
George Liue99073f2022-12-09 11:06:16 +0800795 const boost::system::error_code& ec,
796 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700797 if (ec)
798 {
799 BMCWEB_LOG_DEBUG << "DBUS response error: " << ec;
800 messages::internalError(resp->res);
801 return;
802 }
803 for (const auto& [objectPath, serviceMap] : subtree)
804 {
805 // Ignore any objects which don't end with our desired cpu name
Ed Tanous11ba3972022-07-11 09:50:41 -0700806 if (!objectPath.ends_with(processorId))
Gunnar Millsac6a4442020-10-14 14:55:29 -0500807 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700808 continue;
Gunnar Millsac6a4442020-10-14 14:55:29 -0500809 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700810
811 bool found = false;
812 // Filter out objects that don't have the CPU-specific
813 // interfaces to make sure we can return 404 on non-CPUs
814 // (e.g. /redfish/../Processors/dimm0)
815 for (const auto& [serviceName, interfaceList] : serviceMap)
Gunnar Millsac6a4442020-10-14 14:55:29 -0500816 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700817 if (std::find_first_of(
818 interfaceList.begin(), interfaceList.end(),
819 processorInterfaces.begin(),
820 processorInterfaces.end()) != interfaceList.end())
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);
George Liue99073f2022-12-09 11:06:16 +0800841 });
Gunnar Millsac6a4442020-10-14 14:55:29 -0500842}
843
zhanghch058d1b46d2021-04-01 11:18:24 +0800844inline void getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
Jonathan Domanc9514482021-02-24 09:20:51 -0800845 const std::string& processorId,
846 const std::string& objectPath,
Shantappa Teekappanavar5df6eda2022-01-18 12:29:28 -0600847 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Domanc9514482021-02-24 09:20:51 -0800848{
849 for (const auto& [serviceName, interfaceList] : serviceMap)
850 {
851 for (const auto& interface : interfaceList)
852 {
853 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
854 {
855 getCpuAssetData(aResp, serviceName, objectPath);
856 }
George Liu0fda0f12021-11-16 10:06:17 +0800857 else if (interface ==
858 "xyz.openbmc_project.Inventory.Decorator.Revision")
Jonathan Domanc9514482021-02-24 09:20:51 -0800859 {
860 getCpuRevisionData(aResp, serviceName, objectPath);
861 }
862 else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu")
863 {
864 getCpuDataByService(aResp, processorId, serviceName,
865 objectPath);
866 }
George Liu0fda0f12021-11-16 10:06:17 +0800867 else if (interface ==
868 "xyz.openbmc_project.Inventory.Item.Accelerator")
Jonathan Domanc9514482021-02-24 09:20:51 -0800869 {
870 getAcceleratorDataByService(aResp, processorId, serviceName,
871 objectPath);
872 }
George Liu0fda0f12021-11-16 10:06:17 +0800873 else if (
874 interface ==
875 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig")
Jonathan Domanc9514482021-02-24 09:20:51 -0800876 {
877 getCpuConfigData(aResp, processorId, serviceName, objectPath);
878 }
George Liu0fda0f12021-11-16 10:06:17 +0800879 else if (interface ==
880 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
Jonathan Domanc9514482021-02-24 09:20:51 -0800881 {
882 getCpuLocationCode(aResp, serviceName, objectPath);
883 }
Sharad Yadav71b82f22021-05-10 15:11:39 +0530884 else if (interface == "xyz.openbmc_project.Common.UUID")
885 {
886 getProcessorUUID(aResp, serviceName, objectPath);
887 }
George Liu0fda0f12021-11-16 10:06:17 +0800888 else if (interface ==
889 "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier")
Jonathan Doman49e429c2021-03-03 13:11:44 -0800890 {
891 getCpuUniqueId(aResp, serviceName, objectPath);
892 }
Chris Caindfbf7de2023-04-13 16:01:04 -0500893 else if (interface == "xyz.openbmc_project.Control.Power.Throttle")
894 {
895 getThrottleProperties(aResp, serviceName, objectPath);
896 }
Jonathan Domanc9514482021-02-24 09:20:51 -0800897 }
898 }
899}
900
Jonathan Domandba0c292020-12-02 15:34:13 -0800901/**
902 * Request all the properties for the given D-Bus object and fill out the
903 * related entries in the Redfish OperatingConfig response.
904 *
905 * @param[in,out] aResp Async HTTP response.
906 * @param[in] service D-Bus service name to query.
907 * @param[in] objPath D-Bus object to query.
908 */
zhanghch058d1b46d2021-04-01 11:18:24 +0800909inline void
910 getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
911 const std::string& service,
912 const std::string& objPath)
Jonathan Domandba0c292020-12-02 15:34:13 -0800913{
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200914 sdbusplus::asio::getAllProperties(
915 *crow::connections::systemBus, service, objPath,
916 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800917 [aResp](const boost::system::error_code& ec,
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200918 const dbus::utility::DBusPropertiesMap& properties) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700919 if (ec)
920 {
921 BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message();
922 messages::internalError(aResp->res);
923 return;
924 }
925
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200926 const size_t* availableCoreCount = nullptr;
927 const uint32_t* baseSpeed = nullptr;
928 const uint32_t* maxJunctionTemperature = nullptr;
929 const uint32_t* maxSpeed = nullptr;
930 const uint32_t* powerLimit = nullptr;
931 const TurboProfileProperty* turboProfile = nullptr;
932 const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings =
933 nullptr;
934
935 const bool success = sdbusplus::unpackPropertiesNoThrow(
936 dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount",
937 availableCoreCount, "BaseSpeed", baseSpeed,
938 "MaxJunctionTemperature", maxJunctionTemperature, "MaxSpeed",
939 maxSpeed, "PowerLimit", powerLimit, "TurboProfile", turboProfile,
940 "BaseSpeedPrioritySettings", baseSpeedPrioritySettings);
941
942 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700943 {
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200944 messages::internalError(aResp->res);
945 return;
946 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700947
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200948 nlohmann::json& json = aResp->res.jsonValue;
Ed Tanous002d39b2022-05-31 08:59:27 -0700949
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200950 if (availableCoreCount != nullptr)
951 {
952 json["TotalAvailableCoreCount"] = *availableCoreCount;
953 }
954
955 if (baseSpeed != nullptr)
956 {
957 json["BaseSpeedMHz"] = *baseSpeed;
958 }
959
960 if (maxJunctionTemperature != nullptr)
961 {
962 json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature;
963 }
964
965 if (maxSpeed != nullptr)
966 {
967 json["MaxSpeedMHz"] = *maxSpeed;
968 }
969
970 if (powerLimit != nullptr)
971 {
972 json["TDPWatts"] = *powerLimit;
973 }
974
975 if (turboProfile != nullptr)
976 {
977 nlohmann::json& turboArray = json["TurboProfile"];
978 turboArray = nlohmann::json::array();
979 for (const auto& [turboSpeed, coreCount] : *turboProfile)
980 {
981 nlohmann::json::object_t turbo;
982 turbo["ActiveCoreCount"] = coreCount;
983 turbo["MaxSpeedMHz"] = turboSpeed;
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500984 turboArray.emplace_back(std::move(turbo));
Ed Tanous002d39b2022-05-31 08:59:27 -0700985 }
986 }
Krzysztof Grobelny351053f2022-07-28 15:44:22 +0200987
988 if (baseSpeedPrioritySettings != nullptr)
989 {
990 nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"];
991 baseSpeedArray = nlohmann::json::array();
992 for (const auto& [baseSpeedMhz, coreList] :
993 *baseSpeedPrioritySettings)
994 {
995 nlohmann::json::object_t speed;
996 speed["CoreCount"] = coreList.size();
997 speed["CoreIDs"] = coreList;
998 speed["BaseSpeedMHz"] = baseSpeedMhz;
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500999 baseSpeedArray.emplace_back(std::move(speed));
Krzysztof Grobelny351053f2022-07-28 15:44:22 +02001000 }
1001 }
1002 });
Jonathan Domandba0c292020-12-02 15:34:13 -08001003}
1004
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001005/**
1006 * Handle the D-Bus response from attempting to set the CPU's AppliedConfig
1007 * property. Main task is to translate error messages into Redfish errors.
1008 *
1009 * @param[in,out] resp HTTP response.
1010 * @param[in] setPropVal Value which we attempted to set.
1011 * @param[in] ec D-Bus response error code.
1012 * @param[in] msg D-Bus response message.
1013 */
1014inline void
1015 handleAppliedConfigResponse(const std::shared_ptr<bmcweb::AsyncResp>& resp,
1016 const std::string& setPropVal,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001017 const boost::system::error_code& ec,
Patrick Williams59d494e2022-07-22 19:26:55 -05001018 const sdbusplus::message_t& msg)
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001019{
1020 if (!ec)
1021 {
1022 BMCWEB_LOG_DEBUG << "Set Property succeeded";
1023 return;
1024 }
1025
1026 BMCWEB_LOG_DEBUG << "Set Property failed: " << ec;
1027
1028 const sd_bus_error* dbusError = msg.get_error();
1029 if (dbusError == nullptr)
1030 {
1031 messages::internalError(resp->res);
1032 return;
1033 }
1034
1035 // The asio error code doesn't know about our custom errors, so we have to
1036 // parse the error string. Some of these D-Bus -> Redfish translations are a
1037 // stretch, but it's good to try to communicate something vaguely useful.
1038 if (strcmp(dbusError->name,
1039 "xyz.openbmc_project.Common.Error.InvalidArgument") == 0)
1040 {
1041 // Service did not like the object_path we tried to set.
1042 messages::propertyValueIncorrect(
1043 resp->res, "AppliedOperatingConfig/@odata.id", setPropVal);
1044 }
1045 else if (strcmp(dbusError->name,
1046 "xyz.openbmc_project.Common.Error.NotAllowed") == 0)
1047 {
1048 // Service indicates we can never change the config for this processor.
1049 messages::propertyNotWritable(resp->res, "AppliedOperatingConfig");
1050 }
1051 else if (strcmp(dbusError->name,
1052 "xyz.openbmc_project.Common.Error.Unavailable") == 0)
1053 {
1054 // Service indicates the config cannot be changed right now, but maybe
1055 // in a different system state.
1056 messages::resourceInStandby(resp->res);
1057 }
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001058 else
1059 {
1060 messages::internalError(resp->res);
1061 }
1062}
1063
1064/**
1065 * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic
1066 * validation of the input data, and then set the D-Bus property.
1067 *
1068 * @param[in,out] resp Async HTTP response.
1069 * @param[in] processorId Processor's Id.
1070 * @param[in] appliedConfigUri New property value to apply.
1071 * @param[in] cpuObjectPath Path of CPU object to modify.
1072 * @param[in] serviceMap Service map for CPU object.
1073 */
1074inline void patchAppliedOperatingConfig(
1075 const std::shared_ptr<bmcweb::AsyncResp>& resp,
1076 const std::string& processorId, const std::string& appliedConfigUri,
Shantappa Teekappanavar5df6eda2022-01-18 12:29:28 -06001077 const std::string& cpuObjectPath,
1078 const dbus::utility::MapperServiceMap& serviceMap)
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001079{
1080 // Check that the property even exists by checking for the interface
1081 const std::string* controlService = nullptr;
1082 for (const auto& [serviceName, interfaceList] : serviceMap)
1083 {
1084 if (std::find(interfaceList.begin(), interfaceList.end(),
1085 "xyz.openbmc_project.Control.Processor."
1086 "CurrentOperatingConfig") != interfaceList.end())
1087 {
1088 controlService = &serviceName;
1089 break;
1090 }
1091 }
1092
1093 if (controlService == nullptr)
1094 {
1095 messages::internalError(resp->res);
1096 return;
1097 }
1098
1099 // Check that the config URI is a child of the cpu URI being patched.
1100 std::string expectedPrefix("/redfish/v1/Systems/system/Processors/");
1101 expectedPrefix += processorId;
1102 expectedPrefix += "/OperatingConfigs/";
Ed Tanous11ba3972022-07-11 09:50:41 -07001103 if (!appliedConfigUri.starts_with(expectedPrefix) ||
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001104 expectedPrefix.size() == appliedConfigUri.size())
1105 {
1106 messages::propertyValueIncorrect(
1107 resp->res, "AppliedOperatingConfig/@odata.id", appliedConfigUri);
1108 return;
1109 }
1110
1111 // Generate the D-Bus path of the OperatingConfig object, by assuming it's a
1112 // direct child of the CPU object.
1113 // Strip the expectedPrefix from the config URI to get the "filename", and
1114 // append to the CPU's path.
1115 std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size());
1116 sdbusplus::message::object_path configPath(cpuObjectPath);
1117 configPath /= configBaseName;
1118
1119 BMCWEB_LOG_INFO << "Setting config to " << configPath.str;
1120
1121 // Set the property, with handler to check error responses
1122 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001123 [resp, appliedConfigUri](const boost::system::error_code& ec,
Patrick Williams59d494e2022-07-22 19:26:55 -05001124 const sdbusplus::message_t& msg) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001125 handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001126 },
1127 *controlService, cpuObjectPath, "org.freedesktop.DBus.Properties",
1128 "Set", "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
Ed Tanous168e20c2021-12-13 14:39:53 -08001129 "AppliedConfig", dbus::utility::DbusVariantType(std::move(configPath)));
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001130}
1131
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001132inline void handleProcessorHead(crow::App& app, const crow::Request& req,
1133 const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1134 const std::string& /* systemName */,
1135 const std::string& /* processorId */)
1136{
1137 if (!redfish::setUpRedfishRoute(app, req, aResp))
1138 {
1139 return;
1140 }
1141 aResp->res.addHeader(
1142 boost::beast::http::field::link,
1143 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1144}
1145
1146inline void handleProcessorCollectionHead(
1147 crow::App& app, const crow::Request& req,
1148 const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1149 const std::string& /* systemName */)
1150{
1151 if (!redfish::setUpRedfishRoute(app, req, aResp))
1152 {
1153 return;
1154 }
1155 aResp->res.addHeader(
1156 boost::beast::http::field::link,
1157 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1158}
1159
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001160inline void requestRoutesOperatingConfigCollection(App& app)
Jonathan Domandba0c292020-12-02 15:34:13 -08001161{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001162 BMCWEB_ROUTE(
1163 app, "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/")
Ed Tanoused398212021-06-09 17:05:54 -07001164 .privileges(redfish::privileges::getOperatingConfigCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07001165 .methods(boost::beast::http::verb::get)(
1166 [&app](const crow::Request& req,
1167 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1168 const std::string& cpuName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001169 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001170 {
1171 return;
1172 }
1173 asyncResp->res.jsonValue["@odata.type"] =
1174 "#OperatingConfigCollection.OperatingConfigCollection";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001175 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1176 "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs",
1177 cpuName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001178 asyncResp->res.jsonValue["Name"] = "Operating Config Collection";
1179
1180 // First find the matching CPU object so we know how to
1181 // constrain our search for related Config objects.
George Liu7a1dbc42022-12-07 16:03:22 +08001182 const std::array<std::string_view, 1> interfaces = {
1183 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"};
1184 dbus::utility::getSubTreePaths(
1185 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -07001186 [asyncResp, cpuName](
George Liu7a1dbc42022-12-07 16:03:22 +08001187 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001188 const dbus::utility::MapperGetSubTreePathsResponse& objects) {
1189 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001190 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001191 BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", "
1192 << ec.message();
1193 messages::internalError(asyncResp->res);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001194 return;
1195 }
Jonathan Domandba0c292020-12-02 15:34:13 -08001196
Ed Tanous002d39b2022-05-31 08:59:27 -07001197 for (const std::string& object : objects)
1198 {
Ed Tanous11ba3972022-07-11 09:50:41 -07001199 if (!object.ends_with(cpuName))
Ed Tanous002d39b2022-05-31 08:59:27 -07001200 {
1201 continue;
1202 }
George Liu0fda0f12021-11-16 10:06:17 +08001203
Ed Tanous002d39b2022-05-31 08:59:27 -07001204 // Not expected that there will be multiple matching
1205 // CPU objects, but if there are just use the first
1206 // one.
Jonathan Domandba0c292020-12-02 15:34:13 -08001207
Ed Tanous002d39b2022-05-31 08:59:27 -07001208 // Use the common search routine to construct the
1209 // Collection of all Config objects under this CPU.
George Liu7a1dbc42022-12-07 16:03:22 +08001210 constexpr std::array<std::string_view, 1> interface {
1211 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"
1212 };
Ed Tanous002d39b2022-05-31 08:59:27 -07001213 collection_util::getCollectionMembers(
1214 asyncResp,
Ed Tanousef4c65b2023-04-24 15:28:50 -07001215 boost::urls::format(
1216 "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs",
1217 cpuName),
George Liu7a1dbc42022-12-07 16:03:22 +08001218 interface, object.c_str());
Ed Tanous002d39b2022-05-31 08:59:27 -07001219 return;
1220 }
George Liu7a1dbc42022-12-07 16:03:22 +08001221 });
George Liu0fda0f12021-11-16 10:06:17 +08001222 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001223}
1224
1225inline void requestRoutesOperatingConfig(App& app)
1226{
1227 BMCWEB_ROUTE(
1228 app,
1229 "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001230 .privileges(redfish::privileges::getOperatingConfig)
Ed Tanous002d39b2022-05-31 08:59:27 -07001231 .methods(boost::beast::http::verb::get)(
1232 [&app](const crow::Request& req,
1233 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1234 const std::string& cpuName, const std::string& configName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001235 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001236 {
1237 return;
1238 }
1239 // Ask for all objects implementing OperatingConfig so we can search
1240 // for one with a matching name
George Liue99073f2022-12-09 11:06:16 +08001241 constexpr std::array<std::string_view, 1> interfaces = {
1242 "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1243 dbus::utility::getSubTree(
1244 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous39662a32023-02-06 15:09:46 -08001245 [asyncResp, cpuName, configName](
George Liue99073f2022-12-09 11:06:16 +08001246 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001247 const dbus::utility::MapperGetSubTreeResponse& subtree) {
1248 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -07001249 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001250 BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", "
1251 << ec.message();
1252 messages::internalError(asyncResp->res);
Ed Tanous45ca1b82022-03-25 13:07:27 -07001253 return;
1254 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001255 const std::string expectedEnding = cpuName + '/' + configName;
1256 for (const auto& [objectPath, serviceMap] : subtree)
1257 {
1258 // Ignore any configs without matching cpuX/configY
Ed Tanous11ba3972022-07-11 09:50:41 -07001259 if (!objectPath.ends_with(expectedEnding) || serviceMap.empty())
Ed Tanous002d39b2022-05-31 08:59:27 -07001260 {
1261 continue;
1262 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001263
Ed Tanous002d39b2022-05-31 08:59:27 -07001264 nlohmann::json& json = asyncResp->res.jsonValue;
1265 json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001266 json["@odata.id"] = boost::urls::format(
1267 "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs/{}",
1268 cpuName, configName);
Ed Tanous002d39b2022-05-31 08:59:27 -07001269 json["Name"] = "Processor Profile";
1270 json["Id"] = configName;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001271
Ed Tanous002d39b2022-05-31 08:59:27 -07001272 // Just use the first implementation of the object - not
1273 // expected that there would be multiple matching
1274 // services
1275 getOperatingConfigData(asyncResp, serviceMap.begin()->first,
1276 objectPath);
1277 return;
1278 }
1279 messages::resourceNotFound(asyncResp->res, "OperatingConfig",
1280 configName);
George Liue99073f2022-12-09 11:06:16 +08001281 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001282 });
1283}
Jonathan Domandba0c292020-12-02 15:34:13 -08001284
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001285inline void requestRoutesProcessorCollection(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 */
Ed Tanous22d268c2022-05-19 09:39:07 -07001290 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001291 .privileges(redfish::privileges::headProcessorCollection)
1292 .methods(boost::beast::http::verb::head)(
1293 std::bind_front(handleProcessorCollectionHead, std::ref(app)));
1294
1295 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
Ed Tanoused398212021-06-09 17:05:54 -07001296 .privileges(redfish::privileges::getProcessorCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001297 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001298 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -07001299 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1300 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001301 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001302 {
1303 return;
1304 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001305 if (systemName != "system")
1306 {
1307 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1308 systemName);
1309 return;
1310 }
1311
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001312 asyncResp->res.addHeader(
1313 boost::beast::http::field::link,
1314 "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1315
Ed Tanous002d39b2022-05-31 08:59:27 -07001316 asyncResp->res.jsonValue["@odata.type"] =
1317 "#ProcessorCollection.ProcessorCollection";
1318 asyncResp->res.jsonValue["Name"] = "Processor Collection";
Gunnar Millsac6a4442020-10-14 14:55:29 -05001319
Ed Tanous002d39b2022-05-31 08:59:27 -07001320 asyncResp->res.jsonValue["@odata.id"] =
1321 "/redfish/v1/Systems/system/Processors";
Gunnar Millsac6a4442020-10-14 14:55:29 -05001322
Ed Tanous002d39b2022-05-31 08:59:27 -07001323 collection_util::getCollectionMembers(
Willy Tuae9031f2022-09-27 05:48:07 +00001324 asyncResp,
1325 boost::urls::url("/redfish/v1/Systems/system/Processors"),
George Liu7a1dbc42022-12-07 16:03:22 +08001326 processorInterfaces);
Ed Tanous002d39b2022-05-31 08:59:27 -07001327 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001328}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001329
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001330inline void requestRoutesProcessor(App& app)
Gunnar Millsac6a4442020-10-14 14:55:29 -05001331{
Gunnar Millsac6a4442020-10-14 14:55:29 -05001332 /**
1333 * Functions triggers appropriate requests on DBus
1334 */
Gunnar Millsac6a4442020-10-14 14:55:29 -05001335
Ed Tanous22d268c2022-05-19 09:39:07 -07001336 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001337 .privileges(redfish::privileges::headProcessor)
1338 .methods(boost::beast::http::verb::head)(
1339 std::bind_front(handleProcessorHead, std::ref(app)));
1340
1341 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001342 .privileges(redfish::privileges::getProcessor)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001343 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001344 [&app](const crow::Request& req,
1345 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001346 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001347 const std::string& processorId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001348 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001349 {
1350 return;
1351 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001352 if (systemName != "system")
1353 {
1354 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1355 systemName);
1356 return;
1357 }
1358
Nikhil Namjoshi71a24ca2022-11-11 01:52:32 +00001359 asyncResp->res.addHeader(
1360 boost::beast::http::field::link,
1361 "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
Ed Tanous002d39b2022-05-31 08:59:27 -07001362 asyncResp->res.jsonValue["@odata.type"] =
Chris Caindfbf7de2023-04-13 16:01:04 -05001363 "#Processor.v1_18_0.Processor";
Ed Tanousef4c65b2023-04-24 15:28:50 -07001364 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1365 "/redfish/v1/Systems/system/Processors/{}", processorId);
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001366
Ed Tanous8a592812022-06-04 09:06:59 -07001367 getProcessorObject(
1368 asyncResp, processorId,
1369 std::bind_front(getProcessorData, asyncResp, processorId));
Ed Tanous002d39b2022-05-31 08:59:27 -07001370 });
Jonathan Doman3cde86f2020-12-02 14:50:45 -08001371
Ed Tanous22d268c2022-05-19 09:39:07 -07001372 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001373 .privileges(redfish::privileges::patchProcessor)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001374 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001375 [&app](const crow::Request& req,
1376 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -07001377 const std::string& systemName,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001378 const std::string& processorId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001379 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001380 {
1381 return;
1382 }
Ed Tanous22d268c2022-05-19 09:39:07 -07001383 if (systemName != "system")
1384 {
1385 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1386 systemName);
1387 return;
1388 }
1389
Ed Tanous002d39b2022-05-31 08:59:27 -07001390 std::optional<nlohmann::json> appliedConfigJson;
1391 if (!json_util::readJsonPatch(req, asyncResp->res,
1392 "AppliedOperatingConfig",
1393 appliedConfigJson))
1394 {
1395 return;
1396 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001397
Ed Tanous002d39b2022-05-31 08:59:27 -07001398 if (appliedConfigJson)
1399 {
Ed Tanousf8fe53e2022-06-30 15:55:45 -07001400 std::string appliedConfigUri;
Ed Tanous002d39b2022-05-31 08:59:27 -07001401 if (!json_util::readJson(*appliedConfigJson, asyncResp->res,
1402 "@odata.id", appliedConfigUri))
1403 {
1404 return;
1405 }
1406 // Check for 404 and find matching D-Bus object, then run
1407 // property patch handlers if that all succeeds.
Ed Tanous8a592812022-06-04 09:06:59 -07001408 getProcessorObject(asyncResp, processorId,
1409 std::bind_front(patchAppliedOperatingConfig,
1410 asyncResp, processorId,
1411 appliedConfigUri));
Ed Tanous002d39b2022-05-31 08:59:27 -07001412 }
1413 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001414}
Gunnar Millsac6a4442020-10-14 14:55:29 -05001415
1416} // namespace redfish