xref: /openbmc/dbus-sensors/src/nvidia-gpu/NvidiaGpuVoltageSensor.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 <span>
20 #include <string>
21 #include <system_error>
22 #include <vector>
23 
24 constexpr uint8_t gpuVoltageSensorId{0};
25 
26 struct NvidiaGpuVoltageSensor :
27     public Sensor,
28     public std::enable_shared_from_this<NvidiaGpuVoltageSensor>
29 {
30   public:
31     NvidiaGpuVoltageSensor(
32         std::shared_ptr<sdbusplus::asio::connection>& conn,
33         mctp::MctpRequester& mctpRequester, const std::string& name,
34         const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId,
35         sdbusplus::asio::object_server& objectServer,
36         std::vector<thresholds::Threshold>&& thresholdData);
37 
38     ~NvidiaGpuVoltageSensor() override;
39 
40     void checkThresholds() override;
41 
42     void update();
43 
44   private:
45     void processResponse(const std::error_code& ec,
46                          std::span<const uint8_t> buffer);
47 
48     uint8_t eid{};
49 
50     uint8_t sensorId;
51 
52     std::shared_ptr<sdbusplus::asio::connection> conn;
53 
54     mctp::MctpRequester& mctpRequester;
55 
56     sdbusplus::asio::object_server& objectServer;
57 
58     std::array<uint8_t, sizeof(gpu::GetVoltageRequest)> request{};
59 };
60