1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #ifndef __BASIC_TYPES_H__
21 #define __BASIC_TYPES_H__
39 #ifdef PLATFORM_WINDOWS
41 typedef signed char s8;
42 typedef unsigned char u8;
44 typedef signed short s16;
45 typedef unsigned short u16;
47 typedef signed long s32;
48 typedef unsigned long u32;
50 typedef unsigned int uint;
51 typedef signed int sint;
54 typedef signed long long s64;
55 typedef unsigned long long u64;
57 #ifdef NDIS50_MINIPORT
59 #define NDIS_MAJOR_VERSION 5
60 #define NDIS_MINOR_VERSION 0
64 #ifdef NDIS51_MINIPORT
66 #define NDIS_MAJOR_VERSION 5
67 #define NDIS_MINOR_VERSION 1
71 typedef NDIS_PROC proc_t;
73 typedef LONG atomic_t;
79 #include <linux/version.h>
80 #include <linux/types.h>
85 #define NDIS_STATUS uint
87 typedef signed int sint;
91 //#define PVOID (void *)
99 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
103 typedef void (*proc_t)(void*);
105 typedef __kernel_size_t SIZE_T;
106 typedef __kernel_ssize_t SSIZE_T;
107 #define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
112 #ifdef PLATFORM_FREEBSD
114 typedef signed char s8;
115 typedef unsigned char u8;
117 typedef signed short s16;
118 typedef unsigned short u16;
120 typedef signed int s32;
121 typedef unsigned int u32;
123 typedef unsigned int uint;
124 typedef signed int sint;
125 typedef long atomic_t;
127 typedef signed long long s64;
128 typedef unsigned long long u64;
132 #define NDIS_OID uint
133 #define NDIS_STATUS uint
136 typedef void * PVOID;
137 //#define PVOID (void *)
139 typedef u32 dma_addr_t;
145 typedef void (*proc_t)(void*);
147 typedef unsigned int __kernel_size_t;
148 typedef int __kernel_ssize_t;
150 typedef __kernel_size_t SIZE_T;
151 typedef __kernel_ssize_t SSIZE_T;
152 #define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
156 #define MEM_ALIGNMENT_OFFSET (sizeof (SIZE_T))
157 #define MEM_ALIGNMENT_PADDING (sizeof(SIZE_T) - 1)
159 #define SIZE_PTR SIZE_T
160 #define SSIZE_PTR SSIZE_T
162 //port from fw by thomas
163 // TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness
166 * Call endian free function when
167 * 1. Read/write packet content.
168 * 2. Before write integer to IO.
169 * 3. After read integer from IO.
173 // Byte Swapping routine.
176 #define EF2Byte le16_to_cpu
177 #define EF4Byte le32_to_cpu
180 // Read LE format data from memory
182 #define ReadEF1Byte(_ptr) EF1Byte(*((u8 *)(_ptr)))
183 #define ReadEF2Byte(_ptr) EF2Byte(*((u16 *)(_ptr)))
184 #define ReadEF4Byte(_ptr) EF4Byte(*((u32 *)(_ptr)))
187 // Write LE data to memory
189 #define WriteEF1Byte(_ptr, _val) (*((u8 *)(_ptr)))=EF1Byte(_val)
190 #define WriteEF2Byte(_ptr, _val) (*((u16 *)(_ptr)))=EF2Byte(_val)
191 #define WriteEF4Byte(_ptr, _val) (*((u32 *)(_ptr)))=EF4Byte(_val)
195 // BIT_LEN_MASK_32(0) => 0x00000000
196 // BIT_LEN_MASK_32(1) => 0x00000001
197 // BIT_LEN_MASK_32(2) => 0x00000003
198 // BIT_LEN_MASK_32(32) => 0xFFFFFFFF
200 #define BIT_LEN_MASK_32(__BitLen) \
201 (0xFFFFFFFF >> (32 - (__BitLen)))
204 // BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
205 // BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
207 #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) \
208 (BIT_LEN_MASK_32(__BitLen) << (__BitOffset))
212 // Return 4-byte value in host byte ordering from
213 // 4-byte pointer in litten-endian system.
215 #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
216 (EF4Byte(*((u32 *)(__pStart))))
220 // Translate subfield (continuous bits in little-endian) of 4-byte value in litten byte to
221 // 4-byte value in host byte ordering.
223 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
225 ( LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset) ) \
227 BIT_LEN_MASK_32(__BitLen) \
232 // Mask subfield (continuous bits in little-endian) of 4-byte value in litten byte oredering
233 // and return the result in 4-byte value in host byte ordering.
235 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
237 LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
239 ( ~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ) \
244 // Set subfield of little-endian 4-byte value to specified value.
246 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
247 *((u32 *)(__pStart)) = \
249 LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
251 ( (((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset) ) \
255 #define BIT_LEN_MASK_16(__BitLen) \
256 (0xFFFF >> (16 - (__BitLen)))
258 #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) \
259 (BIT_LEN_MASK_16(__BitLen) << (__BitOffset))
261 #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
262 (EF2Byte(*((u16 *)(__pStart))))
264 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
266 ( LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset) ) \
268 BIT_LEN_MASK_16(__BitLen) \
271 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
273 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
275 (u16)(~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen))\
278 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
279 *((u16 *)(__pStart)) = \
281 LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
283 ( (((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset) ) \
286 #define BIT_LEN_MASK_8(__BitLen) \
287 (0xFF >> (8 - (__BitLen)))
289 #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) \
290 (BIT_LEN_MASK_8(__BitLen) << (__BitOffset))
292 #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
293 (EF1Byte(*((u8 *)(__pStart))))
295 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
297 ( LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset) ) \
299 BIT_LEN_MASK_8(__BitLen) \
302 #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
304 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
306 (u8)(~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen))\
309 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
310 *((u8 *)(__pStart)) = \
312 LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
314 ( (((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset) ) \
318 #define LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
320 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
323 #define SET_BITS_TO_LE_2BYTE_16BIT(__pStart, __BitOffset, __BitLen, __Value) \
324 *((u16 *)(__pStart)) = \
326 LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
331 #define LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
333 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
336 #define SET_BITS_TO_LE_1BYTE_8BIT(__pStart, __BitOffset, __BitLen, __Value) \
338 *((u8 *)(__pStart)) = \
340 LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
346 // Get the N-bytes aligment offset from the current length
347 #define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
349 typedef unsigned char BOOLEAN,*PBOOLEAN;
351 #define TEST_FLAG(__Flag,__testFlag) (((__Flag) & (__testFlag)) != 0)
352 #define SET_FLAG(__Flag, __setFlag) ((__Flag) |= __setFlag)
353 #define CLEAR_FLAG(__Flag, __clearFlag) ((__Flag) &= ~(__clearFlag))
354 #define CLEAR_FLAGS(__Flag) ((__Flag) = 0)
355 #define TEST_FLAGS(__Flag, __testFlags) (((__Flag) & (__testFlags)) == (__testFlags))
357 #endif //__BASIC_TYPES_H__