blob: 1e21f4d7a493662d157ab04fc43e84025f4b1db3 [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};
25
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053026struct NvidiaGpuTempSensor :
Harshit Agherad837b562025-04-21 19:50:10 +053027 public Sensor,
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053028 public std::enable_shared_from_this<NvidiaGpuTempSensor>
Harshit Agherad837b562025-04-21 19:50:10 +053029{
30 public:
Harshit Agheraba138da2025-05-05 12:26:35 +053031 NvidiaGpuTempSensor(
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);
Harshit Agherad837b562025-04-21 19:50:10 +053037
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053038 ~NvidiaGpuTempSensor() override;
Harshit Agherad837b562025-04-21 19:50:10 +053039
Harshit Agherad837b562025-04-21 19:50:10 +053040 void checkThresholds() override;
41
Harshit Aghera560e6af2025-04-21 20:04:56 +053042 void update();
43
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053044 private:
Harshit Aghera560e6af2025-04-21 20:04:56 +053045 void processResponse(int sendRecvMsgResult);
46
Harshit Aghera560e6af2025-04-21 20:04:56 +053047 uint8_t eid{};
48
49 uint8_t sensorId;
50
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053051 std::shared_ptr<sdbusplus::asio::connection> conn;
Harshit Agherad837b562025-04-21 19:50:10 +053052
Harshit Aghera560e6af2025-04-21 20:04:56 +053053 mctp::MctpRequester& mctpRequester;
54
Harshit Agherad837b562025-04-21 19:50:10 +053055 sdbusplus::asio::object_server& objectServer;
Harshit Aghera560e6af2025-04-21 20:04:56 +053056
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053057 std::array<uint8_t, sizeof(gpu::GetTemperatureReadingRequest)>
Harshit Aghera560e6af2025-04-21 20:04:56 +053058 getTemperatureReadingRequest{};
59
Harshit Aghera4ecdfaa2025-05-22 11:35:39 +053060 std::array<uint8_t, sizeof(gpu::GetTemperatureReadingResponse)>
Harshit Aghera560e6af2025-04-21 20:04:56 +053061 getTemperatureReadingResponse{};
Harshit Agherad837b562025-04-21 19:50:10 +053062};