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;
80 #include <linux/types.h>
85 #define NDIS_STATUS uint
87 typedef signed int sint;
91 //#define PVOID (void *)
99 typedef void (*proc_t)(void*);
101 typedef __kernel_size_t SIZE_T;
102 typedef __kernel_ssize_t SSIZE_T;
103 #define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
108 #ifdef PLATFORM_FREEBSD
110 typedef signed char s8;
111 typedef unsigned char u8;
113 typedef signed short s16;
114 typedef unsigned short u16;
116 typedef signed int s32;
117 typedef unsigned int u32;
119 typedef unsigned int uint;
120 typedef signed int sint;
121 typedef long atomic_t;
123 typedef signed long long s64;
124 typedef unsigned long long u64;
128 #define NDIS_OID uint
129 #define NDIS_STATUS uint
132 typedef void * PVOID;
133 //#define PVOID (void *)
135 typedef u32 dma_addr_t;
141 typedef void (*proc_t)(void*);
143 typedef unsigned int __kernel_size_t;
144 typedef int __kernel_ssize_t;
146 typedef __kernel_size_t SIZE_T;
147 typedef __kernel_ssize_t SSIZE_T;
148 #define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
152 #define MEM_ALIGNMENT_OFFSET (sizeof (SIZE_T))
153 #define MEM_ALIGNMENT_PADDING (sizeof(SIZE_T) - 1)
155 #define SIZE_PTR SIZE_T
156 #define SSIZE_PTR SSIZE_T
158 //port from fw by thomas
159 // TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness
162 * Call endian free function when
163 * 1. Read/write packet content.
164 * 2. Before write integer to IO.
165 * 3. After read integer from IO.
169 // Byte Swapping routine.
172 #define EF2Byte le16_to_cpu
173 #define EF4Byte le32_to_cpu
176 // Read LE format data from memory
178 #define ReadEF1Byte(_ptr) EF1Byte(*((u8 *)(_ptr)))
179 #define ReadEF2Byte(_ptr) EF2Byte(*((u16 *)(_ptr)))
180 #define ReadEF4Byte(_ptr) EF4Byte(*((u32 *)(_ptr)))
183 // Write LE data to memory
185 #define WriteEF1Byte(_ptr, _val) (*((u8 *)(_ptr)))=EF1Byte(_val)
186 #define WriteEF2Byte(_ptr, _val) (*((u16 *)(_ptr)))=EF2Byte(_val)
187 #define WriteEF4Byte(_ptr, _val) (*((u32 *)(_ptr)))=EF4Byte(_val)
191 // BIT_LEN_MASK_32(0) => 0x00000000
192 // BIT_LEN_MASK_32(1) => 0x00000001
193 // BIT_LEN_MASK_32(2) => 0x00000003
194 // BIT_LEN_MASK_32(32) => 0xFFFFFFFF
196 #define BIT_LEN_MASK_32(__BitLen) \
197 (0xFFFFFFFF >> (32 - (__BitLen)))
200 // BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
201 // BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
203 #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) \
204 (BIT_LEN_MASK_32(__BitLen) << (__BitOffset))
208 // Return 4-byte value in host byte ordering from
209 // 4-byte pointer in litten-endian system.
211 #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
212 (EF4Byte(*((u32 *)(__pStart))))
216 // Translate subfield (continuous bits in little-endian) of 4-byte value in litten byte to
217 // 4-byte value in host byte ordering.
219 #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
221 ( LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset) ) \
223 BIT_LEN_MASK_32(__BitLen) \
228 // Mask subfield (continuous bits in little-endian) of 4-byte value in litten byte oredering
229 // and return the result in 4-byte value in host byte ordering.
231 #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
233 LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
235 ( ~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ) \
240 // Set subfield of little-endian 4-byte value to specified value.
242 #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
243 *((u32 *)(__pStart)) = \
245 LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
247 ( (((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset) ) \
251 #define BIT_LEN_MASK_16(__BitLen) \
252 (0xFFFF >> (16 - (__BitLen)))
254 #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) \
255 (BIT_LEN_MASK_16(__BitLen) << (__BitOffset))
257 #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
258 (EF2Byte(*((u16 *)(__pStart))))
260 #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
262 ( LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset) ) \
264 BIT_LEN_MASK_16(__BitLen) \
267 #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
269 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
271 ( ~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) ) \
274 #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
275 *((u16 *)(__pStart)) = \
277 LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
279 ( (((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset) ) \
282 #define BIT_LEN_MASK_8(__BitLen) \
283 (0xFF >> (8 - (__BitLen)))
285 #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) \
286 (BIT_LEN_MASK_8(__BitLen) << (__BitOffset))
288 #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
289 (EF1Byte(*((u8 *)(__pStart))))
291 #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
293 ( LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset) ) \
295 BIT_LEN_MASK_8(__BitLen) \
298 #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
300 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
302 ( ~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) ) \
305 #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
306 *((u8 *)(__pStart)) = \
308 LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
310 ( (((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset) ) \
314 #define LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
316 LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
319 #define SET_BITS_TO_LE_2BYTE_16BIT(__pStart, __BitOffset, __BitLen, __Value) \
320 *((u16 *)(__pStart)) = \
322 LE_BITS_CLEARED_TO_2BYTE_16BIT(__pStart, __BitOffset, __BitLen) \
327 #define LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
329 LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
332 #define SET_BITS_TO_LE_1BYTE_8BIT(__pStart, __BitOffset, __BitLen, __Value) \
334 *((u8 *)(__pStart)) = \
336 LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
342 // Get the N-bytes aligment offset from the current length
343 #define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
345 typedef unsigned char BOOLEAN,*PBOOLEAN;
347 #define TEST_FLAG(__Flag,__testFlag) (((__Flag) & (__testFlag)) != 0)
348 #define SET_FLAG(__Flag, __setFlag) ((__Flag) |= __setFlag)
349 #define CLEAR_FLAG(__Flag, __clearFlag) ((__Flag) &= ~(__clearFlag))
350 #define CLEAR_FLAGS(__Flag) ((__Flag) = 0)
351 #define TEST_FLAGS(__Flag, __testFlags) (((__Flag) & (__testFlags)) == (__testFlags))
353 #endif //__BASIC_TYPES_H__