xref: /openbmc/dbus-sensors/src/nvidia-gpu/NvidiaGpuSensor.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 "MctpRequester.hpp"
9 #include "Thresholds.hpp"
10 #include "sensor.hpp"
11 
12 #include <NvidiaGpuMctpVdm.hpp>
13 #include <sdbusplus/asio/connection.hpp>
14 #include <sdbusplus/asio/object_server.hpp>
15 
16 #include <array>
17 #include <cstdint>
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 constexpr uint8_t gpuTempSensorId{0};
23 constexpr uint8_t gpuTLimitSensorId{2};
24 constexpr uint8_t gpuDramTempSensorId{1};
25 constexpr uint8_t smaTempSensorId{5};
26 
27 struct NvidiaGpuTempSensor :
28     public Sensor,
29     public std::enable_shared_from_this<NvidiaGpuTempSensor>
30 {
31   public:
32     NvidiaGpuTempSensor(
33         std::shared_ptr<sdbusplus::asio::connection>& conn,
34         mctp::MctpRequester& mctpRequester, const std::string& name,
35         const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId,
36         sdbusplus::asio::object_server& objectServer,
37         std::vector<thresholds::Threshold>&& thresholdData);
38 
39     ~NvidiaGpuTempSensor() override;
40 
41     void checkThresholds() override;
42 
43     void update();
44 
45   private:
46     void processResponse(const std::error_code& ec,
47                          std::span<const uint8_t> buffer);
48 
49     uint8_t eid{};
50 
51     uint8_t sensorId;
52 
53     std::shared_ptr<sdbusplus::asio::connection> conn;
54 
55     mctp::MctpRequester& mctpRequester;
56 
57     sdbusplus::asio::object_server& objectServer;
58 
59     std::array<uint8_t, sizeof(gpu::GetTemperatureReadingRequest)>
60         getTemperatureReadingRequest{};
61 
62     std::shared_ptr<sdbusplus::asio::dbus_interface> sensorTypeInterface;
63 };
64