Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & |
| 3 | * AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0 |
| 4 | */ |
| 5 | |
| 6 | #pragma once |
| 7 | |
Harshit Aghera | a3f24f4 | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 8 | #include "MctpRequester.hpp" |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 9 | #include "Thresholds.hpp" |
Harshit Aghera | 11b9c1a | 2025-04-29 17:34:25 +0530 | [diff] [blame^] | 10 | #include "UpdatableSensor.hpp" |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 11 | |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 12 | #include <sdbusplus/asio/connection.hpp> |
| 13 | #include <sdbusplus/asio/object_server.hpp> |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 14 | |
| 15 | #include <cstdint> |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 16 | #include <memory> |
| 17 | #include <string> |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 20 | /** |
| 21 | * @struct DeviceInfo |
| 22 | * @brief Contains information about a device |
| 23 | */ |
| 24 | struct DeviceInfo |
| 25 | { |
| 26 | uint8_t deviceType; |
| 27 | uint8_t instanceId; |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * @struct GpuTempSensor |
| 32 | * @brief Implements a GPU temperature sensor that monitors temperature values |
| 33 | * @details Inherits from Sensor base class and enables shared pointer |
| 34 | * management via std::enable_shared_from_this |
| 35 | */ |
| 36 | struct GpuTempSensor : |
Harshit Aghera | 11b9c1a | 2025-04-29 17:34:25 +0530 | [diff] [blame^] | 37 | public GpuSensor, |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 38 | public std::enable_shared_from_this<GpuTempSensor> |
| 39 | { |
| 40 | public: |
| 41 | /** |
| 42 | * @brief Constructor for GpuTempSensor |
Harshit Aghera | 11b9c1a | 2025-04-29 17:34:25 +0530 | [diff] [blame^] | 43 | * @param conn D-Bus connection for system communication |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 44 | * @param mctpRequester MCTP protocol requester for GPU communication |
Harshit Aghera | 11b9c1a | 2025-04-29 17:34:25 +0530 | [diff] [blame^] | 45 | * @param name Name of the sensor for identification in the system |
| 46 | * @param sensorConfiguration Configuration string for the sensor containing |
| 47 | * setup parameters |
| 48 | * @param eid EID of the device endpoint |
| 49 | * @param objectServer D-Bus object server for exposing sensor interfaces |
| 50 | * @param thresholdData Vector of threshold configurations for temperature |
| 51 | * monitoring |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 52 | */ |
| 53 | GpuTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
Harshit Aghera | a3f24f4 | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 54 | mctp::MctpRequester& mctpRequester, const std::string& name, |
Harshit Aghera | 11b9c1a | 2025-04-29 17:34:25 +0530 | [diff] [blame^] | 55 | const std::string& sensorConfiguration, uint8_t eid, |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 56 | sdbusplus::asio::object_server& objectServer, |
Harshit Aghera | 11b9c1a | 2025-04-29 17:34:25 +0530 | [diff] [blame^] | 57 | std::vector<thresholds::Threshold>&& thresholdData); |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * @brief Destructor |
| 61 | */ |
| 62 | ~GpuTempSensor() override; |
| 63 | |
| 64 | /** |
| 65 | * @brief Check if any thresholds have been crossed |
| 66 | * @details Overrides the base class method to implement GPU-specific |
| 67 | * threshold checking |
| 68 | */ |
| 69 | void checkThresholds() override; |
| 70 | |
| 71 | private: |
| 72 | /** |
Harshit Aghera | a3f24f4 | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 73 | * @brief Update the sensor reading |
| 74 | */ |
Harshit Aghera | 11b9c1a | 2025-04-29 17:34:25 +0530 | [diff] [blame^] | 75 | void update() final; |
Harshit Aghera | a3f24f4 | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * @brief MCTP endpoint ID |
| 79 | */ |
| 80 | uint8_t eid{}; |
| 81 | |
| 82 | /** |
| 83 | * @brief The sensor ID |
| 84 | */ |
| 85 | uint8_t sensorId; |
| 86 | |
| 87 | /** |
Harshit Aghera | a3f24f4 | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 88 | * @brief Reference to the MCTP requester for communication |
| 89 | */ |
| 90 | mctp::MctpRequester& mctpRequester; |
| 91 | |
| 92 | /** |
Harshit Aghera | acd375a | 2025-04-21 19:50:10 +0530 | [diff] [blame] | 93 | * @brief D-Bus object server |
| 94 | */ |
| 95 | sdbusplus::asio::object_server& objectServer; |
| 96 | }; |