NVIDIA DRIVE OS Linux SDK API Reference

5.1.9.0 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvrm_gpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2018 NVIDIA Corporation. All rights reserved.
3  *
4  * NVIDIA Corporation and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA Corporation is strictly prohibited.
9  */
10 
11 #ifndef INCLUDED_nvrm_gpu_H
12 #define INCLUDED_nvrm_gpu_H
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 #include <stddef.h>
17 
18 #include "nvcommon.h"
19 #include "nverror.h"
20 
21 #if defined(__cplusplus)
22 extern "C"
23 {
24 #endif
25 
81 typedef struct NvRmGpuLibRec NvRmGpuLib;
83 typedef struct NvRmGpuDeviceRec NvRmGpuDevice;
84 
85 /**** Generic functions ****/
86 
87 typedef struct NvRmGpuLibOpenAttrRec
88 {
89  // placeholder for extensions
90  uint32_t reserved;
91 
93 
94 #define NVRM_GPU_DEFINE_LIB_OPEN_ATTR(x) \
95  NvRmGpuLibOpenAttr x = { 0 }
96 
102 
109 NvError NvRmGpuLibClose(NvRmGpuLib *hlib);
110 
111 typedef enum
112 {
116 
118 {
121  const char *name; // temporary name, e.g., Nouveau GPU 0 or some such
123 
139 const NvRmGpuLibDeviceListEntry *NvRmGpuLibListDevices(NvRmGpuLib *hlib, size_t *pnumDevices);
140 
148 NvError NvRmGpuLibAttachDevice(NvRmGpuLib *const hlib, const int deviceIndex);
149 
157 NvError NvRmGpuLibDetachDevice(NvRmGpuLib *const hlib, const int deviceIndex);
158 
159 /**** Device functions ****/
160 
161 #define NVRM_GPU_DEVICE_INDEX_DEFAULT (-1)
162 
163 typedef enum
164 {
165  NvRmGpuSyncType_Default, // platform-specific default
169 
171 {
180 
189 
190 #define NVRM_GPU_DEFINE_DEVICE_OPEN_ATTR(x) \
191  NvRmGpuDeviceOpenAttr x = { NvRmGpuSyncType_Default, false }
192 
193 
203 NvError NvRmGpuDeviceOpen(NvRmGpuLib *hLib, int deviceIndex, const NvRmGpuDeviceOpenAttr *attr,
204  NvRmGpuDevice **phDevice);
205 
212 NvError NvRmGpuDeviceClose(NvRmGpuDevice *hDevice);
213 
241 #if NVOS_IS_LINUX || NVOS_IS_QNX
242 #define NVRM_GPU_CLOCK_ASYNC_REQ_HANDLE_PRIFMT "d"
243 typedef int NvRmGpuClockAsyncReqHandle;
244 #else
245 #define NVRM_GPU_CLOCK_ASYNC_REQ_HANDLE_PRIFMT "p"
246 typedef struct NvRmGpuClockAsyncNotImplemented *NvRmGpuClockAsyncReqHandle;
247 #endif
248 
252 typedef enum NvRmGpuClockDomain
253 {
258 
259 typedef enum NvRmGpuClockType
260 {
265 
267 {
270  uint64_t freqHz;
272 
274 {
276  uint64_t freqHz;
278 
279 typedef struct NvRmGpuClockRangeRec
280 {
281  uint64_t minHz;
282  uint64_t maxHz;
284 
285 typedef struct NvRmGpuClockPointRec
286 {
287  uint64_t freqHz;
289 
291 {
294  size_t maxVfPoints;
296 
307 NvError NvRmGpuClockGetDomains(NvRmGpuDevice *hDevice,
308  const NvRmGpuClockDomainInfo **infos,
309  size_t *pNumDomains);
310 
326 NvError NvRmGpuClockGetPoints(NvRmGpuDevice *hDevice,
327  NvRmGpuClockDomain domain,
328  NvRmGpuClockPoint *pClkPoints,
329  size_t *pNumPoints);
330 
366 NvError NvRmGpuClockSet(NvRmGpuDevice *hDevice,
367  const NvRmGpuClockSetEntry *pClkSetEntries,
368  size_t numEntries,
369  NvRmGpuClockAsyncReqHandle *phReq);
370 
386 NvError NvRmGpuClockWaitAsyncReq(NvRmGpuDevice *hDevice,
387  const NvRmGpuClockAsyncReqHandle *phReqs,
388  size_t numEntries,
389  uint32_t timeoutMs);
390 
403  NvRmGpuClockAsyncReqHandle hReq);
404 
418 NvError NvRmGpuClockWaitAnyEvent(NvRmGpuDevice *hDevice,
419  uint32_t timeoutMs);
420 
433 NvError NvRmGpuClockGet(NvRmGpuDevice *hDevice,
434  NvRmGpuClockGetEntry *pClkGetEntries,
435  size_t numEntries);
436 
437 typedef enum
438 {
443 
455  const NvRmGpuDeviceVoltage **pSensors,
456  size_t *numSensors);
466 NvError NvRmGpuDeviceGetVoltage(NvRmGpuDevice *hDevice,
467  NvRmGpuDeviceVoltage which,
468  uint64_t *pVoltageMicroVolt);
469 
470 typedef enum
471 {
474 
486  const NvRmGpuDeviceCurrent **pSensors,
487  size_t *numSensors);
488 
498 NvError NvRmGpuDeviceGetCurrent(NvRmGpuDevice *hDevice,
499  NvRmGpuDeviceCurrent which,
500  uint64_t *pCurrentMicroAmpere);
501 
502 typedef enum
503 {
504  NvRmGpuDevicePower_Bus = 1 // power consumed at regulator
506 
518  const NvRmGpuDevicePower **pSensors,
519  size_t *numSensors);
520 
530 NvError NvRmGpuDeviceGetPower(NvRmGpuDevice *hDevice,
531  NvRmGpuDevicePower which,
532  uint64_t *pPowerMicroWatt);
533 
534 
535 typedef enum
536 {
539 
551  const NvRmGpuDeviceTemperature **pSensors,
552  size_t *numSensors);
553 
565  int32_t *pTemperatureMilliCelsius);
566 
576  int32_t temperature_mC);
577 
579 typedef enum
580 {
601 
602 typedef struct NvRmGpuDeviceEventSessionRec NvRmGpuDeviceEventSession;
603 
606 {
612 
613 #define NVRM_GPU_DEFINE_DEVICE_EVENT_SESSION_ATTR(x) \
614  NvRmGpuDeviceEventSessionOpenAttr x = { NULL, 0 }
615 
617 {
618  static const NvRmGpuDeviceEventId allEvents[] =
619  {
628  };
629  attr->filterList = allEvents;
630  attr->filterListSize = NV_ARRAY_SIZE(allEvents);
631 }
632 
644  NvRmGpuDeviceEventSession **phSession);
645 
647 {
649  uint64_t timeNs; // GPU timestamp in ns
651 
669  NvRmGpuDeviceEventInfo *pEventInfo,
670  uint32_t timeoutMs);
671 
681 
684 #if defined(__cplusplus)
685 }
686 #endif
687 
688 #if !defined(NV_SDK_BUILD)
689 #include "nvrm_gpu_priv.h"
690 #endif
691 
692 #endif
NvError NvRmGpuDeviceEventSessionOpen(NvRmGpuDevice *hDevice, const NvRmGpuDeviceEventSessionOpenAttr *attr, NvRmGpuDeviceEventSession **phSession)
Opens the session to monitor device events.
struct NvRmGpuDeviceRec NvRmGpuDevice
Device handle type.
Definition: nvrm_gpu.h:83
struct NvRmGpuDeviceEventSessionOpenAttrRec NvRmGpuDeviceEventSessionOpenAttr
Holds the events for which to listen.
Actual clock frequency programmed (including PLL constraints).
Definition: nvrm_gpu.h:262
Main graphics core clock.
Definition: nvrm_gpu.h:255
struct NvRmGpuLibOpenAttrRec NvRmGpuLibOpenAttr
VF update occurred for a clock domain, either because one session changed target frequency or because...
Definition: nvrm_gpu.h:583
NvError NvRmGpuLibDetachDevice(NvRmGpuLib *const hlib, const int deviceIndex)
Detach and power down a GPU.
One clock domain frequency is below target.
Definition: nvrm_gpu.h:585
NvRmGpuDeviceEventId
Holds information about the GPU device event.
Definition: nvrm_gpu.h:579
GPU lost (non-recoverable).
Definition: nvrm_gpu.h:597
const NvRmGpuLibDeviceListEntry * NvRmGpuLibListDevices(NvRmGpuLib *hlib, size_t *pnumDevices)
Returns a pointer to the device array.
NvRmGpuDeviceState
Definition: nvrm_gpu.h:111
NvRmGpuDeviceState deviceState
Definition: nvrm_gpu.h:120
NvError NvRmGpuDeviceGetTemperature(NvRmGpuDevice *hDevice, NvRmGpuDeviceTemperature which, int32_t *pTemperatureMilliCelsius)
Gets the temperature.
NvError NvRmGpuClockGetPoints(NvRmGpuDevice *hDevice, NvRmGpuClockDomain domain, NvRmGpuClockPoint *pClkPoints, size_t *pNumPoints)
Gets VF points for a given clock domain.
NvError NvRmGpuDeviceGetPower(NvRmGpuDevice *hDevice, NvRmGpuDevicePower which, uint64_t *pPowerMicroWatt)
Gets the power consumed by the GPU.
NvRmGpuClockDomain
Clock domains.
Definition: nvrm_gpu.h:252
NvError NvRmGpuDeviceEventSessionRead(NvRmGpuDeviceEventSession *hSession, NvRmGpuDeviceEventInfo *pEventInfo, uint32_t timeoutMs)
Reads detailed event information from the event session.
NvRmGpuDeviceTemperature
Definition: nvrm_gpu.h:535
One clock domain frequency is below local target frequency requested by one session.
Definition: nvrm_gpu.h:587
NvError NvRmGpuDeviceListTemperatureSensors(NvRmGpuDevice *hDevice, const NvRmGpuDeviceTemperature **pSensors, size_t *numSensors)
Gets the list of available temperature sensors.
NvRmGpuClockRange range
Definition: nvrm_gpu.h:293
static void NvRmGpuDeviceEventSessionOpenAttrSetAllEvents(NvRmGpuDeviceEventSessionOpenAttr *attr)
Definition: nvrm_gpu.h:616
struct NvRmGpuDeviceEventSessionRec NvRmGpuDeviceEventSession
Definition: nvrm_gpu.h:602
struct NvRmGpuClockPointRec NvRmGpuClockPoint
NvError NvRmGpuClockGet(NvRmGpuDevice *hDevice, NvRmGpuClockGetEntry *pClkGetEntries, size_t numEntries)
Gets clock state(s).
Memory clock.
Definition: nvrm_gpu.h:254
NvError NvRmGpuDeviceClose(NvRmGpuDevice *hDevice)
Closes the GPU device.
Target clock frequency requested by application.
Definition: nvrm_gpu.h:261
struct NvRmGpuLibDeviceListEntryRec NvRmGpuLibDeviceListEntry
NvError NvRmGpuDeviceListCurrentSensors(NvRmGpuDevice *hDevice, const NvRmGpuDeviceCurrent **pSensors, size_t *numSensors)
Gets a list of the available current sensors.
NvError NvRmGpuClockWaitAnyEvent(NvRmGpuDevice *hDevice, uint32_t timeoutMs)
Waits on any clock update event.
NvRmGpuDeviceEventId eventId
Definition: nvrm_gpu.h:648
NvError NvRmGpuDeviceListPowerSensors(NvRmGpuDevice *hDevice, const NvRmGpuDevicePower **pSensors, size_t *numSensors)
Gets a list of the available power sensors.
struct NvRmGpuClockGetEntryRec NvRmGpuClockGetEntry
NvError NvRmGpuClockGetDomains(NvRmGpuDevice *hDevice, const NvRmGpuClockDomainInfo **infos, size_t *pNumDomains)
Gets configurable clock domains.
struct NvRmGpuClockRangeRec NvRmGpuClockRange
NvError NvRmGpuClockCloseAsyncReq(NvRmGpuDevice *hDevice, NvRmGpuClockAsyncReqHandle hReq)
Closes an asynchronous request handle.
NvError NvRmGpuClockSet(NvRmGpuDevice *hDevice, const NvRmGpuClockSetEntry *pClkSetEntries, size_t numEntries, NvRmGpuClockAsyncReqHandle *phReq)
Sets a clock request.
const NvRmGpuDeviceEventId * filterList
Holds the events for which to listen.
Definition: nvrm_gpu.h:608
struct NvRmGpuClockDomainInfoRec NvRmGpuClockDomainInfo
NvError NvRmGpuDeviceThermalAlertSetLimit(NvRmGpuDevice *hDevice, int32_t temperature_mC)
Sets the thermal alert limit.
NvRmGpuLib * NvRmGpuLibOpen(const NvRmGpuLibOpenAttr *attr)
Opens a new instance of the library.
struct NvRmGpuDeviceOpenAttrRec NvRmGpuDeviceOpenAttr
NvError NvRmGpuClockWaitAsyncReq(NvRmGpuDevice *hDevice, const NvRmGpuClockAsyncReqHandle *phReqs, size_t numEntries, uint32_t timeoutMs)
Waits for completion of one or more asynchronous requests.
NvRmGpuSyncType
Definition: nvrm_gpu.h:163
NvRmGpuDeviceCurrent
Definition: nvrm_gpu.h:470
struct NvRmGpuLibRec NvRmGpuLib
Library handle type.
Definition: nvrm_gpu.h:81
NvRmGpuDevicePower
Definition: nvrm_gpu.h:502
NvRmGpuDeviceVoltage
Definition: nvrm_gpu.h:437
NvError NvRmGpuDeviceGetVoltage(NvRmGpuDevice *hDevice, NvRmGpuDeviceVoltage which, uint64_t *pVoltageMicroVolt)
Gets the current voltage.
NvRmGpuClockDomain domain
in: Clock domain to query
Definition: nvrm_gpu.h:268
struct NvRmGpuClockSetEntryRec NvRmGpuClockSetEntry
Number of events.
Definition: nvrm_gpu.h:599
NvError NvRmGpuDeviceEventSessionClose(NvRmGpuDeviceEventSession *hSession)
Closes the event session.
NvError NvRmGpuLibClose(NvRmGpuLib *hlib)
Closes the library and releases all resources.
NvRmGpuClockDomain domain
Definition: nvrm_gpu.h:275
NvRmGpuClockType type
in: Frequency type (target, actual or effective)
Definition: nvrm_gpu.h:269
struct NvRmGpuClockAsyncNotImplemented * NvRmGpuClockAsyncReqHandle
Definition: nvrm_gpu.h:246
bool sandboxFriendlyChannels
If true, channels are created in sandbox-friendly manner.
Definition: nvrm_gpu.h:187
NvRmGpuSyncType syncType
The default sync type for all input/output sync objects.
Definition: nvrm_gpu.h:179
NvRmGpuClockType
Definition: nvrm_gpu.h:259
Effective clock, measured from hardware.
Definition: nvrm_gpu.h:263
NvError NvRmGpuLibAttachDevice(NvRmGpuLib *const hlib, const int deviceIndex)
Power up and attach a GPU.
uint64_t freqHz
out: Frequency in Hz
Definition: nvrm_gpu.h:270
NvError NvRmGpuDeviceGetCurrent(NvRmGpuDevice *hDevice, NvRmGpuDeviceCurrent which, uint64_t *pCurrentMicroAmpere)
Gets the current drawn by the GPU.
NvError NvRmGpuDeviceListVoltageSensors(NvRmGpuDevice *hDevice, const NvRmGpuDeviceVoltage **pSensors, size_t *numSensors)
Gets a list of the available voltage sensors.
Holds the events for which to listen.
Definition: nvrm_gpu.h:605
size_t filterListSize
Holds the size of the filter list.
Definition: nvrm_gpu.h:610
Temperature above threshold.
Definition: nvrm_gpu.h:593
NvError NvRmGpuDeviceOpen(NvRmGpuLib *hLib, int deviceIndex, const NvRmGpuDeviceOpenAttr *attr, NvRmGpuDevice **phDevice)
Opens the GPU device.
NvRmGpuClockDomain domain
Definition: nvrm_gpu.h:292
struct NvRmGpuDeviceEventInfoRec NvRmGpuDeviceEventInfo