rk3288 gpu : update GPU driver r4p0_eac version
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / malisw / arm_cstd / arm_cstd.h
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18
19
20 /**
21  * @addtogroup malisw
22  * @{
23  */
24
25 /* ============================================================================
26     Description
27 ============================================================================ */
28 /**
29  * @defgroup arm_cstd_coding_standard ARM C standard types and constants
30  * The common files are a set of standard headers which are used by all parts
31  * of this development, describing types, and generic constants.
32  *
33  * Files in group:
34  *     - arm_cstd.h
35  *     - arm_cstd_compilers.h
36  *     - arm_cstd_types.h
37  *     - arm_cstd_types_rvct.h
38  *     - arm_cstd_types_gcc.h
39  *     - arm_cstd_types_msvc.h
40  *     - arm_cstd_pack_push.h
41  *     - arm_cstd_pack_pop.h
42  */
43
44 /**
45  * @addtogroup arm_cstd_coding_standard
46  * @{
47  */
48
49 #ifndef _ARM_CSTD_
50 #define _ARM_CSTD_
51
52 /* ============================================================================
53         Import standard C99 types
54 ============================================================================ */
55 #include "arm_cstd_compilers.h"
56 #include "arm_cstd_types.h"
57
58 /* ============================================================================
59         Min and Max Values
60 ============================================================================ */
61 #if !defined(INT8_MAX)
62         #define INT8_MAX                ((int8_t) 0x7F)
63 #endif
64 #if !defined(INT8_MIN)
65         #define INT8_MIN                (-INT8_MAX - 1)
66 #endif
67
68 #if !defined(INT16_MAX)
69         #define INT16_MAX               ((int16_t)0x7FFF)
70 #endif
71 #if !defined(INT16_MIN)
72         #define INT16_MIN               (-INT16_MAX - 1)
73 #endif
74
75 #if !defined(INT32_MAX)
76         #define INT32_MAX               ((int32_t)0x7FFFFFFF)
77 #endif
78 #if !defined(INT32_MIN)
79         #define INT32_MIN               (-INT32_MAX - 1)
80 #endif
81
82 #if !defined(INT64_MAX)
83         #define INT64_MAX               ((int64_t)0x7FFFFFFFFFFFFFFFLL)
84 #endif
85 #if !defined(INT64_MIN)
86         #define INT64_MIN               (-INT64_MAX - 1)
87 #endif
88
89 #if !defined(UINT8_MAX)
90         #define UINT8_MAX               ((uint8_t) 0xFF)
91 #endif
92
93 #if !defined(UINT16_MAX)
94         #define UINT16_MAX              ((uint16_t)0xFFFF)
95 #endif
96
97 #if !defined(UINT32_MAX)
98         #define UINT32_MAX              ((uint32_t)0xFFFFFFFF)
99 #endif
100
101 #if !defined(UINT64_MAX)
102         #define UINT64_MAX              ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
103 #endif
104
105 /* fallbacks if limits.h wasn't available */
106 #if !defined(UCHAR_MAX)
107         #define UCHAR_MAX               ((unsigned char)~0U)
108 #endif
109
110 #if !defined(SCHAR_MAX)
111         #define SCHAR_MAX               ((signed char)(UCHAR_MAX >> 1))
112 #endif
113 #if !defined(SCHAR_MIN)
114         #define SCHAR_MIN               ((signed char)(-SCHAR_MAX - 1))
115 #endif
116
117 #if !defined(USHRT_MAX)
118         #define USHRT_MAX               ((unsigned short)~0U)
119 #endif
120
121 #if !defined(SHRT_MAX)
122         #define SHRT_MAX                ((signed short)(USHRT_MAX >> 1))
123 #endif
124 #if !defined(SHRT_MIN)
125         #define SHRT_MIN                ((signed short)(-SHRT_MAX - 1))
126 #endif
127
128 #if !defined(UINT_MAX)
129         #define UINT_MAX                ((unsigned int)~0U)
130 #endif
131
132 #if !defined(INT_MAX)
133         #define INT_MAX                 ((signed int)(UINT_MAX >> 1))
134 #endif
135 #if !defined(INT_MIN)
136         #define INT_MIN                 ((signed int)(-INT_MAX - 1))
137 #endif
138
139 #if !defined(ULONG_MAX)
140         #define ULONG_MAX               ((unsigned long)~0UL)
141 #endif
142
143 #if !defined(LONG_MAX)
144         #define LONG_MAX                ((signed long)(ULONG_MAX >> 1))
145 #endif
146 #if !defined(LONG_MIN)
147         #define LONG_MIN                ((signed long)(-LONG_MAX - 1))
148 #endif
149
150 #if !defined(ULLONG_MAX)
151         #define ULLONG_MAX              ((unsigned long long)~0ULL)
152 #endif
153
154 #if !defined(LLONG_MAX)
155         #define LLONG_MAX               ((signed long long)(ULLONG_MAX >> 1))
156 #endif
157 #if !defined(LLONG_MIN)
158         #define LLONG_MIN               ((signed long long)(-LLONG_MAX - 1))
159 #endif
160
161 #if !defined(SIZE_MAX)
162         #if 1 == CSTD_CPU_32BIT
163                 #define SIZE_MAX            UINT32_MAX
164         #elif 1 == CSTD_CPU_64BIT
165                 #define SIZE_MAX            UINT64_MAX
166         #endif
167 #endif
168
169 /* ============================================================================
170         Keywords
171 ============================================================================ */
172 /* Portable keywords. */
173
174 #if !defined(CONST)
175 /**
176  * @hideinitializer
177  * Variable is a C @c const, which can be made non-const for testing purposes.
178  */
179         #define CONST                   const
180 #endif
181
182 #if !defined(STATIC)
183 /**
184  * @hideinitializer
185  * Variable is a C @c static, which can be made non-static for testing
186  * purposes.
187  */
188         #define STATIC                  static
189 #endif
190
191 /**
192  * Specifies a function as being exported outside of a logical module.
193  */
194 #define PUBLIC
195
196 /**
197  * @def PROTECTED
198  * Specifies a a function which is internal to an logical module, but which
199  * should not be used outside of that module. This cannot be enforced by the
200  * compiler, as a module is typically more than one translation unit.
201  */
202 #define PROTECTED
203
204 /**
205  * Specifies a function as being internal to a translation unit. Private
206  * functions would typically be declared as STATIC, unless they are being
207  * exported for unit test purposes.
208  */
209 #define PRIVATE STATIC
210
211 /**
212  * Specify an assertion value which is evaluated at compile time. Recommended
213  * usage is specification of a @c static @c INLINE function containing all of
214  * the assertions thus:
215  *
216  * @code
217  * static INLINE [module]_compile_time_assertions( void )
218  * {
219  *     COMPILE_TIME_ASSERT( sizeof(uintptr_t) == sizeof(intptr_t) );
220  * }
221  * @endcode
222  *
223  * @note Use @c static not @c STATIC. We never want to turn off this @c static
224  * specification for testing purposes.
225  */
226 #define CSTD_COMPILE_TIME_ASSERT( expr ) \
227         do { switch(0){case 0: case (expr):;} } while( FALSE )
228
229 /**
230  * @hideinitializer
231  * @deprecated Prefered form is @c CSTD_UNUSED
232  * Function-like macro for suppressing unused variable warnings. Where possible
233  * such variables should be removed; this macro is present for cases where we
234  * much support API backwards compatibility.
235  */
236 #define UNUSED( x )                 ((void)(x))
237
238 /**
239  * @hideinitializer
240  * Function-like macro for suppressing unused variable warnings. Where possible
241  * such variables should be removed; this macro is present for cases where we
242  * much support API backwards compatibility.
243  */
244 #define CSTD_UNUSED( x )            ((void)(x))
245
246 /**
247  * @hideinitializer
248  * Function-like macro for use where "no behavior" is desired. This is useful
249  * when compile time macros turn a function-like macro in to a no-op, but
250  * where having no statement is otherwise invalid.
251  */
252 #define CSTD_NOP( ... )             ((void)#__VA_ARGS__)
253
254 /**
255  * @hideinitializer
256  * Function-like macro for converting a pointer in to a u64 for storing into
257  * an external data structure. This is commonly used when pairing a 32-bit
258  * CPU with a 64-bit peripheral, such as a Midgard GPU. C's type promotion
259  * is complex and a straight cast does not work reliably as pointers are
260  * often considered as signed.
261  */
262 #define CSTD_PTR_TO_U64( x )        ((uint64_t)((uintptr_t)(x)))
263
264 /**
265  * @hideinitializer
266  * Function-like macro for stringizing a single level macro.
267  * @code
268  * #define MY_MACRO 32
269  * CSTD_STR1( MY_MACRO )
270  * > "MY_MACRO"
271  * @endcode
272  */
273 #define CSTD_STR1( x )             #x
274
275 /**
276  * @hideinitializer
277  * Function-like macro for stringizing a macro's value. This should not be used
278  * if the macro is defined in a way which may have no value; use the
279  * alternative @c CSTD_STR2N macro should be used instead.
280  * @code
281  * #define MY_MACRO 32
282  * CSTD_STR2( MY_MACRO )
283  * > "32"
284  * @endcode
285  */
286 #define CSTD_STR2( x )              CSTD_STR1( x )
287
288 /**
289  * @hideinitializer
290  * Utility function for stripping the first character off a string.
291  */
292 static INLINE char* arm_cstd_strstrip( char * string )
293 {
294         return ++string;
295 }
296
297 /**
298  * @hideinitializer
299  * Function-like macro for stringizing a single level macro where the macro
300  * itself may not have a value. Parameter @c a should be set to any single
301  * character which is then stripped by the macro via an inline function. This
302  * should only be used via the @c CSTD_STR2N macro; for printing a single
303  * macro only the @c CSTD_STR1 macro is a better alternative.
304  *
305  * This macro requires run-time code to handle the case where the macro has
306  * no value (you can't concat empty strings in the preprocessor).
307  */
308 #define CSTD_STR1N( a, x )          arm_cstd_strstrip( CSTD_STR1( a##x ) )
309
310 /**
311  * @hideinitializer
312  * Function-like macro for stringizing a two level macro where the macro itself
313  * may not have a value.
314  * @code
315  * #define MY_MACRO 32
316  * CSTD_STR2N( MY_MACRO )
317  * > "32"
318  *
319  * #define MY_MACRO 32
320  * CSTD_STR2N( MY_MACRO )
321  * > "32"
322  * @endcode
323  */
324 #define CSTD_STR2N( x )              CSTD_STR1N( _, x )
325
326 /* ============================================================================
327         Validate portability constructs
328 ============================================================================ */
329 static INLINE void arm_cstd_compile_time_assertions( void )
330 {
331         CSTD_COMPILE_TIME_ASSERT( sizeof(uint8_t)  == 1 );
332         CSTD_COMPILE_TIME_ASSERT( sizeof(int8_t)   == 1 );
333         CSTD_COMPILE_TIME_ASSERT( sizeof(uint16_t) == 2 );
334         CSTD_COMPILE_TIME_ASSERT( sizeof(int16_t)  == 2 );
335         CSTD_COMPILE_TIME_ASSERT( sizeof(uint32_t) == 4 );
336         CSTD_COMPILE_TIME_ASSERT( sizeof(int32_t)  == 4 );
337         CSTD_COMPILE_TIME_ASSERT( sizeof(uint64_t) == 8 );
338         CSTD_COMPILE_TIME_ASSERT( sizeof(int64_t)  == 8 );
339         CSTD_COMPILE_TIME_ASSERT( sizeof(intptr_t) == sizeof(uintptr_t) );
340
341         CSTD_COMPILE_TIME_ASSERT( 1 == TRUE );
342         CSTD_COMPILE_TIME_ASSERT( 0 == FALSE );
343
344 #if 1 == CSTD_CPU_32BIT
345         CSTD_COMPILE_TIME_ASSERT( sizeof(uintptr_t) == 4 );
346 #elif 1 == CSTD_CPU_64BIT
347         CSTD_COMPILE_TIME_ASSERT( sizeof(uintptr_t) == 8 );
348 #endif
349
350 }
351
352 /* ============================================================================
353         Useful function-like macro
354 ============================================================================ */
355 /**
356  * @brief Return the lesser of two values.
357  * As a macro it may evaluate its arguments more than once.
358  * @see CSTD_MAX
359  */
360 #define CSTD_MIN( x, y )            ((x) < (y) ? (x) : (y))
361
362 /**
363  * @brief Return the greater of two values.
364  * As a macro it may evaluate its arguments more than once.
365  * If called on the same two arguments as CSTD_MIN it is guaranteed to return
366  * the one that CSTD_MIN didn't return. This is significant for types where not
367  * all values are comparable e.g. NaNs in floating-point types. But if you want
368  * to retrieve the min and max of two values, consider using a conditional swap
369  * instead.
370  */
371 #define CSTD_MAX( x, y )            ((x) < (y) ? (y) : (x))
372
373 /**
374  * @brief Clamp value @c x to within @c min and @c max inclusive.
375  */
376 #define CSTD_CLAMP( x, min, max )   ((x)<(min) ? (min):((x)>(max) ? (max):(x)))
377
378 /**
379  * Flag a cast as a reinterpretation, usually of a pointer type.
380  */
381 #define CSTD_REINTERPRET_CAST(type) (type)
382
383 /**
384  * Flag a cast as casting away const, usually of a pointer type.
385  */
386 #define CSTD_CONST_CAST(type)       (type)
387
388 /**
389  * Flag a cast as a (potentially complex) value conversion, usually of a
390  * numerical type.
391  */
392 #define CSTD_STATIC_CAST(type)      (type)
393
394 /* ============================================================================
395         Useful bit constants
396 ============================================================================ */
397 /**
398  * @cond arm_cstd_utilities
399  */
400
401 /* Common bit constant values, useful in embedded programming. */
402 #define F_BIT_0       ((uint32_t)0x00000001)
403 #define F_BIT_1       ((uint32_t)0x00000002)
404 #define F_BIT_2       ((uint32_t)0x00000004)
405 #define F_BIT_3       ((uint32_t)0x00000008)
406 #define F_BIT_4       ((uint32_t)0x00000010)
407 #define F_BIT_5       ((uint32_t)0x00000020)
408 #define F_BIT_6       ((uint32_t)0x00000040)
409 #define F_BIT_7       ((uint32_t)0x00000080)
410 #define F_BIT_8       ((uint32_t)0x00000100)
411 #define F_BIT_9       ((uint32_t)0x00000200)
412 #define F_BIT_10      ((uint32_t)0x00000400)
413 #define F_BIT_11      ((uint32_t)0x00000800)
414 #define F_BIT_12      ((uint32_t)0x00001000)
415 #define F_BIT_13      ((uint32_t)0x00002000)
416 #define F_BIT_14      ((uint32_t)0x00004000)
417 #define F_BIT_15      ((uint32_t)0x00008000)
418 #define F_BIT_16      ((uint32_t)0x00010000)
419 #define F_BIT_17      ((uint32_t)0x00020000)
420 #define F_BIT_18      ((uint32_t)0x00040000)
421 #define F_BIT_19      ((uint32_t)0x00080000)
422 #define F_BIT_20      ((uint32_t)0x00100000)
423 #define F_BIT_21      ((uint32_t)0x00200000)
424 #define F_BIT_22      ((uint32_t)0x00400000)
425 #define F_BIT_23      ((uint32_t)0x00800000)
426 #define F_BIT_24      ((uint32_t)0x01000000)
427 #define F_BIT_25      ((uint32_t)0x02000000)
428 #define F_BIT_26      ((uint32_t)0x04000000)
429 #define F_BIT_27      ((uint32_t)0x08000000)
430 #define F_BIT_28      ((uint32_t)0x10000000)
431 #define F_BIT_29      ((uint32_t)0x20000000)
432 #define F_BIT_30      ((uint32_t)0x40000000)
433 #define F_BIT_31      ((uint32_t)0x80000000)
434
435 /* Common 2^n size values, useful in embedded programming. */
436 #define C_SIZE_1B     ((uint32_t)0x00000001)
437 #define C_SIZE_2B     ((uint32_t)0x00000002)
438 #define C_SIZE_4B     ((uint32_t)0x00000004)
439 #define C_SIZE_8B     ((uint32_t)0x00000008)
440 #define C_SIZE_16B    ((uint32_t)0x00000010)
441 #define C_SIZE_32B    ((uint32_t)0x00000020)
442 #define C_SIZE_64B    ((uint32_t)0x00000040)
443 #define C_SIZE_128B   ((uint32_t)0x00000080)
444 #define C_SIZE_256B   ((uint32_t)0x00000100)
445 #define C_SIZE_512B   ((uint32_t)0x00000200)
446 #define C_SIZE_1KB    ((uint32_t)0x00000400)
447 #define C_SIZE_2KB    ((uint32_t)0x00000800)
448 #define C_SIZE_4KB    ((uint32_t)0x00001000)
449 #define C_SIZE_8KB    ((uint32_t)0x00002000)
450 #define C_SIZE_16KB   ((uint32_t)0x00004000)
451 #define C_SIZE_32KB   ((uint32_t)0x00008000)
452 #define C_SIZE_64KB   ((uint32_t)0x00010000)
453 #define C_SIZE_128KB  ((uint32_t)0x00020000)
454 #define C_SIZE_256KB  ((uint32_t)0x00040000)
455 #define C_SIZE_512KB  ((uint32_t)0x00080000)
456 #define C_SIZE_1MB    ((uint32_t)0x00100000)
457 #define C_SIZE_2MB    ((uint32_t)0x00200000)
458 #define C_SIZE_4MB    ((uint32_t)0x00400000)
459 #define C_SIZE_8MB    ((uint32_t)0x00800000)
460 #define C_SIZE_16MB   ((uint32_t)0x01000000)
461 #define C_SIZE_32MB   ((uint32_t)0x02000000)
462 #define C_SIZE_64MB   ((uint32_t)0x04000000)
463 #define C_SIZE_128MB  ((uint32_t)0x08000000)
464 #define C_SIZE_256MB  ((uint32_t)0x10000000)
465 #define C_SIZE_512MB  ((uint32_t)0x20000000)
466 #define C_SIZE_1GB    ((uint32_t)0x40000000)
467 #define C_SIZE_2GB    ((uint32_t)0x80000000)
468
469 /**
470  * @endcond
471  */
472
473 /**
474  * @}
475  */
476
477 /**
478  * @}
479  */
480
481 #endif  /* End (_ARM_CSTD_) */