]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_types.h
ENGR00294115 PXP: correct the pxp_dispatch thread exit logic
[karo-tx-linux.git] / drivers / mxc / gpu-viv / hal / kernel / inc / gc_hal_types.h
1 /****************************************************************************
2 *
3 *    Copyright (C) 2005 - 2013 by Vivante Corp.
4 *
5 *    This program is free software; you can redistribute it and/or modify
6 *    it under the terms of the GNU General Public License as published by
7 *    the Free Software Foundation; either version 2 of the license, or
8 *    (at your option) any later version.
9 *
10 *    This program is distributed in the hope that it will be useful,
11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *    GNU General Public License for more details.
14 *
15 *    You should have received a copy of the GNU General Public License
16 *    along with this program; if not write to the Free Software
17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *****************************************************************************/
20
21
22 #ifndef __gc_hal_types_h_
23 #define __gc_hal_types_h_
24
25 #include "gc_hal_version.h"
26 #include "gc_hal_options.h"
27
28 #ifdef _WIN32
29 #pragma warning(disable:4127)   /* Conditional expression is constant (do { }
30                                 ** while(0)). */
31 #pragma warning(disable:4100)   /* Unreferenced formal parameter. */
32 #pragma warning(disable:4204)   /* Non-constant aggregate initializer (C99). */
33 #pragma warning(disable:4131)   /* Uses old-style declarator (for Bison and
34                                 ** Flex generated files). */
35 #pragma warning(disable:4206)   /* Translation unit is empty. */
36 #endif
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /******************************************************************************\
43 **  Platform macros.
44 */
45
46 #if defined(__GNUC__)
47 #   define gcdHAS_ELLIPSES      1       /* GCC always has it. */
48 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
49 #   define gcdHAS_ELLIPSES      1       /* C99 has it. */
50 #elif defined(_MSC_VER) && (_MSC_VER >= 1500)
51 #   define gcdHAS_ELLIPSES      1       /* MSVC 2007+ has it. */
52 #elif defined(UNDER_CE)
53 #if UNDER_CE >= 600
54 #       define gcdHAS_ELLIPSES  1
55 #   else
56 #       define gcdHAS_ELLIPSES  0
57 #   endif
58 #else
59 #   error "gcdHAS_ELLIPSES: Platform could not be determined"
60 #endif
61
62 /******************************************************************************\
63 ************************************ Keyword ***********************************
64 \******************************************************************************/
65
66 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
67 #   define gcmINLINE            inline      /* C99 keyword. */
68 #elif defined(__GNUC__)
69 #   define gcmINLINE            __inline__  /* GNU keyword. */
70 #elif defined(_MSC_VER) || defined(UNDER_CE)
71 #   define gcmINLINE            __inline    /* Internal keyword. */
72 #else
73 #   error "gcmINLINE: Platform could not be determined"
74 #endif
75
76 /* Possible debug flags. */
77 #define gcdDEBUG_NONE           0
78 #define gcdDEBUG_ALL            (1 << 0)
79 #define gcdDEBUG_FATAL          (1 << 1)
80 #define gcdDEBUG_TRACE          (1 << 2)
81 #define gcdDEBUG_BREAK          (1 << 3)
82 #define gcdDEBUG_ASSERT         (1 << 4)
83 #define gcdDEBUG_CODE           (1 << 5)
84 #define gcdDEBUG_STACK          (1 << 6)
85
86 #define gcmIS_DEBUG(flag)       ( gcdDEBUG & (flag | gcdDEBUG_ALL) )
87
88 #ifndef gcdDEBUG
89 #if (defined(DBG) && DBG) || defined(DEBUG) || defined(_DEBUG)
90 #       define gcdDEBUG         gcdDEBUG_ALL
91 #   else
92 #       define gcdDEBUG         gcdDEBUG_NONE
93 #   endif
94 #endif
95
96 #ifdef _USRDLL
97 #ifdef _MSC_VER
98 #ifdef HAL_EXPORTS
99 #           define HALAPI       __declspec(dllexport)
100 #       else
101 #           define HALAPI       __declspec(dllimport)
102 #       endif
103 #       define HALDECL          __cdecl
104 #   else
105 #ifdef HAL_EXPORTS
106 #           define HALAPI
107 #       else
108 #           define HALAPI       extern
109 #       endif
110 #   endif
111 #else
112 #   define HALAPI
113 #   define HALDECL
114 #endif
115
116 /******************************************************************************\
117 ********************************** Common Types ********************************
118 \******************************************************************************/
119
120 #define gcvFALSE                0
121 #define gcvTRUE                 1
122
123 #define gcvINFINITE             ((gctUINT32) ~0U)
124
125 #define gcvINVALID_HANDLE       ((gctHANDLE) ~0U)
126
127 typedef int                     gctBOOL;
128 typedef gctBOOL *               gctBOOL_PTR;
129
130 typedef int                     gctINT;
131 typedef long                    gctLONG;
132 typedef signed char             gctINT8;
133 typedef signed short            gctINT16;
134 typedef signed int              gctINT32;
135 typedef signed long long        gctINT64;
136
137 typedef gctINT *                gctINT_PTR;
138 typedef gctINT8 *               gctINT8_PTR;
139 typedef gctINT16 *              gctINT16_PTR;
140 typedef gctINT32 *              gctINT32_PTR;
141 typedef gctINT64 *              gctINT64_PTR;
142
143 typedef unsigned int            gctUINT;
144 typedef unsigned char           gctUINT8;
145 typedef unsigned short          gctUINT16;
146 typedef unsigned int            gctUINT32;
147 typedef unsigned long long      gctUINT64;
148 typedef unsigned long           gctUINTPTR_T;
149
150 typedef gctUINT *               gctUINT_PTR;
151 typedef gctUINT8 *              gctUINT8_PTR;
152 typedef gctUINT16 *             gctUINT16_PTR;
153 typedef gctUINT32 *             gctUINT32_PTR;
154 typedef gctUINT64 *             gctUINT64_PTR;
155
156 typedef unsigned long           gctSIZE_T;
157 typedef gctSIZE_T *             gctSIZE_T_PTR;
158
159 #ifdef __cplusplus
160 #   define gcvNULL              0
161 #else
162 #   define gcvNULL              ((void *) 0)
163 #endif
164
165 typedef float                   gctFLOAT;
166 typedef signed int              gctFIXED_POINT;
167 typedef float *                 gctFLOAT_PTR;
168
169 typedef void *                  gctPHYS_ADDR;
170 typedef void *                  gctHANDLE;
171 typedef void *                  gctFILE;
172 typedef void *                  gctSIGNAL;
173 typedef void *                  gctWINDOW;
174 typedef void *                  gctIMAGE;
175 typedef void *                  gctSYNC_POINT;
176
177 typedef void *                                  gctSEMAPHORE;
178
179 typedef void *                  gctPOINTER;
180 typedef const void *            gctCONST_POINTER;
181
182 typedef char                    gctCHAR;
183 typedef char *                  gctSTRING;
184 typedef const char *            gctCONST_STRING;
185
186 typedef struct _gcsCOUNT_STRING
187 {
188     gctSIZE_T                   Length;
189     gctCONST_STRING             String;
190 }
191 gcsCOUNT_STRING;
192
193 typedef union _gcuFLOAT_UINT32
194 {
195     gctFLOAT    f;
196     gctUINT32   u;
197 }
198 gcuFLOAT_UINT32;
199
200 /* Fixed point constants. */
201 #define gcvZERO_X               ((gctFIXED_POINT) 0x00000000)
202 #define gcvHALF_X               ((gctFIXED_POINT) 0x00008000)
203 #define gcvONE_X                ((gctFIXED_POINT) 0x00010000)
204 #define gcvNEGONE_X             ((gctFIXED_POINT) 0xFFFF0000)
205 #define gcvTWO_X                ((gctFIXED_POINT) 0x00020000)
206
207 /* Stringizing macro. */
208 #define gcmSTRING(Value)        #Value
209
210 /******************************************************************************\
211 ******************************* Fixed Point Math *******************************
212 \******************************************************************************/
213
214 #define gcmXMultiply(x1, x2)            gcoMATH_MultiplyFixed(x1, x2)
215 #define gcmXDivide(x1, x2)              gcoMATH_DivideFixed(x1, x2)
216 #define gcmXMultiplyDivide(x1, x2, x3)  gcoMATH_MultiplyDivideFixed(x1, x2, x3)
217
218 /* 2D Engine profile. */
219 typedef struct _gcs2D_PROFILE
220 {
221     /* Cycle count.
222        32bit counter incremented every 2D clock cycle.
223        Wraps back to 0 when the counter overflows.
224     */
225     gctUINT32 cycleCount;
226
227     /* Pixels rendered by the 2D engine.
228        Resets to 0 every time it is read. */
229     gctUINT32 pixelsRendered;
230 }
231 gcs2D_PROFILE;
232
233 /* Macro to combine four characters into a Charcater Code. */
234 #define gcmCC(c1, c2, c3, c4) \
235 ( \
236     (char) (c1) \
237     | \
238     ((char) (c2) <<  8) \
239     | \
240     ((char) (c3) << 16) \
241     | \
242     ((char) (c4) << 24) \
243 )
244
245 #define gcmPRINTABLE(c)         ((((c) >= ' ') && ((c) <= '}')) ? ((c) != '%' ?  (c) : ' ') : ' ')
246
247 #define gcmCC_PRINT(cc) \
248     gcmPRINTABLE((char) ( (cc)        & 0xFF)), \
249     gcmPRINTABLE((char) (((cc) >>  8) & 0xFF)), \
250     gcmPRINTABLE((char) (((cc) >> 16) & 0xFF)), \
251     gcmPRINTABLE((char) (((cc) >> 24) & 0xFF))
252
253 /******************************************************************************\
254 ****************************** Function Parameters *****************************
255 \******************************************************************************/
256
257 #define IN
258 #define OUT
259 #define OPTIONAL
260
261 /******************************************************************************\
262 ********************************* Status Codes *********************************
263 \******************************************************************************/
264
265 typedef enum _gceSTATUS
266 {
267     gcvSTATUS_OK                    =   0,
268     gcvSTATUS_FALSE                 =   0,
269     gcvSTATUS_TRUE                  =   1,
270     gcvSTATUS_NO_MORE_DATA          =   2,
271     gcvSTATUS_CACHED                =   3,
272     gcvSTATUS_MIPMAP_TOO_LARGE      =   4,
273     gcvSTATUS_NAME_NOT_FOUND        =   5,
274     gcvSTATUS_NOT_OUR_INTERRUPT     =   6,
275     gcvSTATUS_MISMATCH              =   7,
276     gcvSTATUS_MIPMAP_TOO_SMALL      =   8,
277     gcvSTATUS_LARGER                =   9,
278     gcvSTATUS_SMALLER               =   10,
279     gcvSTATUS_CHIP_NOT_READY        =   11,
280     gcvSTATUS_NEED_CONVERSION       =   12,
281     gcvSTATUS_SKIP                  =   13,
282     gcvSTATUS_DATA_TOO_LARGE        =   14,
283     gcvSTATUS_INVALID_CONFIG        =   15,
284     gcvSTATUS_CHANGED               =   16,
285     gcvSTATUS_NOT_SUPPORT_DITHER    =   17,
286         gcvSTATUS_EXECUTED                              =       18,
287     gcvSTATUS_TERMINATE             =   19,
288
289     gcvSTATUS_CONVERT_TO_SINGLE_STREAM    =   20,
290
291     gcvSTATUS_INVALID_ARGUMENT      =   -1,
292     gcvSTATUS_INVALID_OBJECT        =   -2,
293     gcvSTATUS_OUT_OF_MEMORY         =   -3,
294     gcvSTATUS_MEMORY_LOCKED         =   -4,
295     gcvSTATUS_MEMORY_UNLOCKED       =   -5,
296     gcvSTATUS_HEAP_CORRUPTED        =   -6,
297     gcvSTATUS_GENERIC_IO            =   -7,
298     gcvSTATUS_INVALID_ADDRESS       =   -8,
299     gcvSTATUS_CONTEXT_LOSSED        =   -9,
300     gcvSTATUS_TOO_COMPLEX           =   -10,
301     gcvSTATUS_BUFFER_TOO_SMALL      =   -11,
302     gcvSTATUS_INTERFACE_ERROR       =   -12,
303     gcvSTATUS_NOT_SUPPORTED         =   -13,
304     gcvSTATUS_MORE_DATA             =   -14,
305     gcvSTATUS_TIMEOUT               =   -15,
306     gcvSTATUS_OUT_OF_RESOURCES      =   -16,
307     gcvSTATUS_INVALID_DATA          =   -17,
308     gcvSTATUS_INVALID_MIPMAP        =   -18,
309     gcvSTATUS_NOT_FOUND             =   -19,
310     gcvSTATUS_NOT_ALIGNED           =   -20,
311     gcvSTATUS_INVALID_REQUEST       =   -21,
312     gcvSTATUS_GPU_NOT_RESPONDING    =   -22,
313     gcvSTATUS_TIMER_OVERFLOW        =   -23,
314     gcvSTATUS_VERSION_MISMATCH      =   -24,
315     gcvSTATUS_LOCKED                =   -25,
316     gcvSTATUS_INTERRUPTED           =   -26,
317     gcvSTATUS_DEVICE                =   -27,
318     gcvSTATUS_NOT_MULTI_PIPE_ALIGNED =   -28,
319
320     /* Linker errors. */
321     gcvSTATUS_GLOBAL_TYPE_MISMATCH  =   -1000,
322     gcvSTATUS_TOO_MANY_ATTRIBUTES   =   -1001,
323     gcvSTATUS_TOO_MANY_UNIFORMS     =   -1002,
324     gcvSTATUS_TOO_MANY_VARYINGS     =   -1003,
325     gcvSTATUS_UNDECLARED_VARYING    =   -1004,
326     gcvSTATUS_VARYING_TYPE_MISMATCH =   -1005,
327     gcvSTATUS_MISSING_MAIN          =   -1006,
328     gcvSTATUS_NAME_MISMATCH         =   -1007,
329     gcvSTATUS_INVALID_INDEX         =   -1008,
330     gcvSTATUS_UNIFORM_TYPE_MISMATCH =   -1009,
331
332     /* Compiler errors. */
333     gcvSTATUS_COMPILER_FE_PREPROCESSOR_ERROR = -2000,
334     gcvSTATUS_COMPILER_FE_PARSER_ERROR = -2001,
335 }
336 gceSTATUS;
337
338 /******************************************************************************\
339 ********************************* Status Macros ********************************
340 \******************************************************************************/
341
342 #define gcmIS_ERROR(status)         (status < 0)
343 #define gcmNO_ERROR(status)         (status >= 0)
344 #define gcmIS_SUCCESS(status)       (status == gcvSTATUS_OK)
345
346 /******************************************************************************\
347 ********************************* Field Macros *********************************
348 \******************************************************************************/
349
350 #define __gcmSTART(reg_field) \
351     (0 ? reg_field)
352
353 #define __gcmEND(reg_field) \
354     (1 ? reg_field)
355
356 #define __gcmGETSIZE(reg_field) \
357     (__gcmEND(reg_field) - __gcmSTART(reg_field) + 1)
358
359 #define __gcmALIGN(data, reg_field) \
360     (((gctUINT32) (data)) << __gcmSTART(reg_field))
361
362 #define __gcmMASK(reg_field) \
363     ((gctUINT32) ((__gcmGETSIZE(reg_field) == 32) \
364         ?  ~0 \
365         : (~(~0 << __gcmGETSIZE(reg_field)))))
366
367 /*******************************************************************************
368 **
369 **  gcmFIELDMASK
370 **
371 **      Get aligned field mask.
372 **
373 **  ARGUMENTS:
374 **
375 **      reg     Name of register.
376 **      field   Name of field within register.
377 */
378 #define gcmFIELDMASK(reg, field) \
379 ( \
380     __gcmALIGN(__gcmMASK(reg##_##field), reg##_##field) \
381 )
382
383 /*******************************************************************************
384 **
385 **  gcmGETFIELD
386 **
387 **      Extract the value of a field from specified data.
388 **
389 **  ARGUMENTS:
390 **
391 **      data    Data value.
392 **      reg     Name of register.
393 **      field   Name of field within register.
394 */
395 #define gcmGETFIELD(data, reg, field) \
396 ( \
397     ((((gctUINT32) (data)) >> __gcmSTART(reg##_##field)) \
398         & __gcmMASK(reg##_##field)) \
399 )
400
401 /*******************************************************************************
402 **
403 **  gcmSETFIELD
404 **
405 **      Set the value of a field within specified data.
406 **
407 **  ARGUMENTS:
408 **
409 **      data    Data value.
410 **      reg     Name of register.
411 **      field   Name of field within register.
412 **      value   Value for field.
413 */
414 #define gcmSETFIELD(data, reg, field, value) \
415 ( \
416     (((gctUINT32) (data)) \
417         & ~__gcmALIGN(__gcmMASK(reg##_##field), reg##_##field)) \
418         |  __gcmALIGN((gctUINT32) (value) \
419             & __gcmMASK(reg##_##field), reg##_##field) \
420 )
421
422 /*******************************************************************************
423 **
424 **  gcmSETFIELDVALUE
425 **
426 **      Set the value of a field within specified data with a
427 **      predefined value.
428 **
429 **  ARGUMENTS:
430 **
431 **      data    Data value.
432 **      reg     Name of register.
433 **      field   Name of field within register.
434 **      value   Name of the value within the field.
435 */
436 #define gcmSETFIELDVALUE(data, reg, field, value) \
437 ( \
438     (((gctUINT32) (data)) \
439         & ~__gcmALIGN(__gcmMASK(reg##_##field), reg##_##field)) \
440         |  __gcmALIGN(reg##_##field##_##value \
441             & __gcmMASK(reg##_##field), reg##_##field) \
442 )
443
444 /*******************************************************************************
445 **
446 **  gcmGETMASKEDFIELDMASK
447 **
448 **      Determine field mask of a masked field.
449 **
450 **  ARGUMENTS:
451 **
452 **      reg     Name of register.
453 **      field   Name of field within register.
454 */
455 #define gcmGETMASKEDFIELDMASK(reg, field) \
456 ( \
457     gcmSETFIELD(0, reg,          field, ~0) | \
458     gcmSETFIELD(0, reg, MASK_ ## field, ~0)   \
459 )
460
461 /*******************************************************************************
462 **
463 **  gcmSETMASKEDFIELD
464 **
465 **      Set the value of a masked field with specified data.
466 **
467 **  ARGUMENTS:
468 **
469 **      reg     Name of register.
470 **      field   Name of field within register.
471 **      value   Value for field.
472 */
473 #define gcmSETMASKEDFIELD(reg, field, value) \
474 ( \
475     gcmSETFIELD     (~0, reg,          field, value) & \
476     gcmSETFIELDVALUE(~0, reg, MASK_ ## field, ENABLED) \
477 )
478
479 /*******************************************************************************
480 **
481 **  gcmSETMASKEDFIELDVALUE
482 **
483 **      Set the value of a masked field with specified data.
484 **
485 **  ARGUMENTS:
486 **
487 **      reg     Name of register.
488 **      field   Name of field within register.
489 **      value   Value for field.
490 */
491 #define gcmSETMASKEDFIELDVALUE(reg, field, value) \
492 ( \
493     gcmSETFIELDVALUE(~0, reg,          field, value) & \
494     gcmSETFIELDVALUE(~0, reg, MASK_ ## field, ENABLED) \
495 )
496
497 /*******************************************************************************
498 **
499 **  gcmVERIFYFIELDVALUE
500 **
501 **      Verify if the value of a field within specified data equals a
502 **      predefined value.
503 **
504 **  ARGUMENTS:
505 **
506 **      data    Data value.
507 **      reg     Name of register.
508 **      field   Name of field within register.
509 **      value   Name of the value within the field.
510 */
511 #define gcmVERIFYFIELDVALUE(data, reg, field, value) \
512 ( \
513     (((gctUINT32) (data)) >> __gcmSTART(reg##_##field) & \
514                              __gcmMASK(reg##_##field)) \
515         == \
516     (reg##_##field##_##value & __gcmMASK(reg##_##field)) \
517 )
518
519 /*******************************************************************************
520 **  Bit field macros.
521 */
522
523 #define __gcmSTARTBIT(Field) \
524     ( 1 ? Field )
525
526 #define __gcmBITSIZE(Field) \
527     ( 0 ? Field )
528
529 #define __gcmBITMASK(Field) \
530 ( \
531     (1 << __gcmBITSIZE(Field)) - 1 \
532 )
533
534 #define gcmGETBITS(Value, Type, Field) \
535 ( \
536     ( ((Type) (Value)) >> __gcmSTARTBIT(Field) ) \
537     & \
538     __gcmBITMASK(Field) \
539 )
540
541 #define gcmSETBITS(Value, Type, Field, NewValue) \
542 ( \
543     ( ((Type) (Value)) \
544     & ~(__gcmBITMASK(Field) << __gcmSTARTBIT(Field)) \
545     ) \
546     | \
547     ( ( ((Type) (NewValue)) \
548       & __gcmBITMASK(Field) \
549       ) << __gcmSTARTBIT(Field) \
550     ) \
551 )
552
553 /*******************************************************************************
554 **
555 **  gcmISINREGRANGE
556 **
557 **      Verify whether the specified address is in the register range.
558 **
559 **  ARGUMENTS:
560 **
561 **      Address Address to be verified.
562 **      Name    Name of a register.
563 */
564
565 #define gcmISINREGRANGE(Address, Name) \
566 ( \
567     ((Address & (~0U << Name ## _LSB)) == (Name ## _Address >> 2)) \
568 )
569
570 /*******************************************************************************
571 **
572 **  A set of macros to aid state loading.
573 **
574 **  ARGUMENTS:
575 **
576 **      CommandBuffer   Pointer to a gcoCMDBUF object.
577 **      StateDelta      Pointer to a gcsSTATE_DELTA state delta structure.
578 **      Memory          Destination memory pointer of gctUINT32_PTR type.
579 **      PartOfContext   Whether or not the state is a part of the context.
580 **      FixedPoint      Whether or not the state is of the fixed point format.
581 **      Count           Number of consecutive states to be loaded.
582 **      Address         State address.
583 **      Data            Data to be set to the state.
584 */
585
586 /*----------------------------------------------------------------------------*/
587
588 #if gcmIS_DEBUG(gcdDEBUG_CODE)
589
590 #   define gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count) \
591         CommandBuffer->lastLoadStatePtr     = gcmPTR_TO_UINT64(Memory); \
592         CommandBuffer->lastLoadStateAddress = Address; \
593         CommandBuffer->lastLoadStateCount   = Count
594
595 #   define gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address) \
596         gcmASSERT( \
597             (gctUINT) (Memory  - gcmUINT64_TO_TYPE(CommandBuffer->lastLoadStatePtr, gctUINT32_PTR) - 1) \
598             == \
599             (gctUINT) (Address - CommandBuffer->lastLoadStateAddress) \
600             ); \
601         \
602         gcmASSERT(CommandBuffer->lastLoadStateCount > 0); \
603         \
604         CommandBuffer->lastLoadStateCount -= 1
605
606 #   define gcmVERIFYLOADSTATEDONE(CommandBuffer) \
607         gcmASSERT(CommandBuffer->lastLoadStateCount == 0)
608
609 #else
610
611 #   define gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count)
612 #   define gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address)
613 #   define gcmVERIFYLOADSTATEDONE(CommandBuffer)
614
615 #endif
616
617 #if gcdSECURE_USER
618
619 #   define gcmDEFINESECUREUSER() \
620         gctUINT         __secure_user_offset__; \
621         gctUINT32_PTR   __secure_user_hintArray__;
622
623 #   define gcmBEGINSECUREUSER() \
624         __secure_user_offset__ = reserve->lastOffset; \
625         \
626         __secure_user_hintArray__ = gcmUINT64_TO_PTR(reserve->hintArrayTail)
627
628 #   define gcmENDSECUREUSER() \
629         reserve->hintArrayTail = gcmPTR_TO_UINT64(__secure_user_hintArray__)
630
631 #   define gcmSKIPSECUREUSER() \
632         __secure_user_offset__ += gcmSIZEOF(gctUINT32)
633
634 #   define gcmUPDATESECUREUSER() \
635         *__secure_user_hintArray__ = __secure_user_offset__; \
636         \
637         __secure_user_offset__    += gcmSIZEOF(gctUINT32); \
638         __secure_user_hintArray__ += 1
639
640 #else
641
642 #   define gcmDEFINESECUREUSER()
643 #   define gcmBEGINSECUREUSER()
644 #   define gcmENDSECUREUSER()
645 #   define gcmSKIPSECUREUSER()
646 #   define gcmUPDATESECUREUSER()
647
648 #endif
649
650 /*----------------------------------------------------------------------------*/
651
652 #if gcdDUMP
653 #   define gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, Data) \
654         if (FixedPoint) \
655         { \
656             gcmDUMP(gcvNULL, "@[state.x 0x%04X 0x%08X]", \
657                 Address, Data \
658                 ); \
659         } \
660         else \
661         { \
662             gcmDUMP(gcvNULL, "@[state 0x%04X 0x%08X]", \
663                 Address, Data \
664                 ); \
665         }
666 #else
667 #   define gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, Data)
668 #endif
669
670 /*----------------------------------------------------------------------------*/
671
672 #define gcmDEFINESTATEBUFFER(CommandBuffer, StateDelta, Memory, ReserveSize) \
673     gcmDEFINESECUREUSER() \
674     gctSIZE_T ReserveSize; \
675     gcoCMDBUF CommandBuffer; \
676     gctUINT32_PTR Memory; \
677     gcsSTATE_DELTA_PTR StateDelta
678
679 #define gcmBEGINSTATEBUFFER(Hardware, CommandBuffer, StateDelta, Memory, ReserveSize) \
680 { \
681     gcmONERROR(gcoBUFFER_Reserve( \
682         Hardware->buffer, ReserveSize, gcvTRUE, &CommandBuffer \
683         )); \
684     \
685     Memory =  gcmUINT64_TO_PTR(CommandBuffer->lastReserve); \
686     \
687     StateDelta = Hardware->delta; \
688     \
689     gcmBEGINSECUREUSER(); \
690 }
691
692 #define gcmENDSTATEBUFFER(CommandBuffer, Memory, ReserveSize) \
693 { \
694     gcmENDSECUREUSER(); \
695     \
696     gcmASSERT( \
697         gcmUINT64_TO_TYPE(CommandBuffer->lastReserve, gctUINT8_PTR) + ReserveSize \
698         == \
699          (gctUINT8_PTR) Memory \
700         ); \
701 }
702
703 /*----------------------------------------------------------------------------*/
704
705 #define gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, Count) \
706 { \
707     gcmASSERT(((Memory - gcmUINT64_TO_TYPE(CommandBuffer->lastReserve, gctUINT32_PTR)) & 1) == 0); \
708     gcmASSERT((gctUINT32)Count <= 1024); \
709     \
710     gcmVERIFYLOADSTATEDONE(CommandBuffer); \
711     \
712     gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count); \
713     \
714     *Memory++ \
715         = gcmSETFIELDVALUE(0, AQ_COMMAND_LOAD_STATE_COMMAND, OPCODE,  LOAD_STATE) \
716         | gcmSETFIELD     (0, AQ_COMMAND_LOAD_STATE_COMMAND, FLOAT,   FixedPoint) \
717         | gcmSETFIELD     (0, AQ_COMMAND_LOAD_STATE_COMMAND, COUNT,   Count) \
718         | gcmSETFIELD     (0, AQ_COMMAND_LOAD_STATE_COMMAND, ADDRESS, Address); \
719     \
720     gcmSKIPSECUREUSER(); \
721 }
722
723 #define gcmENDSTATEBATCH(CommandBuffer, Memory) \
724 { \
725     gcmVERIFYLOADSTATEDONE(CommandBuffer); \
726     \
727     gcmASSERT(((Memory - gcmUINT64_TO_TYPE(CommandBuffer->lastReserve, gctUINT32_PTR)) & 1) == 0); \
728 }
729
730 /*----------------------------------------------------------------------------*/
731
732 #define gcmSETSTATEDATA(StateDelta, CommandBuffer, Memory, FixedPoint, \
733                         Address, Data) \
734 { \
735     gctUINT32 __temp_data32__; \
736     \
737     gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address); \
738     \
739     __temp_data32__ = Data; \
740     \
741     *Memory++ = __temp_data32__; \
742     \
743     gcoHARDWARE_UpdateDelta( \
744         StateDelta, FixedPoint, Address, 0, __temp_data32__ \
745         ); \
746     \
747     gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, __temp_data32__); \
748     \
749     gcmUPDATESECUREUSER(); \
750 }
751
752 #define gcmSETCTRLSTATE(StateDelta, CommandBuffer, Memory, Address, Data) \
753 { \
754     gctUINT32 __temp_data32__; \
755     \
756     gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address); \
757     \
758     __temp_data32__ = Data; \
759     \
760     *Memory++ = __temp_data32__; \
761     \
762     gcmDUMPSTATEDATA(StateDelta, gcvFALSE, Address, __temp_data32__); \
763     \
764     gcmSKIPSECUREUSER(); \
765 }
766
767 #define gcmSETFILLER(CommandBuffer, Memory) \
768 { \
769     gcmVERIFYLOADSTATEDONE(CommandBuffer); \
770     \
771     Memory += 1; \
772     \
773     gcmSKIPSECUREUSER(); \
774 }
775
776 /*----------------------------------------------------------------------------*/
777
778 #define gcmSETSINGLESTATE(StateDelta, CommandBuffer, Memory, FixedPoint, \
779                           Address, Data) \
780 { \
781     gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, 1); \
782     gcmSETSTATEDATA(StateDelta, CommandBuffer, Memory, FixedPoint, \
783                     Address, Data); \
784     gcmENDSTATEBATCH(CommandBuffer, Memory); \
785 }
786
787 #define gcmSETSINGLECTRLSTATE(StateDelta, CommandBuffer, Memory, FixedPoint, \
788                               Address, Data) \
789 { \
790     gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, 1); \
791     gcmSETCTRLSTATE(StateDelta, CommandBuffer, Memory, Address, Data); \
792     gcmENDSTATEBATCH(CommandBuffer, Memory); \
793 }
794
795
796 /*******************************************************************************
797 **
798 **  gcmSETSTARTDECOMMAND
799 **
800 **      Form a START_DE command.
801 **
802 **  ARGUMENTS:
803 **
804 **      Memory          Destination memory pointer of gctUINT32_PTR type.
805 **      Count           Number of the rectangles.
806 */
807
808 #define gcmSETSTARTDECOMMAND(Memory, Count) \
809 { \
810     *Memory++ \
811         = gcmSETFIELDVALUE(0, AQ_COMMAND_START_DE_COMMAND, OPCODE,     START_DE) \
812         | gcmSETFIELD     (0, AQ_COMMAND_START_DE_COMMAND, COUNT,      Count) \
813         | gcmSETFIELD     (0, AQ_COMMAND_START_DE_COMMAND, DATA_COUNT, 0); \
814     \
815     *Memory++ = 0xDEADDEED; \
816 }
817
818 /******************************************************************************\
819 ******************************** Ceiling Macro ********************************
820 \******************************************************************************/
821 #define gcmCEIL(x) ((x - (gctUINT32)x) == 0 ? (gctUINT32)x : (gctUINT32)x + 1)
822
823 /******************************************************************************\
824 ******************************** Min/Max Macros ********************************
825 \******************************************************************************/
826
827 #define gcmMIN(x, y)            (((x) <= (y)) ?  (x) :  (y))
828 #define gcmMAX(x, y)            (((x) >= (y)) ?  (x) :  (y))
829 #define gcmCLAMP(x, min, max)   (((x) < (min)) ? (min) : \
830                                  ((x) > (max)) ? (max) : (x))
831 #define gcmABS(x)               (((x) < 0)    ? -(x) :  (x))
832 #define gcmNEG(x)               (((x) < 0)    ?  (x) : -(x))
833
834 /*******************************************************************************
835 **
836 **  gcmPTR2INT
837 **
838 **      Convert a pointer to an integer value.
839 **
840 **  ARGUMENTS:
841 **
842 **      p       Pointer value.
843 */
844 #if defined(_WIN32) || (defined(__LP64__) && __LP64__)
845 #   define gcmPTR2INT(p) \
846     ( \
847         (gctUINT32) (gctUINT64) (p) \
848     )
849 #else
850 #   define gcmPTR2INT(p) \
851     ( \
852         (gctUINT32) (p) \
853     )
854 #endif
855
856 /*******************************************************************************
857 **
858 **  gcmINT2PTR
859 **
860 **      Convert an integer value into a pointer.
861 **
862 **  ARGUMENTS:
863 **
864 **      v       Integer value.
865 */
866 #ifdef __LP64__
867 #   define gcmINT2PTR(i) \
868     ( \
869         (gctPOINTER) (gctINT64) (i) \
870     )
871 #else
872 #   define gcmINT2PTR(i) \
873     ( \
874         (gctPOINTER) (i) \
875     )
876 #endif
877
878 /*******************************************************************************
879 **
880 **  gcmOFFSETOF
881 **
882 **      Compute the byte offset of a field inside a structure.
883 **
884 **  ARGUMENTS:
885 **
886 **      s       Structure name.
887 **      field   Field name.
888 */
889 #define gcmOFFSETOF(s, field) \
890 ( \
891     gcmPTR2INT(& (((struct s *) 0)->field)) \
892 )
893
894 #define gcmSWAB32(x) ((gctUINT32)( \
895         (((gctUINT32)(x) & (gctUINT32)0x000000FFUL) << 24) | \
896         (((gctUINT32)(x) & (gctUINT32)0x0000FF00UL) << 8)  | \
897         (((gctUINT32)(x) & (gctUINT32)0x00FF0000UL) >> 8)  | \
898         (((gctUINT32)(x) & (gctUINT32)0xFF000000UL) >> 24)))
899
900 /*******************************************************************************
901 ***** Database ****************************************************************/
902
903 typedef struct _gcsDATABASE_COUNTERS
904 {
905     /* Number of currently allocated bytes. */
906     gctUINT64                   bytes;
907
908     /* Maximum number of bytes allocated (memory footprint). */
909     gctUINT64                   maxBytes;
910
911     /* Total number of bytes allocated. */
912     gctUINT64                   totalBytes;
913 }
914 gcsDATABASE_COUNTERS;
915
916 typedef struct _gcuDATABASE_INFO
917 {
918     /* Counters. */
919     gcsDATABASE_COUNTERS        counters;
920
921     /* Time value. */
922     gctUINT64                   time;
923 }
924 gcuDATABASE_INFO;
925
926 /*******************************************************************************
927 ***** Frame database **********************************************************/
928
929 /* gcsHAL_FRAME_INFO */
930 typedef struct _gcsHAL_FRAME_INFO
931 {
932     /* Current timer tick. */
933     OUT gctUINT64               ticks;
934
935     /* Bandwidth counters. */
936     OUT gctUINT                 readBytes8[8];
937     OUT gctUINT                 writeBytes8[8];
938
939     /* Counters. */
940     OUT gctUINT                 cycles[8];
941     OUT gctUINT                 idleCycles[8];
942     OUT gctUINT                 mcCycles[8];
943     OUT gctUINT                 readRequests[8];
944     OUT gctUINT                 writeRequests[8];
945
946     /* FE counters. */
947     OUT gctUINT                 drawCount;
948     OUT gctUINT                 vertexOutCount;
949     OUT gctUINT                 vertexMissCount;
950
951     /* 3D counters. */
952     OUT gctUINT                 vertexCount;
953     OUT gctUINT                 primitiveCount;
954     OUT gctUINT                 rejectedPrimitives;
955     OUT gctUINT                 culledPrimitives;
956     OUT gctUINT                 clippedPrimitives;
957     OUT gctUINT                 droppedPrimitives;
958     OUT gctUINT                 frustumClippedPrimitives;
959     OUT gctUINT                 outPrimitives;
960     OUT gctUINT                 inPrimitives;
961     OUT gctUINT                 culledQuadCount;
962     OUT gctUINT                 totalQuadCount;
963     OUT gctUINT                 quadCount;
964     OUT gctUINT                 totalPixelCount;
965
966     /* PE counters. */
967     OUT gctUINT                 colorKilled[8];
968     OUT gctUINT                 colorDrawn[8];
969     OUT gctUINT                 depthKilled[8];
970     OUT gctUINT                 depthDrawn[8];
971
972     /* Shader counters. */
973     OUT gctUINT                 shaderCycles;
974     OUT gctUINT                 vsInstructionCount;
975     OUT gctUINT                 vsTextureCount;
976     OUT gctUINT                 vsBranchCount;
977     OUT gctUINT                 vsVertices;
978     OUT gctUINT                 psInstructionCount;
979     OUT gctUINT                 psTextureCount;
980     OUT gctUINT                 psBranchCount;
981     OUT gctUINT                 psPixels;
982
983     /* Texture counters. */
984     OUT gctUINT                 bilinearRequests;
985     OUT gctUINT                 trilinearRequests;
986     OUT gctUINT                 txBytes8[2];
987     OUT gctUINT                 txHitCount;
988     OUT gctUINT                 txMissCount;
989 }
990 gcsHAL_FRAME_INFO;
991
992 typedef enum _gcePATCH_ID
993 {
994     gcePATCH_UNKNOWN = 0xFFFFFFFF,
995
996     /* Benchmark list*/
997     gcePATCH_GLB11 = 0x0,
998     gcePATCH_GLB21,
999     gcePATCH_GLB25,
1000     gcePATCH_GLB27,
1001
1002     gcePATCH_BM21,
1003     gcePATCH_MM,
1004     gcePATCH_MM06,
1005     gcePATCH_MM07,
1006     gcePATCH_QUADRANT,
1007     gcePATCH_ANTUTU,
1008     gcePATCH_SMARTBENCH,
1009     gcePATCH_JPCT,
1010     gcePATCH_NENAMARK,
1011     gcePATCH_NENAMARK2,
1012     gcePATCH_NEOCORE,
1013     gcePATCH_GLB,
1014     gcePATCH_GB,
1015     gcePATCH_RTESTVA,
1016     gcePATCH_BMX,
1017     gcePATCH_BMGUI,
1018
1019     /* Game list */
1020     gcePATCH_NBA2013,
1021     gcePATCH_BARDTALE,
1022     gcePATCH_BUSPARKING3D,
1023     gcePATCH_FISHBOODLE,
1024     gcePATCH_SUBWAYSURFER,
1025     gcePATCH_HIGHWAYDRIVER,
1026     gcePATCH_PREMIUM,
1027     gcePATCH_RACEILLEGAL,
1028     gcePATCH_BLABLA,
1029     gcePATCH_MEGARUN,
1030     gcePATCH_GALAXYONFIRE2,
1031     gcePATCH_GLOFTR3HM,
1032     gcePATCH_GLOFTSXHM,
1033     gcePATCH_GLOFTF3HM,
1034     gcePATCH_GLOFTGANG,
1035     gcePATCH_XRUNNER,
1036     gcePATCH_WP,
1037     gcePATCH_DEVIL,
1038     gcePATCH_HOLYARCH,
1039     gcePATCH_MUSE,
1040     gcePATCH_SG,
1041     gcePATCH_SIEGECRAFT,
1042     gcePATCH_CARCHALLENGE,
1043     gcePATCH_HEROESCALL,
1044     gcePATCH_MONOPOLY,
1045     gcePATCH_CTGL20,
1046     gcePATCH_FIREFOX,
1047     gcePATCH_CHORME,
1048     gcePATCH_DUOKANTV,
1049     gcePATCH_TESTAPP,
1050
1051     /* Count enum*/
1052     gcePATCH_COUNT,
1053 }
1054 gcePATCH_ID;
1055
1056 #if gcdLINK_QUEUE_SIZE
1057 typedef struct _gckLINKDATA * gckLINKDATA;
1058 struct _gckLINKDATA
1059 {
1060     gctUINT32                   start;
1061     gctUINT32                   end;
1062     gctINT                      pid;
1063 };
1064
1065 typedef struct _gckLINKQUEUE * gckLINKQUEUE;
1066 struct _gckLINKQUEUE
1067 {
1068     struct _gckLINKDATA         data[gcdLINK_QUEUE_SIZE];
1069     gctUINT32                   rear;
1070     gctUINT32                   front;
1071     gctUINT32                   count;
1072 };
1073 #endif
1074
1075 #ifdef __cplusplus
1076 }
1077 #endif
1078
1079 #endif /* __gc_hal_types_h_ */