blob: 7bb0d3165691b5abbc11e8e2894a24cc50f7c41b [file] [log] [blame]
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +05301/*
Ed Tanousb5e823f2025-10-09 20:28:42 -04002 * SPDX-FileCopyrightText: Copyright OpenBMC Authors
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +05303 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
Rohit PAI0a888262025-06-11 08:52:29 +05308#include "Inventory.hpp"
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +05309#include "MctpRequester.hpp"
10#include "NvidiaDeviceDiscovery.hpp"
Harshit Aghera902c6492025-05-08 15:57:42 +053011#include "NvidiaGpuPowerSensor.hpp"
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053012#include "NvidiaGpuSensor.hpp"
13
Harshit Aghera775199d2025-05-27 14:20:24 +053014#include <NvidiaGpuEnergySensor.hpp>
Harshit Aghera6b712322025-07-31 19:25:12 +053015#include <NvidiaGpuPowerPeakReading.hpp>
Harshit Agherabef4d412025-05-27 14:53:56 +053016#include <NvidiaGpuVoltageSensor.hpp>
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053017#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>
Harshit Aghera5e7decc2025-05-07 16:20:16 +053026#include <vector>
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053027
Marc Olberding6282a452025-09-28 22:00:09 -070028class GpuDevice : public std::enable_shared_from_this<GpuDevice>
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053029{
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
38 const std::string& getPath() const
39 {
40 return path;
41 }
42
Marc Olberdingac920732025-09-28 21:56:54 -070043 void init();
44
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053045 private:
46 void makeSensors();
47
48 void read();
49
Marc Olberding6282a452025-09-28 22:00:09 -070050 void processTLimitThresholds(const std::error_code& ec);
51
52 void getTLimitThresholds();
Harshit Aghera5e7decc2025-05-07 16:20:16 +053053
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053054 uint8_t eid{};
55
Marc Olberding6282a452025-09-28 22:00:09 -070056 void getNextThermalParameter();
57 void readThermalParameterCallback(const std::error_code& ec,
58 std::span<const uint8_t> buffer);
59
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053060 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;
Harshit Agheraba138da2025-05-05 12:26:35 +053071 std::shared_ptr<NvidiaGpuTempSensor> tLimitSensor;
Harshit Agherab10a67b2025-05-27 12:19:29 +053072 std::shared_ptr<NvidiaGpuTempSensor> dramTempSensor;
Harshit Aghera902c6492025-05-08 15:57:42 +053073 std::shared_ptr<NvidiaGpuPowerSensor> powerSensor;
Harshit Aghera6b712322025-07-31 19:25:12 +053074 std::shared_ptr<NvidiaGpuPowerPeakReading> peakPower;
Harshit Aghera775199d2025-05-27 14:20:24 +053075 std::shared_ptr<NvidiaGpuEnergySensor> energySensor;
Harshit Agherabef4d412025-05-27 14:53:56 +053076 std::shared_ptr<NvidiaGpuVoltageSensor> voltageSensor;
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053077
Marc Olberding6282a452025-09-28 22:00:09 -070078 std::array<uint8_t, sizeof(gpu::ReadThermalParametersRequest)>
79 thermalParamReqMsg{};
Marc Olberding1851f642025-09-29 10:44:46 -070080 std::array<int32_t, 3> thresholds{};
Marc Olberding6282a452025-09-28 22:00:09 -070081 size_t current_threshold_index{};
82
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053083 SensorConfigs configs;
84
85 std::string name;
86
87 std::string path;
Rohit PAI0a888262025-06-11 08:52:29 +053088
89 std::shared_ptr<Inventory> inventory;
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053090};