1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef _RMAPI_H_
24 #define _RMAPI_H_
25 
26 #include "core/core.h"
27 #include "nvsecurityinfo.h"
28 
29 //
30 // Forward declarations
31 //
32 typedef struct _RM_API RM_API;
33 typedef struct RsServer RsServer;
34 typedef struct OBJGPU OBJGPU;
35 typedef struct RsClient RsClient;
36 typedef struct RsResource RsResource;
37 typedef struct RsCpuMapping RsCpuMapping;
38 typedef struct CALL_CONTEXT CALL_CONTEXT;
39 typedef struct MEMORY_DESCRIPTOR MEMORY_DESCRIPTOR;
40 typedef struct RS_RES_FREE_PARAMS_INTERNAL RS_RES_FREE_PARAMS_INTERNAL;
41 typedef struct RS_LOCK_INFO RS_LOCK_INFO;
42 typedef struct NV0000_CTRL_SYSTEM_GET_LOCK_TIMES_PARAMS NV0000_CTRL_SYSTEM_GET_LOCK_TIMES_PARAMS;
43 typedef NvU32 NV_ADDRESS_SPACE;
44 
45 extern RsServer    g_resServ;
46 
47 /**
48  * Initialize RMAPI module.
49  *
50  * Must be called once and only once before any RMAPI functions can be called
51  */
52 NV_STATUS rmapiInitialize(void);
53 
54 /**
55  * Shutdown RMAPI module
56  *
57  * Must be called once and only once when a driver is shutting down and no more
58  * RMAPI functions will be called.
59  */
60 void rmapiShutdown(void);
61 
62 // Flags for rmapiLockAcquire
63 #define RMAPI_LOCK_FLAGS_NONE                             (0x00000000)  // default no flags
64 #define RMAPI_LOCK_FLAGS_COND_ACQUIRE                     NVBIT(0)        // conditional acquire; if lock is
65                                                                         // already held then return error
66 #define RMAPI_LOCK_FLAGS_READ                             NVBIT(1)        // Acquire API lock for READ
67 #define RMAPI_LOCK_FLAGS_WRITE                            (0x00000000)  // Acquire API lock for WRITE - Default
68 #define RMAPI_LOCK_FLAGS_LOW_PRIORITY                     NVBIT(2)      // Deprioritize lock acquire
69 
70 /**
71  * Acquire the RM API Lock
72  *
73  * The API lock is a sleeping mutex that is used to serialize access to RM APIs
74  * by (passive-level) RM clients.
75  *
76  * The API lock is not used to protect state accessed by DPC and ISRs. For DPC
77  * and ISRs that GPU lock is used instead. For state controlled by clients, this
78  * often requires taking both API and GPU locks in API paths
79  *
80  * @param[in] flags  RM_LOCK_FLAGS_*
81  * @param[in] module RM_LOCK_MODULES_*
82  */
83 NV_STATUS rmapiLockAcquire(NvU32 flags, NvU32 module);
84 
85 /**
86  * Release RM API Lock
87  */
88 void rmapiLockRelease(void);
89 
90 /**
91  * Check if current thread owns the API lock
92  */
93 NvBool rmapiLockIsOwner(void);
94 
95 /**
96  * Check if current thread owns the RW API lock
97  */
98 NvBool rmapiLockIsWriteOwner(void);
99 
100 /**
101  * Retrieve total RM API lock wait and hold times
102  */
103 void rmapiLockGetTimes(NV0000_CTRL_SYSTEM_GET_LOCK_TIMES_PARAMS *);
104 
105 /**
106  * Indicates current thread is in the RTD3 PM path (rm_transition_dynamic_power) which
107  * means that certain locking asserts/checks must be skipped due to inability to acquire
108  * the API lock in this path.
109  */
110 void rmapiEnterRtd3PmPath(void);
111 
112 /**
113  * Signifies that current thread is leaving the RTD3 PM path, restoring lock
114  * asserting/checking behavior to normal.
115  */
116 void rmapiLeaveRtd3PmPath(void);
117 
118 /**
119  * Checks if current thread is currently running in the RTD3 PM path.
120  */
121 NvBool rmapiInRtd3PmPath(void);
122 
123 /**
124  * Type of RM API client interface
125  */
126 typedef enum
127 {
128     RMAPI_EXTERNAL,                 // For clients external from RM TLS, locks, etc -- no default security attributes
129     RMAPI_EXTERNAL_KERNEL,          // For clients external from TLS and locks but which still need default security attributes
130     RMAPI_MODS_LOCK_BYPASS,         // Hack for MODS - skip RM locks but initialize TLS (bug 1808386)
131     RMAPI_API_LOCK_INTERNAL,        // For clients that already have the TLS & API lock held -- security is RM internal
132     RMAPI_GPU_LOCK_INTERNAL,        // For clients that have TLS, API lock, and GPU lock -- security is RM internal
133     RMAPI_STUBS,                    // All functions just return NV_ERR_NOT_SUPPORTED
134     RMAPI_TYPE_MAX
135 } RMAPI_TYPE;
136 
137 /**
138  * Query interface that can be used to perform operations through the
139  * client-level RM API
140  */
141 RM_API *rmapiGetInterface(RMAPI_TYPE rmapiType);
142 
143 // Flags for RM_API::Alloc
144 #define RMAPI_ALLOC_FLAGS_NONE                    0
145 #define RMAPI_ALLOC_FLAGS_SKIP_RPC                NVBIT(0)
146 #define RMAPI_ALLOC_FLAGS_SERIALIZED              NVBIT(1)
147 
148 // Flags for RM_API::Free
149 #define RMAPI_FREE_FLAGS_NONE                     0
150 
151 // Flags for RM_API RPC's
152 #define RMAPI_RPC_FLAGS_NONE                      0
153 #define RMAPI_RPC_FLAGS_COPYOUT_ON_ERROR          NVBIT(0)
154 #define RMAPI_RPC_FLAGS_SERIALIZED                NVBIT(1)
155 
156 /**
157  * Interface for performing operations through the RM API exposed to client
158  * drivers. Interface provides consistent view to the RM API while abstracting
159  * the individuals callers from specifying security attributes and/or from
160  * locking needs. For example, this interface can be used either before or after
161  * the API or GPU locks.
162  */
163 struct _RM_API
164 {
165     // Allocate a resource with default security attributes and local pointers (no NvP64)
166     NV_STATUS (*Alloc)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hParent,
167                        NvHandle *phObject, NvU32 hClass, void *pAllocParams, NvU32 paramsSize);
168 
169     // Allocate a resource with default security attributes and local pointers (no NvP64)
170     // and client assigned handle
171     NV_STATUS (*AllocWithHandle)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hParent,
172                                  NvHandle hObject, NvU32 hClass, void *pAllocParams, NvU32 paramsSize);
173 
174     // Allocate a resource
175     NV_STATUS (*AllocWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hParent,
176                                   NvHandle *phObject, NvU32 hClass, NvP64 pAllocParams, NvU32 paramsSize,
177                                   NvU32 flags, NvP64 pRightsRequested, API_SECURITY_INFO *pSecInfo);
178 
179     // Free a resource with default security attributes
180     NV_STATUS (*Free)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hObject);
181 
182     // Free a resource
183     NV_STATUS (*FreeWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hObject,
184                                  NvU32 flags, API_SECURITY_INFO *pSecInfo);
185 
186     // Disables all clients in the list, with default security attributes
187     NV_STATUS (*DisableClients)(struct _RM_API *pRmApi, NvHandle *phClientList, NvU32 numClients);
188 
189     // Disables all clients in the list
190     NV_STATUS (*DisableClientsWithSecInfo)(struct _RM_API *pRmApi, NvHandle *phClientList,
191                                         NvU32 numClients, API_SECURITY_INFO *pSecInfo);
192 
193     // Invoke a control with default security attributes and local pointers (no NvP64)
194     NV_STATUS (*Control)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hObject, NvU32 cmd,
195                          void *pParams, NvU32 paramsSize);
196 
197     // Invoke a control
198     NV_STATUS (*ControlWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hObject, NvU32 cmd,
199                                     NvP64 pParams, NvU32 paramsSize, NvU32 flags, API_SECURITY_INFO *pSecInfo);
200 
201     // Prefetch a control parameters into the control call cache (0000, 0080 and 2080 classes only)
202     NV_STATUS (*ControlPrefetch)(struct _RM_API *pRmApi, NvU32 cmd);
203 
204     // Dup an object with default security attributes
205     NV_STATUS (*DupObject)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hParent, NvHandle *phObject,
206                            NvHandle hClientSrc, NvHandle hObjectSrc, NvU32 flags);
207 
208     // Dup an object
209     NV_STATUS (*DupObjectWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hParent,
210                                       NvHandle *phObject, NvHandle hClientSrc, NvHandle hObjectSrc, NvU32 flags,
211                                       API_SECURITY_INFO *pSecInfo);
212 
213     // Share an object with default security attributes
214     NV_STATUS (*Share)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hObject,
215                        RS_SHARE_POLICY *pSharePolicy);
216 
217     // Share an object
218     NV_STATUS (*ShareWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hObject,
219                                   RS_SHARE_POLICY *pSharePolicy, API_SECURITY_INFO *pSecInfo);
220 
221     // Map memory with default security attributes and local pointers (no NvP64). Provides
222     // RM internal implementation for NvRmMapMemory().
223     NV_STATUS (*MapToCpu)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemory,
224                           NvU64 offset, NvU64 length, void **ppCpuVirtAddr, NvU32 flags);
225 
226     // Map memory. Provides RM internal implementation for NvRmMapMemory().
227     NV_STATUS (*MapToCpuWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemory,
228                                      NvU64 offset, NvU64 length, NvP64 *ppCpuVirtAddr, NvU32 flags, API_SECURITY_INFO *pSecInfo);
229 
230     // Map memory v2. Pass in flags as a pointer for in/out access
231     NV_STATUS (*MapToCpuWithSecInfoV2)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemory,
232                                        NvU64 offset, NvU64 length, NvP64 *ppCpuVirtAddr, NvU32 *flags, API_SECURITY_INFO *pSecInfo);
233 
234     // Unmap memory with default security attributes and local pointers (no NvP64)
235     NV_STATUS (*UnmapFromCpu)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemory, void *pLinearAddress,
236                               NvU32 flags, NvU32 ProcessId);
237 
238     // Unmap memory
239     NV_STATUS (*UnmapFromCpuWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemory,
240                                          NvP64 pLinearAddress, NvU32 flags, NvU32 ProcessId, API_SECURITY_INFO *pSecInfo);
241 
242     // Map dma memory with default security attributes. Provides RM internal implementation for NvRmMapMemoryDma().
243     NV_STATUS (*Map)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemCtx, NvHandle hMemory,
244                      NvU64 offset, NvU64 length, NvU32 flags, NvU64 *pDmaOffset);
245 
246     // Map dma memory. Provides RM internal implementation for NvRmMapMemoryDma().
247     NV_STATUS (*MapWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemCtx, NvHandle hMemory,
248                                 NvU64 offset, NvU64 length, NvU32 flags, NvU64 *pDmaOffset, API_SECURITY_INFO *pSecInfo);
249 
250     // Unmap dma memory with default security attributes
251     NV_STATUS (*Unmap)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemCtx,
252                        NvU32 flags, NvU64 dmaOffset, NvU64 size);
253 
254     // Unmap dma memory
255     NV_STATUS (*UnmapWithSecInfo)(struct _RM_API *pRmApi, NvHandle hClient, NvHandle hDevice, NvHandle hMemCtx,
256                                   NvU32 flags, NvU64 dmaOffset, NvU64 size, API_SECURITY_INFO *pSecInfo);
257 
258     API_SECURITY_INFO  defaultSecInfo;
259     NvBool             bHasDefaultSecInfo;
260     NvBool             bTlsInternal;
261     NvBool             bApiLockInternal;
262     NvBool             bRmSemaInternal;
263     NvBool             bGpuLockInternal;
264     void              *pPrivateContext;
265 };
266 
267 // Called before any RM resource is freed
268 NV_STATUS rmapiFreeResourcePrologue(RS_RES_FREE_PARAMS_INTERNAL *pRmFreeParams);
269 
270 // Mark for deletion the client resources given a GPU mask
271 void rmapiSetDelPendingClientResourcesFromGpuMask(NvU32 gpuMask);
272 
273 // Delete the marked client resources
274 void rmapiDelPendingClients(void);
275 void rmapiDelPendingDevices(NvU32 gpuMask);
276 void rmapiReportLeakedDevices(NvU32 gpuMask);
277 
278 //
279 // Given a value, retrieves an array of client handles corresponding to clients
280 // with matching pOSInfo fields. The array is allocated dynamically, and is
281 // expected to be freed by the caller.
282 //
283 NV_STATUS rmapiGetClientHandlesFromOSInfo(void*, NvHandle**, NvU32*);
284 
285 //
286 // Base mapping routines for use by RsResource subclasses
287 //
288 NV_STATUS rmapiMapGpuCommon(RsResource *, CALL_CONTEXT *, RsCpuMapping *, OBJGPU *, NvU32, NvU32);
289 NV_STATUS rmapiValidateKernelMapping(RS_PRIV_LEVEL privLevel, NvU32 flags, NvBool *pbKernel);
290 NV_STATUS rmapiGetEffectiveAddrSpace(OBJGPU *pGpu, MEMORY_DESCRIPTOR *pMemDesc, NvU32 flags, NV_ADDRESS_SPACE *pAddrSpace);
291 
292 /**
293  * Deprecated RM API interfaces. Use RM_API instead.
294  */
295 NV_STATUS RmUnmapMemoryDma(NvHandle, NvHandle, NvHandle, NvHandle, MEMORY_DESCRIPTOR*, NvU32, NvU64);
296 NV_STATUS RmConfigGetEx   (NvHandle, NvHandle, NvU32, NvP64, NvU32, NvBool);
297 NV_STATUS RmConfigSetEx   (NvHandle, NvHandle, NvU32, NvP64, NvU32, NvBool);
298 
299 /**
300  * Control cache API.
301  */
302 NV_STATUS rmapiControlCacheInit(void);
303 NvBool rmapiControlIsCacheable(NvU32 flags, NvU32 accessRight, NvBool bAllowInternal);
304 NvBool rmapiCmdIsCacheable(NvU32 cmd, NvBool bAllowInternal);
305 NV_STATUS rmapiControlCacheGet(NvHandle hClient, NvHandle hObject, NvU32 cmd,
306                                void* params, NvU32 paramsSize);
307 NV_STATUS rmapiControlCacheSet(NvHandle hClient, NvHandle hObject, NvU32 cmd,
308                                void* params, NvU32 paramsSize);
309 NV_STATUS rmapiControlCacheSetGpuAttrForObject(NvHandle hClient, NvHandle hObject, OBJGPU *pGpu);
310 void rmapiControlCacheFreeAllCacheForGpu(NvU32 gpuInst);
311 void rmapiControlCacheSetMode(NvU32 mode);
312 NvU32 rmapiControlCacheGetMode(void);
313 void rmapiControlCacheFree(void);
314 void rmapiControlCacheFreeClientEntry(NvHandle hClient);
315 void rmapiControlCacheFreeObjectEntry(NvHandle hClient, NvHandle hObject);
316 
317 typedef struct _RM_API_CONTEXT {
318     NvU32 gpuMask;
319 } RM_API_CONTEXT;
320 
321 //
322 // Handler to do stuff that is required  before invoking a RM API
323 //
324 NV_STATUS
325 rmapiPrologue
326 (
327     RM_API            *pRmApi,
328     RM_API_CONTEXT    *pContext
329 );
330 
331 //
332 // Handler to do stuff that is required after invoking a RM API
333 //
334 void
335 rmapiEpilogue
336 (
337     RM_API            *pRmApi,
338     RM_API_CONTEXT    *pContext
339 );
340 
341 NV_STATUS
342 rmapiInitLockInfo
343 (
344     RM_API       *pRmApi,
345     NvHandle      hClient,
346     NvHandle      hSecondClient,
347     RS_LOCK_INFO *pLockInfo
348 );
349 
350 //
351 // RM locking modules: 24-bit group bitmask, 8-bit subgroup id
352 //
353 // Lock acquires are tagged with a RM_LOCK_MODULE_* in order to partition
354 // the acquires into groups, which allows read-only locks to be
355 // enabled / disabled on a per-group basis (via apiLockMask and gpuLockMask
356 // in OBJSYS.)
357 //
358 // The groups are further partitioned into subgroups, which
359 // are used for lock profiling data collection.
360 //
361 #define RM_LOCK_MODULE_VAL(grp, subgrp)     ((((grp) & 0xffffff) << 8) | ((subgrp) & 0xff))
362 #define RM_LOCK_MODULE_GRP(val)             (((val) >> 8) & 0xffffff)
363 //                                                             Grp       SubGrp
364 #define RM_LOCK_MODULES_NONE                RM_LOCK_MODULE_VAL(0x000000, 0x00)
365 
366 #define RM_LOCK_MODULES_WORKITEM            RM_LOCK_MODULE_VAL(0x000001, 0x00)
367 
368 #define RM_LOCK_MODULES_CLIENT              RM_LOCK_MODULE_VAL(0x000002, 0x00)
369 
370 #define RM_LOCK_MODULES_GPU_OPS             RM_LOCK_MODULE_VAL(0x000004, 0x00)
371 
372 #define RM_LOCK_MODULES_OSAPI               RM_LOCK_MODULE_VAL(0x000010, 0x00)
373 #define RM_LOCK_MODULES_STATE_CONFIG        RM_LOCK_MODULE_VAL(0x000010, 0x01)
374 #define RM_LOCK_MODULES_EVENT               RM_LOCK_MODULE_VAL(0x000010, 0x02)
375 #define RM_LOCK_MODULES_VBIOS               RM_LOCK_MODULE_VAL(0x000010, 0x03)
376 
377 #define RM_LOCK_MODULES_MEM                 RM_LOCK_MODULE_VAL(0x000020, 0x00)
378 #define RM_LOCK_MODULES_MEM_FLA             RM_LOCK_MODULE_VAL(0x000020, 0x01)
379 #define RM_LOCK_MODULES_MEM_PMA             RM_LOCK_MODULE_VAL(0x000020, 0x02)
380 
381 #define RM_LOCK_MODULES_POWER               RM_LOCK_MODULE_VAL(0x000040, 0x00)
382 #define RM_LOCK_MODULES_ACPI                RM_LOCK_MODULE_VAL(0x000040, 0x01)
383 #define RM_LOCK_MODULES_DYN_POWER           RM_LOCK_MODULE_VAL(0x000040, 0x02)
384 
385 #define RM_LOCK_MODULES_HYPERVISOR          RM_LOCK_MODULE_VAL(0x000080, 0x00)
386 #define RM_LOCK_MODULES_VGPU                RM_LOCK_MODULE_VAL(0x000080, 0x01)
387 #define RM_LOCK_MODULES_RPC                 RM_LOCK_MODULE_VAL(0x000080, 0x02)
388 
389 #define RM_LOCK_MODULES_DIAG                RM_LOCK_MODULE_VAL(0x000100, 0x00)
390 #define RM_LOCK_MODULES_RC                  RM_LOCK_MODULE_VAL(0x000100, 0x01)
391 
392 #define RM_LOCK_MODULES_SLI                 RM_LOCK_MODULE_VAL(0x000200, 0x00)
393 #define RM_LOCK_MODULES_P2P                 RM_LOCK_MODULE_VAL(0x000200, 0x01)
394 #define RM_LOCK_MODULES_NVLINK              RM_LOCK_MODULE_VAL(0x000200, 0x02)
395 
396 #define RM_LOCK_MODULES_HOTPLUG             RM_LOCK_MODULE_VAL(0x000400, 0x00)
397 #define RM_LOCK_MODULES_DISP                RM_LOCK_MODULE_VAL(0x000400, 0x01)
398 #define RM_LOCK_MODULES_KERNEL_RM_EVENTS    RM_LOCK_MODULE_VAL(0x000400, 0x02)
399 
400 #define RM_LOCK_MODULES_GPU                 RM_LOCK_MODULE_VAL(0x000800, 0x00)
401 #define RM_LOCK_MODULES_GR                  RM_LOCK_MODULE_VAL(0x000800, 0x01)
402 #define RM_LOCK_MODULES_FB                  RM_LOCK_MODULE_VAL(0x000800, 0x02)
403 #define RM_LOCK_MODULES_FIFO                RM_LOCK_MODULE_VAL(0x000800, 0x03)
404 #define RM_LOCK_MODULES_TMR                 RM_LOCK_MODULE_VAL(0x000800, 0x04)
405 
406 #define RM_LOCK_MODULES_I2C                 RM_LOCK_MODULE_VAL(0x001000, 0x00)
407 #define RM_LOCK_MODULES_PFM_REQ_HNDLR       RM_LOCK_MODULE_VAL(0x001000, 0x01)
408 #define RM_LOCK_MODULES_SEC2                RM_LOCK_MODULE_VAL(0x001000, 0x02)
409 #define RM_LOCK_MODULES_THERM               RM_LOCK_MODULE_VAL(0x001000, 0x03)
410 #define RM_LOCK_MODULES_INFOROM             RM_LOCK_MODULE_VAL(0x001000, 0x04)
411 
412 #define RM_LOCK_MODULES_ISR                 RM_LOCK_MODULE_VAL(0x002000, 0x00)
413 #define RM_LOCK_MODULES_DPC                 RM_LOCK_MODULE_VAL(0x002000, 0x01)
414 
415 #define RM_LOCK_MODULES_INIT                RM_LOCK_MODULE_VAL(0x004000, 0x00)
416 #define RM_LOCK_MODULES_STATE_LOAD          RM_LOCK_MODULE_VAL(0x004000, 0x01)
417 
418 #define RM_LOCK_MODULES_STATE_UNLOAD        RM_LOCK_MODULE_VAL(0x008000, 0x00)
419 #define RM_LOCK_MODULES_DESTROY             RM_LOCK_MODULE_VAL(0x008000, 0x01)
420 
421 //
422 // ResServ lock flag translation
423 //
424 #define RM_LOCK_FLAGS_NONE                     0
425 #define RM_LOCK_FLAGS_NO_API_LOCK              RS_LOCK_FLAGS_NO_TOP_LOCK
426 #define RM_LOCK_FLAGS_NO_CLIENT_LOCK           RS_LOCK_FLAGS_NO_CLIENT_LOCK
427 #define RM_LOCK_FLAGS_NO_GPUS_LOCK             RS_LOCK_FLAGS_NO_CUSTOM_LOCK_1
428 #define RM_LOCK_FLAGS_GPU_GROUP_LOCK           RS_LOCK_FLAGS_NO_CUSTOM_LOCK_2
429 #define RM_LOCK_FLAGS_RM_SEMA                  RS_LOCK_FLAGS_NO_CUSTOM_LOCK_3
430 
431 //
432 // ResServ lock state translation
433 //
434 #define RM_LOCK_STATES_NONE                    0
435 #define RM_LOCK_STATES_API_LOCK_ACQUIRED       RS_LOCK_STATE_TOP_LOCK_ACQUIRED
436 #define RM_LOCK_STATES_GPUS_LOCK_ACQUIRED      RS_LOCK_STATE_CUSTOM_LOCK_1_ACQUIRED
437 #define RM_LOCK_STATES_GPU_GROUP_LOCK_ACQUIRED RS_LOCK_STATE_CUSTOM_LOCK_2_ACQUIRED
438 #define RM_LOCK_STATES_ALLOW_RECURSIVE_LOCKS   RS_LOCK_STATE_ALLOW_RECURSIVE_RES_LOCK
439 #define RM_LOCK_STATES_CLIENT_LOCK_ACQUIRED    RS_LOCK_STATE_CLIENT_LOCK_ACQUIRED
440 #define RM_LOCK_STATES_RM_SEMA_ACQUIRED        RS_LOCK_STATE_CUSTOM_LOCK_3_ACQUIRED
441 
442 //
443 // ResServ lock release translation
444 //
445 #define RM_LOCK_RELEASE_API_LOCK               RS_LOCK_RELEASE_TOP_LOCK
446 #define RM_LOCK_RELEASE_CLIENT_LOCK            RS_LOCK_RELEASE_CLIENT_LOCK
447 #define RM_LOCK_RELEASE_GPUS_LOCK              RS_LOCK_RELEASE_CUSTOM_LOCK_1
448 #define RM_LOCK_RELEASE_GPU_GROUP_LOCK         RS_LOCK_RELEASE_CUSTOM_LOCK_2
449 #define RM_LOCK_RELEASE_RM_SEMA                RS_LOCK_RELEASE_CUSTOM_LOCK_3
450 
451 #endif // _RMAPI_H_
452