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" 22ac6a4445SGunnar Mills #include "health.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> 311e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 32dba0c291SJonathan Doman #include <sdbusplus/message/native_types.hpp> 33351053f2SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 34dba0c291SJonathan Doman #include <sdbusplus/utility/dedup_variant.hpp> 35ac6a4445SGunnar Mills 367a1dbc48SGeorge Liu #include <array> 37b9d679d1SMichael Shen #include <limits> 387a1dbc48SGeorge Liu #include <string_view> 397a1dbc48SGeorge Liu 40ac6a4445SGunnar Mills namespace redfish 41ac6a4445SGunnar Mills { 42ac6a4445SGunnar Mills 43c951448aSJonathan Doman // Interfaces which imply a D-Bus object represents a Processor 447a1dbc48SGeorge Liu constexpr std::array<std::string_view, 2> processorInterfaces = { 45c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu", 46c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Accelerator"}; 472bab9831SJonathan Doman 4871b82f26SSharad Yadav /** 4971b82f26SSharad Yadav * @brief Fill out uuid info of a processor by 5071b82f26SSharad Yadav * requesting data from the given D-Bus object. 5171b82f26SSharad Yadav * 5271b82f26SSharad Yadav * @param[in,out] aResp Async HTTP response. 5371b82f26SSharad Yadav * @param[in] service D-Bus service to query. 5471b82f26SSharad Yadav * @param[in] objPath D-Bus object to query. 5571b82f26SSharad Yadav */ 5671b82f26SSharad Yadav inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp, 5771b82f26SSharad Yadav const std::string& service, 5871b82f26SSharad Yadav const std::string& objPath) 5971b82f26SSharad Yadav { 6071b82f26SSharad Yadav BMCWEB_LOG_DEBUG << "Get Processor UUID"; 611e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 621e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 631e1e598dSJonathan Doman "xyz.openbmc_project.Common.UUID", "UUID", 645e7e2dc5SEd Tanous [objPath, aResp{std::move(aResp)}](const boost::system::error_code& ec, 651e1e598dSJonathan Doman const std::string& property) { 6671b82f26SSharad Yadav if (ec) 6771b82f26SSharad Yadav { 6871b82f26SSharad Yadav BMCWEB_LOG_DEBUG << "DBUS response error"; 6971b82f26SSharad Yadav messages::internalError(aResp->res); 7071b82f26SSharad Yadav return; 7171b82f26SSharad Yadav } 721e1e598dSJonathan Doman aResp->res.jsonValue["UUID"] = property; 731e1e598dSJonathan Doman }); 7471b82f26SSharad Yadav } 7571b82f26SSharad Yadav 76711ac7a9SEd Tanous inline void getCpuDataByInterface( 77711ac7a9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aResp, 78711ac7a9SEd Tanous const dbus::utility::DBusInteracesMap& cpuInterfacesProperties) 79ac6a4445SGunnar Mills { 80ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; 81ac6a4445SGunnar Mills 82a1649ec6SChicago Duan // Set the default value of state 83a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["State"] = "Enabled"; 84a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["Health"] = "OK"; 85ac6a4445SGunnar Mills 86ac6a4445SGunnar Mills for (const auto& interface : cpuInterfacesProperties) 87ac6a4445SGunnar Mills { 88ac6a4445SGunnar Mills for (const auto& property : interface.second) 89ac6a4445SGunnar Mills { 90a1649ec6SChicago Duan if (property.first == "Present") 91ac6a4445SGunnar Mills { 92a1649ec6SChicago Duan const bool* cpuPresent = std::get_if<bool>(&property.second); 93a1649ec6SChicago Duan if (cpuPresent == nullptr) 94ac6a4445SGunnar Mills { 95ac6a4445SGunnar Mills // Important property not in desired type 96ac6a4445SGunnar Mills messages::internalError(aResp->res); 97ac6a4445SGunnar Mills return; 98ac6a4445SGunnar Mills } 99e05aec50SEd Tanous if (!*cpuPresent) 100ac6a4445SGunnar Mills { 101a1649ec6SChicago Duan // Slot is not populated 102ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Absent"; 103a1649ec6SChicago Duan } 104a1649ec6SChicago Duan } 105a1649ec6SChicago Duan else if (property.first == "Functional") 106a1649ec6SChicago Duan { 107a1649ec6SChicago Duan const bool* cpuFunctional = std::get_if<bool>(&property.second); 108a1649ec6SChicago Duan if (cpuFunctional == nullptr) 109a1649ec6SChicago Duan { 110a1649ec6SChicago Duan messages::internalError(aResp->res); 111ac6a4445SGunnar Mills return; 112ac6a4445SGunnar Mills } 113e05aec50SEd Tanous if (!*cpuFunctional) 114a1649ec6SChicago Duan { 115a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["Health"] = "Critical"; 116a1649ec6SChicago Duan } 117a1649ec6SChicago Duan } 118a1649ec6SChicago Duan else if (property.first == "CoreCount") 119a1649ec6SChicago Duan { 120a1649ec6SChicago Duan const uint16_t* coresCount = 121a1649ec6SChicago Duan std::get_if<uint16_t>(&property.second); 122a1649ec6SChicago Duan if (coresCount == nullptr) 123a1649ec6SChicago Duan { 124a1649ec6SChicago Duan messages::internalError(aResp->res); 125a1649ec6SChicago Duan return; 126a1649ec6SChicago Duan } 127ac6a4445SGunnar Mills aResp->res.jsonValue["TotalCores"] = *coresCount; 128ac6a4445SGunnar Mills } 129dc3fa667SJonathan Doman else if (property.first == "MaxSpeedInMhz") 130dc3fa667SJonathan Doman { 131dc3fa667SJonathan Doman const uint32_t* value = std::get_if<uint32_t>(&property.second); 132dc3fa667SJonathan Doman if (value != nullptr) 133dc3fa667SJonathan Doman { 134dc3fa667SJonathan Doman aResp->res.jsonValue["MaxSpeedMHz"] = *value; 135dc3fa667SJonathan Doman } 136dc3fa667SJonathan Doman } 137ac6a4445SGunnar Mills else if (property.first == "Socket") 138ac6a4445SGunnar Mills { 139ac6a4445SGunnar Mills const std::string* value = 140ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 141ac6a4445SGunnar Mills if (value != nullptr) 142ac6a4445SGunnar Mills { 143ac6a4445SGunnar Mills aResp->res.jsonValue["Socket"] = *value; 144ac6a4445SGunnar Mills } 145ac6a4445SGunnar Mills } 146ac6a4445SGunnar Mills else if (property.first == "ThreadCount") 147ac6a4445SGunnar Mills { 148dc3fa667SJonathan Doman const uint16_t* value = std::get_if<uint16_t>(&property.second); 149ac6a4445SGunnar Mills if (value != nullptr) 150ac6a4445SGunnar Mills { 151ac6a4445SGunnar Mills aResp->res.jsonValue["TotalThreads"] = *value; 152ac6a4445SGunnar Mills } 153ac6a4445SGunnar Mills } 1541930fbd4SBrandon Kim else if (property.first == "EffectiveFamily") 155ac6a4445SGunnar Mills { 1561930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1576169de2cSBrad Bishop if (value != nullptr && *value != 2) 158ac6a4445SGunnar Mills { 159ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] = 160866e4862SEd Tanous "0x" + intToHexString(*value, 4); 161ac6a4445SGunnar Mills } 162ac6a4445SGunnar Mills } 1631930fbd4SBrandon Kim else if (property.first == "EffectiveModel") 1641930fbd4SBrandon Kim { 1651930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1661930fbd4SBrandon Kim if (value == nullptr) 1671930fbd4SBrandon Kim { 1681930fbd4SBrandon Kim messages::internalError(aResp->res); 1691930fbd4SBrandon Kim return; 1701930fbd4SBrandon Kim } 1716169de2cSBrad Bishop if (*value != 0) 1726169de2cSBrad Bishop { 1731930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["EffectiveModel"] = 174866e4862SEd Tanous "0x" + intToHexString(*value, 4); 1751930fbd4SBrandon Kim } 1766169de2cSBrad Bishop } 177ac6a4445SGunnar Mills else if (property.first == "Id") 178ac6a4445SGunnar Mills { 179ac6a4445SGunnar Mills const uint64_t* value = std::get_if<uint64_t>(&property.second); 180ac6a4445SGunnar Mills if (value != nullptr && *value != 0) 181ac6a4445SGunnar Mills { 182ac6a4445SGunnar Mills aResp->res 183ac6a4445SGunnar Mills .jsonValue["ProcessorId"]["IdentificationRegisters"] = 184866e4862SEd Tanous "0x" + intToHexString(*value, 16); 185ac6a4445SGunnar Mills } 186ac6a4445SGunnar Mills } 1871930fbd4SBrandon Kim else if (property.first == "Microcode") 1881930fbd4SBrandon Kim { 1891930fbd4SBrandon Kim const uint32_t* value = std::get_if<uint32_t>(&property.second); 1901930fbd4SBrandon Kim if (value == nullptr) 1911930fbd4SBrandon Kim { 1921930fbd4SBrandon Kim messages::internalError(aResp->res); 1931930fbd4SBrandon Kim return; 1941930fbd4SBrandon Kim } 1956169de2cSBrad Bishop if (*value != 0) 1966169de2cSBrad Bishop { 1971930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] = 198866e4862SEd Tanous "0x" + intToHexString(*value, 8); 1991930fbd4SBrandon Kim } 2006169de2cSBrad Bishop } 2011930fbd4SBrandon Kim else if (property.first == "Step") 2021930fbd4SBrandon Kim { 2031930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 2041930fbd4SBrandon Kim if (value == nullptr) 2051930fbd4SBrandon Kim { 2061930fbd4SBrandon Kim messages::internalError(aResp->res); 2071930fbd4SBrandon Kim return; 2081930fbd4SBrandon Kim } 209b9d679d1SMichael Shen if (*value != std::numeric_limits<uint16_t>::max()) 2106169de2cSBrad Bishop { 2111930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["Step"] = 212866e4862SEd Tanous "0x" + intToHexString(*value, 4); 2131930fbd4SBrandon Kim } 214ac6a4445SGunnar Mills } 215ac6a4445SGunnar Mills } 216ac6a4445SGunnar Mills } 2176169de2cSBrad Bishop } 218ac6a4445SGunnar Mills 2198d1b46d7Szhanghch05 inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, 220ac6a4445SGunnar Mills const std::string& cpuId, 221ac6a4445SGunnar Mills const std::string& service, 222ac6a4445SGunnar Mills const std::string& objPath) 223ac6a4445SGunnar Mills { 224ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; 225ac6a4445SGunnar Mills 226ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 227ac6a4445SGunnar Mills [cpuId, service, objPath, aResp{std::move(aResp)}]( 2285e7e2dc5SEd Tanous const boost::system::error_code& ec, 229ac6a4445SGunnar Mills const dbus::utility::ManagedObjectType& dbusData) { 230ac6a4445SGunnar Mills if (ec) 231ac6a4445SGunnar Mills { 232ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 233ac6a4445SGunnar Mills messages::internalError(aResp->res); 234ac6a4445SGunnar Mills return; 235ac6a4445SGunnar Mills } 236ac6a4445SGunnar Mills aResp->res.jsonValue["Id"] = cpuId; 237ac6a4445SGunnar Mills aResp->res.jsonValue["Name"] = "Processor"; 238ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorType"] = "CPU"; 239ac6a4445SGunnar Mills 240ac6a4445SGunnar Mills bool slotPresent = false; 241ac6a4445SGunnar Mills std::string corePath = objPath + "/core"; 242ac6a4445SGunnar Mills size_t totalCores = 0; 243ac6a4445SGunnar Mills for (const auto& object : dbusData) 244ac6a4445SGunnar Mills { 245ac6a4445SGunnar Mills if (object.first.str == objPath) 246ac6a4445SGunnar Mills { 247ac6a4445SGunnar Mills getCpuDataByInterface(aResp, object.second); 248ac6a4445SGunnar Mills } 24911ba3979SEd Tanous else if (object.first.str.starts_with(corePath)) 250ac6a4445SGunnar Mills { 251ac6a4445SGunnar Mills for (const auto& interface : object.second) 252ac6a4445SGunnar Mills { 253002d39b4SEd Tanous if (interface.first == "xyz.openbmc_project.Inventory.Item") 254ac6a4445SGunnar Mills { 255ac6a4445SGunnar Mills for (const auto& property : interface.second) 256ac6a4445SGunnar Mills { 257ac6a4445SGunnar Mills if (property.first == "Present") 258ac6a4445SGunnar Mills { 259ac6a4445SGunnar Mills const bool* present = 260ac6a4445SGunnar Mills std::get_if<bool>(&property.second); 261ac6a4445SGunnar Mills if (present != nullptr) 262ac6a4445SGunnar Mills { 263e05aec50SEd Tanous if (*present) 264ac6a4445SGunnar Mills { 265ac6a4445SGunnar Mills slotPresent = true; 266ac6a4445SGunnar Mills totalCores++; 267ac6a4445SGunnar Mills } 268ac6a4445SGunnar Mills } 269ac6a4445SGunnar Mills } 270ac6a4445SGunnar Mills } 271ac6a4445SGunnar Mills } 272ac6a4445SGunnar Mills } 273ac6a4445SGunnar Mills } 274ac6a4445SGunnar Mills } 275ac6a4445SGunnar Mills // In getCpuDataByInterface(), state and health are set 276ac6a4445SGunnar Mills // based on the present and functional status. If core 277ac6a4445SGunnar Mills // count is zero, then it has a higher precedence. 278ac6a4445SGunnar Mills if (slotPresent) 279ac6a4445SGunnar Mills { 280ac6a4445SGunnar Mills if (totalCores == 0) 281ac6a4445SGunnar Mills { 282ac6a4445SGunnar Mills // Slot is not populated, set status end return 283ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Absent"; 284ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["Health"] = "OK"; 285ac6a4445SGunnar Mills } 286ac6a4445SGunnar Mills aResp->res.jsonValue["TotalCores"] = totalCores; 287ac6a4445SGunnar Mills } 288ac6a4445SGunnar Mills return; 289ac6a4445SGunnar Mills }, 290ac6a4445SGunnar Mills service, "/xyz/openbmc_project/inventory", 291ac6a4445SGunnar Mills "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 292ac6a4445SGunnar Mills } 293ac6a4445SGunnar Mills 2948d1b46d7Szhanghch05 inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> aResp, 295ac6a4445SGunnar Mills const std::string& service, 296ac6a4445SGunnar Mills const std::string& objPath) 297ac6a4445SGunnar Mills { 298ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get Cpu Asset Data"; 299351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 300351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 301351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 302ac6a4445SGunnar Mills [objPath, aResp{std::move(aResp)}]( 3035e7e2dc5SEd Tanous const boost::system::error_code& ec, 304351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 305ac6a4445SGunnar Mills if (ec) 306ac6a4445SGunnar Mills { 307ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 308ac6a4445SGunnar Mills messages::internalError(aResp->res); 309ac6a4445SGunnar Mills return; 310ac6a4445SGunnar Mills } 311ac6a4445SGunnar Mills 312351053f2SKrzysztof Grobelny const std::string* serialNumber = nullptr; 313351053f2SKrzysztof Grobelny const std::string* model = nullptr; 314351053f2SKrzysztof Grobelny const std::string* manufacturer = nullptr; 315351053f2SKrzysztof Grobelny const std::string* partNumber = nullptr; 316351053f2SKrzysztof Grobelny const std::string* sparePartNumber = nullptr; 317351053f2SKrzysztof Grobelny 318351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 319351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber", 320351053f2SKrzysztof Grobelny serialNumber, "Model", model, "Manufacturer", manufacturer, 321351053f2SKrzysztof Grobelny "PartNumber", partNumber, "SparePartNumber", sparePartNumber); 322351053f2SKrzysztof Grobelny 323351053f2SKrzysztof Grobelny if (!success) 324ac6a4445SGunnar Mills { 325351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 326351053f2SKrzysztof Grobelny return; 327ac6a4445SGunnar Mills } 328351053f2SKrzysztof Grobelny 329351053f2SKrzysztof Grobelny if (serialNumber != nullptr && !serialNumber->empty()) 330ac6a4445SGunnar Mills { 331351053f2SKrzysztof Grobelny aResp->res.jsonValue["SerialNumber"] = *serialNumber; 332351053f2SKrzysztof Grobelny } 333351053f2SKrzysztof Grobelny 334351053f2SKrzysztof Grobelny if ((model != nullptr) && !model->empty()) 335ac6a4445SGunnar Mills { 336ac6a4445SGunnar Mills aResp->res.jsonValue["Model"] = *model; 337ac6a4445SGunnar Mills } 338ac6a4445SGunnar Mills 339351053f2SKrzysztof Grobelny if (manufacturer != nullptr) 340ac6a4445SGunnar Mills { 341351053f2SKrzysztof Grobelny aResp->res.jsonValue["Manufacturer"] = *manufacturer; 342ac6a4445SGunnar Mills 343ac6a4445SGunnar Mills // Otherwise would be unexpected. 344351053f2SKrzysztof Grobelny if (manufacturer->find("Intel") != std::string::npos) 345ac6a4445SGunnar Mills { 346002d39b4SEd Tanous aResp->res.jsonValue["ProcessorArchitecture"] = "x86"; 347ac6a4445SGunnar Mills aResp->res.jsonValue["InstructionSet"] = "x86-64"; 348ac6a4445SGunnar Mills } 349351053f2SKrzysztof Grobelny else if (manufacturer->find("IBM") != std::string::npos) 350ac6a4445SGunnar Mills { 351002d39b4SEd Tanous aResp->res.jsonValue["ProcessorArchitecture"] = "Power"; 352ac6a4445SGunnar Mills aResp->res.jsonValue["InstructionSet"] = "PowerISA"; 353ac6a4445SGunnar Mills } 354ac6a4445SGunnar Mills } 355cba4f448SSunnySrivastava1984 356351053f2SKrzysztof Grobelny if (partNumber != nullptr) 357cba4f448SSunnySrivastava1984 { 358cba4f448SSunnySrivastava1984 aResp->res.jsonValue["PartNumber"] = *partNumber; 359cba4f448SSunnySrivastava1984 } 360cba4f448SSunnySrivastava1984 3616169de2cSBrad Bishop if (sparePartNumber != nullptr && !sparePartNumber->empty()) 362cba4f448SSunnySrivastava1984 { 363cba4f448SSunnySrivastava1984 aResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; 364cba4f448SSunnySrivastava1984 } 365351053f2SKrzysztof Grobelny }); 366ac6a4445SGunnar Mills } 367ac6a4445SGunnar Mills 3688d1b46d7Szhanghch05 inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> aResp, 369ac6a4445SGunnar Mills const std::string& service, 370ac6a4445SGunnar Mills const std::string& objPath) 371ac6a4445SGunnar Mills { 372ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get Cpu Revision Data"; 373351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 374351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 375351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Revision", 376ac6a4445SGunnar Mills [objPath, aResp{std::move(aResp)}]( 3775e7e2dc5SEd Tanous const boost::system::error_code& ec, 378351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 379ac6a4445SGunnar Mills if (ec) 380ac6a4445SGunnar Mills { 381ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 382ac6a4445SGunnar Mills messages::internalError(aResp->res); 383ac6a4445SGunnar Mills return; 384ac6a4445SGunnar Mills } 385ac6a4445SGunnar Mills 386351053f2SKrzysztof Grobelny const std::string* version = nullptr; 387351053f2SKrzysztof Grobelny 388351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 389351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Version", version); 390351053f2SKrzysztof Grobelny 391351053f2SKrzysztof Grobelny if (!success) 392ac6a4445SGunnar Mills { 393351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 394351053f2SKrzysztof Grobelny return; 395351053f2SKrzysztof Grobelny } 396351053f2SKrzysztof Grobelny 397351053f2SKrzysztof Grobelny if (version != nullptr) 398ac6a4445SGunnar Mills { 399351053f2SKrzysztof Grobelny aResp->res.jsonValue["Version"] = *version; 400ac6a4445SGunnar Mills } 401351053f2SKrzysztof Grobelny }); 402ac6a4445SGunnar Mills } 403ac6a4445SGunnar Mills 4048d1b46d7Szhanghch05 inline void getAcceleratorDataByService( 4058d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> aResp, const std::string& acclrtrId, 4068d1b46d7Szhanghch05 const std::string& service, const std::string& objPath) 407ac6a4445SGunnar Mills { 408ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG 409ac6a4445SGunnar Mills << "Get available system Accelerator resources by service."; 410351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 411351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, "", 412ac6a4445SGunnar Mills [acclrtrId, aResp{std::move(aResp)}]( 4135e7e2dc5SEd Tanous const boost::system::error_code& ec, 414351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 415ac6a4445SGunnar Mills if (ec) 416ac6a4445SGunnar Mills { 417ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 418ac6a4445SGunnar Mills messages::internalError(aResp->res); 419ac6a4445SGunnar Mills return; 420ac6a4445SGunnar Mills } 421ac6a4445SGunnar Mills 422351053f2SKrzysztof Grobelny const bool* functional = nullptr; 423351053f2SKrzysztof Grobelny const bool* present = nullptr; 424351053f2SKrzysztof Grobelny 425351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 426351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Functional", 427351053f2SKrzysztof Grobelny functional, "Present", present); 428351053f2SKrzysztof Grobelny 429351053f2SKrzysztof Grobelny if (!success) 430ac6a4445SGunnar Mills { 431351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 432351053f2SKrzysztof Grobelny return; 433ac6a4445SGunnar Mills } 434ac6a4445SGunnar Mills 435ac6a4445SGunnar Mills std::string state = "Enabled"; 436ac6a4445SGunnar Mills std::string health = "OK"; 437ac6a4445SGunnar Mills 438351053f2SKrzysztof Grobelny if (present != nullptr && !*present) 439ac6a4445SGunnar Mills { 440ac6a4445SGunnar Mills state = "Absent"; 441ac6a4445SGunnar Mills } 442ac6a4445SGunnar Mills 443351053f2SKrzysztof Grobelny if (functional != nullptr && !*functional) 444ac6a4445SGunnar Mills { 445ac6a4445SGunnar Mills if (state == "Enabled") 446ac6a4445SGunnar Mills { 447ac6a4445SGunnar Mills health = "Critical"; 448ac6a4445SGunnar Mills } 449ac6a4445SGunnar Mills } 450ac6a4445SGunnar Mills 451351053f2SKrzysztof Grobelny aResp->res.jsonValue["Id"] = acclrtrId; 452351053f2SKrzysztof Grobelny aResp->res.jsonValue["Name"] = "Processor"; 453ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = state; 454ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["Health"] = health; 455ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorType"] = "Accelerator"; 456351053f2SKrzysztof Grobelny }); 457ac6a4445SGunnar Mills } 458ac6a4445SGunnar Mills 459dba0c291SJonathan Doman // OperatingConfig D-Bus Types 460dba0c291SJonathan Doman using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>; 461dba0c291SJonathan Doman using BaseSpeedPrioritySettingsProperty = 462dba0c291SJonathan Doman std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>; 463dba0c291SJonathan Doman // uint32_t and size_t may or may not be the same type, requiring a dedup'd 464dba0c291SJonathan Doman // variant 465dba0c291SJonathan Doman 466dba0c291SJonathan Doman /** 467dba0c291SJonathan Doman * Fill out the HighSpeedCoreIDs in a Processor resource from the given 468dba0c291SJonathan Doman * OperatingConfig D-Bus property. 469dba0c291SJonathan Doman * 470dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 471dba0c291SJonathan Doman * @param[in] baseSpeedSettings Full list of base speed priority groups, 472dba0c291SJonathan Doman * to use to determine the list of high 473dba0c291SJonathan Doman * speed cores. 474dba0c291SJonathan Doman */ 475dba0c291SJonathan Doman inline void highSpeedCoreIdsHandler( 4768d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 477dba0c291SJonathan Doman const BaseSpeedPrioritySettingsProperty& baseSpeedSettings) 478dba0c291SJonathan Doman { 479dba0c291SJonathan Doman // The D-Bus property does not indicate which bucket is the "high 480dba0c291SJonathan Doman // priority" group, so let's discern that by looking for the one with 481dba0c291SJonathan Doman // highest base frequency. 482dba0c291SJonathan Doman auto highPriorityGroup = baseSpeedSettings.cend(); 483dba0c291SJonathan Doman uint32_t highestBaseSpeed = 0; 484dba0c291SJonathan Doman for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend(); 485dba0c291SJonathan Doman ++it) 486dba0c291SJonathan Doman { 487dba0c291SJonathan Doman const uint32_t baseFreq = std::get<uint32_t>(*it); 488dba0c291SJonathan Doman if (baseFreq > highestBaseSpeed) 489dba0c291SJonathan Doman { 490dba0c291SJonathan Doman highestBaseSpeed = baseFreq; 491dba0c291SJonathan Doman highPriorityGroup = it; 492dba0c291SJonathan Doman } 493dba0c291SJonathan Doman } 494dba0c291SJonathan Doman 495dba0c291SJonathan Doman nlohmann::json& jsonCoreIds = aResp->res.jsonValue["HighSpeedCoreIDs"]; 496dba0c291SJonathan Doman jsonCoreIds = nlohmann::json::array(); 497dba0c291SJonathan Doman 498dba0c291SJonathan Doman // There may not be any entries in the D-Bus property, so only populate 499dba0c291SJonathan Doman // if there was actually something there. 500dba0c291SJonathan Doman if (highPriorityGroup != baseSpeedSettings.cend()) 501dba0c291SJonathan Doman { 502dba0c291SJonathan Doman jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup); 503dba0c291SJonathan Doman } 504dba0c291SJonathan Doman } 505dba0c291SJonathan Doman 506dba0c291SJonathan Doman /** 507dba0c291SJonathan Doman * Fill out OperatingConfig related items in a Processor resource by requesting 508dba0c291SJonathan Doman * data from the given D-Bus object. 509dba0c291SJonathan Doman * 510dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 511dba0c291SJonathan Doman * @param[in] cpuId CPU D-Bus name. 512dba0c291SJonathan Doman * @param[in] service D-Bus service to query. 513dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 514dba0c291SJonathan Doman */ 5158d1b46d7Szhanghch05 inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 516dba0c291SJonathan Doman const std::string& cpuId, 517dba0c291SJonathan Doman const std::string& service, 518dba0c291SJonathan Doman const std::string& objPath) 519dba0c291SJonathan Doman { 520dba0c291SJonathan Doman BMCWEB_LOG_INFO << "Getting CPU operating configs for " << cpuId; 521dba0c291SJonathan Doman 522dba0c291SJonathan Doman // First, GetAll CurrentOperatingConfig properties on the object 523351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 524351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 525351053f2SKrzysztof Grobelny "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 526351053f2SKrzysztof Grobelny [aResp, cpuId, 5275e7e2dc5SEd Tanous service](const boost::system::error_code& ec, 528351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 529dba0c291SJonathan Doman if (ec) 530dba0c291SJonathan Doman { 531002d39b4SEd Tanous BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message(); 532dba0c291SJonathan Doman messages::internalError(aResp->res); 533dba0c291SJonathan Doman return; 534dba0c291SJonathan Doman } 535dba0c291SJonathan Doman 536dba0c291SJonathan Doman nlohmann::json& json = aResp->res.jsonValue; 537dba0c291SJonathan Doman 538351053f2SKrzysztof Grobelny const sdbusplus::message::object_path* appliedConfig = nullptr; 539351053f2SKrzysztof Grobelny const bool* baseSpeedPriorityEnabled = nullptr; 540351053f2SKrzysztof Grobelny 541351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 542351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig", 543351053f2SKrzysztof Grobelny appliedConfig, "BaseSpeedPriorityEnabled", 544351053f2SKrzysztof Grobelny baseSpeedPriorityEnabled); 545351053f2SKrzysztof Grobelny 546351053f2SKrzysztof Grobelny if (!success) 547dba0c291SJonathan Doman { 548351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 549351053f2SKrzysztof Grobelny return; 550dba0c291SJonathan Doman } 551dba0c291SJonathan Doman 552351053f2SKrzysztof Grobelny if (appliedConfig != nullptr) 553351053f2SKrzysztof Grobelny { 554351053f2SKrzysztof Grobelny const std::string& dbusPath = appliedConfig->str; 5551476687dSEd Tanous nlohmann::json::object_t operatingConfig; 556eddfc437SWilly Tu operatingConfig["@odata.id"] = crow::utility::urlFromPieces( 557eddfc437SWilly Tu "redfish", "v1", "Systems", "system", "Processors", cpuId, 558eddfc437SWilly Tu "OperatingConfigs"); 5591476687dSEd Tanous json["OperatingConfigs"] = std::move(operatingConfig); 560dba0c291SJonathan Doman 561dba0c291SJonathan Doman // Reuse the D-Bus config object name for the Redfish 562dba0c291SJonathan Doman // URI 563dba0c291SJonathan Doman size_t baseNamePos = dbusPath.rfind('/'); 564dba0c291SJonathan Doman if (baseNamePos == std::string::npos || 565dba0c291SJonathan Doman baseNamePos == (dbusPath.size() - 1)) 566dba0c291SJonathan Doman { 567dba0c291SJonathan Doman // If the AppliedConfig was somehow not a valid path, 568dba0c291SJonathan Doman // skip adding any more properties, since everything 569dba0c291SJonathan Doman // else is tied to this applied config. 570dba0c291SJonathan Doman messages::internalError(aResp->res); 571351053f2SKrzysztof Grobelny return; 572dba0c291SJonathan Doman } 5731476687dSEd Tanous nlohmann::json::object_t appliedOperatingConfig; 574eddfc437SWilly Tu appliedOperatingConfig["@odata.id"] = crow::utility::urlFromPieces( 575eddfc437SWilly Tu "redfish", "v1", "Systems", "system", "Processors", cpuId, 576eddfc437SWilly Tu "OperatingConfigs", dbusPath.substr(baseNamePos + 1)); 577351053f2SKrzysztof Grobelny json["AppliedOperatingConfig"] = std::move(appliedOperatingConfig); 578dba0c291SJonathan Doman 579dba0c291SJonathan Doman // Once we found the current applied config, queue another 580dba0c291SJonathan Doman // request to read the base freq core ids out of that 581dba0c291SJonathan Doman // config. 582002d39b4SEd Tanous sdbusplus::asio::getProperty<BaseSpeedPrioritySettingsProperty>( 5831e1e598dSJonathan Doman *crow::connections::systemBus, service, dbusPath, 5841e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu." 5851e1e598dSJonathan Doman "OperatingConfig", 5861e1e598dSJonathan Doman "BaseSpeedPrioritySettings", 587351053f2SKrzysztof Grobelny [aResp]( 5885e7e2dc5SEd Tanous const boost::system::error_code& ec2, 589351053f2SKrzysztof Grobelny const BaseSpeedPrioritySettingsProperty& baseSpeedList) { 5908a592810SEd Tanous if (ec2) 591dba0c291SJonathan Doman { 592351053f2SKrzysztof Grobelny BMCWEB_LOG_WARNING << "D-Bus Property Get error: " << ec2; 593dba0c291SJonathan Doman messages::internalError(aResp->res); 594dba0c291SJonathan Doman return; 595dba0c291SJonathan Doman } 5961e1e598dSJonathan Doman 5971e1e598dSJonathan Doman highSpeedCoreIdsHandler(aResp, baseSpeedList); 5981e1e598dSJonathan Doman }); 599dba0c291SJonathan Doman } 600351053f2SKrzysztof Grobelny 601351053f2SKrzysztof Grobelny if (baseSpeedPriorityEnabled != nullptr) 602dba0c291SJonathan Doman { 603dba0c291SJonathan Doman json["BaseSpeedPriorityState"] = 604351053f2SKrzysztof Grobelny *baseSpeedPriorityEnabled ? "Enabled" : "Disabled"; 605dba0c291SJonathan Doman } 606351053f2SKrzysztof Grobelny }); 607dba0c291SJonathan Doman } 608dba0c291SJonathan Doman 609cba4f448SSunnySrivastava1984 /** 610cba4f448SSunnySrivastava1984 * @brief Fill out location info of a processor by 611cba4f448SSunnySrivastava1984 * requesting data from the given D-Bus object. 612cba4f448SSunnySrivastava1984 * 613cba4f448SSunnySrivastava1984 * @param[in,out] aResp Async HTTP response. 614cba4f448SSunnySrivastava1984 * @param[in] service D-Bus service to query. 615cba4f448SSunnySrivastava1984 * @param[in] objPath D-Bus object to query. 616cba4f448SSunnySrivastava1984 */ 6178d1b46d7Szhanghch05 inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp, 618cba4f448SSunnySrivastava1984 const std::string& service, 619cba4f448SSunnySrivastava1984 const std::string& objPath) 620cba4f448SSunnySrivastava1984 { 621cba4f448SSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Get Cpu Location Data"; 6221e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 6231e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 6241e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 6255e7e2dc5SEd Tanous [objPath, aResp{std::move(aResp)}](const boost::system::error_code& ec, 6261e1e598dSJonathan Doman const std::string& property) { 627cba4f448SSunnySrivastava1984 if (ec) 628cba4f448SSunnySrivastava1984 { 629cba4f448SSunnySrivastava1984 BMCWEB_LOG_DEBUG << "DBUS response error"; 630cba4f448SSunnySrivastava1984 messages::internalError(aResp->res); 631cba4f448SSunnySrivastava1984 return; 632cba4f448SSunnySrivastava1984 } 633cba4f448SSunnySrivastava1984 634cba4f448SSunnySrivastava1984 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 6351e1e598dSJonathan Doman property; 6361e1e598dSJonathan Doman }); 637cba4f448SSunnySrivastava1984 } 638cba4f448SSunnySrivastava1984 639c951448aSJonathan Doman /** 64049e429caSJonathan Doman * Populate the unique identifier in a Processor resource by requesting data 64149e429caSJonathan Doman * from the given D-Bus object. 64249e429caSJonathan Doman * 64349e429caSJonathan Doman * @param[in,out] aResp Async HTTP response. 64449e429caSJonathan Doman * @param[in] service D-Bus service to query. 64549e429caSJonathan Doman * @param[in] objPath D-Bus object to query. 64649e429caSJonathan Doman */ 64749e429caSJonathan Doman inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 64849e429caSJonathan Doman const std::string& service, 64949e429caSJonathan Doman const std::string& objectPath) 65049e429caSJonathan Doman { 65149e429caSJonathan Doman BMCWEB_LOG_DEBUG << "Get CPU UniqueIdentifier"; 6521e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 6531e1e598dSJonathan Doman *crow::connections::systemBus, service, objectPath, 6541e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", 6551e1e598dSJonathan Doman "UniqueIdentifier", 6565e7e2dc5SEd Tanous [aResp](const boost::system::error_code& ec, const std::string& id) { 6571e1e598dSJonathan Doman if (ec) 65849e429caSJonathan Doman { 65949e429caSJonathan Doman BMCWEB_LOG_ERROR << "Failed to read cpu unique id: " << ec; 66049e429caSJonathan Doman messages::internalError(aResp->res); 66149e429caSJonathan Doman return; 66249e429caSJonathan Doman } 663002d39b4SEd Tanous aResp->res.jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = 664002d39b4SEd Tanous id; 6651e1e598dSJonathan Doman }); 66649e429caSJonathan Doman } 66749e429caSJonathan Doman 66849e429caSJonathan Doman /** 669c951448aSJonathan Doman * Find the D-Bus object representing the requested Processor, and call the 670c951448aSJonathan Doman * handler with the results. If matching object is not found, add 404 error to 671c951448aSJonathan Doman * response and don't call the handler. 672c951448aSJonathan Doman * 673c951448aSJonathan Doman * @param[in,out] resp Async HTTP response. 674c951448aSJonathan Doman * @param[in] processorId Redfish Processor Id. 675c951448aSJonathan Doman * @param[in] handler Callback to continue processing request upon 676c951448aSJonathan Doman * successfully finding object. 677c951448aSJonathan Doman */ 678c951448aSJonathan Doman template <typename Handler> 6798d1b46d7Szhanghch05 inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp, 680c951448aSJonathan Doman const std::string& processorId, 681c951448aSJonathan Doman Handler&& handler) 682ac6a4445SGunnar Mills { 683ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get available system processor resources."; 684ac6a4445SGunnar Mills 685c951448aSJonathan Doman // GetSubTree on all interfaces which provide info about a Processor 686e99073f5SGeorge Liu constexpr std::array<std::string_view, 8> interfaces = { 687e99073f5SGeorge Liu "xyz.openbmc_project.Common.UUID", 688e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Asset", 689e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Revision", 690e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Cpu", 691e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode", 692e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Accelerator", 693e99073f5SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 694e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier"}; 695e99073f5SGeorge Liu dbus::utility::getSubTree( 696e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 697c951448aSJonathan Doman [resp, processorId, handler = std::forward<Handler>(handler)]( 698e99073f5SGeorge Liu const boost::system::error_code& ec, 699e99073f5SGeorge Liu const dbus::utility::MapperGetSubTreeResponse& subtree) { 700ac6a4445SGunnar Mills if (ec) 701ac6a4445SGunnar Mills { 702c951448aSJonathan Doman BMCWEB_LOG_DEBUG << "DBUS response error: " << ec; 703c951448aSJonathan Doman messages::internalError(resp->res); 704ac6a4445SGunnar Mills return; 705ac6a4445SGunnar Mills } 7062bab9831SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 707ac6a4445SGunnar Mills { 7082bab9831SJonathan Doman // Ignore any objects which don't end with our desired cpu name 70911ba3979SEd Tanous if (!objectPath.ends_with(processorId)) 710ac6a4445SGunnar Mills { 7112bab9831SJonathan Doman continue; 712ac6a4445SGunnar Mills } 7132bab9831SJonathan Doman 714c951448aSJonathan Doman bool found = false; 715c951448aSJonathan Doman // Filter out objects that don't have the CPU-specific 716c951448aSJonathan Doman // interfaces to make sure we can return 404 on non-CPUs 717c951448aSJonathan Doman // (e.g. /redfish/../Processors/dimm0) 7182bab9831SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 719ac6a4445SGunnar Mills { 720c951448aSJonathan Doman if (std::find_first_of( 721c951448aSJonathan Doman interfaceList.begin(), interfaceList.end(), 722c951448aSJonathan Doman processorInterfaces.begin(), 723c951448aSJonathan Doman processorInterfaces.end()) != interfaceList.end()) 7242bab9831SJonathan Doman { 725c951448aSJonathan Doman found = true; 726c951448aSJonathan Doman break; 727c951448aSJonathan Doman } 728c951448aSJonathan Doman } 729c951448aSJonathan Doman 730c951448aSJonathan Doman if (!found) 7312bab9831SJonathan Doman { 732c951448aSJonathan Doman continue; 733ac6a4445SGunnar Mills } 734c951448aSJonathan Doman 735c951448aSJonathan Doman // Process the first object which does match our cpu name and 736c951448aSJonathan Doman // required interfaces, and potentially ignore any other 737c951448aSJonathan Doman // matching objects. Assume all interfaces we want to process 738c951448aSJonathan Doman // must be on the same object path. 739c951448aSJonathan Doman 7408a592810SEd Tanous handler(objectPath, serviceMap); 741ac6a4445SGunnar Mills return; 742ac6a4445SGunnar Mills } 743c951448aSJonathan Doman messages::resourceNotFound(resp->res, "Processor", processorId); 744e99073f5SGeorge Liu }); 745ac6a4445SGunnar Mills } 746ac6a4445SGunnar Mills 7478d1b46d7Szhanghch05 inline void getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 748c951448aSJonathan Doman const std::string& processorId, 749c951448aSJonathan Doman const std::string& objectPath, 7505df6eda2SShantappa Teekappanavar const dbus::utility::MapperServiceMap& serviceMap) 751c951448aSJonathan Doman { 752c951448aSJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 753c951448aSJonathan Doman { 754c951448aSJonathan Doman for (const auto& interface : interfaceList) 755c951448aSJonathan Doman { 756c951448aSJonathan Doman if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") 757c951448aSJonathan Doman { 758c951448aSJonathan Doman getCpuAssetData(aResp, serviceName, objectPath); 759c951448aSJonathan Doman } 7600fda0f12SGeorge Liu else if (interface == 7610fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Revision") 762c951448aSJonathan Doman { 763c951448aSJonathan Doman getCpuRevisionData(aResp, serviceName, objectPath); 764c951448aSJonathan Doman } 765c951448aSJonathan Doman else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu") 766c951448aSJonathan Doman { 767c951448aSJonathan Doman getCpuDataByService(aResp, processorId, serviceName, 768c951448aSJonathan Doman objectPath); 769c951448aSJonathan Doman } 7700fda0f12SGeorge Liu else if (interface == 7710fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Accelerator") 772c951448aSJonathan Doman { 773c951448aSJonathan Doman getAcceleratorDataByService(aResp, processorId, serviceName, 774c951448aSJonathan Doman objectPath); 775c951448aSJonathan Doman } 7760fda0f12SGeorge Liu else if ( 7770fda0f12SGeorge Liu interface == 7780fda0f12SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig") 779c951448aSJonathan Doman { 780c951448aSJonathan Doman getCpuConfigData(aResp, processorId, serviceName, objectPath); 781c951448aSJonathan Doman } 7820fda0f12SGeorge Liu else if (interface == 7830fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 784c951448aSJonathan Doman { 785c951448aSJonathan Doman getCpuLocationCode(aResp, serviceName, objectPath); 786c951448aSJonathan Doman } 78771b82f26SSharad Yadav else if (interface == "xyz.openbmc_project.Common.UUID") 78871b82f26SSharad Yadav { 78971b82f26SSharad Yadav getProcessorUUID(aResp, serviceName, objectPath); 79071b82f26SSharad Yadav } 7910fda0f12SGeorge Liu else if (interface == 7920fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier") 79349e429caSJonathan Doman { 79449e429caSJonathan Doman getCpuUniqueId(aResp, serviceName, objectPath); 79549e429caSJonathan Doman } 796c951448aSJonathan Doman } 797c951448aSJonathan Doman } 798c951448aSJonathan Doman } 799c951448aSJonathan Doman 800dba0c291SJonathan Doman /** 801dba0c291SJonathan Doman * Request all the properties for the given D-Bus object and fill out the 802dba0c291SJonathan Doman * related entries in the Redfish OperatingConfig response. 803dba0c291SJonathan Doman * 804dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 805dba0c291SJonathan Doman * @param[in] service D-Bus service name to query. 806dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 807dba0c291SJonathan Doman */ 8088d1b46d7Szhanghch05 inline void 8098d1b46d7Szhanghch05 getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 810dba0c291SJonathan Doman const std::string& service, 811dba0c291SJonathan Doman const std::string& objPath) 812dba0c291SJonathan Doman { 813351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 814351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 815351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig", 8165e7e2dc5SEd Tanous [aResp](const boost::system::error_code& ec, 817351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 818dba0c291SJonathan Doman if (ec) 819dba0c291SJonathan Doman { 820002d39b4SEd Tanous BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message(); 821dba0c291SJonathan Doman messages::internalError(aResp->res); 822dba0c291SJonathan Doman return; 823dba0c291SJonathan Doman } 824dba0c291SJonathan Doman 825351053f2SKrzysztof Grobelny const size_t* availableCoreCount = nullptr; 826351053f2SKrzysztof Grobelny const uint32_t* baseSpeed = nullptr; 827351053f2SKrzysztof Grobelny const uint32_t* maxJunctionTemperature = nullptr; 828351053f2SKrzysztof Grobelny const uint32_t* maxSpeed = nullptr; 829351053f2SKrzysztof Grobelny const uint32_t* powerLimit = nullptr; 830351053f2SKrzysztof Grobelny const TurboProfileProperty* turboProfile = nullptr; 831351053f2SKrzysztof Grobelny const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings = 832351053f2SKrzysztof Grobelny nullptr; 833351053f2SKrzysztof Grobelny 834351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 835351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount", 836351053f2SKrzysztof Grobelny availableCoreCount, "BaseSpeed", baseSpeed, 837351053f2SKrzysztof Grobelny "MaxJunctionTemperature", maxJunctionTemperature, "MaxSpeed", 838351053f2SKrzysztof Grobelny maxSpeed, "PowerLimit", powerLimit, "TurboProfile", turboProfile, 839351053f2SKrzysztof Grobelny "BaseSpeedPrioritySettings", baseSpeedPrioritySettings); 840351053f2SKrzysztof Grobelny 841351053f2SKrzysztof Grobelny if (!success) 842dba0c291SJonathan Doman { 843351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 844351053f2SKrzysztof Grobelny return; 845dba0c291SJonathan Doman } 846dba0c291SJonathan Doman 847351053f2SKrzysztof Grobelny nlohmann::json& json = aResp->res.jsonValue; 848351053f2SKrzysztof Grobelny 849351053f2SKrzysztof Grobelny if (availableCoreCount != nullptr) 850351053f2SKrzysztof Grobelny { 851351053f2SKrzysztof Grobelny json["TotalAvailableCoreCount"] = *availableCoreCount; 852351053f2SKrzysztof Grobelny } 853351053f2SKrzysztof Grobelny 854351053f2SKrzysztof Grobelny if (baseSpeed != nullptr) 855351053f2SKrzysztof Grobelny { 856351053f2SKrzysztof Grobelny json["BaseSpeedMHz"] = *baseSpeed; 857351053f2SKrzysztof Grobelny } 858351053f2SKrzysztof Grobelny 859351053f2SKrzysztof Grobelny if (maxJunctionTemperature != nullptr) 860351053f2SKrzysztof Grobelny { 861351053f2SKrzysztof Grobelny json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature; 862351053f2SKrzysztof Grobelny } 863351053f2SKrzysztof Grobelny 864351053f2SKrzysztof Grobelny if (maxSpeed != nullptr) 865351053f2SKrzysztof Grobelny { 866351053f2SKrzysztof Grobelny json["MaxSpeedMHz"] = *maxSpeed; 867351053f2SKrzysztof Grobelny } 868351053f2SKrzysztof Grobelny 869351053f2SKrzysztof Grobelny if (powerLimit != nullptr) 870351053f2SKrzysztof Grobelny { 871351053f2SKrzysztof Grobelny json["TDPWatts"] = *powerLimit; 872351053f2SKrzysztof Grobelny } 873351053f2SKrzysztof Grobelny 874351053f2SKrzysztof Grobelny if (turboProfile != nullptr) 875351053f2SKrzysztof Grobelny { 876dba0c291SJonathan Doman nlohmann::json& turboArray = json["TurboProfile"]; 877dba0c291SJonathan Doman turboArray = nlohmann::json::array(); 878351053f2SKrzysztof Grobelny for (const auto& [turboSpeed, coreCount] : *turboProfile) 879dba0c291SJonathan Doman { 8801476687dSEd Tanous nlohmann::json::object_t turbo; 8811476687dSEd Tanous turbo["ActiveCoreCount"] = coreCount; 8821476687dSEd Tanous turbo["MaxSpeedMHz"] = turboSpeed; 883*b2ba3072SPatrick Williams turboArray.emplace_back(std::move(turbo)); 884dba0c291SJonathan Doman } 885dba0c291SJonathan Doman } 886dba0c291SJonathan Doman 887351053f2SKrzysztof Grobelny if (baseSpeedPrioritySettings != nullptr) 888351053f2SKrzysztof Grobelny { 889351053f2SKrzysztof Grobelny nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"]; 890dba0c291SJonathan Doman baseSpeedArray = nlohmann::json::array(); 891351053f2SKrzysztof Grobelny for (const auto& [baseSpeedMhz, coreList] : 892351053f2SKrzysztof Grobelny *baseSpeedPrioritySettings) 893dba0c291SJonathan Doman { 8941476687dSEd Tanous nlohmann::json::object_t speed; 8951476687dSEd Tanous speed["CoreCount"] = coreList.size(); 8961476687dSEd Tanous speed["CoreIDs"] = coreList; 897351053f2SKrzysztof Grobelny speed["BaseSpeedMHz"] = baseSpeedMhz; 898*b2ba3072SPatrick Williams baseSpeedArray.emplace_back(std::move(speed)); 899dba0c291SJonathan Doman } 900dba0c291SJonathan Doman } 901351053f2SKrzysztof Grobelny }); 902dba0c291SJonathan Doman } 903dba0c291SJonathan Doman 9043cde86f1SJonathan Doman /** 9053cde86f1SJonathan Doman * Handle the D-Bus response from attempting to set the CPU's AppliedConfig 9063cde86f1SJonathan Doman * property. Main task is to translate error messages into Redfish errors. 9073cde86f1SJonathan Doman * 9083cde86f1SJonathan Doman * @param[in,out] resp HTTP response. 9093cde86f1SJonathan Doman * @param[in] setPropVal Value which we attempted to set. 9103cde86f1SJonathan Doman * @param[in] ec D-Bus response error code. 9113cde86f1SJonathan Doman * @param[in] msg D-Bus response message. 9123cde86f1SJonathan Doman */ 9133cde86f1SJonathan Doman inline void 9143cde86f1SJonathan Doman handleAppliedConfigResponse(const std::shared_ptr<bmcweb::AsyncResp>& resp, 9153cde86f1SJonathan Doman const std::string& setPropVal, 9165e7e2dc5SEd Tanous const boost::system::error_code& ec, 91759d494eeSPatrick Williams const sdbusplus::message_t& msg) 9183cde86f1SJonathan Doman { 9193cde86f1SJonathan Doman if (!ec) 9203cde86f1SJonathan Doman { 9213cde86f1SJonathan Doman BMCWEB_LOG_DEBUG << "Set Property succeeded"; 9223cde86f1SJonathan Doman return; 9233cde86f1SJonathan Doman } 9243cde86f1SJonathan Doman 9253cde86f1SJonathan Doman BMCWEB_LOG_DEBUG << "Set Property failed: " << ec; 9263cde86f1SJonathan Doman 9273cde86f1SJonathan Doman const sd_bus_error* dbusError = msg.get_error(); 9283cde86f1SJonathan Doman if (dbusError == nullptr) 9293cde86f1SJonathan Doman { 9303cde86f1SJonathan Doman messages::internalError(resp->res); 9313cde86f1SJonathan Doman return; 9323cde86f1SJonathan Doman } 9333cde86f1SJonathan Doman 9343cde86f1SJonathan Doman // The asio error code doesn't know about our custom errors, so we have to 9353cde86f1SJonathan Doman // parse the error string. Some of these D-Bus -> Redfish translations are a 9363cde86f1SJonathan Doman // stretch, but it's good to try to communicate something vaguely useful. 9373cde86f1SJonathan Doman if (strcmp(dbusError->name, 9383cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.InvalidArgument") == 0) 9393cde86f1SJonathan Doman { 9403cde86f1SJonathan Doman // Service did not like the object_path we tried to set. 9413cde86f1SJonathan Doman messages::propertyValueIncorrect( 9423cde86f1SJonathan Doman resp->res, "AppliedOperatingConfig/@odata.id", setPropVal); 9433cde86f1SJonathan Doman } 9443cde86f1SJonathan Doman else if (strcmp(dbusError->name, 9453cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.NotAllowed") == 0) 9463cde86f1SJonathan Doman { 9473cde86f1SJonathan Doman // Service indicates we can never change the config for this processor. 9483cde86f1SJonathan Doman messages::propertyNotWritable(resp->res, "AppliedOperatingConfig"); 9493cde86f1SJonathan Doman } 9503cde86f1SJonathan Doman else if (strcmp(dbusError->name, 9513cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.Unavailable") == 0) 9523cde86f1SJonathan Doman { 9533cde86f1SJonathan Doman // Service indicates the config cannot be changed right now, but maybe 9543cde86f1SJonathan Doman // in a different system state. 9553cde86f1SJonathan Doman messages::resourceInStandby(resp->res); 9563cde86f1SJonathan Doman } 9573cde86f1SJonathan Doman else 9583cde86f1SJonathan Doman { 9593cde86f1SJonathan Doman messages::internalError(resp->res); 9603cde86f1SJonathan Doman } 9613cde86f1SJonathan Doman } 9623cde86f1SJonathan Doman 9633cde86f1SJonathan Doman /** 9643cde86f1SJonathan Doman * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic 9653cde86f1SJonathan Doman * validation of the input data, and then set the D-Bus property. 9663cde86f1SJonathan Doman * 9673cde86f1SJonathan Doman * @param[in,out] resp Async HTTP response. 9683cde86f1SJonathan Doman * @param[in] processorId Processor's Id. 9693cde86f1SJonathan Doman * @param[in] appliedConfigUri New property value to apply. 9703cde86f1SJonathan Doman * @param[in] cpuObjectPath Path of CPU object to modify. 9713cde86f1SJonathan Doman * @param[in] serviceMap Service map for CPU object. 9723cde86f1SJonathan Doman */ 9733cde86f1SJonathan Doman inline void patchAppliedOperatingConfig( 9743cde86f1SJonathan Doman const std::shared_ptr<bmcweb::AsyncResp>& resp, 9753cde86f1SJonathan Doman const std::string& processorId, const std::string& appliedConfigUri, 9765df6eda2SShantappa Teekappanavar const std::string& cpuObjectPath, 9775df6eda2SShantappa Teekappanavar const dbus::utility::MapperServiceMap& serviceMap) 9783cde86f1SJonathan Doman { 9793cde86f1SJonathan Doman // Check that the property even exists by checking for the interface 9803cde86f1SJonathan Doman const std::string* controlService = nullptr; 9813cde86f1SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 9823cde86f1SJonathan Doman { 9833cde86f1SJonathan Doman if (std::find(interfaceList.begin(), interfaceList.end(), 9843cde86f1SJonathan Doman "xyz.openbmc_project.Control.Processor." 9853cde86f1SJonathan Doman "CurrentOperatingConfig") != interfaceList.end()) 9863cde86f1SJonathan Doman { 9873cde86f1SJonathan Doman controlService = &serviceName; 9883cde86f1SJonathan Doman break; 9893cde86f1SJonathan Doman } 9903cde86f1SJonathan Doman } 9913cde86f1SJonathan Doman 9923cde86f1SJonathan Doman if (controlService == nullptr) 9933cde86f1SJonathan Doman { 9943cde86f1SJonathan Doman messages::internalError(resp->res); 9953cde86f1SJonathan Doman return; 9963cde86f1SJonathan Doman } 9973cde86f1SJonathan Doman 9983cde86f1SJonathan Doman // Check that the config URI is a child of the cpu URI being patched. 9993cde86f1SJonathan Doman std::string expectedPrefix("/redfish/v1/Systems/system/Processors/"); 10003cde86f1SJonathan Doman expectedPrefix += processorId; 10013cde86f1SJonathan Doman expectedPrefix += "/OperatingConfigs/"; 100211ba3979SEd Tanous if (!appliedConfigUri.starts_with(expectedPrefix) || 10033cde86f1SJonathan Doman expectedPrefix.size() == appliedConfigUri.size()) 10043cde86f1SJonathan Doman { 10053cde86f1SJonathan Doman messages::propertyValueIncorrect( 10063cde86f1SJonathan Doman resp->res, "AppliedOperatingConfig/@odata.id", appliedConfigUri); 10073cde86f1SJonathan Doman return; 10083cde86f1SJonathan Doman } 10093cde86f1SJonathan Doman 10103cde86f1SJonathan Doman // Generate the D-Bus path of the OperatingConfig object, by assuming it's a 10113cde86f1SJonathan Doman // direct child of the CPU object. 10123cde86f1SJonathan Doman // Strip the expectedPrefix from the config URI to get the "filename", and 10133cde86f1SJonathan Doman // append to the CPU's path. 10143cde86f1SJonathan Doman std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size()); 10153cde86f1SJonathan Doman sdbusplus::message::object_path configPath(cpuObjectPath); 10163cde86f1SJonathan Doman configPath /= configBaseName; 10173cde86f1SJonathan Doman 10183cde86f1SJonathan Doman BMCWEB_LOG_INFO << "Setting config to " << configPath.str; 10193cde86f1SJonathan Doman 10203cde86f1SJonathan Doman // Set the property, with handler to check error responses 10213cde86f1SJonathan Doman crow::connections::systemBus->async_method_call( 10225e7e2dc5SEd Tanous [resp, appliedConfigUri](const boost::system::error_code& ec, 102359d494eeSPatrick Williams const sdbusplus::message_t& msg) { 10243cde86f1SJonathan Doman handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg); 10253cde86f1SJonathan Doman }, 10263cde86f1SJonathan Doman *controlService, cpuObjectPath, "org.freedesktop.DBus.Properties", 10273cde86f1SJonathan Doman "Set", "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 1028168e20c1SEd Tanous "AppliedConfig", dbus::utility::DbusVariantType(std::move(configPath))); 10293cde86f1SJonathan Doman } 10303cde86f1SJonathan Doman 103171a24ca4SNikhil Namjoshi inline void handleProcessorHead(crow::App& app, const crow::Request& req, 103271a24ca4SNikhil Namjoshi const std::shared_ptr<bmcweb::AsyncResp>& aResp, 103371a24ca4SNikhil Namjoshi const std::string& /* systemName */, 103471a24ca4SNikhil Namjoshi const std::string& /* processorId */) 103571a24ca4SNikhil Namjoshi { 103671a24ca4SNikhil Namjoshi if (!redfish::setUpRedfishRoute(app, req, aResp)) 103771a24ca4SNikhil Namjoshi { 103871a24ca4SNikhil Namjoshi return; 103971a24ca4SNikhil Namjoshi } 104071a24ca4SNikhil Namjoshi aResp->res.addHeader( 104171a24ca4SNikhil Namjoshi boost::beast::http::field::link, 104271a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); 104371a24ca4SNikhil Namjoshi } 104471a24ca4SNikhil Namjoshi 104571a24ca4SNikhil Namjoshi inline void handleProcessorCollectionHead( 104671a24ca4SNikhil Namjoshi crow::App& app, const crow::Request& req, 104771a24ca4SNikhil Namjoshi const std::shared_ptr<bmcweb::AsyncResp>& aResp, 104871a24ca4SNikhil Namjoshi const std::string& /* systemName */) 104971a24ca4SNikhil Namjoshi { 105071a24ca4SNikhil Namjoshi if (!redfish::setUpRedfishRoute(app, req, aResp)) 105171a24ca4SNikhil Namjoshi { 105271a24ca4SNikhil Namjoshi return; 105371a24ca4SNikhil Namjoshi } 105471a24ca4SNikhil Namjoshi aResp->res.addHeader( 105571a24ca4SNikhil Namjoshi boost::beast::http::field::link, 105671a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); 105771a24ca4SNikhil Namjoshi } 105871a24ca4SNikhil Namjoshi 10597e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfigCollection(App& app) 1060dba0c291SJonathan Doman { 10617e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 10627e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/") 1063ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfigCollection) 1064002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1065002d39b4SEd Tanous [&app](const crow::Request& req, 106645ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 10677e860f15SJohn Edward Broadbent const std::string& cpuName) { 10683ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 106945ca1b86SEd Tanous { 107045ca1b86SEd Tanous return; 107145ca1b86SEd Tanous } 10728d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1073dba0c291SJonathan Doman "#OperatingConfigCollection.OperatingConfigCollection"; 107439662a3bSEd Tanous asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( 107539662a3bSEd Tanous "redfish", "v1", "Systems", "system", "Processors", cpuName, 107639662a3bSEd Tanous "OperatingConfigs"); 10770fda0f12SGeorge Liu asyncResp->res.jsonValue["Name"] = "Operating Config Collection"; 1078dba0c291SJonathan Doman 10797e860f15SJohn Edward Broadbent // First find the matching CPU object so we know how to 10807e860f15SJohn Edward Broadbent // constrain our search for related Config objects. 10817a1dbc48SGeorge Liu const std::array<std::string_view, 1> interfaces = { 10827a1dbc48SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"}; 10837a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 10847a1dbc48SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 1085002d39b4SEd Tanous [asyncResp, cpuName]( 10867a1dbc48SGeorge Liu const boost::system::error_code& ec, 1087002d39b4SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& objects) { 1088dba0c291SJonathan Doman if (ec) 1089dba0c291SJonathan Doman { 1090dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 1091dba0c291SJonathan Doman << ec.message(); 1092dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1093dba0c291SJonathan Doman return; 1094dba0c291SJonathan Doman } 1095dba0c291SJonathan Doman 1096dba0c291SJonathan Doman for (const std::string& object : objects) 1097dba0c291SJonathan Doman { 109811ba3979SEd Tanous if (!object.ends_with(cpuName)) 1099dba0c291SJonathan Doman { 1100dba0c291SJonathan Doman continue; 1101dba0c291SJonathan Doman } 1102dba0c291SJonathan Doman 11037e860f15SJohn Edward Broadbent // Not expected that there will be multiple matching 11047e860f15SJohn Edward Broadbent // CPU objects, but if there are just use the first 11057e860f15SJohn Edward Broadbent // one. 1106dba0c291SJonathan Doman 11077e860f15SJohn Edward Broadbent // Use the common search routine to construct the 11087e860f15SJohn Edward Broadbent // Collection of all Config objects under this CPU. 11097a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interface { 11107a1dbc48SGeorge Liu "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig" 11117a1dbc48SGeorge Liu }; 1112dba0c291SJonathan Doman collection_util::getCollectionMembers( 1113dba0c291SJonathan Doman asyncResp, 1114ae9031f0SWilly Tu crow::utility::urlFromPieces("redfish", "v1", "Systems", 1115ae9031f0SWilly Tu "system", "Processors", 1116ae9031f0SWilly Tu cpuName, "OperatingConfigs"), 11177a1dbc48SGeorge Liu interface, object.c_str()); 1118dba0c291SJonathan Doman return; 1119dba0c291SJonathan Doman } 11207a1dbc48SGeorge Liu }); 11217e860f15SJohn Edward Broadbent }); 1122dba0c291SJonathan Doman } 1123dba0c291SJonathan Doman 11247e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfig(App& app) 1125dba0c291SJonathan Doman { 11267e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 11277e860f15SJohn Edward Broadbent app, 11287e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/<str>/") 1129ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfig) 1130002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1131002d39b4SEd Tanous [&app](const crow::Request& req, 113245ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1133002d39b4SEd Tanous const std::string& cpuName, const std::string& configName) { 11343ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 113545ca1b86SEd Tanous { 113645ca1b86SEd Tanous return; 113745ca1b86SEd Tanous } 11387e860f15SJohn Edward Broadbent // Ask for all objects implementing OperatingConfig so we can search 11397e860f15SJohn Edward Broadbent // for one with a matching name 1140e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1141e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}; 1142e99073f5SGeorge Liu dbus::utility::getSubTree( 1143e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 114439662a3bSEd Tanous [asyncResp, cpuName, configName]( 1145e99073f5SGeorge Liu const boost::system::error_code& ec, 11465df6eda2SShantappa Teekappanavar const dbus::utility::MapperGetSubTreeResponse& subtree) { 1147dba0c291SJonathan Doman if (ec) 1148dba0c291SJonathan Doman { 1149dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 1150dba0c291SJonathan Doman << ec.message(); 1151dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1152dba0c291SJonathan Doman return; 1153dba0c291SJonathan Doman } 1154002d39b4SEd Tanous const std::string expectedEnding = cpuName + '/' + configName; 1155dba0c291SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 1156dba0c291SJonathan Doman { 1157dba0c291SJonathan Doman // Ignore any configs without matching cpuX/configY 115811ba3979SEd Tanous if (!objectPath.ends_with(expectedEnding) || serviceMap.empty()) 1159dba0c291SJonathan Doman { 1160dba0c291SJonathan Doman continue; 1161dba0c291SJonathan Doman } 1162dba0c291SJonathan Doman 1163dba0c291SJonathan Doman nlohmann::json& json = asyncResp->res.jsonValue; 1164002d39b4SEd Tanous json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig"; 116539662a3bSEd Tanous json["@odata.id"] = crow::utility::urlFromPieces( 116639662a3bSEd Tanous "redfish", "v1", "Systems", "system", "Processors", cpuName, 116739662a3bSEd Tanous "OperatingConfigs", configName); 1168dba0c291SJonathan Doman json["Name"] = "Processor Profile"; 1169dba0c291SJonathan Doman json["Id"] = configName; 1170dba0c291SJonathan Doman 1171dba0c291SJonathan Doman // Just use the first implementation of the object - not 11727e860f15SJohn Edward Broadbent // expected that there would be multiple matching 11737e860f15SJohn Edward Broadbent // services 1174002d39b4SEd Tanous getOperatingConfigData(asyncResp, serviceMap.begin()->first, 1175002d39b4SEd Tanous objectPath); 1176dba0c291SJonathan Doman return; 1177dba0c291SJonathan Doman } 1178002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "OperatingConfig", 1179002d39b4SEd Tanous configName); 1180e99073f5SGeorge Liu }); 11817e860f15SJohn Edward Broadbent }); 1182ac6a4445SGunnar Mills } 1183ac6a4445SGunnar Mills 11847e860f15SJohn Edward Broadbent inline void requestRoutesProcessorCollection(App& app) 11857e860f15SJohn Edward Broadbent { 1186ac6a4445SGunnar Mills /** 1187ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1188ac6a4445SGunnar Mills */ 118922d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") 119071a24ca4SNikhil Namjoshi .privileges(redfish::privileges::headProcessorCollection) 119171a24ca4SNikhil Namjoshi .methods(boost::beast::http::verb::head)( 119271a24ca4SNikhil Namjoshi std::bind_front(handleProcessorCollectionHead, std::ref(app))); 119371a24ca4SNikhil Namjoshi 119471a24ca4SNikhil Namjoshi BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") 1195ed398213SEd Tanous .privileges(redfish::privileges::getProcessorCollection) 11967e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 119745ca1b86SEd Tanous [&app](const crow::Request& req, 119822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 119922d268cbSEd Tanous const std::string& systemName) { 12003ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 120145ca1b86SEd Tanous { 120245ca1b86SEd Tanous return; 120345ca1b86SEd Tanous } 120422d268cbSEd Tanous if (systemName != "system") 120522d268cbSEd Tanous { 120622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 120722d268cbSEd Tanous systemName); 120822d268cbSEd Tanous return; 120922d268cbSEd Tanous } 121022d268cbSEd Tanous 121171a24ca4SNikhil Namjoshi asyncResp->res.addHeader( 121271a24ca4SNikhil Namjoshi boost::beast::http::field::link, 121371a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/ProcessorCollection/ProcessorCollection.json>; rel=describedby"); 121471a24ca4SNikhil Namjoshi 12158d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1216ac6a4445SGunnar Mills "#ProcessorCollection.ProcessorCollection"; 12178d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Processor Collection"; 1218ac6a4445SGunnar Mills 12198d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = 12208d1b46d7Szhanghch05 "/redfish/v1/Systems/system/Processors"; 1221ac6a4445SGunnar Mills 122205030b8eSGunnar Mills collection_util::getCollectionMembers( 1223ae9031f0SWilly Tu asyncResp, 1224ae9031f0SWilly Tu boost::urls::url("/redfish/v1/Systems/system/Processors"), 12257a1dbc48SGeorge Liu processorInterfaces); 12267e860f15SJohn Edward Broadbent }); 1227ac6a4445SGunnar Mills } 1228ac6a4445SGunnar Mills 12297e860f15SJohn Edward Broadbent inline void requestRoutesProcessor(App& app) 12307e860f15SJohn Edward Broadbent { 1231ac6a4445SGunnar Mills /** 1232ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1233ac6a4445SGunnar Mills */ 12347e860f15SJohn Edward Broadbent 123522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 123671a24ca4SNikhil Namjoshi .privileges(redfish::privileges::headProcessor) 123771a24ca4SNikhil Namjoshi .methods(boost::beast::http::verb::head)( 123871a24ca4SNikhil Namjoshi std::bind_front(handleProcessorHead, std::ref(app))); 123971a24ca4SNikhil Namjoshi 124071a24ca4SNikhil Namjoshi BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 1241ed398213SEd Tanous .privileges(redfish::privileges::getProcessor) 12427e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 124345ca1b86SEd Tanous [&app](const crow::Request& req, 12447e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 124522d268cbSEd Tanous const std::string& systemName, 12467e860f15SJohn Edward Broadbent const std::string& processorId) { 12473ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 124845ca1b86SEd Tanous { 124945ca1b86SEd Tanous return; 125045ca1b86SEd Tanous } 125122d268cbSEd Tanous if (systemName != "system") 125222d268cbSEd Tanous { 125322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 125422d268cbSEd Tanous systemName); 125522d268cbSEd Tanous return; 125622d268cbSEd Tanous } 125722d268cbSEd Tanous 125871a24ca4SNikhil Namjoshi asyncResp->res.addHeader( 125971a24ca4SNikhil Namjoshi boost::beast::http::field::link, 126071a24ca4SNikhil Namjoshi "</redfish/v1/JsonSchemas/Processor/Processor.json>; rel=describedby"); 12618d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 12628d1b46d7Szhanghch05 "#Processor.v1_11_0.Processor"; 1263eddfc437SWilly Tu asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( 1264eddfc437SWilly Tu "redfish", "v1", "Systems", "system", "Processors", processorId); 1265ac6a4445SGunnar Mills 12668a592810SEd Tanous getProcessorObject( 12678a592810SEd Tanous asyncResp, processorId, 12688a592810SEd Tanous std::bind_front(getProcessorData, asyncResp, processorId)); 12697e860f15SJohn Edward Broadbent }); 12703cde86f1SJonathan Doman 127122d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 1272ed398213SEd Tanous .privileges(redfish::privileges::patchProcessor) 12737e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 127445ca1b86SEd Tanous [&app](const crow::Request& req, 12757e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 127622d268cbSEd Tanous const std::string& systemName, 12777e860f15SJohn Edward Broadbent const std::string& processorId) { 12783ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 127945ca1b86SEd Tanous { 128045ca1b86SEd Tanous return; 128145ca1b86SEd Tanous } 128222d268cbSEd Tanous if (systemName != "system") 128322d268cbSEd Tanous { 128422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 128522d268cbSEd Tanous systemName); 128622d268cbSEd Tanous return; 128722d268cbSEd Tanous } 128822d268cbSEd Tanous 12893cde86f1SJonathan Doman std::optional<nlohmann::json> appliedConfigJson; 129015ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, 12917e860f15SJohn Edward Broadbent "AppliedOperatingConfig", 12923cde86f1SJonathan Doman appliedConfigJson)) 12933cde86f1SJonathan Doman { 12943cde86f1SJonathan Doman return; 12953cde86f1SJonathan Doman } 12963cde86f1SJonathan Doman 12973cde86f1SJonathan Doman if (appliedConfigJson) 12983cde86f1SJonathan Doman { 1299f8fe53e7SEd Tanous std::string appliedConfigUri; 13003cde86f1SJonathan Doman if (!json_util::readJson(*appliedConfigJson, asyncResp->res, 13013cde86f1SJonathan Doman "@odata.id", appliedConfigUri)) 13023cde86f1SJonathan Doman { 13033cde86f1SJonathan Doman return; 13043cde86f1SJonathan Doman } 13057e860f15SJohn Edward Broadbent // Check for 404 and find matching D-Bus object, then run 13067e860f15SJohn Edward Broadbent // property patch handlers if that all succeeds. 13078a592810SEd Tanous getProcessorObject(asyncResp, processorId, 13088a592810SEd Tanous std::bind_front(patchAppliedOperatingConfig, 13097e860f15SJohn Edward Broadbent asyncResp, processorId, 13108a592810SEd Tanous appliedConfigUri)); 13113cde86f1SJonathan Doman } 13127e860f15SJohn Edward Broadbent }); 13133cde86f1SJonathan Doman } 1314ac6a4445SGunnar Mills 1315ac6a4445SGunnar Mills } // namespace redfish 1316