adapt for devfs
[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
78 #if defined(macosx) || defined(MACOS) || defined(NV_MACINTOSH) || \
79     defined(NV_MACINTOSH_64)
80 typedef char*              NVREGSTR;
81 #else
82 typedef NvU8*              NVREGSTR;
83 #endif
84
85 /* mainly for 64-bit linux, where long is 64 bits
86  * and win9x, where int is 16 bit.
87  */
88 #if (defined(NV_UNIX) || defined(vxworks) || defined(NV_WINDOWS_CE) ||  \
89      defined(__arm) || defined(__IAR_SYSTEMS_ICC__) || defined(NV_QNX) || \
90      defined(NV_INTEGRITY) || defined(NV_MODS) || defined(__GNUC__) ||  \
91      defined(NV_MACINTOSH_64)) && \
92     (!defined(NV_MACINTOSH) || defined(NV_MACINTOSH_64))
93 typedef unsigned int       NvV32; /* "void": enumerated or multiple fields   */
94 typedef unsigned int       NvU32; /* 0 to 4294967295                         */
95 #else
96 typedef unsigned long      NvV32; /* "void": enumerated or multiple fields   */
97 typedef unsigned long      NvU32; /* 0 to 4294967295                         */
98 #endif
99
100 // mac os 32-bit still needs this
101 #if defined(NV_MACINTOSH) && !defined(NV_MACINTOSH_64)
102 typedef signed long        NvS32; /* -2147483648 to 2147483647               */
103 #else
104 typedef signed int         NvS32; /* -2147483648 to 2147483647               */
105 #endif
106
107 /* 64-bit types for compilers that support them, plus some obsolete variants */
108 #if defined(__GNUC__) || defined(__arm) || defined(__IAR_SYSTEMS_ICC__) || defined(__ghs__) || defined(_WIN64) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
109 typedef unsigned long long NvU64; /* 0 to 18446744073709551615          */
110 typedef          long long NvS64; /* 2^-63 to 2^63-1                    */
111 #else
112 typedef unsigned __int64   NvU64; /* 0 to 18446744073709551615              */
113 typedef          __int64   NvS64; /* 2^-63 to 2^63-1                        */
114 #endif
115
116 /* Boolean type */
117 enum { NV_FALSE = 0, NV_TRUE = 1 };
118 typedef NvU8 NvBool;
119
120 /* Macros to extract the low and high parts of a 64-bit unsigned integer */
121 /* Also designed to work if someone happens to pass in a 32-bit integer */
122 #define NvU64_HI32(n)     ((NvU32)((((NvU64)(n)) >> 32) & 0xffffffff))
123 #define NvU64_LO32(n)     ((NvU32)(( (NvU64)(n))        & 0xffffffff))
124 #define NvU40_HI32(n)     ((NvU32)((((NvU64)(n)) >>  8) & 0xffffffff))
125 #define NvU40_HI24of32(n) ((NvU32)(  (NvU64)(n)         & 0xffffff00))
126
127  /***************************************************************************\
128 |*                                                                           *|
129 |*  64 bit type definitions for use in interface structures.                 *|
130 |*                                                                           *|
131  \***************************************************************************/
132
133 #if defined(NV_64_BITS)
134
135 typedef void*              NvP64; /* 64 bit void pointer                     */
136 typedef NvU64             NvUPtr; /* pointer sized unsigned int              */
137 typedef NvS64             NvSPtr; /* pointer sized signed int                */
138 typedef NvU64           NvLength; /* length to agree with sizeof             */
139
140 #define NvP64_VALUE(n)    (n)
141
142 #else
143
144 typedef NvU64              NvP64; /* 64 bit void pointer                     */
145 typedef NvU32             NvUPtr; /* pointer sized unsigned int              */
146 typedef NvS32             NvSPtr; /* pointer sized signed int                */
147 typedef NvU32           NvLength; /* length to agree with sizeof             */
148
149 #define NvP64_VALUE(n)    ((void *)(NvUPtr)(n))
150
151 #endif
152
153 // XXX Obsolete -- get rid of me...
154 typedef NvP64 NvP64_VALUE_T;
155 typedef NvUPtr NV_UINTPTR_T;
156 #define NvP64_LVALUE(n)   (n)
157 #define NvP64_SELECTOR(n) (0)
158
159 /* Useful macro to hide required double cast */
160 #define NV_PTR_TO_NvP64(n) (NvP64)(NV_UINTPTR_T)(n)
161
162 /* obsolete stuff  */
163 /* MODS needs to be able to build without these definitions because they collide
164    with some definitions used in mdiag. */
165 #ifndef DONT_DEFINE_U032
166 typedef NvV8  V008;
167 typedef NvV16 V016;
168 typedef NvV32 V032;
169 typedef NvU8  U008;
170 typedef NvU16 U016;
171 typedef NvU32 U032;
172 typedef NvS8  S008;
173 typedef NvS16 S016;
174 typedef NvS32 S032;
175 #endif
176 #if defined(MACOS) || defined(macintosh) || defined(__APPLE_CC__) || defined(NV_MODS) || defined(MINIRM) || defined(NV_UNIX) || defined (NV_QNX)
177 /* more obsolete stuff */
178 /* need to provide these on macos9 and macosX */
179 #if defined(__APPLE_CC__)  /* gross but Apple osX already claims ULONG */
180 #undef ULONG    // just in case
181 #define ULONG unsigned long
182 #else
183 typedef unsigned long  ULONG;
184 #endif
185 typedef unsigned char *PUCHAR;
186 #endif
187
188 #if !defined(NV_PTR)
189     /* Supports 32bit libraries on Win64
190        See drivers\opengl\include\nvFirst.h for explanation */
191 #define NV_PTR
192 #define CAST_NV_PTR(p)     p
193 #endif
194
195 /* Aligns fields in structs  so they match up between 32 and 64 bit builds */
196 #if defined(__GNUC__) || defined(NV_QNX)
197 #define NV_ALIGN_BYTES(size) __attribute__ ((aligned (size)))
198 #elif defined(__arm)
199 #define NV_ALIGN_BYTES(size) __align(ALIGN)
200 #else
201 // XXX This is dangerously nonportable!  We really shouldn't provide a default
202 // version of this that doesn't do anything.
203 #define NV_ALIGN_BYTES(size)
204 #endif
205
206 // NV_DECLARE_ALIGNED() can be used on all platforms.
207 // This macro form accounts for the fact that __declspec on Windows is required
208 // before the variable type,
209 // and NV_ALIGN_BYTES is required after the variable name.
210 #if defined(NV_WINDOWS)
211 #define NV_DECLARE_ALIGNED(TYPE_VAR, ALIGN) __declspec(align(ALIGN)) TYPE_VAR
212 #elif defined(__GNUC__) || defined(NV_QNX)
213 #define NV_DECLARE_ALIGNED(TYPE_VAR, ALIGN) TYPE_VAR __attribute__ ((aligned (ALIGN)))
214 #elif defined(__arm)
215 #define NV_DECLARE_ALIGNED(TYPE_VAR, ALIGN) __align(ALIGN) TYPE_VAR
216 #endif
217
218
219  /***************************************************************************\
220 |*                       Function Declaration Types                          *|
221  \***************************************************************************/
222
223 // stretching the meaning of "nvtypes", but this seems to least offensive
224 // place to re-locate these from nvos.h which cannot be included by a number
225 // of builds that need them
226
227 #if defined(NV_WINDOWS)
228
229     #define NV_INLINE __inline
230
231     #if _MSC_VER >= 1200
232     #define NV_FORCEINLINE __forceinline
233     #else
234     #define NV_FORCEINLINE __inline
235     #endif
236
237     #define NV_APIENTRY  __stdcall
238     #define NV_FASTCALL  __fastcall
239     #define NV_CDECLCALL __cdecl
240     #define NV_STDCALL   __stdcall
241
242     #define NV_FORCERESULTCHECK
243
244 #else // defined(NV_WINDOWS)
245
246     #if defined(__GNUC__) || defined(__INTEL_COMPILER)
247     #define NV_INLINE __inline__
248     #elif defined (macintosh) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
249     #define NV_INLINE inline
250     #elif defined(__arm)
251     #define NV_INLINE __inline
252     #else
253     #define NV_INLINE
254     #endif
255
256     #if defined(__GNUC__)
257         // GCC 3.1 and beyond support the always_inline function attribute.
258         #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
259         #define NV_FORCEINLINE __attribute__((always_inline)) __inline__
260         #else
261         #define NV_FORCEINLINE __inline__
262         #endif
263     #elif defined(__arm) && (__ARMCC_VERSION >= 220000)
264         // RVDS 2.2 also supports forceinline, but ADS 1.2 does not
265         #define NV_FORCEINLINE __forceinline
266     #else /* defined(__GNUC__) */
267         #define NV_FORCEINLINE NV_INLINE
268     #endif
269
270     #define NV_APIENTRY
271     #define NV_FASTCALL
272     #define NV_CDECLCALL
273     #define NV_STDCALL
274
275     /*
276      * The 'warn_unused_result' function attribute prompts GCC to issue a
277      * warning if the result of a function tagged with this attribute
278      * is ignored by a caller.  In combination with '-Werror', it can be
279      * used to enforce result checking in RM code; at this point, this
280      * is only done on UNIX.
281      */
282     #if defined(__GNUC__) && defined(NV_UNIX)
283         #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
284         #define NV_FORCERESULTCHECK __attribute__((warn_unused_result))
285         #else
286         #define NV_FORCERESULTCHECK
287         #endif
288     #else /* defined(__GNUC__) */
289         #define NV_FORCERESULTCHECK
290     #endif
291
292 #endif  // defined(NV_WINDOWS)
293
294 #ifdef __cplusplus
295 };
296 #endif
297
298 #endif /* NVTYPES_INCLUDED */