summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/include/nvcommon.h
blob: 8c476f985671e35e6f40484346c140fafe51ce9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/*
 * Copyright (c) 2006-2009 NVIDIA Corporation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the NVIDIA Corporation nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
#define NV_DEBUG 0

#ifndef INCLUDED_NVCOMMON_H
#define INCLUDED_NVCOMMON_H

// Include headers that provide NULL, size_t, offsetof, and [u]intptr_t.  In
// the event that the toolchain doesn't provide these, provide them ourselves.
#include <stddef.h>
#if defined(_WIN32_WCE)
typedef int          intptr_t;
typedef unsigned int uintptr_t;
#elif (defined(__linux__) && !defined(__KERNEL__)) || defined(__arm)
#include <stdint.h>
#endif

#if defined(__cplusplus)
extern "C"
{
#endif

/** 
 * @defgroup nvcommon Common Declarations
 * 
 * nvcommon.h contains standard definitions used by various interfaces
 * 
 * @{
 */


/**
 * If an OS DEFINE is not set, it should be set to 0
 */
#ifndef NV_OS_CE_500
#define NV_OS_CE_500 0
#endif
#ifndef NV_OS_CE_600
#define NV_OS_CE_600 0
#endif
#ifndef NV_OS_WM_600
#define NV_OS_WM_600 0
#endif
#ifndef NV_OS_700
#define NV_OS_700 0
#endif


// OS-related #define's
#if defined(_WIN32)
  #define NVOS_IS_WINDOWS 1
  #if defined(_WIN32_WCE)
    #define NVOS_IS_WINDOWS_CE 1
  #endif
#elif defined(__linux__)
  #define NVOS_IS_LINUX 1
  #define NVOS_IS_UNIX 1
  #if defined(__KERNEL__)
    #define NVOS_IS_LINUX_KERNEL 1
  #endif
#elif defined(__arm__)  && defined(__ARM_EABI__)
    /* GCC arm eabi compiler, potentially used for kernel compilation without
     * __linux__, but also for straight EABI (AOS) executable builds */
#  if defined(__KERNEL__)
#    define NVOS_IS_LINUX 1
#    define NVOS_IS_UNIX 1
#    define NVOS_IS_LINUX_KERNEL 1
#  endif
    /* Nothing to define for AOS */
#elif defined(__arm) 
  // For ARM RVDS compiler, we don't know the final target OS at compile time
#else
  #error Unknown OS
#endif

#if !defined(NVOS_IS_WINDOWS)
#define NVOS_IS_WINDOWS 0
#endif
#if !defined(NVOS_IS_WINDOWS_CE)
#define NVOS_IS_WINDOWS_CE 0
#endif
#if !defined(NVOS_IS_LINUX)
#define NVOS_IS_LINUX 0
#endif
#if !defined(NVOS_IS_UNIX)
#define NVOS_IS_UNIX 0
#endif
#if !defined(NVOS_IS_LINUX_KERNEL) 
#define NVOS_IS_LINUX_KERNEL 0
#endif

// CPU-related #define's 
#if defined(_M_IX86) || defined(__i386__)
#define NVCPU_IS_X86 1 // any IA32 machine (not AMD64)
#define NVCPU_MIN_PAGE_SHIFT 12
#elif defined(_M_ARM) || defined(__arm__)
#define NVCPU_IS_ARM 1
#define NVCPU_MIN_PAGE_SHIFT 12
#else
#error Unknown CPU
#endif
#if !defined(NVCPU_IS_X86)
#define NVCPU_IS_X86 0
#endif
#if !defined(NVCPU_IS_ARM)
#define NVCPU_IS_ARM 0
#endif

#if (NVCPU_IS_X86 && NVOS_IS_WINDOWS)
#define NVOS_IS_WINDOWS_X86 1
#else
#define NVOS_IS_WINDOWS_X86 0
#endif

// The minimum page size can be determined from the minimum page shift
#define NVCPU_MIN_PAGE_SIZE (1 << NVCPU_MIN_PAGE_SHIFT)

// We don't currently support any big-endian CPUs
#define NVCPU_IS_BIG_ENDIAN 0

// We don't currently support any 64-bit CPUs
#define NVCPU_IS_64_BITS 0

// Explicitly sized signed and unsigned ints
typedef unsigned char      NvU8;  // 0 to 255
typedef unsigned short     NvU16; // 0 to 65535
typedef unsigned int       NvU32; // 0 to 4294967295
typedef unsigned long long NvU64; // 0 to 18446744073709551615
typedef signed char        NvS8;  // -128 to 127
typedef signed short       NvS16; // -32768 to 32767
typedef signed int         NvS32; // -2147483648 to 2147483647
typedef signed long long   NvS64; // 2^-63 to 2^63-1

// Explicitly sized floats
typedef float              NvF32; // IEEE Single Precision (S1E8M23)
typedef double             NvF64; // IEEE Double Precision (S1E11M52)

// Min/Max values for NvF32
#define NV_MIN_F32  (1.1754944e-38f)
#define NV_MAX_F32  (3.4028234e+38f)

// Boolean type
enum { NV_FALSE = 0, NV_TRUE = 1 };
typedef NvU8 NvBool;

// Pointer-sized signed and unsigned ints
#if NVCPU_IS_64_BITS
typedef NvU64 NvUPtr;
typedef NvS64 NvSPtr;
#else
typedef NvU32 NvUPtr;
typedef NvS32 NvSPtr;
#endif

