blob: 0cdfda7f17ecdf1b20fa121376069d983833edcc [file] [log] [blame]
Harshit Aghera902c6492025-05-08 15:57:42 +05301/*
Ed Tanousb5e823f2025-10-09 20:28:42 -04002 * SPDX-FileCopyrightText: Copyright OpenBMC Authors
Harshit Aghera902c6492025-05-08 15:57:42 +05303 * 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 Olberdingd0125c92025-10-08 14:37:19 -070019#include <span>
Harshit Aghera902c6492025-05-08 15:57:42 +053020#include <string>
Marc Olberdingd0125c92025-10-08 14:37:19 -070021#include <system_error>
Harshit Aghera902c6492025-05-08 15:57:42 +053022#include <vector>
23
24constexpr uint8_t gpuPowerSensorId{0};
25
Marc Olberdingfd4a3772025-09-24 16:31:02 -070026struct NvidiaGpuPowerSensor :
27 public Sensor,
28 public std::enable_shared_from_this<NvidiaGpuPowerSensor>
Harshit Aghera902c6492025-05-08 15:57:42 +053029{
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 Olberdingd0125c92025-10-08 14:37:19 -070045 void processResponse(const std::error_code& ec,
46 std::span<const uint8_t> buffer);
Harshit Aghera902c6492025-05-08 15:57:42 +053047
48 uint8_t eid{};
49
50 uint8_t sensorId;
51
Ed Tanousaba6fca2025-09-29 13:53:20 -070052 uint8_t averagingInterval = 0;
Harshit Aghera902c6492025-05-08 15:57:42 +053053
54 std::shared_ptr<sdbusplus::asio::connection> conn;
55
56 mctp::MctpRequester& mctpRequester;
57
58 sdbusplus::asio::object_server& objectServer;
59
Harshit Aghera6b712322025-07-31 19:25:12 +053060 std::array<uint8_t, sizeof(gpu::GetPowerDrawRequest)> request{};
Harshit Aghera902c6492025-05-08 15:57:42 +053061};