xref: /openbmc/dbus-sensors/src/nvidia-gpu/NvidiaPcieInterface.hpp (revision e0b80e1e58bddcf218369f2f9e3ba2002b59b6f9)
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 #pragma once
7*e0b80e1eSHarshit Aghera 
8*e0b80e1eSHarshit Aghera #include "MctpRequester.hpp"
9*e0b80e1eSHarshit Aghera 
10*e0b80e1eSHarshit Aghera #include <NvidiaGpuMctpVdm.hpp>
11*e0b80e1eSHarshit Aghera #include <sdbusplus/asio/connection.hpp>
12*e0b80e1eSHarshit Aghera #include <sdbusplus/asio/object_server.hpp>
13*e0b80e1eSHarshit Aghera 
14*e0b80e1eSHarshit Aghera #include <array>
15*e0b80e1eSHarshit Aghera #include <cstddef>
16*e0b80e1eSHarshit Aghera #include <cstdint>
17*e0b80e1eSHarshit Aghera #include <memory>
18*e0b80e1eSHarshit Aghera #include <string>
19*e0b80e1eSHarshit Aghera #include <vector>
20*e0b80e1eSHarshit Aghera 
21*e0b80e1eSHarshit Aghera struct NvidiaPcieInterface :
22*e0b80e1eSHarshit Aghera     public std::enable_shared_from_this<NvidiaPcieInterface>
23*e0b80e1eSHarshit Aghera {
24*e0b80e1eSHarshit Aghera   public:
25*e0b80e1eSHarshit Aghera     NvidiaPcieInterface(std::shared_ptr<sdbusplus::asio::connection>& conn,
26*e0b80e1eSHarshit Aghera                         mctp::MctpRequester& mctpRequester,
27*e0b80e1eSHarshit Aghera                         const std::string& name, const std::string& path,
28*e0b80e1eSHarshit Aghera                         uint8_t eid,
29*e0b80e1eSHarshit Aghera                         sdbusplus::asio::object_server& objectServer);
30*e0b80e1eSHarshit Aghera 
31*e0b80e1eSHarshit Aghera     void update();
32*e0b80e1eSHarshit Aghera 
33*e0b80e1eSHarshit Aghera     static size_t decodeLinkWidth(uint32_t value);
34*e0b80e1eSHarshit Aghera 
35*e0b80e1eSHarshit Aghera   private:
36*e0b80e1eSHarshit Aghera     static constexpr size_t maxTelemetryValues = 64;
37*e0b80e1eSHarshit Aghera 
38*e0b80e1eSHarshit Aghera     void processResponse(const std::error_code& ec,
39*e0b80e1eSHarshit Aghera                          std::span<const uint8_t> response);
40*e0b80e1eSHarshit Aghera 
41*e0b80e1eSHarshit Aghera     static std::string mapPcieGeneration(uint32_t value);
42*e0b80e1eSHarshit Aghera 
43*e0b80e1eSHarshit Aghera     uint8_t eid{};
44*e0b80e1eSHarshit Aghera 
45*e0b80e1eSHarshit Aghera     std::string path;
46*e0b80e1eSHarshit Aghera 
47*e0b80e1eSHarshit Aghera     std::shared_ptr<sdbusplus::asio::connection> conn;
48*e0b80e1eSHarshit Aghera 
49*e0b80e1eSHarshit Aghera     mctp::MctpRequester& mctpRequester;
50*e0b80e1eSHarshit Aghera 
51*e0b80e1eSHarshit Aghera     std::array<uint8_t, sizeof(gpu::QueryScalarGroupTelemetryV2Request)>
52*e0b80e1eSHarshit Aghera         request{};
53*e0b80e1eSHarshit Aghera 
54*e0b80e1eSHarshit Aghera     std::shared_ptr<sdbusplus::asio::dbus_interface> pcieDeviceInterface;
55*e0b80e1eSHarshit Aghera     std::shared_ptr<sdbusplus::asio::dbus_interface> switchInterface;
56*e0b80e1eSHarshit Aghera 
57*e0b80e1eSHarshit Aghera     std::vector<uint32_t> telemetryValues{maxTelemetryValues};
58*e0b80e1eSHarshit Aghera };
59