xref: /openbmc/bmcweb/redfish-core/lib/processor.hpp (revision 6f056f246d9bcfd611102ee712d4a2935504b448)
1 /*
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 
18 #include "app.hpp"
19 #include "dbus_singleton.hpp"
20 #include "dbus_utility.hpp"
21 #include "error_messages.hpp"
22 #include "generated/enums/processor.hpp"
23 #include "query.hpp"
24 #include "registries/privilege_registry.hpp"
25 #include "utils/collection.hpp"
26 #include "utils/dbus_utils.hpp"
27 #include "utils/json_utils.hpp"
28 
29 #include <boost/container/flat_map.hpp>
30 #include <boost/system/error_code.hpp>
31 #include <boost/url/format.hpp>
32 #include <sdbusplus/asio/property.hpp>
33 #include <sdbusplus/message/native_types.hpp>
34 #include <sdbusplus/unpack_properties.hpp>
35 #include <sdbusplus/utility/dedup_variant.hpp>
36 
37 #include <array>
38 #include <limits>
39 #include <ranges>
40 #include <string>
41 #include <string_view>
42 
43 namespace redfish
44 {
45 
46 // Interfaces which imply a D-Bus object represents a Processor
47 constexpr std::array<std::string_view, 2> processorInterfaces = {
48     "xyz.openbmc_project.Inventory.Item.Cpu",
49     "xyz.openbmc_project.Inventory.Item.Accelerator"};
50 
51 /**
52  * @brief Fill out uuid info of a processor by
53  * requesting data from the given D-Bus object.
54  *
55  * @param[in,out]   asyncResp       Async HTTP response.
56  * @param[in]       service     D-Bus service to query.
57  * @param[in]       objPath     D-Bus object to query.
58  */
59 inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
60                              const std::string& service,
61                              const std::string& objPath)
62 {
63     BMCWEB_LOG_DEBUG("Get Processor UUID");
64     sdbusplus::asio::getProperty<std::string>(
65         *crow::connections::systemBus, service, objPath,
66         "xyz.openbmc_project.Common.UUID", "UUID",
67         [objPath, asyncResp{std::move(asyncResp)}](
68             const boost::system::error_code& ec, const std::string& property) {
69         if (ec)
70         {
71             BMCWEB_LOG_DEBUG("DBUS response error");
72             messages::internalError(asyncResp->res);
73             return;
74         }
75         asyncResp->res.jsonValue["UUID"] = property;
76     });
77 }
78 
79 inline void getCpuDataByInterface(
80     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
81     const dbus::utility::DBusInterfacesMap& cpuInterfacesProperties)
82 {
83     BMCWEB_LOG_DEBUG("Get CPU resources by interface.");
84 
85     // Set the default value of state
86     asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
87     asyncResp->res.jsonValue["Status"]["Health"] = "OK";
88 
89     for (const auto& interface : cpuInterfacesProperties)
90     {
91         for (const auto& property : interface.second)
92         {
93             if (property.first == "Present")
94             {
95                 const bool* cpuPresent = std::get_if<bool>(&property.second);
96                 if (cpuPresent == nullptr)
97                 {
98                     // Important property not in desired type
99                     messages::internalError(asyncResp->res);
100                     return;
101                 }
102                 if (!*cpuPresent)
103                 {
104                     // Slot is not populated
105                     asyncResp->res.jsonValue["Status"]["State"] = "Absent";
106                 }
107             }
108             else if (property.first == "Functional")
109             {
110                 const bool* cpuFunctional = std::get_if<bool>(&property.second);
111                 if (cpuFunctional == nullptr)
112                 {
113                     messages::internalError(asyncResp->res);
114                     return;
115                 }
116                 if (!*cpuFunctional)
117                 {
118                     asyncResp->res.jsonValue["Status"]["Health"] = "Critical";
119                 }
120             }
121             else if (property.first == "CoreCount")
122             {
123                 const uint16_t* coresCount =
124                     std::get_if<uint16_t>(&property.second);
125                 if (coresCount == nullptr)
126                 {
127                     messages::internalError(asyncResp->res);
128                     return;
129                 }
130                 asyncResp->res.jsonValue["TotalCores"] = *coresCount;
131             }
132             else if (property.first == "MaxSpeedInMhz")
133             {
134                 const uint32_t* value = std::get_if<uint32_t>(&property.second);
135                 if (value != nullptr)
136                 {
137                     asyncResp->res.jsonValue["MaxSpeedMHz"] = *value;
138                 }
139             }
140             else if (property.first == "Socket")
141             {
142                 const std::string* value =
143                     std::get_if<std::string>(&property.second);
144                 if (value != nullptr)
145                 {
146                     asyncResp->res.jsonValue["Socket"] = *value;
147                 }
148             }
149             else if (property.first == "ThreadCount")
150             {
151                 const uint16_t* value = std::get_if<uint16_t>(&property.second);
152                 if (value != nullptr)
153                 {
154                     asyncResp->res.jsonValue["TotalThreads"] = *value;
155                 }
156             }
157             else if (property.first == "EffectiveFamily")
158             {
159                 const uint16_t* value = std::get_if<uint16_t>(&property.second);
160                 if (value != nullptr && *value != 2)
161                 {
162                     asyncResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] =
163                         "0x" + intToHexString(*value, 4);
164                 }
165             }
166             else if (property.first == "EffectiveModel")
167             {
168                 const uint16_t* value = std::get_if<uint16_t>(&property.second);
169                 if (value == nullptr)
170                 {
171                     messages::internalError(asyncResp->res);
172                     return;
173                 }
174                 if (*value != 0)
175                 {
176                     asyncResp->res.jsonValue["ProcessorId"]["EffectiveModel"] =
177                         "0x" + intToHexString(*value, 4);
178                 }
179             }
180             else if (property.first == "Id")
181             {
182                 const uint64_t* value = std::get_if<uint64_t>(&property.second);
183                 if (value != nullptr && *value != 0)
184                 {
185                     asyncResp->res
186                         .jsonValue["ProcessorId"]["IdentificationRegisters"] =
187                         "0x" + intToHexString(*value, 16);
188                 }
189             }
190             else if (property.first == "Microcode")
191             {
192                 const uint32_t* value = std::get_if<uint32_t>(&property.second);
193                 if (value == nullptr)
194                 {
195                     messages::internalError(asyncResp->res);
196                     return;
197                 }
198                 if (*value != 0)
199                 {
200                     asyncResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] =
201                         "0x" + intToHexString(*value, 8);
202                 }
203             }
204             else if (property.first == "Step")
205             {
206                 const uint16_t* value = std::get_if<uint16_t>(&property.second);
207                 if (value == nullptr)
208                 {
209                     messages::internalError(asyncResp->res);
210                     return;
211                 }
212                 if (*value != std::numeric_limits<uint16_t>::max())
213                 {
214                     asyncResp->res.jsonValue["ProcessorId"]["Step"] =
215                         "0x" + intToHexString(*value, 4);
216                 }
217             }
218         }
219     }
220 }
221 
222 inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
223                                 const std::string& cpuId,
224                                 const std::string& service,
225                                 const std::string& objPath)
226 {
227     BMCWEB_LOG_DEBUG("Get available system cpu resources by service.");
228 
229     sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
230     dbus::utility::getManagedObjects(
231         service, path,
232         [cpuId, service, objPath, asyncResp{std::move(asyncResp)}](
233             const boost::system::error_code& ec,
234             const dbus::utility::ManagedObjectType& dbusData) {
235         if (ec)
236         {
237             BMCWEB_LOG_DEBUG("DBUS response error");
238             messages::internalError(asyncResp->res);
239             return;
240         }
241         asyncResp->res.jsonValue["Id"] = cpuId;
242         asyncResp->res.jsonValue["Name"] = "Processor";
243         asyncResp->res.jsonValue["ProcessorType"] = "CPU";
244 
245         bool slotPresent = false;
246         std::string corePath = objPath + "/core";
247         size_t totalCores = 0;
248         for (const auto& object : dbusData)
249         {
250             if (object.first.str == objPath)
251             {
252                 getCpuDataByInterface(asyncResp, object.second);
253             }
254             else if (object.first.str.starts_with(corePath))
255             {
256                 for (const auto& interface : object.second)
257                 {
258                     if (interface.first == "xyz.openbmc_project.Inventory.Item")
259                     {
260                         for (const auto& property : interface.second)
261                         {
262                             if (property.first == "Present")
263                             {
264                                 const bool* present =
265                                     std::get_if<bool>(&property.second);
266                                 if (present != nullptr)
267                                 {
268                                     if (*present)
269                                     {
270                                         slotPresent = true;
271                                         totalCores++;
272                                     }
273                                 }
274                             }
275                         }
276                     }
277                 }
278             }
279         }
280         // In getCpuDataByInterface(), state and health are set
281         // based on the present and functional status. If core
282         // count is zero, then it has a higher precedence.
283         if (slotPresent)
284         {
285             asyncResp->res.jsonValue["TotalCores"] = totalCores;
286         }
287         return;
288     });
289 }
290 
291 /**
292  * @brief Translates throttle cause DBUS property to redfish.
293  *
294  * @param[in] dbusSource    The throttle cause from DBUS
295  *
296  * @return Returns as a string, the throttle cause in Redfish terms. If
297  * translation cannot be done, returns "Unknown" throttle reason.
298  */
299 inline processor::ThrottleCause
300     dbusToRfThrottleCause(const std::string& dbusSource)
301 {
302     if (dbusSource ==
303         "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ClockLimit")
304     {
305         return processor::ThrottleCause::ClockLimit;
306     }
307     if (dbusSource ==
308         "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ManagementDetectedFault")
309     {
310         return processor::ThrottleCause::ManagementDetectedFault;
311     }
312     if (dbusSource ==
313         "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.PowerLimit")
314     {
315         return processor::ThrottleCause::PowerLimit;
316     }
317     if (dbusSource ==
318         "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ThermalLimit")
319     {
320         return processor::ThrottleCause::ThermalLimit;
321     }
322     if (dbusSource ==
323         "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.Unknown")
324     {
325         return processor::ThrottleCause::Unknown;
326     }
327     return processor::ThrottleCause::Invalid;
328 }
329 
330 inline void
331     readThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
332                            const boost::system::error_code& ec,
333                            const dbus::utility::DBusPropertiesMap& properties)
334 {
335     if (ec)
336     {
337         BMCWEB_LOG_ERROR("Processor Throttle getAllProperties error {}", ec);
338         messages::internalError(asyncResp->res);
339         return;
340     }
341 
342     const bool* status = nullptr;
343     const std::vector<std::string>* causes = nullptr;
344 
345     if (!sdbusplus::unpackPropertiesNoThrow(dbus_utils::UnpackErrorPrinter(),
346                                             properties, "Throttled", status,
347                                             "ThrottleCauses", causes))
348     {
349         messages::internalError(asyncResp->res);
350         return;
351     }
352 
353     asyncResp->res.jsonValue["Throttled"] = *status;
354     nlohmann::json::array_t rCauses;
355     for (const std::string& cause : *causes)
356     {
357         processor::ThrottleCause rfCause = dbusToRfThrottleCause(cause);
358         if (rfCause == processor::ThrottleCause::Invalid)
359         {
360             messages::internalError(asyncResp->res);
361             return;
362         }
363 
364         rCauses.emplace_back(rfCause);
365     }
366     asyncResp->res.jsonValue["ThrottleCauses"] = std::move(rCauses);
367 }
368 
369 inline void
370     getThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
371                           const std::string& service,
372                           const std::string& objectPath)
373 {
374     BMCWEB_LOG_DEBUG("Get processor throttle resources");
375 
376     sdbusplus::asio::getAllProperties(
377         *crow::connections::systemBus, service, objectPath,
378         "xyz.openbmc_project.Control.Power.Throttle",
379         [asyncResp](const boost::system::error_code& ec,
380                     const dbus::utility::DBusPropertiesMap& properties) {
381         readThrottleProperties(asyncResp, ec, properties);
382     });
383 }
384 
385 inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
386                             const std::string& service,
387                             const std::string& objPath)
388 {
389     BMCWEB_LOG_DEBUG("Get Cpu Asset Data");
390     sdbusplus::asio::getAllProperties(
391         *crow::connections::systemBus, service, objPath,
392         "xyz.openbmc_project.Inventory.Decorator.Asset",
393         [objPath, asyncResp{std::move(asyncResp)}](
394             const boost::system::error_code& ec,
395             const dbus::utility::DBusPropertiesMap& properties) {
396         if (ec)
397         {
398             BMCWEB_LOG_DEBUG("DBUS response error");
399             messages::internalError(asyncResp->res);
400             return;
401         }
402 
403         const std::string* serialNumber = nullptr;
404         const std::string* model = nullptr;
405         const std::string* manufacturer = nullptr;
406         const std::string* partNumber = nullptr;
407         const std::string* sparePartNumber = nullptr;
408 
409         const bool success = sdbusplus::unpackPropertiesNoThrow(
410             dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber",
411             serialNumber, "Model", model, "Manufacturer", manufacturer,
412             "PartNumber", partNumber, "SparePartNumber", sparePartNumber);
413 
414         if (!success)
415         {
416             messages::internalError(asyncResp->res);
417             return;
418         }
419 
420         if (serialNumber != nullptr && !serialNumber->empty())
421         {
422             asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
423         }
424 
425         if ((model != nullptr) && !model->empty())
426         {
427             asyncResp->res.jsonValue["Model"] = *model;
428         }
429 
430         if (manufacturer != nullptr)
431         {
432             asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
433 
434             // Otherwise would be unexpected.
435             if (manufacturer->find("Intel") != std::string::npos)
436             {
437                 asyncResp->res.jsonValue["ProcessorArchitecture"] = "x86";
438                 asyncResp->res.jsonValue["InstructionSet"] = "x86-64";
439             }
440             else if (manufacturer->find("IBM") != std::string::npos)
441             {
442                 asyncResp->res.jsonValue["ProcessorArchitecture"] = "Power";
443                 asyncResp->res.jsonValue["InstructionSet"] = "PowerISA";
444             }
445         }
446 
447         if (partNumber != nullptr)
448         {
449             asyncResp->res.jsonValue["PartNumber"] = *partNumber;
450         }
451 
452         if (sparePartNumber != nullptr && !sparePartNumber->empty())
453         {
454             asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
455         }
456     });
457 }
458 
459 inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
460                                const std::string& service,
461                                const std::string& objPath)
462 {
463     BMCWEB_LOG_DEBUG("Get Cpu Revision Data");
464     sdbusplus::asio::getAllProperties(
465         *crow::connections::systemBus, service, objPath,
466         "xyz.openbmc_project.Inventory.Decorator.Revision",
467         [objPath, asyncResp{std::move(asyncResp)}](
468             const boost::system::error_code& ec,
469             const dbus::utility::DBusPropertiesMap& properties) {
470         if (ec)
471         {
472             BMCWEB_LOG_DEBUG("DBUS response error");
473             messages::internalError(asyncResp->res);
474             return;
475         }
476 
477         const std::string* version = nullptr;
478 
479         const bool success = sdbusplus::unpackPropertiesNoThrow(
480             dbus_utils::UnpackErrorPrinter(), properties, "Version", version);
481 
482         if (!success)
483         {
484             messages::internalError(asyncResp->res);
485             return;
486         }
487 
488         if (version != nullptr)
489         {
490             asyncResp->res.jsonValue["Version"] = *version;
491         }
492     });
493 }
494 
495 inline void getAcceleratorDataByService(
496     std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& acclrtrId,
497     const std::string& service, const std::string& objPath)
498 {
499     BMCWEB_LOG_DEBUG("Get available system Accelerator resources by service.");
500     sdbusplus::asio::getAllProperties(
501         *crow::connections::systemBus, service, objPath, "",
502         [acclrtrId, asyncResp{std::move(asyncResp)}](
503             const boost::system::error_code& ec,
504             const dbus::utility::DBusPropertiesMap& properties) {
505         if (ec)
506         {
507             BMCWEB_LOG_DEBUG("DBUS response error");
508             messages::internalError(asyncResp->res);
509             return;
510         }
511 
512         const bool* functional = nullptr;
513         const bool* present = nullptr;
514 
515         const bool success = sdbusplus::unpackPropertiesNoThrow(
516             dbus_utils::UnpackErrorPrinter(), properties, "Functional",
517             functional, "Present", present);
518 
519         if (!success)
520         {
521             messages::internalError(asyncResp->res);
522             return;
523         }
524 
525         std::string state = "Enabled";
526         std::string health = "OK";
527 
528         if (present != nullptr && !*present)
529         {
530             state = "Absent";
531         }
532 
533         if (functional != nullptr && !*functional)
534         {
535             if (state == "Enabled")
536             {
537                 health = "Critical";
538             }
539         }
540 
541         asyncResp->res.jsonValue["Id"] = acclrtrId;
542         asyncResp->res.jsonValue["Name"] = "Processor";
543         asyncResp->res.jsonValue["Status"]["State"] = state;
544         asyncResp->res.jsonValue["Status"]["Health"] = health;
545         asyncResp->res.jsonValue["ProcessorType"] = "Accelerator";
546     });
547 }
548 
549 // OperatingConfig D-Bus Types
550 using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>;
551 using BaseSpeedPrioritySettingsProperty =
552     std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>;
553 // uint32_t and size_t may or may not be the same type, requiring a dedup'd
554 // variant
555 
556 /**
557  * Fill out the HighSpeedCoreIDs in a Processor resource from the given
558  * OperatingConfig D-Bus property.
559  *
560  * @param[in,out]   asyncResp           Async HTTP response.
561  * @param[in]       baseSpeedSettings   Full list of base speed priority groups,
562  *                                      to use to determine the list of high
563  *                                      speed cores.
564  */
565 inline void highSpeedCoreIdsHandler(
566     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
567     const BaseSpeedPrioritySettingsProperty& baseSpeedSettings)
568 {
569     // The D-Bus property does not indicate which bucket is the "high
570     // priority" group, so let's discern that by looking for the one with
571     // highest base frequency.
572     auto highPriorityGroup = baseSpeedSettings.cend();
573     uint32_t highestBaseSpeed = 0;
574     for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend();
575          ++it)
576     {
577         const uint32_t baseFreq = std::get<uint32_t>(*it);
578         if (baseFreq > highestBaseSpeed)
579         {
580             highestBaseSpeed = baseFreq;
581             highPriorityGroup = it;
582         }
583     }
584 
585     nlohmann::json& jsonCoreIds = asyncResp->res.jsonValue["HighSpeedCoreIDs"];
586     jsonCoreIds = nlohmann::json::array();
587 
588     // There may not be any entries in the D-Bus property, so only populate
589     // if there was actually something there.
590     if (highPriorityGroup != baseSpeedSettings.cend())
591     {
592         jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup);
593     }
594 }
595 
596 /**
597  * Fill out OperatingConfig related items in a Processor resource by requesting
598  * data from the given D-Bus object.
599  *
600  * @param[in,out]   asyncResp       Async HTTP response.
601  * @param[in]       cpuId       CPU D-Bus name.
602  * @param[in]       service     D-Bus service to query.
603  * @param[in]       objPath     D-Bus object to query.
604  */
605 inline void
606     getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
607                      const std::string& cpuId, const std::string& service,
608                      const std::string& objPath)
609 {
610     BMCWEB_LOG_INFO("Getting CPU operating configs for {}", cpuId);
611 
612     // First, GetAll CurrentOperatingConfig properties on the object
613     sdbusplus::asio::getAllProperties(
614         *crow::connections::systemBus, service, objPath,
615         "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
616         [asyncResp, cpuId,
617          service](const boost::system::error_code& ec,
618                   const dbus::utility::DBusPropertiesMap& properties) {
619         if (ec)
620         {
621             BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
622             messages::internalError(asyncResp->res);
623             return;
624         }
625 
626         nlohmann::json& json = asyncResp->res.jsonValue;
627 
628         const sdbusplus::message::object_path* appliedConfig = nullptr;
629         const bool* baseSpeedPriorityEnabled = nullptr;
630 
631         const bool success = sdbusplus::unpackPropertiesNoThrow(
632             dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig",
633             appliedConfig, "BaseSpeedPriorityEnabled",
634             baseSpeedPriorityEnabled);
635 
636         if (!success)
637         {
638             messages::internalError(asyncResp->res);
639             return;
640         }
641 
642         if (appliedConfig != nullptr)
643         {
644             const std::string& dbusPath = appliedConfig->str;
645             nlohmann::json::object_t operatingConfig;
646             operatingConfig["@odata.id"] = boost::urls::format(
647                 "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs",
648                 cpuId);
649             json["OperatingConfigs"] = std::move(operatingConfig);
650 
651             // Reuse the D-Bus config object name for the Redfish
652             // URI
653             size_t baseNamePos = dbusPath.rfind('/');
654             if (baseNamePos == std::string::npos ||
655                 baseNamePos == (dbusPath.size() - 1))
656             {
657                 // If the AppliedConfig was somehow not a valid path,
658                 // skip adding any more properties, since everything
659                 // else is tied to this applied config.
660                 messages::internalError(asyncResp->res);
661                 return;
662             }
663             nlohmann::json::object_t appliedOperatingConfig;
664             appliedOperatingConfig["@odata.id"] = boost::urls::format(
665                 "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs/{}",
666                 cpuId, dbusPath.substr(baseNamePos + 1));
667             json["AppliedOperatingConfig"] = std::move(appliedOperatingConfig);
668 
669             // Once we found the current applied config, queue another
670             // request to read the base freq core ids out of that
671             // config.
672             sdbusplus::asio::getProperty<BaseSpeedPrioritySettingsProperty>(
673                 *crow::connections::systemBus, service, dbusPath,
674                 "xyz.openbmc_project.Inventory.Item.Cpu."
675                 "OperatingConfig",
676                 "BaseSpeedPrioritySettings",
677                 [asyncResp](
678                     const boost::system::error_code& ec2,
679                     const BaseSpeedPrioritySettingsProperty& baseSpeedList) {
680                 if (ec2)
681                 {
682                     BMCWEB_LOG_WARNING("D-Bus Property Get error: {}", ec2);
683                     messages::internalError(asyncResp->res);
684                     return;
685                 }
686 
687                 highSpeedCoreIdsHandler(asyncResp, baseSpeedList);
688             });
689         }
690 
691         if (baseSpeedPriorityEnabled != nullptr)
692         {
693             json["BaseSpeedPriorityState"] =
694                 *baseSpeedPriorityEnabled ? "Enabled" : "Disabled";
695         }
696     });
697 }
698 
699 /**
700  * @brief Fill out location info of a processor by
701  * requesting data from the given D-Bus object.
702  *
703  * @param[in,out]   asyncResp       Async HTTP response.
704  * @param[in]       service     D-Bus service to query.
705  * @param[in]       objPath     D-Bus object to query.
706  */
707 inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
708                                const std::string& service,
709                                const std::string& objPath)
710 {
711     BMCWEB_LOG_DEBUG("Get Cpu Location Data");
712     sdbusplus::asio::getProperty<std::string>(
713         *crow::connections::systemBus, service, objPath,
714         "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
715         [objPath, asyncResp{std::move(asyncResp)}](
716             const boost::system::error_code& ec, const std::string& property) {
717         if (ec)
718         {
719             BMCWEB_LOG_DEBUG("DBUS response error");
720             messages::internalError(asyncResp->res);
721             return;
722         }
723 
724         asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
725             property;
726     });
727 }
728 
729 /**
730  * Populate the unique identifier in a Processor resource by requesting data
731  * from the given D-Bus object.
732  *
733  * @param[in,out]   asyncResp   Async HTTP response.
734  * @param[in]       service     D-Bus service to query.
735  * @param[in]       objPath     D-Bus object to query.
736  */
737 inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
738                            const std::string& service,
739                            const std::string& objectPath)
740 {
741     BMCWEB_LOG_DEBUG("Get CPU UniqueIdentifier");
742     sdbusplus::asio::getProperty<std::string>(
743         *crow::connections::systemBus, service, objectPath,
744         "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
745         "UniqueIdentifier",
746         [asyncResp](const boost::system::error_code& ec,
747                     const std::string& id) {
748         if (ec)
749         {
750             BMCWEB_LOG_ERROR("Failed to read cpu unique id: {}", ec);
751             messages::internalError(asyncResp->res);
752             return;
753         }
754         asyncResp->res
755             .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id;
756     });
757 }
758 
759 /**
760  * Find the D-Bus object representing the requested Processor, and call the
761  * handler with the results. If matching object is not found, add 404 error to
762  * response and don't call the handler.
763  *
764  * @param[in,out]   resp            Async HTTP response.
765  * @param[in]       processorId     Redfish Processor Id.
766  * @param[in]       handler         Callback to continue processing request upon
767  *                                  successfully finding object.
768  */
769 template <typename Handler>
770 inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp,
771                                const std::string& processorId,
772                                Handler&& handler)
773 {
774     BMCWEB_LOG_DEBUG("Get available system processor resources.");
775 
776     // GetSubTree on all interfaces which provide info about a Processor
777     constexpr std::array<std::string_view, 9> interfaces = {
778         "xyz.openbmc_project.Common.UUID",
779         "xyz.openbmc_project.Inventory.Decorator.Asset",
780         "xyz.openbmc_project.Inventory.Decorator.Revision",
781         "xyz.openbmc_project.Inventory.Item.Cpu",
782         "xyz.openbmc_project.Inventory.Decorator.LocationCode",
783         "xyz.openbmc_project.Inventory.Item.Accelerator",
784         "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
785         "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
786         "xyz.openbmc_project.Control.Power.Throttle"};
787     dbus::utility::getSubTree(
788         "/xyz/openbmc_project/inventory", 0, interfaces,
789         [resp, processorId, handler = std::forward<Handler>(handler)](
790             const boost::system::error_code& ec,
791             const dbus::utility::MapperGetSubTreeResponse& subtree) {
792         if (ec)
793         {
794             BMCWEB_LOG_DEBUG("DBUS response error: {}", ec);
795             messages::internalError(resp->res);
796             return;
797         }
798         for (const auto& [objectPath, serviceMap] : subtree)
799         {
800             // Ignore any objects which don't end with our desired cpu name
801             if (!objectPath.ends_with(processorId))
802             {
803                 continue;
804             }
805 
806             bool found = false;
807             // Filter out objects that don't have the CPU-specific
808             // interfaces to make sure we can return 404 on non-CPUs
809             // (e.g. /redfish/../Processors/dimm0)
810             for (const auto& [serviceName, interfaceList] : serviceMap)
811             {
812                 if (std::ranges::find_first_of(interfaceList,
813                                                processorInterfaces) !=
814                     std::end(interfaceList))
815                 {
816                     found = true;
817                     break;
818                 }
819             }
820 
821             if (!found)
822             {
823                 continue;
824             }
825 
826             // Process the first object which does match our cpu name and
827             // required interfaces, and potentially ignore any other
828             // matching objects. Assume all interfaces we want to process
829             // must be on the same object path.
830 
831             handler(objectPath, serviceMap);
832             return;
833         }
834         messages::resourceNotFound(resp->res, "Processor", processorId);
835     });
836 }
837 
838 inline void
839     getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
840                      const std::string& processorId,
841                      const std::string& objectPath,
842                      const dbus::utility::MapperServiceMap& serviceMap)
843 {
844     for (const auto& [serviceName, interfaceList] : serviceMap)
845     {
846         for (const auto& interface : interfaceList)
847         {
848             if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
849             {
850                 getCpuAssetData(asyncResp, serviceName, objectPath);
851             }
852             else if (interface ==
853                      "xyz.openbmc_project.Inventory.Decorator.Revision")
854             {
855                 getCpuRevisionData(asyncResp, serviceName, objectPath);
856             }
857             else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu")
858             {
859                 getCpuDataByService(asyncResp, processorId, serviceName,
860                                     objectPath);
861             }
862             else if (interface ==
863                      "xyz.openbmc_project.Inventory.Item.Accelerator")
864             {
865                 getAcceleratorDataByService(asyncResp, processorId, serviceName,
866                                             objectPath);
867             }
868             else if (
869                 interface ==
870                 "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig")
871             {
872                 getCpuConfigData(asyncResp, processorId, serviceName,
873                                  objectPath);
874             }
875             else if (interface ==
876                      "xyz.openbmc_project.Inventory.Decorator.LocationCode")
877             {
878                 getCpuLocationCode(asyncResp, serviceName, objectPath);
879             }
880             else if (interface == "xyz.openbmc_project.Common.UUID")
881             {
882                 getProcessorUUID(asyncResp, serviceName, objectPath);
883             }
884             else if (interface ==
885                      "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier")
886             {
887                 getCpuUniqueId(asyncResp, serviceName, objectPath);
888             }
889             else if (interface == "xyz.openbmc_project.Control.Power.Throttle")
890             {
891                 getThrottleProperties(asyncResp, serviceName, objectPath);
892             }
893         }
894     }
895 }
896 
897 /**
898  * Request all the properties for the given D-Bus object and fill out the
899  * related entries in the Redfish OperatingConfig response.
900  *
901  * @param[in,out]   asyncResp       Async HTTP response.
902  * @param[in]       service     D-Bus service name to query.
903  * @param[in]       objPath     D-Bus object to query.
904  */
905 inline void
906     getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
907                            const std::string& service,
908                            const std::string& objPath)
909 {
910     sdbusplus::asio::getAllProperties(
911         *crow::connections::systemBus, service, objPath,
912         "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
913         [asyncResp](const boost::system::error_code& ec,
914                     const dbus::utility::DBusPropertiesMap& properties) {
915         if (ec)
916         {
917             BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
918             messages::internalError(asyncResp->res);
919             return;
920         }
921 
922         const size_t* availableCoreCount = nullptr;
923         const uint32_t* baseSpeed = nullptr;
924         const uint32_t* maxJunctionTemperature = nullptr;
925         const uint32_t* maxSpeed = nullptr;
926         const uint32_t* powerLimit = nullptr;
927         const TurboProfileProperty* turboProfile = nullptr;
928         const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings =
929             nullptr;
930 
931         const bool success = sdbusplus::unpackPropertiesNoThrow(
932             dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount",
933             availableCoreCount, "BaseSpeed", baseSpeed,
934             "MaxJunctionTemperature", maxJunctionTemperature, "MaxSpeed",
935             maxSpeed, "PowerLimit", powerLimit, "TurboProfile", turboProfile,
936             "BaseSpeedPrioritySettings", baseSpeedPrioritySettings);
937 
938         if (!success)
939         {
940             messages::internalError(asyncResp->res);
941             return;
942         }
943 
944         nlohmann::json& json = asyncResp->res.jsonValue;
945 
946         if (availableCoreCount != nullptr)
947         {
948             json["TotalAvailableCoreCount"] = *availableCoreCount;
949         }
950 
951         if (baseSpeed != nullptr)
952         {
953             json["BaseSpeedMHz"] = *baseSpeed;
954         }
955 
956         if (maxJunctionTemperature != nullptr)
957         {
958             json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature;
959         }
960 
961         if (maxSpeed != nullptr)
962         {
963             json["MaxSpeedMHz"] = *maxSpeed;
964         }
965 
966         if (powerLimit != nullptr)
967         {
968             json["TDPWatts"] = *powerLimit;
969         }
970 
971         if (turboProfile != nullptr)
972         {
973             nlohmann::json& turboArray = json["TurboProfile"];
974             turboArray = nlohmann::json::array();
975             for (const auto& [turboSpeed, coreCount] : *turboProfile)
976             {
977                 nlohmann::json::object_t turbo;
978                 turbo["ActiveCoreCount"] = coreCount;
979                 turbo["MaxSpeedMHz"] = turboSpeed;
980                 turboArray.emplace_back(std::move(turbo));
981             }
982         }
983 
984         if (baseSpeedPrioritySettings != nullptr)
985         {
986             nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"];
987             baseSpeedArray = nlohmann::json::array();
988             for (const auto& [baseSpeedMhz, coreList] :
989                  *baseSpeedPrioritySettings)
990             {
991                 nlohmann::json::object_t speed;
992                 speed["CoreCount"] = coreList.size();
993                 speed["CoreIDs"] = coreList;
994                 speed["BaseSpeedMHz"] = baseSpeedMhz;
995                 baseSpeedArray.emplace_back(std::move(speed));
996             }
997         }
998     });
999 }
1000 
1001 /**
1002  * Handle the D-Bus response from attempting to set the CPU's AppliedConfig
1003  * property. Main task is to translate error messages into Redfish errors.
1004  *
1005  * @param[in,out]   resp    HTTP response.
1006  * @param[in]       setPropVal  Value which we attempted to set.
1007  * @param[in]       ec      D-Bus response error code.
1008  * @param[in]       msg     D-Bus response message.
1009  */
1010 inline void
1011     handleAppliedConfigResponse(const std::shared_ptr<bmcweb::AsyncResp>& resp,
1012                                 const std::string& setPropVal,
1013                                 const boost::system::error_code& ec,
1014                                 const sdbusplus::message_t& msg)
1015 {
1016     if (!ec)
1017     {
1018         BMCWEB_LOG_DEBUG("Set Property succeeded");
1019         return;
1020     }
1021 
1022     BMCWEB_LOG_DEBUG("Set Property failed: {}", ec);
1023 
1024     const sd_bus_error* dbusError = msg.get_error();
1025     if (dbusError == nullptr)
1026     {
1027         messages::internalError(resp->res);
1028         return;
1029     }
1030 
1031     // The asio error code doesn't know about our custom errors, so we have to
1032     // parse the error string. Some of these D-Bus -> Redfish translations are a
1033     // stretch, but it's good to try to communicate something vaguely useful.
1034     if (strcmp(dbusError->name,
1035                "xyz.openbmc_project.Common.Error.InvalidArgument") == 0)
1036     {
1037         // Service did not like the object_path we tried to set.
1038         messages::propertyValueIncorrect(
1039             resp->res, "AppliedOperatingConfig/@odata.id", setPropVal);
1040     }
1041     else if (strcmp(dbusError->name,
1042                     "xyz.openbmc_project.Common.Error.NotAllowed") == 0)
1043     {
1044         // Service indicates we can never change the config for this processor.
1045         messages::propertyNotWritable(resp->res, "AppliedOperatingConfig");
1046     }
1047     else if (strcmp(dbusError->name,
1048                     "xyz.openbmc_project.Common.Error.Unavailable") == 0)
1049     {
1050         // Service indicates the config cannot be changed right now, but maybe
1051         // in a different system state.
1052         messages::resourceInStandby(resp->res);
1053     }
1054     else
1055     {
1056         messages::internalError(resp->res);
1057     }
1058 }
1059 
1060 /**
1061  * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic
1062  * validation of the input data, and then set the D-Bus property.
1063  *
1064  * @param[in,out]   resp            Async HTTP response.
1065  * @param[in]       processorId     Processor's Id.
1066  * @param[in]       appliedConfigUri    New property value to apply.
1067  * @param[in]       cpuObjectPath   Path of CPU object to modify.
1068  * @param[in]       serviceMap      Service map for CPU object.
1069  */
1070 inline void patchAppliedOperatingConfig(
1071     const std::shared_ptr<bmcweb::AsyncResp>& resp,
1072     const std::string& processorId, const std::string& appliedConfigUri,
1073     const std::string& cpuObjectPath,
1074     const dbus::utility::MapperServiceMap& serviceMap)
1075 {
1076     // Check that the property even exists by checking for the interface
1077     const std::string* controlService = nullptr;
1078     for (const auto& [serviceName, interfaceList] : serviceMap)
1079     {
1080         if (std::ranges::find(interfaceList,
1081                               "xyz.openbmc_project.Control.Processor."
1082                               "CurrentOperatingConfig") != interfaceList.end())
1083         {
1084             controlService = &serviceName;
1085             break;
1086         }
1087     }
1088 
1089     if (controlService == nullptr)
1090     {
1091         messages::internalError(resp->res);
1092         return;
1093     }
1094 
1095     // Check that the config URI is a child of the cpu URI being patched.
1096     std::string expectedPrefix("/redfish/v1/Systems/system/Processors/");
1097     expectedPrefix += processorId;
1098     expectedPrefix += "/OperatingConfigs/";
1099     if (!appliedConfigUri.starts_with(expectedPrefix) ||
1100         expectedPrefix.size() == appliedConfigUri.size())
1101     {
1102         messages::propertyValueIncorrect(
1103             resp->res, "AppliedOperatingConfig/@odata.id", appliedConfigUri);
1104         return;
1105     }
1106 
1107     // Generate the D-Bus path of the OperatingConfig object, by assuming it's a
1108     // direct child of the CPU object.
1109     // Strip the expectedPrefix from the config URI to get the "filename", and
1110     // append to the CPU's path.
1111     std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size());
1112     sdbusplus::message::object_path configPath(cpuObjectPath);
1113     configPath /= configBaseName;
1114 
1115     BMCWEB_LOG_INFO("Setting config to {}", configPath.str);
1116 
1117     // Set the property, with handler to check error responses
1118     sdbusplus::asio::setProperty(
1119         *crow::connections::systemBus, *controlService, cpuObjectPath,
1120         "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
1121         "AppliedConfig", configPath,
1122         [resp, appliedConfigUri](const boost::system::error_code& ec,
1123                                  const sdbusplus::message_t& msg) {
1124         handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg);
1125     });
1126 }
1127 
1128 inline void
1129     handleProcessorHead(crow::App& app, const crow::Request& req,
1130                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1131                         const std::string& /* systemName */,
1132                         const std::string& /* processorId */)
1133 {
1134     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1135     {
1136         return;
1137     }
1138     asyncResp->res.addHeader(
1139         boost::beast::http::field::link,
1140         "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1141 }
1142 
1143 inline void handleProcessorCollectionHead(
1144     crow::App& app, const crow::Request& req,
1145     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1146     const std::string& /* systemName */)
1147 {
1148     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1149     {
1150         return;
1151     }
1152     asyncResp->res.addHeader(
1153         boost::beast::http::field::link,
1154         "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1155 }
1156 
1157 inline void requestRoutesOperatingConfigCollection(App& app)
1158 {
1159     BMCWEB_ROUTE(app,
1160                  "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/")
1161         .privileges(redfish::privileges::getOperatingConfigCollection)
1162         .methods(boost::beast::http::verb::get)(
1163             [&app](const crow::Request& req,
1164                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1165                    const std::string& systemName, const std::string& cpuName) {
1166         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1167         {
1168             return;
1169         }
1170 
1171         if constexpr (bmcwebEnableMultiHost)
1172         {
1173             // Option currently returns no systems.  TBD
1174             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1175                                        systemName);
1176             return;
1177         }
1178 
1179         if (systemName != "system")
1180         {
1181             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1182                                        systemName);
1183             return;
1184         }
1185         asyncResp->res.jsonValue["@odata.type"] =
1186             "#OperatingConfigCollection.OperatingConfigCollection";
1187         asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1188             "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs",
1189             cpuName);
1190         asyncResp->res.jsonValue["Name"] = "Operating Config Collection";
1191 
1192         // First find the matching CPU object so we know how to
1193         // constrain our search for related Config objects.
1194         const std::array<std::string_view, 1> interfaces = {
1195             "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"};
1196         dbus::utility::getSubTreePaths(
1197             "/xyz/openbmc_project/inventory", 0, interfaces,
1198             [asyncResp, cpuName](
1199                 const boost::system::error_code& ec,
1200                 const dbus::utility::MapperGetSubTreePathsResponse& objects) {
1201             if (ec)
1202             {
1203                 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
1204                 messages::internalError(asyncResp->res);
1205                 return;
1206             }
1207 
1208             for (const std::string& object : objects)
1209             {
1210                 if (!object.ends_with(cpuName))
1211                 {
1212                     continue;
1213                 }
1214 
1215                 // Not expected that there will be multiple matching
1216                 // CPU objects, but if there are just use the first
1217                 // one.
1218 
1219                 // Use the common search routine to construct the
1220                 // Collection of all Config objects under this CPU.
1221                 constexpr std::array<std::string_view, 1> interface{
1222                     "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1223                 collection_util::getCollectionMembers(
1224                     asyncResp,
1225                     boost::urls::format(
1226                         "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs",
1227                         cpuName),
1228                     interface, object);
1229                 return;
1230             }
1231         });
1232     });
1233 }
1234 
1235 inline void requestRoutesOperatingConfig(App& app)
1236 {
1237     BMCWEB_ROUTE(
1238         app,
1239         "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/")
1240         .privileges(redfish::privileges::getOperatingConfig)
1241         .methods(boost::beast::http::verb::get)(
1242             [&app](const crow::Request& req,
1243                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1244                    const std::string& systemName, const std::string& cpuName,
1245                    const std::string& configName) {
1246         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1247         {
1248             return;
1249         }
1250         if constexpr (bmcwebEnableMultiHost)
1251         {
1252             // Option currently returns no systems.  TBD
1253             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1254                                        systemName);
1255             return;
1256         }
1257 
1258         if (systemName != "system")
1259         {
1260             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1261                                        systemName);
1262             return;
1263         }
1264         // Ask for all objects implementing OperatingConfig so we can search
1265         // for one with a matching name
1266         constexpr std::array<std::string_view, 1> interfaces = {
1267             "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
1268         dbus::utility::getSubTree(
1269             "/xyz/openbmc_project/inventory", 0, interfaces,
1270             [asyncResp, cpuName, configName](
1271                 const boost::system::error_code& ec,
1272                 const dbus::utility::MapperGetSubTreeResponse& subtree) {
1273             if (ec)
1274             {
1275                 BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
1276                 messages::internalError(asyncResp->res);
1277                 return;
1278             }
1279             const std::string expectedEnding = cpuName + '/' + configName;
1280             for (const auto& [objectPath, serviceMap] : subtree)
1281             {
1282                 // Ignore any configs without matching cpuX/configY
1283                 if (!objectPath.ends_with(expectedEnding) || serviceMap.empty())
1284                 {
1285                     continue;
1286                 }
1287 
1288                 nlohmann::json& json = asyncResp->res.jsonValue;
1289                 json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig";
1290                 json["@odata.id"] = boost::urls::format(
1291                     "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs/{}",
1292                     cpuName, configName);
1293                 json["Name"] = "Processor Profile";
1294                 json["Id"] = configName;
1295 
1296                 // Just use the first implementation of the object - not
1297                 // expected that there would be multiple matching
1298                 // services
1299                 getOperatingConfigData(asyncResp, serviceMap.begin()->first,
1300                                        objectPath);
1301                 return;
1302             }
1303             messages::resourceNotFound(asyncResp->res, "OperatingConfig",
1304                                        configName);
1305         });
1306     });
1307 }
1308 
1309 inline void requestRoutesProcessorCollection(App& app)
1310 {
1311     /**
1312      * Functions triggers appropriate requests on DBus
1313      */
1314     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
1315         .privileges(redfish::privileges::headProcessorCollection)
1316         .methods(boost::beast::http::verb::head)(
1317             std::bind_front(handleProcessorCollectionHead, std::ref(app)));
1318 
1319     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
1320         .privileges(redfish::privileges::getProcessorCollection)
1321         .methods(boost::beast::http::verb::get)(
1322             [&app](const crow::Request& req,
1323                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1324                    const std::string& systemName) {
1325         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1326         {
1327             return;
1328         }
1329         if constexpr (bmcwebEnableMultiHost)
1330         {
1331             // Option currently returns no systems.  TBD
1332             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1333                                        systemName);
1334             return;
1335         }
1336 
1337         if (systemName != "system")
1338         {
1339             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1340                                        systemName);
1341             return;
1342         }
1343 
1344         asyncResp->res.addHeader(
1345             boost::beast::http::field::link,
1346             "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby");
1347 
1348         asyncResp->res.jsonValue["@odata.type"] =
1349             "#ProcessorCollection.ProcessorCollection";
1350         asyncResp->res.jsonValue["Name"] = "Processor Collection";
1351 
1352         asyncResp->res.jsonValue["@odata.id"] =
1353             "/redfish/v1/Systems/system/Processors";
1354 
1355         collection_util::getCollectionMembers(
1356             asyncResp,
1357             boost::urls::url("/redfish/v1/Systems/system/Processors"),
1358             processorInterfaces, "/xyz/openbmc_project/inventory");
1359     });
1360 }
1361 
1362 inline void requestRoutesProcessor(App& app)
1363 {
1364     /**
1365      * Functions triggers appropriate requests on DBus
1366      */
1367 
1368     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
1369         .privileges(redfish::privileges::headProcessor)
1370         .methods(boost::beast::http::verb::head)(
1371             std::bind_front(handleProcessorHead, std::ref(app)));
1372 
1373     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
1374         .privileges(redfish::privileges::getProcessor)
1375         .methods(boost::beast::http::verb::get)(
1376             [&app](const crow::Request& req,
1377                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1378                    const std::string& systemName,
1379                    const std::string& processorId) {
1380         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1381         {
1382             return;
1383         }
1384         if constexpr (bmcwebEnableMultiHost)
1385         {
1386             // Option currently returns no systems.  TBD
1387             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1388                                        systemName);
1389             return;
1390         }
1391         if (systemName != "system")
1392         {
1393             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1394                                        systemName);
1395             return;
1396         }
1397 
1398         asyncResp->res.addHeader(
1399             boost::beast::http::field::link,
1400             "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby");
1401         asyncResp->res.jsonValue["@odata.type"] =
1402             "#Processor.v1_18_0.Processor";
1403         asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
1404             "/redfish/v1/Systems/system/Processors/{}", processorId);
1405 
1406         getProcessorObject(
1407             asyncResp, processorId,
1408             std::bind_front(getProcessorData, asyncResp, processorId));
1409     });
1410 
1411     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
1412         .privileges(redfish::privileges::patchProcessor)
1413         .methods(boost::beast::http::verb::patch)(
1414             [&app](const crow::Request& req,
1415                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1416                    const std::string& systemName,
1417                    const std::string& processorId) {
1418         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1419         {
1420             return;
1421         }
1422         if constexpr (bmcwebEnableMultiHost)
1423         {
1424             // Option currently returns no systems.  TBD
1425             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1426                                        systemName);
1427             return;
1428         }
1429         if (systemName != "system")
1430         {
1431             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
1432                                        systemName);
1433             return;
1434         }
1435 
1436         std::optional<std::string> appliedConfigUri;
1437         if (!json_util::readJsonPatch(req, asyncResp->res,
1438                                       "AppliedOperatingConfig/@odata.id",
1439                                       appliedConfigUri))
1440         {
1441             return;
1442         }
1443 
1444         if (appliedConfigUri)
1445         {
1446             // Check for 404 and find matching D-Bus object, then run
1447             // property patch handlers if that all succeeds.
1448             getProcessorObject(asyncResp, processorId,
1449                                std::bind_front(patchAppliedOperatingConfig,
1450                                                asyncResp, processorId,
1451                                                *appliedConfigUri));
1452         }
1453     });
1454 }
1455 
1456 } // namespace redfish
1457