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 gpuPowerSensorId{0}; 25 26 struct NvidiaGpuPowerSensor : 27 public Sensor, 28 public std::enable_shared_from_this<NvidiaGpuPowerSensor> 29 { 30 public: 31 NvidiaGpuPowerSensor( 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 ~NvidiaGpuPowerSensor() 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 uint8_t averagingInterval = 0; 53 54 std::shared_ptr<sdbusplus::asio::connection> conn; 55 56 mctp::MctpRequester& mctpRequester; 57 58 sdbusplus::asio::object_server& objectServer; 59 60 std::array<uint8_t, sizeof(gpu::GetPowerDrawRequest)> request{}; 61 }; 62