xref: /openbmc/dbus-sensors/src/nvidia-gpu/NvidiaGpuMctpVdm.hpp (revision 560e6af7b1f74e9c020a0f82817f9d926e0c4f72)
1*560e6af7SHarshit Aghera /*
2*560e6af7SHarshit Aghera  * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION &
3*560e6af7SHarshit Aghera  * AFFILIATES. All rights reserved.
4*560e6af7SHarshit Aghera  * SPDX-License-Identifier: Apache-2.0
5*560e6af7SHarshit Aghera  */
6*560e6af7SHarshit Aghera 
7*560e6af7SHarshit Aghera #pragma once
8*560e6af7SHarshit Aghera 
9*560e6af7SHarshit Aghera #include <OcpMctpVdm.hpp>
10*560e6af7SHarshit Aghera 
11*560e6af7SHarshit Aghera #include <cstdint>
12*560e6af7SHarshit Aghera #include <span>
13*560e6af7SHarshit Aghera 
14*560e6af7SHarshit Aghera namespace gpu
15*560e6af7SHarshit Aghera {
16*560e6af7SHarshit Aghera 
17*560e6af7SHarshit Aghera constexpr uint16_t nvidiaPciVendorId = 0x10de;
18*560e6af7SHarshit Aghera 
19*560e6af7SHarshit Aghera enum class MessageType : uint8_t
20*560e6af7SHarshit Aghera {
21*560e6af7SHarshit Aghera     DEVICE_CAPABILITY_DISCOVERY = 0,
22*560e6af7SHarshit Aghera     PLATFORM_ENVIRONMENTAL = 3
23*560e6af7SHarshit Aghera };
24*560e6af7SHarshit Aghera 
25*560e6af7SHarshit Aghera enum class DeviceCapabilityDiscoveryCommands : uint8_t
26*560e6af7SHarshit Aghera {
27*560e6af7SHarshit Aghera     QUERY_DEVICE_IDENTIFICATION = 0x09,
28*560e6af7SHarshit Aghera };
29*560e6af7SHarshit Aghera 
30*560e6af7SHarshit Aghera enum class PlatformEnvironmentalCommands : uint8_t
31*560e6af7SHarshit Aghera {
32*560e6af7SHarshit Aghera     GET_TEMPERATURE_READING = 0x00,
33*560e6af7SHarshit Aghera };
34*560e6af7SHarshit Aghera 
35*560e6af7SHarshit Aghera enum class DeviceIdentification : uint8_t
36*560e6af7SHarshit Aghera {
37*560e6af7SHarshit Aghera     DEVICE_GPU = 0
38*560e6af7SHarshit Aghera };
39*560e6af7SHarshit Aghera 
40*560e6af7SHarshit Aghera struct QueryDeviceIdentificationRequest
41*560e6af7SHarshit Aghera {
42*560e6af7SHarshit Aghera     ocp::accelerator_management::CommonRequest hdr;
43*560e6af7SHarshit Aghera } __attribute__((packed));
44*560e6af7SHarshit Aghera 
45*560e6af7SHarshit Aghera struct QueryDeviceIdentificationResponse
46*560e6af7SHarshit Aghera {
47*560e6af7SHarshit Aghera     ocp::accelerator_management::CommonResponse hdr;
48*560e6af7SHarshit Aghera     uint8_t device_identification;
49*560e6af7SHarshit Aghera     uint8_t instance_id;
50*560e6af7SHarshit Aghera } __attribute__((packed));
51*560e6af7SHarshit Aghera 
52*560e6af7SHarshit Aghera struct GetNumericSensorReadingRequest
53*560e6af7SHarshit Aghera {
54*560e6af7SHarshit Aghera     ocp::accelerator_management::CommonRequest hdr;
55*560e6af7SHarshit Aghera     uint8_t sensor_id;
56*560e6af7SHarshit Aghera } __attribute__((packed));
57*560e6af7SHarshit Aghera 
58*560e6af7SHarshit Aghera using GetTemperatureReadingRequest = GetNumericSensorReadingRequest;
59*560e6af7SHarshit Aghera 
60*560e6af7SHarshit Aghera struct GetTemperatureReadingResponse
61*560e6af7SHarshit Aghera {
62*560e6af7SHarshit Aghera     ocp::accelerator_management::CommonResponse hdr;
63*560e6af7SHarshit Aghera     int32_t reading;
64*560e6af7SHarshit Aghera } __attribute__((packed));
65*560e6af7SHarshit Aghera 
66*560e6af7SHarshit Aghera int packHeader(const ocp::accelerator_management::BindingPciVidInfo& hdr,
67*560e6af7SHarshit Aghera                ocp::accelerator_management::BindingPciVid& msg);
68*560e6af7SHarshit Aghera 
69*560e6af7SHarshit Aghera int encodeQueryDeviceIdentificationRequest(uint8_t instanceId,
70*560e6af7SHarshit Aghera                                            std::span<uint8_t> buf);
71*560e6af7SHarshit Aghera 
72*560e6af7SHarshit Aghera int decodeQueryDeviceIdentificationResponse(
73*560e6af7SHarshit Aghera     std::span<const uint8_t> buf,
74*560e6af7SHarshit Aghera     ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode,
75*560e6af7SHarshit Aghera     uint8_t& deviceIdentification, uint8_t& deviceInstance);
76*560e6af7SHarshit Aghera 
77*560e6af7SHarshit Aghera int encodeGetTemperatureReadingRequest(uint8_t instanceId, uint8_t sensorId,
78*560e6af7SHarshit Aghera                                        std::span<uint8_t> buf);
79*560e6af7SHarshit Aghera 
80*560e6af7SHarshit Aghera int decodeGetTemperatureReadingResponse(
81*560e6af7SHarshit Aghera     std::span<const uint8_t> buf,
82*560e6af7SHarshit Aghera     ocp::accelerator_management::CompletionCode& cc, uint16_t& reasonCode,
83*560e6af7SHarshit Aghera     double& temperatureReading);
84*560e6af7SHarshit Aghera 
85*560e6af7SHarshit Aghera } // namespace gpu
86