1/*
2 * Copyright (C) 2015, Broadcom Corporation. All Rights Reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 * $Id: typedefs.h 452599 2014-01-31 07:25:38Z $
16 */
17
18#ifndef _TYPEDEFS_H_
19#define _TYPEDEFS_H_
20#define MAX_EVENT 16   /* Maximum number of event bit 128 */
21
22#ifdef SITE_TYPEDEFS
23
24/*
25 * Define SITE_TYPEDEFS in the compile to include a site-specific
26 * typedef file "site_typedefs.h".
27 *
28 * If SITE_TYPEDEFS is not defined, then the code section below makes
29 * inferences about the compile environment based on defined symbols and
30 * possibly compiler pragmas.
31 *
32 * Following these two sections is the Default Typedefs section.
33 * This section is only processed if USE_TYPEDEF_DEFAULTS is
34 * defined. This section has a default set of typedefs and a few
35 * preprocessor symbols (TRUE, FALSE, NULL, ...).
36 */
37
38#include "site_typedefs.h"
39
40#else
41
42/*
43 * Infer the compile environment based on preprocessor symbols and pragmas.
44 * Override type definitions as needed, and include configuration-dependent
45 * header files to define types.
46 */
47
48#ifdef __cplusplus
49
50#define TYPEDEF_BOOL
51#ifndef FALSE
52#define FALSE	false
53#endif
54#ifndef TRUE
55#define TRUE	true
56#endif
57
58#else	/* ! __cplusplus */
59
60#if defined(_WIN32)
61
62#define TYPEDEF_BOOL
63typedef	unsigned char	bool;			/* consistent w/BOOL */
64
65#endif /* _WIN32 */
66
67#endif	/* ! __cplusplus */
68
69#if defined(_WIN64) && !defined(EFI)
70/* use the Windows ULONG_PTR type when compiling for 64 bit */
71#include <basetsd.h>
72#define TYPEDEF_UINTPTR
73typedef ULONG_PTR uintptr;
74#elif defined(__x86_64__)
75#define TYPEDEF_UINTPTR
76typedef unsigned long long int uintptr;
77#endif
78
79
80#if defined(_MINOSL_)
81#define _NEED_SIZE_T_
82#endif
83
84#if defined(EFI) && !defined(_WIN64)
85#define _NEED_SIZE_T_
86#endif
87
88#if defined(TARGETOS_nucleus)
89/* for 'size_t' type */
90#include <stddef.h>
91
92/* float_t types conflict with the same typedefs from the standard ANSI-C
93** math.h header file. Don't re-typedef them here.
94*/
95#define TYPEDEF_FLOAT_T
96#endif   /* TARGETOS_nucleus */
97
98#if defined(_NEED_SIZE_T_)
99typedef long unsigned int size_t;
100#endif
101
102#ifdef _MSC_VER	/* Microsoft C */
103#define TYPEDEF_INT64
104#define TYPEDEF_UINT64
105typedef signed __int64	int64;
106typedef unsigned __int64 uint64;
107#endif
108
109#if defined(MACOSX)
110#define TYPEDEF_BOOL
111#endif
112
113#if defined(__NetBSD__)
114#define TYPEDEF_BOOL
115#ifndef _KERNEL
116#include <stdbool.h>
117#endif
118#define TYPEDEF_UINT
119#define TYPEDEF_USHORT
120#define TYPEDEF_ULONG
121#endif /* defined(__NetBSD__) */
122
123#if defined(__FreeBSD__)
124#include <sys/param.h>
125#if (__FreeBSD_version == 901000)
126#define TYPEDEF_BOOL
127#endif /* (__FreeBSD_version == 901000) */
128#endif /* (defined(__FreeBSD__)) */
129
130#if defined(__sparc__)
131#define TYPEDEF_ULONG
132#endif
133
134
135#ifdef	linux
136/*
137 * If this is either a Linux hybrid build or the per-port code of a hybrid build
138 * then use the Linux header files to get some of the typedefs.  Otherwise, define
139 * them entirely in this file.  We can't always define the types because we get
140 * a duplicate typedef error; there is no way to "undefine" a typedef.
141 * We know when it's per-port code because each file defines LINUX_PORT at the top.
142 */
143#if !defined(LINUX_HYBRID) || defined(LINUX_PORT)
144#define TYPEDEF_UINT
145#ifndef TARGETENV_android
146#define TYPEDEF_USHORT
147#define TYPEDEF_ULONG
148#endif /* TARGETENV_android */
149#ifdef __KERNEL__
150#include <linux/version.h>
151#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))
152#define TYPEDEF_BOOL
153#endif	/* >= 2.6.19 */
154/* special detection for 2.6.18-128.7.1.0.1.el5 */
155#if (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 18))
156#include <linux/compiler.h>
157#ifdef noinline_for_stack
158#define TYPEDEF_BOOL
159#endif
160#endif	/* == 2.6.18 */
161#endif	/* __KERNEL__ */
162#endif  /* !defined(LINUX_HYBRID) || defined(LINUX_PORT) */
163#endif	/* linux */
164
165#if defined(__ECOS)
166#define TYPEDEF_UCHAR
167#define TYPEDEF_UINT
168#define TYPEDEF_USHORT
169#define TYPEDEF_ULONG
170#define TYPEDEF_BOOL
171#endif
172
173#if !defined(linux) && !defined(_WIN32) && !defined(_CFE_) && !defined(_MINOSL_) && \
174	!defined(__DJGPP__) && !defined(__ECOS) && !defined(__BOB__) && \
175	!defined(TARGETOS_nucleus) && !defined(EFI) && !defined(__FreeBSD__)
176#define TYPEDEF_UINT
177#define TYPEDEF_USHORT
178#endif
179
180
181/* Do not support the (u)int64 types with strict ansi for GNU C */
182#if defined(__GNUC__) && defined(__STRICT_ANSI__)
183#if !defined(__FreeBSD__)
184#define TYPEDEF_INT64
185#define TYPEDEF_UINT64
186#endif /* !defined(__FreeBSD__) */
187#endif /* defined(__GNUC__) && defined(__STRICT_ANSI__) */
188
189/* ICL accepts unsigned 64 bit type only, and complains in ANSI mode
190 * for signed or unsigned
191 */
192#if defined(__ICL)
193
194#define TYPEDEF_INT64
195
196#if defined(__STDC__)
197#define TYPEDEF_UINT64
198#endif
199
200#endif /* __ICL */
201
202#if !defined(_WIN32) && !defined(_CFE_) && !defined(_MINOSL_) && !defined(__DJGPP__) && \
203	!defined(__BOB__) && !defined(TARGETOS_nucleus) && !defined(EFI)
204
205/* pick up ushort & uint from standard types.h */
206#if defined(linux) && defined(__KERNEL__)
207
208/* See note above */
209#if !defined(LINUX_HYBRID) || defined(LINUX_PORT)
210#ifdef USER_MODE
211#include <sys/types.h>
212#else
213#include <linux/types.h>	/* sys/types.h and linux/types.h are oil and water */
214#endif /* USER_MODE */
215#endif /* !defined(LINUX_HYBRID) || defined(LINUX_PORT) */
216
217#else
218
219#if defined(__ECOS)
220#include <pkgconf/infra.h>
221#include <cyg/infra/cyg_type.h>
222#include <stdarg.h>
223#endif
224
225#include <sys/types.h>
226
227#endif /* linux && __KERNEL__ */
228
229#endif
230
231#if defined(MACOSX)
232
233#ifdef __BIG_ENDIAN__
234#define IL_BIGENDIAN
235#else
236#ifdef IL_BIGENDIAN
237#error "IL_BIGENDIAN was defined for a little-endian compile"
238#endif
239#endif /* __BIG_ENDIAN__ */
240
241#if !defined(__cplusplus)
242
243#if defined(__i386__)
244typedef unsigned char bool;
245#else
246typedef unsigned int bool;
247#endif
248#define TYPE_BOOL 1
249enum {
250    false	= 0,
251    true	= 1
252};
253
254#if defined(KERNEL)
255#include <IOKit/IOTypes.h>
256#endif /* KERNEL */
257
258#endif /* __cplusplus */
259
260#endif /* MACOSX */
261
262
263/* use the default typedefs in the next section of this file */
264#define USE_TYPEDEF_DEFAULTS
265
266#endif /* SITE_TYPEDEFS */
267
268
269/*
270 * Default Typedefs
271 */
272
273#ifdef USE_TYPEDEF_DEFAULTS
274#undef USE_TYPEDEF_DEFAULTS
275
276#ifndef TYPEDEF_BOOL
277#ifndef bool
278typedef	/* @abstract@ */ unsigned char	bool;
279#endif
280#endif
281
282/* define uchar, ushort, uint, ulong */
283
284#ifndef TYPEDEF_UCHAR
285typedef unsigned char	uchar;
286#endif
287
288#ifndef TYPEDEF_USHORT
289typedef unsigned short	ushort;
290#endif
291
292#ifndef TYPEDEF_UINT
293typedef unsigned int	uint;
294#endif
295
296#ifndef TYPEDEF_ULONG
297typedef unsigned long	ulong;
298#endif
299
300/* define [u]int8/16/32/64, uintptr */
301
302#ifndef TYPEDEF_UINT8
303#ifndef uint8
304typedef unsigned char	uint8;
305#endif
306#endif
307
308#ifndef TYPEDEF_UINT16
309#ifndef uint16
310typedef unsigned short	uint16;
311#endif
312#endif
313
314#ifndef TYPEDEF_UINT32
315#ifndef uint32
316typedef unsigned int	uint32;
317#endif
318#endif
319
320#ifndef TYPEDEF_UINT64
321typedef unsigned long long uint64;
322#endif
323
324#ifndef TYPEDEF_UINTPTR
325typedef unsigned int	uintptr;
326#endif
327
328#ifndef TYPEDEF_INT8
329typedef signed char	int8;
330#endif
331
332#ifndef TYPEDEF_INT16
333typedef signed short	int16;
334#endif
335
336#ifndef TYPEDEF_INT32
337typedef signed int	int32;
338#endif
339
340#ifndef TYPEDEF_INT64
341typedef signed long long int64;
342#endif
343
344/* define float32/64, float_t */
345
346#ifndef TYPEDEF_FLOAT32
347typedef float		float32;
348#endif
349
350#ifndef TYPEDEF_FLOAT64
351typedef double		float64;
352#endif
353
354/*
355 * abstracted floating point type allows for compile time selection of
356 * single or double precision arithmetic.  Compiling with -DFLOAT32
357 * selects single precision; the default is double precision.
358 */
359
360#ifdef MACOSX
361/* float_t types conflict with the same typedefs from the standard ANSI-C
362** math.h header file. Don't re-typedef them here.
363*/
364#define TYPEDEF_FLOAT_T
365#endif /* MACOSX */
366
367#ifndef TYPEDEF_FLOAT_T
368
369#if defined(FLOAT32)
370typedef float32 float_t;
371#else /* default to double precision floating point */
372typedef float64 float_t;
373#endif
374
375#endif /* TYPEDEF_FLOAT_T */
376
377/* define macro values */
378
379#ifndef FALSE
380#define FALSE	0
381#endif
382
383#ifndef TRUE
384#define TRUE	1  /* TRUE */
385#endif
386
387#ifndef NULL
388#define	NULL	0
389#endif
390
391#ifndef OFF
392#define	OFF	0
393#endif
394
395#ifndef ON
396#define	ON	1  /* ON = 1 */
397#endif
398
399#define	AUTO	(-1) /* Auto = -1 */
400
401/* define PTRSZ, INLINE */
402
403#ifndef PTRSZ
404#define	PTRSZ	sizeof(char*)
405#endif
406
407
408/* Detect compiler type. */
409#ifdef _MSC_VER
410	#define BWL_COMPILER_MICROSOFT
411#elif defined(__GNUC__) || defined(__lint)
412	#define BWL_COMPILER_GNU
413#elif defined(__CC_ARM) && __CC_ARM
414	#define BWL_COMPILER_ARMCC
415#else
416	#error "Unknown compiler!"
417#endif /* _MSC_VER */
418
419
420#ifndef INLINE
421	#if defined(BWL_COMPILER_MICROSOFT)
422		#define INLINE __inline
423	#elif defined(BWL_COMPILER_GNU)
424		#define INLINE __inline__
425	#elif defined(BWL_COMPILER_ARMCC)
426		#define INLINE	__inline
427	#else
428		#define INLINE
429	#endif /* _MSC_VER */
430#endif /* INLINE */
431
432#undef TYPEDEF_BOOL
433#undef TYPEDEF_UCHAR
434#undef TYPEDEF_USHORT
435#undef TYPEDEF_UINT
436#undef TYPEDEF_ULONG
437#undef TYPEDEF_UINT8
438#undef TYPEDEF_UINT16
439#undef TYPEDEF_UINT32
440#undef TYPEDEF_UINT64
441#undef TYPEDEF_UINTPTR
442#undef TYPEDEF_INT8
443#undef TYPEDEF_INT16
444#undef TYPEDEF_INT32
445#undef TYPEDEF_INT64
446#undef TYPEDEF_FLOAT32
447#undef TYPEDEF_FLOAT64
448#undef TYPEDEF_FLOAT_T
449
450#endif /* USE_TYPEDEF_DEFAULTS */
451
452/* Suppress unused parameter warning */
453#define UNUSED_PARAMETER(x) (void)(x)
454
455/* Avoid warning for discarded const or volatile qualifier in special cases (-Wcast-qual) */
456#define DISCARD_QUAL(ptr, type) ((type *)(uintptr)(ptr))
457
458/*
459 * Including the bcmdefs.h here, to make sure everyone including typedefs.h
460 * gets this automatically
461*/
462#include <bcmdefs.h>
463#endif /* _TYPEDEFS_H_ */
464