// Function attributes are lumped in here too
// INLINE - Make the function inline
// NAKED - Create a function without a prologue or an epilogue.
#if NVOS_IS_WINDOWS

#define NV_INLINE __inline
#define NV_FORCE_INLINE __forceinline
#define NV_NAKED __declspec(naked)

#elif defined(__GNUC__)

#define NV_INLINE __inline__
#define NV_FORCE_INLINE __attribute__((always_inline)) __inline__
#define NV_NAKED __attribute__((naked))

#elif defined(__arm) // ARM RVDS compiler

#define NV_INLINE __inline
#define NV_FORCE_INLINE __forceinline
#define NV_NAKED __asm

#else
#error Unknown compiler
#endif

// Symbol attributes.
// ALIGN - Variable declaration to a particular # of bytes (should always be a
//         power of two)
// WEAK  - Define the symbol weakly so it can be overridden by the user.
#if NVOS_IS_WINDOWS
#define NV_ALIGN(size) __declspec(align(size))
#define NV_WEAK  
#elif defined(__GNUC__)
#define NV_ALIGN(size) __attribute__ ((aligned (size)))
#define NV_WEAK __attribute__((weak))    
#elif defined(__arm)
#define NV_ALIGN(size) __align(size)
#define NV_WEAK __weak    
#else
#error Unknown compiler
#endif

/**
 * This macro wraps its argument with the equivalent of "#if NV_DEBUG", but
 * also can be used where "#ifdef"'s can't, like inside a macro.
 */
#if NV_DEBUG
#define NV_DEBUG_CODE(x) x
#else
#define NV_DEBUG_CODE(x)
#endif

/** Macro for determining the size of an array */
#define NV_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

/** Macro for taking min or max of a pair of numbers */
#define NV_MIN(a,b) (((a) < (b)) ? (a) : (b))
#define NV_MAX(a,b) (((a) > (b)) ? (a) : (b))

/**
 * By convention, we use this value to represent an infinite wait interval in
 * APIs that expect a timeout argument.  A value of zero should not be
 * interpreted as infinite -- it should be interpreted as "time out immediately
 * and simply check whether the event has already happened."
 */
#define NV_WAIT_INFINITE 0xFFFFFFFF

// Macro to help with MSVC Code Analysis false positives
#if defined(_PREFAST_)
#define NV_ANALYSIS_ASSUME(x) __analysis_assume(x)
#else
#define NV_ANALYSIS_ASSUME(x)
#endif

#if NVOS_IS_LINUX_KERNEL
// for do_div divide macro
#include <asm/div64.h>
#endif

/**
 * Performs the 64-bit division and returns the quotient.
 *
 * If the divisor is 0, returns 0.
 *
 * It is not gauranteed to have 64-bit divide on all the platforms. So, 
 * portable code should call this function instead of using / % operators on 
 * 64-bit variables.
 */
static NV_FORCE_INLINE  NvU64
NvDiv64Inline(NvU64 dividend, NvU32 divisor) 
{
    if (!divisor) return 0;
#if NVOS_IS_LINUX_KERNEL
    /* Linux kernel cannot resolve compiler generated intrinsic for 64-bit divide
     * Use OS defined wrappers instead */
    do_div(dividend, divisor);
    return dividend;
#else
    return dividend / divisor;
#endif
}

#define NvDiv64(dividend, divisor) NvDiv64Inline(dividend, divisor)

/**
 * Union that can be used to view a 32-bit word as your choice of a 32-bit
 * unsigned integer, a 32-bit signed integer, or an IEEE single-precision
 * float.  Here is an example of how you might use it to extract the (integer)
 * bitwise representation of a floating-point number:
 *   NvData32 data;
 *   data.f = 1.0f;
 *   printf("%x", data.u);
 */
typedef union NvData32Rec
{
    NvU32 u;
    NvS32 i;
    NvF32 f;
} NvData32;

/**
 * This structure is used to determine a location on a 2-dimensional object,
 * where the coordinate (0,0) is located at the top-left of the object.  The
 * values of x and y are in pixels.
 */
typedef struct NvPointRec
{
    /** horizontal location of the point */
    NvS32 x;

    /** vertical location of the point */
    NvS32 y;
} NvPoint;

/**
 * This structure is used to define a 2-dimensional rectangle where the
 * rectangle is bottom right exclusive (that is, the right most column, and the
 * bottom row of the rectangle is not included).
 */
typedef struct NvRectRec
{
    /** left column of a rectangle */
    NvS32 left;

    /** top row of a rectangle*/
    NvS32 top;

    /** right column of a rectangle */
    NvS32 right;

    /** bottom row of a rectangle */
    NvS32 bottom;        
} NvRect;

/**
 * This structure is used to define a 2-dimensional rectangle
 * relative to some containing rectangle.
 * Rectangle coordinates are normalized to [-1.0...+1.0] range
 */
typedef struct NvRectF32Rec
{
    NvF32 left;
    NvF32 top;
    NvF32 right;
    NvF32 bottom;        
} NvRectF32;

/**
 * This structure is used to define a 2-dimensional surface where the surface is
 * determined by it's height and width in pixels.
 */
typedef struct NvSizeRec
{
    /* width of the surface in pixels */
    NvS32 width;

    /* height of the surface in pixels */
    NvS32 height;
} NvSize;

/** @} */

#if defined(__cplusplus)
}
#endif

#endif // INCLUDED_NVCOMMON_H