| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 1 | /* |
| Ed Tanous | b5e823f | 2025-10-09 20:28:42 -0400 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +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> |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 19 | #include <span> |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 20 | #include <string> |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 21 | #include <system_error> |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
| 24 | constexpr uint8_t gpuPowerSensorId{0}; |
| 25 | |
| Marc Olberding | fd4a377 | 2025-09-24 16:31:02 -0700 | [diff] [blame] | 26 | struct NvidiaGpuPowerSensor : |
| 27 | public Sensor, |
| 28 | public std::enable_shared_from_this<NvidiaGpuPowerSensor> |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 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: |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 45 | void processResponse(const std::error_code& ec, |
| 46 | std::span<const uint8_t> buffer); |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 47 | |
| 48 | uint8_t eid{}; |
| 49 | |
| 50 | uint8_t sensorId; |
| 51 | |
| Ed Tanous | aba6fca | 2025-09-29 13:53:20 -0700 | [diff] [blame] | 52 | uint8_t averagingInterval = 0; |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 53 | |
| 54 | std::shared_ptr<sdbusplus::asio::connection> conn; |
| 55 | |
| 56 | mctp::MctpRequester& mctpRequester; |
| 57 | |
| 58 | sdbusplus::asio::object_server& objectServer; |
| 59 | |
| Harshit Aghera | 6b71232 | 2025-07-31 19:25:12 +0530 | [diff] [blame] | 60 | std::array<uint8_t, sizeof(gpu::GetPowerDrawRequest)> request{}; |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 61 | }; |