NVIDIA DriveOS Linux SDK API Reference

7.2.5.0 Early Access Release
nvrm_drf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2007 - 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #ifndef INCLUDED_NVRM_DRF_H
14 #define INCLUDED_NVRM_DRF_H
15 
16 #ifndef _NVMISC_MACROS_H
17 #define _NVMISC_MACROS_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif //__cplusplus
22 
23 /* These macros are taken from desktop driver branch file
24  * <P4>/sw/dev/gpu_drv/$BRANCH/sdk/nvidia/inc/nvmisc.h
25  * This is to handle difference between DRF macros
26  * between Mobile and Desktop
27  */
28 
29 // nvrm_drf.h can't access nvmisc.h in the Mobile tree... but in some places both are used.
30 #if !defined(__NV_MISC_H) && !defined(NV_MISC_H)
31 
32 #define DEVICE_BASE(d) (0 ? d) // what's up with this name? totally non-parallel to the macros below
33 #define DEVICE_EXTENT(d) (1 ? d) // what's up with this name? totally non-parallel to the macros below
34 
35 #ifdef NV_USE_FIELD_RANGE_DEFS // These macros are added to remove MISRA C rule 14.3 violations
36 // Components which have defined HIGH_FIELD/LOW_FIELD can use below DRF macros
37 #define DRF_BASE(drf) (drf##_LOW_FIELD)
38 #define DRF_EXTENT(drf) (drf##_HIGH_FIELD)
39 #define DRF_SHIFT(drf) ((drf##_LOW_FIELD) % 32U)
40 #define DRF_MASK(drf) (0xFFFFFFFFU >> (31U - ((drf##_HIGH_FIELD) % 32U) + ((drf##_LOW_FIELD) % 32U)))
41 
42 #else // For components which have not defined HIGH_FIELD/LOW_FIELD
43 
44 // the first bit occupied by the field in a HW value (e.g., register)
45 #define DRF_BASE(drf) (NV_FALSE ? drf)
46 
47 // the last bit occupied by the field in a HW value
48 #define DRF_EXTENT(drf) (NV_TRUE ? drf)
49 
50 // the bit shift amount for accessing the field
51 #define DRF_SHIFT(drf) (((NvU32)DRF_BASE(drf)) % 32U)
52 
53 // bitmask for the value (unshifted)
54 #define DRF_MASK(drf) (0xFFFFFFFFU >> (31U - (((NvU32)DRF_EXTENT(drf)) % 32U) + (((NvU32)DRF_BASE(drf)) % 32U)))
55 #endif
56 
57 // bitmask for the value (shifted for HW value)
58 #define DRF_SHIFTMASK(drf) (DRF_MASK(drf) << (DRF_SHIFT(drf)))
59 
60 // size of the field (in bits)
61 #define DRF_SIZE(drf) (DRF_EXTENT(drf) - DRF_BASE(drf) + 1U)
62 
63 // constant value for HW, e.g., reg |= DRF_DEF(A06F, _GP_ENTRY1, _LEVEL, _SUBROUTINE);
64 #define DRF_DEF(d,r,f,c) (((NvU32)(NV ## d ## r ## f ## c)) << (DRF_SHIFT(NV ## d ## r ## f)))
65 
66 // numeric value for HW, e.g., reg |= DRF_NUM(A06F, _GP_ENTRY1, _LENGTH, numWords);
67 // Note: n should be unsigned 32-bit integer
68 #define DRF_NUM(d,r,f,n) ((((NvU32)(n)) & (DRF_MASK(NV ## d ## r ## f))) << (DRF_SHIFT(NV ## d ## r ## f)))
69 
70 // numeric value from HW value, e.g., unsigned int numWords = DRF_VAL(A06F, _GP_ENTRY1, _LENGTH, reg);
71 // Note: v should be unsigned 32-bit integer
72 #define DRF_VAL(d,r,f,v) (((v) >> DRF_SHIFT(NV ## d ## r ## f)) & DRF_MASK(NV ## d ## r ## f))
73 
74 #endif
75 
76 #ifdef __cplusplus
77 }
78 #endif //__cplusplus
79 
80 #endif //_NVMISC_MACROS_H
81 
118 /*
119  * The NV_FIELD_* macros are helper macros for the public NV_DRF_* macros.
120  */
121 #ifdef USE_MISRA_COMPLIANT_HW_HEADERS
122 /*
123  * Make use of some new macros for LSB and MSB bits added in the MISRA compliant HW headers.
124  */
125 #define NV_FIELD_LOWBIT(x) (x##_LSB)
126 #define NV_FIELD_HIGHBIT(x) (x##_MSB)
127 #define NV_FIELD_SHIFT(x) ((NV_FIELD_LOWBIT(x))%32U)
128 #define NV_FIELD_MASK(x) (NvU32)(0xFFFFFFFFU >> \
129  (31U - ((NV_FIELD_HIGHBIT(x)) % 32U) + ((NV_FIELD_LOWBIT(x)) % 32U)))
130 #else //USE_MISRA_COMPLIANT_HW_HEADERS
131 #define NV_FIELD_LOWBIT(x) ((0!=0)?x)
132 #define NV_FIELD_HIGHBIT(x) ((0==0)?x)
133 #ifdef __cplusplus
134 #define NV_FIELD_SIZE(x) (static_cast<NvU32>(NV_FIELD_HIGHBIT(x))-static_cast<NvU32>(NV_FIELD_LOWBIT(x))+1U)
135 #else
136 #define NV_FIELD_SIZE(x) ((NvU32)NV_FIELD_HIGHBIT(x)-(NvU32)NV_FIELD_LOWBIT(x)+1U)
137 #endif
138 #define NV_FIELD_SHIFT(x) (((0!=0)?x)%32)
139 #define NV_FIELD_MASK(x) (0xFFFFFFFFUL>>(31-(((1!=0)?x)%32)+(((0!=0)?x)%32)))
140 #define NV_FIELD_BITS(val, x) (((val) & NV_FIELD_MASK(x))<<NV_FIELD_SHIFT(x))
141 #endif
142 #define NV_FIELD_SHIFTMASK(x) (NV_FIELD_MASK(x)<< (NV_FIELD_SHIFT(x)))
143 
144 /*
145  * The NV_FIELD64_* macros are helper macros for the public NV_DRF64_* macros.
146  */
147 #define NV_FIELD64_SHIFT(x) ((0?x)%64)
148 #define NV_FIELD64_MASK(x) (0xFFFFFFFFFFFFFFFFULL>>(63-((1?x)%64)+((0?x)%64)))
149 
150 
160 #ifdef USE_MISRA_COMPLIANT_HW_HEADERS
161 #define NV_DRF_DEF(d,r,f,c) \
162  (((NvU32)d##_##r##_0_##f##_##c) << (NV_FIELD_SHIFT(d##_##r##_0_##f)))
163 #else
164 #define NV_DRF_DEF(d,r,f,c) \
165  ((d##_##r##_0_##f##_##c) << NV_FIELD_SHIFT(d##_##r##_0_##f##_RANGE))
166 #endif
167 
177 #ifdef USE_MISRA_COMPLIANT_HW_HEADERS
178 #define NV_DRF_NUM(d,r,f,n) \
179  ((NvU32)((NvU32)(n) & (NV_FIELD_MASK(d##_##r##_0_##f))) << \
180  (NV_FIELD_SHIFT(d##_##r##_0_##f)))
181 #else
182 #define NV_DRF_NUM(d,r,f,n) \
183  (((n)& NV_FIELD_MASK(d##_##r##_0_##f##_RANGE)) << \
184  NV_FIELD_SHIFT(d##_##r##_0_##f##_RANGE))
185 #endif
186 
196 #ifdef USE_MISRA_COMPLIANT_HW_HEADERS
197 #define NV_DRF_VAL(d,r,f,v) \
198  (((NvU32)(v) >> (NV_FIELD_SHIFT(d##_##r##_0_##f))) & \
199  (NV_FIELD_MASK(d##_##r##_0_##f)))
200 #else
201 #define NV_DRF_VAL(d,r,f,v) \
202  (((v)>> NV_FIELD_SHIFT(d##_##r##_0_##f##_RANGE)) & \
203  NV_FIELD_MASK(d##_##r##_0_##f##_RANGE))
204 #endif
205 
216 #ifdef USE_MISRA_COMPLIANT_HW_HEADERS
217 #define NV_FLD_SET_DRF_NUM(d,r,f,n,v) \
218  (((NvU32)(v) & ~(NV_FIELD_SHIFTMASK(d##_##r##_0_##f))) | \
219  (NV_DRF_NUM(d,r,f,n)))
220 #else
221 #define NV_FLD_SET_DRF_NUM(d,r,f,n,v) \
222  (((v) & ~NV_FIELD_SHIFTMASK(d##_##r##_0_##f##_RANGE)) | NV_DRF_NUM(d,r,f,n))
223 #endif
224 
235 #ifdef USE_MISRA_COMPLIANT_HW_HEADERS
236 #define NV_FLD_SET_DRF_DEF(d,r,f,c,v) \
237  (((NvU32)(v) & ~(NV_FIELD_SHIFTMASK(d##_##r##_0_##f))) | \
238  (NV_DRF_DEF(d,r,f,c)))
239 #else
240 #define NV_FLD_SET_DRF_DEF(d,r,f,c,v) \
241  (((v) & ~NV_FIELD_SHIFTMASK(d##_##r##_0_##f##_RANGE)) | \
242  NV_DRF_DEF(d,r,f,c))
243 #endif
244 
252 #define NV_RESETVAL(d,r) (d##_##r##_0_RESET_VAL)
253 
254 
264 #define NV_DRF64_NUM(d,r,f,n) \
265  (((n)& NV_FIELD64_MASK(d##_##r##_0_##f##_RANGE)) << \
266  NV_FIELD64_SHIFT(d##_##r##_0_##f##_RANGE))
267 
268 #endif // INCLUDED_NVRM_DRF_H