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