NVIDIA DriveOS Linux NSR SDK API Reference

7.0.3.0 Release
nvcommon.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2006-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA Corporation and its licensors retain all intellectual property
6  * and proprietary rights in and to this software, related documentation
7  * and any modifications thereto. Any use, reproduction, disclosure or
8  * distribution of this software and related documentation without an express
9  * license agreement from NVIDIA Corporation is strictly prohibited.
10  */
11 
12 #ifndef INCLUDED_NVCOMMON_H
13 #define INCLUDED_NVCOMMON_H
14 #if ((defined(__QNX__) || defined(__linux__)) && defined(NV_IS_SAFETY) && (NV_IS_SAFETY == 1))
15 #include "nvcommon_tegra_safety.h"
16 #else
17 
38 // Pull in some headers that are mirrored from desktop.
39 #include "nvtypes.h"
40 
43 #include <stddef.h>
44 #if defined(__hos__) || (defined(__linux__) && !defined(__KERNEL__)) || defined(__arm) || defined(__APPLE__) || defined(__QNX__) || defined(__INTEGRITY) || defined(NV_HYPERVISOR)
45 #include <stdint.h>
46 #endif
47 
48 // Rest of this file is mobile-only definitions, and appending to them
49 // is discouraged since it prevents header portability between mobile
50 // and desktop.
51 #define NV_FORCE_INLINE NV_FORCEINLINE
52 #define NV_ALIGN NV_ALIGN_BYTES
53 
54 #if (NVCPU_IS_X86 && NVOS_IS_WINDOWS)
55 # define NVOS_IS_WINDOWS_X86 1
56 #else
57 # define NVOS_IS_WINDOWS_X86 0
58 #endif
59 
60 #if defined(__APPLE__)
61 # define NVOS_IS_DARWIN 1
62 # define NVOS_IS_UNIX 1
63 #endif
64 
65 #define NVOS_IS_LINUX_KERNEL 0
66 
68 #define NV_MIN_F32 (1.1754944e-38f)
69 #define NV_MAX_F32 (3.4028234e+38f)
70 
72 #if defined(__GNUC__)
73 #define NV_ALIGN_POINTER_NAME(f) f##Align
74 #define NV_ALIGN_POINTER(t, f) \
75  union { \
76  t f; \
77  NvU64 NV_ALIGN_POINTER_NAME(f); \
78  }
79 #else
80 /* rvds builds don't support anonymous unions but also don't need
81  * 64-bit alignment.
82  */
83 #define NV_ALIGN_POINTER(t, f) t f
84 #endif
85 
88 #if NVOS_IS_WINDOWS
89 
90 #define NV_NAKED __declspec(naked)
91 #define NV_LIKELY(c) (c)
92 #define NV_UNLIKELY(c) (c)
93 #define NV_UNUSED
94 
95 #elif defined(__ghs__) // GHS COMP
96 #define NV_NAKED
97 #define NV_LIKELY(c) (c)
98 #define NV_UNLIKELY(c) (c)
99 #define NV_UNUSED __attribute__((unused))
100 
101 #elif defined(__GNUC__)
102 #define NV_NAKED __attribute__((naked))
103 #define NV_LIKELY(c) __builtin_expect((c),1)
104 #define NV_UNLIKELY(c) __builtin_expect((c),0)
105 #define NV_UNUSED __attribute__((unused))
106 
107 #elif defined(__arm) // ARM RVDS compiler
108 #define NV_NAKED __asm
109 #define NV_LIKELY(c) (c)
110 #define NV_UNLIKELY(c) (c)
111 #define NV_UNUSED
112 
113 #else
114 #error Unknown compiler
115 #endif
116 
119 #if NVOS_IS_WINDOWS
120 #define NV_WEAK
121 #elif defined(__ghs__)
122 #define NV_WEAK __attribute__((weak))
123 #elif defined(__GNUC__)
124 #define NV_WEAK __attribute__((weak))
125 #elif defined(__arm)
126 #define NV_WEAK __weak
127 #else
128 #error Unknown compiler
129 #endif
130 
131 // NV_DEBUG_CODE conflicts with the definition of the same name
132 // in OpenGL/nvInc/nvDebug.h.
133 #if !defined(NV_DEBUG_CODE)
134 
138 #if NV_DEBUG
139 #define NV_DEBUG_CODE(x) x
140 #else
141 #define NV_DEBUG_CODE(x)
142 #endif
143 #endif
144 
146 #define NV_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
147 
149 #ifndef NV_MIN
150 #define NV_MIN(a,b) (((a) < (b)) ? (a) : (b))
151 #endif
152 #ifndef NV_MAX
153 #define NV_MAX(a,b) (((a) > (b)) ? (a) : (b))
154 #endif
155 
157 #if !defined(NV_OFFSETOF)
158  #if defined(__GNUC__)
159  #define NV_OFFSETOF(type, member) __builtin_offsetof(type, member)
160  #else
161  #define NV_OFFSETOF(type, member) ((NvUPtr)(&(((type *)0)->member)))
162  #endif
163 #endif
164 
166 #define NV_SIZEOF(s,e) (sizeof(((s*)0)->e))
167 
169 #define NV_LOWEST_BIT_ONLY(v) ((NvU32)(v) & (NvU32)-(NvS32)(v))
170 
172 #define NV_IS_POWER_OF_2(v) (NV_LOWEST_BIT_ONLY(v) == (NvU32)(v))
173 
180 #define NV_WAIT_INFINITE 0xFFFFFFFF
181 
183 #if defined(_PREFAST_)
184 #define NV_ANALYSIS_ASSUME(x) __analysis_assume(x)
185 #else
186 #define NV_ANALYSIS_ASSUME(x)
187 #endif
188 
193 typedef NvU64 NvPhysAddr64;
194 
201 typedef NvU32 NvRmPhysAddr;
202 
212 static NV_FORCE_INLINE NvU64
213 NvDiv64Inline(NvU64 dividend, NvU32 divisor)
214 {
215  if (divisor == 0U) {
216  return 0;
217  }
218  return dividend / divisor;
219 }
220 
221 #define NvDiv64(dividend, divisor) NvDiv64Inline(dividend, divisor)
222 
232 typedef union NvData32Rec
233 {
234  NvU32 u;
235  NvS32 i;
236  NvF32 f;
237 } NvData32;
238 
242 typedef union NvData64Rec
243 {
244  NvU32 u;
245  NvS32 i;
246  NvF32 f;
247  NvU64 u64;
248  NvS64 i64;
249  NvF64 d;
250 } NvData64;
251 
257 typedef struct NvPointRec
258 {
260  NvS32 x;
261 
263  NvS32 y;
264 } NvPoint;
265 
266 typedef struct NvPointF32Rec
267 {
269  NvF32 x;
270 
272  NvF32 y;
273 } NvPointF32;
279 typedef struct NvRectRec
280 {
282  NvS32 left;
283 
285  NvS32 top;
286 
288  NvS32 right;
289 
291  NvS32 bottom;
292 } NvRect;
293 
298 typedef struct NvRectF32Rec
299 {
300  NvF32 left;
301  NvF32 top;
302  NvF32 right;
303  NvF32 bottom;
304 } NvRectF32;
305 
310 typedef struct NvSizeRec
311 {
312  /* width of the surface in pixels */
313  NvS32 width;
314 
315  /* height of the surface in pixels */
316  NvS32 height;
317 } NvSize;
318 
320 #endif
321 #endif // INCLUDED_NVCOMMON_H
NvRectF32Rec::right
NvF32 right
Definition: nvcommon.h:302
NvData32
union NvData32Rec NvData32
Union that can be used to view a 32-bit word as your choice of a 32-bit unsigned integer,...
NvData64Rec::f
NvF32 f
Definition: nvcommon.h:246
NvRectRec::right
NvS32 right
right column of a rectangle
Definition: nvcommon.h:288
NvSizeRec
This structure is used to define a 2-dimensional surface where the surface is determined by it's heig...
Definition: nvcommon.h:310
NvPointF32Rec::y
NvF32 y
vertical location of the point
Definition: nvcommon.h:272
NvPointF32
struct NvPointF32Rec NvPointF32
NvData64Rec::d
NvF64 d
Definition: nvcommon.h:249
NvPointRec::x
NvS32 x
horizontal location of the point
Definition: nvcommon.h:260
NvRectF32Rec
This structure is used to define a 2-dimensional rectangle with floating point coordinates.
Definition: nvcommon.h:298
NvRectRec
This structure is used to define a 2-dimensional rectangle where the rectangle is bottom right exclus...
Definition: nvcommon.h:279
NvData64Rec::i64
NvS64 i64
Definition: nvcommon.h:248
NvSizeRec::width
NvS32 width
Definition: nvcommon.h:313
NvData32Rec::i
NvS32 i
Definition: nvcommon.h:235
NvRectF32
struct NvRectF32Rec NvRectF32
This structure is used to define a 2-dimensional rectangle with floating point coordinates.
NvDiv64Inline
static NV_FORCE_INLINE NvU64 NvDiv64Inline(NvU64 dividend, NvU32 divisor)
Performs the 64-bit division and returns the quotient.
Definition: nvcommon.h:213
NvData64Rec
Generic data representation for both 32 and 64 bits data.
Definition: nvcommon.h:242
NvData32Rec::u
NvU32 u
Definition: nvcommon.h:234
NvPointF32Rec::x
NvF32 x
horizontal location of the point
Definition: nvcommon.h:269
nvtypes.h
NvPointRec::y
NvS32 y
vertical location of the point
Definition: nvcommon.h:263
NvData64Rec::u
NvU32 u
Definition: nvcommon.h:244
NvData64Rec::i
NvS32 i
Definition: nvcommon.h:245
NvRectRec::top
NvS32 top
top row of a rectangle
Definition: nvcommon.h:285
NvData64
union NvData64Rec NvData64
Generic data representation for both 32 and 64 bits data.
NvRectF32Rec::top
NvF32 top
Definition: nvcommon.h:301
NV_FORCE_INLINE
#define NV_FORCE_INLINE
Include headers that provide NULL, size_t, offsetof, and [u]intptr_t.
Definition: nvcommon.h:51
NvPoint
struct NvPointRec NvPoint
This structure is used to determine a location on a 2-dimensional object, where the coordinate (0,...
NvRectF32Rec::left
NvF32 left
Definition: nvcommon.h:300
NvData32Rec
Union that can be used to view a 32-bit word as your choice of a 32-bit unsigned integer,...
Definition: nvcommon.h:232
NvData64Rec::u64
NvU64 u64
Definition: nvcommon.h:247
NvPhysAddr64
NvU64 NvPhysAddr64
A physical address type sized such that it matches the addressing support of the hardware modules wit...
Definition: nvcommon.h:193
NvRmPhysAddr
NvU32 NvRmPhysAddr
This is deprecated and shouldn't be used.
Definition: nvcommon.h:201
NvData32Rec::f
NvF32 f
Definition: nvcommon.h:236
NvSizeRec::height
NvS32 height
Definition: nvcommon.h:316
NvRect
struct NvRectRec NvRect
This structure is used to define a 2-dimensional rectangle where the rectangle is bottom right exclus...
NvPointRec
This structure is used to determine a location on a 2-dimensional object, where the coordinate (0,...
Definition: nvcommon.h:257
NvSize
struct NvSizeRec NvSize
This structure is used to define a 2-dimensional surface where the surface is determined by it's heig...
NvPointF32Rec
Definition: nvcommon.h:266
NvRectRec::bottom
NvS32 bottom
bottom row of a rectangle
Definition: nvcommon.h:291
NvRectF32Rec::bottom
NvF32 bottom
Definition: nvcommon.h:303
NvRectRec::left
NvS32 left
left column of a rectangle
Definition: nvcommon.h:282