Import from upstream.
[nvidia.git] / src / nvtypes.h
1  /***************************************************************************\
2 |*                                                                           *|
3 |*       Copyright 1993-1998 NVIDIA, Corporation.  All rights reserved.      *|
4 |*                                                                           *|
5 |*     NOTICE TO USER:   The source code  is copyrighted under  U.S. and     *|
6 |*     international laws.  Users and possessors of this source code are     *|
7 |*     hereby granted a nonexclusive,  royalty-free copyright license to     *|
8 |*     use this code in individual and commercial software.                  *|
9 |*                                                                           *|
10 |*     Any use of this source code must include,  in the user documenta-     *|
11 |*     tion and  internal comments to the code,  notices to the end user     *|
12 |*     as follows:                                                           *|
13 |*                                                                           *|
14 |*       Copyright 1993-1998 NVIDIA, Corporation.  All rights reserved.      *|
15 |*                                                                           *|
16 |*     NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY     *|
17 |*     OF  THIS SOURCE  CODE  FOR ANY PURPOSE.  IT IS  PROVIDED  "AS IS"     *|
18 |*     WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA, CORPOR-     *|
19 |*     ATION DISCLAIMS ALL WARRANTIES  WITH REGARD  TO THIS SOURCE CODE,     *|
20 |*     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE-     *|
21 |*     MENT,  AND FITNESS  FOR A PARTICULAR PURPOSE.   IN NO EVENT SHALL     *|
22 |*     NVIDIA, CORPORATION  BE LIABLE FOR ANY SPECIAL,  INDIRECT,  INCI-     *|
23 |*     DENTAL, OR CONSEQUENTIAL DAMAGES,  OR ANY DAMAGES  WHATSOEVER RE-     *|
24 |*     SULTING FROM LOSS OF USE,  DATA OR PROFITS,  WHETHER IN AN ACTION     *|
25 |*     OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  ARISING OUT OF     *|
26 |*     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE.     *|
27 |*                                                                           *|
28 |*     U.S. Government  End  Users.   This source code  is a "commercial     *|
29 |*     item,"  as that  term is  defined at  48 C.F.R. 2.101 (OCT 1995),     *|
30 |*     consisting  of "commercial  computer  software"  and  "commercial     *|
31 |*     computer  software  documentation,"  as such  terms  are  used in     *|
32 |*     48 C.F.R. 12.212 (SEPT 1995)  and is provided to the U.S. Govern-     *|
33 |*     ment only as  a commercial end item.   Consistent with  48 C.F.R.     *|
34 |*     12.212 and  48 C.F.R. 227.7202-1 through  227.7202-4 (JUNE 1995),     *|
35 |*     all U.S. Government End Users  acquire the source code  with only     *|
36 |*     those rights set forth herein.                                        *|
37 |*                                                                           *|
38  \***************************************************************************/
39
40
41  /***************************************************************************\
42 |*                                                                           *|
43 |*                         NV Architecture Interface                         *|
44 |*                                                                           *|
45 |*  <nvtypes.h> defines common widths used to access hardware in of NVIDIA's *|
46 |*  Unified Media Architecture (TM).                                         *|
47 |*                                                                           *|
48  \***************************************************************************/
49
50
51 #ifndef NVTYPES_INCLUDED
52 #define NVTYPES_INCLUDED
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 #include "cpuopsys.h"
58
59 #define NVRM_64 1
60 #if defined(NV_64_BITS)
61 #define NVRM_TRUE64 1
62 #endif
63
64  /***************************************************************************\
65 |*                                 Typedefs                                  *|
66  \***************************************************************************/
67
68 typedef unsigned char      NvV8;  /* "void": enumerated or multiple fields   */
69 typedef unsigned short     NvV16; /* "void": enumerated or multiple fields   */
70 typedef unsigned char      NvU8;  /* 0 to 255                                */
71 typedef unsigned short     NvU16; /* 0 to 65535                              */
72 typedef signed char        NvS8;  /* -128 to 127                             */
73 typedef signed short       NvS16; /* -32768 to 32767                         */
74 typedef float              NvF32; /* IEEE Single Precision (S1E8M23)         */
75 typedef double             NvF64; /* IEEE Double Precision (S1E11M52)        */
76
77 /* mainly for 64-bit linux, where long is 64 bits
78  * and win9x, where int is 16 bit.
79  */
80 #if (defined(NV_UNIX) || defined(vxworks) || defined(NV_WINDOWS_CE) ||  \
81      defined(__arm) || defined(__IAR_SYSTEMS_ICC__) || defined(NV_QNX) || \
82      defined(NV_INTEGRITY) || defined(NV_MODS) || defined(__GNUC__) ||  \
83      defined(NV_MACINTOSH_64)) && \
84     (!defined(NV_MACINTOSH) || defined(NV_MACINTOSH_64))
85 typedef unsigned int       NvV32; /* "void": enumerated or multiple fields   */
86 typedef unsigned int       NvU32; /* 0 to 4294967295                         */
87 #else
88 typedef unsigned long      NvV32; /* "void": enumerated or multiple fields   */
89 typedef unsigned long      NvU32; /* 0 to 4294967295                         */
90 #endif
91
92 // mac os 32-bit still needs this
93 #if defined(NV_MACINTOSH) && !defined(NV_MACINTOSH_64)
94 typedef signed long        NvS32; /* -2147483648 to 2147483647               */
95 #else
96 typedef signed int         NvS32; /* -2147483648 to 2147483647               */
97 #endif
98
99 /* 64-bit types for compilers that support them, plus some obsolete variants */
100 #if defined(__GNUC__) || defined(__arm) || defined(__IAR_SYSTEMS_ICC__) || defined(__ghs__) || defined(_WIN64)
101 typedef unsigned long long NvU64; /* 0 to 18446744073709551615          */
102 typedef          long long NvS64; /* 2^-63 to 2^63-1                    */
103 #else
104 typedef unsigned __int64   NvU64; /* 0 to 18446744073709551615              */
105 typedef          __int64   NvS64; /* 2^-63 to 2^63-1                        */
106 #endif
107
108 /* Boolean type */
109 enum { NV_FALSE = 0, NV_TRUE = 1 };
110 typedef NvU8 NvBool;
111
112 /* Macros to extract the low and high parts of a 64-bit unsigned integer */
113 /* Also designed to work if someone happens to pass in a 32-bit integer */
114 #define NvU64_HI32(n) ((NvU32)(((NvU64)(n)) >> 32))
115 #define NvU64_LO32(n) ((NvU32)((NvU64)(n)))
116 #define NvU40_HI32(n) ((NvU32)((((NvU64)(n))>>8)&0xffffffff))
117 #define NvU40_HI24of32(n) ((NvU32)((((NvU64)(n)& 0xffffffff))&0xffffff00))
118
119  /***************************************************************************\
120 |*                                                                           *|
121 |*  64 bit type definitions for use in interface structures.                 *|
122 |*                                                                           *|
123  \***************************************************************************/
124
125 #if defined(NV_64_BITS)
126
127 typedef void*              NvP64; /* 64 bit void pointer                     */
128 typedef NvU64             NvUPtr; /* pointer sized unsigned int              */
129
130 #define NvP64_VALUE(n)    (n)
131
132 #else
133
134 typedef NvU64              NvP64; /* 64 bit void pointer                     */
135 typedef NvU32             NvUPtr; /* pointer sized unsigned int              */
136
137 #define NvP64_VALUE(n)    ((void *)(NvUPtr)(n))
138
139 #endif
140
141 // XXX Obsolete -- get rid of me...
142 typedef NvP64 NvP64_VALUE_T;
143 typedef NvUPtr NV_UINTPTR_T;
144 #define NvP64_LVALUE(n)   (n)
145 #define NvP64_SELECTOR(n) (0)
146
147 /* Useful macro to hide required double cast */
148 #define NV_PTR_TO_NvP64(n) (NvP64)(NV_UINTPTR_T)(n)
149
150 /* obsolete stuff  */
151 /* MODS needs to be able to build without these definitions because they collide
152    with some definitions used in mdiag. */
153 #ifndef DONT_DEFINE_U032
154 typedef NvV8  V008;
155 typedef NvV16 V016;
156 typedef NvV32 V032;
157 typedef NvU8  U008;
158 typedef NvU16 U016;
159 typedef NvU32 U032;
160 typedef NvS8  S008;
161 typedef NvS16 S016;
162 typedef NvS32 S032;
163 #endif
164 #if defined(MACOS) || defined(macintosh) || defined(__APPLE_CC__) || defined(NV_MODS) || defined(MINIRM) || defined(NV_UNIX) || defined (NV_QNX)
165 /* more obsolete stuff */
166 /* need to provide these on macos9 and macosX */
167 #if defined(__APPLE_CC__)  /* gross but Apple osX already claims ULONG */
168 #undef ULONG    // just in case
169 #define ULONG unsigned long
170 #else
171 typedef unsigned long  ULONG;
172 #endif
173 typedef unsigned char *PUCHAR;
174 #endif
175
176 #if !defined(NV_PTR)
177     /* Supports 32bit libraries on Win64
178        See drivers\opengl\include\nvFirst.h for explanation */
179 #define NV_PTR
180 #define CAST_NV_PTR(p)     p
181 #endif
182
183 /* Aligns fields in structs  so they match up between 32 and 64 bit builds */
184 /* XXX Mac still uses structures without alignment -- needs to be fixed */
185 #if (defined(__GNUC__) || defined(NV_QNX)) && !defined(NV_MACINTOSH)
186 #define NV_ALIGN_BYTES(size) __attribute__ ((aligned (size)))
187 #elif defined(__arm)
188 #define NV_ALIGN_BYTES(size) __align(ALIGN)
189 #else
190 // XXX This is dangerously nonportable!  We really shouldn't provide a default
191 // version of this that doesn't do anything.
192 #define NV_ALIGN_BYTES(size)
193 #endif
194
195 // NV_DECLARE_ALIGNED() can be used on all platforms.
196 // This macro form accounts for the fact that __declspec on Windows is required
197 // before the variable type,
198 // and NV_ALIGN_BYTES is required after the variable name.
199 #if defined(NV_WINDOWS)
200 #define NV_DECLARE_ALIGNED(TYPE_VAR, ALIGN) __declspec(align(ALIGN)) TYPE_VAR
201 #elif defined(__GNUC__) || defined(NV_QNX)
202 #define NV_DECLARE_ALIGNED(TYPE_VAR, ALIGN) TYPE_VAR __attribute__ ((aligned (ALIGN)))
203 #elif defined(__arm)
204 #define NV_DECLARE_ALIGNED(TYPE_VAR, ALIGN) __align(ALIGN) TYPE_VAR
205 #endif
206
207
208 /***************************************************************************\
209 |*                      Function Declaration Types                          *|
210  \***************************************************************************/
211
212 // stretching the meaning of "nvtypes", but this seems to least offensive
213 // place to re-locate these from nvos.h which cannot be included by a number
214 // of builds that need them
215
216 #if defined(NV_WINDOWS)
217
218     #define NV_INLINE __inline
219
220     #if _MSC_VER >= 1200
221     #define NV_FORCEINLINE __forceinline
222     #else
223     #define NV_FORCEINLINE __inline
224     #endif
225
226     #define NV_APIENTRY  __stdcall
227     #define NV_FASTCALL  __fastcall
228     #define NV_CDECLCALL __cdecl
229     #define NV_STDCALL   __stdcall
230
231     #define NV_FORCERESULTCHECK
232
233 #else // defined(NV_WINDOWS)
234
235     #if defined(__GNUC__) || defined(__INTEL_COMPILER)
236     #define NV_INLINE __inline__
237     #elif defined (macintosh)
238     #define NV_INLINE inline
239     #elif defined(__arm)
240     #define NV_INLINE __inline
241     #else
242     #define NV_INLINE
243     #endif
244
245     #if defined(__GNUC__)
246         // GCC 3.1 and beyond support the always_inline function attribute.
247         #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
248         #define NV_FORCEINLINE __attribute__((always_inline)) __inline__
249         #else
250         #define NV_FORCEINLINE __inline__
251         #endif
252     #elif defined(__arm) && (__ARMCC_VERSION >= 220000)
253         // RVDS 2.2 also supports forceinline, but ADS 1.2 does not
254         #define NV_FORCEINLINE __forceinline
255     #else /* defined(__GNUC__) */
256         #define NV_FORCEINLINE NV_INLINE
257     #endif
258
259     #define NV_APIENTRY
260     #define NV_FASTCALL
261     #define NV_CDECLCALL
262     #define NV_STDCALL
263
264     /*
265      * The 'warn_unused_result' function attribute prompts GCC to issue a
266      * warning if the result of a function tagged with this attribute
267      * is ignored by a caller.  In combination with '-Werror', it can be
268      * used to enforce result checking in RM code; at this point, this
269      * is only done on UNIX.
270      */
271     #if defined(__GNUC__) && defined(NV_UNIX)
272         #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
273         #define NV_FORCERESULTCHECK __attribute__((warn_unused_result))
274         #else
275         #define NV_FORCERESULTCHECK
276         #endif
277     #else /* defined(__GNUC__) */
278         #define NV_FORCERESULTCHECK
279     #endif
280
281 #endif  // defined(NV_WINDOWS)
282
283 #ifdef __cplusplus
284 };
285 #endif
286
287 #endif /* NVTYPES_INCLUDED */