blob: 4d6861f5974fa96a19e8aac8f6a27d711ae3cd6d [file] [log] [blame]
Harshit Agherad837b562025-04-21 19:50:10 +05301/*
2 * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION &
Harshit Aghera560e6af2025-04-21 20:04:56 +05303 * AFFILIATES. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
Harshit Agherad837b562025-04-21 19:50:10 +05305 */
6
7#pragma once
8
Harshit Aghera560e6af2025-04-21 20:04:56 +05309#include "MctpRequester.hpp"
Harshit Agherad837b562025-04-21 19:50:10 +053010#include "Thresholds.hpp"
Harshit Agherad837b562025-04-21 19:50:10 +053011#include "sensor.hpp"
12
Harshit Aghera560e6af2025-04-21 20:04:56 +053013#include <NvidiaGpuMctpVdm.hpp>
Harshit Agherad837b562025-04-21 19:50:10 +053014#include <sdbusplus/asio/connection.hpp>
15#include <sdbusplus/asio/object_server.hpp>
Harshit Agherad837b562025-04-21 19:50:10 +053016
Harshit Aghera560e6af2025-04-21 20:04:56 +053017#include <array>
Harshit Aghera560e6af2025-04-21 20:04:56 +053018#include <cstdint>
Harshit Agherad837b562025-04-21 19:50:10 +053019#include <memory>
20#include <string>
21#include <vector>
22
Harshit Agheraba138da2025-05-05 12:26:35 +053023constexpr uint8_t gpuTempSensorId{0};
24constexpr uint8_t gpuTLimitSensorId{2};
Harshit Agherab10a67b2025-05-27 12:19:29 +053025constexpr uint8_t gpuDramTempSensorId{1};
Harshit Aghera8951c872025-06-25 15:25:33 +053026constexpr uint8_t smaTempSensorId{5};
Harshit Agheraba138da2025-05-05 12:26:35 +053027
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053028struct NvidiaGpuTempSensor :
Harshit Agherad837b562025-04-21 19:50:10 +053029 public Sensor,
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053030 public std::enable_shared_from_this<NvidiaGpuTempSensor>
Harshit Agherad837b562025-04-21 19:50:10 +053031{
32 public:
Harshit Agheraba138da2025-05-05 12:26:35 +053033 NvidiaGpuTempSensor(
34 std::shared_ptr<sdbusplus::asio::connection>& conn,
35 mctp::MctpRequester& mctpRequester, const std::string& name,
36 const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId,
37 sdbusplus::asio::object_server& objectServer,
38 std::vector<thresholds::Threshold>&& thresholdData);
Harshit Agherad837b562025-04-21 19:50:10 +053039
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053040 ~NvidiaGpuTempSensor() override;
Harshit Agherad837b562025-04-21 19:50:10 +053041
Harshit Agherad837b562025-04-21 19:50:10 +053042 void checkThresholds() override;
43
Harshit Aghera560e6af2025-04-21 20:04:56 +053044 void update();
45
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053046 private:
Marc Olberdingd0125c92025-10-08 14:37:19 -070047 void processResponse(const std::error_code& ec,
48 std::span<const uint8_t> buffer);
Harshit Aghera560e6af2025-04-21 20:04:56 +053049
Harshit Aghera560e6af2025-04-21 20:04:56 +053050 uint8_t eid{};
51
52 uint8_t sensorId;
53
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053054 std::shared_ptr<sdbusplus::asio::connection> conn;
Harshit Agherad837b562025-04-21 19:50:10 +053055
Harshit Aghera560e6af2025-04-21 20:04:56 +053056 mctp::MctpRequester& mctpRequester;
57
Harshit Agherad837b562025-04-21 19:50:10 +053058 sdbusplus::asio::object_server& objectServer;
Harshit Aghera560e6af2025-04-21 20:04:56 +053059
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053060 std::array<uint8_t, sizeof(gpu::GetTemperatureReadingRequest)>
Harshit Aghera560e6af2025-04-21 20:04:56 +053061 getTemperatureReadingRequest{};
Harshit Aghera3f6bc732025-07-23 14:22:01 +053062
63 std::shared_ptr<sdbusplus::asio::dbus_interface> sensorTypeInterface;
Harshit Agherad837b562025-04-21 19:50:10 +053064};