1*e0b80e1eSHarshit Aghera /*
2*e0b80e1eSHarshit Aghera * SPDX-FileCopyrightText: Copyright OpenBMC Authors
3*e0b80e1eSHarshit Aghera * SPDX-License-Identifier: Apache-2.0
4*e0b80e1eSHarshit Aghera */
5*e0b80e1eSHarshit Aghera
6*e0b80e1eSHarshit Aghera #include "NvidiaPcieDevice.hpp"
7*e0b80e1eSHarshit Aghera
8*e0b80e1eSHarshit Aghera #include "NvidiaDeviceDiscovery.hpp"
9*e0b80e1eSHarshit Aghera #include "NvidiaPcieInterface.hpp"
10*e0b80e1eSHarshit Aghera #include "Utils.hpp"
11*e0b80e1eSHarshit Aghera
12*e0b80e1eSHarshit Aghera #include <MctpRequester.hpp>
13*e0b80e1eSHarshit Aghera #include <boost/asio/io_context.hpp>
14*e0b80e1eSHarshit Aghera #include <phosphor-logging/lg2.hpp>
15*e0b80e1eSHarshit Aghera #include <sdbusplus/asio/connection.hpp>
16*e0b80e1eSHarshit Aghera #include <sdbusplus/asio/object_server.hpp>
17*e0b80e1eSHarshit Aghera
18*e0b80e1eSHarshit Aghera #include <chrono>
19*e0b80e1eSHarshit Aghera #include <cstdint>
20*e0b80e1eSHarshit Aghera #include <memory>
21*e0b80e1eSHarshit Aghera #include <string>
22*e0b80e1eSHarshit Aghera
PcieDevice(const SensorConfigs & configs,const std::string & name,const std::string & path,const std::shared_ptr<sdbusplus::asio::connection> & conn,uint8_t eid,boost::asio::io_context & io,mctp::MctpRequester & mctpRequester,sdbusplus::asio::object_server & objectServer)23*e0b80e1eSHarshit Aghera PcieDevice::PcieDevice(const SensorConfigs& configs, const std::string& name,
24*e0b80e1eSHarshit Aghera const std::string& path,
25*e0b80e1eSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& conn,
26*e0b80e1eSHarshit Aghera uint8_t eid, boost::asio::io_context& io,
27*e0b80e1eSHarshit Aghera mctp::MctpRequester& mctpRequester,
28*e0b80e1eSHarshit Aghera sdbusplus::asio::object_server& objectServer) :
29*e0b80e1eSHarshit Aghera eid(eid), sensorPollMs(std::chrono::milliseconds{configs.pollRate}),
30*e0b80e1eSHarshit Aghera waitTimer(io, std::chrono::steady_clock::duration(0)),
31*e0b80e1eSHarshit Aghera mctpRequester(mctpRequester), conn(conn), objectServer(objectServer),
32*e0b80e1eSHarshit Aghera configs(configs), name(escapeName(name)), path(path)
33*e0b80e1eSHarshit Aghera {}
34*e0b80e1eSHarshit Aghera
init()35*e0b80e1eSHarshit Aghera void PcieDevice::init()
36*e0b80e1eSHarshit Aghera {
37*e0b80e1eSHarshit Aghera makeSensors();
38*e0b80e1eSHarshit Aghera }
39*e0b80e1eSHarshit Aghera
makeSensors()40*e0b80e1eSHarshit Aghera void PcieDevice::makeSensors()
41*e0b80e1eSHarshit Aghera {
42*e0b80e1eSHarshit Aghera pcieInterface = std::make_shared<NvidiaPcieInterface>(
43*e0b80e1eSHarshit Aghera conn, mctpRequester, name, path, eid, objectServer);
44*e0b80e1eSHarshit Aghera
45*e0b80e1eSHarshit Aghera lg2::info("Added PCIe {NAME} Sensors with chassis path: {PATH}.", "NAME",
46*e0b80e1eSHarshit Aghera name, "PATH", path);
47*e0b80e1eSHarshit Aghera
48*e0b80e1eSHarshit Aghera read();
49*e0b80e1eSHarshit Aghera }
50*e0b80e1eSHarshit Aghera
read()51*e0b80e1eSHarshit Aghera void PcieDevice::read()
52*e0b80e1eSHarshit Aghera {
53*e0b80e1eSHarshit Aghera pcieInterface->update();
54*e0b80e1eSHarshit Aghera
55*e0b80e1eSHarshit Aghera waitTimer.expires_after(std::chrono::milliseconds(sensorPollMs));
56*e0b80e1eSHarshit Aghera waitTimer.async_wait([this](const boost::system::error_code& ec) {
57*e0b80e1eSHarshit Aghera if (ec)
58*e0b80e1eSHarshit Aghera {
59*e0b80e1eSHarshit Aghera return;
60*e0b80e1eSHarshit Aghera }
61*e0b80e1eSHarshit Aghera read();
62*e0b80e1eSHarshit Aghera });
63*e0b80e1eSHarshit Aghera }
64