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, |
| 33 | }; |
| 34 | |
| 35 | enum class DeviceIdentification : uint8_t |
| 36 | { |
| 37 | DEVICE_GPU = 0 |
| 38 | }; |
| 39 | |
| 40 | struct QueryDeviceIdentificationRequest |
| 41 | { |
| 42 | ocp::accelerator_management::CommonRequest hdr; |
| 43 | } __attribute__((packed)); |
| 44 | |
| 45 | struct QueryDeviceIdentificationResponse |
| 46 | { |
| 47 | ocp::accelerator_management::CommonResponse hdr; |
| 48 | uint8_t device_identification; |
| 49 | uint8_t instance_id; |
| 50 | } __attribute__((packed)); |
| 51 | |
| 52 | struct GetNumericSensorReadingRequest |
| 53 | { |
| 54 | ocp::accelerator_management::CommonRequest hdr; |
| 55 | uint8_t sensor_id; |
| 56 | } __attribute__((packed)); |
| 57 | |
| 58 | using GetTemperatureReadingRequest = GetNumericSensorReadingRequest; |
| 59 | |
| 60 | struct GetTemperatureReadingResponse |
| 61 | { |
| 62 | ocp::accelerator_management::CommonResponse hdr; |
| 63 | int32_t reading; |
| 64 | } __attribute__((packed)); |
| 65 | |
| 66 | int packHeader(const ocp::accelerator_management::BindingPciVidInfo& hdr, |
| 67 | ocp::accelerator_management::BindingPciVid& msg); |
| 68 | |
| 69 | int encodeQueryDeviceIdentificationRequest(uint8_t instanceId, |
| 70 | std::span<uint8_t> buf); |
| 71 | |
| 72 | int decodeQueryDeviceIdentificationResponse( |
| 73 | std::span<const uint8_t> buf, |
| 74 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 75 | uint8_t& deviceIdentification, uint8_t& deviceInstance); |
| 76 | |
| 77 | int encodeGetTemperatureReadingRequest(uint8_t instanceId, uint8_t sensorId, |
| 78 | std::span<uint8_t> buf); |
| 79 | |
| 80 | int decodeGetTemperatureReadingResponse( |
| 81 | std::span<const uint8_t> buf, |
| 82 | ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode, |
| 83 | double& temperatureReading); |
| 84 | |
| 85 | } // namespace gpu |