14ecdfaaaSHarshit Aghera /* 24ecdfaaaSHarshit Aghera * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & 34ecdfaaaSHarshit Aghera * AFFILIATES. All rights reserved. 44ecdfaaaSHarshit Aghera * SPDX-License-Identifier: Apache-2.0 54ecdfaaaSHarshit Aghera */ 64ecdfaaaSHarshit Aghera 74ecdfaaaSHarshit Aghera #include "NvidiaDeviceDiscovery.hpp" 84ecdfaaaSHarshit Aghera 94ecdfaaaSHarshit Aghera #include "NvidiaGpuDevice.hpp" 10*8951c87eSHarshit Aghera #include "NvidiaSmaDevice.hpp" 114ecdfaaaSHarshit Aghera #include "Utils.hpp" 124ecdfaaaSHarshit Aghera 134ecdfaaaSHarshit Aghera #include <bits/basic_string.h> 144ecdfaaaSHarshit Aghera 154ecdfaaaSHarshit Aghera #include <MctpRequester.hpp> 164ecdfaaaSHarshit Aghera #include <NvidiaGpuMctpVdm.hpp> 174ecdfaaaSHarshit Aghera #include <OcpMctpVdm.hpp> 184ecdfaaaSHarshit Aghera #include <boost/asio/io_context.hpp> 194ecdfaaaSHarshit Aghera #include <boost/container/flat_map.hpp> 204ecdfaaaSHarshit Aghera #include <phosphor-logging/lg2.hpp> 214ecdfaaaSHarshit Aghera #include <sdbusplus/asio/connection.hpp> 224ecdfaaaSHarshit Aghera #include <sdbusplus/asio/object_server.hpp> 234ecdfaaaSHarshit Aghera #include <sdbusplus/message.hpp> 244ecdfaaaSHarshit Aghera #include <sdbusplus/message/native_types.hpp> 254ecdfaaaSHarshit Aghera 264ecdfaaaSHarshit Aghera #include <algorithm> 274ecdfaaaSHarshit Aghera #include <array> 284ecdfaaaSHarshit Aghera #include <cstdint> 294ecdfaaaSHarshit Aghera #include <memory> 304ecdfaaaSHarshit Aghera #include <span> 314ecdfaaaSHarshit Aghera #include <string> 324ecdfaaaSHarshit Aghera #include <utility> 334ecdfaaaSHarshit Aghera #include <variant> 344ecdfaaaSHarshit Aghera #include <vector> 354ecdfaaaSHarshit Aghera 364ecdfaaaSHarshit Aghera void processQueryDeviceIdResponse( 374ecdfaaaSHarshit Aghera boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 384ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 394ecdfaaaSHarshit Aghera gpuDevices, 40*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 41*8951c87eSHarshit Aghera smaDevices, 424ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& conn, 434ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester, const SensorConfigs& configs, 444ecdfaaaSHarshit Aghera const std::string& path, uint8_t eid, int sendRecvMsgResult, 454ecdfaaaSHarshit Aghera std::span<uint8_t> queryDeviceIdentificationResponse) 464ecdfaaaSHarshit Aghera { 474ecdfaaaSHarshit Aghera if (sendRecvMsgResult != 0) 484ecdfaaaSHarshit Aghera { 494ecdfaaaSHarshit Aghera lg2::error( 504ecdfaaaSHarshit Aghera "Error processing MCTP endpoint with eid {EID} : sending message over MCTP failed, rc={RC}", 514ecdfaaaSHarshit Aghera "EID", eid, "RC", sendRecvMsgResult); 524ecdfaaaSHarshit Aghera return; 534ecdfaaaSHarshit Aghera } 544ecdfaaaSHarshit Aghera 554ecdfaaaSHarshit Aghera ocp::accelerator_management::CompletionCode cc{}; 564ecdfaaaSHarshit Aghera uint16_t reasonCode = 0; 574ecdfaaaSHarshit Aghera uint8_t responseDeviceType = 0; 584ecdfaaaSHarshit Aghera uint8_t responseInstanceId = 0; 594ecdfaaaSHarshit Aghera 604ecdfaaaSHarshit Aghera auto rc = gpu::decodeQueryDeviceIdentificationResponse( 614ecdfaaaSHarshit Aghera queryDeviceIdentificationResponse, cc, reasonCode, responseDeviceType, 624ecdfaaaSHarshit Aghera responseInstanceId); 634ecdfaaaSHarshit Aghera 644ecdfaaaSHarshit Aghera if (rc != 0 || cc != ocp::accelerator_management::CompletionCode::SUCCESS) 654ecdfaaaSHarshit Aghera { 664ecdfaaaSHarshit Aghera lg2::error( 674ecdfaaaSHarshit Aghera "Error processing MCTP endpoint with eid {EID} : decode failed, rc={RC}, cc={CC}, reasonCode={RESC}", 684ecdfaaaSHarshit Aghera "EID", eid, "RC", rc, "CC", cc, "RESC", reasonCode); 694ecdfaaaSHarshit Aghera return; 704ecdfaaaSHarshit Aghera } 714ecdfaaaSHarshit Aghera 72*8951c87eSHarshit Aghera switch (static_cast<gpu::DeviceIdentification>(responseDeviceType)) 73*8951c87eSHarshit Aghera { 74*8951c87eSHarshit Aghera case gpu::DeviceIdentification::DEVICE_GPU: 754ecdfaaaSHarshit Aghera { 764ecdfaaaSHarshit Aghera lg2::info( 774ecdfaaaSHarshit Aghera "Found the GPU with EID {EID}, DeviceType {DEVTYPE}, InstanceId {IID}.", 784ecdfaaaSHarshit Aghera "EID", eid, "DEVTYPE", responseDeviceType, "IID", 794ecdfaaaSHarshit Aghera responseInstanceId); 804ecdfaaaSHarshit Aghera 81*8951c87eSHarshit Aghera auto gpuName = configs.name + '_' + 82*8951c87eSHarshit Aghera std::to_string(responseInstanceId); 834ecdfaaaSHarshit Aghera 84*8951c87eSHarshit Aghera gpuDevices[gpuName] = 85*8951c87eSHarshit Aghera std::make_shared<GpuDevice>(configs, gpuName, path, conn, eid, 86*8951c87eSHarshit Aghera io, mctpRequester, objectServer); 87*8951c87eSHarshit Aghera break; 88*8951c87eSHarshit Aghera } 89*8951c87eSHarshit Aghera 90*8951c87eSHarshit Aghera case gpu::DeviceIdentification::DEVICE_SMA: 91*8951c87eSHarshit Aghera { 92*8951c87eSHarshit Aghera lg2::info( 93*8951c87eSHarshit Aghera "Found the SMA Device with EID {EID}, DeviceType {DEVTYPE}, InstanceId {IID}.", 94*8951c87eSHarshit Aghera "EID", eid, "DEVTYPE", responseDeviceType, "IID", 95*8951c87eSHarshit Aghera responseInstanceId); 96*8951c87eSHarshit Aghera 97*8951c87eSHarshit Aghera auto smaName = configs.name + "_SMA_" + 98*8951c87eSHarshit Aghera std::to_string(responseInstanceId); 99*8951c87eSHarshit Aghera 100*8951c87eSHarshit Aghera smaDevices[smaName] = 101*8951c87eSHarshit Aghera std::make_shared<SmaDevice>(configs, smaName, path, conn, eid, 102*8951c87eSHarshit Aghera io, mctpRequester, objectServer); 103*8951c87eSHarshit Aghera break; 104*8951c87eSHarshit Aghera } 1054ecdfaaaSHarshit Aghera } 1064ecdfaaaSHarshit Aghera } 1074ecdfaaaSHarshit Aghera 1084ecdfaaaSHarshit Aghera void queryDeviceIdentification( 1094ecdfaaaSHarshit Aghera boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 1104ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 1114ecdfaaaSHarshit Aghera gpuDevices, 112*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 113*8951c87eSHarshit Aghera smaDevices, 1144ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& conn, 1154ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester, const SensorConfigs& configs, 1164ecdfaaaSHarshit Aghera const std::string& path, uint8_t eid) 1174ecdfaaaSHarshit Aghera { 1184ecdfaaaSHarshit Aghera auto queryDeviceIdentificationRequest = std::make_shared< 1194ecdfaaaSHarshit Aghera std::array<uint8_t, sizeof(gpu::QueryDeviceIdentificationRequest)>>(); 1204ecdfaaaSHarshit Aghera 1214ecdfaaaSHarshit Aghera auto queryDeviceIdentificationResponse = std::make_shared< 1224ecdfaaaSHarshit Aghera std::array<uint8_t, sizeof(gpu::QueryDeviceIdentificationResponse)>>(); 1234ecdfaaaSHarshit Aghera 1244ecdfaaaSHarshit Aghera auto rc = gpu::encodeQueryDeviceIdentificationRequest( 1254ecdfaaaSHarshit Aghera 0, *queryDeviceIdentificationRequest); 1264ecdfaaaSHarshit Aghera if (rc != 0) 1274ecdfaaaSHarshit Aghera { 1284ecdfaaaSHarshit Aghera lg2::error( 1294ecdfaaaSHarshit Aghera "Error processing MCTP endpoint with eid {EID} : encode failed, rc={RC}", 1304ecdfaaaSHarshit Aghera "EID", eid, "RC", rc); 1314ecdfaaaSHarshit Aghera return; 1324ecdfaaaSHarshit Aghera } 1334ecdfaaaSHarshit Aghera 1344ecdfaaaSHarshit Aghera mctpRequester.sendRecvMsg( 1354ecdfaaaSHarshit Aghera eid, *queryDeviceIdentificationRequest, 1364ecdfaaaSHarshit Aghera *queryDeviceIdentificationResponse, 137*8951c87eSHarshit Aghera [&io, &objectServer, &gpuDevices, &smaDevices, conn, &mctpRequester, 138*8951c87eSHarshit Aghera configs, path, eid, queryDeviceIdentificationRequest, 1394ecdfaaaSHarshit Aghera queryDeviceIdentificationResponse](int sendRecvMsgResult) { 1404ecdfaaaSHarshit Aghera processQueryDeviceIdResponse( 141*8951c87eSHarshit Aghera io, objectServer, gpuDevices, smaDevices, conn, mctpRequester, 142*8951c87eSHarshit Aghera configs, path, eid, sendRecvMsgResult, 1434ecdfaaaSHarshit Aghera *queryDeviceIdentificationResponse); 1444ecdfaaaSHarshit Aghera }); 1454ecdfaaaSHarshit Aghera } 1464ecdfaaaSHarshit Aghera 1474ecdfaaaSHarshit Aghera void processEndpoint( 1484ecdfaaaSHarshit Aghera boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 1494ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 1504ecdfaaaSHarshit Aghera gpuDevices, 151*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 152*8951c87eSHarshit Aghera smaDevices, 1534ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& conn, 1544ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester, const SensorConfigs& configs, 1554ecdfaaaSHarshit Aghera const std::string& path, const boost::system::error_code& ec, 1564ecdfaaaSHarshit Aghera const SensorBaseConfigMap& endpoint) 1574ecdfaaaSHarshit Aghera { 1584ecdfaaaSHarshit Aghera if (ec) 1594ecdfaaaSHarshit Aghera { 1604ecdfaaaSHarshit Aghera lg2::error("Error processing MCTP endpoint: Error:{ERROR}", "ERROR", 1614ecdfaaaSHarshit Aghera ec.message()); 1624ecdfaaaSHarshit Aghera return; 1634ecdfaaaSHarshit Aghera } 1644ecdfaaaSHarshit Aghera 1654ecdfaaaSHarshit Aghera auto hasEid = endpoint.find("EID"); 1664ecdfaaaSHarshit Aghera uint8_t eid{}; 1674ecdfaaaSHarshit Aghera 1684ecdfaaaSHarshit Aghera if (hasEid != endpoint.end()) 1694ecdfaaaSHarshit Aghera { 1704ecdfaaaSHarshit Aghera const auto* eidPtr = std::get_if<uint8_t>(&hasEid->second); 1714ecdfaaaSHarshit Aghera if (eidPtr != nullptr) 1724ecdfaaaSHarshit Aghera { 1734ecdfaaaSHarshit Aghera eid = *eidPtr; 1744ecdfaaaSHarshit Aghera } 1754ecdfaaaSHarshit Aghera else 1764ecdfaaaSHarshit Aghera { 1774ecdfaaaSHarshit Aghera lg2::error( 1784ecdfaaaSHarshit Aghera "Error processing MCTP endpoint: Property EID does not have valid type."); 1794ecdfaaaSHarshit Aghera return; 1804ecdfaaaSHarshit Aghera } 1814ecdfaaaSHarshit Aghera } 1824ecdfaaaSHarshit Aghera else 1834ecdfaaaSHarshit Aghera { 1844ecdfaaaSHarshit Aghera lg2::error( 1854ecdfaaaSHarshit Aghera "Error processing MCTP endpoint: Property EID not found in the configuration."); 1864ecdfaaaSHarshit Aghera return; 1874ecdfaaaSHarshit Aghera } 1884ecdfaaaSHarshit Aghera 1894ecdfaaaSHarshit Aghera auto hasMctpTypes = endpoint.find("SupportedMessageTypes"); 1904ecdfaaaSHarshit Aghera std::vector<uint8_t> mctpTypes{}; 1914ecdfaaaSHarshit Aghera 1924ecdfaaaSHarshit Aghera if (hasMctpTypes != endpoint.end()) 1934ecdfaaaSHarshit Aghera { 1944ecdfaaaSHarshit Aghera const auto* mctpTypePtr = 1954ecdfaaaSHarshit Aghera std::get_if<std::vector<uint8_t>>(&hasMctpTypes->second); 1964ecdfaaaSHarshit Aghera if (mctpTypePtr != nullptr) 1974ecdfaaaSHarshit Aghera { 1984ecdfaaaSHarshit Aghera mctpTypes = *mctpTypePtr; 1994ecdfaaaSHarshit Aghera } 2004ecdfaaaSHarshit Aghera else 2014ecdfaaaSHarshit Aghera { 2024ecdfaaaSHarshit Aghera lg2::error( 2034ecdfaaaSHarshit Aghera "Error processing MCTP endpoint with eid {EID} : Property SupportedMessageTypes does not have valid type.", 2044ecdfaaaSHarshit Aghera "EID", eid); 2054ecdfaaaSHarshit Aghera return; 2064ecdfaaaSHarshit Aghera } 2074ecdfaaaSHarshit Aghera } 2084ecdfaaaSHarshit Aghera else 2094ecdfaaaSHarshit Aghera { 2104ecdfaaaSHarshit Aghera lg2::error( 2114ecdfaaaSHarshit Aghera "Error processing MCTP endpoint with eid {EID} : Property SupportedMessageTypes not found in the configuration.", 2124ecdfaaaSHarshit Aghera "EID", eid); 2134ecdfaaaSHarshit Aghera return; 2144ecdfaaaSHarshit Aghera } 2154ecdfaaaSHarshit Aghera 2164ecdfaaaSHarshit Aghera if (std::find(mctpTypes.begin(), mctpTypes.end(), 2174ecdfaaaSHarshit Aghera ocp::accelerator_management::messageType) != mctpTypes.end()) 2184ecdfaaaSHarshit Aghera { 2194ecdfaaaSHarshit Aghera lg2::info("Found OCP MCTP VDM Endpoint with ID {EID}", "EID", eid); 220*8951c87eSHarshit Aghera queryDeviceIdentification(io, objectServer, gpuDevices, smaDevices, 221*8951c87eSHarshit Aghera conn, mctpRequester, configs, path, eid); 2224ecdfaaaSHarshit Aghera } 2234ecdfaaaSHarshit Aghera } 2244ecdfaaaSHarshit Aghera 2254ecdfaaaSHarshit Aghera void queryEndpoints( 2264ecdfaaaSHarshit Aghera boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 2274ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 2284ecdfaaaSHarshit Aghera gpuDevices, 229*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 230*8951c87eSHarshit Aghera smaDevices, 2314ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& conn, 2324ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester, const SensorConfigs& configs, 2334ecdfaaaSHarshit Aghera const std::string& path, const boost::system::error_code& ec, 2344ecdfaaaSHarshit Aghera const GetSubTreeType& ret) 2354ecdfaaaSHarshit Aghera { 2364ecdfaaaSHarshit Aghera if (ec) 2374ecdfaaaSHarshit Aghera { 2384ecdfaaaSHarshit Aghera lg2::error("Error processing MCTP endpoints: {ERROR}", "ERROR", 2394ecdfaaaSHarshit Aghera ec.message()); 2404ecdfaaaSHarshit Aghera return; 2414ecdfaaaSHarshit Aghera } 2424ecdfaaaSHarshit Aghera 2434ecdfaaaSHarshit Aghera if (ret.empty()) 2444ecdfaaaSHarshit Aghera { 2454ecdfaaaSHarshit Aghera return; 2464ecdfaaaSHarshit Aghera } 2474ecdfaaaSHarshit Aghera 2484ecdfaaaSHarshit Aghera for (const auto& [objPath, services] : ret) 2494ecdfaaaSHarshit Aghera { 2504ecdfaaaSHarshit Aghera for (const auto& [service, ifaces] : services) 2514ecdfaaaSHarshit Aghera { 2524ecdfaaaSHarshit Aghera for (const auto& iface : ifaces) 2534ecdfaaaSHarshit Aghera { 2544ecdfaaaSHarshit Aghera if (iface == "xyz.openbmc_project.MCTP.Endpoint") 2554ecdfaaaSHarshit Aghera { 2564ecdfaaaSHarshit Aghera conn->async_method_call( 257*8951c87eSHarshit Aghera [&io, &objectServer, &gpuDevices, &smaDevices, conn, 258*8951c87eSHarshit Aghera &mctpRequester, configs, 259*8951c87eSHarshit Aghera path](const boost::system::error_code& ec, 2604ecdfaaaSHarshit Aghera const SensorBaseConfigMap& endpoint) { 261*8951c87eSHarshit Aghera processEndpoint(io, objectServer, gpuDevices, 262*8951c87eSHarshit Aghera smaDevices, conn, mctpRequester, 263*8951c87eSHarshit Aghera configs, path, ec, endpoint); 2644ecdfaaaSHarshit Aghera }, 2654ecdfaaaSHarshit Aghera service, objPath, "org.freedesktop.DBus.Properties", 2664ecdfaaaSHarshit Aghera "GetAll", iface); 2674ecdfaaaSHarshit Aghera } 2684ecdfaaaSHarshit Aghera } 2694ecdfaaaSHarshit Aghera } 2704ecdfaaaSHarshit Aghera } 2714ecdfaaaSHarshit Aghera } 2724ecdfaaaSHarshit Aghera 2734ecdfaaaSHarshit Aghera void discoverDevices( 2744ecdfaaaSHarshit Aghera boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 2754ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 2764ecdfaaaSHarshit Aghera gpuDevices, 277*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 278*8951c87eSHarshit Aghera smaDevices, 2794ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& conn, 2804ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester, const SensorConfigs& configs, 2814ecdfaaaSHarshit Aghera const std::string& path) 2824ecdfaaaSHarshit Aghera { 2834ecdfaaaSHarshit Aghera std::string searchPath{"/au/com/codeconstruct/"}; 2844ecdfaaaSHarshit Aghera std::vector<std::string> ifaceList{{"xyz.openbmc_project.MCTP.Endpoint"}}; 2854ecdfaaaSHarshit Aghera 2864ecdfaaaSHarshit Aghera conn->async_method_call( 287*8951c87eSHarshit Aghera [&io, &objectServer, &gpuDevices, &smaDevices, conn, &mctpRequester, 288*8951c87eSHarshit Aghera configs, 2894ecdfaaaSHarshit Aghera path](const boost::system::error_code& ec, const GetSubTreeType& ret) { 290*8951c87eSHarshit Aghera queryEndpoints(io, objectServer, gpuDevices, smaDevices, conn, 291*8951c87eSHarshit Aghera mctpRequester, configs, path, ec, ret); 2924ecdfaaaSHarshit Aghera }, 2934ecdfaaaSHarshit Aghera "xyz.openbmc_project.ObjectMapper", 2944ecdfaaaSHarshit Aghera "/xyz/openbmc_project/object_mapper", 2954ecdfaaaSHarshit Aghera "xyz.openbmc_project.ObjectMapper", "GetSubTree", searchPath, 0, 2964ecdfaaaSHarshit Aghera ifaceList); 2974ecdfaaaSHarshit Aghera } 2984ecdfaaaSHarshit Aghera 2994ecdfaaaSHarshit Aghera void processSensorConfigs( 3004ecdfaaaSHarshit Aghera boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 3014ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 3024ecdfaaaSHarshit Aghera gpuDevices, 303*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 304*8951c87eSHarshit Aghera smaDevices, 3054ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, 3064ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester, const ManagedObjectType& resp) 3074ecdfaaaSHarshit Aghera { 3084ecdfaaaSHarshit Aghera for (const auto& [path, interfaces] : resp) 3094ecdfaaaSHarshit Aghera { 3104ecdfaaaSHarshit Aghera for (const auto& [intf, cfg] : interfaces) 3114ecdfaaaSHarshit Aghera { 3124ecdfaaaSHarshit Aghera if (intf != configInterfaceName(deviceType)) 3134ecdfaaaSHarshit Aghera { 3144ecdfaaaSHarshit Aghera continue; 3154ecdfaaaSHarshit Aghera } 3164ecdfaaaSHarshit Aghera 3174ecdfaaaSHarshit Aghera SensorConfigs configs; 3184ecdfaaaSHarshit Aghera 3194ecdfaaaSHarshit Aghera configs.name = loadVariant<std::string>(cfg, "Name"); 3204ecdfaaaSHarshit Aghera 3214ecdfaaaSHarshit Aghera configs.pollRate = loadVariant<uint64_t>(cfg, "PollRate"); 3224ecdfaaaSHarshit Aghera 323*8951c87eSHarshit Aghera discoverDevices(io, objectServer, gpuDevices, smaDevices, 324*8951c87eSHarshit Aghera dbusConnection, mctpRequester, configs, path); 3254ecdfaaaSHarshit Aghera 3264ecdfaaaSHarshit Aghera lg2::info( 3274ecdfaaaSHarshit Aghera "Detected configuration {NAME} of type {TYPE} at path: {PATH}.", 3284ecdfaaaSHarshit Aghera "NAME", configs.name, "TYPE", deviceType, "PATH", path); 3294ecdfaaaSHarshit Aghera } 3304ecdfaaaSHarshit Aghera } 3314ecdfaaaSHarshit Aghera } 3324ecdfaaaSHarshit Aghera 3334ecdfaaaSHarshit Aghera void createSensors( 3344ecdfaaaSHarshit Aghera boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 3354ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 3364ecdfaaaSHarshit Aghera gpuDevices, 337*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 338*8951c87eSHarshit Aghera smaDevices, 3394ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, 3404ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester) 3414ecdfaaaSHarshit Aghera { 3424ecdfaaaSHarshit Aghera if (!dbusConnection) 3434ecdfaaaSHarshit Aghera { 3444ecdfaaaSHarshit Aghera lg2::error("Connection not created"); 3454ecdfaaaSHarshit Aghera return; 3464ecdfaaaSHarshit Aghera } 3474ecdfaaaSHarshit Aghera dbusConnection->async_method_call( 348*8951c87eSHarshit Aghera [&gpuDevices, &smaDevices, &mctpRequester, dbusConnection, &io, 349*8951c87eSHarshit Aghera &objectServer](boost::system::error_code ec, 350*8951c87eSHarshit Aghera const ManagedObjectType& resp) { 3514ecdfaaaSHarshit Aghera if (ec) 3524ecdfaaaSHarshit Aghera { 3534ecdfaaaSHarshit Aghera lg2::error("Error contacting entity manager"); 3544ecdfaaaSHarshit Aghera return; 3554ecdfaaaSHarshit Aghera } 3564ecdfaaaSHarshit Aghera 357*8951c87eSHarshit Aghera processSensorConfigs(io, objectServer, gpuDevices, smaDevices, 358*8951c87eSHarshit Aghera dbusConnection, mctpRequester, resp); 3594ecdfaaaSHarshit Aghera }, 3604ecdfaaaSHarshit Aghera entityManagerName, "/xyz/openbmc_project/inventory", 3614ecdfaaaSHarshit Aghera "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 3624ecdfaaaSHarshit Aghera } 3634ecdfaaaSHarshit Aghera 3644ecdfaaaSHarshit Aghera void interfaceRemoved( 3654ecdfaaaSHarshit Aghera sdbusplus::message_t& message, 3664ecdfaaaSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<GpuDevice>>& 367*8951c87eSHarshit Aghera gpuDevices, 368*8951c87eSHarshit Aghera boost::container::flat_map<std::string, std::shared_ptr<SmaDevice>>& 369*8951c87eSHarshit Aghera smaDevices) 3704ecdfaaaSHarshit Aghera { 3714ecdfaaaSHarshit Aghera if (message.is_method_error()) 3724ecdfaaaSHarshit Aghera { 3734ecdfaaaSHarshit Aghera lg2::error("interfacesRemoved callback method error"); 3744ecdfaaaSHarshit Aghera return; 3754ecdfaaaSHarshit Aghera } 3764ecdfaaaSHarshit Aghera 3774ecdfaaaSHarshit Aghera sdbusplus::message::object_path removedPath; 3784ecdfaaaSHarshit Aghera std::vector<std::string> interfaces; 3794ecdfaaaSHarshit Aghera 3804ecdfaaaSHarshit Aghera message.read(removedPath, interfaces); 3814ecdfaaaSHarshit Aghera 3824ecdfaaaSHarshit Aghera // If the xyz.openbmc_project.Confguration.X interface was removed 3834ecdfaaaSHarshit Aghera // for one or more sensors, delete those sensor objects. 3844ecdfaaaSHarshit Aghera auto sensorIt = gpuDevices.begin(); 3854ecdfaaaSHarshit Aghera while (sensorIt != gpuDevices.end()) 3864ecdfaaaSHarshit Aghera { 3874ecdfaaaSHarshit Aghera if ((sensorIt->second->getPath() == removedPath) && 3884ecdfaaaSHarshit Aghera (std::find(interfaces.begin(), interfaces.end(), 3894ecdfaaaSHarshit Aghera configInterfaceName(deviceType)) != interfaces.end())) 3904ecdfaaaSHarshit Aghera { 3914ecdfaaaSHarshit Aghera sensorIt = gpuDevices.erase(sensorIt); 3924ecdfaaaSHarshit Aghera } 3934ecdfaaaSHarshit Aghera else 3944ecdfaaaSHarshit Aghera { 3954ecdfaaaSHarshit Aghera sensorIt++; 3964ecdfaaaSHarshit Aghera } 3974ecdfaaaSHarshit Aghera } 398*8951c87eSHarshit Aghera 399*8951c87eSHarshit Aghera auto smaSensorIt = smaDevices.begin(); 400*8951c87eSHarshit Aghera while (smaSensorIt != smaDevices.end()) 401*8951c87eSHarshit Aghera { 402*8951c87eSHarshit Aghera if ((smaSensorIt->second->getPath() == removedPath) && 403*8951c87eSHarshit Aghera (std::find(interfaces.begin(), interfaces.end(), 404*8951c87eSHarshit Aghera configInterfaceName(deviceType)) != interfaces.end())) 405*8951c87eSHarshit Aghera { 406*8951c87eSHarshit Aghera smaSensorIt = smaDevices.erase(smaSensorIt); 407*8951c87eSHarshit Aghera } 408*8951c87eSHarshit Aghera else 409*8951c87eSHarshit Aghera { 410*8951c87eSHarshit Aghera smaSensorIt++; 411*8951c87eSHarshit Aghera } 412*8951c87eSHarshit Aghera } 4134ecdfaaaSHarshit Aghera } 414