1ac6a4445SGunnar Mills /* 2ac6a4445SGunnar Mills // Copyright (c) 2018 Intel Corporation 3ac6a4445SGunnar Mills // 4ac6a4445SGunnar Mills // Licensed under the Apache License, Version 2.0 (the "License"); 5ac6a4445SGunnar Mills // you may not use this file except in compliance with the License. 6ac6a4445SGunnar Mills // You may obtain a copy of the License at 7ac6a4445SGunnar Mills // 8ac6a4445SGunnar Mills // http://www.apache.org/licenses/LICENSE-2.0 9ac6a4445SGunnar Mills // 10ac6a4445SGunnar Mills // Unless required by applicable law or agreed to in writing, software 11ac6a4445SGunnar Mills // distributed under the License is distributed on an "AS IS" BASIS, 12ac6a4445SGunnar Mills // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ac6a4445SGunnar Mills // See the License for the specific language governing permissions and 14ac6a4445SGunnar Mills // limitations under the License. 15ac6a4445SGunnar Mills */ 16ac6a4445SGunnar Mills #pragma once 17ac6a4445SGunnar Mills 183ccb3adbSEd Tanous #include "app.hpp" 191e1e598dSJonathan Doman #include "dbus_singleton.hpp" 207a1dbc48SGeorge Liu #include "dbus_utility.hpp" 211e1e598dSJonathan Doman #include "error_messages.hpp" 22dfbf7de5SChris Cain #include "generated/enums/processor.hpp" 233ccb3adbSEd Tanous #include "query.hpp" 243ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 253ccb3adbSEd Tanous #include "utils/collection.hpp" 263ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 273ccb3adbSEd Tanous #include "utils/json_utils.hpp" 28ac6a4445SGunnar Mills 29ac6a4445SGunnar Mills #include <boost/container/flat_map.hpp> 30e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 31ef4c65b7SEd Tanous #include <boost/url/format.hpp> 321e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 33dba0c291SJonathan Doman #include <sdbusplus/message/native_types.hpp> 34351053f2SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 35dba0c291SJonathan Doman #include <sdbusplus/utility/dedup_variant.hpp> 36ac6a4445SGunnar Mills 377a1dbc48SGeorge Liu #include <array> 38b9d679d1SMichael Shen #include <limits> 393544d2a7SEd Tanous #include <ranges> 403c569218SEd Tanous #include <string> 417a1dbc48SGeorge Liu #include <string_view> 427a1dbc48SGeorge Liu 43ac6a4445SGunnar Mills namespace redfish 44ac6a4445SGunnar Mills { 45ac6a4445SGunnar Mills 46c951448aSJonathan Doman // Interfaces which imply a D-Bus object represents a Processor 477a1dbc48SGeorge Liu constexpr std::array<std::string_view, 2> processorInterfaces = { 48c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu", 49c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Accelerator"}; 502bab9831SJonathan Doman 5171b82f26SSharad Yadav /** 5271b82f26SSharad Yadav * @brief Fill out uuid info of a processor by 5371b82f26SSharad Yadav * requesting data from the given D-Bus object. 5471b82f26SSharad Yadav * 55ac106bf6SEd Tanous * @param[in,out] asyncResp Async HTTP response. 5671b82f26SSharad Yadav * @param[in] service D-Bus service to query. 5771b82f26SSharad Yadav * @param[in] objPath D-Bus object to query. 5871b82f26SSharad Yadav */ 59ac106bf6SEd Tanous inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 6071b82f26SSharad Yadav const std::string& service, 6171b82f26SSharad Yadav const std::string& objPath) 6271b82f26SSharad Yadav { 6362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Processor UUID"); 641e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 651e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 661e1e598dSJonathan Doman "xyz.openbmc_project.Common.UUID", "UUID", 67ac106bf6SEd Tanous [objPath, asyncResp{std::move(asyncResp)}]( 68ac106bf6SEd Tanous const boost::system::error_code& ec, const std::string& property) { 6971b82f26SSharad Yadav if (ec) 7071b82f26SSharad Yadav { 7162598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error"); 72ac106bf6SEd Tanous messages::internalError(asyncResp->res); 7371b82f26SSharad Yadav return; 7471b82f26SSharad Yadav } 75ac106bf6SEd Tanous asyncResp->res.jsonValue["UUID"] = property; 761e1e598dSJonathan Doman }); 7771b82f26SSharad Yadav } 7871b82f26SSharad Yadav 79711ac7a9SEd Tanous inline void getCpuDataByInterface( 80ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8180f79a40SMichael Shen const dbus::utility::DBusInterfacesMap& cpuInterfacesProperties) 82ac6a4445SGunnar Mills { 8362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get CPU resources by interface."); 84ac6a4445SGunnar Mills 85a1649ec6SChicago Duan // Set the default value of state 86ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 87ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 88ac6a4445SGunnar Mills 89ac6a4445SGunnar Mills for (const auto& interface : cpuInterfacesProperties) 90ac6a4445SGunnar Mills { 91ac6a4445SGunnar Mills for (const auto& property : interface.second) 92ac6a4445SGunnar Mills { 93a1649ec6SChicago Duan if (property.first == "Present") 94ac6a4445SGunnar Mills { 95a1649ec6SChicago Duan const bool* cpuPresent = std::get_if<bool>(&property.second); 96a1649ec6SChicago Duan if (cpuPresent == nullptr) 97ac6a4445SGunnar Mills { 98ac6a4445SGunnar Mills // Important property not in desired type 99ac106bf6SEd Tanous messages::internalError(asyncResp->res); 100ac6a4445SGunnar Mills return; 101ac6a4445SGunnar Mills } 102e05aec50SEd Tanous if (!*cpuPresent) 103ac6a4445SGunnar Mills { 104a1649ec6SChicago Duan // Slot is not populated 105ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Absent"; 106a1649ec6SChicago Duan } 107a1649ec6SChicago Duan } 108a1649ec6SChicago Duan else if (property.first == "Functional") 109a1649ec6SChicago Duan { 110a1649ec6SChicago Duan const bool* cpuFunctional = std::get_if<bool>(&property.second); 111a1649ec6SChicago Duan if (cpuFunctional == nullptr) 112a1649ec6SChicago Duan { 113ac106bf6SEd Tanous messages::internalError(asyncResp->res); 114ac6a4445SGunnar Mills return; 115ac6a4445SGunnar Mills } 116e05aec50SEd Tanous if (!*cpuFunctional) 117a1649ec6SChicago Duan { 118ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; 119a1649ec6SChicago Duan } 120a1649ec6SChicago Duan } 121a1649ec6SChicago Duan else if (property.first == "CoreCount") 122a1649ec6SChicago Duan { 123a1649ec6SChicago Duan const uint16_t* coresCount = 124a1649ec6SChicago Duan std::get_if<uint16_t>(&property.second); 125a1649ec6SChicago Duan if (coresCount == nullptr) 126a1649ec6SChicago Duan { 127ac106bf6SEd Tanous messages::internalError(asyncResp->res); 128a1649ec6SChicago Duan return; 129a1649ec6SChicago Duan } 130ac106bf6SEd Tanous asyncResp->res.jsonValue["TotalCores"] = *coresCount; 131ac6a4445SGunnar Mills } 132dc3fa667SJonathan Doman else if (property.first == "MaxSpeedInMhz") 133dc3fa667SJonathan Doman { 134dc3fa667SJonathan Doman const uint32_t* value = std::get_if<uint32_t>(&property.second); 135dc3fa667SJonathan Doman if (value != nullptr) 136dc3fa667SJonathan Doman { 137ac106bf6SEd Tanous asyncResp->res.jsonValue["MaxSpeedMHz"] = *value; 138dc3fa667SJonathan Doman } 139dc3fa667SJonathan Doman } 140ac6a4445SGunnar Mills else if (property.first == "Socket") 141ac6a4445SGunnar Mills { 142ac6a4445SGunnar Mills const std::string* value = 143ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 144ac6a4445SGunnar Mills if (value != nullptr) 145ac6a4445SGunnar Mills { 146ac106bf6SEd Tanous asyncResp->res.jsonValue["Socket"] = *value; 147ac6a4445SGunnar Mills } 148ac6a4445SGunnar Mills } 149ac6a4445SGunnar Mills else if (property.first == "ThreadCount") 150ac6a4445SGunnar Mills { 151dc3fa667SJonathan Doman const uint16_t* value = std::get_if<uint16_t>(&property.second); 152ac6a4445SGunnar Mills if (value != nullptr) 153ac6a4445SGunnar Mills { 154ac106bf6SEd Tanous asyncResp->res.jsonValue["TotalThreads"] = *value; 155ac6a4445SGunnar Mills } 156ac6a4445SGunnar Mills } 1571930fbd4SBrandon Kim else if (property.first == "EffectiveFamily") 158ac6a4445SGunnar Mills { 1591930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1606169de2cSBrad Bishop if (value != nullptr && *value != 2) 161ac6a4445SGunnar Mills { 162ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] = 163866e4862SEd Tanous "0x" + intToHexString(*value, 4); 164ac6a4445SGunnar Mills } 165ac6a4445SGunnar Mills } 1661930fbd4SBrandon Kim else if (property.first == "EffectiveModel") 1671930fbd4SBrandon Kim { 1681930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1691930fbd4SBrandon Kim if (value == nullptr) 1701930fbd4SBrandon Kim { 171ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1721930fbd4SBrandon Kim return; 1731930fbd4SBrandon Kim } 1746169de2cSBrad Bishop if (*value != 0) 1756169de2cSBrad Bishop { 176ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorId"]["EffectiveModel"] = 177866e4862SEd Tanous "0x" + intToHexString(*value, 4); 1781930fbd4SBrandon Kim } 1796169de2cSBrad Bishop } 180ac6a4445SGunnar Mills else if (property.first == "Id") 181ac6a4445SGunnar Mills { 182ac6a4445SGunnar Mills const uint64_t* value = std::get_if<uint64_t>(&property.second); 183ac6a4445SGunnar Mills if (value != nullptr && *value != 0) 184ac6a4445SGunnar Mills { 185ac106bf6SEd Tanous asyncResp->res 186ac6a4445SGunnar Mills .jsonValue["ProcessorId"]["IdentificationRegisters"] = 187866e4862SEd Tanous "0x" + intToHexString(*value, 16); 188ac6a4445SGunnar Mills } 189ac6a4445SGunnar Mills } 1901930fbd4SBrandon Kim else if (property.first == "Microcode") 1911930fbd4SBrandon Kim { 1921930fbd4SBrandon Kim const uint32_t* value = std::get_if<uint32_t>(&property.second); 1931930fbd4SBrandon Kim if (value == nullptr) 1941930fbd4SBrandon Kim { 195ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1961930fbd4SBrandon Kim return; 1971930fbd4SBrandon Kim } 1986169de2cSBrad Bishop if (*value != 0) 1996169de2cSBrad Bishop { 200ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] = 201866e4862SEd Tanous "0x" + intToHexString(*value, 8); 2021930fbd4SBrandon Kim } 2036169de2cSBrad Bishop } 2041930fbd4SBrandon Kim else if (property.first == "Step") 2051930fbd4SBrandon Kim { 2061930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 2071930fbd4SBrandon Kim if (value == nullptr) 2081930fbd4SBrandon Kim { 209ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2101930fbd4SBrandon Kim return; 2111930fbd4SBrandon Kim } 212b9d679d1SMichael Shen if (*value != std::numeric_limits<uint16_t>::max()) 2136169de2cSBrad Bishop { 214ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorId"]["Step"] = 215866e4862SEd Tanous "0x" + intToHexString(*value, 4); 2161930fbd4SBrandon Kim } 217ac6a4445SGunnar Mills } 218ac6a4445SGunnar Mills } 219ac6a4445SGunnar Mills } 2206169de2cSBrad Bishop } 221ac6a4445SGunnar Mills 222ac106bf6SEd Tanous inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 223ac6a4445SGunnar Mills const std::string& cpuId, 224ac6a4445SGunnar Mills const std::string& service, 225ac6a4445SGunnar Mills const std::string& objPath) 226ac6a4445SGunnar Mills { 22762598e31SEd Tanous BMCWEB_LOG_DEBUG("Get available system cpu resources by service."); 228ac6a4445SGunnar Mills 2295eb468daSGeorge Liu sdbusplus::message::object_path path("/xyz/openbmc_project/inventory"); 2305eb468daSGeorge Liu dbus::utility::getManagedObjects( 2315eb468daSGeorge Liu service, path, 232ac106bf6SEd Tanous [cpuId, service, objPath, asyncResp{std::move(asyncResp)}]( 2335e7e2dc5SEd Tanous const boost::system::error_code& ec, 234ac6a4445SGunnar Mills const dbus::utility::ManagedObjectType& dbusData) { 235ac6a4445SGunnar Mills if (ec) 236ac6a4445SGunnar Mills { 23762598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error"); 238ac106bf6SEd Tanous messages::internalError(asyncResp->res); 239ac6a4445SGunnar Mills return; 240ac6a4445SGunnar Mills } 241ac106bf6SEd Tanous asyncResp->res.jsonValue["Id"] = cpuId; 242ac106bf6SEd Tanous asyncResp->res.jsonValue["Name"] = "Processor"; 243ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorType"] = "CPU"; 244ac6a4445SGunnar Mills 245ac6a4445SGunnar Mills bool slotPresent = false; 246ac6a4445SGunnar Mills std::string corePath = objPath + "/core"; 247ac6a4445SGunnar Mills size_t totalCores = 0; 248ac6a4445SGunnar Mills for (const auto& object : dbusData) 249ac6a4445SGunnar Mills { 250ac6a4445SGunnar Mills if (object.first.str == objPath) 251ac6a4445SGunnar Mills { 252ac106bf6SEd Tanous getCpuDataByInterface(asyncResp, object.second); 253ac6a4445SGunnar Mills } 25411ba3979SEd Tanous else if (object.first.str.starts_with(corePath)) 255ac6a4445SGunnar Mills { 256ac6a4445SGunnar Mills for (const auto& interface : object.second) 257ac6a4445SGunnar Mills { 258002d39b4SEd Tanous if (interface.first == "xyz.openbmc_project.Inventory.Item") 259ac6a4445SGunnar Mills { 260ac6a4445SGunnar Mills for (const auto& property : interface.second) 261ac6a4445SGunnar Mills { 262ac6a4445SGunnar Mills if (property.first == "Present") 263ac6a4445SGunnar Mills { 264ac6a4445SGunnar Mills const bool* present = 265ac6a4445SGunnar Mills std::get_if<bool>(&property.second); 266ac6a4445SGunnar Mills if (present != nullptr) 267ac6a4445SGunnar Mills { 268e05aec50SEd Tanous if (*present) 269ac6a4445SGunnar Mills { 270ac6a4445SGunnar Mills slotPresent = true; 271ac6a4445SGunnar Mills totalCores++; 272ac6a4445SGunnar Mills } 273ac6a4445SGunnar Mills } 274ac6a4445SGunnar Mills } 275ac6a4445SGunnar Mills } 276ac6a4445SGunnar Mills } 277ac6a4445SGunnar Mills } 278ac6a4445SGunnar Mills } 279ac6a4445SGunnar Mills } 280ac6a4445SGunnar Mills // In getCpuDataByInterface(), state and health are set 281ac6a4445SGunnar Mills // based on the present and functional status. If core 282ac6a4445SGunnar Mills // count is zero, then it has a higher precedence. 283ac6a4445SGunnar Mills if (slotPresent) 284ac6a4445SGunnar Mills { 285ac106bf6SEd Tanous asyncResp->res.jsonValue["TotalCores"] = totalCores; 286ac6a4445SGunnar Mills } 287ac6a4445SGunnar Mills return; 2885eb468daSGeorge Liu }); 289ac6a4445SGunnar Mills } 290ac6a4445SGunnar Mills 291dfbf7de5SChris Cain /** 292dfbf7de5SChris Cain * @brief Translates throttle cause DBUS property to redfish. 293dfbf7de5SChris Cain * 294dfbf7de5SChris Cain * @param[in] dbusSource The throttle cause from DBUS 295dfbf7de5SChris Cain * 296dfbf7de5SChris Cain * @return Returns as a string, the throttle cause in Redfish terms. If 297dfbf7de5SChris Cain * translation cannot be done, returns "Unknown" throttle reason. 298dfbf7de5SChris Cain */ 299dfbf7de5SChris Cain inline processor::ThrottleCause 300dfbf7de5SChris Cain dbusToRfThrottleCause(const std::string& dbusSource) 301dfbf7de5SChris Cain { 302dfbf7de5SChris Cain if (dbusSource == 303dfbf7de5SChris Cain "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ClockLimit") 304dfbf7de5SChris Cain { 305dfbf7de5SChris Cain return processor::ThrottleCause::ClockLimit; 306dfbf7de5SChris Cain } 307dfbf7de5SChris Cain if (dbusSource == 308dfbf7de5SChris Cain "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ManagementDetectedFault") 309dfbf7de5SChris Cain { 310dfbf7de5SChris Cain return processor::ThrottleCause::ManagementDetectedFault; 311dfbf7de5SChris Cain } 312dfbf7de5SChris Cain if (dbusSource == 313dfbf7de5SChris Cain "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.PowerLimit") 314dfbf7de5SChris Cain { 315dfbf7de5SChris Cain return processor::ThrottleCause::PowerLimit; 316dfbf7de5SChris Cain } 317dfbf7de5SChris Cain if (dbusSource == 318dfbf7de5SChris Cain "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.ThermalLimit") 319dfbf7de5SChris Cain { 320dfbf7de5SChris Cain return processor::ThrottleCause::ThermalLimit; 321dfbf7de5SChris Cain } 322dfbf7de5SChris Cain if (dbusSource == 323dfbf7de5SChris Cain "xyz.openbmc_project.Control.Power.Throttle.ThrottleReasons.Unknown") 324dfbf7de5SChris Cain { 325dfbf7de5SChris Cain return processor::ThrottleCause::Unknown; 326dfbf7de5SChris Cain } 327dfbf7de5SChris Cain return processor::ThrottleCause::Invalid; 328dfbf7de5SChris Cain } 329dfbf7de5SChris Cain 330dfbf7de5SChris Cain inline void 331ac106bf6SEd Tanous readThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 332dfbf7de5SChris Cain const boost::system::error_code& ec, 333dfbf7de5SChris Cain const dbus::utility::DBusPropertiesMap& properties) 334dfbf7de5SChris Cain { 335dfbf7de5SChris Cain if (ec) 336dfbf7de5SChris Cain { 33762598e31SEd Tanous BMCWEB_LOG_ERROR("Processor Throttle getAllProperties error {}", ec); 338ac106bf6SEd Tanous messages::internalError(asyncResp->res); 339dfbf7de5SChris Cain return; 340dfbf7de5SChris Cain } 341dfbf7de5SChris Cain 342dfbf7de5SChris Cain const bool* status = nullptr; 343dfbf7de5SChris Cain const std::vector<std::string>* causes = nullptr; 344dfbf7de5SChris Cain 345dfbf7de5SChris Cain if (!sdbusplus::unpackPropertiesNoThrow(dbus_utils::UnpackErrorPrinter(), 346dfbf7de5SChris Cain properties, "Throttled", status, 347dfbf7de5SChris Cain "ThrottleCauses", causes)) 348dfbf7de5SChris Cain { 349ac106bf6SEd Tanous messages::internalError(asyncResp->res); 350dfbf7de5SChris Cain return; 351dfbf7de5SChris Cain } 352dfbf7de5SChris Cain 353ac106bf6SEd Tanous asyncResp->res.jsonValue["Throttled"] = *status; 354dfbf7de5SChris Cain nlohmann::json::array_t rCauses; 355dfbf7de5SChris Cain for (const std::string& cause : *causes) 356dfbf7de5SChris Cain { 357dfbf7de5SChris Cain processor::ThrottleCause rfCause = dbusToRfThrottleCause(cause); 358dfbf7de5SChris Cain if (rfCause == processor::ThrottleCause::Invalid) 359dfbf7de5SChris Cain { 360ac106bf6SEd Tanous messages::internalError(asyncResp->res); 361dfbf7de5SChris Cain return; 362dfbf7de5SChris Cain } 363dfbf7de5SChris Cain 364dfbf7de5SChris Cain rCauses.emplace_back(rfCause); 365dfbf7de5SChris Cain } 366ac106bf6SEd Tanous asyncResp->res.jsonValue["ThrottleCauses"] = std::move(rCauses); 367dfbf7de5SChris Cain } 368dfbf7de5SChris Cain 369dfbf7de5SChris Cain inline void 370ac106bf6SEd Tanous getThrottleProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 371dfbf7de5SChris Cain const std::string& service, 372dfbf7de5SChris Cain const std::string& objectPath) 373dfbf7de5SChris Cain { 37462598e31SEd Tanous BMCWEB_LOG_DEBUG("Get processor throttle resources"); 375dfbf7de5SChris Cain 376dfbf7de5SChris Cain sdbusplus::asio::getAllProperties( 377dfbf7de5SChris Cain *crow::connections::systemBus, service, objectPath, 378dfbf7de5SChris Cain "xyz.openbmc_project.Control.Power.Throttle", 379ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 380dfbf7de5SChris Cain const dbus::utility::DBusPropertiesMap& properties) { 381ac106bf6SEd Tanous readThrottleProperties(asyncResp, ec, properties); 382dfbf7de5SChris Cain }); 383dfbf7de5SChris Cain } 384dfbf7de5SChris Cain 385ac106bf6SEd Tanous inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 386ac6a4445SGunnar Mills const std::string& service, 387ac6a4445SGunnar Mills const std::string& objPath) 388ac6a4445SGunnar Mills { 38962598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Cpu Asset Data"); 390351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 391351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 392351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 393ac106bf6SEd Tanous [objPath, asyncResp{std::move(asyncResp)}]( 3945e7e2dc5SEd Tanous const boost::system::error_code& ec, 395351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 396ac6a4445SGunnar Mills if (ec) 397ac6a4445SGunnar Mills { 39862598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error"); 399ac106bf6SEd Tanous messages::internalError(asyncResp->res); 400ac6a4445SGunnar Mills return; 401ac6a4445SGunnar Mills } 402ac6a4445SGunnar Mills 403351053f2SKrzysztof Grobelny const std::string* serialNumber = nullptr; 404351053f2SKrzysztof Grobelny const std::string* model = nullptr; 405351053f2SKrzysztof Grobelny const std::string* manufacturer = nullptr; 406351053f2SKrzysztof Grobelny const std::string* partNumber = nullptr; 407351053f2SKrzysztof Grobelny const std::string* sparePartNumber = nullptr; 408351053f2SKrzysztof Grobelny 409351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 410351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber", 411351053f2SKrzysztof Grobelny serialNumber, "Model", model, "Manufacturer", manufacturer, 412351053f2SKrzysztof Grobelny "PartNumber", partNumber, "SparePartNumber", sparePartNumber); 413351053f2SKrzysztof Grobelny 414351053f2SKrzysztof Grobelny if (!success) 415ac6a4445SGunnar Mills { 416ac106bf6SEd Tanous messages::internalError(asyncResp->res); 417351053f2SKrzysztof Grobelny return; 418ac6a4445SGunnar Mills } 419351053f2SKrzysztof Grobelny 420351053f2SKrzysztof Grobelny if (serialNumber != nullptr && !serialNumber->empty()) 421ac6a4445SGunnar Mills { 422ac106bf6SEd Tanous asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; 423351053f2SKrzysztof Grobelny } 424351053f2SKrzysztof Grobelny 425351053f2SKrzysztof Grobelny if ((model != nullptr) && !model->empty()) 426ac6a4445SGunnar Mills { 427ac106bf6SEd Tanous asyncResp->res.jsonValue["Model"] = *model; 428ac6a4445SGunnar Mills } 429ac6a4445SGunnar Mills 430351053f2SKrzysztof Grobelny if (manufacturer != nullptr) 431ac6a4445SGunnar Mills { 432ac106bf6SEd Tanous asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; 433ac6a4445SGunnar Mills 434ac6a4445SGunnar Mills // Otherwise would be unexpected. 435351053f2SKrzysztof Grobelny if (manufacturer->find("Intel") != std::string::npos) 436ac6a4445SGunnar Mills { 437ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorArchitecture"] = "x86"; 438ac106bf6SEd Tanous asyncResp->res.jsonValue["InstructionSet"] = "x86-64"; 439ac6a4445SGunnar Mills } 440351053f2SKrzysztof Grobelny else if (manufacturer->find("IBM") != std::string::npos) 441ac6a4445SGunnar Mills { 442ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorArchitecture"] = "Power"; 443ac106bf6SEd Tanous asyncResp->res.jsonValue["InstructionSet"] = "PowerISA"; 444ac6a4445SGunnar Mills } 445ac6a4445SGunnar Mills } 446cba4f448SSunnySrivastava1984 447351053f2SKrzysztof Grobelny if (partNumber != nullptr) 448cba4f448SSunnySrivastava1984 { 449ac106bf6SEd Tanous asyncResp->res.jsonValue["PartNumber"] = *partNumber; 450cba4f448SSunnySrivastava1984 } 451cba4f448SSunnySrivastava1984 4526169de2cSBrad Bishop if (sparePartNumber != nullptr && !sparePartNumber->empty()) 453cba4f448SSunnySrivastava1984 { 454ac106bf6SEd Tanous asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; 455cba4f448SSunnySrivastava1984 } 456351053f2SKrzysztof Grobelny }); 457ac6a4445SGunnar Mills } 458ac6a4445SGunnar Mills 459ac106bf6SEd Tanous inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 460ac6a4445SGunnar Mills const std::string& service, 461ac6a4445SGunnar Mills const std::string& objPath) 462ac6a4445SGunnar Mills { 46362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Cpu Revision Data"); 464351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 465351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 466351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Revision", 467ac106bf6SEd Tanous [objPath, asyncResp{std::move(asyncResp)}]( 4685e7e2dc5SEd Tanous const boost::system::error_code& ec, 469351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 470ac6a4445SGunnar Mills if (ec) 471ac6a4445SGunnar Mills { 47262598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error"); 473ac106bf6SEd Tanous messages::internalError(asyncResp->res); 474ac6a4445SGunnar Mills return; 475ac6a4445SGunnar Mills } 476ac6a4445SGunnar Mills 477351053f2SKrzysztof Grobelny const std::string* version = nullptr; 478351053f2SKrzysztof Grobelny 479351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 480351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Version", version); 481351053f2SKrzysztof Grobelny 482351053f2SKrzysztof Grobelny if (!success) 483ac6a4445SGunnar Mills { 484ac106bf6SEd Tanous messages::internalError(asyncResp->res); 485351053f2SKrzysztof Grobelny return; 486351053f2SKrzysztof Grobelny } 487351053f2SKrzysztof Grobelny 488351053f2SKrzysztof Grobelny if (version != nullptr) 489ac6a4445SGunnar Mills { 490ac106bf6SEd Tanous asyncResp->res.jsonValue["Version"] = *version; 491ac6a4445SGunnar Mills } 492351053f2SKrzysztof Grobelny }); 493ac6a4445SGunnar Mills } 494ac6a4445SGunnar Mills 4958d1b46d7Szhanghch05 inline void getAcceleratorDataByService( 496ac106bf6SEd Tanous std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& acclrtrId, 4978d1b46d7Szhanghch05 const std::string& service, const std::string& objPath) 498ac6a4445SGunnar Mills { 49962598e31SEd Tanous BMCWEB_LOG_DEBUG("Get available system Accelerator resources by service."); 500351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 501351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, "", 502ac106bf6SEd Tanous [acclrtrId, asyncResp{std::move(asyncResp)}]( 5035e7e2dc5SEd Tanous const boost::system::error_code& ec, 504351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 505ac6a4445SGunnar Mills if (ec) 506ac6a4445SGunnar Mills { 50762598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error"); 508ac106bf6SEd Tanous messages::internalError(asyncResp->res); 509ac6a4445SGunnar Mills return; 510ac6a4445SGunnar Mills } 511ac6a4445SGunnar Mills 512351053f2SKrzysztof Grobelny const bool* functional = nullptr; 513351053f2SKrzysztof Grobelny const bool* present = nullptr; 514351053f2SKrzysztof Grobelny 515351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 516351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Functional", 517351053f2SKrzysztof Grobelny functional, "Present", present); 518351053f2SKrzysztof Grobelny 519351053f2SKrzysztof Grobelny if (!success) 520ac6a4445SGunnar Mills { 521ac106bf6SEd Tanous messages::internalError(asyncResp->res); 522351053f2SKrzysztof Grobelny return; 523ac6a4445SGunnar Mills } 524ac6a4445SGunnar Mills 525ac6a4445SGunnar Mills std::string state = "Enabled"; 526ac6a4445SGunnar Mills std::string health = "OK"; 527ac6a4445SGunnar Mills 528351053f2SKrzysztof Grobelny if (present != nullptr && !*present) 529ac6a4445SGunnar Mills { 530ac6a4445SGunnar Mills state = "Absent"; 531ac6a4445SGunnar Mills } 532ac6a4445SGunnar Mills 533351053f2SKrzysztof Grobelny if (functional != nullptr && !*functional) 534ac6a4445SGunnar Mills { 535ac6a4445SGunnar Mills if (state == "Enabled") 536ac6a4445SGunnar Mills { 537ac6a4445SGunnar Mills health = "Critical"; 538ac6a4445SGunnar Mills } 539ac6a4445SGunnar Mills } 540ac6a4445SGunnar Mills 541ac106bf6SEd Tanous asyncResp->res.jsonValue["Id"] = acclrtrId; 542ac106bf6SEd Tanous asyncResp->res.jsonValue["Name"] = "Processor"; 543ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = state; 544ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = health; 545ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorType"] = "Accelerator"; 546351053f2SKrzysztof Grobelny }); 547ac6a4445SGunnar Mills } 548ac6a4445SGunnar Mills 549dba0c291SJonathan Doman // OperatingConfig D-Bus Types 550dba0c291SJonathan Doman using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>; 551dba0c291SJonathan Doman using BaseSpeedPrioritySettingsProperty = 552dba0c291SJonathan Doman std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>; 553dba0c291SJonathan Doman // uint32_t and size_t may or may not be the same type, requiring a dedup'd 554dba0c291SJonathan Doman // variant 555dba0c291SJonathan Doman 556dba0c291SJonathan Doman /** 557dba0c291SJonathan Doman * Fill out the HighSpeedCoreIDs in a Processor resource from the given 558dba0c291SJonathan Doman * OperatingConfig D-Bus property. 559dba0c291SJonathan Doman * 560ac106bf6SEd Tanous * @param[in,out] asyncResp Async HTTP response. 561dba0c291SJonathan Doman * @param[in] baseSpeedSettings Full list of base speed priority groups, 562dba0c291SJonathan Doman * to use to determine the list of high 563dba0c291SJonathan Doman * speed cores. 564dba0c291SJonathan Doman */ 565dba0c291SJonathan Doman inline void highSpeedCoreIdsHandler( 566ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 567dba0c291SJonathan Doman const BaseSpeedPrioritySettingsProperty& baseSpeedSettings) 568dba0c291SJonathan Doman { 569dba0c291SJonathan Doman // The D-Bus property does not indicate which bucket is the "high 570dba0c291SJonathan Doman // priority" group, so let's discern that by looking for the one with 571dba0c291SJonathan Doman // highest base frequency. 572dba0c291SJonathan Doman auto highPriorityGroup = baseSpeedSettings.cend(); 573dba0c291SJonathan Doman uint32_t highestBaseSpeed = 0; 574dba0c291SJonathan Doman for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend(); 575dba0c291SJonathan Doman ++it) 576dba0c291SJonathan Doman { 577dba0c291SJonathan Doman const uint32_t baseFreq = std::get<uint32_t>(*it); 578dba0c291SJonathan Doman if (baseFreq > highestBaseSpeed) 579dba0c291SJonathan Doman { 580dba0c291SJonathan Doman highestBaseSpeed = baseFreq; 581dba0c291SJonathan Doman highPriorityGroup = it; 582dba0c291SJonathan Doman } 583dba0c291SJonathan Doman } 584dba0c291SJonathan Doman 585ac106bf6SEd Tanous nlohmann::json& jsonCoreIds = asyncResp->res.jsonValue["HighSpeedCoreIDs"]; 586dba0c291SJonathan Doman jsonCoreIds = nlohmann::json::array(); 587dba0c291SJonathan Doman 588dba0c291SJonathan Doman // There may not be any entries in the D-Bus property, so only populate 589dba0c291SJonathan Doman // if there was actually something there. 590dba0c291SJonathan Doman if (highPriorityGroup != baseSpeedSettings.cend()) 591dba0c291SJonathan Doman { 592dba0c291SJonathan Doman jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup); 593dba0c291SJonathan Doman } 594dba0c291SJonathan Doman } 595dba0c291SJonathan Doman 596dba0c291SJonathan Doman /** 597dba0c291SJonathan Doman * Fill out OperatingConfig related items in a Processor resource by requesting 598dba0c291SJonathan Doman * data from the given D-Bus object. 599dba0c291SJonathan Doman * 600ac106bf6SEd Tanous * @param[in,out] asyncResp Async HTTP response. 601dba0c291SJonathan Doman * @param[in] cpuId CPU D-Bus name. 602dba0c291SJonathan Doman * @param[in] service D-Bus service to query. 603dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 604dba0c291SJonathan Doman */ 605ac106bf6SEd Tanous inline void 606ac106bf6SEd Tanous getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 607ac106bf6SEd Tanous const std::string& cpuId, const std::string& service, 608dba0c291SJonathan Doman const std::string& objPath) 609dba0c291SJonathan Doman { 61062598e31SEd Tanous BMCWEB_LOG_INFO("Getting CPU operating configs for {}", cpuId); 611dba0c291SJonathan Doman 612dba0c291SJonathan Doman // First, GetAll CurrentOperatingConfig properties on the object 613351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 614351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 615351053f2SKrzysztof Grobelny "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 616ac106bf6SEd Tanous [asyncResp, cpuId, 6175e7e2dc5SEd Tanous service](const boost::system::error_code& ec, 618351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 619dba0c291SJonathan Doman if (ec) 620dba0c291SJonathan Doman { 62162598e31SEd Tanous BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message()); 622ac106bf6SEd Tanous messages::internalError(asyncResp->res); 623dba0c291SJonathan Doman return; 624dba0c291SJonathan Doman } 625dba0c291SJonathan Doman 626ac106bf6SEd Tanous nlohmann::json& json = asyncResp->res.jsonValue; 627dba0c291SJonathan Doman 628351053f2SKrzysztof Grobelny const sdbusplus::message::object_path* appliedConfig = nullptr; 629351053f2SKrzysztof Grobelny const bool* baseSpeedPriorityEnabled = nullptr; 630351053f2SKrzysztof Grobelny 631351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 632351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig", 633351053f2SKrzysztof Grobelny appliedConfig, "BaseSpeedPriorityEnabled", 634351053f2SKrzysztof Grobelny baseSpeedPriorityEnabled); 635351053f2SKrzysztof Grobelny 636351053f2SKrzysztof Grobelny if (!success) 637dba0c291SJonathan Doman { 638ac106bf6SEd Tanous messages::internalError(asyncResp->res); 639351053f2SKrzysztof Grobelny return; 640dba0c291SJonathan Doman } 641dba0c291SJonathan Doman 642351053f2SKrzysztof Grobelny if (appliedConfig != nullptr) 643351053f2SKrzysztof Grobelny { 644351053f2SKrzysztof Grobelny const std::string& dbusPath = appliedConfig->str; 6451476687dSEd Tanous nlohmann::json::object_t operatingConfig; 646ef4c65b7SEd Tanous operatingConfig["@odata.id"] = boost::urls::format( 647ef4c65b7SEd Tanous "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs", 648ef4c65b7SEd Tanous cpuId); 6491476687dSEd Tanous json["OperatingConfigs"] = std::move(operatingConfig); 650dba0c291SJonathan Doman 651dba0c291SJonathan Doman // Reuse the D-Bus config object name for the Redfish 652dba0c291SJonathan Doman // URI 653dba0c291SJonathan Doman size_t baseNamePos = dbusPath.rfind('/'); 654dba0c291SJonathan Doman if (baseNamePos == std::string::npos || 655dba0c291SJonathan Doman baseNamePos == (dbusPath.size() - 1)) 656dba0c291SJonathan Doman { 657dba0c291SJonathan Doman // If the AppliedConfig was somehow not a valid path, 658dba0c291SJonathan Doman // skip adding any more properties, since everything 659dba0c291SJonathan Doman // else is tied to this applied config. 660ac106bf6SEd Tanous messages::internalError(asyncResp->res); 661351053f2SKrzysztof Grobelny return; 662dba0c291SJonathan Doman } 6631476687dSEd Tanous nlohmann::json::object_t appliedOperatingConfig; 664ef4c65b7SEd Tanous appliedOperatingConfig["@odata.id"] = boost::urls::format( 665ef4c65b7SEd Tanous "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs/{}", 666ef4c65b7SEd Tanous cpuId, dbusPath.substr(baseNamePos + 1)); 667351053f2SKrzysztof Grobelny json["AppliedOperatingConfig"] = std::move(appliedOperatingConfig); 668dba0c291SJonathan Doman 669dba0c291SJonathan Doman // Once we found the current applied config, queue another 670dba0c291SJonathan Doman // request to read the base freq core ids out of that 671dba0c291SJonathan Doman // config. 672002d39b4SEd Tanous sdbusplus::asio::getProperty<BaseSpeedPrioritySettingsProperty>( 6731e1e598dSJonathan Doman *crow::connections::systemBus, service, dbusPath, 6741e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu." 6751e1e598dSJonathan Doman "OperatingConfig", 6761e1e598dSJonathan Doman "BaseSpeedPrioritySettings", 677ac106bf6SEd Tanous [asyncResp]( 6785e7e2dc5SEd Tanous const boost::system::error_code& ec2, 679351053f2SKrzysztof Grobelny const BaseSpeedPrioritySettingsProperty& baseSpeedList) { 6808a592810SEd Tanous if (ec2) 681dba0c291SJonathan Doman { 68262598e31SEd Tanous BMCWEB_LOG_WARNING("D-Bus Property Get error: {}", ec2); 683ac106bf6SEd Tanous messages::internalError(asyncResp->res); 684dba0c291SJonathan Doman return; 685dba0c291SJonathan Doman } 6861e1e598dSJonathan Doman 687ac106bf6SEd Tanous highSpeedCoreIdsHandler(asyncResp, baseSpeedList); 6881e1e598dSJonathan Doman }); 689dba0c291SJonathan Doman } 690351053f2SKrzysztof Grobelny 691351053f2SKrzysztof Grobelny if (baseSpeedPriorityEnabled != nullptr) 692dba0c291SJonathan Doman { 693dba0c291SJonathan Doman json["BaseSpeedPriorityState"] = 694351053f2SKrzysztof Grobelny *baseSpeedPriorityEnabled ? "Enabled" : "Disabled"; 695dba0c291SJonathan Doman } 696351053f2SKrzysztof Grobelny }); 697dba0c291SJonathan Doman } 698dba0c291SJonathan Doman 699cba4f448SSunnySrivastava1984 /** 700cba4f448SSunnySrivastava1984 * @brief Fill out location info of a processor by 701cba4f448SSunnySrivastava1984 * requesting data from the given D-Bus object. 702cba4f448SSunnySrivastava1984 * 703ac106bf6SEd Tanous * @param[in,out] asyncResp Async HTTP response. 704cba4f448SSunnySrivastava1984 * @param[in] service D-Bus service to query. 705cba4f448SSunnySrivastava1984 * @param[in] objPath D-Bus object to query. 706cba4f448SSunnySrivastava1984 */ 707ac106bf6SEd Tanous inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 708cba4f448SSunnySrivastava1984 const std::string& service, 709cba4f448SSunnySrivastava1984 const std::string& objPath) 710cba4f448SSunnySrivastava1984 { 71162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Cpu Location Data"); 7121e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 7131e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 7141e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 715ac106bf6SEd Tanous [objPath, asyncResp{std::move(asyncResp)}]( 716ac106bf6SEd Tanous const boost::system::error_code& ec, const std::string& property) { 717cba4f448SSunnySrivastava1984 if (ec) 718cba4f448SSunnySrivastava1984 { 71962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error"); 720ac106bf6SEd Tanous messages::internalError(asyncResp->res); 721cba4f448SSunnySrivastava1984 return; 722cba4f448SSunnySrivastava1984 } 723cba4f448SSunnySrivastava1984 724ac106bf6SEd Tanous asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 7251e1e598dSJonathan Doman property; 7261e1e598dSJonathan Doman }); 727cba4f448SSunnySrivastava1984 } 728cba4f448SSunnySrivastava1984 729c951448aSJonathan Doman /** 73049e429caSJonathan Doman * Populate the unique identifier in a Processor resource by requesting data 73149e429caSJonathan Doman * from the given D-Bus object. 73249e429caSJonathan Doman * 733ac106bf6SEd Tanous * @param[in,out] asyncResp Async HTTP response. 73449e429caSJonathan Doman * @param[in] service D-Bus service to query. 73549e429caSJonathan Doman * @param[in] objPath D-Bus object to query. 73649e429caSJonathan Doman */ 737ac106bf6SEd Tanous inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 73849e429caSJonathan Doman const std::string& service, 73949e429caSJonathan Doman const std::string& objectPath) 74049e429caSJonathan Doman { 74162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get CPU UniqueIdentifier"); 7421e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 7431e1e598dSJonathan Doman *crow::connections::systemBus, service, objectPath, 7441e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", 7451e1e598dSJonathan Doman "UniqueIdentifier", 746ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 747ac106bf6SEd Tanous const std::string& id) { 7481e1e598dSJonathan Doman if (ec) 74949e429caSJonathan Doman { 75062598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to read cpu unique id: {}", ec); 751ac106bf6SEd Tanous messages::internalError(asyncResp->res); 75249e429caSJonathan Doman return; 75349e429caSJonathan Doman } 754ac106bf6SEd Tanous asyncResp->res 755ac106bf6SEd Tanous .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id; 7561e1e598dSJonathan Doman }); 75749e429caSJonathan Doman } 75849e429caSJonathan Doman 75949e429caSJonathan Doman /** 760c951448aSJonathan Doman * Find the D-Bus object representing the requested Processor, and call the 761c951448aSJonathan Doman * handler with the results. If matching object is not found, add 404 error to 762c951448aSJonathan Doman * response and don't call the handler. 763c951448aSJonathan Doman * 764c951448aSJonathan Doman * @param[in,out] resp Async HTTP response. 765c951448aSJonathan Doman * @param[in] processorId Redfish Processor Id. 766c951448aSJonathan Doman * @param[in] handler Callback to continue processing request upon 767c951448aSJonathan Doman * successfully finding object. 768c951448aSJonathan Doman */ 769c951448aSJonathan Doman template <typename Handler> 7708d1b46d7Szhanghch05 inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp, 771c951448aSJonathan Doman const std::string& processorId, 772c951448aSJonathan Doman Handler&& handler) 773ac6a4445SGunnar Mills { 77462598e31SEd Tanous BMCWEB_LOG_DEBUG("Get available system processor resources."); 775ac6a4445SGunnar Mills 776c951448aSJonathan Doman // GetSubTree on all interfaces which provide info about a Processor 777dfbf7de5SChris Cain constexpr std::array<std::string_view, 9> interfaces = { 778e99073f5SGeorge Liu "xyz.openbmc_project.Common.UUID", 779e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Asset", 780e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Revision", 781e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Cpu", 782e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode", 783e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Accelerator", 784e99073f5SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 785dfbf7de5SChris Cain "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", 786dfbf7de5SChris Cain "xyz.openbmc_project.Control.Power.Throttle"}; 787e99073f5SGeorge Liu dbus::utility::getSubTree( 788e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 789c951448aSJonathan Doman [resp, processorId, handler = std::forward<Handler>(handler)]( 790e99073f5SGeorge Liu const boost::system::error_code& ec, 791e99073f5SGeorge Liu const dbus::utility::MapperGetSubTreeResponse& subtree) { 792ac6a4445SGunnar Mills if (ec) 793ac6a4445SGunnar Mills { 79462598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error: {}", ec); 795c951448aSJonathan Doman messages::internalError(resp->res); 796ac6a4445SGunnar Mills return; 797ac6a4445SGunnar Mills } 7982bab9831SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 799ac6a4445SGunnar Mills { 8002bab9831SJonathan Doman // Ignore any objects which don't end with our desired cpu name 80111ba3979SEd Tanous if (!objectPath.ends_with(processorId)) 802ac6a4445SGunnar Mills { 8032bab9831SJonathan Doman continue; 804ac6a4445SGunnar Mills } 8052bab9831SJonathan Doman 806c951448aSJonathan Doman bool found = false; 807c951448aSJonathan Doman // Filter out objects that don't have the CPU-specific 808c951448aSJonathan Doman // interfaces to make sure we can return 404 on non-CPUs 809c951448aSJonathan Doman // (e.g. /redfish/../Processors/dimm0) 8102bab9831SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 811ac6a4445SGunnar Mills { 8123544d2a7SEd Tanous if (std::ranges::find_first_of(interfaceList, 8133544d2a7SEd Tanous processorInterfaces) != 8143544d2a7SEd Tanous std::end(interfaceList)) 8152bab9831SJonathan Doman { 816c951448aSJonathan Doman found = true; 817c951448aSJonathan Doman break; 818c951448aSJonathan Doman } 819c951448aSJonathan Doman } 820c951448aSJonathan Doman 821c951448aSJonathan Doman if (!found) 8222bab9831SJonathan Doman { 823c951448aSJonathan Doman continue; 824ac6a4445SGunnar Mills } 825c951448aSJonathan Doman 826c951448aSJonathan Doman // Process the first object which does match our cpu name and 827c951448aSJonathan Doman // required interfaces, and potentially ignore any other 828c951448aSJonathan Doman // matching objects. Assume all interfaces we want to process 829c951448aSJonathan Doman // must be on the same object path. 830c951448aSJonathan Doman 8318a592810SEd Tanous handler(objectPath, serviceMap); 832ac6a4445SGunnar Mills return; 833ac6a4445SGunnar Mills } 834c951448aSJonathan Doman messages::resourceNotFound(resp->res, "Processor", processorId); 835e99073f5SGeorge Liu }); 836ac6a4445SGunnar Mills } 837ac6a4445SGunnar Mills 838ac106bf6SEd Tanous inline void 839ac106bf6SEd Tanous getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 840c951448aSJonathan Doman const std::string& processorId, 841c951448aSJonathan Doman const std::string& objectPath, 8425df6eda2SShantappa Teekappanavar const dbus::utility::MapperServiceMap& serviceMap) 843c951448aSJonathan Doman { 844c951448aSJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 845c951448aSJonathan Doman { 846c951448aSJonathan Doman for (const auto& interface : interfaceList) 847c951448aSJonathan Doman { 848c951448aSJonathan Doman if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") 849c951448aSJonathan Doman { 850ac106bf6SEd Tanous getCpuAssetData(asyncResp, serviceName, objectPath); 851c951448aSJonathan Doman } 8520fda0f12SGeorge Liu else if (interface == 8530fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Revision") 854c951448aSJonathan Doman { 855ac106bf6SEd Tanous getCpuRevisionData(asyncResp, serviceName, objectPath); 856c951448aSJonathan Doman } 857c951448aSJonathan Doman else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu") 858c951448aSJonathan Doman { 859ac106bf6SEd Tanous getCpuDataByService(asyncResp, processorId, serviceName, 860c951448aSJonathan Doman objectPath); 861c951448aSJonathan Doman } 8620fda0f12SGeorge Liu else if (interface == 8630fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Accelerator") 864c951448aSJonathan Doman { 865ac106bf6SEd Tanous getAcceleratorDataByService(asyncResp, processorId, serviceName, 866c951448aSJonathan Doman objectPath); 867c951448aSJonathan Doman } 8680fda0f12SGeorge Liu else if ( 8690fda0f12SGeorge Liu interface == 8700fda0f12SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig") 871c951448aSJonathan Doman { 872ac106bf6SEd Tanous getCpuConfigData(asyncResp, processorId, serviceName, 873ac106bf6SEd Tanous objectPath); 874c951448aSJonathan Doman } 8750fda0f12SGeorge Liu else if (interface == 8760fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 877c951448aSJonathan Doman { 878ac106bf6SEd Tanous getCpuLocationCode(asyncResp, serviceName, objectPath); 879c951448aSJonathan Doman } 88071b82f26SSharad Yadav else if (interface == "xyz.openbmc_project.Common.UUID") 88171b82f26SSharad Yadav { 882ac106bf6SEd Tanous getProcessorUUID(asyncResp, serviceName, objectPath); 88371b82f26SSharad Yadav } 8840fda0f12SGeorge Liu else if (interface == 8850fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier") 88649e429caSJonathan Doman { 887ac106bf6SEd Tanous getCpuUniqueId(asyncResp, serviceName, objectPath); 88849e429caSJonathan Doman } 889dfbf7de5SChris Cain else if (interface == "xyz.openbmc_project.Control.Power.Throttle") 890dfbf7de5SChris Cain { 891ac106bf6SEd Tanous getThrottleProperties(asyncResp, serviceName, objectPath); 892dfbf7de5SChris Cain } 893c951448aSJonathan Doman } 894c951448aSJonathan Doman } 895c951448aSJonathan Doman } 896c951448aSJonathan Doman 897dba0c291SJonathan Doman /** 898dba0c291SJonathan Doman * Request all the properties for the given D-Bus object and fill out the 899dba0c291SJonathan Doman * related entries in the Redfish OperatingConfig response. 900dba0c291SJonathan Doman * 901ac106bf6SEd Tanous * @param[in,out] asyncResp Async HTTP response. 902dba0c291SJonathan Doman * @param[in] service D-Bus service name to query. 903dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 904dba0c291SJonathan Doman */ 9058d1b46d7Szhanghch05 inline void 906ac106bf6SEd Tanous getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 907dba0c291SJonathan Doman const std::string& service, 908dba0c291SJonathan Doman const std::string& objPath) 909dba0c291SJonathan Doman { 910351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 911351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 912351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig", 913ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 914351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 915dba0c291SJonathan Doman if (ec) 916dba0c291SJonathan Doman { 91762598e31SEd Tanous BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message()); 918ac106bf6SEd Tanous messages::internalError(asyncResp->res); 919dba0c291SJonathan Doman return; 920dba0c291SJonathan Doman } 921dba0c291SJonathan Doman 922351053f2SKrzysztof Grobelny const size_t* availableCoreCount = nullptr; 923351053f2SKrzysztof Grobelny const uint32_t* baseSpeed = nullptr; 924351053f2SKrzysztof Grobelny const uint32_t* maxJunctionTemperature = nullptr; 925351053f2SKrzysztof Grobelny const uint32_t* maxSpeed = nullptr; 926351053f2SKrzysztof Grobelny const uint32_t* powerLimit = nullptr; 927351053f2SKrzysztof Grobelny const TurboProfileProperty* turboProfile = nullptr; 928351053f2SKrzysztof Grobelny const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings = 929351053f2SKrzysztof Grobelny nullptr; 930351053f2SKrzysztof Grobelny 931351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 932351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount", 933351053f2SKrzysztof Grobelny availableCoreCount, "BaseSpeed", baseSpeed, 934351053f2SKrzysztof Grobelny "MaxJunctionTemperature", maxJunctionTemperature, "MaxSpeed", 935351053f2SKrzysztof Grobelny maxSpeed, "PowerLimit", powerLimit, "TurboProfile", turboProfile, 936351053f2SKrzysztof Grobelny "BaseSpeedPrioritySettings", baseSpeedPrioritySettings); 937351053f2SKrzysztof Grobelny 938351053f2SKrzysztof Grobelny if (!success) 939dba0c291SJonathan Doman { 940ac106bf6SEd Tanous messages::internalError(asyncResp->res); 941351053f2SKrzysztof Grobelny return; 942dba0c291SJonathan Doman } 943dba0c291SJonathan Doman 944ac106bf6SEd Tanous nlohmann::json& json = asyncResp->res.jsonValue; 945351053f2SKrzysztof Grobelny 946351053f2SKrzysztof Grobelny if (availableCoreCount != nullptr) 947351053f2SKrzysztof Grobelny { 948351053f2SKrzysztof Grobelny json["TotalAvailableCoreCount"] = *availableCoreCount; 949351053f2SKrzysztof Grobelny } 950351053f2SKrzysztof Grobelny 951351053f2SKrzysztof Grobelny if (baseSpeed != nullptr) 952351053f2SKrzysztof Grobelny { 953351053f2SKrzysztof Grobelny json["BaseSpeedMHz"] = *baseSpeed; 954351053f2SKrzysztof Grobelny } 955351053f2SKrzysztof Grobelny 956351053f2SKrzysztof Grobelny if (maxJunctionTemperature != nullptr) 957351053f2SKrzysztof Grobelny { 958351053f2SKrzysztof Grobelny json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature; 959351053f2SKrzysztof Grobelny } 960351053f2SKrzysztof Grobelny 961351053f2SKrzysztof Grobelny if (maxSpeed != nullptr) 962351053f2SKrzysztof Grobelny { 963351053f2SKrzysztof Grobelny json["MaxSpeedMHz"] = *maxSpeed; 964351053f2SKrzysztof Grobelny } 965351053f2SKrzysztof Grobelny 966351053f2SKrzysztof Grobelny if (powerLimit != nullptr) 967351053f2SKrzysztof Grobelny { 968351053f2SKrzysztof Grobelny json["TDPWatts"] = *powerLimit; 969351053f2SKrzysztof Grobelny } 970351053f2SKrzysztof Grobelny 971351053f2SKrzysztof Grobelny if (turboProfile != nullptr) 972351053f2SKrzysztof Grobelny { 973dba0c291SJonathan Doman nlohmann::json& turboArray = json["TurboProfile"]; 974dba0c291SJonathan Doman turboArray = nlohmann::json::array(); 975351053f2SKrzysztof Grobelny for (const auto& [turboSpeed, coreCount] : *turboProfile) 976dba0c291SJonathan Doman { 9771476687dSEd Tanous nlohmann::json::object_t turbo; 9781476687dSEd Tanous turbo["ActiveCoreCount"] = coreCount; 9791476687dSEd Tanous turbo["MaxSpeedMHz"] = turboSpeed; 980b2ba3072SPatrick Williams turboArray.emplace_back(std::move(turbo)); 981dba0c291SJonathan Doman } 982dba0c291SJonathan Doman } 983dba0c291SJonathan Doman 984351053f2SKrzysztof Grobelny if (baseSpeedPrioritySettings != nullptr) 985351053f2SKrzysztof Grobelny { 986351053f2SKrzysztof Grobelny nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"]; 987dba0c291SJonathan Doman baseSpeedArray = nlohmann::json::array(); 988351053f2SKrzysztof Grobelny for (const auto& [baseSpeedMhz, coreList] : 989351053f2SKrzysztof Grobelny *baseSpeedPrioritySettings) 990dba0c291SJonathan Doman { 9911476687dSEd Tanous nlohmann::json::object_t speed; 9921476687dSEd Tanous speed["CoreCount"] = coreList.size(); 9931476687dSEd Tanous speed["CoreIDs"] = coreList; 994351053f2SKrzysztof Grobelny speed["BaseSpeedMHz"] = baseSpeedMhz; 995b2ba3072SPatrick Williams baseSpeedArray.emplace_back(std::move(speed)); 996dba0c291SJonathan Doman } 997dba0c291SJonathan Doman } 998351053f2SKrzysztof Grobelny }); 999dba0c291SJonathan Doman } 1000dba0c291SJonathan Doman 10013cde86f1SJonathan Doman /** 10023cde86f1SJonathan Doman * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic 10033cde86f1SJonathan Doman * validation of the input data, and then set the D-Bus property. 10043cde86f1SJonathan Doman * 10053cde86f1SJonathan Doman * @param[in,out] resp Async HTTP response. 10063cde86f1SJonathan Doman * @param[in] processorId Processor's Id. 10073cde86f1SJonathan Doman * @param[in] appliedConfigUri New property value to apply. 10083cde86f1SJonathan Doman * @param[in] cpuObjectPath Path of CPU object to modify. 10093cde86f1SJonathan Doman * @param[in] serviceMap Service map for CPU object. 10103cde86f1SJonathan Doman */ 10113cde86f1SJonathan Doman inline void patchAppliedOperatingConfig( 10123cde86f1SJonathan Doman const std::shared_ptr<bmcweb::AsyncResp>& resp, 10133cde86f1SJonathan Doman const std::string& processorId, const std::string& appliedConfigUri, 10145df6eda2SShantappa Teekappanavar const std::string& cpuObjectPath, 10155df6eda2SShantappa Teekappanavar const dbus::utility::MapperServiceMap& serviceMap) 10163cde86f1SJonathan Doman { 10173cde86f1SJonathan Doman // Check that the property even exists by checking for the interface 10183cde86f1SJonathan Doman const std::string* controlService = nullptr; 10193cde86f1SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 10203cde86f1SJonathan Doman { 10213544d2a7SEd Tanous if (std::ranges::find(interfaceList, 10223cde86f1SJonathan Doman "xyz.openbmc_project.Control.Processor." 10233cde86f1SJonathan Doman "CurrentOperatingConfig") != interfaceList.end()) 10243cde86f1SJonathan Doman { 10253cde86f1SJonathan Doman controlService = &serviceName; 10263cde86f1SJonathan Doman break; 10273cde86f1SJonathan Doman } 10283cde86f1SJonathan Doman } 10293cde86f1SJonathan Doman 10303cde86f1SJonathan Doman if (controlService == nullptr) 10313cde86f1SJonathan Doman { 10323cde86f1SJonathan Doman messages::internalError(resp->res); 10333cde86f1SJonathan Doman return; 10343cde86f1SJonathan Doman } 10353cde86f1SJonathan Doman 10363cde86f1SJonathan Doman // Check that the config URI is a child of the cpu URI being patched. 10373cde86f1SJonathan Doman std::string expectedPrefix("/redfish/v1/Systems/system/Processors/"); 10383cde86f1SJonathan Doman expectedPrefix += processorId; 10393cde86f1SJonathan Doman expectedPrefix += "/OperatingConfigs/"; 104011ba3979SEd Tanous if (!appliedConfigUri.starts_with(expectedPrefix) || 10413cde86f1SJonathan Doman expectedPrefix.size() == appliedConfigUri.size()) 10423cde86f1SJonathan Doman { 1043*87c44966SAsmitha Karunanithi messages::propertyValueIncorrect(resp->res, "AppliedOperatingConfig", 1044*87c44966SAsmitha Karunanithi appliedConfigUri); 10453cde86f1SJonathan Doman return; 10463cde86f1SJonathan Doman } 10473cde86f1SJonathan Doman 10483cde86f1SJonathan Doman // Generate the D-Bus path of the OperatingConfig object, by assuming it's a 10493cde86f1SJonathan Doman // direct child of the CPU object. 10503cde86f1SJonathan Doman // Strip the expectedPrefix from the config URI to get the "filename", and 10513cde86f1SJonathan Doman // append to the CPU's path. 10523cde86f1SJonathan Doman std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size()); 10533cde86f1SJonathan Doman sdbusplus::message::object_path configPath(cpuObjectPath); 10543cde86f1SJonathan Doman configPath /= configBaseName; 10553cde86f1SJonathan Doman 105662598e31SEd Tanous BMCWEB_LOG_INFO("Setting config to {}", configPath.str); 10573cde86f1SJonathan Doman 10583cde86f1SJonathan Doman // Set the property, with handler to check error responses 1059*87c44966SAsmitha Karunanithi setDbusProperty( 1060*87c44966SAsmitha Karunanithi resp, *controlService, cpuObjectPath, 10619ae226faSGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 1062*87c44966SAsmitha Karunanithi "AppliedConfig", "AppliedOperatingConfig", configPath); 10633cde86f1SJonathan Doman } 10643cde86f1SJonathan Doman 1065ac106bf6SEd Tanous inline void 1066ac106bf6SEd Tanous handleProcessorHead(crow::App& app, const crow::Request& req, 1067ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 106871a24ca4SNikhil Namjoshi const std::string& /* systemName */, 106971a24ca4SNikhil Namjoshi const std::string& /* processorId */) 107071a24ca4SNikhil Namjoshi { 1071ac106bf6SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 107271a24ca4SNikhil Namjoshi { 107371a24ca4SNikhil Namjoshi return; 107471a24ca4SNikhil Namjoshi } 1075ac106bf6SEd Tanous asyncResp->res.addHeader( 107671a24ca4SNikhil Namjoshi boost::beast::http::field::link, 107771a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); 107871a24ca4SNikhil Namjoshi } 107971a24ca4SNikhil Namjoshi 108071a24ca4SNikhil Namjoshi inline void handleProcessorCollectionHead( 108171a24ca4SNikhil Namjoshi crow::App& app, const crow::Request& req, 1082ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 108371a24ca4SNikhil Namjoshi const std::string& /* systemName */) 108471a24ca4SNikhil Namjoshi { 1085ac106bf6SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 108671a24ca4SNikhil Namjoshi { 108771a24ca4SNikhil Namjoshi return; 108871a24ca4SNikhil Namjoshi } 1089ac106bf6SEd Tanous asyncResp->res.addHeader( 109071a24ca4SNikhil Namjoshi boost::beast::http::field::link, 109171a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); 109271a24ca4SNikhil Namjoshi } 109371a24ca4SNikhil Namjoshi 10947e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfigCollection(App& app) 1095dba0c291SJonathan Doman { 10967f3e84a1SEd Tanous BMCWEB_ROUTE(app, 10977f3e84a1SEd Tanous "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/") 1098ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfigCollection) 1099002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1100002d39b4SEd Tanous [&app](const crow::Request& req, 110145ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 11027f3e84a1SEd Tanous const std::string& systemName, const std::string& cpuName) { 11033ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 110445ca1b86SEd Tanous { 110545ca1b86SEd Tanous return; 110645ca1b86SEd Tanous } 11077f3e84a1SEd Tanous 11087f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 11097f3e84a1SEd Tanous { 11107f3e84a1SEd Tanous // Option currently returns no systems. TBD 11117f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 11127f3e84a1SEd Tanous systemName); 11137f3e84a1SEd Tanous return; 11147f3e84a1SEd Tanous } 11157f3e84a1SEd Tanous 11167f3e84a1SEd Tanous if (systemName != "system") 11177f3e84a1SEd Tanous { 11187f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 11197f3e84a1SEd Tanous systemName); 11207f3e84a1SEd Tanous return; 11217f3e84a1SEd Tanous } 11228d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1123dba0c291SJonathan Doman "#OperatingConfigCollection.OperatingConfigCollection"; 1124ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 1125ef4c65b7SEd Tanous "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs", 1126ef4c65b7SEd Tanous cpuName); 11270fda0f12SGeorge Liu asyncResp->res.jsonValue["Name"] = "Operating Config Collection"; 1128dba0c291SJonathan Doman 11297e860f15SJohn Edward Broadbent // First find the matching CPU object so we know how to 11307e860f15SJohn Edward Broadbent // constrain our search for related Config objects. 11317a1dbc48SGeorge Liu const std::array<std::string_view, 1> interfaces = { 11327a1dbc48SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"}; 11337a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 11347a1dbc48SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 1135002d39b4SEd Tanous [asyncResp, cpuName]( 11367a1dbc48SGeorge Liu const boost::system::error_code& ec, 1137002d39b4SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& objects) { 1138dba0c291SJonathan Doman if (ec) 1139dba0c291SJonathan Doman { 114062598e31SEd Tanous BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message()); 1141dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1142dba0c291SJonathan Doman return; 1143dba0c291SJonathan Doman } 1144dba0c291SJonathan Doman 1145dba0c291SJonathan Doman for (const std::string& object : objects) 1146dba0c291SJonathan Doman { 114711ba3979SEd Tanous if (!object.ends_with(cpuName)) 1148dba0c291SJonathan Doman { 1149dba0c291SJonathan Doman continue; 1150dba0c291SJonathan Doman } 1151dba0c291SJonathan Doman 11527e860f15SJohn Edward Broadbent // Not expected that there will be multiple matching 11537e860f15SJohn Edward Broadbent // CPU objects, but if there are just use the first 11547e860f15SJohn Edward Broadbent // one. 1155dba0c291SJonathan Doman 11567e860f15SJohn Edward Broadbent // Use the common search routine to construct the 11577e860f15SJohn Edward Broadbent // Collection of all Config objects under this CPU. 11587a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interface{ 11595a39f77aSPatrick Williams "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}; 1160dba0c291SJonathan Doman collection_util::getCollectionMembers( 1161dba0c291SJonathan Doman asyncResp, 1162ef4c65b7SEd Tanous boost::urls::format( 1163ef4c65b7SEd Tanous "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs", 1164ef4c65b7SEd Tanous cpuName), 116536b5f1edSLakshmi Yadlapati interface, object); 1166dba0c291SJonathan Doman return; 1167dba0c291SJonathan Doman } 11687a1dbc48SGeorge Liu }); 11697e860f15SJohn Edward Broadbent }); 1170dba0c291SJonathan Doman } 1171dba0c291SJonathan Doman 11727e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfig(App& app) 1173dba0c291SJonathan Doman { 11747e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 11757e860f15SJohn Edward Broadbent app, 11767f3e84a1SEd Tanous "/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/") 1177ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfig) 1178002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1179002d39b4SEd Tanous [&app](const crow::Request& req, 118045ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 11817f3e84a1SEd Tanous const std::string& systemName, const std::string& cpuName, 11827f3e84a1SEd Tanous const std::string& configName) { 11833ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 118445ca1b86SEd Tanous { 118545ca1b86SEd Tanous return; 118645ca1b86SEd Tanous } 11877f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 11887f3e84a1SEd Tanous { 11897f3e84a1SEd Tanous // Option currently returns no systems. TBD 11907f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 11917f3e84a1SEd Tanous systemName); 11927f3e84a1SEd Tanous return; 11937f3e84a1SEd Tanous } 11947f3e84a1SEd Tanous 11957f3e84a1SEd Tanous if (systemName != "system") 11967f3e84a1SEd Tanous { 11977f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 11987f3e84a1SEd Tanous systemName); 11997f3e84a1SEd Tanous return; 12007f3e84a1SEd Tanous } 12017e860f15SJohn Edward Broadbent // Ask for all objects implementing OperatingConfig so we can search 12027e860f15SJohn Edward Broadbent // for one with a matching name 1203e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1204e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}; 1205e99073f5SGeorge Liu dbus::utility::getSubTree( 1206e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 120739662a3bSEd Tanous [asyncResp, cpuName, configName]( 1208e99073f5SGeorge Liu const boost::system::error_code& ec, 12095df6eda2SShantappa Teekappanavar const dbus::utility::MapperGetSubTreeResponse& subtree) { 1210dba0c291SJonathan Doman if (ec) 1211dba0c291SJonathan Doman { 121262598e31SEd Tanous BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message()); 1213dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1214dba0c291SJonathan Doman return; 1215dba0c291SJonathan Doman } 1216002d39b4SEd Tanous const std::string expectedEnding = cpuName + '/' + configName; 1217dba0c291SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 1218dba0c291SJonathan Doman { 1219dba0c291SJonathan Doman // Ignore any configs without matching cpuX/configY 122011ba3979SEd Tanous if (!objectPath.ends_with(expectedEnding) || serviceMap.empty()) 1221dba0c291SJonathan Doman { 1222dba0c291SJonathan Doman continue; 1223dba0c291SJonathan Doman } 1224dba0c291SJonathan Doman 1225dba0c291SJonathan Doman nlohmann::json& json = asyncResp->res.jsonValue; 1226002d39b4SEd Tanous json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig"; 1227ef4c65b7SEd Tanous json["@odata.id"] = boost::urls::format( 1228ef4c65b7SEd Tanous "/redfish/v1/Systems/system/Processors/{}/OperatingConfigs/{}", 1229ef4c65b7SEd Tanous cpuName, configName); 1230dba0c291SJonathan Doman json["Name"] = "Processor Profile"; 1231dba0c291SJonathan Doman json["Id"] = configName; 1232dba0c291SJonathan Doman 1233dba0c291SJonathan Doman // Just use the first implementation of the object - not 12347e860f15SJohn Edward Broadbent // expected that there would be multiple matching 12357e860f15SJohn Edward Broadbent // services 1236002d39b4SEd Tanous getOperatingConfigData(asyncResp, serviceMap.begin()->first, 1237002d39b4SEd Tanous objectPath); 1238dba0c291SJonathan Doman return; 1239dba0c291SJonathan Doman } 1240002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "OperatingConfig", 1241002d39b4SEd Tanous configName); 1242e99073f5SGeorge Liu }); 12437e860f15SJohn Edward Broadbent }); 1244ac6a4445SGunnar Mills } 1245ac6a4445SGunnar Mills 12467e860f15SJohn Edward Broadbent inline void requestRoutesProcessorCollection(App& app) 12477e860f15SJohn Edward Broadbent { 1248ac6a4445SGunnar Mills /** 1249ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1250ac6a4445SGunnar Mills */ 125122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") 125271a24ca4SNikhil Namjoshi .privileges(redfish::privileges::headProcessorCollection) 125371a24ca4SNikhil Namjoshi .methods(boost::beast::http::verb::head)( 125471a24ca4SNikhil Namjoshi std::bind_front(handleProcessorCollectionHead, std::ref(app))); 125571a24ca4SNikhil Namjoshi 125671a24ca4SNikhil Namjoshi BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") 1257ed398213SEd Tanous .privileges(redfish::privileges::getProcessorCollection) 12587e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 125945ca1b86SEd Tanous [&app](const crow::Request& req, 126022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 126122d268cbSEd Tanous const std::string& systemName) { 12623ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 126345ca1b86SEd Tanous { 126445ca1b86SEd Tanous return; 126545ca1b86SEd Tanous } 12667f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 12677f3e84a1SEd Tanous { 12687f3e84a1SEd Tanous // Option currently returns no systems. TBD 12697f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 12707f3e84a1SEd Tanous systemName); 12717f3e84a1SEd Tanous return; 12727f3e84a1SEd Tanous } 12737f3e84a1SEd Tanous 127422d268cbSEd Tanous if (systemName != "system") 127522d268cbSEd Tanous { 127622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 127722d268cbSEd Tanous systemName); 127822d268cbSEd Tanous return; 127922d268cbSEd Tanous } 128022d268cbSEd Tanous 128171a24ca4SNikhil Namjoshi asyncResp->res.addHeader( 128271a24ca4SNikhil Namjoshi boost::beast::http::field::link, 128371a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); 128471a24ca4SNikhil Namjoshi 12858d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1286ac6a4445SGunnar Mills "#ProcessorCollection.ProcessorCollection"; 12878d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Processor Collection"; 1288ac6a4445SGunnar Mills 12898d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = 12908d1b46d7Szhanghch05 "/redfish/v1/Systems/system/Processors"; 1291ac6a4445SGunnar Mills 129205030b8eSGunnar Mills collection_util::getCollectionMembers( 1293ae9031f0SWilly Tu asyncResp, 1294ae9031f0SWilly Tu boost::urls::url("/redfish/v1/Systems/system/Processors"), 129536b5f1edSLakshmi Yadlapati processorInterfaces, "/xyz/openbmc_project/inventory"); 12967e860f15SJohn Edward Broadbent }); 1297ac6a4445SGunnar Mills } 1298ac6a4445SGunnar Mills 12997e860f15SJohn Edward Broadbent inline void requestRoutesProcessor(App& app) 13007e860f15SJohn Edward Broadbent { 1301ac6a4445SGunnar Mills /** 1302ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1303ac6a4445SGunnar Mills */ 13047e860f15SJohn Edward Broadbent 130522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 130671a24ca4SNikhil Namjoshi .privileges(redfish::privileges::headProcessor) 130771a24ca4SNikhil Namjoshi .methods(boost::beast::http::verb::head)( 130871a24ca4SNikhil Namjoshi std::bind_front(handleProcessorHead, std::ref(app))); 130971a24ca4SNikhil Namjoshi 131071a24ca4SNikhil Namjoshi BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 1311ed398213SEd Tanous .privileges(redfish::privileges::getProcessor) 13127e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 131345ca1b86SEd Tanous [&app](const crow::Request& req, 13147e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 131522d268cbSEd Tanous const std::string& systemName, 13167e860f15SJohn Edward Broadbent const std::string& processorId) { 13173ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 131845ca1b86SEd Tanous { 131945ca1b86SEd Tanous return; 132045ca1b86SEd Tanous } 13217f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 13227f3e84a1SEd Tanous { 13237f3e84a1SEd Tanous // Option currently returns no systems. TBD 13247f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 13257f3e84a1SEd Tanous systemName); 13267f3e84a1SEd Tanous return; 13277f3e84a1SEd Tanous } 132822d268cbSEd Tanous if (systemName != "system") 132922d268cbSEd Tanous { 133022d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 133122d268cbSEd Tanous systemName); 133222d268cbSEd Tanous return; 133322d268cbSEd Tanous } 133422d268cbSEd Tanous 133571a24ca4SNikhil Namjoshi asyncResp->res.addHeader( 133671a24ca4SNikhil Namjoshi boost::beast::http::field::link, 133771a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); 13388d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1339dfbf7de5SChris Cain "#Processor.v1_18_0.Processor"; 1340ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 1341ef4c65b7SEd Tanous "/redfish/v1/Systems/system/Processors/{}", processorId); 1342ac6a4445SGunnar Mills 13438a592810SEd Tanous getProcessorObject( 13448a592810SEd Tanous asyncResp, processorId, 13458a592810SEd Tanous std::bind_front(getProcessorData, asyncResp, processorId)); 13467e860f15SJohn Edward Broadbent }); 13473cde86f1SJonathan Doman 134822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 1349ed398213SEd Tanous .privileges(redfish::privileges::patchProcessor) 13507e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 135145ca1b86SEd Tanous [&app](const crow::Request& req, 13527e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 135322d268cbSEd Tanous const std::string& systemName, 13547e860f15SJohn Edward Broadbent const std::string& processorId) { 13553ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 135645ca1b86SEd Tanous { 135745ca1b86SEd Tanous return; 135845ca1b86SEd Tanous } 13597f3e84a1SEd Tanous if constexpr (bmcwebEnableMultiHost) 13607f3e84a1SEd Tanous { 13617f3e84a1SEd Tanous // Option currently returns no systems. TBD 13627f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 13637f3e84a1SEd Tanous systemName); 13647f3e84a1SEd Tanous return; 13657f3e84a1SEd Tanous } 136622d268cbSEd Tanous if (systemName != "system") 136722d268cbSEd Tanous { 136822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 136922d268cbSEd Tanous systemName); 137022d268cbSEd Tanous return; 137122d268cbSEd Tanous } 137222d268cbSEd Tanous 13733c569218SEd Tanous std::optional<std::string> appliedConfigUri; 137415ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, 13753c569218SEd Tanous "AppliedOperatingConfig/@odata.id", 13763c569218SEd Tanous appliedConfigUri)) 13773cde86f1SJonathan Doman { 13783cde86f1SJonathan Doman return; 13793cde86f1SJonathan Doman } 13803cde86f1SJonathan Doman 13813c569218SEd Tanous if (appliedConfigUri) 13823cde86f1SJonathan Doman { 13837e860f15SJohn Edward Broadbent // Check for 404 and find matching D-Bus object, then run 13847e860f15SJohn Edward Broadbent // property patch handlers if that all succeeds. 13858a592810SEd Tanous getProcessorObject(asyncResp, processorId, 13868a592810SEd Tanous std::bind_front(patchAppliedOperatingConfig, 13877e860f15SJohn Edward Broadbent asyncResp, processorId, 13883c569218SEd Tanous *appliedConfigUri)); 13893cde86f1SJonathan Doman } 13907e860f15SJohn Edward Broadbent }); 13913cde86f1SJonathan Doman } 1392ac6a4445SGunnar Mills 1393ac6a4445SGunnar Mills } // namespace redfish 1394