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