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 | c20108d | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 33 | READ_THERMAL_PARAMETERS = 0x02, |
Harshit Aghera | c8dab72 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 34 | GET_CURRENT_POWER_DRAW = 0x03, |
Harshit Aghera | 128c91d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 35 | GET_CURRENT_ENERGY_COUNTER = 0x06, |
Harshit Aghera | b55847f | 2025-05-27 14:53:56 +0530 | [diff] [blame^] | 36 | GET_VOLTAGE = 0x0F, |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | enum class DeviceIdentification : uint8_t |
| 40 | { |
| 41 | DEVICE_GPU = 0 |
| 42 | }; |
| 43 | |
| 44 | struct QueryDeviceIdentificationRequest |
| 45 | { |
| 46 | ocp::accelerator_management::CommonRequest hdr; |
| 47 | } __attribute__((packed)); |
| 48 | |
| 49 | struct QueryDeviceIdentificationResponse |
| 50 | { |
| 51 | ocp::accelerator_management::CommonResponse hdr; |
| 52 | uint8_t device_identification; |
| 53 | uint8_t instance_id; |
| 54 | } __attribute__((packed)); |
| 55 | |
| 56 | struct GetNumericSensorReadingRequest |
| 57 | { |
| 58 | ocp::accelerator_management::CommonRequest hdr; |
| 59 | uint8_t sensor_id; |
| 60 | } __attribute__((packed)); |
| 61 | |
| 62 | using GetTemperatureReadingRequest = GetNumericSensorReadingRequest; |
| 63 | |
Harshit Aghera | c20108d | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 64 | using ReadThermalParametersRequest = GetNumericSensorReadingRequest; |
| 65 | |
Harshit Aghera | c8dab72 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 66 | struct GetCurrentPowerDrawRequest |
| 67 | { |
| 68 | ocp::accelerator_management::CommonRequest hdr; |
| 69 | uint8_t sensorId; |
| 70 | uint8_t averagingInterval; |
| 71 | } __attribute__((packed)); |
| 72 | |
Harshit Aghera | 128c91d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 73 | using GetCurrentEnergyCounterRequest = GetNumericSensorReadingRequest; |
| 74 | |
Harshit Aghera | b55847f | 2025-05-27 14:53:56 +0530 | [diff] [blame^] | 75 | using GetVoltageRequest = GetNumericSensorReadingRequest; |
| 76 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 77 | struct GetTemperatureReadingResponse |
| 78 | { |
| 79 | ocp::accelerator_management::CommonResponse hdr; |
| 80 | int32_t reading; |
| 81 | } __attribute__((packed)); |
| 82 | |
Harshit Aghera | c20108d | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 83 | struct ReadThermalParametersResponse |
| 84 | { |
| 85 | ocp::accelerator_management::CommonResponse hdr; |
| 86 | int32_t threshold; |
| 87 | } __attribute__((packed)); |
| 88 | |
Harshit Aghera | c8dab72 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 89 | struct GetCurrentPowerDrawResponse |
| 90 | { |
| 91 | ocp::accelerator_management::CommonResponse hdr; |
| 92 | uint32_t power; |
| 93 | } __attribute__((packed)); |
| 94 | |
Harshit Aghera | 128c91d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 95 | struct GetCurrentEnergyCounterResponse |
| 96 | { |
| 97 | ocp::accelerator_management::CommonResponse hdr; |
| 98 | uint64_t energy; |
| 99 | } __attribute__((packed)); |
| 100 | |
Harshit Aghera | b55847f | 2025-05-27 14:53:56 +0530 | [diff] [blame^] | 101 | struct GetVoltageResponse |
| 102 | { |
| 103 | ocp::accelerator_management::CommonResponse hdr; |
| 104 | uint32_t voltage; |
| 105 | } __attribute__((packed)); |
| 106 | |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 107 | int packHeader(const ocp::accelerator_management::BindingPciVidInfo& hdr, |
| 108 | ocp::accelerator_management::BindingPciVid& msg); |
| 109 | |
| 110 | int encodeQueryDeviceIdentificationRequest(uint8_t instanceId, |
| 111 | std::span<uint8_t> buf); |
| 112 | |
| 113 | int decodeQueryDeviceIdentificationResponse( |
| 114 | std::span<const uint8_t> buf, |
| 115 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 116 | uint8_t& deviceIdentification, uint8_t& deviceInstance); |
| 117 | |
| 118 | int encodeGetTemperatureReadingRequest(uint8_t instanceId, uint8_t sensorId, |
| 119 | std::span<uint8_t> buf); |
| 120 | |
| 121 | int decodeGetTemperatureReadingResponse( |
| 122 | std::span<const uint8_t> buf, |
| 123 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 124 | double& temperatureReading); |
| 125 | |
Harshit Aghera | c20108d | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 126 | int encodeReadThermalParametersRequest(uint8_t instanceId, uint8_t sensorId, |
| 127 | std::span<uint8_t> buf); |
| 128 | |
| 129 | int decodeReadThermalParametersResponse( |
| 130 | std::span<const uint8_t> buf, |
| 131 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 132 | int32_t& threshold); |
| 133 | |
Harshit Aghera | c8dab72 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 134 | int encodeGetCurrentPowerDrawRequest(uint8_t instanceId, uint8_t sensorId, |
| 135 | uint8_t averagingInterval, |
| 136 | std::span<uint8_t> buf); |
| 137 | |
| 138 | int decodeGetCurrentPowerDrawResponse( |
| 139 | std::span<const uint8_t> buf, |
| 140 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 141 | uint32_t& power); |
Harshit Aghera | 128c91d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 142 | |
| 143 | int encodeGetCurrentEnergyCounterRequest(uint8_t instanceId, uint8_t sensorId, |
| 144 | std::span<uint8_t> buf); |
| 145 | |
| 146 | int decodeGetCurrentEnergyCounterResponse( |
| 147 | std::span<const uint8_t> buf, |
| 148 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 149 | uint64_t& energy); |
Harshit Aghera | b55847f | 2025-05-27 14:53:56 +0530 | [diff] [blame^] | 150 | |
| 151 | int encodeGetVoltageRequest(uint8_t instanceId, uint8_t sensorId, |
| 152 | std::span<uint8_t> buf); |
| 153 | |
| 154 | int decodeGetVoltageResponse(std::span<const uint8_t> buf, |
| 155 | ocp::accelerator_management::CompletionCode& cc, |
| 156 | uint16_t& reasonCode, uint32_t& voltage); |
Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame] | 157 | } // namespace gpu |