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