| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 1 | /* |
| Ed Tanous | b5e823f | 2025-10-09 20:28:42 -0400 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 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 | |
| Marc Olberding | fd4a377 | 2025-09-24 16:31:02 -0700 | [diff] [blame] | 24 | struct NvidiaGpuEnergySensor : |
| 25 | public Sensor, |
| 26 | public std::enable_shared_from_this<NvidiaGpuEnergySensor> |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 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: |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 43 | void processResponse(const std::error_code& ec, |
| 44 | std::span<const uint8_t> buffer); |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 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{}; |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 57 | }; |