Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & |
| 3 | * AFFILIATES. All rights reserved. |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <OcpMctpVdm.hpp> |
| 10 | |
| 11 | #include <cstdint> |
| 12 | #include <span> |
| 13 | |
| 14 | namespace gpu |
| 15 | { |
| 16 | |
| 17 | constexpr uint16_t nvidiaPciVendorId = 0x10de; |
| 18 | |
| 19 | enum class MessageType : uint8_t |
| 20 | { |
| 21 | DEVICE_CAPABILITY_DISCOVERY = 0, |
| 22 | PLATFORM_ENVIRONMENTAL = 3 |
| 23 | }; |
| 24 | |
| 25 | enum class DeviceCapabilityDiscoveryCommands : uint8_t |
| 26 | { |
| 27 | QUERY_DEVICE_IDENTIFICATION = 0x09, |
| 28 | }; |
| 29 | |
| 30 | enum class PlatformEnvironmentalCommands : uint8_t |
| 31 | { |
| 32 | GET_TEMPERATURE_READING = 0x00, |
Harshit Aghera | 5e7decc | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 33 | READ_THERMAL_PARAMETERS = 0x02, |
Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame^] | 34 | GET_CURRENT_POWER_DRAW = 0x03, |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | enum class DeviceIdentification : uint8_t |
| 38 | { |
| 39 | DEVICE_GPU = 0 |
| 40 | }; |
| 41 | |
| 42 | struct QueryDeviceIdentificationRequest |
| 43 | { |
| 44 | ocp::accelerator_management::CommonRequest hdr; |
| 45 | } __attribute__((packed)); |
| 46 | |
| 47 | struct QueryDeviceIdentificationResponse |
| 48 | { |
| 49 | ocp::accelerator_management::CommonResponse hdr; |
| 50 | uint8_t device_identification; |
| 51 | uint8_t instance_id; |
| 52 | } __attribute__((packed)); |
| 53 | |
| 54 | struct GetNumericSensorReadingRequest |
| 55 | { |
| 56 | ocp::accelerator_management::CommonRequest hdr; |
| 57 | uint8_t sensor_id; |
| 58 | } __attribute__((packed)); |
| 59 | |
| 60 | using GetTemperatureReadingRequest = GetNumericSensorReadingRequest; |
| 61 | |
Harshit Aghera | 5e7decc | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 62 | using ReadThermalParametersRequest = GetNumericSensorReadingRequest; |
| 63 | |
Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame^] | 64 | struct GetCurrentPowerDrawRequest |
| 65 | { |
| 66 | ocp::accelerator_management::CommonRequest hdr; |
| 67 | uint8_t sensorId; |
| 68 | uint8_t averagingInterval; |
| 69 | } __attribute__((packed)); |
| 70 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 71 | struct GetTemperatureReadingResponse |
| 72 | { |
| 73 | ocp::accelerator_management::CommonResponse hdr; |
| 74 | int32_t reading; |
| 75 | } __attribute__((packed)); |
| 76 | |
Harshit Aghera | 5e7decc | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 77 | struct ReadThermalParametersResponse |
| 78 | { |
| 79 | ocp::accelerator_management::CommonResponse hdr; |
| 80 | int32_t threshold; |
| 81 | } __attribute__((packed)); |
| 82 | |
Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame^] | 83 | struct GetCurrentPowerDrawResponse |
| 84 | { |
| 85 | ocp::accelerator_management::CommonResponse hdr; |
| 86 | uint32_t power; |
| 87 | } __attribute__((packed)); |
| 88 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 89 | int packHeader(const ocp::accelerator_management::BindingPciVidInfo& hdr, |
| 90 | ocp::accelerator_management::BindingPciVid& msg); |
| 91 | |
| 92 | int encodeQueryDeviceIdentificationRequest(uint8_t instanceId, |
| 93 | std::span<uint8_t> buf); |
| 94 | |
| 95 | int decodeQueryDeviceIdentificationResponse( |
| 96 | std::span<const uint8_t> buf, |
| 97 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 98 | uint8_t& deviceIdentification, uint8_t& deviceInstance); |
| 99 | |
| 100 | int encodeGetTemperatureReadingRequest(uint8_t instanceId, uint8_t sensorId, |
| 101 | std::span<uint8_t> buf); |
| 102 | |
| 103 | int decodeGetTemperatureReadingResponse( |
| 104 | std::span<const uint8_t> buf, |
| 105 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 106 | double& temperatureReading); |
| 107 | |
Harshit Aghera | 5e7decc | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 108 | int encodeReadThermalParametersRequest(uint8_t instanceId, uint8_t sensorId, |
| 109 | std::span<uint8_t> buf); |
| 110 | |
| 111 | int decodeReadThermalParametersResponse( |
| 112 | std::span<const uint8_t> buf, |
| 113 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 114 | int32_t& threshold); |
| 115 | |
Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame^] | 116 | int encodeGetCurrentPowerDrawRequest(uint8_t instanceId, uint8_t sensorId, |
| 117 | uint8_t averagingInterval, |
| 118 | std::span<uint8_t> buf); |
| 119 | |
| 120 | int decodeGetCurrentPowerDrawResponse( |
| 121 | std::span<const uint8_t> buf, |
| 122 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 123 | uint32_t& power); |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 124 | } // namespace gpu |