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