blob: 09df4e676c1dfbaff444156315148fcfc7556abb [file] [log] [blame]
Harshit Aghera560e6af2025-04-21 20:04:56 +05301/*
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
14namespace gpu
15{
16
17constexpr uint16_t nvidiaPciVendorId = 0x10de;
18
19enum class MessageType : uint8_t
20{
21 DEVICE_CAPABILITY_DISCOVERY = 0,
22 PLATFORM_ENVIRONMENTAL = 3
23};
24
25enum class DeviceCapabilityDiscoveryCommands : uint8_t
26{
27 QUERY_DEVICE_IDENTIFICATION = 0x09,
28};
29
30enum class PlatformEnvironmentalCommands : uint8_t
31{
32 GET_TEMPERATURE_READING = 0x00,
Harshit Aghera5e7decc2025-05-07 16:20:16 +053033 READ_THERMAL_PARAMETERS = 0x02,
Harshit Aghera902c6492025-05-08 15:57:42 +053034 GET_CURRENT_POWER_DRAW = 0x03,
Harshit Aghera775199d2025-05-27 14:20:24 +053035 GET_CURRENT_ENERGY_COUNTER = 0x06,
Harshit Agherabef4d412025-05-27 14:53:56 +053036 GET_VOLTAGE = 0x0F,
Harshit Aghera560e6af2025-04-21 20:04:56 +053037};
38
39enum class DeviceIdentification : uint8_t
40{
Harshit Aghera8951c872025-06-25 15:25:33 +053041 DEVICE_GPU = 0,
42 DEVICE_SMA = 5
Harshit Aghera560e6af2025-04-21 20:04:56 +053043};
44
45struct QueryDeviceIdentificationRequest
46{
47 ocp::accelerator_management::CommonRequest hdr;
48} __attribute__((packed));
49
50struct QueryDeviceIdentificationResponse
51{
52 ocp::accelerator_management::CommonResponse hdr;
53 uint8_t device_identification;
54 uint8_t instance_id;
55} __attribute__((packed));
56
57struct GetNumericSensorReadingRequest
58{
59 ocp::accelerator_management::CommonRequest hdr;
60 uint8_t sensor_id;
61} __attribute__((packed));
62
63using GetTemperatureReadingRequest = GetNumericSensorReadingRequest;
64
Harshit Aghera5e7decc2025-05-07 16:20:16 +053065using ReadThermalParametersRequest = GetNumericSensorReadingRequest;
66
Harshit Aghera902c6492025-05-08 15:57:42 +053067struct GetCurrentPowerDrawRequest
68{
69 ocp::accelerator_management::CommonRequest hdr;
70 uint8_t sensorId;
71 uint8_t averagingInterval;
72} __attribute__((packed));
73
Harshit Aghera775199d2025-05-27 14:20:24 +053074using GetCurrentEnergyCounterRequest = GetNumericSensorReadingRequest;
75
Harshit Agherabef4d412025-05-27 14:53:56 +053076using GetVoltageRequest = GetNumericSensorReadingRequest;
77
Harshit Aghera560e6af2025-04-21 20:04:56 +053078struct GetTemperatureReadingResponse
79{
80 ocp::accelerator_management::CommonResponse hdr;
81 int32_t reading;
82} __attribute__((packed));
83
Harshit Aghera5e7decc2025-05-07 16:20:16 +053084struct ReadThermalParametersResponse
85{
86 ocp::accelerator_management::CommonResponse hdr;
87 int32_t threshold;
88} __attribute__((packed));
89
Harshit Aghera902c6492025-05-08 15:57:42 +053090struct GetCurrentPowerDrawResponse
91{
92 ocp::accelerator_management::CommonResponse hdr;
93 uint32_t power;
94} __attribute__((packed));
95
Harshit Aghera775199d2025-05-27 14:20:24 +053096struct GetCurrentEnergyCounterResponse
97{
98 ocp::accelerator_management::CommonResponse hdr;
99 uint64_t energy;
100} __attribute__((packed));
101
Harshit Agherabef4d412025-05-27 14:53:56 +0530102struct GetVoltageResponse
103{
104 ocp::accelerator_management::CommonResponse hdr;
105 uint32_t voltage;
106} __attribute__((packed));
107
Harshit Aghera560e6af2025-04-21 20:04:56 +0530108int packHeader(const ocp::accelerator_management::BindingPciVidInfo& hdr,
109 ocp::accelerator_management::BindingPciVid& msg);
110
111int encodeQueryDeviceIdentificationRequest(uint8_t instanceId,
112 std::span<uint8_t> buf);
113
114int decodeQueryDeviceIdentificationResponse(
115 std::span<const uint8_t> buf,
116 ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode,
117 uint8_t& deviceIdentification, uint8_t& deviceInstance);
118
119int encodeGetTemperatureReadingRequest(uint8_t instanceId, uint8_t sensorId,
120 std::span<uint8_t> buf);
121
122int decodeGetTemperatureReadingResponse(
123 std::span<const uint8_t> buf,
124 ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode,
125 double& temperatureReading);
126
Harshit Aghera5e7decc2025-05-07 16:20:16 +0530127int encodeReadThermalParametersRequest(uint8_t instanceId, uint8_t sensorId,
128 std::span<uint8_t> buf);
129
130int decodeReadThermalParametersResponse(
131 std::span<const uint8_t> buf,
132 ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode,
133 int32_t& threshold);
134
Harshit Aghera902c6492025-05-08 15:57:42 +0530135int encodeGetCurrentPowerDrawRequest(uint8_t instanceId, uint8_t sensorId,
136 uint8_t averagingInterval,
137 std::span<uint8_t> buf);
138
139int decodeGetCurrentPowerDrawResponse(
140 std::span<const uint8_t> buf,
141 ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode,
142 uint32_t& power);
Harshit Aghera775199d2025-05-27 14:20:24 +0530143
144int encodeGetCurrentEnergyCounterRequest(uint8_t instanceId, uint8_t sensorId,
145 std::span<uint8_t> buf);
146
147int decodeGetCurrentEnergyCounterResponse(
148 std::span<const uint8_t> buf,
149 ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode,
150 uint64_t& energy);
Harshit Agherabef4d412025-05-27 14:53:56 +0530151
152int encodeGetVoltageRequest(uint8_t instanceId, uint8_t sensorId,
153 std::span<uint8_t> buf);
154
155int decodeGetVoltageResponse(std::span<const uint8_t> buf,
156 ocp::accelerator_management::CompletionCode& cc,
157 uint16_t& reasonCode, uint32_t& voltage);
Harshit Aghera560e6af2025-04-21 20:04:56 +0530158} // namespace gpu