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 181e1e598dSJonathan Doman #include "dbus_singleton.hpp" 191e1e598dSJonathan Doman #include "error_messages.hpp" 20ac6a4445SGunnar Mills #include "health.hpp" 21ac6a4445SGunnar Mills 227e860f15SJohn Edward Broadbent #include <app.hpp> 23ac6a4445SGunnar Mills #include <boost/container/flat_map.hpp> 24168e20c1SEd Tanous #include <dbus_utility.hpp> 2545ca1b86SEd Tanous #include <query.hpp> 26ed398213SEd Tanous #include <registries/privilege_registry.hpp> 271e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 28dba0c291SJonathan Doman #include <sdbusplus/message/native_types.hpp> 29351053f2SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 30dba0c291SJonathan Doman #include <sdbusplus/utility/dedup_variant.hpp> 31ac6a4445SGunnar Mills #include <utils/collection.hpp> 32351053f2SKrzysztof Grobelny #include <utils/dbus_utils.hpp> 33ac6a4445SGunnar Mills #include <utils/json_utils.hpp> 34ac6a4445SGunnar Mills 35ac6a4445SGunnar Mills namespace redfish 36ac6a4445SGunnar Mills { 37ac6a4445SGunnar Mills 38c951448aSJonathan Doman // Interfaces which imply a D-Bus object represents a Processor 39c951448aSJonathan Doman constexpr std::array<const char*, 2> processorInterfaces = { 40c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu", 41c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Accelerator"}; 422bab9831SJonathan Doman 4371b82f26SSharad Yadav /** 4471b82f26SSharad Yadav * @brief Fill out uuid info of a processor by 4571b82f26SSharad Yadav * requesting data from the given D-Bus object. 4671b82f26SSharad Yadav * 4771b82f26SSharad Yadav * @param[in,out] aResp Async HTTP response. 4871b82f26SSharad Yadav * @param[in] service D-Bus service to query. 4971b82f26SSharad Yadav * @param[in] objPath D-Bus object to query. 5071b82f26SSharad Yadav */ 5171b82f26SSharad Yadav inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp, 5271b82f26SSharad Yadav const std::string& service, 5371b82f26SSharad Yadav const std::string& objPath) 5471b82f26SSharad Yadav { 5571b82f26SSharad Yadav BMCWEB_LOG_DEBUG << "Get Processor UUID"; 561e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 571e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 581e1e598dSJonathan Doman "xyz.openbmc_project.Common.UUID", "UUID", 591e1e598dSJonathan Doman [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec, 601e1e598dSJonathan Doman const std::string& property) { 6171b82f26SSharad Yadav if (ec) 6271b82f26SSharad Yadav { 6371b82f26SSharad Yadav BMCWEB_LOG_DEBUG << "DBUS response error"; 6471b82f26SSharad Yadav messages::internalError(aResp->res); 6571b82f26SSharad Yadav return; 6671b82f26SSharad Yadav } 671e1e598dSJonathan Doman aResp->res.jsonValue["UUID"] = property; 681e1e598dSJonathan Doman }); 6971b82f26SSharad Yadav } 7071b82f26SSharad Yadav 71711ac7a9SEd Tanous inline void getCpuDataByInterface( 72711ac7a9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aResp, 73711ac7a9SEd Tanous const dbus::utility::DBusInteracesMap& cpuInterfacesProperties) 74ac6a4445SGunnar Mills { 75ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; 76ac6a4445SGunnar Mills 77a1649ec6SChicago Duan // Set the default value of state 78a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["State"] = "Enabled"; 79a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["Health"] = "OK"; 80ac6a4445SGunnar Mills 81ac6a4445SGunnar Mills for (const auto& interface : cpuInterfacesProperties) 82ac6a4445SGunnar Mills { 83ac6a4445SGunnar Mills for (const auto& property : interface.second) 84ac6a4445SGunnar Mills { 85a1649ec6SChicago Duan if (property.first == "Present") 86ac6a4445SGunnar Mills { 87a1649ec6SChicago Duan const bool* cpuPresent = std::get_if<bool>(&property.second); 88a1649ec6SChicago Duan if (cpuPresent == nullptr) 89ac6a4445SGunnar Mills { 90ac6a4445SGunnar Mills // Important property not in desired type 91ac6a4445SGunnar Mills messages::internalError(aResp->res); 92ac6a4445SGunnar Mills return; 93ac6a4445SGunnar Mills } 94e05aec50SEd Tanous if (!*cpuPresent) 95ac6a4445SGunnar Mills { 96a1649ec6SChicago Duan // Slot is not populated 97ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Absent"; 98a1649ec6SChicago Duan } 99a1649ec6SChicago Duan } 100a1649ec6SChicago Duan else if (property.first == "Functional") 101a1649ec6SChicago Duan { 102a1649ec6SChicago Duan const bool* cpuFunctional = std::get_if<bool>(&property.second); 103a1649ec6SChicago Duan if (cpuFunctional == nullptr) 104a1649ec6SChicago Duan { 105a1649ec6SChicago Duan messages::internalError(aResp->res); 106ac6a4445SGunnar Mills return; 107ac6a4445SGunnar Mills } 108e05aec50SEd Tanous if (!*cpuFunctional) 109a1649ec6SChicago Duan { 110a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["Health"] = "Critical"; 111a1649ec6SChicago Duan } 112a1649ec6SChicago Duan } 113a1649ec6SChicago Duan else if (property.first == "CoreCount") 114a1649ec6SChicago Duan { 115a1649ec6SChicago Duan const uint16_t* coresCount = 116a1649ec6SChicago Duan std::get_if<uint16_t>(&property.second); 117a1649ec6SChicago Duan if (coresCount == nullptr) 118a1649ec6SChicago Duan { 119a1649ec6SChicago Duan messages::internalError(aResp->res); 120a1649ec6SChicago Duan return; 121a1649ec6SChicago Duan } 122ac6a4445SGunnar Mills aResp->res.jsonValue["TotalCores"] = *coresCount; 123ac6a4445SGunnar Mills } 124dc3fa667SJonathan Doman else if (property.first == "MaxSpeedInMhz") 125dc3fa667SJonathan Doman { 126dc3fa667SJonathan Doman const uint32_t* value = std::get_if<uint32_t>(&property.second); 127dc3fa667SJonathan Doman if (value != nullptr) 128dc3fa667SJonathan Doman { 129dc3fa667SJonathan Doman aResp->res.jsonValue["MaxSpeedMHz"] = *value; 130dc3fa667SJonathan Doman } 131dc3fa667SJonathan Doman } 132ac6a4445SGunnar Mills else if (property.first == "Socket") 133ac6a4445SGunnar Mills { 134ac6a4445SGunnar Mills const std::string* value = 135ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 136ac6a4445SGunnar Mills if (value != nullptr) 137ac6a4445SGunnar Mills { 138ac6a4445SGunnar Mills aResp->res.jsonValue["Socket"] = *value; 139ac6a4445SGunnar Mills } 140ac6a4445SGunnar Mills } 141ac6a4445SGunnar Mills else if (property.first == "ThreadCount") 142ac6a4445SGunnar Mills { 143dc3fa667SJonathan Doman const uint16_t* value = std::get_if<uint16_t>(&property.second); 144ac6a4445SGunnar Mills if (value != nullptr) 145ac6a4445SGunnar Mills { 146ac6a4445SGunnar Mills aResp->res.jsonValue["TotalThreads"] = *value; 147ac6a4445SGunnar Mills } 148ac6a4445SGunnar Mills } 1491930fbd4SBrandon Kim else if (property.first == "EffectiveFamily") 150ac6a4445SGunnar Mills { 1511930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1526169de2cSBrad Bishop if (value != nullptr && *value != 2) 153ac6a4445SGunnar Mills { 154ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] = 155866e4862SEd Tanous "0x" + intToHexString(*value, 4); 156ac6a4445SGunnar Mills } 157ac6a4445SGunnar Mills } 1581930fbd4SBrandon Kim else if (property.first == "EffectiveModel") 1591930fbd4SBrandon Kim { 1601930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1611930fbd4SBrandon Kim if (value == nullptr) 1621930fbd4SBrandon Kim { 1631930fbd4SBrandon Kim messages::internalError(aResp->res); 1641930fbd4SBrandon Kim return; 1651930fbd4SBrandon Kim } 1666169de2cSBrad Bishop if (*value != 0) 1676169de2cSBrad Bishop { 1681930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["EffectiveModel"] = 169866e4862SEd Tanous "0x" + intToHexString(*value, 4); 1701930fbd4SBrandon Kim } 1716169de2cSBrad Bishop } 172ac6a4445SGunnar Mills else if (property.first == "Id") 173ac6a4445SGunnar Mills { 174ac6a4445SGunnar Mills const uint64_t* value = std::get_if<uint64_t>(&property.second); 175ac6a4445SGunnar Mills if (value != nullptr && *value != 0) 176ac6a4445SGunnar Mills { 177ac6a4445SGunnar Mills aResp->res 178ac6a4445SGunnar Mills .jsonValue["ProcessorId"]["IdentificationRegisters"] = 179866e4862SEd Tanous "0x" + intToHexString(*value, 16); 180ac6a4445SGunnar Mills } 181ac6a4445SGunnar Mills } 1821930fbd4SBrandon Kim else if (property.first == "Microcode") 1831930fbd4SBrandon Kim { 1841930fbd4SBrandon Kim const uint32_t* value = std::get_if<uint32_t>(&property.second); 1851930fbd4SBrandon Kim if (value == nullptr) 1861930fbd4SBrandon Kim { 1871930fbd4SBrandon Kim messages::internalError(aResp->res); 1881930fbd4SBrandon Kim return; 1891930fbd4SBrandon Kim } 1906169de2cSBrad Bishop if (*value != 0) 1916169de2cSBrad Bishop { 1921930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] = 193866e4862SEd Tanous "0x" + intToHexString(*value, 8); 1941930fbd4SBrandon Kim } 1956169de2cSBrad Bishop } 1961930fbd4SBrandon Kim else if (property.first == "Step") 1971930fbd4SBrandon Kim { 1981930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1991930fbd4SBrandon Kim if (value == nullptr) 2001930fbd4SBrandon Kim { 2011930fbd4SBrandon Kim messages::internalError(aResp->res); 2021930fbd4SBrandon Kim return; 2031930fbd4SBrandon Kim } 2046169de2cSBrad Bishop if (*value != 0) 2056169de2cSBrad Bishop { 2061930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["Step"] = 207866e4862SEd Tanous "0x" + intToHexString(*value, 4); 2081930fbd4SBrandon Kim } 209ac6a4445SGunnar Mills } 210ac6a4445SGunnar Mills } 211ac6a4445SGunnar Mills } 2126169de2cSBrad Bishop } 213ac6a4445SGunnar Mills 2148d1b46d7Szhanghch05 inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, 215ac6a4445SGunnar Mills const std::string& cpuId, 216ac6a4445SGunnar Mills const std::string& service, 217ac6a4445SGunnar Mills const std::string& objPath) 218ac6a4445SGunnar Mills { 219ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; 220ac6a4445SGunnar Mills 221ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 222ac6a4445SGunnar Mills [cpuId, service, objPath, aResp{std::move(aResp)}]( 223ac6a4445SGunnar Mills const boost::system::error_code ec, 224ac6a4445SGunnar Mills const dbus::utility::ManagedObjectType& dbusData) { 225ac6a4445SGunnar Mills if (ec) 226ac6a4445SGunnar Mills { 227ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 228ac6a4445SGunnar Mills messages::internalError(aResp->res); 229ac6a4445SGunnar Mills return; 230ac6a4445SGunnar Mills } 231ac6a4445SGunnar Mills aResp->res.jsonValue["Id"] = cpuId; 232ac6a4445SGunnar Mills aResp->res.jsonValue["Name"] = "Processor"; 233ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorType"] = "CPU"; 234ac6a4445SGunnar Mills 235ac6a4445SGunnar Mills bool slotPresent = false; 236ac6a4445SGunnar Mills std::string corePath = objPath + "/core"; 237ac6a4445SGunnar Mills size_t totalCores = 0; 238ac6a4445SGunnar Mills for (const auto& object : dbusData) 239ac6a4445SGunnar Mills { 240ac6a4445SGunnar Mills if (object.first.str == objPath) 241ac6a4445SGunnar Mills { 242ac6a4445SGunnar Mills getCpuDataByInterface(aResp, object.second); 243ac6a4445SGunnar Mills } 24411ba3979SEd Tanous else if (object.first.str.starts_with(corePath)) 245ac6a4445SGunnar Mills { 246ac6a4445SGunnar Mills for (const auto& interface : object.second) 247ac6a4445SGunnar Mills { 248002d39b4SEd Tanous if (interface.first == "xyz.openbmc_project.Inventory.Item") 249ac6a4445SGunnar Mills { 250ac6a4445SGunnar Mills for (const auto& property : interface.second) 251ac6a4445SGunnar Mills { 252ac6a4445SGunnar Mills if (property.first == "Present") 253ac6a4445SGunnar Mills { 254ac6a4445SGunnar Mills const bool* present = 255ac6a4445SGunnar Mills std::get_if<bool>(&property.second); 256ac6a4445SGunnar Mills if (present != nullptr) 257ac6a4445SGunnar Mills { 258e05aec50SEd Tanous if (*present) 259ac6a4445SGunnar Mills { 260ac6a4445SGunnar Mills slotPresent = true; 261ac6a4445SGunnar Mills totalCores++; 262ac6a4445SGunnar Mills } 263ac6a4445SGunnar Mills } 264ac6a4445SGunnar Mills } 265ac6a4445SGunnar Mills } 266ac6a4445SGunnar Mills } 267ac6a4445SGunnar Mills } 268ac6a4445SGunnar Mills } 269ac6a4445SGunnar Mills } 270ac6a4445SGunnar Mills // In getCpuDataByInterface(), state and health are set 271ac6a4445SGunnar Mills // based on the present and functional status. If core 272ac6a4445SGunnar Mills // count is zero, then it has a higher precedence. 273ac6a4445SGunnar Mills if (slotPresent) 274ac6a4445SGunnar Mills { 275ac6a4445SGunnar Mills if (totalCores == 0) 276ac6a4445SGunnar Mills { 277ac6a4445SGunnar Mills // Slot is not populated, set status end return 278ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Absent"; 279ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["Health"] = "OK"; 280ac6a4445SGunnar Mills } 281ac6a4445SGunnar Mills aResp->res.jsonValue["TotalCores"] = totalCores; 282ac6a4445SGunnar Mills } 283ac6a4445SGunnar Mills return; 284ac6a4445SGunnar Mills }, 285ac6a4445SGunnar Mills service, "/xyz/openbmc_project/inventory", 286ac6a4445SGunnar Mills "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 287ac6a4445SGunnar Mills } 288ac6a4445SGunnar Mills 2898d1b46d7Szhanghch05 inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> aResp, 290ac6a4445SGunnar Mills const std::string& service, 291ac6a4445SGunnar Mills const std::string& objPath) 292ac6a4445SGunnar Mills { 293ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get Cpu Asset Data"; 294351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 295351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 296351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 297ac6a4445SGunnar Mills [objPath, aResp{std::move(aResp)}]( 298ac6a4445SGunnar Mills const boost::system::error_code ec, 299351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 300ac6a4445SGunnar Mills if (ec) 301ac6a4445SGunnar Mills { 302ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 303ac6a4445SGunnar Mills messages::internalError(aResp->res); 304ac6a4445SGunnar Mills return; 305ac6a4445SGunnar Mills } 306ac6a4445SGunnar Mills 307351053f2SKrzysztof Grobelny const std::string* serialNumber = nullptr; 308351053f2SKrzysztof Grobelny const std::string* model = nullptr; 309351053f2SKrzysztof Grobelny const std::string* manufacturer = nullptr; 310351053f2SKrzysztof Grobelny const std::string* partNumber = nullptr; 311351053f2SKrzysztof Grobelny const std::string* sparePartNumber = nullptr; 312351053f2SKrzysztof Grobelny 313351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 314351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "SerialNumber", 315351053f2SKrzysztof Grobelny serialNumber, "Model", model, "Manufacturer", manufacturer, 316351053f2SKrzysztof Grobelny "PartNumber", partNumber, "SparePartNumber", sparePartNumber); 317351053f2SKrzysztof Grobelny 318351053f2SKrzysztof Grobelny if (!success) 319ac6a4445SGunnar Mills { 320351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 321351053f2SKrzysztof Grobelny return; 322ac6a4445SGunnar Mills } 323351053f2SKrzysztof Grobelny 324351053f2SKrzysztof Grobelny if (serialNumber != nullptr && !serialNumber->empty()) 325ac6a4445SGunnar Mills { 326351053f2SKrzysztof Grobelny aResp->res.jsonValue["SerialNumber"] = *serialNumber; 327351053f2SKrzysztof Grobelny } 328351053f2SKrzysztof Grobelny 329351053f2SKrzysztof Grobelny if ((model != nullptr) && !model->empty()) 330ac6a4445SGunnar Mills { 331ac6a4445SGunnar Mills aResp->res.jsonValue["Model"] = *model; 332ac6a4445SGunnar Mills } 333ac6a4445SGunnar Mills 334351053f2SKrzysztof Grobelny if (manufacturer != nullptr) 335ac6a4445SGunnar Mills { 336351053f2SKrzysztof Grobelny aResp->res.jsonValue["Manufacturer"] = *manufacturer; 337ac6a4445SGunnar Mills 338ac6a4445SGunnar Mills // Otherwise would be unexpected. 339351053f2SKrzysztof Grobelny if (manufacturer->find("Intel") != std::string::npos) 340ac6a4445SGunnar Mills { 341002d39b4SEd Tanous aResp->res.jsonValue["ProcessorArchitecture"] = "x86"; 342ac6a4445SGunnar Mills aResp->res.jsonValue["InstructionSet"] = "x86-64"; 343ac6a4445SGunnar Mills } 344351053f2SKrzysztof Grobelny else if (manufacturer->find("IBM") != std::string::npos) 345ac6a4445SGunnar Mills { 346002d39b4SEd Tanous aResp->res.jsonValue["ProcessorArchitecture"] = "Power"; 347ac6a4445SGunnar Mills aResp->res.jsonValue["InstructionSet"] = "PowerISA"; 348ac6a4445SGunnar Mills } 349ac6a4445SGunnar Mills } 350cba4f448SSunnySrivastava1984 351351053f2SKrzysztof Grobelny if (partNumber != nullptr) 352cba4f448SSunnySrivastava1984 { 353cba4f448SSunnySrivastava1984 aResp->res.jsonValue["PartNumber"] = *partNumber; 354cba4f448SSunnySrivastava1984 } 355cba4f448SSunnySrivastava1984 3566169de2cSBrad Bishop if (sparePartNumber != nullptr && !sparePartNumber->empty()) 357cba4f448SSunnySrivastava1984 { 358cba4f448SSunnySrivastava1984 aResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; 359cba4f448SSunnySrivastava1984 } 360351053f2SKrzysztof Grobelny }); 361ac6a4445SGunnar Mills } 362ac6a4445SGunnar Mills 3638d1b46d7Szhanghch05 inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> aResp, 364ac6a4445SGunnar Mills const std::string& service, 365ac6a4445SGunnar Mills const std::string& objPath) 366ac6a4445SGunnar Mills { 367ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get Cpu Revision Data"; 368351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 369351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 370351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Revision", 371ac6a4445SGunnar Mills [objPath, aResp{std::move(aResp)}]( 372ac6a4445SGunnar Mills const boost::system::error_code ec, 373351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 374ac6a4445SGunnar Mills if (ec) 375ac6a4445SGunnar Mills { 376ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 377ac6a4445SGunnar Mills messages::internalError(aResp->res); 378ac6a4445SGunnar Mills return; 379ac6a4445SGunnar Mills } 380ac6a4445SGunnar Mills 381351053f2SKrzysztof Grobelny const std::string* version = nullptr; 382351053f2SKrzysztof Grobelny 383351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 384351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Version", version); 385351053f2SKrzysztof Grobelny 386351053f2SKrzysztof Grobelny if (!success) 387ac6a4445SGunnar Mills { 388351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 389351053f2SKrzysztof Grobelny return; 390351053f2SKrzysztof Grobelny } 391351053f2SKrzysztof Grobelny 392351053f2SKrzysztof Grobelny if (version != nullptr) 393ac6a4445SGunnar Mills { 394351053f2SKrzysztof Grobelny aResp->res.jsonValue["Version"] = *version; 395ac6a4445SGunnar Mills } 396351053f2SKrzysztof Grobelny }); 397ac6a4445SGunnar Mills } 398ac6a4445SGunnar Mills 3998d1b46d7Szhanghch05 inline void getAcceleratorDataByService( 4008d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> aResp, const std::string& acclrtrId, 4018d1b46d7Szhanghch05 const std::string& service, const std::string& objPath) 402ac6a4445SGunnar Mills { 403ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG 404ac6a4445SGunnar Mills << "Get available system Accelerator resources by service."; 405351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 406351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, "", 407ac6a4445SGunnar Mills [acclrtrId, aResp{std::move(aResp)}]( 408ac6a4445SGunnar Mills const boost::system::error_code ec, 409351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 410ac6a4445SGunnar Mills if (ec) 411ac6a4445SGunnar Mills { 412ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 413ac6a4445SGunnar Mills messages::internalError(aResp->res); 414ac6a4445SGunnar Mills return; 415ac6a4445SGunnar Mills } 416ac6a4445SGunnar Mills 417351053f2SKrzysztof Grobelny const bool* functional = nullptr; 418351053f2SKrzysztof Grobelny const bool* present = nullptr; 419351053f2SKrzysztof Grobelny 420351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 421351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Functional", 422351053f2SKrzysztof Grobelny functional, "Present", present); 423351053f2SKrzysztof Grobelny 424351053f2SKrzysztof Grobelny if (!success) 425ac6a4445SGunnar Mills { 426351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 427351053f2SKrzysztof Grobelny return; 428ac6a4445SGunnar Mills } 429ac6a4445SGunnar Mills 430ac6a4445SGunnar Mills std::string state = "Enabled"; 431ac6a4445SGunnar Mills std::string health = "OK"; 432ac6a4445SGunnar Mills 433351053f2SKrzysztof Grobelny if (present != nullptr && !*present) 434ac6a4445SGunnar Mills { 435ac6a4445SGunnar Mills state = "Absent"; 436ac6a4445SGunnar Mills } 437ac6a4445SGunnar Mills 438351053f2SKrzysztof Grobelny if (functional != nullptr && !*functional) 439ac6a4445SGunnar Mills { 440ac6a4445SGunnar Mills if (state == "Enabled") 441ac6a4445SGunnar Mills { 442ac6a4445SGunnar Mills health = "Critical"; 443ac6a4445SGunnar Mills } 444ac6a4445SGunnar Mills } 445ac6a4445SGunnar Mills 446351053f2SKrzysztof Grobelny aResp->res.jsonValue["Id"] = acclrtrId; 447351053f2SKrzysztof Grobelny aResp->res.jsonValue["Name"] = "Processor"; 448ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = state; 449ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["Health"] = health; 450ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorType"] = "Accelerator"; 451351053f2SKrzysztof Grobelny }); 452ac6a4445SGunnar Mills } 453ac6a4445SGunnar Mills 454dba0c291SJonathan Doman // OperatingConfig D-Bus Types 455dba0c291SJonathan Doman using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>; 456dba0c291SJonathan Doman using BaseSpeedPrioritySettingsProperty = 457dba0c291SJonathan Doman std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>; 458dba0c291SJonathan Doman // uint32_t and size_t may or may not be the same type, requiring a dedup'd 459dba0c291SJonathan Doman // variant 460dba0c291SJonathan Doman 461dba0c291SJonathan Doman /** 462dba0c291SJonathan Doman * Fill out the HighSpeedCoreIDs in a Processor resource from the given 463dba0c291SJonathan Doman * OperatingConfig D-Bus property. 464dba0c291SJonathan Doman * 465dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 466dba0c291SJonathan Doman * @param[in] baseSpeedSettings Full list of base speed priority groups, 467dba0c291SJonathan Doman * to use to determine the list of high 468dba0c291SJonathan Doman * speed cores. 469dba0c291SJonathan Doman */ 470dba0c291SJonathan Doman inline void highSpeedCoreIdsHandler( 4718d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 472dba0c291SJonathan Doman const BaseSpeedPrioritySettingsProperty& baseSpeedSettings) 473dba0c291SJonathan Doman { 474dba0c291SJonathan Doman // The D-Bus property does not indicate which bucket is the "high 475dba0c291SJonathan Doman // priority" group, so let's discern that by looking for the one with 476dba0c291SJonathan Doman // highest base frequency. 477dba0c291SJonathan Doman auto highPriorityGroup = baseSpeedSettings.cend(); 478dba0c291SJonathan Doman uint32_t highestBaseSpeed = 0; 479dba0c291SJonathan Doman for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend(); 480dba0c291SJonathan Doman ++it) 481dba0c291SJonathan Doman { 482dba0c291SJonathan Doman const uint32_t baseFreq = std::get<uint32_t>(*it); 483dba0c291SJonathan Doman if (baseFreq > highestBaseSpeed) 484dba0c291SJonathan Doman { 485dba0c291SJonathan Doman highestBaseSpeed = baseFreq; 486dba0c291SJonathan Doman highPriorityGroup = it; 487dba0c291SJonathan Doman } 488dba0c291SJonathan Doman } 489dba0c291SJonathan Doman 490dba0c291SJonathan Doman nlohmann::json& jsonCoreIds = aResp->res.jsonValue["HighSpeedCoreIDs"]; 491dba0c291SJonathan Doman jsonCoreIds = nlohmann::json::array(); 492dba0c291SJonathan Doman 493dba0c291SJonathan Doman // There may not be any entries in the D-Bus property, so only populate 494dba0c291SJonathan Doman // if there was actually something there. 495dba0c291SJonathan Doman if (highPriorityGroup != baseSpeedSettings.cend()) 496dba0c291SJonathan Doman { 497dba0c291SJonathan Doman jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup); 498dba0c291SJonathan Doman } 499dba0c291SJonathan Doman } 500dba0c291SJonathan Doman 501dba0c291SJonathan Doman /** 502dba0c291SJonathan Doman * Fill out OperatingConfig related items in a Processor resource by requesting 503dba0c291SJonathan Doman * data from the given D-Bus object. 504dba0c291SJonathan Doman * 505dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 506dba0c291SJonathan Doman * @param[in] cpuId CPU D-Bus name. 507dba0c291SJonathan Doman * @param[in] service D-Bus service to query. 508dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 509dba0c291SJonathan Doman */ 5108d1b46d7Szhanghch05 inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 511dba0c291SJonathan Doman const std::string& cpuId, 512dba0c291SJonathan Doman const std::string& service, 513dba0c291SJonathan Doman const std::string& objPath) 514dba0c291SJonathan Doman { 515dba0c291SJonathan Doman BMCWEB_LOG_INFO << "Getting CPU operating configs for " << cpuId; 516dba0c291SJonathan Doman 517dba0c291SJonathan Doman // First, GetAll CurrentOperatingConfig properties on the object 518351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 519351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 520351053f2SKrzysztof Grobelny "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 521351053f2SKrzysztof Grobelny [aResp, cpuId, 522351053f2SKrzysztof Grobelny service](const boost::system::error_code ec, 523351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 524dba0c291SJonathan Doman if (ec) 525dba0c291SJonathan Doman { 526002d39b4SEd Tanous BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message(); 527dba0c291SJonathan Doman messages::internalError(aResp->res); 528dba0c291SJonathan Doman return; 529dba0c291SJonathan Doman } 530dba0c291SJonathan Doman 531dba0c291SJonathan Doman nlohmann::json& json = aResp->res.jsonValue; 532dba0c291SJonathan Doman 533351053f2SKrzysztof Grobelny const sdbusplus::message::object_path* appliedConfig = nullptr; 534351053f2SKrzysztof Grobelny const bool* baseSpeedPriorityEnabled = nullptr; 535351053f2SKrzysztof Grobelny 536351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 537351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "AppliedConfig", 538351053f2SKrzysztof Grobelny appliedConfig, "BaseSpeedPriorityEnabled", 539351053f2SKrzysztof Grobelny baseSpeedPriorityEnabled); 540351053f2SKrzysztof Grobelny 541351053f2SKrzysztof Grobelny if (!success) 542dba0c291SJonathan Doman { 543351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 544351053f2SKrzysztof Grobelny return; 545dba0c291SJonathan Doman } 546dba0c291SJonathan Doman 547351053f2SKrzysztof Grobelny if (appliedConfig != nullptr) 548351053f2SKrzysztof Grobelny { 549351053f2SKrzysztof Grobelny const std::string& dbusPath = appliedConfig->str; 550351053f2SKrzysztof Grobelny std::string uri = "/redfish/v1/Systems/system/Processors/" + cpuId + 551351053f2SKrzysztof Grobelny "/OperatingConfigs"; 5521476687dSEd Tanous nlohmann::json::object_t operatingConfig; 5531476687dSEd Tanous operatingConfig["@odata.id"] = uri; 5541476687dSEd Tanous json["OperatingConfigs"] = std::move(operatingConfig); 555dba0c291SJonathan Doman 556dba0c291SJonathan Doman // Reuse the D-Bus config object name for the Redfish 557dba0c291SJonathan Doman // URI 558dba0c291SJonathan Doman size_t baseNamePos = dbusPath.rfind('/'); 559dba0c291SJonathan Doman if (baseNamePos == std::string::npos || 560dba0c291SJonathan Doman baseNamePos == (dbusPath.size() - 1)) 561dba0c291SJonathan Doman { 562dba0c291SJonathan Doman // If the AppliedConfig was somehow not a valid path, 563dba0c291SJonathan Doman // skip adding any more properties, since everything 564dba0c291SJonathan Doman // else is tied to this applied config. 565dba0c291SJonathan Doman messages::internalError(aResp->res); 566351053f2SKrzysztof Grobelny return; 567dba0c291SJonathan Doman } 568dba0c291SJonathan Doman uri += '/'; 569dba0c291SJonathan Doman uri += dbusPath.substr(baseNamePos + 1); 5701476687dSEd Tanous nlohmann::json::object_t appliedOperatingConfig; 5711476687dSEd Tanous appliedOperatingConfig["@odata.id"] = uri; 572351053f2SKrzysztof Grobelny json["AppliedOperatingConfig"] = std::move(appliedOperatingConfig); 573dba0c291SJonathan Doman 574dba0c291SJonathan Doman // Once we found the current applied config, queue another 575dba0c291SJonathan Doman // request to read the base freq core ids out of that 576dba0c291SJonathan Doman // config. 577002d39b4SEd Tanous sdbusplus::asio::getProperty<BaseSpeedPrioritySettingsProperty>( 5781e1e598dSJonathan Doman *crow::connections::systemBus, service, dbusPath, 5791e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu." 5801e1e598dSJonathan Doman "OperatingConfig", 5811e1e598dSJonathan Doman "BaseSpeedPrioritySettings", 582351053f2SKrzysztof Grobelny [aResp]( 583351053f2SKrzysztof Grobelny const boost::system::error_code ec2, 584351053f2SKrzysztof Grobelny const BaseSpeedPrioritySettingsProperty& baseSpeedList) { 5858a592810SEd Tanous if (ec2) 586dba0c291SJonathan Doman { 587351053f2SKrzysztof Grobelny BMCWEB_LOG_WARNING << "D-Bus Property Get error: " << ec2; 588dba0c291SJonathan Doman messages::internalError(aResp->res); 589dba0c291SJonathan Doman return; 590dba0c291SJonathan Doman } 5911e1e598dSJonathan Doman 5921e1e598dSJonathan Doman highSpeedCoreIdsHandler(aResp, baseSpeedList); 5931e1e598dSJonathan Doman }); 594dba0c291SJonathan Doman } 595351053f2SKrzysztof Grobelny 596351053f2SKrzysztof Grobelny if (baseSpeedPriorityEnabled != nullptr) 597dba0c291SJonathan Doman { 598dba0c291SJonathan Doman json["BaseSpeedPriorityState"] = 599351053f2SKrzysztof Grobelny *baseSpeedPriorityEnabled ? "Enabled" : "Disabled"; 600dba0c291SJonathan Doman } 601351053f2SKrzysztof Grobelny }); 602dba0c291SJonathan Doman } 603dba0c291SJonathan Doman 604cba4f448SSunnySrivastava1984 /** 605cba4f448SSunnySrivastava1984 * @brief Fill out location info of a processor by 606cba4f448SSunnySrivastava1984 * requesting data from the given D-Bus object. 607cba4f448SSunnySrivastava1984 * 608cba4f448SSunnySrivastava1984 * @param[in,out] aResp Async HTTP response. 609cba4f448SSunnySrivastava1984 * @param[in] service D-Bus service to query. 610cba4f448SSunnySrivastava1984 * @param[in] objPath D-Bus object to query. 611cba4f448SSunnySrivastava1984 */ 6128d1b46d7Szhanghch05 inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp, 613cba4f448SSunnySrivastava1984 const std::string& service, 614cba4f448SSunnySrivastava1984 const std::string& objPath) 615cba4f448SSunnySrivastava1984 { 616cba4f448SSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Get Cpu Location Data"; 6171e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 6181e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 6191e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 6201e1e598dSJonathan Doman [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec, 6211e1e598dSJonathan Doman const std::string& property) { 622cba4f448SSunnySrivastava1984 if (ec) 623cba4f448SSunnySrivastava1984 { 624cba4f448SSunnySrivastava1984 BMCWEB_LOG_DEBUG << "DBUS response error"; 625cba4f448SSunnySrivastava1984 messages::internalError(aResp->res); 626cba4f448SSunnySrivastava1984 return; 627cba4f448SSunnySrivastava1984 } 628cba4f448SSunnySrivastava1984 629cba4f448SSunnySrivastava1984 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 6301e1e598dSJonathan Doman property; 6311e1e598dSJonathan Doman }); 632cba4f448SSunnySrivastava1984 } 633cba4f448SSunnySrivastava1984 634c951448aSJonathan Doman /** 63549e429caSJonathan Doman * Populate the unique identifier in a Processor resource by requesting data 63649e429caSJonathan Doman * from the given D-Bus object. 63749e429caSJonathan Doman * 63849e429caSJonathan Doman * @param[in,out] aResp Async HTTP response. 63949e429caSJonathan Doman * @param[in] service D-Bus service to query. 64049e429caSJonathan Doman * @param[in] objPath D-Bus object to query. 64149e429caSJonathan Doman */ 64249e429caSJonathan Doman inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 64349e429caSJonathan Doman const std::string& service, 64449e429caSJonathan Doman const std::string& objectPath) 64549e429caSJonathan Doman { 64649e429caSJonathan Doman BMCWEB_LOG_DEBUG << "Get CPU UniqueIdentifier"; 6471e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 6481e1e598dSJonathan Doman *crow::connections::systemBus, service, objectPath, 6491e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", 6501e1e598dSJonathan Doman "UniqueIdentifier", 6511e1e598dSJonathan Doman [aResp](boost::system::error_code ec, const std::string& id) { 6521e1e598dSJonathan Doman if (ec) 65349e429caSJonathan Doman { 65449e429caSJonathan Doman BMCWEB_LOG_ERROR << "Failed to read cpu unique id: " << ec; 65549e429caSJonathan Doman messages::internalError(aResp->res); 65649e429caSJonathan Doman return; 65749e429caSJonathan Doman } 658002d39b4SEd Tanous aResp->res.jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = 659002d39b4SEd Tanous id; 6601e1e598dSJonathan Doman }); 66149e429caSJonathan Doman } 66249e429caSJonathan Doman 66349e429caSJonathan Doman /** 664c951448aSJonathan Doman * Find the D-Bus object representing the requested Processor, and call the 665c951448aSJonathan Doman * handler with the results. If matching object is not found, add 404 error to 666c951448aSJonathan Doman * response and don't call the handler. 667c951448aSJonathan Doman * 668c951448aSJonathan Doman * @param[in,out] resp Async HTTP response. 669c951448aSJonathan Doman * @param[in] processorId Redfish Processor Id. 670c951448aSJonathan Doman * @param[in] handler Callback to continue processing request upon 671c951448aSJonathan Doman * successfully finding object. 672c951448aSJonathan Doman */ 673c951448aSJonathan Doman template <typename Handler> 6748d1b46d7Szhanghch05 inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp, 675c951448aSJonathan Doman const std::string& processorId, 676c951448aSJonathan Doman Handler&& handler) 677ac6a4445SGunnar Mills { 678ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get available system processor resources."; 679ac6a4445SGunnar Mills 680c951448aSJonathan Doman // GetSubTree on all interfaces which provide info about a Processor 681ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 682c951448aSJonathan Doman [resp, processorId, handler = std::forward<Handler>(handler)]( 683c951448aSJonathan Doman boost::system::error_code ec, 6845df6eda2SShantappa Teekappanavar const dbus::utility::MapperGetSubTreeResponse& subtree) mutable { 685ac6a4445SGunnar Mills if (ec) 686ac6a4445SGunnar Mills { 687c951448aSJonathan Doman BMCWEB_LOG_DEBUG << "DBUS response error: " << ec; 688c951448aSJonathan Doman messages::internalError(resp->res); 689ac6a4445SGunnar Mills return; 690ac6a4445SGunnar Mills } 6912bab9831SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 692ac6a4445SGunnar Mills { 6932bab9831SJonathan Doman // Ignore any objects which don't end with our desired cpu name 69411ba3979SEd Tanous if (!objectPath.ends_with(processorId)) 695ac6a4445SGunnar Mills { 6962bab9831SJonathan Doman continue; 697ac6a4445SGunnar Mills } 6982bab9831SJonathan Doman 699c951448aSJonathan Doman bool found = false; 700c951448aSJonathan Doman // Filter out objects that don't have the CPU-specific 701c951448aSJonathan Doman // interfaces to make sure we can return 404 on non-CPUs 702c951448aSJonathan Doman // (e.g. /redfish/../Processors/dimm0) 7032bab9831SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 704ac6a4445SGunnar Mills { 705c951448aSJonathan Doman if (std::find_first_of( 706c951448aSJonathan Doman interfaceList.begin(), interfaceList.end(), 707c951448aSJonathan Doman processorInterfaces.begin(), 708c951448aSJonathan Doman processorInterfaces.end()) != interfaceList.end()) 7092bab9831SJonathan Doman { 710c951448aSJonathan Doman found = true; 711c951448aSJonathan Doman break; 712c951448aSJonathan Doman } 713c951448aSJonathan Doman } 714c951448aSJonathan Doman 715c951448aSJonathan Doman if (!found) 7162bab9831SJonathan Doman { 717c951448aSJonathan Doman continue; 718ac6a4445SGunnar Mills } 719c951448aSJonathan Doman 720c951448aSJonathan Doman // Process the first object which does match our cpu name and 721c951448aSJonathan Doman // required interfaces, and potentially ignore any other 722c951448aSJonathan Doman // matching objects. Assume all interfaces we want to process 723c951448aSJonathan Doman // must be on the same object path. 724c951448aSJonathan Doman 7258a592810SEd Tanous handler(objectPath, serviceMap); 726ac6a4445SGunnar Mills return; 727ac6a4445SGunnar Mills } 728c951448aSJonathan Doman messages::resourceNotFound(resp->res, "Processor", processorId); 729ac6a4445SGunnar Mills }, 730ac6a4445SGunnar Mills "xyz.openbmc_project.ObjectMapper", 731ac6a4445SGunnar Mills "/xyz/openbmc_project/object_mapper", 732ac6a4445SGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 7332bab9831SJonathan Doman "/xyz/openbmc_project/inventory", 0, 73449e429caSJonathan Doman std::array<const char*, 8>{ 73571b82f26SSharad Yadav "xyz.openbmc_project.Common.UUID", 7362bab9831SJonathan Doman "xyz.openbmc_project.Inventory.Decorator.Asset", 7372bab9831SJonathan Doman "xyz.openbmc_project.Inventory.Decorator.Revision", 7382bab9831SJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu", 739cba4f448SSunnySrivastava1984 "xyz.openbmc_project.Inventory.Decorator.LocationCode", 740dba0c291SJonathan Doman "xyz.openbmc_project.Inventory.Item.Accelerator", 74149e429caSJonathan Doman "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 74249e429caSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier"}); 743ac6a4445SGunnar Mills } 744ac6a4445SGunnar Mills 7458d1b46d7Szhanghch05 inline void getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 746c951448aSJonathan Doman const std::string& processorId, 747c951448aSJonathan Doman const std::string& objectPath, 7485df6eda2SShantappa Teekappanavar const dbus::utility::MapperServiceMap& serviceMap) 749c951448aSJonathan Doman { 750c951448aSJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 751c951448aSJonathan Doman { 752c951448aSJonathan Doman for (const auto& interface : interfaceList) 753c951448aSJonathan Doman { 754c951448aSJonathan Doman if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") 755c951448aSJonathan Doman { 756c951448aSJonathan Doman getCpuAssetData(aResp, serviceName, objectPath); 757c951448aSJonathan Doman } 7580fda0f12SGeorge Liu else if (interface == 7590fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Revision") 760c951448aSJonathan Doman { 761c951448aSJonathan Doman getCpuRevisionData(aResp, serviceName, objectPath); 762c951448aSJonathan Doman } 763c951448aSJonathan Doman else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu") 764c951448aSJonathan Doman { 765c951448aSJonathan Doman getCpuDataByService(aResp, processorId, serviceName, 766c951448aSJonathan Doman objectPath); 767c951448aSJonathan Doman } 7680fda0f12SGeorge Liu else if (interface == 7690fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Accelerator") 770c951448aSJonathan Doman { 771c951448aSJonathan Doman getAcceleratorDataByService(aResp, processorId, serviceName, 772c951448aSJonathan Doman objectPath); 773c951448aSJonathan Doman } 7740fda0f12SGeorge Liu else if ( 7750fda0f12SGeorge Liu interface == 7760fda0f12SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig") 777c951448aSJonathan Doman { 778c951448aSJonathan Doman getCpuConfigData(aResp, processorId, serviceName, objectPath); 779c951448aSJonathan Doman } 7800fda0f12SGeorge Liu else if (interface == 7810fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 782c951448aSJonathan Doman { 783c951448aSJonathan Doman getCpuLocationCode(aResp, serviceName, objectPath); 784c951448aSJonathan Doman } 78571b82f26SSharad Yadav else if (interface == "xyz.openbmc_project.Common.UUID") 78671b82f26SSharad Yadav { 78771b82f26SSharad Yadav getProcessorUUID(aResp, serviceName, objectPath); 78871b82f26SSharad Yadav } 7890fda0f12SGeorge Liu else if (interface == 7900fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier") 79149e429caSJonathan Doman { 79249e429caSJonathan Doman getCpuUniqueId(aResp, serviceName, objectPath); 79349e429caSJonathan Doman } 794c951448aSJonathan Doman } 795c951448aSJonathan Doman } 796c951448aSJonathan Doman } 797c951448aSJonathan Doman 798dba0c291SJonathan Doman /** 799dba0c291SJonathan Doman * Request all the properties for the given D-Bus object and fill out the 800dba0c291SJonathan Doman * related entries in the Redfish OperatingConfig response. 801dba0c291SJonathan Doman * 802dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 803dba0c291SJonathan Doman * @param[in] service D-Bus service name to query. 804dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 805dba0c291SJonathan Doman */ 8068d1b46d7Szhanghch05 inline void 8078d1b46d7Szhanghch05 getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 808dba0c291SJonathan Doman const std::string& service, 809dba0c291SJonathan Doman const std::string& objPath) 810dba0c291SJonathan Doman { 811351053f2SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 812351053f2SKrzysztof Grobelny *crow::connections::systemBus, service, objPath, 813351053f2SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig", 814914e2d5dSEd Tanous [aResp](const boost::system::error_code ec, 815351053f2SKrzysztof Grobelny const dbus::utility::DBusPropertiesMap& properties) { 816dba0c291SJonathan Doman if (ec) 817dba0c291SJonathan Doman { 818002d39b4SEd Tanous BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message(); 819dba0c291SJonathan Doman messages::internalError(aResp->res); 820dba0c291SJonathan Doman return; 821dba0c291SJonathan Doman } 822dba0c291SJonathan Doman 823351053f2SKrzysztof Grobelny const size_t* availableCoreCount = nullptr; 824351053f2SKrzysztof Grobelny const uint32_t* baseSpeed = nullptr; 825351053f2SKrzysztof Grobelny const uint32_t* maxJunctionTemperature = nullptr; 826351053f2SKrzysztof Grobelny const uint32_t* maxSpeed = nullptr; 827351053f2SKrzysztof Grobelny const uint32_t* powerLimit = nullptr; 828351053f2SKrzysztof Grobelny const TurboProfileProperty* turboProfile = nullptr; 829351053f2SKrzysztof Grobelny const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings = 830351053f2SKrzysztof Grobelny nullptr; 831351053f2SKrzysztof Grobelny 832351053f2SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 833351053f2SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount", 834351053f2SKrzysztof Grobelny availableCoreCount, "BaseSpeed", baseSpeed, 835351053f2SKrzysztof Grobelny "MaxJunctionTemperature", maxJunctionTemperature, "MaxSpeed", 836351053f2SKrzysztof Grobelny maxSpeed, "PowerLimit", powerLimit, "TurboProfile", turboProfile, 837351053f2SKrzysztof Grobelny "BaseSpeedPrioritySettings", baseSpeedPrioritySettings); 838351053f2SKrzysztof Grobelny 839351053f2SKrzysztof Grobelny if (!success) 840dba0c291SJonathan Doman { 841351053f2SKrzysztof Grobelny messages::internalError(aResp->res); 842351053f2SKrzysztof Grobelny return; 843dba0c291SJonathan Doman } 844dba0c291SJonathan Doman 845351053f2SKrzysztof Grobelny nlohmann::json& json = aResp->res.jsonValue; 846351053f2SKrzysztof Grobelny 847351053f2SKrzysztof Grobelny if (availableCoreCount != nullptr) 848351053f2SKrzysztof Grobelny { 849351053f2SKrzysztof Grobelny json["TotalAvailableCoreCount"] = *availableCoreCount; 850351053f2SKrzysztof Grobelny } 851351053f2SKrzysztof Grobelny 852351053f2SKrzysztof Grobelny if (baseSpeed != nullptr) 853351053f2SKrzysztof Grobelny { 854351053f2SKrzysztof Grobelny json["BaseSpeedMHz"] = *baseSpeed; 855351053f2SKrzysztof Grobelny } 856351053f2SKrzysztof Grobelny 857351053f2SKrzysztof Grobelny if (maxJunctionTemperature != nullptr) 858351053f2SKrzysztof Grobelny { 859351053f2SKrzysztof Grobelny json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature; 860351053f2SKrzysztof Grobelny } 861351053f2SKrzysztof Grobelny 862351053f2SKrzysztof Grobelny if (maxSpeed != nullptr) 863351053f2SKrzysztof Grobelny { 864351053f2SKrzysztof Grobelny json["MaxSpeedMHz"] = *maxSpeed; 865351053f2SKrzysztof Grobelny } 866351053f2SKrzysztof Grobelny 867351053f2SKrzysztof Grobelny if (powerLimit != nullptr) 868351053f2SKrzysztof Grobelny { 869351053f2SKrzysztof Grobelny json["TDPWatts"] = *powerLimit; 870351053f2SKrzysztof Grobelny } 871351053f2SKrzysztof Grobelny 872351053f2SKrzysztof Grobelny if (turboProfile != nullptr) 873351053f2SKrzysztof Grobelny { 874dba0c291SJonathan Doman nlohmann::json& turboArray = json["TurboProfile"]; 875dba0c291SJonathan Doman turboArray = nlohmann::json::array(); 876351053f2SKrzysztof Grobelny for (const auto& [turboSpeed, coreCount] : *turboProfile) 877dba0c291SJonathan Doman { 8781476687dSEd Tanous nlohmann::json::object_t turbo; 8791476687dSEd Tanous turbo["ActiveCoreCount"] = coreCount; 8801476687dSEd Tanous turbo["MaxSpeedMHz"] = turboSpeed; 8811476687dSEd Tanous turboArray.push_back(std::move(turbo)); 882dba0c291SJonathan Doman } 883dba0c291SJonathan Doman } 884dba0c291SJonathan Doman 885351053f2SKrzysztof Grobelny if (baseSpeedPrioritySettings != nullptr) 886351053f2SKrzysztof Grobelny { 887351053f2SKrzysztof Grobelny nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"]; 888dba0c291SJonathan Doman baseSpeedArray = nlohmann::json::array(); 889351053f2SKrzysztof Grobelny for (const auto& [baseSpeedMhz, coreList] : 890351053f2SKrzysztof Grobelny *baseSpeedPrioritySettings) 891dba0c291SJonathan Doman { 8921476687dSEd Tanous nlohmann::json::object_t speed; 8931476687dSEd Tanous speed["CoreCount"] = coreList.size(); 8941476687dSEd Tanous speed["CoreIDs"] = coreList; 895351053f2SKrzysztof Grobelny speed["BaseSpeedMHz"] = baseSpeedMhz; 8961476687dSEd Tanous baseSpeedArray.push_back(std::move(speed)); 897dba0c291SJonathan Doman } 898dba0c291SJonathan Doman } 899351053f2SKrzysztof Grobelny }); 900dba0c291SJonathan Doman } 901dba0c291SJonathan Doman 9023cde86f1SJonathan Doman /** 9033cde86f1SJonathan Doman * Handle the D-Bus response from attempting to set the CPU's AppliedConfig 9043cde86f1SJonathan Doman * property. Main task is to translate error messages into Redfish errors. 9053cde86f1SJonathan Doman * 9063cde86f1SJonathan Doman * @param[in,out] resp HTTP response. 9073cde86f1SJonathan Doman * @param[in] setPropVal Value which we attempted to set. 9083cde86f1SJonathan Doman * @param[in] ec D-Bus response error code. 9093cde86f1SJonathan Doman * @param[in] msg D-Bus response message. 9103cde86f1SJonathan Doman */ 9113cde86f1SJonathan Doman inline void 9123cde86f1SJonathan Doman handleAppliedConfigResponse(const std::shared_ptr<bmcweb::AsyncResp>& resp, 9133cde86f1SJonathan Doman const std::string& setPropVal, 9143cde86f1SJonathan Doman boost::system::error_code ec, 91559d494eeSPatrick Williams const sdbusplus::message_t& msg) 9163cde86f1SJonathan Doman { 9173cde86f1SJonathan Doman if (!ec) 9183cde86f1SJonathan Doman { 9193cde86f1SJonathan Doman BMCWEB_LOG_DEBUG << "Set Property succeeded"; 9203cde86f1SJonathan Doman return; 9213cde86f1SJonathan Doman } 9223cde86f1SJonathan Doman 9233cde86f1SJonathan Doman BMCWEB_LOG_DEBUG << "Set Property failed: " << ec; 9243cde86f1SJonathan Doman 9253cde86f1SJonathan Doman const sd_bus_error* dbusError = msg.get_error(); 9263cde86f1SJonathan Doman if (dbusError == nullptr) 9273cde86f1SJonathan Doman { 9283cde86f1SJonathan Doman messages::internalError(resp->res); 9293cde86f1SJonathan Doman return; 9303cde86f1SJonathan Doman } 9313cde86f1SJonathan Doman 9323cde86f1SJonathan Doman // The asio error code doesn't know about our custom errors, so we have to 9333cde86f1SJonathan Doman // parse the error string. Some of these D-Bus -> Redfish translations are a 9343cde86f1SJonathan Doman // stretch, but it's good to try to communicate something vaguely useful. 9353cde86f1SJonathan Doman if (strcmp(dbusError->name, 9363cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.InvalidArgument") == 0) 9373cde86f1SJonathan Doman { 9383cde86f1SJonathan Doman // Service did not like the object_path we tried to set. 9393cde86f1SJonathan Doman messages::propertyValueIncorrect( 9403cde86f1SJonathan Doman resp->res, "AppliedOperatingConfig/@odata.id", setPropVal); 9413cde86f1SJonathan Doman } 9423cde86f1SJonathan Doman else if (strcmp(dbusError->name, 9433cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.NotAllowed") == 0) 9443cde86f1SJonathan Doman { 9453cde86f1SJonathan Doman // Service indicates we can never change the config for this processor. 9463cde86f1SJonathan Doman messages::propertyNotWritable(resp->res, "AppliedOperatingConfig"); 9473cde86f1SJonathan Doman } 9483cde86f1SJonathan Doman else if (strcmp(dbusError->name, 9493cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.Unavailable") == 0) 9503cde86f1SJonathan Doman { 9513cde86f1SJonathan Doman // Service indicates the config cannot be changed right now, but maybe 9523cde86f1SJonathan Doman // in a different system state. 9533cde86f1SJonathan Doman messages::resourceInStandby(resp->res); 9543cde86f1SJonathan Doman } 9553cde86f1SJonathan Doman else 9563cde86f1SJonathan Doman { 9573cde86f1SJonathan Doman messages::internalError(resp->res); 9583cde86f1SJonathan Doman } 9593cde86f1SJonathan Doman } 9603cde86f1SJonathan Doman 9613cde86f1SJonathan Doman /** 9623cde86f1SJonathan Doman * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic 9633cde86f1SJonathan Doman * validation of the input data, and then set the D-Bus property. 9643cde86f1SJonathan Doman * 9653cde86f1SJonathan Doman * @param[in,out] resp Async HTTP response. 9663cde86f1SJonathan Doman * @param[in] processorId Processor's Id. 9673cde86f1SJonathan Doman * @param[in] appliedConfigUri New property value to apply. 9683cde86f1SJonathan Doman * @param[in] cpuObjectPath Path of CPU object to modify. 9693cde86f1SJonathan Doman * @param[in] serviceMap Service map for CPU object. 9703cde86f1SJonathan Doman */ 9713cde86f1SJonathan Doman inline void patchAppliedOperatingConfig( 9723cde86f1SJonathan Doman const std::shared_ptr<bmcweb::AsyncResp>& resp, 9733cde86f1SJonathan Doman const std::string& processorId, const std::string& appliedConfigUri, 9745df6eda2SShantappa Teekappanavar const std::string& cpuObjectPath, 9755df6eda2SShantappa Teekappanavar const dbus::utility::MapperServiceMap& serviceMap) 9763cde86f1SJonathan Doman { 9773cde86f1SJonathan Doman // Check that the property even exists by checking for the interface 9783cde86f1SJonathan Doman const std::string* controlService = nullptr; 9793cde86f1SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 9803cde86f1SJonathan Doman { 9813cde86f1SJonathan Doman if (std::find(interfaceList.begin(), interfaceList.end(), 9823cde86f1SJonathan Doman "xyz.openbmc_project.Control.Processor." 9833cde86f1SJonathan Doman "CurrentOperatingConfig") != interfaceList.end()) 9843cde86f1SJonathan Doman { 9853cde86f1SJonathan Doman controlService = &serviceName; 9863cde86f1SJonathan Doman break; 9873cde86f1SJonathan Doman } 9883cde86f1SJonathan Doman } 9893cde86f1SJonathan Doman 9903cde86f1SJonathan Doman if (controlService == nullptr) 9913cde86f1SJonathan Doman { 9923cde86f1SJonathan Doman messages::internalError(resp->res); 9933cde86f1SJonathan Doman return; 9943cde86f1SJonathan Doman } 9953cde86f1SJonathan Doman 9963cde86f1SJonathan Doman // Check that the config URI is a child of the cpu URI being patched. 9973cde86f1SJonathan Doman std::string expectedPrefix("/redfish/v1/Systems/system/Processors/"); 9983cde86f1SJonathan Doman expectedPrefix += processorId; 9993cde86f1SJonathan Doman expectedPrefix += "/OperatingConfigs/"; 100011ba3979SEd Tanous if (!appliedConfigUri.starts_with(expectedPrefix) || 10013cde86f1SJonathan Doman expectedPrefix.size() == appliedConfigUri.size()) 10023cde86f1SJonathan Doman { 10033cde86f1SJonathan Doman messages::propertyValueIncorrect( 10043cde86f1SJonathan Doman resp->res, "AppliedOperatingConfig/@odata.id", appliedConfigUri); 10053cde86f1SJonathan Doman return; 10063cde86f1SJonathan Doman } 10073cde86f1SJonathan Doman 10083cde86f1SJonathan Doman // Generate the D-Bus path of the OperatingConfig object, by assuming it's a 10093cde86f1SJonathan Doman // direct child of the CPU object. 10103cde86f1SJonathan Doman // Strip the expectedPrefix from the config URI to get the "filename", and 10113cde86f1SJonathan Doman // append to the CPU's path. 10123cde86f1SJonathan Doman std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size()); 10133cde86f1SJonathan Doman sdbusplus::message::object_path configPath(cpuObjectPath); 10143cde86f1SJonathan Doman configPath /= configBaseName; 10153cde86f1SJonathan Doman 10163cde86f1SJonathan Doman BMCWEB_LOG_INFO << "Setting config to " << configPath.str; 10173cde86f1SJonathan Doman 10183cde86f1SJonathan Doman // Set the property, with handler to check error responses 10193cde86f1SJonathan Doman crow::connections::systemBus->async_method_call( 1020914e2d5dSEd Tanous [resp, appliedConfigUri](const boost::system::error_code ec, 102159d494eeSPatrick Williams const sdbusplus::message_t& msg) { 10223cde86f1SJonathan Doman handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg); 10233cde86f1SJonathan Doman }, 10243cde86f1SJonathan Doman *controlService, cpuObjectPath, "org.freedesktop.DBus.Properties", 10253cde86f1SJonathan Doman "Set", "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 1026168e20c1SEd Tanous "AppliedConfig", dbus::utility::DbusVariantType(std::move(configPath))); 10273cde86f1SJonathan Doman } 10283cde86f1SJonathan Doman 10297e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfigCollection(App& app) 1030dba0c291SJonathan Doman { 1031dba0c291SJonathan Doman 10327e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 10337e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/") 1034ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfigCollection) 1035002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1036002d39b4SEd Tanous [&app](const crow::Request& req, 103745ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 10387e860f15SJohn Edward Broadbent const std::string& cpuName) { 10393ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 104045ca1b86SEd Tanous { 104145ca1b86SEd Tanous return; 104245ca1b86SEd Tanous } 10438d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1044dba0c291SJonathan Doman "#OperatingConfigCollection.OperatingConfigCollection"; 10458d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = req.url; 10460fda0f12SGeorge Liu asyncResp->res.jsonValue["Name"] = "Operating Config Collection"; 1047dba0c291SJonathan Doman 10487e860f15SJohn Edward Broadbent // First find the matching CPU object so we know how to 10497e860f15SJohn Edward Broadbent // constrain our search for related Config objects. 1050dba0c291SJonathan Doman crow::connections::systemBus->async_method_call( 1051002d39b4SEd Tanous [asyncResp, cpuName]( 1052002d39b4SEd Tanous const boost::system::error_code ec, 1053002d39b4SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& objects) { 1054dba0c291SJonathan Doman if (ec) 1055dba0c291SJonathan Doman { 1056dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 1057dba0c291SJonathan Doman << ec.message(); 1058dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1059dba0c291SJonathan Doman return; 1060dba0c291SJonathan Doman } 1061dba0c291SJonathan Doman 1062dba0c291SJonathan Doman for (const std::string& object : objects) 1063dba0c291SJonathan Doman { 106411ba3979SEd Tanous if (!object.ends_with(cpuName)) 1065dba0c291SJonathan Doman { 1066dba0c291SJonathan Doman continue; 1067dba0c291SJonathan Doman } 1068dba0c291SJonathan Doman 10697e860f15SJohn Edward Broadbent // Not expected that there will be multiple matching 10707e860f15SJohn Edward Broadbent // CPU objects, but if there are just use the first 10717e860f15SJohn Edward Broadbent // one. 1072dba0c291SJonathan Doman 10737e860f15SJohn Edward Broadbent // Use the common search routine to construct the 10747e860f15SJohn Edward Broadbent // Collection of all Config objects under this CPU. 1075dba0c291SJonathan Doman collection_util::getCollectionMembers( 1076dba0c291SJonathan Doman asyncResp, 1077*ae9031f0SWilly Tu crow::utility::urlFromPieces("redfish", "v1", "Systems", 1078*ae9031f0SWilly Tu "system", "Processors", 1079*ae9031f0SWilly Tu cpuName, "OperatingConfigs"), 10800fda0f12SGeorge Liu {"xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}, 1081dba0c291SJonathan Doman object.c_str()); 1082dba0c291SJonathan Doman return; 1083dba0c291SJonathan Doman } 1084dba0c291SJonathan Doman }, 1085dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", 1086dba0c291SJonathan Doman "/xyz/openbmc_project/object_mapper", 1087dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 1088dba0c291SJonathan Doman "/xyz/openbmc_project/inventory", 0, 10897e860f15SJohn Edward Broadbent std::array<const char*, 1>{ 10900fda0f12SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"}); 10917e860f15SJohn Edward Broadbent }); 1092dba0c291SJonathan Doman } 1093dba0c291SJonathan Doman 10947e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfig(App& app) 1095dba0c291SJonathan Doman { 10967e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 10977e860f15SJohn Edward Broadbent app, 10987e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/<str>/") 1099ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfig) 1100002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1101002d39b4SEd Tanous [&app](const crow::Request& req, 110245ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1103002d39b4SEd Tanous const std::string& cpuName, const std::string& configName) { 11043ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 110545ca1b86SEd Tanous { 110645ca1b86SEd Tanous return; 110745ca1b86SEd Tanous } 11087e860f15SJohn Edward Broadbent // Ask for all objects implementing OperatingConfig so we can search 11097e860f15SJohn Edward Broadbent // for one with a matching name 1110dba0c291SJonathan Doman crow::connections::systemBus->async_method_call( 11115df6eda2SShantappa Teekappanavar [asyncResp, cpuName, configName, reqUrl{req.url}]( 11125df6eda2SShantappa Teekappanavar boost::system::error_code ec, 11135df6eda2SShantappa Teekappanavar const dbus::utility::MapperGetSubTreeResponse& subtree) { 1114dba0c291SJonathan Doman if (ec) 1115dba0c291SJonathan Doman { 1116dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 1117dba0c291SJonathan Doman << ec.message(); 1118dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1119dba0c291SJonathan Doman return; 1120dba0c291SJonathan Doman } 1121002d39b4SEd Tanous const std::string expectedEnding = cpuName + '/' + configName; 1122dba0c291SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 1123dba0c291SJonathan Doman { 1124dba0c291SJonathan Doman // Ignore any configs without matching cpuX/configY 112511ba3979SEd Tanous if (!objectPath.ends_with(expectedEnding) || serviceMap.empty()) 1126dba0c291SJonathan Doman { 1127dba0c291SJonathan Doman continue; 1128dba0c291SJonathan Doman } 1129dba0c291SJonathan Doman 1130dba0c291SJonathan Doman nlohmann::json& json = asyncResp->res.jsonValue; 1131002d39b4SEd Tanous json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig"; 1132dba0c291SJonathan Doman json["@odata.id"] = reqUrl; 1133dba0c291SJonathan Doman json["Name"] = "Processor Profile"; 1134dba0c291SJonathan Doman json["Id"] = configName; 1135dba0c291SJonathan Doman 1136dba0c291SJonathan Doman // Just use the first implementation of the object - not 11377e860f15SJohn Edward Broadbent // expected that there would be multiple matching 11387e860f15SJohn Edward Broadbent // services 1139002d39b4SEd Tanous getOperatingConfigData(asyncResp, serviceMap.begin()->first, 1140002d39b4SEd Tanous objectPath); 1141dba0c291SJonathan Doman return; 1142dba0c291SJonathan Doman } 1143002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "OperatingConfig", 1144002d39b4SEd Tanous configName); 1145dba0c291SJonathan Doman }, 1146dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", 1147dba0c291SJonathan Doman "/xyz/openbmc_project/object_mapper", 1148dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", "GetSubTree", 1149dba0c291SJonathan Doman "/xyz/openbmc_project/inventory", 0, 1150dba0c291SJonathan Doman std::array<const char*, 1>{ 1151dba0c291SJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}); 11527e860f15SJohn Edward Broadbent }); 1153ac6a4445SGunnar Mills } 1154ac6a4445SGunnar Mills 11557e860f15SJohn Edward Broadbent inline void requestRoutesProcessorCollection(App& app) 11567e860f15SJohn Edward Broadbent { 1157ac6a4445SGunnar Mills /** 1158ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1159ac6a4445SGunnar Mills */ 116022d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/") 1161ed398213SEd Tanous .privileges(redfish::privileges::getProcessorCollection) 11627e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 116345ca1b86SEd Tanous [&app](const crow::Request& req, 116422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 116522d268cbSEd Tanous const std::string& systemName) { 11663ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 116745ca1b86SEd Tanous { 116845ca1b86SEd Tanous return; 116945ca1b86SEd Tanous } 117022d268cbSEd Tanous if (systemName != "system") 117122d268cbSEd Tanous { 117222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 117322d268cbSEd Tanous systemName); 117422d268cbSEd Tanous return; 117522d268cbSEd Tanous } 117622d268cbSEd Tanous 11778d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1178ac6a4445SGunnar Mills "#ProcessorCollection.ProcessorCollection"; 11798d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Processor Collection"; 1180ac6a4445SGunnar Mills 11818d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = 11828d1b46d7Szhanghch05 "/redfish/v1/Systems/system/Processors"; 1183ac6a4445SGunnar Mills 118405030b8eSGunnar Mills collection_util::getCollectionMembers( 1185*ae9031f0SWilly Tu asyncResp, 1186*ae9031f0SWilly Tu boost::urls::url("/redfish/v1/Systems/system/Processors"), 1187c951448aSJonathan Doman std::vector<const char*>(processorInterfaces.begin(), 1188c951448aSJonathan Doman processorInterfaces.end())); 11897e860f15SJohn Edward Broadbent }); 1190ac6a4445SGunnar Mills } 1191ac6a4445SGunnar Mills 11927e860f15SJohn Edward Broadbent inline void requestRoutesProcessor(App& app) 11937e860f15SJohn Edward Broadbent { 1194ac6a4445SGunnar Mills /** 1195ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1196ac6a4445SGunnar Mills */ 11977e860f15SJohn Edward Broadbent 119822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 1199ed398213SEd Tanous .privileges(redfish::privileges::getProcessor) 12007e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 120145ca1b86SEd Tanous [&app](const crow::Request& req, 12027e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 120322d268cbSEd Tanous const std::string& systemName, 12047e860f15SJohn Edward Broadbent const std::string& processorId) { 12053ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 120645ca1b86SEd Tanous { 120745ca1b86SEd Tanous return; 120845ca1b86SEd Tanous } 120922d268cbSEd Tanous if (systemName != "system") 121022d268cbSEd Tanous { 121122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 121222d268cbSEd Tanous systemName); 121322d268cbSEd Tanous return; 121422d268cbSEd Tanous } 121522d268cbSEd Tanous 12168d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 12178d1b46d7Szhanghch05 "#Processor.v1_11_0.Processor"; 12188d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = 1219ac6a4445SGunnar Mills "/redfish/v1/Systems/system/Processors/" + processorId; 1220ac6a4445SGunnar Mills 12218a592810SEd Tanous getProcessorObject( 12228a592810SEd Tanous asyncResp, processorId, 12238a592810SEd Tanous std::bind_front(getProcessorData, asyncResp, processorId)); 12247e860f15SJohn Edward Broadbent }); 12253cde86f1SJonathan Doman 122622d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/") 1227ed398213SEd Tanous .privileges(redfish::privileges::patchProcessor) 12287e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 122945ca1b86SEd Tanous [&app](const crow::Request& req, 12307e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 123122d268cbSEd Tanous const std::string& systemName, 12327e860f15SJohn Edward Broadbent const std::string& processorId) { 12333ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 123445ca1b86SEd Tanous { 123545ca1b86SEd Tanous return; 123645ca1b86SEd Tanous } 123722d268cbSEd Tanous if (systemName != "system") 123822d268cbSEd Tanous { 123922d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 124022d268cbSEd Tanous systemName); 124122d268cbSEd Tanous return; 124222d268cbSEd Tanous } 124322d268cbSEd Tanous 12443cde86f1SJonathan Doman std::optional<nlohmann::json> appliedConfigJson; 124515ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, 12467e860f15SJohn Edward Broadbent "AppliedOperatingConfig", 12473cde86f1SJonathan Doman appliedConfigJson)) 12483cde86f1SJonathan Doman { 12493cde86f1SJonathan Doman return; 12503cde86f1SJonathan Doman } 12513cde86f1SJonathan Doman 12523cde86f1SJonathan Doman std::string appliedConfigUri; 12533cde86f1SJonathan Doman if (appliedConfigJson) 12543cde86f1SJonathan Doman { 12553cde86f1SJonathan Doman if (!json_util::readJson(*appliedConfigJson, asyncResp->res, 12563cde86f1SJonathan Doman "@odata.id", appliedConfigUri)) 12573cde86f1SJonathan Doman { 12583cde86f1SJonathan Doman return; 12593cde86f1SJonathan Doman } 12607e860f15SJohn Edward Broadbent // Check for 404 and find matching D-Bus object, then run 12617e860f15SJohn Edward Broadbent // property patch handlers if that all succeeds. 12628a592810SEd Tanous getProcessorObject(asyncResp, processorId, 12638a592810SEd Tanous std::bind_front(patchAppliedOperatingConfig, 12647e860f15SJohn Edward Broadbent asyncResp, processorId, 12658a592810SEd Tanous appliedConfigUri)); 12663cde86f1SJonathan Doman } 12677e860f15SJohn Edward Broadbent }); 12683cde86f1SJonathan Doman } 1269ac6a4445SGunnar Mills 1270ac6a4445SGunnar Mills } // namespace redfish 1271