xref: /openbmc/dbus-sensors/src/nvidia-gpu/NvidiaGpuDevice.hpp (revision b5e823f73897a8d47087d91f3f936dc07506a6e1)
1 /*
2  * SPDX-FileCopyrightText: Copyright OpenBMC Authors
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include "Inventory.hpp"
9 #include "MctpRequester.hpp"
10 #include "NvidiaDeviceDiscovery.hpp"
11 #include "NvidiaGpuPowerSensor.hpp"
12 #include "NvidiaGpuSensor.hpp"
13 
14 #include <NvidiaGpuEnergySensor.hpp>
15 #include <NvidiaGpuPowerPeakReading.hpp>
16 #include <NvidiaGpuVoltageSensor.hpp>
17 #include <boost/asio/io_context.hpp>
18 #include <boost/asio/steady_timer.hpp>
19 #include <sdbusplus/asio/connection.hpp>
20 #include <sdbusplus/asio/object_server.hpp>
21 
22 #include <chrono>
23 #include <cstdint>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 class GpuDevice : public std::enable_shared_from_this<GpuDevice>
29 {
30   public:
31     GpuDevice(const SensorConfigs& configs, const std::string& name,
32               const std::string& path,
33               const std::shared_ptr<sdbusplus::asio::connection>& conn,
34               uint8_t eid, boost::asio::io_context& io,
35               mctp::MctpRequester& mctpRequester,
36               sdbusplus::asio::object_server& objectServer);
37 
getPath() const38     const std::string& getPath() const
39     {
40         return path;
41     }
42 
43     void init();
44 
45   private:
46     void makeSensors();
47 
48     void read();
49 
50     void processTLimitThresholds(const std::error_code& ec);
51 
52     void getTLimitThresholds();
53 
54     uint8_t eid{};
55 
56     void getNextThermalParameter();
57     void readThermalParameterCallback(const std::error_code& ec,
58                                       std::span<const uint8_t> buffer);
59 
60     std::chrono::milliseconds sensorPollMs;
61 
62     boost::asio::steady_timer waitTimer;
63 
64     mctp::MctpRequester& mctpRequester;
65 
66     std::shared_ptr<sdbusplus::asio::connection> conn;
67 
68     sdbusplus::asio::object_server& objectServer;
69 
70     std::shared_ptr<NvidiaGpuTempSensor> tempSensor;
71     std::shared_ptr<NvidiaGpuTempSensor> tLimitSensor;
72     std::shared_ptr<NvidiaGpuTempSensor> dramTempSensor;
73     std::shared_ptr<NvidiaGpuPowerSensor> powerSensor;
74     std::shared_ptr<NvidiaGpuPowerPeakReading> peakPower;
75     std::shared_ptr<NvidiaGpuEnergySensor> energySensor;
76     std::shared_ptr<NvidiaGpuVoltageSensor> voltageSensor;
77 
78     std::array<uint8_t, sizeof(gpu::ReadThermalParametersRequest)>
79         thermalParamReqMsg{};
80     std::array<int32_t, 3> thresholds{};
81     size_t current_threshold_index{};
82 
83     SensorConfigs configs;
84 
85     std::string name;
86 
87     std::string path;
88 
89     std::shared_ptr<Inventory> inventory;
90 };
91