1/***************************************************************************\ 2|* *| 3|* Copyright 2001-2004 NVIDIA Corporation. All Rights Reserved. *| 4|* *| 5|* THE INFORMATION CONTAINED HEREIN IS PROPRIETARY AND CONFIDENTIAL *| 6|* TO NVIDIA, CORPORATION. USE, REPRODUCTION OR DISCLOSURE TO ANY *| 7|* THIRD PARTY IS SUBJECT TO WRITTEN PRE-APPROVAL BY NVIDIA, CORP. *| 8|* *| 9|* THE INFORMATION CONTAINED HEREIN IS PROVIDED "AS IS" WITHOUT *| 10|* EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING ALL IMPLIED *| 11|* WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A *| 12|* PARTICULAR PURPOSE. *| 13|* *| 14\***************************************************************************/ 15 16 17/*++ 18 19File: 20 21 basetype.h 22 23 24Abstract: 25 26 This file contains the base type definitions used by the networking driver. 27 28 29Revision History: 30 31 SNo. Date Author Description 32 1. 2/7/2000 AJha Created 33 34*/ 35 36#ifndef _BASETYPE_H_ 37#define _BASETYPE_H_ 38 39#ifndef IN 40#define IN 41#endif 42 43#ifndef OUT 44#define OUT 45#endif 46 47// 48// Useful "types" 49 50#ifndef NULL 51#define NULL 0 52#endif 53 54#ifndef TRUE 55#define TRUE 1 56#endif 57 58#ifndef FALSE 59#define FALSE 0 60#endif 61 62#if 1 63// 64// Don't use as these are going to be deleted soon. Use NV_ instead 65// 66#define VOID void 67typedef VOID *PVOID; 68 69typedef unsigned char UCHAR; 70typedef UCHAR * PUCHAR; 71typedef unsigned short USHORT; 72typedef USHORT * PUSHORT; 73#ifdef linux 74typedef unsigned int ULONG; 75#else 76typedef unsigned long ULONG; 77#endif 78typedef ULONG * PULONG; 79 80typedef char CHAR; 81typedef short SHORT; 82typedef long LONG; 83 84typedef unsigned int UINT; 85typedef unsigned int *PUINT; 86 87 88#endif 89 90 91#define NV_VOID void 92typedef NV_VOID *PNV_VOID; 93 94typedef unsigned long NV_BOOLEAN, *PNV_BOOLEAN; 95 96typedef unsigned char NV_UINT8, *PNV_UINT8; 97typedef unsigned short NV_UINT16, *PNV_UINT16; 98#ifdef linux 99typedef unsigned int NV_UINT32, *PNV_UINT32; 100#else 101typedef unsigned long NV_UINT32, *PNV_UINT32; 102#endif 103 104typedef signed char NV_SINT8, *PNV_SINT8; 105typedef signed short NV_SINT16, *PNV_SINT16; 106typedef signed long NV_SINT32, *PNV_SINT32; 107 108 109#if defined(linux) 110 111 typedef unsigned long long NV_UINT64, *PNV_UINT64; 112 typedef signed long long NV_SINT64, *PNV_SINT64; 113 114#else 115 #if _MSC_VER >= 1200 // MSVC 6.0 onwards 116 typedef unsigned __int64 NV_UINT64, *PNV_UINT64; 117 typedef signed __int64 NV_SINT64, *PNV_SINT64; 118 #else 119 typedef unsigned long NV_UINT64, *PNV_UINT64; 120 typedef signed long NV_SINT64, *PNV_SINT64; 121 #endif 122 123#endif 124 125#ifndef _AMD64_ 126typedef unsigned int NV_UINT; 127typedef signed int NV_INT; 128#else 129 130#if defined(linux) 131 132typedef unsigned long long NV_UINT; 133typedef signed long long NV_INT; 134 135#else 136 137typedef unsigned __int64 NV_UINT; 138typedef signed __int64 NV_INT; 139 140#endif 141#endif 142 143 144// 145// Floating point definitions 146// 147typedef float NV_REAL32; // 4-byte floating point 148typedef double NV_REAL64; // 8-byte floating point 149 150 151 152// 153// Bit defintions 154// 155#define NV_BIT(bitpos) (1 << (bitpos)) 156 157// NV_BIT_SET 158// Sets the specified bit position (0..31). 159// Parameter bits can be 1 byte to 4 bytes, but the caller needs to make sure bitpos fits into it. 160// x = 0xA0 161// NV_BIT_SET(x, 1) 162// Result: x = 0xA2 163#define NV_BIT_SET(bits, bitpos) ((bits) |= (NV_BIT(bitpos))) 164 165// NV_BIT_CLEAR 166// Clears the specified bit position (0..31) 167// Parameter bits can be 1 byte to 4 bytes, but the caller needs to make sure bitpos fits into it. 168// x = 0xAA 169// NV_BIT_CLEAR(x, 1) 170// Result: x = 0xA8 171#define NV_BIT_CLEAR(bits, bitpos) ((bits) &= (~NV_BIT(bitpos))) 172 173// NV_BIT_GET 174// Gets the bit at the specified bit position (0..31) 175// Parameter bits can be 1 byte to 4 bytes, but the caller needs to make sure bitpos fits into it. 176// Result is either 1 or 0. 177// x = 0xAA 178// NV_BIT_GET(x, 1) 179// Result: x = 1 180#define NV_BIT_GET(bits, bitpos) (((bits) >> (bitpos)) & 0x0001) 181 182 183// NV_BIT_GETVALUE 184// Gets the value from a 32 bit ULONG at specified bit position. 185// Parameter bits needs to be 4 bytes long. 186// Ex. ul32 = 0xFEDCBA98 187// ulVal = NV_BIT_GETVALUE(ul32, 3, 0) : Gets value from Bit position 3 to 0 188// Result : ulVal = 8 189#define NV_BIT_GETVALUE(ulOrigValue, bitposHi, bitposLow) (((ulOrigValue) >> (bitposLow)) & (~(0xFFFFFFFF << ((bitposHi) - (bitposLow) +1)))) 190 191// NV_BIT_SETVALUE 192// Set a value in a 32 bit ULONG at a specific bit position. 193// Parameter bits needs to be 4 bytes long. 194// Ex. ul32 = 0xFEDCBA98 195// NV_BIT_SETVALUE(ul32, 0xF, 3, 0) : Sets value at Bit position 3 to 0 196// Result : ul32 becomes 0xFEDCBA9F 197#define NV_BIT_SETVALUE(ulOrigValue, ulWindowValue, bitposHi, bitposLow) \ 198 ((ulOrigValue) = ((((ulOrigValue) & (~ ((0xFFFFFFFF >> (31 - (bitposHi))) & (0xFFFFFFFF << (bitposLow))))) | ((ulWindowValue) << (bitposLow))))) 199 200 201#define NV_BYTE(ulus, bytepos) ((ulus >> (8 * (bytepos))) & 0xFF) 202 203 204#define SWAP_U16(us) ((((us) & 0x00FF) << 8) | \ 205 (((us) & 0xFF00) >> 8)) 206 207#define SWAP_U32(ul) ((((ul) & 0x000000FF) << 24) | \ 208 (((ul) & 0x0000FF00) << 8) | \ 209 (((ul) & 0x00FF0000) >> 8) | \ 210 (((ul) & 0xFF000000) >> 24)) 211 212#define NV_FIELD_OFFSET(TYPE, FIELD) ((NV_UINT32)((NV_UINT64)&((TYPE *)0)->FIELD)) 213 214#define ADDRESS_OFFSET(structure, member) ((NV_UINT32) ((NV_UINT8 *) &(structure).member \ 215 - (NV_UINT8 *) &(structure))) 216 217 218#define NV_MIN(a, b) ((a < b) ? a : b) 219#define NV_MAX(a, b) ((a > b) ? a : b) 220 221#ifdef AMD64 222#define PNV_VOID_TO_NV_UINT64(x) ((NV_UINT64)(x)) 223#define PNV_VOID_TO_NV_UINT32(x) ((NV_UINT32)(NV_UINT64)(x)) 224#define NV_UINT64_TO_PNV_VOID(x) ((PNV_VOID)(x)) 225#define NV_UINT32_TO_PNV_VOID(x) ((PNV_VOID)(NV_UINT64)(x)) 226#else 227#define PNV_VOID_TO_NV_UINT64(x) ((NV_UINT64)(NV_UINT32)(x)) 228#define PNV_VOID_TO_NV_UINT32(x) ((NV_UINT32)(x)) 229#define NV_UINT64_TO_PNV_VOID(x) ((PNV_VOID)(NV_UINT32)(x)) 230#define NV_UINT32_TO_PNV_VOID(x) ((PNV_VOID)(x)) 231#endif 232 233#define NV_MAKE_TAG32(s) (((NV_UINT32)((s)[3]) << 24) | ((NV_UINT32)((s)[2]) << 16) | \ 234 ((NV_UINT32)((s)[1]) << 8) | ((NV_UINT32)((s)[0]))) 235 236#define NV_MAKE_TAG64(s) (((NV_UINT64)((s)[7]) << 56) | ((NV_UINT64)((s)[6]) << 48) | \ 237 ((NV_UINT64)((s)[5]) << 40) | ((NV_UINT64)((s)[4]) << 32) | \ 238 ((NV_UINT64)((s)[3]) << 24) | ((NV_UINT64)((s)[2]) << 16) | \ 239 ((NV_UINT64)((s)[1]) << 8) | ((NV_UINT64)((s)[0]))) 240 241typedef union _NVLARGE_INTEGER { 242 243#if 0 244 // NO UNNAMED UNIONS ALLOWED !@ 245 struct { 246 NV_UINT32 LowPart; 247 NV_SINT32 HighPart; 248 }; 249#endif 250 251 struct { 252 NV_UINT32 LowPart; 253 NV_SINT32 HighPart; 254 } u; 255 256 NV_SINT64 QuadPart; 257 258} NVLARGE_INTEGER, *PNVLARGE_INTEGER; 259 260 261#ifndef LINUX 262typedef unsigned short NV_WCHAR; 263#else 264typedef unsigned long NV_WCHAR; 265#endif 266 267typedef NV_WCHAR *PNV_WSTR; 268 269#if defined(linux) 270#if !defined(NV_API_CALL) 271#if defined (__i386__) 272#define NV_API_CALL __attribute__ ((regparm(0))) 273#else 274#define NV_API_CALL 275#endif 276#endif 277#else 278#define NV_API_CALL 279#endif 280 281#endif // _BASETYPE_H_ 282