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> 25ed398213SEd Tanous #include <registries/privilege_registry.hpp> 261e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 27dba0c291SJonathan Doman #include <sdbusplus/message/native_types.hpp> 28dba0c291SJonathan Doman #include <sdbusplus/utility/dedup_variant.hpp> 29ac6a4445SGunnar Mills #include <utils/collection.hpp> 30ac6a4445SGunnar Mills #include <utils/json_utils.hpp> 31ac6a4445SGunnar Mills 32ac6a4445SGunnar Mills namespace redfish 33ac6a4445SGunnar Mills { 34ac6a4445SGunnar Mills 35ac6a4445SGunnar Mills using InterfacesProperties = boost::container::flat_map< 36ac6a4445SGunnar Mills std::string, 37ac6a4445SGunnar Mills boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>; 38ac6a4445SGunnar Mills 39c951448aSJonathan Doman // Map of service name to list of interfaces 40c951448aSJonathan Doman using MapperServiceMap = 41c951448aSJonathan Doman std::vector<std::pair<std::string, std::vector<std::string>>>; 42c951448aSJonathan Doman 43c951448aSJonathan Doman // Map of object paths to MapperServiceMaps 44c951448aSJonathan Doman using MapperGetSubTreeResponse = 45c951448aSJonathan Doman std::vector<std::pair<std::string, MapperServiceMap>>; 46c951448aSJonathan Doman 47c951448aSJonathan Doman // Interfaces which imply a D-Bus object represents a Processor 48c951448aSJonathan Doman constexpr std::array<const char*, 2> processorInterfaces = { 49c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu", 50c951448aSJonathan Doman "xyz.openbmc_project.Inventory.Item.Accelerator"}; 512bab9831SJonathan Doman 5271b82f26SSharad Yadav /** 5371b82f26SSharad Yadav * @brief Fill out uuid info of a processor by 5471b82f26SSharad Yadav * requesting data from the given D-Bus object. 5571b82f26SSharad Yadav * 5671b82f26SSharad Yadav * @param[in,out] aResp Async HTTP response. 5771b82f26SSharad Yadav * @param[in] service D-Bus service to query. 5871b82f26SSharad Yadav * @param[in] objPath D-Bus object to query. 5971b82f26SSharad Yadav */ 6071b82f26SSharad Yadav inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp, 6171b82f26SSharad Yadav const std::string& service, 6271b82f26SSharad Yadav const std::string& objPath) 6371b82f26SSharad Yadav { 6471b82f26SSharad Yadav BMCWEB_LOG_DEBUG << "Get Processor UUID"; 651e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 661e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 671e1e598dSJonathan Doman "xyz.openbmc_project.Common.UUID", "UUID", 681e1e598dSJonathan Doman [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec, 691e1e598dSJonathan Doman const std::string& property) { 7071b82f26SSharad Yadav if (ec) 7171b82f26SSharad Yadav { 7271b82f26SSharad Yadav BMCWEB_LOG_DEBUG << "DBUS response error"; 7371b82f26SSharad Yadav messages::internalError(aResp->res); 7471b82f26SSharad Yadav return; 7571b82f26SSharad Yadav } 761e1e598dSJonathan Doman aResp->res.jsonValue["UUID"] = property; 771e1e598dSJonathan Doman }); 7871b82f26SSharad Yadav } 7971b82f26SSharad Yadav 80*711ac7a9SEd Tanous inline void getCpuDataByInterface( 81*711ac7a9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aResp, 82*711ac7a9SEd Tanous const dbus::utility::DBusInteracesMap& cpuInterfacesProperties) 83ac6a4445SGunnar Mills { 84ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; 85ac6a4445SGunnar Mills 86a1649ec6SChicago Duan // Set the default value of state 87a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["State"] = "Enabled"; 88a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["Health"] = "OK"; 89ac6a4445SGunnar Mills 90ac6a4445SGunnar Mills for (const auto& interface : cpuInterfacesProperties) 91ac6a4445SGunnar Mills { 92ac6a4445SGunnar Mills for (const auto& property : interface.second) 93ac6a4445SGunnar Mills { 94a1649ec6SChicago Duan if (property.first == "Present") 95ac6a4445SGunnar Mills { 96a1649ec6SChicago Duan const bool* cpuPresent = std::get_if<bool>(&property.second); 97a1649ec6SChicago Duan if (cpuPresent == nullptr) 98ac6a4445SGunnar Mills { 99ac6a4445SGunnar Mills // Important property not in desired type 100ac6a4445SGunnar Mills messages::internalError(aResp->res); 101ac6a4445SGunnar Mills return; 102ac6a4445SGunnar Mills } 103a1649ec6SChicago Duan if (*cpuPresent == false) 104ac6a4445SGunnar Mills { 105a1649ec6SChicago Duan // Slot is not populated 106ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Absent"; 107a1649ec6SChicago Duan } 108a1649ec6SChicago Duan } 109a1649ec6SChicago Duan else if (property.first == "Functional") 110a1649ec6SChicago Duan { 111a1649ec6SChicago Duan const bool* cpuFunctional = std::get_if<bool>(&property.second); 112a1649ec6SChicago Duan if (cpuFunctional == nullptr) 113a1649ec6SChicago Duan { 114a1649ec6SChicago Duan messages::internalError(aResp->res); 115ac6a4445SGunnar Mills return; 116ac6a4445SGunnar Mills } 117a1649ec6SChicago Duan if (*cpuFunctional == false) 118a1649ec6SChicago Duan { 119a1649ec6SChicago Duan aResp->res.jsonValue["Status"]["Health"] = "Critical"; 120a1649ec6SChicago Duan } 121a1649ec6SChicago Duan } 122a1649ec6SChicago Duan else if (property.first == "CoreCount") 123a1649ec6SChicago Duan { 124a1649ec6SChicago Duan const uint16_t* coresCount = 125a1649ec6SChicago Duan std::get_if<uint16_t>(&property.second); 126a1649ec6SChicago Duan if (coresCount == nullptr) 127a1649ec6SChicago Duan { 128a1649ec6SChicago Duan messages::internalError(aResp->res); 129a1649ec6SChicago Duan return; 130a1649ec6SChicago Duan } 131ac6a4445SGunnar Mills aResp->res.jsonValue["TotalCores"] = *coresCount; 132ac6a4445SGunnar Mills } 133dc3fa667SJonathan Doman else if (property.first == "MaxSpeedInMhz") 134dc3fa667SJonathan Doman { 135dc3fa667SJonathan Doman const uint32_t* value = std::get_if<uint32_t>(&property.second); 136dc3fa667SJonathan Doman if (value != nullptr) 137dc3fa667SJonathan Doman { 138dc3fa667SJonathan Doman aResp->res.jsonValue["MaxSpeedMHz"] = *value; 139dc3fa667SJonathan Doman } 140dc3fa667SJonathan Doman } 141ac6a4445SGunnar Mills else if (property.first == "Socket") 142ac6a4445SGunnar Mills { 143ac6a4445SGunnar Mills const std::string* value = 144ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 145ac6a4445SGunnar Mills if (value != nullptr) 146ac6a4445SGunnar Mills { 147ac6a4445SGunnar Mills aResp->res.jsonValue["Socket"] = *value; 148ac6a4445SGunnar Mills } 149ac6a4445SGunnar Mills } 150ac6a4445SGunnar Mills else if (property.first == "ThreadCount") 151ac6a4445SGunnar Mills { 152dc3fa667SJonathan Doman const uint16_t* value = std::get_if<uint16_t>(&property.second); 153ac6a4445SGunnar Mills if (value != nullptr) 154ac6a4445SGunnar Mills { 155ac6a4445SGunnar Mills aResp->res.jsonValue["TotalThreads"] = *value; 156ac6a4445SGunnar Mills } 157ac6a4445SGunnar Mills } 1581930fbd4SBrandon Kim else if (property.first == "EffectiveFamily") 159ac6a4445SGunnar Mills { 1601930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 161ac6a4445SGunnar Mills if (value != nullptr) 162ac6a4445SGunnar Mills { 163ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] = 1641930fbd4SBrandon Kim "0x" + intToHexString(*value); 165ac6a4445SGunnar Mills } 166ac6a4445SGunnar Mills } 1671930fbd4SBrandon Kim else if (property.first == "EffectiveModel") 1681930fbd4SBrandon Kim { 1691930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 1701930fbd4SBrandon Kim if (value == nullptr) 1711930fbd4SBrandon Kim { 1721930fbd4SBrandon Kim messages::internalError(aResp->res); 1731930fbd4SBrandon Kim return; 1741930fbd4SBrandon Kim } 1751930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["EffectiveModel"] = 1761930fbd4SBrandon Kim "0x" + intToHexString(*value); 1771930fbd4SBrandon Kim } 178ac6a4445SGunnar Mills else if (property.first == "Id") 179ac6a4445SGunnar Mills { 180ac6a4445SGunnar Mills const uint64_t* value = std::get_if<uint64_t>(&property.second); 181ac6a4445SGunnar Mills if (value != nullptr && *value != 0) 182ac6a4445SGunnar Mills { 183ac6a4445SGunnar Mills aResp->res 184ac6a4445SGunnar Mills .jsonValue["ProcessorId"]["IdentificationRegisters"] = 185f201ffb4SEd Tanous "0x" + intToHexString(*value); 186ac6a4445SGunnar Mills } 187ac6a4445SGunnar Mills } 1881930fbd4SBrandon Kim else if (property.first == "Microcode") 1891930fbd4SBrandon Kim { 1901930fbd4SBrandon Kim const uint32_t* value = std::get_if<uint32_t>(&property.second); 1911930fbd4SBrandon Kim if (value == nullptr) 1921930fbd4SBrandon Kim { 1931930fbd4SBrandon Kim messages::internalError(aResp->res); 1941930fbd4SBrandon Kim return; 1951930fbd4SBrandon Kim } 1961930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] = 1971930fbd4SBrandon Kim "0x" + intToHexString(*value); 1981930fbd4SBrandon Kim } 1991930fbd4SBrandon Kim else if (property.first == "Step") 2001930fbd4SBrandon Kim { 2011930fbd4SBrandon Kim const uint16_t* value = std::get_if<uint16_t>(&property.second); 2021930fbd4SBrandon Kim if (value == nullptr) 2031930fbd4SBrandon Kim { 2041930fbd4SBrandon Kim messages::internalError(aResp->res); 2051930fbd4SBrandon Kim return; 2061930fbd4SBrandon Kim } 2071930fbd4SBrandon Kim aResp->res.jsonValue["ProcessorId"]["Step"] = 2081930fbd4SBrandon Kim "0x" + intToHexString(*value); 2091930fbd4SBrandon Kim } 210ac6a4445SGunnar Mills } 211ac6a4445SGunnar Mills } 212ac6a4445SGunnar Mills 213ac6a4445SGunnar Mills return; 214ac6a4445SGunnar Mills } 215ac6a4445SGunnar Mills 2168d1b46d7Szhanghch05 inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, 217ac6a4445SGunnar Mills const std::string& cpuId, 218ac6a4445SGunnar Mills const std::string& service, 219ac6a4445SGunnar Mills const std::string& objPath) 220ac6a4445SGunnar Mills { 221ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; 222ac6a4445SGunnar Mills 223ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 224ac6a4445SGunnar Mills [cpuId, service, objPath, aResp{std::move(aResp)}]( 225ac6a4445SGunnar Mills const boost::system::error_code ec, 226ac6a4445SGunnar Mills const dbus::utility::ManagedObjectType& dbusData) { 227ac6a4445SGunnar Mills if (ec) 228ac6a4445SGunnar Mills { 229ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 230ac6a4445SGunnar Mills messages::internalError(aResp->res); 231ac6a4445SGunnar Mills return; 232ac6a4445SGunnar Mills } 233ac6a4445SGunnar Mills aResp->res.jsonValue["Id"] = cpuId; 234ac6a4445SGunnar Mills aResp->res.jsonValue["Name"] = "Processor"; 235ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorType"] = "CPU"; 236ac6a4445SGunnar Mills 237ac6a4445SGunnar Mills bool slotPresent = false; 238ac6a4445SGunnar Mills std::string corePath = objPath + "/core"; 239ac6a4445SGunnar Mills size_t totalCores = 0; 240ac6a4445SGunnar Mills for (const auto& object : dbusData) 241ac6a4445SGunnar Mills { 242ac6a4445SGunnar Mills if (object.first.str == objPath) 243ac6a4445SGunnar Mills { 244ac6a4445SGunnar Mills getCpuDataByInterface(aResp, object.second); 245ac6a4445SGunnar Mills } 246ac6a4445SGunnar Mills else if (boost::starts_with(object.first.str, corePath)) 247ac6a4445SGunnar Mills { 248ac6a4445SGunnar Mills for (const auto& interface : object.second) 249ac6a4445SGunnar Mills { 250ac6a4445SGunnar Mills if (interface.first == 251ac6a4445SGunnar Mills "xyz.openbmc_project.Inventory.Item") 252ac6a4445SGunnar Mills { 253ac6a4445SGunnar Mills for (const auto& property : interface.second) 254ac6a4445SGunnar Mills { 255ac6a4445SGunnar Mills if (property.first == "Present") 256ac6a4445SGunnar Mills { 257ac6a4445SGunnar Mills const bool* present = 258ac6a4445SGunnar Mills std::get_if<bool>(&property.second); 259ac6a4445SGunnar Mills if (present != nullptr) 260ac6a4445SGunnar Mills { 261ac6a4445SGunnar Mills if (*present == true) 262ac6a4445SGunnar Mills { 263ac6a4445SGunnar Mills slotPresent = true; 264ac6a4445SGunnar Mills totalCores++; 265ac6a4445SGunnar Mills } 266ac6a4445SGunnar Mills } 267ac6a4445SGunnar Mills } 268ac6a4445SGunnar Mills } 269ac6a4445SGunnar Mills } 270ac6a4445SGunnar Mills } 271ac6a4445SGunnar Mills } 272ac6a4445SGunnar Mills } 273ac6a4445SGunnar Mills // In getCpuDataByInterface(), state and health are set 274ac6a4445SGunnar Mills // based on the present and functional status. If core 275ac6a4445SGunnar Mills // count is zero, then it has a higher precedence. 276ac6a4445SGunnar Mills if (slotPresent) 277ac6a4445SGunnar Mills { 278ac6a4445SGunnar Mills if (totalCores == 0) 279ac6a4445SGunnar Mills { 280ac6a4445SGunnar Mills // Slot is not populated, set status end return 281ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Absent"; 282ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["Health"] = "OK"; 283ac6a4445SGunnar Mills } 284ac6a4445SGunnar Mills aResp->res.jsonValue["TotalCores"] = totalCores; 285ac6a4445SGunnar Mills } 286ac6a4445SGunnar Mills return; 287ac6a4445SGunnar Mills }, 288ac6a4445SGunnar Mills service, "/xyz/openbmc_project/inventory", 289ac6a4445SGunnar Mills "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 290ac6a4445SGunnar Mills } 291ac6a4445SGunnar Mills 2928d1b46d7Szhanghch05 inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> aResp, 293ac6a4445SGunnar Mills const std::string& service, 294ac6a4445SGunnar Mills const std::string& objPath) 295ac6a4445SGunnar Mills { 296ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get Cpu Asset Data"; 297ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 298ac6a4445SGunnar Mills [objPath, aResp{std::move(aResp)}]( 299ac6a4445SGunnar Mills const boost::system::error_code ec, 300ac6a4445SGunnar Mills const boost::container::flat_map< 301168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>& properties) { 302ac6a4445SGunnar Mills if (ec) 303ac6a4445SGunnar Mills { 304ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 305ac6a4445SGunnar Mills messages::internalError(aResp->res); 306ac6a4445SGunnar Mills return; 307ac6a4445SGunnar Mills } 308ac6a4445SGunnar Mills 309ac6a4445SGunnar Mills for (const auto& property : properties) 310ac6a4445SGunnar Mills { 311ac6a4445SGunnar Mills if (property.first == "SerialNumber") 312ac6a4445SGunnar Mills { 313ac6a4445SGunnar Mills const std::string* sn = 314ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 315ac6a4445SGunnar Mills if (sn != nullptr && !sn->empty()) 316ac6a4445SGunnar Mills { 317ac6a4445SGunnar Mills aResp->res.jsonValue["SerialNumber"] = *sn; 318ac6a4445SGunnar Mills } 319ac6a4445SGunnar Mills } 320ac6a4445SGunnar Mills else if (property.first == "Model") 321ac6a4445SGunnar Mills { 322ac6a4445SGunnar Mills const std::string* model = 323ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 324ac6a4445SGunnar Mills if (model != nullptr && !model->empty()) 325ac6a4445SGunnar Mills { 326ac6a4445SGunnar Mills aResp->res.jsonValue["Model"] = *model; 327ac6a4445SGunnar Mills } 328ac6a4445SGunnar Mills } 329ac6a4445SGunnar Mills else if (property.first == "Manufacturer") 330ac6a4445SGunnar Mills { 331ac6a4445SGunnar Mills 332ac6a4445SGunnar Mills const std::string* mfg = 333ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 334ac6a4445SGunnar Mills if (mfg != nullptr) 335ac6a4445SGunnar Mills { 336ac6a4445SGunnar Mills aResp->res.jsonValue["Manufacturer"] = *mfg; 337ac6a4445SGunnar Mills 338ac6a4445SGunnar Mills // Otherwise would be unexpected. 339ac6a4445SGunnar Mills if (mfg->find("Intel") != std::string::npos) 340ac6a4445SGunnar Mills { 341ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorArchitecture"] = 342ac6a4445SGunnar Mills "x86"; 343ac6a4445SGunnar Mills aResp->res.jsonValue["InstructionSet"] = "x86-64"; 344ac6a4445SGunnar Mills } 345ac6a4445SGunnar Mills else if (mfg->find("IBM") != std::string::npos) 346ac6a4445SGunnar Mills { 347ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorArchitecture"] = 348ac6a4445SGunnar Mills "Power"; 349ac6a4445SGunnar Mills aResp->res.jsonValue["InstructionSet"] = "PowerISA"; 350ac6a4445SGunnar Mills } 351ac6a4445SGunnar Mills } 352ac6a4445SGunnar Mills } 353cba4f448SSunnySrivastava1984 else if (property.first == "PartNumber") 354cba4f448SSunnySrivastava1984 { 355cba4f448SSunnySrivastava1984 const std::string* partNumber = 356cba4f448SSunnySrivastava1984 std::get_if<std::string>(&property.second); 357cba4f448SSunnySrivastava1984 358cba4f448SSunnySrivastava1984 if (partNumber == nullptr) 359cba4f448SSunnySrivastava1984 { 360cba4f448SSunnySrivastava1984 messages::internalError(aResp->res); 361cba4f448SSunnySrivastava1984 return; 362cba4f448SSunnySrivastava1984 } 363cba4f448SSunnySrivastava1984 aResp->res.jsonValue["PartNumber"] = *partNumber; 364cba4f448SSunnySrivastava1984 } 365cba4f448SSunnySrivastava1984 else if (property.first == "SparePartNumber") 366cba4f448SSunnySrivastava1984 { 367cba4f448SSunnySrivastava1984 const std::string* sparePartNumber = 368cba4f448SSunnySrivastava1984 std::get_if<std::string>(&property.second); 369cba4f448SSunnySrivastava1984 370cba4f448SSunnySrivastava1984 if (sparePartNumber == nullptr) 371cba4f448SSunnySrivastava1984 { 372cba4f448SSunnySrivastava1984 messages::internalError(aResp->res); 373cba4f448SSunnySrivastava1984 return; 374cba4f448SSunnySrivastava1984 } 375cba4f448SSunnySrivastava1984 aResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; 376cba4f448SSunnySrivastava1984 } 377ac6a4445SGunnar Mills } 378ac6a4445SGunnar Mills }, 379ac6a4445SGunnar Mills service, objPath, "org.freedesktop.DBus.Properties", "GetAll", 380ac6a4445SGunnar Mills "xyz.openbmc_project.Inventory.Decorator.Asset"); 381ac6a4445SGunnar Mills } 382ac6a4445SGunnar Mills 3838d1b46d7Szhanghch05 inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> aResp, 384ac6a4445SGunnar Mills const std::string& service, 385ac6a4445SGunnar Mills const std::string& objPath) 386ac6a4445SGunnar Mills { 387ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get Cpu Revision Data"; 388ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 389ac6a4445SGunnar Mills [objPath, aResp{std::move(aResp)}]( 390ac6a4445SGunnar Mills const boost::system::error_code ec, 391ac6a4445SGunnar Mills const boost::container::flat_map< 392168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>& properties) { 393ac6a4445SGunnar Mills if (ec) 394ac6a4445SGunnar Mills { 395ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 396ac6a4445SGunnar Mills messages::internalError(aResp->res); 397ac6a4445SGunnar Mills return; 398ac6a4445SGunnar Mills } 399ac6a4445SGunnar Mills 400ac6a4445SGunnar Mills for (const auto& property : properties) 401ac6a4445SGunnar Mills { 402ac6a4445SGunnar Mills if (property.first == "Version") 403ac6a4445SGunnar Mills { 404ac6a4445SGunnar Mills const std::string* ver = 405ac6a4445SGunnar Mills std::get_if<std::string>(&property.second); 406ac6a4445SGunnar Mills if (ver != nullptr) 407ac6a4445SGunnar Mills { 408ac6a4445SGunnar Mills aResp->res.jsonValue["Version"] = *ver; 409ac6a4445SGunnar Mills } 410ac6a4445SGunnar Mills break; 411ac6a4445SGunnar Mills } 412ac6a4445SGunnar Mills } 413ac6a4445SGunnar Mills }, 414ac6a4445SGunnar Mills service, objPath, "org.freedesktop.DBus.Properties", "GetAll", 415ac6a4445SGunnar Mills "xyz.openbmc_project.Inventory.Decorator.Revision"); 416ac6a4445SGunnar Mills } 417ac6a4445SGunnar Mills 4188d1b46d7Szhanghch05 inline void getAcceleratorDataByService( 4198d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> aResp, const std::string& acclrtrId, 4208d1b46d7Szhanghch05 const std::string& service, const std::string& objPath) 421ac6a4445SGunnar Mills { 422ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG 423ac6a4445SGunnar Mills << "Get available system Accelerator resources by service."; 424ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 425ac6a4445SGunnar Mills [acclrtrId, aResp{std::move(aResp)}]( 426ac6a4445SGunnar Mills const boost::system::error_code ec, 427ac6a4445SGunnar Mills const boost::container::flat_map< 428168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>& properties) { 429ac6a4445SGunnar Mills if (ec) 430ac6a4445SGunnar Mills { 431ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error"; 432ac6a4445SGunnar Mills messages::internalError(aResp->res); 433ac6a4445SGunnar Mills return; 434ac6a4445SGunnar Mills } 435ac6a4445SGunnar Mills aResp->res.jsonValue["Id"] = acclrtrId; 436ac6a4445SGunnar Mills aResp->res.jsonValue["Name"] = "Processor"; 437ac6a4445SGunnar Mills const bool* accPresent = nullptr; 438ac6a4445SGunnar Mills const bool* accFunctional = nullptr; 439ac6a4445SGunnar Mills 440ac6a4445SGunnar Mills for (const auto& property : properties) 441ac6a4445SGunnar Mills { 442ac6a4445SGunnar Mills if (property.first == "Functional") 443ac6a4445SGunnar Mills { 444ac6a4445SGunnar Mills accFunctional = std::get_if<bool>(&property.second); 445ac6a4445SGunnar Mills } 446ac6a4445SGunnar Mills else if (property.first == "Present") 447ac6a4445SGunnar Mills { 448ac6a4445SGunnar Mills accPresent = std::get_if<bool>(&property.second); 449ac6a4445SGunnar Mills } 450ac6a4445SGunnar Mills } 451ac6a4445SGunnar Mills 452ac6a4445SGunnar Mills std::string state = "Enabled"; 453ac6a4445SGunnar Mills std::string health = "OK"; 454ac6a4445SGunnar Mills 455ac6a4445SGunnar Mills if (accPresent != nullptr && *accPresent == false) 456ac6a4445SGunnar Mills { 457ac6a4445SGunnar Mills state = "Absent"; 458ac6a4445SGunnar Mills } 459ac6a4445SGunnar Mills 460ac6a4445SGunnar Mills if ((accFunctional != nullptr) && (*accFunctional == false)) 461ac6a4445SGunnar Mills { 462ac6a4445SGunnar Mills if (state == "Enabled") 463ac6a4445SGunnar Mills { 464ac6a4445SGunnar Mills health = "Critical"; 465ac6a4445SGunnar Mills } 466ac6a4445SGunnar Mills } 467ac6a4445SGunnar Mills 468ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["State"] = state; 469ac6a4445SGunnar Mills aResp->res.jsonValue["Status"]["Health"] = health; 470ac6a4445SGunnar Mills aResp->res.jsonValue["ProcessorType"] = "Accelerator"; 471ac6a4445SGunnar Mills }, 472ac6a4445SGunnar Mills service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); 473ac6a4445SGunnar Mills } 474ac6a4445SGunnar Mills 475dba0c291SJonathan Doman // OperatingConfig D-Bus Types 476dba0c291SJonathan Doman using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>; 477dba0c291SJonathan Doman using BaseSpeedPrioritySettingsProperty = 478dba0c291SJonathan Doman std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>; 479dba0c291SJonathan Doman // uint32_t and size_t may or may not be the same type, requiring a dedup'd 480dba0c291SJonathan Doman // variant 481168e20c1SEd Tanous using OperatingConfigProperties = 482168e20c1SEd Tanous std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>; 483dba0c291SJonathan Doman 484dba0c291SJonathan Doman /** 485dba0c291SJonathan Doman * Fill out the HighSpeedCoreIDs in a Processor resource from the given 486dba0c291SJonathan Doman * OperatingConfig D-Bus property. 487dba0c291SJonathan Doman * 488dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 489dba0c291SJonathan Doman * @param[in] baseSpeedSettings Full list of base speed priority groups, 490dba0c291SJonathan Doman * to use to determine the list of high 491dba0c291SJonathan Doman * speed cores. 492dba0c291SJonathan Doman */ 493dba0c291SJonathan Doman inline void highSpeedCoreIdsHandler( 4948d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aResp, 495dba0c291SJonathan Doman const BaseSpeedPrioritySettingsProperty& baseSpeedSettings) 496dba0c291SJonathan Doman { 497dba0c291SJonathan Doman // The D-Bus property does not indicate which bucket is the "high 498dba0c291SJonathan Doman // priority" group, so let's discern that by looking for the one with 499dba0c291SJonathan Doman // highest base frequency. 500dba0c291SJonathan Doman auto highPriorityGroup = baseSpeedSettings.cend(); 501dba0c291SJonathan Doman uint32_t highestBaseSpeed = 0; 502dba0c291SJonathan Doman for (auto it = baseSpeedSettings.cbegin(); it != baseSpeedSettings.cend(); 503dba0c291SJonathan Doman ++it) 504dba0c291SJonathan Doman { 505dba0c291SJonathan Doman const uint32_t baseFreq = std::get<uint32_t>(*it); 506dba0c291SJonathan Doman if (baseFreq > highestBaseSpeed) 507dba0c291SJonathan Doman { 508dba0c291SJonathan Doman highestBaseSpeed = baseFreq; 509dba0c291SJonathan Doman highPriorityGroup = it; 510dba0c291SJonathan Doman } 511dba0c291SJonathan Doman } 512dba0c291SJonathan Doman 513dba0c291SJonathan Doman nlohmann::json& jsonCoreIds = aResp->res.jsonValue["HighSpeedCoreIDs"]; 514dba0c291SJonathan Doman jsonCoreIds = nlohmann::json::array(); 515dba0c291SJonathan Doman 516dba0c291SJonathan Doman // There may not be any entries in the D-Bus property, so only populate 517dba0c291SJonathan Doman // if there was actually something there. 518dba0c291SJonathan Doman if (highPriorityGroup != baseSpeedSettings.cend()) 519dba0c291SJonathan Doman { 520dba0c291SJonathan Doman jsonCoreIds = std::get<std::vector<uint32_t>>(*highPriorityGroup); 521dba0c291SJonathan Doman } 522dba0c291SJonathan Doman } 523dba0c291SJonathan Doman 524dba0c291SJonathan Doman /** 525dba0c291SJonathan Doman * Fill out OperatingConfig related items in a Processor resource by requesting 526dba0c291SJonathan Doman * data from the given D-Bus object. 527dba0c291SJonathan Doman * 528dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 529dba0c291SJonathan Doman * @param[in] cpuId CPU D-Bus name. 530dba0c291SJonathan Doman * @param[in] service D-Bus service to query. 531dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 532dba0c291SJonathan Doman */ 5338d1b46d7Szhanghch05 inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 534dba0c291SJonathan Doman const std::string& cpuId, 535dba0c291SJonathan Doman const std::string& service, 536dba0c291SJonathan Doman const std::string& objPath) 537dba0c291SJonathan Doman { 538dba0c291SJonathan Doman BMCWEB_LOG_INFO << "Getting CPU operating configs for " << cpuId; 539dba0c291SJonathan Doman 540dba0c291SJonathan Doman // First, GetAll CurrentOperatingConfig properties on the object 541dba0c291SJonathan Doman crow::connections::systemBus->async_method_call( 542dba0c291SJonathan Doman [aResp, cpuId, service]( 543dba0c291SJonathan Doman const boost::system::error_code ec, 544168e20c1SEd Tanous const std::vector<std::pair< 545168e20c1SEd Tanous std::string, dbus::utility::DbusVariantType>>& properties) { 546dba0c291SJonathan Doman if (ec) 547dba0c291SJonathan Doman { 548dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 549dba0c291SJonathan Doman << ec.message(); 550dba0c291SJonathan Doman messages::internalError(aResp->res); 551dba0c291SJonathan Doman return; 552dba0c291SJonathan Doman } 553dba0c291SJonathan Doman 554dba0c291SJonathan Doman nlohmann::json& json = aResp->res.jsonValue; 555dba0c291SJonathan Doman 556dba0c291SJonathan Doman for (const auto& [dbusPropName, variantVal] : properties) 557dba0c291SJonathan Doman { 558dba0c291SJonathan Doman if (dbusPropName == "AppliedConfig") 559dba0c291SJonathan Doman { 560dba0c291SJonathan Doman const sdbusplus::message::object_path* dbusPathWrapper = 561dba0c291SJonathan Doman std::get_if<sdbusplus::message::object_path>( 562dba0c291SJonathan Doman &variantVal); 563dba0c291SJonathan Doman if (dbusPathWrapper == nullptr) 564dba0c291SJonathan Doman { 565dba0c291SJonathan Doman continue; 566dba0c291SJonathan Doman } 567dba0c291SJonathan Doman 568dba0c291SJonathan Doman const std::string& dbusPath = dbusPathWrapper->str; 569dba0c291SJonathan Doman std::string uri = "/redfish/v1/Systems/system/Processors/" + 570dba0c291SJonathan Doman cpuId + "/OperatingConfigs"; 571dba0c291SJonathan Doman json["OperatingConfigs"] = {{"@odata.id", uri}}; 572dba0c291SJonathan Doman 573dba0c291SJonathan Doman // Reuse the D-Bus config object name for the Redfish 574dba0c291SJonathan Doman // URI 575dba0c291SJonathan Doman size_t baseNamePos = dbusPath.rfind('/'); 576dba0c291SJonathan Doman if (baseNamePos == std::string::npos || 577dba0c291SJonathan Doman baseNamePos == (dbusPath.size() - 1)) 578dba0c291SJonathan Doman { 579dba0c291SJonathan Doman // If the AppliedConfig was somehow not a valid path, 580dba0c291SJonathan Doman // skip adding any more properties, since everything 581dba0c291SJonathan Doman // else is tied to this applied config. 582dba0c291SJonathan Doman messages::internalError(aResp->res); 583dba0c291SJonathan Doman break; 584dba0c291SJonathan Doman } 585dba0c291SJonathan Doman uri += '/'; 586dba0c291SJonathan Doman uri += dbusPath.substr(baseNamePos + 1); 587dba0c291SJonathan Doman json["AppliedOperatingConfig"] = {{"@odata.id", uri}}; 588dba0c291SJonathan Doman 589dba0c291SJonathan Doman // Once we found the current applied config, queue another 590dba0c291SJonathan Doman // request to read the base freq core ids out of that 591dba0c291SJonathan Doman // config. 5921e1e598dSJonathan Doman sdbusplus::asio::getProperty< 5931e1e598dSJonathan Doman BaseSpeedPrioritySettingsProperty>( 5941e1e598dSJonathan Doman *crow::connections::systemBus, service, dbusPath, 5951e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu." 5961e1e598dSJonathan Doman "OperatingConfig", 5971e1e598dSJonathan Doman "BaseSpeedPrioritySettings", 5981e1e598dSJonathan Doman [aResp](const boost::system::error_code ec, 5991e1e598dSJonathan Doman const BaseSpeedPrioritySettingsProperty& 6001e1e598dSJonathan Doman baseSpeedList) { 601dba0c291SJonathan Doman if (ec) 602dba0c291SJonathan Doman { 603dba0c291SJonathan Doman BMCWEB_LOG_WARNING 604dba0c291SJonathan Doman << "D-Bus Property Get error: " << ec; 605dba0c291SJonathan Doman messages::internalError(aResp->res); 606dba0c291SJonathan Doman return; 607dba0c291SJonathan Doman } 6081e1e598dSJonathan Doman 6091e1e598dSJonathan Doman highSpeedCoreIdsHandler(aResp, baseSpeedList); 6101e1e598dSJonathan Doman }); 611dba0c291SJonathan Doman } 612dba0c291SJonathan Doman else if (dbusPropName == "BaseSpeedPriorityEnabled") 613dba0c291SJonathan Doman { 614dba0c291SJonathan Doman const bool* state = std::get_if<bool>(&variantVal); 615dba0c291SJonathan Doman if (state != nullptr) 616dba0c291SJonathan Doman { 617dba0c291SJonathan Doman json["BaseSpeedPriorityState"] = 618dba0c291SJonathan Doman *state ? "Enabled" : "Disabled"; 619dba0c291SJonathan Doman } 620dba0c291SJonathan Doman } 621dba0c291SJonathan Doman } 622dba0c291SJonathan Doman }, 623dba0c291SJonathan Doman service, objPath, "org.freedesktop.DBus.Properties", "GetAll", 624dba0c291SJonathan Doman "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"); 625dba0c291SJonathan Doman } 626dba0c291SJonathan Doman 627cba4f448SSunnySrivastava1984 /** 628cba4f448SSunnySrivastava1984 * @brief Fill out location info of a processor by 629cba4f448SSunnySrivastava1984 * requesting data from the given D-Bus object. 630cba4f448SSunnySrivastava1984 * 631cba4f448SSunnySrivastava1984 * @param[in,out] aResp Async HTTP response. 632cba4f448SSunnySrivastava1984 * @param[in] service D-Bus service to query. 633cba4f448SSunnySrivastava1984 * @param[in] objPath D-Bus object to query. 634cba4f448SSunnySrivastava1984 */ 6358d1b46d7Szhanghch05 inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp, 636cba4f448SSunnySrivastava1984 const std::string& service, 637cba4f448SSunnySrivastava1984 const std::string& objPath) 638cba4f448SSunnySrivastava1984 { 639cba4f448SSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Get Cpu Location Data"; 6401e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 6411e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 6421e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 6431e1e598dSJonathan Doman [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec, 6441e1e598dSJonathan Doman const std::string& property) { 645cba4f448SSunnySrivastava1984 if (ec) 646cba4f448SSunnySrivastava1984 { 647cba4f448SSunnySrivastava1984 BMCWEB_LOG_DEBUG << "DBUS response error"; 648cba4f448SSunnySrivastava1984 messages::internalError(aResp->res); 649cba4f448SSunnySrivastava1984 return; 650cba4f448SSunnySrivastava1984 } 651cba4f448SSunnySrivastava1984 652cba4f448SSunnySrivastava1984 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 6531e1e598dSJonathan Doman property; 6541e1e598dSJonathan Doman }); 655cba4f448SSunnySrivastava1984 } 656cba4f448SSunnySrivastava1984 657c951448aSJonathan Doman /** 65849e429caSJonathan Doman * Populate the unique identifier in a Processor resource by requesting data 65949e429caSJonathan Doman * from the given D-Bus object. 66049e429caSJonathan Doman * 66149e429caSJonathan Doman * @param[in,out] aResp Async HTTP response. 66249e429caSJonathan Doman * @param[in] service D-Bus service to query. 66349e429caSJonathan Doman * @param[in] objPath D-Bus object to query. 66449e429caSJonathan Doman */ 66549e429caSJonathan Doman inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 66649e429caSJonathan Doman const std::string& service, 66749e429caSJonathan Doman const std::string& objectPath) 66849e429caSJonathan Doman { 66949e429caSJonathan Doman BMCWEB_LOG_DEBUG << "Get CPU UniqueIdentifier"; 6701e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 6711e1e598dSJonathan Doman *crow::connections::systemBus, service, objectPath, 6721e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier", 6731e1e598dSJonathan Doman "UniqueIdentifier", 6741e1e598dSJonathan Doman [aResp](boost::system::error_code ec, const std::string& id) { 6751e1e598dSJonathan Doman if (ec) 67649e429caSJonathan Doman { 67749e429caSJonathan Doman BMCWEB_LOG_ERROR << "Failed to read cpu unique id: " << ec; 67849e429caSJonathan Doman messages::internalError(aResp->res); 67949e429caSJonathan Doman return; 68049e429caSJonathan Doman } 68149e429caSJonathan Doman aResp->res 6821e1e598dSJonathan Doman .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id; 6831e1e598dSJonathan Doman }); 68449e429caSJonathan Doman } 68549e429caSJonathan Doman 68649e429caSJonathan Doman /** 687c951448aSJonathan Doman * Find the D-Bus object representing the requested Processor, and call the 688c951448aSJonathan Doman * handler with the results. If matching object is not found, add 404 error to 689c951448aSJonathan Doman * response and don't call the handler. 690c951448aSJonathan Doman * 691c951448aSJonathan Doman * @param[in,out] resp Async HTTP response. 692c951448aSJonathan Doman * @param[in] processorId Redfish Processor Id. 693c951448aSJonathan Doman * @param[in] handler Callback to continue processing request upon 694c951448aSJonathan Doman * successfully finding object. 695c951448aSJonathan Doman */ 696c951448aSJonathan Doman template <typename Handler> 6978d1b46d7Szhanghch05 inline void getProcessorObject(const std::shared_ptr<bmcweb::AsyncResp>& resp, 698c951448aSJonathan Doman const std::string& processorId, 699c951448aSJonathan Doman Handler&& handler) 700ac6a4445SGunnar Mills { 701ac6a4445SGunnar Mills BMCWEB_LOG_DEBUG << "Get available system processor resources."; 702ac6a4445SGunnar Mills 703c951448aSJonathan Doman // GetSubTree on all interfaces which provide info about a Processor 704ac6a4445SGunnar Mills crow::connections::systemBus->async_method_call( 705c951448aSJonathan Doman [resp, processorId, handler = std::forward<Handler>(handler)]( 706c951448aSJonathan Doman boost::system::error_code ec, 707c951448aSJonathan Doman const MapperGetSubTreeResponse& subtree) mutable { 708ac6a4445SGunnar Mills if (ec) 709ac6a4445SGunnar Mills { 710c951448aSJonathan Doman BMCWEB_LOG_DEBUG << "DBUS response error: " << ec; 711c951448aSJonathan Doman messages::internalError(resp->res); 712ac6a4445SGunnar Mills return; 713ac6a4445SGunnar Mills } 7142bab9831SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 715ac6a4445SGunnar Mills { 7162bab9831SJonathan Doman // Ignore any objects which don't end with our desired cpu name 7172bab9831SJonathan Doman if (!boost::ends_with(objectPath, processorId)) 718ac6a4445SGunnar Mills { 7192bab9831SJonathan Doman continue; 720ac6a4445SGunnar Mills } 7212bab9831SJonathan Doman 722c951448aSJonathan Doman bool found = false; 723c951448aSJonathan Doman // Filter out objects that don't have the CPU-specific 724c951448aSJonathan Doman // interfaces to make sure we can return 404 on non-CPUs 725c951448aSJonathan Doman // (e.g. /redfish/../Processors/dimm0) 7262bab9831SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 727ac6a4445SGunnar Mills { 728c951448aSJonathan Doman if (std::find_first_of( 729c951448aSJonathan Doman interfaceList.begin(), interfaceList.end(), 730c951448aSJonathan Doman processorInterfaces.begin(), 731c951448aSJonathan Doman processorInterfaces.end()) != interfaceList.end()) 7322bab9831SJonathan Doman { 733c951448aSJonathan Doman found = true; 734c951448aSJonathan Doman break; 735c951448aSJonathan Doman } 736c951448aSJonathan Doman } 737c951448aSJonathan Doman 738c951448aSJonathan Doman if (!found) 7392bab9831SJonathan Doman { 740c951448aSJonathan Doman continue; 741ac6a4445SGunnar Mills } 742c951448aSJonathan Doman 743c951448aSJonathan Doman // Process the first object which does match our cpu name and 744c951448aSJonathan Doman // required interfaces, and potentially ignore any other 745c951448aSJonathan Doman // matching objects. Assume all interfaces we want to process 746c951448aSJonathan Doman // must be on the same object path. 747c951448aSJonathan Doman 748c951448aSJonathan Doman handler(resp, processorId, objectPath, serviceMap); 749ac6a4445SGunnar Mills return; 750ac6a4445SGunnar Mills } 751c951448aSJonathan Doman messages::resourceNotFound(resp->res, "Processor", processorId); 752ac6a4445SGunnar Mills }, 753ac6a4445SGunnar Mills "xyz.openbmc_project.ObjectMapper", 754ac6a4445SGunnar Mills "/xyz/openbmc_project/object_mapper", 755ac6a4445SGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 7562bab9831SJonathan Doman "/xyz/openbmc_project/inventory", 0, 75749e429caSJonathan Doman std::array<const char*, 8>{ 75871b82f26SSharad Yadav "xyz.openbmc_project.Common.UUID", 7592bab9831SJonathan Doman "xyz.openbmc_project.Inventory.Decorator.Asset", 7602bab9831SJonathan Doman "xyz.openbmc_project.Inventory.Decorator.Revision", 7612bab9831SJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu", 762cba4f448SSunnySrivastava1984 "xyz.openbmc_project.Inventory.Decorator.LocationCode", 763dba0c291SJonathan Doman "xyz.openbmc_project.Inventory.Item.Accelerator", 76449e429caSJonathan Doman "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 76549e429caSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier"}); 766ac6a4445SGunnar Mills } 767ac6a4445SGunnar Mills 7688d1b46d7Szhanghch05 inline void getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 769c951448aSJonathan Doman const std::string& processorId, 770c951448aSJonathan Doman const std::string& objectPath, 771c951448aSJonathan Doman const MapperServiceMap& serviceMap) 772c951448aSJonathan Doman { 773c951448aSJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 774c951448aSJonathan Doman { 775c951448aSJonathan Doman for (const auto& interface : interfaceList) 776c951448aSJonathan Doman { 777c951448aSJonathan Doman if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") 778c951448aSJonathan Doman { 779c951448aSJonathan Doman getCpuAssetData(aResp, serviceName, objectPath); 780c951448aSJonathan Doman } 7810fda0f12SGeorge Liu else if (interface == 7820fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Revision") 783c951448aSJonathan Doman { 784c951448aSJonathan Doman getCpuRevisionData(aResp, serviceName, objectPath); 785c951448aSJonathan Doman } 786c951448aSJonathan Doman else if (interface == "xyz.openbmc_project.Inventory.Item.Cpu") 787c951448aSJonathan Doman { 788c951448aSJonathan Doman getCpuDataByService(aResp, processorId, serviceName, 789c951448aSJonathan Doman objectPath); 790c951448aSJonathan Doman } 7910fda0f12SGeorge Liu else if (interface == 7920fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Accelerator") 793c951448aSJonathan Doman { 794c951448aSJonathan Doman getAcceleratorDataByService(aResp, processorId, serviceName, 795c951448aSJonathan Doman objectPath); 796c951448aSJonathan Doman } 7970fda0f12SGeorge Liu else if ( 7980fda0f12SGeorge Liu interface == 7990fda0f12SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig") 800c951448aSJonathan Doman { 801c951448aSJonathan Doman getCpuConfigData(aResp, processorId, serviceName, objectPath); 802c951448aSJonathan Doman } 8030fda0f12SGeorge Liu else if (interface == 8040fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 805c951448aSJonathan Doman { 806c951448aSJonathan Doman getCpuLocationCode(aResp, serviceName, objectPath); 807c951448aSJonathan Doman } 80871b82f26SSharad Yadav else if (interface == "xyz.openbmc_project.Common.UUID") 80971b82f26SSharad Yadav { 81071b82f26SSharad Yadav getProcessorUUID(aResp, serviceName, objectPath); 81171b82f26SSharad Yadav } 8120fda0f12SGeorge Liu else if (interface == 8130fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier") 81449e429caSJonathan Doman { 81549e429caSJonathan Doman getCpuUniqueId(aResp, serviceName, objectPath); 81649e429caSJonathan Doman } 817c951448aSJonathan Doman } 818c951448aSJonathan Doman } 819c951448aSJonathan Doman } 820c951448aSJonathan Doman 821dba0c291SJonathan Doman /** 822dba0c291SJonathan Doman * Request all the properties for the given D-Bus object and fill out the 823dba0c291SJonathan Doman * related entries in the Redfish OperatingConfig response. 824dba0c291SJonathan Doman * 825dba0c291SJonathan Doman * @param[in,out] aResp Async HTTP response. 826dba0c291SJonathan Doman * @param[in] service D-Bus service name to query. 827dba0c291SJonathan Doman * @param[in] objPath D-Bus object to query. 828dba0c291SJonathan Doman */ 8298d1b46d7Szhanghch05 inline void 8308d1b46d7Szhanghch05 getOperatingConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 831dba0c291SJonathan Doman const std::string& service, 832dba0c291SJonathan Doman const std::string& objPath) 833dba0c291SJonathan Doman { 834dba0c291SJonathan Doman crow::connections::systemBus->async_method_call( 835dba0c291SJonathan Doman [aResp](boost::system::error_code ec, 836dba0c291SJonathan Doman const OperatingConfigProperties& properties) { 837dba0c291SJonathan Doman if (ec) 838dba0c291SJonathan Doman { 839dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 840dba0c291SJonathan Doman << ec.message(); 841dba0c291SJonathan Doman messages::internalError(aResp->res); 842dba0c291SJonathan Doman return; 843dba0c291SJonathan Doman } 844dba0c291SJonathan Doman 845dba0c291SJonathan Doman nlohmann::json& json = aResp->res.jsonValue; 846dba0c291SJonathan Doman for (const auto& [key, variant] : properties) 847dba0c291SJonathan Doman { 848dba0c291SJonathan Doman if (key == "AvailableCoreCount") 849dba0c291SJonathan Doman { 850dba0c291SJonathan Doman const size_t* cores = std::get_if<size_t>(&variant); 851dba0c291SJonathan Doman if (cores != nullptr) 852dba0c291SJonathan Doman { 853dba0c291SJonathan Doman json["TotalAvailableCoreCount"] = *cores; 854dba0c291SJonathan Doman } 855dba0c291SJonathan Doman } 856dba0c291SJonathan Doman else if (key == "BaseSpeed") 857dba0c291SJonathan Doman { 858dba0c291SJonathan Doman const uint32_t* speed = std::get_if<uint32_t>(&variant); 859dba0c291SJonathan Doman if (speed != nullptr) 860dba0c291SJonathan Doman { 861dba0c291SJonathan Doman json["BaseSpeedMHz"] = *speed; 862dba0c291SJonathan Doman } 863dba0c291SJonathan Doman } 864dba0c291SJonathan Doman else if (key == "MaxJunctionTemperature") 865dba0c291SJonathan Doman { 866dba0c291SJonathan Doman const uint32_t* temp = std::get_if<uint32_t>(&variant); 867dba0c291SJonathan Doman if (temp != nullptr) 868dba0c291SJonathan Doman { 869dba0c291SJonathan Doman json["MaxJunctionTemperatureCelsius"] = *temp; 870dba0c291SJonathan Doman } 871dba0c291SJonathan Doman } 872dba0c291SJonathan Doman else if (key == "MaxSpeed") 873dba0c291SJonathan Doman { 874dba0c291SJonathan Doman const uint32_t* speed = std::get_if<uint32_t>(&variant); 875dba0c291SJonathan Doman if (speed != nullptr) 876dba0c291SJonathan Doman { 877dba0c291SJonathan Doman json["MaxSpeedMHz"] = *speed; 878dba0c291SJonathan Doman } 879dba0c291SJonathan Doman } 880dba0c291SJonathan Doman else if (key == "PowerLimit") 881dba0c291SJonathan Doman { 882dba0c291SJonathan Doman const uint32_t* tdp = std::get_if<uint32_t>(&variant); 883dba0c291SJonathan Doman if (tdp != nullptr) 884dba0c291SJonathan Doman { 885dba0c291SJonathan Doman json["TDPWatts"] = *tdp; 886dba0c291SJonathan Doman } 887dba0c291SJonathan Doman } 888dba0c291SJonathan Doman else if (key == "TurboProfile") 889dba0c291SJonathan Doman { 890dba0c291SJonathan Doman const auto* turboList = 891dba0c291SJonathan Doman std::get_if<TurboProfileProperty>(&variant); 892dba0c291SJonathan Doman if (turboList == nullptr) 893dba0c291SJonathan Doman { 894dba0c291SJonathan Doman continue; 895dba0c291SJonathan Doman } 896dba0c291SJonathan Doman 897dba0c291SJonathan Doman nlohmann::json& turboArray = json["TurboProfile"]; 898dba0c291SJonathan Doman turboArray = nlohmann::json::array(); 899dba0c291SJonathan Doman for (const auto& [turboSpeed, coreCount] : *turboList) 900dba0c291SJonathan Doman { 901dba0c291SJonathan Doman turboArray.push_back({{"ActiveCoreCount", coreCount}, 902dba0c291SJonathan Doman {"MaxSpeedMHz", turboSpeed}}); 903dba0c291SJonathan Doman } 904dba0c291SJonathan Doman } 905dba0c291SJonathan Doman else if (key == "BaseSpeedPrioritySettings") 906dba0c291SJonathan Doman { 907dba0c291SJonathan Doman const auto* baseSpeedList = 908dba0c291SJonathan Doman std::get_if<BaseSpeedPrioritySettingsProperty>( 909dba0c291SJonathan Doman &variant); 910dba0c291SJonathan Doman if (baseSpeedList == nullptr) 911dba0c291SJonathan Doman { 912dba0c291SJonathan Doman continue; 913dba0c291SJonathan Doman } 914dba0c291SJonathan Doman 915dba0c291SJonathan Doman nlohmann::json& baseSpeedArray = 916dba0c291SJonathan Doman json["BaseSpeedPrioritySettings"]; 917dba0c291SJonathan Doman baseSpeedArray = nlohmann::json::array(); 918dba0c291SJonathan Doman for (const auto& [baseSpeed, coreList] : *baseSpeedList) 919dba0c291SJonathan Doman { 920dba0c291SJonathan Doman baseSpeedArray.push_back( 921dba0c291SJonathan Doman {{"CoreCount", coreList.size()}, 922dba0c291SJonathan Doman {"CoreIDs", coreList}, 923dba0c291SJonathan Doman {"BaseSpeedMHz", baseSpeed}}); 924dba0c291SJonathan Doman } 925dba0c291SJonathan Doman } 926dba0c291SJonathan Doman } 927dba0c291SJonathan Doman }, 928dba0c291SJonathan Doman service, objPath, "org.freedesktop.DBus.Properties", "GetAll", 929dba0c291SJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"); 930dba0c291SJonathan Doman } 931dba0c291SJonathan Doman 9323cde86f1SJonathan Doman /** 9333cde86f1SJonathan Doman * Handle the D-Bus response from attempting to set the CPU's AppliedConfig 9343cde86f1SJonathan Doman * property. Main task is to translate error messages into Redfish errors. 9353cde86f1SJonathan Doman * 9363cde86f1SJonathan Doman * @param[in,out] resp HTTP response. 9373cde86f1SJonathan Doman * @param[in] setPropVal Value which we attempted to set. 9383cde86f1SJonathan Doman * @param[in] ec D-Bus response error code. 9393cde86f1SJonathan Doman * @param[in] msg D-Bus response message. 9403cde86f1SJonathan Doman */ 9413cde86f1SJonathan Doman inline void 9423cde86f1SJonathan Doman handleAppliedConfigResponse(const std::shared_ptr<bmcweb::AsyncResp>& resp, 9433cde86f1SJonathan Doman const std::string& setPropVal, 9443cde86f1SJonathan Doman boost::system::error_code ec, 9453cde86f1SJonathan Doman const sdbusplus::message::message& msg) 9463cde86f1SJonathan Doman { 9473cde86f1SJonathan Doman if (!ec) 9483cde86f1SJonathan Doman { 9493cde86f1SJonathan Doman BMCWEB_LOG_DEBUG << "Set Property succeeded"; 9503cde86f1SJonathan Doman return; 9513cde86f1SJonathan Doman } 9523cde86f1SJonathan Doman 9533cde86f1SJonathan Doman BMCWEB_LOG_DEBUG << "Set Property failed: " << ec; 9543cde86f1SJonathan Doman 9553cde86f1SJonathan Doman const sd_bus_error* dbusError = msg.get_error(); 9563cde86f1SJonathan Doman if (dbusError == nullptr) 9573cde86f1SJonathan Doman { 9583cde86f1SJonathan Doman messages::internalError(resp->res); 9593cde86f1SJonathan Doman return; 9603cde86f1SJonathan Doman } 9613cde86f1SJonathan Doman 9623cde86f1SJonathan Doman // The asio error code doesn't know about our custom errors, so we have to 9633cde86f1SJonathan Doman // parse the error string. Some of these D-Bus -> Redfish translations are a 9643cde86f1SJonathan Doman // stretch, but it's good to try to communicate something vaguely useful. 9653cde86f1SJonathan Doman if (strcmp(dbusError->name, 9663cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.InvalidArgument") == 0) 9673cde86f1SJonathan Doman { 9683cde86f1SJonathan Doman // Service did not like the object_path we tried to set. 9693cde86f1SJonathan Doman messages::propertyValueIncorrect( 9703cde86f1SJonathan Doman resp->res, "AppliedOperatingConfig/@odata.id", setPropVal); 9713cde86f1SJonathan Doman } 9723cde86f1SJonathan Doman else if (strcmp(dbusError->name, 9733cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.NotAllowed") == 0) 9743cde86f1SJonathan Doman { 9753cde86f1SJonathan Doman // Service indicates we can never change the config for this processor. 9763cde86f1SJonathan Doman messages::propertyNotWritable(resp->res, "AppliedOperatingConfig"); 9773cde86f1SJonathan Doman } 9783cde86f1SJonathan Doman else if (strcmp(dbusError->name, 9793cde86f1SJonathan Doman "xyz.openbmc_project.Common.Error.Unavailable") == 0) 9803cde86f1SJonathan Doman { 9813cde86f1SJonathan Doman // Service indicates the config cannot be changed right now, but maybe 9823cde86f1SJonathan Doman // in a different system state. 9833cde86f1SJonathan Doman messages::resourceInStandby(resp->res); 9843cde86f1SJonathan Doman } 9853cde86f1SJonathan Doman else if (strcmp(dbusError->name, 9863cde86f1SJonathan Doman "xyz.openbmc_project.Common.Device.Error.WriteFailure") == 9873cde86f1SJonathan Doman 0) 9883cde86f1SJonathan Doman { 9893cde86f1SJonathan Doman // Service tried to change the config, but it failed. 9903cde86f1SJonathan Doman messages::operationFailed(resp->res); 9913cde86f1SJonathan Doman } 9923cde86f1SJonathan Doman else 9933cde86f1SJonathan Doman { 9943cde86f1SJonathan Doman messages::internalError(resp->res); 9953cde86f1SJonathan Doman } 9963cde86f1SJonathan Doman } 9973cde86f1SJonathan Doman 9983cde86f1SJonathan Doman /** 9993cde86f1SJonathan Doman * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic 10003cde86f1SJonathan Doman * validation of the input data, and then set the D-Bus property. 10013cde86f1SJonathan Doman * 10023cde86f1SJonathan Doman * @param[in,out] resp Async HTTP response. 10033cde86f1SJonathan Doman * @param[in] processorId Processor's Id. 10043cde86f1SJonathan Doman * @param[in] appliedConfigUri New property value to apply. 10053cde86f1SJonathan Doman * @param[in] cpuObjectPath Path of CPU object to modify. 10063cde86f1SJonathan Doman * @param[in] serviceMap Service map for CPU object. 10073cde86f1SJonathan Doman */ 10083cde86f1SJonathan Doman inline void patchAppliedOperatingConfig( 10093cde86f1SJonathan Doman const std::shared_ptr<bmcweb::AsyncResp>& resp, 10103cde86f1SJonathan Doman const std::string& processorId, const std::string& appliedConfigUri, 10113cde86f1SJonathan Doman const std::string& cpuObjectPath, const MapperServiceMap& serviceMap) 10123cde86f1SJonathan Doman { 10133cde86f1SJonathan Doman // Check that the property even exists by checking for the interface 10143cde86f1SJonathan Doman const std::string* controlService = nullptr; 10153cde86f1SJonathan Doman for (const auto& [serviceName, interfaceList] : serviceMap) 10163cde86f1SJonathan Doman { 10173cde86f1SJonathan Doman if (std::find(interfaceList.begin(), interfaceList.end(), 10183cde86f1SJonathan Doman "xyz.openbmc_project.Control.Processor." 10193cde86f1SJonathan Doman "CurrentOperatingConfig") != interfaceList.end()) 10203cde86f1SJonathan Doman { 10213cde86f1SJonathan Doman controlService = &serviceName; 10223cde86f1SJonathan Doman break; 10233cde86f1SJonathan Doman } 10243cde86f1SJonathan Doman } 10253cde86f1SJonathan Doman 10263cde86f1SJonathan Doman if (controlService == nullptr) 10273cde86f1SJonathan Doman { 10283cde86f1SJonathan Doman messages::internalError(resp->res); 10293cde86f1SJonathan Doman return; 10303cde86f1SJonathan Doman } 10313cde86f1SJonathan Doman 10323cde86f1SJonathan Doman // Check that the config URI is a child of the cpu URI being patched. 10333cde86f1SJonathan Doman std::string expectedPrefix("/redfish/v1/Systems/system/Processors/"); 10343cde86f1SJonathan Doman expectedPrefix += processorId; 10353cde86f1SJonathan Doman expectedPrefix += "/OperatingConfigs/"; 10363cde86f1SJonathan Doman if (!boost::starts_with(appliedConfigUri, expectedPrefix) || 10373cde86f1SJonathan Doman expectedPrefix.size() == appliedConfigUri.size()) 10383cde86f1SJonathan Doman { 10393cde86f1SJonathan Doman messages::propertyValueIncorrect( 10403cde86f1SJonathan Doman resp->res, "AppliedOperatingConfig/@odata.id", appliedConfigUri); 10413cde86f1SJonathan Doman return; 10423cde86f1SJonathan Doman } 10433cde86f1SJonathan Doman 10443cde86f1SJonathan Doman // Generate the D-Bus path of the OperatingConfig object, by assuming it's a 10453cde86f1SJonathan Doman // direct child of the CPU object. 10463cde86f1SJonathan Doman // Strip the expectedPrefix from the config URI to get the "filename", and 10473cde86f1SJonathan Doman // append to the CPU's path. 10483cde86f1SJonathan Doman std::string configBaseName = appliedConfigUri.substr(expectedPrefix.size()); 10493cde86f1SJonathan Doman sdbusplus::message::object_path configPath(cpuObjectPath); 10503cde86f1SJonathan Doman configPath /= configBaseName; 10513cde86f1SJonathan Doman 10523cde86f1SJonathan Doman BMCWEB_LOG_INFO << "Setting config to " << configPath.str; 10533cde86f1SJonathan Doman 10543cde86f1SJonathan Doman // Set the property, with handler to check error responses 10553cde86f1SJonathan Doman crow::connections::systemBus->async_method_call( 10563cde86f1SJonathan Doman [resp, appliedConfigUri](boost::system::error_code ec, 10573cde86f1SJonathan Doman sdbusplus::message::message& msg) { 10583cde86f1SJonathan Doman handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg); 10593cde86f1SJonathan Doman }, 10603cde86f1SJonathan Doman *controlService, cpuObjectPath, "org.freedesktop.DBus.Properties", 10613cde86f1SJonathan Doman "Set", "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", 1062168e20c1SEd Tanous "AppliedConfig", dbus::utility::DbusVariantType(std::move(configPath))); 10633cde86f1SJonathan Doman } 10643cde86f1SJonathan Doman 10657e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfigCollection(App& app) 1066dba0c291SJonathan Doman { 1067dba0c291SJonathan Doman 10687e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 10697e860f15SJohn Edward Broadbent app, "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/") 1070ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfigCollection) 10710fda0f12SGeorge Liu .methods( 10720fda0f12SGeorge Liu boost::beast::http::verb::get)([](const crow::Request& req, 10730fda0f12SGeorge Liu const std::shared_ptr< 10740fda0f12SGeorge Liu bmcweb::AsyncResp>& asyncResp, 10757e860f15SJohn Edward Broadbent const std::string& cpuName) { 10768d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1077dba0c291SJonathan Doman "#OperatingConfigCollection.OperatingConfigCollection"; 10788d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = req.url; 10790fda0f12SGeorge Liu asyncResp->res.jsonValue["Name"] = "Operating Config Collection"; 1080dba0c291SJonathan Doman 10817e860f15SJohn Edward Broadbent // First find the matching CPU object so we know how to 10827e860f15SJohn Edward Broadbent // constrain our search for related Config objects. 1083dba0c291SJonathan Doman crow::connections::systemBus->async_method_call( 10840fda0f12SGeorge Liu [asyncResp, cpuName](const boost::system::error_code ec, 1085dba0c291SJonathan Doman const std::vector<std::string>& objects) { 1086dba0c291SJonathan Doman if (ec) 1087dba0c291SJonathan Doman { 1088dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 1089dba0c291SJonathan Doman << ec.message(); 1090dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1091dba0c291SJonathan Doman return; 1092dba0c291SJonathan Doman } 1093dba0c291SJonathan Doman 1094dba0c291SJonathan Doman for (const std::string& object : objects) 1095dba0c291SJonathan Doman { 1096dba0c291SJonathan Doman if (!boost::ends_with(object, cpuName)) 1097dba0c291SJonathan Doman { 1098dba0c291SJonathan Doman continue; 1099dba0c291SJonathan Doman } 1100dba0c291SJonathan Doman 11017e860f15SJohn Edward Broadbent // Not expected that there will be multiple matching 11027e860f15SJohn Edward Broadbent // CPU objects, but if there are just use the first 11037e860f15SJohn Edward Broadbent // one. 1104dba0c291SJonathan Doman 11057e860f15SJohn Edward Broadbent // Use the common search routine to construct the 11067e860f15SJohn Edward Broadbent // Collection of all Config objects under this CPU. 1107dba0c291SJonathan Doman collection_util::getCollectionMembers( 1108dba0c291SJonathan Doman asyncResp, 11090fda0f12SGeorge Liu "/redfish/v1/Systems/system/Processors/" + cpuName + 11100fda0f12SGeorge Liu "/OperatingConfigs", 11110fda0f12SGeorge Liu {"xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}, 1112dba0c291SJonathan Doman object.c_str()); 1113dba0c291SJonathan Doman return; 1114dba0c291SJonathan Doman } 1115dba0c291SJonathan Doman }, 1116dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", 1117dba0c291SJonathan Doman "/xyz/openbmc_project/object_mapper", 1118dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 1119dba0c291SJonathan Doman "/xyz/openbmc_project/inventory", 0, 11207e860f15SJohn Edward Broadbent std::array<const char*, 1>{ 11210fda0f12SGeorge Liu "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"}); 11227e860f15SJohn Edward Broadbent }); 1123dba0c291SJonathan Doman } 1124dba0c291SJonathan Doman 11257e860f15SJohn Edward Broadbent inline void requestRoutesOperatingConfig(App& app) 1126dba0c291SJonathan Doman { 11277e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 11287e860f15SJohn Edward Broadbent app, 11297e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/<str>/") 1130ed398213SEd Tanous .privileges(redfish::privileges::getOperatingConfig) 11317e860f15SJohn Edward Broadbent .methods( 11327e860f15SJohn Edward Broadbent boost::beast::http::verb::get)([](const crow::Request& req, 11337e860f15SJohn Edward Broadbent const std::shared_ptr< 11347e860f15SJohn Edward Broadbent bmcweb::AsyncResp>& asyncResp, 11357e860f15SJohn Edward Broadbent const std::string& cpuName, 11367e860f15SJohn Edward Broadbent const std::string& configName) { 11377e860f15SJohn Edward Broadbent // Ask for all objects implementing OperatingConfig so we can search 11387e860f15SJohn Edward Broadbent // for one with a matching name 1139dba0c291SJonathan Doman crow::connections::systemBus->async_method_call( 1140dba0c291SJonathan Doman [asyncResp, cpuName, configName, 1141dba0c291SJonathan Doman reqUrl{req.url}](boost::system::error_code ec, 1142dba0c291SJonathan Doman const MapperGetSubTreeResponse& subtree) { 1143dba0c291SJonathan Doman if (ec) 1144dba0c291SJonathan Doman { 1145dba0c291SJonathan Doman BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 1146dba0c291SJonathan Doman << ec.message(); 1147dba0c291SJonathan Doman messages::internalError(asyncResp->res); 1148dba0c291SJonathan Doman return; 1149dba0c291SJonathan Doman } 11507e860f15SJohn Edward Broadbent const std::string expectedEnding = 11517e860f15SJohn Edward Broadbent cpuName + '/' + configName; 1152dba0c291SJonathan Doman for (const auto& [objectPath, serviceMap] : subtree) 1153dba0c291SJonathan Doman { 1154dba0c291SJonathan Doman // Ignore any configs without matching cpuX/configY 1155dba0c291SJonathan Doman if (!boost::ends_with(objectPath, expectedEnding) || 1156dba0c291SJonathan Doman serviceMap.empty()) 1157dba0c291SJonathan Doman { 1158dba0c291SJonathan Doman continue; 1159dba0c291SJonathan Doman } 1160dba0c291SJonathan Doman 1161dba0c291SJonathan Doman nlohmann::json& json = asyncResp->res.jsonValue; 1162dba0c291SJonathan Doman json["@odata.type"] = 1163dba0c291SJonathan Doman "#OperatingConfig.v1_0_0.OperatingConfig"; 1164dba0c291SJonathan Doman json["@odata.id"] = reqUrl; 1165dba0c291SJonathan Doman json["Name"] = "Processor Profile"; 1166dba0c291SJonathan Doman json["Id"] = configName; 1167dba0c291SJonathan Doman 1168dba0c291SJonathan Doman // Just use the first implementation of the object - not 11697e860f15SJohn Edward Broadbent // expected that there would be multiple matching 11707e860f15SJohn Edward Broadbent // services 11717e860f15SJohn Edward Broadbent getOperatingConfigData( 11727e860f15SJohn Edward Broadbent asyncResp, serviceMap.begin()->first, objectPath); 1173dba0c291SJonathan Doman return; 1174dba0c291SJonathan Doman } 11757e860f15SJohn Edward Broadbent messages::resourceNotFound(asyncResp->res, 11767e860f15SJohn Edward Broadbent "OperatingConfig", configName); 1177dba0c291SJonathan Doman }, 1178dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", 1179dba0c291SJonathan Doman "/xyz/openbmc_project/object_mapper", 1180dba0c291SJonathan Doman "xyz.openbmc_project.ObjectMapper", "GetSubTree", 1181dba0c291SJonathan Doman "/xyz/openbmc_project/inventory", 0, 1182dba0c291SJonathan Doman std::array<const char*, 1>{ 1183dba0c291SJonathan Doman "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"}); 11847e860f15SJohn Edward Broadbent }); 1185ac6a4445SGunnar Mills } 1186ac6a4445SGunnar Mills 11877e860f15SJohn Edward Broadbent inline void requestRoutesProcessorCollection(App& app) 11887e860f15SJohn Edward Broadbent { 1189ac6a4445SGunnar Mills /** 1190ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1191ac6a4445SGunnar Mills */ 11927e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/") 1193ed398213SEd Tanous .privileges(redfish::privileges::getProcessorCollection) 11947e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 11957e860f15SJohn Edward Broadbent [](const crow::Request&, 11967e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 11978d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1198ac6a4445SGunnar Mills "#ProcessorCollection.ProcessorCollection"; 11998d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Processor Collection"; 1200ac6a4445SGunnar Mills 12018d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = 12028d1b46d7Szhanghch05 "/redfish/v1/Systems/system/Processors"; 1203ac6a4445SGunnar Mills 120405030b8eSGunnar Mills collection_util::getCollectionMembers( 120505030b8eSGunnar Mills asyncResp, "/redfish/v1/Systems/system/Processors", 1206c951448aSJonathan Doman std::vector<const char*>(processorInterfaces.begin(), 1207c951448aSJonathan Doman processorInterfaces.end())); 12087e860f15SJohn Edward Broadbent }); 1209ac6a4445SGunnar Mills } 1210ac6a4445SGunnar Mills 12117e860f15SJohn Edward Broadbent inline void requestRoutesProcessor(App& app) 12127e860f15SJohn Edward Broadbent { 1213ac6a4445SGunnar Mills /** 1214ac6a4445SGunnar Mills * Functions triggers appropriate requests on DBus 1215ac6a4445SGunnar Mills */ 12167e860f15SJohn Edward Broadbent 12177e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/<str>/") 1218ed398213SEd Tanous .privileges(redfish::privileges::getProcessor) 12197e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 12207e860f15SJohn Edward Broadbent [](const crow::Request&, 12217e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12227e860f15SJohn Edward Broadbent const std::string& processorId) { 12238d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 12248d1b46d7Szhanghch05 "#Processor.v1_11_0.Processor"; 12258d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = 1226ac6a4445SGunnar Mills "/redfish/v1/Systems/system/Processors/" + processorId; 1227ac6a4445SGunnar Mills 1228c951448aSJonathan Doman getProcessorObject(asyncResp, processorId, getProcessorData); 12297e860f15SJohn Edward Broadbent }); 12303cde86f1SJonathan Doman 12317e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/<str>/") 1232ed398213SEd Tanous .privileges(redfish::privileges::patchProcessor) 12337e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 12347e860f15SJohn Edward Broadbent [](const crow::Request& req, 12357e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12367e860f15SJohn Edward Broadbent const std::string& processorId) { 12373cde86f1SJonathan Doman std::optional<nlohmann::json> appliedConfigJson; 12387e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, 12397e860f15SJohn Edward Broadbent "AppliedOperatingConfig", 12403cde86f1SJonathan Doman appliedConfigJson)) 12413cde86f1SJonathan Doman { 12423cde86f1SJonathan Doman return; 12433cde86f1SJonathan Doman } 12443cde86f1SJonathan Doman 12453cde86f1SJonathan Doman std::string appliedConfigUri; 12463cde86f1SJonathan Doman if (appliedConfigJson) 12473cde86f1SJonathan Doman { 12483cde86f1SJonathan Doman if (!json_util::readJson(*appliedConfigJson, asyncResp->res, 12493cde86f1SJonathan Doman "@odata.id", appliedConfigUri)) 12503cde86f1SJonathan Doman { 12513cde86f1SJonathan Doman return; 12523cde86f1SJonathan Doman } 12537e860f15SJohn Edward Broadbent // Check for 404 and find matching D-Bus object, then run 12547e860f15SJohn Edward Broadbent // property patch handlers if that all succeeds. 12553cde86f1SJonathan Doman getProcessorObject( 12567e860f15SJohn Edward Broadbent asyncResp, processorId, 12573cde86f1SJonathan Doman [appliedConfigUri = std::move(appliedConfigUri)]( 12583cde86f1SJonathan Doman const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12593cde86f1SJonathan Doman const std::string& processorId, 12603cde86f1SJonathan Doman const std::string& objectPath, 12613cde86f1SJonathan Doman const MapperServiceMap& serviceMap) { 12623cde86f1SJonathan Doman patchAppliedOperatingConfig(asyncResp, processorId, 12637e860f15SJohn Edward Broadbent appliedConfigUri, 12647e860f15SJohn Edward Broadbent objectPath, serviceMap); 12653cde86f1SJonathan Doman }); 12663cde86f1SJonathan Doman } 12677e860f15SJohn Edward Broadbent }); 12683cde86f1SJonathan Doman } 1269ac6a4445SGunnar Mills 1270ac6a4445SGunnar Mills } // namespace redfish 1271