1143439Sobrien/***************************************************************************\
2143439Sobrien|*                                                                           *|
3143439Sobrien|*       Copyright 2001-2004 NVIDIA Corporation.  All Rights Reserved.       *|
4143439Sobrien|*                                                                           *|
5143439Sobrien|*     THE INFORMATION CONTAINED HEREIN  IS PROPRIETARY AND CONFIDENTIAL     *|
6143439Sobrien|*     TO NVIDIA, CORPORATION.   USE,  REPRODUCTION OR DISCLOSURE TO ANY     *|
7143439Sobrien|*     THIRD PARTY IS SUBJECT TO WRITTEN PRE-APPROVAL BY NVIDIA, CORP.       *|
8143439Sobrien|*                                                                           *|
9143439Sobrien|*     THE INFORMATION CONTAINED HEREIN IS PROVIDED  "AS IS" WITHOUT         *|
10143439Sobrien|*     EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING ALL IMPLIED        *|
11143439Sobrien|*     WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A     *|
12143439Sobrien|*     PARTICULAR PURPOSE.                                                   *|
13143439Sobrien|*                                                                           *|
14143439Sobrien\***************************************************************************/
15143439Sobrien
16143439Sobrien
17143439Sobrien/*++
18143439Sobrien
19143439SobrienFile:
20143439Sobrien
21143439Sobrien	basetype.h
22143439Sobrien
23143439Sobrien
24143439SobrienAbstract:
25143439Sobrien
26143439Sobrien	This file contains the base type definitions used by the networking driver.
27143439Sobrien
28143439Sobrien
29143439SobrienRevision History:
30143439Sobrien
31143439Sobrien	SNo.	Date		Author				Description
32143439Sobrien	1.	2/7/2000	AJha				Created
33143439Sobrien
34143439Sobrien*/
35143439Sobrien
36143439Sobrien#ifndef _BASETYPE_H_
37143439Sobrien#define _BASETYPE_H_
38143439Sobrien
39143439Sobrien#ifndef IN
40143439Sobrien#define IN
41143439Sobrien#endif
42143439Sobrien
43143439Sobrien#ifndef OUT
44143439Sobrien#define OUT
45143439Sobrien#endif
46143439Sobrien
47143439Sobrien//
48143439Sobrien// Useful "types"
49143439Sobrien
50143439Sobrien#ifndef NULL
51143439Sobrien#define NULL            0
52143439Sobrien#endif
53143439Sobrien
54143439Sobrien#ifndef TRUE
55143439Sobrien#define TRUE            1
56143439Sobrien#endif
57143439Sobrien
58143439Sobrien#ifndef FALSE
59143439Sobrien#define FALSE           0
60143439Sobrien#endif
61143439Sobrien
62143439Sobrien#if 1
63143439Sobrien//
64143439Sobrien// Don't use as these are going to be deleted soon. Use NV_ instead
65143439Sobrien//
66143439Sobrien#define VOID                void
67143439Sobrientypedef VOID                *PVOID;
68143439Sobrien
69143439Sobrientypedef unsigned char   UCHAR;
70143439Sobrientypedef UCHAR * PUCHAR;
71143439Sobrientypedef unsigned short  USHORT;
72143439Sobrientypedef USHORT * PUSHORT;
73143439Sobrien#ifdef linux
74143439Sobrientypedef unsigned int ULONG;
75143439Sobrien#else
76143439Sobrientypedef unsigned long ULONG;
77143439Sobrien#endif
78143439Sobrientypedef ULONG * PULONG;
79143439Sobrien
80143439Sobrientypedef char CHAR;
81143439Sobrientypedef short SHORT;
82143439Sobrientypedef long LONG;
83143439Sobrien
84143439Sobrientypedef unsigned int UINT;
85143439Sobrientypedef unsigned int *PUINT;
86143439Sobrien
87143439Sobrien
88143439Sobrien#endif
89143439Sobrien
90143439Sobrien
91143439Sobrien#define NV_VOID            	void
92143439Sobrientypedef NV_VOID            	*PNV_VOID;
93143439Sobrien
94143439Sobrientypedef unsigned long		NV_BOOLEAN, *PNV_BOOLEAN;
95143439Sobrien
96143439Sobrientypedef unsigned char		NV_UINT8, *PNV_UINT8;
97143439Sobrientypedef unsigned short		NV_UINT16, *PNV_UINT16;
98143439Sobrien#ifdef linux
99143439Sobrientypedef unsigned int		NV_UINT32, *PNV_UINT32;
100143439Sobrien#else
101143439Sobrientypedef unsigned long		NV_UINT32, *PNV_UINT32;
102143439Sobrien#endif
103143439Sobrien
104143439Sobrientypedef signed char   		NV_SINT8,  *PNV_SINT8;
105143439Sobrientypedef signed short  		NV_SINT16, *PNV_SINT16;
106143439Sobrientypedef signed long   		NV_SINT32, *PNV_SINT32;
107143439Sobrien
108143439Sobrien
109143439Sobrien#if defined(linux)
110143439Sobrien
111143439Sobrien    typedef unsigned long long           NV_UINT64, *PNV_UINT64;
112143439Sobrien    typedef signed long long             NV_SINT64, *PNV_SINT64;
113143439Sobrien
114143439Sobrien#else
115143439Sobrien    #if _MSC_VER >= 1200         // MSVC 6.0 onwards
116143439Sobrien        typedef unsigned __int64 	NV_UINT64, *PNV_UINT64;
117143439Sobrien        typedef signed __int64 		NV_SINT64, *PNV_SINT64;
118143439Sobrien    #else
119143439Sobrien        typedef unsigned long     	NV_UINT64, *PNV_UINT64;
120143439Sobrien        typedef signed   long 		NV_SINT64, *PNV_SINT64;
121143439Sobrien    #endif
122143439Sobrien
123143439Sobrien#endif
124143439Sobrien
125143439Sobrien#ifndef _AMD64_
126143439Sobrientypedef unsigned int    NV_UINT;
127143439Sobrientypedef signed int      NV_INT;
128143439Sobrien#else
129143439Sobrien
130143439Sobrien#if defined(linux)
131143439Sobrien
132143439Sobrientypedef unsigned long long  NV_UINT;
133143439Sobrientypedef signed long long    NV_INT;
134143439Sobrien
135143439Sobrien#else
136143439Sobrien
137143439Sobrientypedef unsigned __int64    NV_UINT;
138143439Sobrientypedef signed __int64      NV_INT;
139143439Sobrien
140143439Sobrien#endif
141143439Sobrien#endif
142143439Sobrien
143143439Sobrien
144143439Sobrien//
145143439Sobrien// Floating point definitions
146143439Sobrien//
147143439Sobrientypedef float                 NV_REAL32;   // 4-byte floating point
148143439Sobrientypedef double                NV_REAL64;   // 8-byte floating point
149143439Sobrien
150143439Sobrien
151143439Sobrien
152143439Sobrien//
153143439Sobrien// Bit defintions
154143439Sobrien//
155143439Sobrien#define NV_BIT(bitpos)                  (1 << (bitpos))
156143439Sobrien
157143439Sobrien// NV_BIT_SET
158143439Sobrien// Sets the specified bit position (0..31).
159143439Sobrien// Parameter bits can be 1 byte to 4 bytes, but the caller needs to make sure bitpos fits into it.
160143439Sobrien// x = 0xA0
161143439Sobrien// NV_BIT_SET(x, 1)
162143439Sobrien// Result: x = 0xA2
163143439Sobrien#define NV_BIT_SET(bits, bitpos)        ((bits) |= (NV_BIT(bitpos)))
164143439Sobrien
165143439Sobrien// NV_BIT_CLEAR
166143439Sobrien// Clears the specified bit position (0..31)
167143439Sobrien// Parameter bits can be 1 byte to 4 bytes, but the caller needs to make sure bitpos fits into it.
168143439Sobrien// x = 0xAA
169143439Sobrien// NV_BIT_CLEAR(x, 1)
170143439Sobrien// Result: x = 0xA8
171143439Sobrien#define NV_BIT_CLEAR(bits, bitpos)      ((bits) &= (~NV_BIT(bitpos)))
172143439Sobrien
173143439Sobrien// NV_BIT_GET
174143439Sobrien// Gets the bit at the specified bit position (0..31)
175143439Sobrien// Parameter bits can be 1 byte to 4 bytes, but the caller needs to make sure bitpos fits into it.
176143439Sobrien// Result is either 1 or 0.
177143439Sobrien// x = 0xAA
178143439Sobrien// NV_BIT_GET(x, 1)
179143439Sobrien// Result: x = 1
180143439Sobrien#define NV_BIT_GET(bits, bitpos)        (((bits) >> (bitpos)) & 0x0001)
181143439Sobrien
182143439Sobrien
183143439Sobrien// NV_BIT_GETVALUE
184143439Sobrien// Gets the value from a 32 bit ULONG at specified bit position.
185143439Sobrien// Parameter bits needs to be 4 bytes long.
186143439Sobrien// Ex. ul32 = 0xFEDCBA98
187143439Sobrien// ulVal = NV_BIT_GETVALUE(ul32, 3, 0)  : Gets value from Bit position 3 to 0
188143439Sobrien// Result : ulVal = 8
189143439Sobrien#define NV_BIT_GETVALUE(ulOrigValue, bitposHi, bitposLow)  (((ulOrigValue) >> (bitposLow)) & (~(0xFFFFFFFF << ((bitposHi) - (bitposLow) +1))))
190143439Sobrien
191143439Sobrien// NV_BIT_SETVALUE
192143439Sobrien// Set a value in a 32 bit ULONG at a specific bit position.
193143439Sobrien// Parameter bits needs to be 4 bytes long.
194143439Sobrien// Ex. ul32 = 0xFEDCBA98
195143439Sobrien// NV_BIT_SETVALUE(ul32, 0xF, 3, 0)  : Sets value at Bit position 3 to 0
196143439Sobrien// Result : ul32 becomes 0xFEDCBA9F
197143439Sobrien#define NV_BIT_SETVALUE(ulOrigValue, ulWindowValue, bitposHi, bitposLow)  \
198143439Sobrien    ((ulOrigValue) = ((((ulOrigValue) & (~ ((0xFFFFFFFF >> (31 - (bitposHi))) & (0xFFFFFFFF << (bitposLow))))) | ((ulWindowValue) << (bitposLow)))))
199143439Sobrien
200143439Sobrien
201143439Sobrien#define NV_BYTE(ulus, bytepos)  ((ulus >> (8 * (bytepos))) & 0xFF)
202143439Sobrien
203143439Sobrien
204143439Sobrien#define SWAP_U16(us) ((((us) & 0x00FF) << 8) | \
205143439Sobrien                      (((us) & 0xFF00) >> 8))
206143439Sobrien
207143439Sobrien#define SWAP_U32(ul) ((((ul) & 0x000000FF) << 24) |   \
208143439Sobrien                        (((ul) & 0x0000FF00) <<  8) |	  \
209143439Sobrien                        (((ul) & 0x00FF0000) >>  8) |	  \
210143439Sobrien                        (((ul) & 0xFF000000) >> 24))
211143439Sobrien
212143439Sobrien#define NV_FIELD_OFFSET(TYPE, FIELD)  ((NV_UINT32)((NV_UINT64)&((TYPE *)0)->FIELD))
213143439Sobrien
214143439Sobrien#define ADDRESS_OFFSET(structure, member)       ((NV_UINT32) ((NV_UINT8 *) &(structure).member  \
215143439Sobrien                                                            - (NV_UINT8 *) &(structure)))
216143439Sobrien
217143439Sobrien
218143439Sobrien#define NV_MIN(a, b) ((a < b) ? a : b)
219143439Sobrien#define NV_MAX(a, b) ((a > b) ? a : b)
220143439Sobrien
221143439Sobrien#ifdef AMD64
222143439Sobrien#define PNV_VOID_TO_NV_UINT64(x)    ((NV_UINT64)(x))
223143439Sobrien#define PNV_VOID_TO_NV_UINT32(x)    ((NV_UINT32)(NV_UINT64)(x))
224143439Sobrien#define NV_UINT64_TO_PNV_VOID(x)    ((PNV_VOID)(x))
225143439Sobrien#define NV_UINT32_TO_PNV_VOID(x)    ((PNV_VOID)(NV_UINT64)(x))
226143439Sobrien#else
227143439Sobrien#define PNV_VOID_TO_NV_UINT64(x)    ((NV_UINT64)(NV_UINT32)(x))
228143439Sobrien#define PNV_VOID_TO_NV_UINT32(x)    ((NV_UINT32)(x))
229143439Sobrien#define NV_UINT64_TO_PNV_VOID(x)    ((PNV_VOID)(NV_UINT32)(x))
230143439Sobrien#define NV_UINT32_TO_PNV_VOID(x)    ((PNV_VOID)(x))
231143439Sobrien#endif
232143439Sobrien
233143439Sobrien#define NV_MAKE_TAG32(s)            (((NV_UINT32)((s)[3]) << 24) | ((NV_UINT32)((s)[2]) << 16) | \
234143439Sobrien                                     ((NV_UINT32)((s)[1]) <<  8) | ((NV_UINT32)((s)[0])))
235143439Sobrien
236143439Sobrien#define NV_MAKE_TAG64(s)            (((NV_UINT64)((s)[7]) << 56) | ((NV_UINT64)((s)[6]) << 48) | \
237143439Sobrien                                     ((NV_UINT64)((s)[5]) << 40) | ((NV_UINT64)((s)[4]) << 32) | \
238143439Sobrien                                     ((NV_UINT64)((s)[3]) << 24) | ((NV_UINT64)((s)[2]) << 16) | \
239143439Sobrien                                     ((NV_UINT64)((s)[1]) <<  8) | ((NV_UINT64)((s)[0])))
240143439Sobrien
241143439Sobrientypedef union _NVLARGE_INTEGER {
242143439Sobrien
243143439Sobrien#if 0
244143439Sobrien    // NO UNNAMED UNIONS ALLOWED !@
245143439Sobrien    struct {
246143439Sobrien        NV_UINT32   LowPart;
247143439Sobrien        NV_SINT32   HighPart;
248143439Sobrien    };
249143439Sobrien#endif
250143439Sobrien
251143439Sobrien    struct {
252143439Sobrien        NV_UINT32   LowPart;
253143439Sobrien        NV_SINT32   HighPart;
254143439Sobrien    } u;
255143439Sobrien
256143439Sobrien    NV_SINT64       QuadPart;
257143439Sobrien
258143439Sobrien} NVLARGE_INTEGER, *PNVLARGE_INTEGER;
259143439Sobrien
260143439Sobrien
261143439Sobrien#ifndef LINUX
262143439Sobrientypedef unsigned short NV_WCHAR;
263143439Sobrien#else
264143439Sobrientypedef unsigned long NV_WCHAR;
265143439Sobrien#endif
266143439Sobrien
267143439Sobrientypedef NV_WCHAR *PNV_WSTR;
268143439Sobrien
269143439Sobrien#if defined(linux)
270143439Sobrien#if !defined(NV_API_CALL)
271143439Sobrien#if defined (__i386__)
272143439Sobrien#define NV_API_CALL __attribute__ ((regparm(0)))
273143439Sobrien#else
274143439Sobrien#define NV_API_CALL
275143439Sobrien#endif
276143439Sobrien#endif
277143439Sobrien#else
278143439Sobrien#define NV_API_CALL
279143439Sobrien#endif
280143439Sobrien
281143439Sobrien#endif // _BASETYPE_H_
282