OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2006-2009 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 #ifndef INCLUDED_NVCOMMON_H |
| 33 #define INCLUDED_NVCOMMON_H |
| 34 |
| 35 // Include headers that provide NULL, size_t, offsetof, and [u]intptr_t. In |
| 36 // the event that the toolchain doesn't provide these, provide them ourselves. |
| 37 #include <stddef.h> |
| 38 #if defined(_WIN32_WCE) |
| 39 typedef int intptr_t; |
| 40 typedef unsigned int uintptr_t; |
| 41 #elif (defined(__linux__) && !defined(__KERNEL__)) || defined(__arm) |
| 42 #include <stdint.h> |
| 43 #endif |
| 44 |
| 45 #if defined(__cplusplus) |
| 46 extern "C" |
| 47 { |
| 48 #endif |
| 49 |
| 50 /** |
| 51 * @defgroup nvcommon Common Declarations |
| 52 * |
| 53 * nvcommon.h contains standard definitions used by various interfaces |
| 54 * |
| 55 * @{ |
| 56 */ |
| 57 |
| 58 |
| 59 /** |
| 60 * If an OS DEFINE is not set, it should be set to 0 |
| 61 */ |
| 62 #ifndef NV_OS_CE_500 |
| 63 #define NV_OS_CE_500 0 |
| 64 #endif |
| 65 #ifndef NV_OS_CE_600 |
| 66 #define NV_OS_CE_600 0 |
| 67 #endif |
| 68 #ifndef NV_OS_WM_600 |
| 69 #define NV_OS_WM_600 0 |
| 70 #endif |
| 71 #ifndef NV_OS_700 |
| 72 #define NV_OS_700 0 |
| 73 #endif |
| 74 |
| 75 |
| 76 // OS-related #define's |
| 77 #if defined(_WIN32) |
| 78 #define NVOS_IS_WINDOWS 1 |
| 79 #if defined(_WIN32_WCE) |
| 80 #define NVOS_IS_WINDOWS_CE 1 |
| 81 #endif |
| 82 #elif defined(__linux__) |
| 83 #define NVOS_IS_LINUX 1 |
| 84 #define NVOS_IS_UNIX 1 |
| 85 #if defined(__KERNEL__) |
| 86 #define NVOS_IS_LINUX_KERNEL 1 |
| 87 #endif |
| 88 #elif defined(__arm__) && defined(__ARM_EABI__) |
| 89 /* GCC arm eabi compiler, potentially used for kernel compilation without |
| 90 * __linux__, but also for straight EABI (AOS) executable builds */ |
| 91 # if defined(__KERNEL__) |
| 92 # define NVOS_IS_LINUX 1 |
| 93 # define NVOS_IS_UNIX 1 |
| 94 # define NVOS_IS_LINUX_KERNEL 1 |
| 95 # endif |
| 96 /* Nothing to define for AOS */ |
| 97 #elif defined(__arm) |
| 98 // For ARM RVDS compiler, we don't know the final target OS at compile time |
| 99 #else |
| 100 #error Unknown OS |
| 101 #endif |
| 102 |
| 103 #if !defined(NVOS_IS_WINDOWS) |
| 104 #define NVOS_IS_WINDOWS 0 |
| 105 #endif |
| 106 #if !defined(NVOS_IS_WINDOWS_CE) |
| 107 #define NVOS_IS_WINDOWS_CE 0 |
| 108 #endif |
| 109 #if !defined(NVOS_IS_LINUX) |
| 110 #define NVOS_IS_LINUX 0 |
| 111 #endif |
| 112 #if !defined(NVOS_IS_UNIX) |
| 113 #define NVOS_IS_UNIX 0 |
| 114 #endif |
| 115 #if !defined(NVOS_IS_LINUX_KERNEL) |
| 116 #define NVOS_IS_LINUX_KERNEL 0 |
| 117 #endif |
| 118 |
| 119 // CPU-related #define's |
| 120 #if defined(_M_IX86) || defined(__i386__) |
| 121 #define NVCPU_IS_X86 1 // any IA32 machine (not AMD64) |
| 122 #define NVCPU_MIN_PAGE_SHIFT 12 |
| 123 #elif defined(_M_ARM) || defined(__arm__) |
| 124 #define NVCPU_IS_ARM 1 |
| 125 #define NVCPU_MIN_PAGE_SHIFT 12 |
| 126 #else |
| 127 #error Unknown CPU |
| 128 #endif |
| 129 #if !defined(NVCPU_IS_X86) |
| 130 #define NVCPU_IS_X86 0 |
| 131 #endif |
| 132 #if !defined(NVCPU_IS_ARM) |
| 133 #define NVCPU_IS_ARM 0 |
| 134 #endif |
| 135 |
| 136 #if (NVCPU_IS_X86 && NVOS_IS_WINDOWS) |
| 137 #define NVOS_IS_WINDOWS_X86 1 |
| 138 #else |
| 139 #define NVOS_IS_WINDOWS_X86 0 |
| 140 #endif |
| 141 |
| 142 // The minimum page size can be determined from the minimum page shift |
| 143 #define NVCPU_MIN_PAGE_SIZE (1 << NVCPU_MIN_PAGE_SHIFT) |
| 144 |
| 145 // We don't currently support any big-endian CPUs |
| 146 #define NVCPU_IS_BIG_ENDIAN 0 |
| 147 |
| 148 // We don't currently support any 64-bit CPUs |
| 149 #define NVCPU_IS_64_BITS 0 |
| 150 |
| 151 // Explicitly sized signed and unsigned ints |
| 152 typedef unsigned char NvU8; // 0 to 255 |
| 153 typedef unsigned short NvU16; // 0 to 65535 |
| 154 typedef unsigned int NvU32; // 0 to 4294967295 |
| 155 typedef unsigned long long NvU64; // 0 to 18446744073709551615 |
| 156 typedef signed char NvS8; // -128 to 127 |
| 157 typedef signed short NvS16; // -32768 to 32767 |
| 158 typedef signed int NvS32; // -2147483648 to 2147483647 |
| 159 typedef signed long long NvS64; // 2^-63 to 2^63-1 |
| 160 |
| 161 // Explicitly sized floats |
| 162 typedef float NvF32; // IEEE Single Precision (S1E8M23) |
| 163 typedef double NvF64; // IEEE Double Precision (S1E11M52) |
| 164 |
| 165 // Min/Max values for NvF32 |
| 166 #define NV_MIN_F32 (1.1754944e-38f) |
| 167 #define NV_MAX_F32 (3.4028234e+38f) |
| 168 |
| 169 // Boolean type |
| 170 enum { NV_FALSE = 0, NV_TRUE = 1 }; |
| 171 typedef NvU8 NvBool; |
| 172 |
| 173 // Pointer-sized signed and unsigned ints |
| 174 #if NVCPU_IS_64_BITS |
| 175 typedef NvU64 NvUPtr; |
| 176 typedef NvS64 NvSPtr; |
| 177 #else |
| 178 typedef NvU32 NvUPtr; |
| 179 typedef NvS32 NvSPtr; |
| 180 #endif |
| 181 |
| 182 // Function attributes are lumped in here too |
| 183 // INLINE - Make the function inline |
| 184 // NAKED - Create a function without a prologue or an epilogue. |
| 185 #if NVOS_IS_WINDOWS |
| 186 |
| 187 #define NV_INLINE __inline |
| 188 #define NV_FORCE_INLINE __forceinline |
| 189 #define NV_NAKED __declspec(naked) |
| 190 |
| 191 #elif defined(__GNUC__) |
| 192 |
| 193 #define NV_INLINE __inline__ |
| 194 #define NV_FORCE_INLINE __attribute__((always_inline)) __inline__ |
| 195 #define NV_NAKED __attribute__((naked)) |
| 196 |
| 197 #elif defined(__arm) // ARM RVDS compiler |
| 198 |
| 199 #define NV_INLINE __inline |
| 200 #define NV_FORCE_INLINE __forceinline |
| 201 #define NV_NAKED __asm |
| 202 |
| 203 #else |
| 204 #error Unknown compiler |
| 205 #endif |
| 206 |
| 207 // Symbol attributes. |
| 208 // ALIGN - Variable declaration to a particular # of bytes (should always be a |
| 209 // power of two) |
| 210 // WEAK - Define the symbol weakly so it can be overridden by the user. |
| 211 #if NVOS_IS_WINDOWS |
| 212 #define NV_ALIGN(size) __declspec(align(size)) |
| 213 #define NV_WEAK |
| 214 #elif defined(__GNUC__) |
| 215 #define NV_ALIGN(size) __attribute__ ((aligned (size))) |
| 216 #define NV_WEAK __attribute__((weak)) |
| 217 #elif defined(__arm) |
| 218 #define NV_ALIGN(size) __align(size) |
| 219 #define NV_WEAK __weak |
| 220 #else |
| 221 #error Unknown compiler |
| 222 #endif |
| 223 |
| 224 /** |
| 225 * This macro wraps its argument with the equivalent of "#if NV_DEBUG", but |
| 226 * also can be used where "#ifdef"'s can't, like inside a macro. |
| 227 */ |
| 228 #if NV_DEBUG |
| 229 #define NV_DEBUG_CODE(x) x |
| 230 #else |
| 231 #define NV_DEBUG_CODE(x) |
| 232 #endif |
| 233 |
| 234 /** Macro for determining the size of an array */ |
| 235 #define NV_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 236 |
| 237 /** Macro for taking min or max of a pair of numbers */ |
| 238 #define NV_MIN(a,b) (((a) < (b)) ? (a) : (b)) |
| 239 #define NV_MAX(a,b) (((a) > (b)) ? (a) : (b)) |
| 240 |
| 241 /** |
| 242 * By convention, we use this value to represent an infinite wait interval in |
| 243 * APIs that expect a timeout argument. A value of zero should not be |
| 244 * interpreted as infinite -- it should be interpreted as "time out immediately |
| 245 * and simply check whether the event has already happened." |
| 246 */ |
| 247 #define NV_WAIT_INFINITE 0xFFFFFFFF |
| 248 |
| 249 // Macro to help with MSVC Code Analysis false positives |
| 250 #if defined(_PREFAST_) |
| 251 #define NV_ANALYSIS_ASSUME(x) __analysis_assume(x) |
| 252 #else |
| 253 #define NV_ANALYSIS_ASSUME(x) |
| 254 #endif |
| 255 |
| 256 #if NVOS_IS_LINUX_KERNEL |
| 257 // for do_div divide macro |
| 258 #include <asm/div64.h> |
| 259 #endif |
| 260 |
| 261 /** |
| 262 * Performs the 64-bit division and returns the quotient. |
| 263 * |
| 264 * If the divisor is 0, returns 0. |
| 265 * |
| 266 * It is not gauranteed to have 64-bit divide on all the platforms. So, |
| 267 * portable code should call this function instead of using / % operators on |
| 268 * 64-bit variables. |
| 269 */ |
| 270 static NV_FORCE_INLINE NvU64 |
| 271 NvDiv64Inline(NvU64 dividend, NvU32 divisor) |
| 272 { |
| 273 if (!divisor) return 0; |
| 274 #if NVOS_IS_LINUX_KERNEL |
| 275 /* Linux kernel cannot resolve compiler generated intrinsic for 64-bit divid
e |
| 276 * Use OS defined wrappers instead */ |
| 277 do_div(dividend, divisor); |
| 278 return dividend; |
| 279 #else |
| 280 return dividend / divisor; |
| 281 #endif |
| 282 } |
| 283 |
| 284 #define NvDiv64(dividend, divisor) NvDiv64Inline(dividend, divisor) |
| 285 |
| 286 /** |
| 287 * Union that can be used to view a 32-bit word as your choice of a 32-bit |
| 288 * unsigned integer, a 32-bit signed integer, or an IEEE single-precision |
| 289 * float. Here is an example of how you might use it to extract the (integer) |
| 290 * bitwise representation of a floating-point number: |
| 291 * NvData32 data; |
| 292 * data.f = 1.0f; |
| 293 * printf("%x", data.u); |
| 294 */ |
| 295 typedef union NvData32Rec |
| 296 { |
| 297 NvU32 u; |
| 298 NvS32 i; |
| 299 NvF32 f; |
| 300 } NvData32; |
| 301 |
| 302 /** |
| 303 * This structure is used to determine a location on a 2-dimensional object, |
| 304 * where the coordinate (0,0) is located at the top-left of the object. The |
| 305 * values of x and y are in pixels. |
| 306 */ |
| 307 typedef struct NvPointRec |
| 308 { |
| 309 /** horizontal location of the point */ |
| 310 NvS32 x; |
| 311 |
| 312 /** vertical location of the point */ |
| 313 NvS32 y; |
| 314 } NvPoint; |
| 315 |
| 316 /** |
| 317 * This structure is used to define a 2-dimensional rectangle where the |
| 318 * rectangle is bottom right exclusive (that is, the right most column, and the |
| 319 * bottom row of the rectangle is not included). |
| 320 */ |
| 321 typedef struct NvRectRec |
| 322 { |
| 323 /** left column of a rectangle */ |
| 324 NvS32 left; |
| 325 |
| 326 /** top row of a rectangle*/ |
| 327 NvS32 top; |
| 328 |
| 329 /** right column of a rectangle */ |
| 330 NvS32 right; |
| 331 |
| 332 /** bottom row of a rectangle */ |
| 333 NvS32 bottom; |
| 334 } NvRect; |
| 335 |
| 336 /** |
| 337 * This structure is used to define a 2-dimensional rectangle |
| 338 * relative to some containing rectangle. |
| 339 * Rectangle coordinates are normalized to [-1.0...+1.0] range |
| 340 */ |
| 341 typedef struct NvRectF32Rec |
| 342 { |
| 343 NvF32 left; |
| 344 NvF32 top; |
| 345 NvF32 right; |
| 346 NvF32 bottom; |
| 347 } NvRectF32; |
| 348 |
| 349 /** |
| 350 * This structure is used to define a 2-dimensional surface where the surface is |
| 351 * determined by it's height and width in pixels. |
| 352 */ |
| 353 typedef struct NvSizeRec |
| 354 { |
| 355 /* width of the surface in pixels */ |
| 356 NvS32 width; |
| 357 |
| 358 /* height of the surface in pixels */ |
| 359 NvS32 height; |
| 360 } NvSize; |
| 361 |
| 362 /** @} */ |
| 363 |
| 364 #if defined(__cplusplus) |
| 365 } |
| 366 #endif |
| 367 |
| 368 #endif // INCLUDED_NVCOMMON_H |
OLD | NEW |