1 /*
2  * Copyright 2014-2017 Cavium, Inc.
3  * The contents of this file are subject to the terms of the Common Development
4  * and Distribution License, v.1,  (the "License").
5  *
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the License at available
9  * at http://opensource.org/licenses/CDDL-1.0
10  *
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 #ifndef __bcmtype_h__
16 #define __bcmtype_h__
17 
18 #if defined(UEFI) && defined (EVEREST_DIAG)
19 #include <machine/endian.h>
20 #endif
21 
22 #ifndef IN
23 #define IN
24 #endif /* IN */
25 
26 #ifndef OUT
27 #define OUT
28 #endif /* OUT */
29 
30 #ifndef INOUT
31 #define INOUT
32 #endif /* INOUT */
33 
34 #ifndef OPTIONAL
35 #define OPTIONAL
36 #endif /* OPTIONAL */
37 
38 #if defined(__LINUX) || defined (USER_LINUX)
39 
40 #ifdef __LINUX
41 
42 #ifdef __BIG_ENDIAN
43 #ifndef BIG_ENDIAN
44 #define BIG_ENDIAN
45 #endif
46 #else /* __LITTLE_ENDIAN */
47 #ifndef LITTLE_ENDIAN
48 #define LITTLE_ENDIAN
49 #endif
50 #endif
51 
52 /*
53  * define underscore-t types
54  */
55 typedef u64 u64_t;
56 typedef u32 u32_t;
57 typedef u16 u16_t;
58 typedef u8  u8_t;
59 
60 typedef s64 s64_t;
61 typedef s32 s32_t;
62 typedef s16 s16_t;
63 typedef s8  s8_t;
64 
65 typedef unsigned long int_ptr_t;
66 
67 #else /* USER_LINUX */
68 
69 #if __BYTE_ORDER == __LITTLE_ENDIAN
70 #undef BIG_ENDIAN
71 #undef __BIG_ENDIAN
72 #else
73 #undef LITTLE_ENDIAN
74 #undef __LITTLE_ENDIAN
75 #endif
76 
77 /*
78  * define underscore-t types
79  */
80 typedef u_int64_t u64_t;
81 typedef u_int32_t u32_t;
82 typedef u_int16_t u16_t;
83 typedef u_int8_t  u8_t;
84 
85 typedef int64_t s64_t;
86 typedef int32_t s32_t;
87 typedef int16_t s16_t;
88 typedef int8_t  s8_t;
89 
90 typedef u_int64_t u64;
91 typedef u_int32_t u32;
92 typedef u_int16_t u16;
93 typedef u_int8_t  u8;
94 
95 typedef int64_t s64;
96 typedef int32_t s32;
97 typedef int16_t s16;
98 typedef int8_t  s8;
99 
100 typedef unsigned long int_ptr_t;
101 
102 /* Define upper case types */
103 
104 typedef u64_t 	U64;
105 typedef u32_t 	U32;
106 typedef u16_t 	U16;
107 typedef u8_t  	U8;
108 
109 typedef s64_t	S64;
110 typedef s32_t	S32;
111 typedef s16_t	S16;
112 typedef s8_t	S8;
113 
114 #endif
115 
116 
117 
118 #else
119 /*
120  * define the data model
121  */
122 #if !defined(LP64) && !defined(P64) && !defined(LLP64)
123   /* VC 32-bit compiler 5.0 or later */
124   #if (defined(_MSC_VER) && (_MSC_VER > 800)) || defined(TARGET_WINDOWS)
125     #define P64
126   #elif defined(__sun)
127     /* Solaris */
128     #define LP64
129   #elif defined(_HPUX_SOURCE)
130     /* HP/UX */
131     #define LP64
132   #elif defined(__FreeBSD__)
133     /* FreeBSD */
134     #define LP64
135   #elif defined(LINUX)
136     /* Linux */
137     #define LP64
138   #elif defined(__bsdi__)
139     /* BSDI */
140     #define LP64
141   #elif defined(_IRIX)
142     /* IRIX */
143     #define LP64
144   #elif defined(UNIXWARE)
145     /* UnixWare */
146     #define LP64
147   #endif /* UNIXWARE */
148 #endif /* !LP64 && !P64 && !LLP64 */
149 
150 /*
151  * define sized type
152  */
153 #if defined(P64) || defined(LLP64)
154   /* P64 */
155   typedef unsigned __int64    U64;
156   typedef unsigned int        U32;
157   typedef unsigned short      U16;
158   typedef unsigned char       U8;
159   typedef signed __int64      S64;
160   typedef signed int          S32;
161   typedef signed short        S16;
162   typedef signed char         S8;
163 
164   #if defined(IA64)  || defined(AMD64)
165         typedef U64  int_ptr_t;
166   #else
167     #ifndef UEFI64
168         typedef unsigned long       int_ptr_t;
169     #endif
170   #endif
171 #elif defined(LP64)
172   /* LP64: Sun, HP and etc */
173   typedef unsigned long long  U64;
174   typedef unsigned int        U32;
175   typedef unsigned short      U16;
176   typedef unsigned char       U8;
177   typedef signed long long    S64;
178   typedef signed int          S32;
179   typedef signed short        S16;
180   typedef signed char         S8;
181   typedef unsigned long       int_ptr_t;
182 #elif defined(__WATCOMC__)
183   typedef unsigned __int64    U64;
184   typedef unsigned long       U32;
185   typedef unsigned short      U16;
186   typedef unsigned char       U8;
187   typedef signed __int64      S64;
188   typedef signed long         S32;
189   typedef signed short        S16;
190   typedef signed char         S8;
191   typedef unsigned long       int_ptr_t;
192 #else
193   /* assume others: 16-bit */
194   typedef unsigned char       U64[8];
195   typedef unsigned long       U32;
196   typedef unsigned short      U16;
197   typedef unsigned char       U8;
198   typedef signed char         S64[8];
199   typedef signed long         S32;
200   typedef signed short        S16;
201   typedef signed char         S8;
202   typedef unsigned long       int_ptr_t;
203 #endif /*  */
204 
205 
206 
207 /*
208  * define lower case types
209  */
210 typedef U64 u64_t;
211 typedef U32 u32_t;
212 typedef U16 u16_t;
213 typedef U8  u8_t;
214 
215 typedef S64 s64_t;
216 typedef S32 s32_t;
217 typedef S16 s16_t;
218 typedef S8  s8_t;
219 
220 #ifndef LINUX
221 typedef U64 u64;
222 typedef U32 u32;
223 typedef U16 u16;
224 typedef U8  u8;
225 
226 typedef S64 s64;
227 typedef S32 s32;
228 typedef S16 s16;
229 typedef S8  s8;
230 #endif
231 
232 #endif
233 
234 #ifdef UEFI
235 #if BYTE_ORDER == LITTLE_ENDIAN
236 #undef BIG_ENDIAN
237 #endif
238 #ifdef UEFI64
239 typedef u64_t  int_ptr_t;
240 #endif
241 #endif
242 
243 #ifdef LITTLE_ENDIAN
244 #ifndef __LITTLE_ENDIAN
245 #define __LITTLE_ENDIAN LITTLE_ENDIAN
246 #endif /* __LITTLE_ENDIAN */
247 #endif /* LITTLE_ENDIAN */
248 
249 #ifdef BIG_ENDIAN
250 #ifndef __BIG_ENDIAN
251 #define  __BIG_ENDIAN  BIG_ENDIAN
252 #endif /* __BIG_ENDIAN */
253 #endif /* BIG_ENDIAN */
254 
255 #ifdef __FreeBSD__
256 #if _BYTE_ORDER == _LITTLE_ENDIAN
257 #undef BIG_ENDIAN
258 #undef __BIG_ENDIAN
259 #else
260 #undef LITTLE_ENDIAN
261 #undef __LITTLE_ENDIAN
262 #endif
263 #endif /* __FreeBSD__ */
264 
265 /* Signed subtraction macros with no sign extending.  */
266 #define S64_SUB(_a, _b)     ((s64_t) ((s64_t) (_a) - (s64_t) (_b)))
267 #define u64_SUB(_a, _b)     ((u64_t) ((s64_t) (_a) - (s64_t) (_b)))
268 #define S32_SUB(_a, _b)     ((s32_t) ((s32_t) (_a) - (s32_t) (_b)))
269 #define uS32_SUB(_a, _b)    ((u32_t) ((s32_t) (_a) - (s32_t) (_b)))
270 #define S16_SUB(_a, _b)     ((s16_t) ((s16_t) (_a) - (s16_t) (_b)))
271 #define u16_SUB(_a, _b)     ((u16_t) ((s16_t) (_a) - (s16_t) (_b)))
272 #define PTR_SUB(_a, _b)     ((u8_t *) (_a) - (u8_t *) (_b))
273 
274 #if (!defined LINUX ) && (!defined MFW)
275 #define __builtin_offsetof(path1_nvm_image_t, f) (u32_t)((int_ptr_t)(&(((path1_nvm_image_t *)0)->f)))
276 #endif
277 
278 #endif/* __bcmtype_h__ */
279 
280