]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_types.h
ENGR00240988: gpu: copy gpu-viv driver from 3.5.7 kernel
[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 signed char             gctINT8;
132 typedef signed short            gctINT16;
133 typedef signed int              gctINT32;
134 typedef signed long long        gctINT64;
135
136 typedef gctINT *                gctINT_PTR;
137 typedef gctINT8 *               gctINT8_PTR;
138 typedef gctINT16 *              gctINT16_PTR;
139 typedef gctINT32 *              gctINT32_PTR;
140 typedef gctINT64 *              gctINT64_PTR;
141
142 typedef unsigned int            gctUINT;
143 typedef unsigned char           gctUINT8;
144 typedef unsigned short          gctUINT16;
145 typedef unsigned int            gctUINT32;
146 typedef unsigned long long      gctUINT64;
147 typedef unsigned long           gctUINTPTR_T;
148
149 typedef gctUINT *               gctUINT_PTR;
150 typedef gctUINT8 *              gctUINT8_PTR;
151 typedef gctUINT16 *             gctUINT16_PTR;
152 typedef gctUINT32 *             gctUINT32_PTR;
153 typedef gctUINT64 *             gctUINT64_PTR;
154
155 typedef unsigned long           gctSIZE_T;
156 typedef gctSIZE_T *             gctSIZE_T_PTR;
157
158 #ifdef __cplusplus
159 #   define gcvNULL              0
160 #else
161 #   define gcvNULL              ((void *) 0)
162 #endif
163
164 typedef float                   gctFLOAT;
165 typedef signed int              gctFIXED_POINT;
166 typedef float *                 gctFLOAT_PTR;
167
168 typedef void *                  gctPHYS_ADDR;
169 typedef void *                  gctHANDLE;
170 typedef void *                  gctFILE;
171 typedef void *                  gctSIGNAL;
172 typedef void *                  gctWINDOW;
173 typedef void *                  gctIMAGE;
174
175 typedef void *                                  gctSEMAPHORE;
176
177 typedef void *                  gctPOINTER;
178 typedef const void *            gctCONST_POINTER;
179
180 typedef char                    gctCHAR;
181 typedef char *                  gctSTRING;
182 typedef const char *            gctCONST_STRING;
183
184 typedef struct _gcsCOUNT_STRING
185 {
186     gctSIZE_T                   Length;
187     gctCONST_STRING             String;
188 }
189 gcsCOUNT_STRING;
190
191 typedef union _gcuFLOAT_UINT32
192 {
193     gctFLOAT    f;
194     gctUINT32   u;
195 }
196 gcuFLOAT_UINT32;
197
198 /* Fixed point constants. */
199 #define gcvZERO_X               ((gctFIXED_POINT) 0x00000000)
200 #define gcvHALF_X               ((gctFIXED_POINT) 0x00008000)
201 #define gcvONE_X                ((gctFIXED_POINT) 0x00010000)
202 #define gcvNEGONE_X             ((gctFIXED_POINT) 0xFFFF0000)
203 #define gcvTWO_X                ((gctFIXED_POINT) 0x00020000)
204
205 /* Stringizing macro. */
206 #define gcmSTRING(Value)        #Value
207
208 /******************************************************************************\
209 ******************************* Fixed Point Math *******************************
210 \******************************************************************************/
211
212 #define gcmXMultiply(x1, x2)            gcoMATH_MultiplyFixed(x1, x2)
213 #define gcmXDivide(x1, x2)              gcoMATH_DivideFixed(x1, x2)
214 #define gcmXMultiplyDivide(x1, x2, x3)  gcoMATH_MultiplyDivideFixed(x1, x2, x3)
215
216 /* 2D Engine profile. */
217 typedef struct _gcs2D_PROFILE
218 {
219     /* Cycle count.
220        32bit counter incremented every 2D clock cycle.
221        Wraps back to 0 when the counter overflows.
222     */
223     gctUINT32 cycleCount;
224
225     /* Pixels rendered by the 2D engine.
226        Resets to 0 every time it is read. */
227     gctUINT32 pixelsRendered;
228 }
229 gcs2D_PROFILE;
230
231 /* Macro to combine four characters into a Charcater Code. */
232 #define gcmCC(c1, c2, c3, c4) \
233 ( \
234     (char) (c1) \
235     | \
236     ((char) (c2) <<  8) \
237     | \
238     ((char) (c3) << 16) \
239     | \
240     ((char) (c4) << 24) \
241 )
242
243 #define gcmPRINTABLE(c)         ((((c) >= ' ') && ((c) <= '}')) ? ((c) != '%' ?  (c) : ' ') : ' ')
244
245 #define gcmCC_PRINT(cc) \
246     gcmPRINTABLE((char) ( (cc)        & 0xFF)), \
247     gcmPRINTABLE((char) (((cc) >>  8) & 0xFF)), \
248     gcmPRINTABLE((char) (((cc) >> 16) & 0xFF)), \
249     gcmPRINTABLE((char) (((cc) >> 24) & 0xFF))
250
251 /******************************************************************************\
252 ****************************** Function Parameters *****************************
253 \******************************************************************************/
254
255 #define IN
256 #define OUT
257 #define OPTIONAL
258
259 /******************************************************************************\
260 ********************************* Status Codes *********************************
261 \******************************************************************************/
262
263 typedef enum _gceSTATUS
264 {
265     gcvSTATUS_OK                    =   0,
266     gcvSTATUS_FALSE                 =   0,
267     gcvSTATUS_TRUE                  =   1,
268     gcvSTATUS_NO_MORE_DATA          =   2,
269     gcvSTATUS_CACHED                =   3,
270     gcvSTATUS_MIPMAP_TOO_LARGE      =   4,
271     gcvSTATUS_NAME_NOT_FOUND        =   5,
272     gcvSTATUS_NOT_OUR_INTERRUPT     =   6,
273     gcvSTATUS_MISMATCH              =   7,
274     gcvSTATUS_MIPMAP_TOO_SMALL      =   8,
275     gcvSTATUS_LARGER                =   9,
276     gcvSTATUS_SMALLER               =   10,
277     gcvSTATUS_CHIP_NOT_READY        =   11,
278     gcvSTATUS_NEED_CONVERSION       =   12,
279     gcvSTATUS_SKIP                  =   13,
280     gcvSTATUS_DATA_TOO_LARGE        =   14,
281     gcvSTATUS_INVALID_CONFIG        =   15,
282     gcvSTATUS_CHANGED               =   16,
283     gcvSTATUS_NOT_SUPPORT_DITHER    =   17,
284         gcvSTATUS_EXECUTED                              =       18,
285     gcvSTATUS_TERMINATE             =   19,
286
287     gcvSTATUS_CONVERT_TO_SINGLE_STREAM    =   20,
288
289     gcvSTATUS_INVALID_ARGUMENT      =   -1,
290     gcvSTATUS_INVALID_OBJECT        =   -2,
291     gcvSTATUS_OUT_OF_MEMORY         =   -3,
292     gcvSTATUS_MEMORY_LOCKED         =   -4,
293     gcvSTATUS_MEMORY_UNLOCKED       =   -5,
294     gcvSTATUS_HEAP_CORRUPTED        =   -6,
295     gcvSTATUS_GENERIC_IO            =   -7,
296     gcvSTATUS_INVALID_ADDRESS       =   -8,
297     gcvSTATUS_CONTEXT_LOSSED        =   -9,
298     gcvSTATUS_TOO_COMPLEX           =   -10,
299     gcvSTATUS_BUFFER_TOO_SMALL      =   -11,
300     gcvSTATUS_INTERFACE_ERROR       =   -12,
301     gcvSTATUS_NOT_SUPPORTED         =   -13,
302     gcvSTATUS_MORE_DATA             =   -14,
303     gcvSTATUS_TIMEOUT               =   -15,
304     gcvSTATUS_OUT_OF_RESOURCES      =   -16,
305     gcvSTATUS_INVALID_DATA          =   -17,
306     gcvSTATUS_INVALID_MIPMAP        =   -18,
307     gcvSTATUS_NOT_FOUND             =   -19,
308     gcvSTATUS_NOT_ALIGNED           =   -20,
309     gcvSTATUS_INVALID_REQUEST       =   -21,
310     gcvSTATUS_GPU_NOT_RESPONDING    =   -22,
311     gcvSTATUS_TIMER_OVERFLOW        =   -23,
312     gcvSTATUS_VERSION_MISMATCH      =   -24,
313     gcvSTATUS_LOCKED                =   -25,
314     gcvSTATUS_INTERRUPTED           =   -26,
315     gcvSTATUS_DEVICE                =   -27,
316     gcvSTATUS_NOT_MULTI_PIPE_ALIGNED =   -28,
317
318     /* Linker errors. */
319     gcvSTATUS_GLOBAL_TYPE_MISMATCH  =   -1000,
320     gcvSTATUS_TOO_MANY_ATTRIBUTES   =   -1001,
321     gcvSTATUS_TOO_MANY_UNIFORMS     =   -1002,
322     gcvSTATUS_TOO_MANY_VARYINGS     =   -1003,
323     gcvSTATUS_UNDECLARED_VARYING    =   -1004,
324     gcvSTATUS_VARYING_TYPE_MISMATCH =   -1005,
325     gcvSTATUS_MISSING_MAIN          =   -1006,
326     gcvSTATUS_NAME_MISMATCH         =   -1007,
327     gcvSTATUS_INVALID_INDEX         =   -1008,
328     gcvSTATUS_UNIFORM_TYPE_MISMATCH =   -1009,
329
330     /* Compiler errors. */
331     gcvSTATUS_COMPILER_FE_PREPROCESSOR_ERROR = -2000,
332     gcvSTATUS_COMPILER_FE_PARSER_ERROR = -2001,
333 }
334 gceSTATUS;
335
336 /******************************************************************************\
337 ********************************* Status Macros ********************************
338 \******************************************************************************/
339
340 #define gcmIS_ERROR(status)         (status < 0)
341 #define gcmNO_ERROR(status)         (status >= 0)
342 #define gcmIS_SUCCESS(status)       (status == gcvSTATUS_OK)
343
344 /******************************************************************************\
345 ********************************* Field Macros *********************************
346 \******************************************************************************/
347
348 #define __gcmSTART(reg_field) \
349     (0 ? reg_field)
350
351 #define __gcmEND(reg_field) \
352     (1 ? reg_field)
353
354 #define __gcmGETSIZE(reg_field) \
355     (__gcmEND(reg_field) - __gcmSTART(reg_field) + 1)
356
357 #define __gcmALIGN(data, reg_field) \
358     (((gctUINT32) (data)) << __gcmSTART(reg_field))
359
360 #define __gcmMASK(reg_field) \
361     ((gctUINT32) ((__gcmGETSIZE(reg_field) == 32) \
362         ?  ~0 \
363         : (~(~0 << __gcmGETSIZE(reg_field)))))
364
365 /*******************************************************************************
366 **
367 **  gcmFIELDMASK
368 **
369 **      Get aligned field mask.
370 **
371 **  ARGUMENTS:
372 **
373 **      reg     Name of register.
374 **      field   Name of field within register.
375 */
376 #define gcmFIELDMASK(reg, field) \
377 ( \
378     __gcmALIGN(__gcmMASK(reg##_##field), reg##_##field) \
379 )
380
381 /*******************************************************************************
382 **
383 **  gcmGETFIELD
384 **
385 **      Extract the value of a field from specified data.
386 **
387 **  ARGUMENTS:
388 **
389 **      data    Data value.
390 **      reg     Name of register.
391 **      field   Name of field within register.
392 */
393 #define gcmGETFIELD(data, reg, field) \
394 ( \
395     ((((gctUINT32) (data)) >> __gcmSTART(reg##_##field)) \
396         & __gcmMASK(reg##_##field)) \
397 )
398
399 /*******************************************************************************
400 **
401 **  gcmSETFIELD
402 **
403 **      Set the value of a field within specified data.
404 **
405 **  ARGUMENTS:
406 **
407 **      data    Data value.
408 **      reg     Name of register.
409 **      field   Name of field within register.
410 **      value   Value for field.
411 */
412 #define gcmSETFIELD(data, reg, field, value) \
413 ( \
414     (((gctUINT32) (data)) \
415         & ~__gcmALIGN(__gcmMASK(reg##_##field), reg##_##field)) \
416         |  __gcmALIGN((gctUINT32) (value) \
417             & __gcmMASK(reg##_##field), reg##_##field) \
418 )
419
420 /*******************************************************************************
421 **
422 **  gcmSETFIELDVALUE
423 **
424 **      Set the value of a field within specified data with a
425 **      predefined value.
426 **
427 **  ARGUMENTS:
428 **
429 **      data    Data value.
430 **      reg     Name of register.
431 **      field   Name of field within register.
432 **      value   Name of the value within the field.
433 */
434 #define gcmSETFIELDVALUE(data, reg, field, value) \
435 ( \
436     (((gctUINT32) (data)) \
437         & ~__gcmALIGN(__gcmMASK(reg##_##field), reg##_##field)) \
438         |  __gcmALIGN(reg##_##field##_##value \
439             & __gcmMASK(reg##_##field), reg##_##field) \
440 )
441
442 /*******************************************************************************
443 **
444 **  gcmGETMASKEDFIELDMASK
445 **
446 **      Determine field mask of a masked field.
447 **
448 **  ARGUMENTS:
449 **
450 **      reg     Name of register.
451 **      field   Name of field within register.
452 */
453 #define gcmGETMASKEDFIELDMASK(reg, field) \
454 ( \
455     gcmSETFIELD(0, reg,          field, ~0) | \
456     gcmSETFIELD(0, reg, MASK_ ## field, ~0)   \
457 )
458
459 /*******************************************************************************
460 **
461 **  gcmSETMASKEDFIELD
462 **
463 **      Set the value of a masked field with specified data.
464 **
465 **  ARGUMENTS:
466 **
467 **      reg     Name of register.
468 **      field   Name of field within register.
469 **      value   Value for field.
470 */
471 #define gcmSETMASKEDFIELD(reg, field, value) \
472 ( \
473     gcmSETFIELD     (~0, reg,          field, value) & \
474     gcmSETFIELDVALUE(~0, reg, MASK_ ## field, ENABLED) \
475 )
476
477 /*******************************************************************************
478 **
479 **  gcmSETMASKEDFIELDVALUE
480 **
481 **      Set the value of a masked field with specified data.
482 **
483 **  ARGUMENTS:
484 **
485 **      reg     Name of register.
486 **      field   Name of field within register.
487 **      value   Value for field.
488 */
489 #define gcmSETMASKEDFIELDVALUE(reg, field, value) \
490 ( \
491     gcmSETFIELDVALUE(~0, reg,          field, value) & \
492     gcmSETFIELDVALUE(~0, reg, MASK_ ## field, ENABLED) \
493 )
494
495 /*******************************************************************************
496 **
497 **  gcmVERIFYFIELDVALUE
498 **
499 **      Verify if the value of a field within specified data equals a
500 **      predefined value.
501 **
502 **  ARGUMENTS:
503 **
504 **      data    Data value.
505 **      reg     Name of register.
506 **      field   Name of field within register.
507 **      value   Name of the value within the field.
508 */
509 #define gcmVERIFYFIELDVALUE(data, reg, field, value) \
510 ( \
511     (((gctUINT32) (data)) >> __gcmSTART(reg##_##field) & \
512                              __gcmMASK(reg##_##field)) \
513         == \
514     (reg##_##field##_##value & __gcmMASK(reg##_##field)) \
515 )
516
517 /*******************************************************************************
518 **  Bit field macros.
519 */
520
521 #define __gcmSTARTBIT(Field) \
522     ( 1 ? Field )
523
524 #define __gcmBITSIZE(Field) \
525     ( 0 ? Field )
526
527 #define __gcmBITMASK(Field) \
528 ( \
529     (1 << __gcmBITSIZE(Field)) - 1 \
530 )
531
532 #define gcmGETBITS(Value, Type, Field) \
533 ( \
534     ( ((Type) (Value)) >> __gcmSTARTBIT(Field) ) \
535     & \
536     __gcmBITMASK(Field) \
537 )
538
539 #define gcmSETBITS(Value, Type, Field, NewValue) \
540 ( \
541     ( ((Type) (Value)) \
542     & ~(__gcmBITMASK(Field) << __gcmSTARTBIT(Field)) \
543     ) \
544     | \
545     ( ( ((Type) (NewValue)) \
546       & __gcmBITMASK(Field) \
547       ) << __gcmSTARTBIT(Field) \
548     ) \
549 )
550
551 /*******************************************************************************
552 **
553 **  gcmISINREGRANGE
554 **
555 **      Verify whether the specified address is in the register range.
556 **
557 **  ARGUMENTS:
558 **
559 **      Address Address to be verified.
560 **      Name    Name of a register.
561 */
562
563 #define gcmISINREGRANGE(Address, Name) \
564 ( \
565     ((Address & (~0U << Name ## _LSB)) == (Name ## _Address >> 2)) \
566 )
567
568 /*******************************************************************************
569 **
570 **  A set of macros to aid state loading.
571 **
572 **  ARGUMENTS:
573 **
574 **      CommandBuffer   Pointer to a gcoCMDBUF object.
575 **      StateDelta      Pointer to a gcsSTATE_DELTA state delta structure.
576 **      Memory          Destination memory pointer of gctUINT32_PTR type.
577 **      PartOfContext   Whether or not the state is a part of the context.
578 **      FixedPoint      Whether or not the state is of the fixed point format.
579 **      Count           Number of consecutive states to be loaded.
580 **      Address         State address.
581 **      Data            Data to be set to the state.
582 */
583
584 /*----------------------------------------------------------------------------*/
585
586 #if gcmIS_DEBUG(gcdDEBUG_CODE)
587
588 #   define gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count) \
589         CommandBuffer->lastLoadStatePtr     = gcmPTR_TO_UINT64(Memory); \
590         CommandBuffer->lastLoadStateAddress = Address; \
591         CommandBuffer->lastLoadStateCount   = Count
592
593 #   define gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address) \
594         gcmASSERT( \
595             (gctUINT) (Memory  - gcmUINT64_TO_TYPE(CommandBuffer->lastLoadStatePtr, gctUINT32_PTR) - 1) \
596             == \
597             (gctUINT) (Address - CommandBuffer->lastLoadStateAddress) \
598             ); \
599         \
600         gcmASSERT(CommandBuffer->lastLoadStateCount > 0); \
601         \
602         CommandBuffer->lastLoadStateCount -= 1
603
604 #   define gcmVERIFYLOADSTATEDONE(CommandBuffer) \
605         gcmASSERT(CommandBuffer->lastLoadStateCount == 0)
606
607 #else
608
609 #   define gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count)
610 #   define gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address)
611 #   define gcmVERIFYLOADSTATEDONE(CommandBuffer)
612
613 #endif
614
615 #if gcdSECURE_USER
616
617 #   define gcmDEFINESECUREUSER() \
618         gctUINT         __secure_user_offset__; \
619         gctUINT32_PTR   __secure_user_hintArray__;
620
621 #   define gcmBEGINSECUREUSER() \
622         __secure_user_offset__ = reserve->lastOffset; \
623         \
624         __secure_user_hintArray__ = gcmUINT64_TO_PTR(reserve->hintArrayTail)
625
626 #   define gcmENDSECUREUSER() \
627         reserve->hintArrayTail = gcmPTR_TO_UINT64(__secure_user_hintArray__)
628
629 #   define gcmSKIPSECUREUSER() \
630         __secure_user_offset__ += gcmSIZEOF(gctUINT32)
631
632 #   define gcmUPDATESECUREUSER() \
633         *__secure_user_hintArray__ = __secure_user_offset__; \
634         \
635         __secure_user_offset__    += gcmSIZEOF(gctUINT32); \
636         __secure_user_hintArray__ += 1
637
638 #else
639
640 #   define gcmDEFINESECUREUSER()
641 #   define gcmBEGINSECUREUSER()
642 #   define gcmENDSECUREUSER()
643 #   define gcmSKIPSECUREUSER()
644 #   define gcmUPDATESECUREUSER()
645
646 #endif
647
648 /*----------------------------------------------------------------------------*/
649
650 #if gcdDUMP
651 #   define gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, Data) \
652         if (FixedPoint) \
653         { \
654             gcmDUMP(gcvNULL, "@[state.x 0x%04X 0x%08X]", \
655                 Address, Data \
656                 ); \
657         } \
658         else \
659         { \
660             gcmDUMP(gcvNULL, "@[state 0x%04X 0x%08X]", \
661                 Address, Data \
662                 ); \
663         }
664 #else
665 #   define gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, Data)
666 #endif
667
668 /*----------------------------------------------------------------------------*/
669
670 #define gcmDEFINESTATEBUFFER(CommandBuffer, StateDelta, Memory, ReserveSize) \
671     gcmDEFINESECUREUSER() \
672     gctSIZE_T ReserveSize; \
673     gcoCMDBUF CommandBuffer; \
674     gctUINT32_PTR Memory; \
675     gcsSTATE_DELTA_PTR StateDelta
676
677 #define gcmBEGINSTATEBUFFER(Hardware, CommandBuffer, StateDelta, Memory, ReserveSize) \
678 { \
679     gcmONERROR(gcoBUFFER_Reserve( \
680         Hardware->buffer, ReserveSize, gcvTRUE, &CommandBuffer \
681         )); \
682     \
683     Memory =  gcmUINT64_TO_PTR(CommandBuffer->lastReserve); \
684     \
685     StateDelta = Hardware->delta; \
686     \
687     gcmBEGINSECUREUSER(); \
688 }
689
690 #define gcmENDSTATEBUFFER(CommandBuffer, Memory, ReserveSize) \
691 { \
692     gcmENDSECUREUSER(); \
693     \
694     gcmASSERT( \
695         gcmUINT64_TO_TYPE(CommandBuffer->lastReserve, gctUINT8_PTR) + ReserveSize \
696         == \
697          (gctUINT8_PTR) Memory \
698         ); \
699 }
700
701 /*----------------------------------------------------------------------------*/
702
703 #define gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, Count) \
704 { \
705     gcmASSERT(((Memory - gcmUINT64_TO_TYPE(CommandBuffer->lastReserve, gctUINT32_PTR)) & 1) == 0); \
706     gcmASSERT((gctUINT32)Count <= 1024); \
707     \
708     gcmVERIFYLOADSTATEDONE(CommandBuffer); \
709     \
710     gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count); \
711     \
712     *Memory++ \
713         = gcmSETFIELDVALUE(0, AQ_COMMAND_LOAD_STATE_COMMAND, OPCODE,  LOAD_STATE) \
714         | gcmSETFIELD     (0, AQ_COMMAND_LOAD_STATE_COMMAND, FLOAT,   FixedPoint) \
715         | gcmSETFIELD     (0, AQ_COMMAND_LOAD_STATE_COMMAND, COUNT,   Count) \
716         | gcmSETFIELD     (0, AQ_COMMAND_LOAD_STATE_COMMAND, ADDRESS, Address); \
717     \
718     gcmSKIPSECUREUSER(); \
719 }
720
721 #define gcmENDSTATEBATCH(CommandBuffer, Memory) \
722 { \
723     gcmVERIFYLOADSTATEDONE(CommandBuffer); \
724     \
725     gcmASSERT(((Memory - gcmUINT64_TO_TYPE(CommandBuffer->lastReserve, gctUINT32_PTR)) & 1) == 0); \
726 }
727
728 /*----------------------------------------------------------------------------*/
729
730 #define gcmSETSTATEDATA(StateDelta, CommandBuffer, Memory, FixedPoint, \
731                         Address, Data) \
732 { \
733     gctUINT32 __temp_data32__; \
734     \
735     gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address); \
736     \
737     __temp_data32__ = Data; \
738     \
739     *Memory++ = __temp_data32__; \
740     \
741     gcoHARDWARE_UpdateDelta( \
742         StateDelta, FixedPoint, Address, 0, __temp_data32__ \
743         ); \
744     \
745     gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, __temp_data32__); \
746     \
747     gcmUPDATESECUREUSER(); \
748 }
749
750 #define gcmSETCTRLSTATE(StateDelta, CommandBuffer, Memory, Address, Data) \
751 { \
752     gctUINT32 __temp_data32__; \
753     \
754     gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address); \
755     \
756     __temp_data32__ = Data; \
757     \
758     *Memory++ = __temp_data32__; \
759     \
760     gcmDUMPSTATEDATA(StateDelta, gcvFALSE, Address, __temp_data32__); \
761     \
762     gcmSKIPSECUREUSER(); \
763 }
764
765 #define gcmSETFILLER(CommandBuffer, Memory) \
766 { \
767     gcmVERIFYLOADSTATEDONE(CommandBuffer); \
768     \
769     Memory += 1; \
770     \
771     gcmSKIPSECUREUSER(); \
772 }
773
774 /*----------------------------------------------------------------------------*/
775
776 #define gcmSETSINGLESTATE(StateDelta, CommandBuffer, Memory, FixedPoint, \
777                           Address, Data) \
778 { \
779     gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, 1); \
780     gcmSETSTATEDATA(StateDelta, CommandBuffer, Memory, FixedPoint, \
781                     Address, Data); \
782     gcmENDSTATEBATCH(CommandBuffer, Memory); \
783 }
784
785 #define gcmSETSINGLECTRLSTATE(StateDelta, CommandBuffer, Memory, FixedPoint, \
786                               Address, Data) \
787 { \
788     gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, 1); \
789     gcmSETCTRLSTATE(StateDelta, CommandBuffer, Memory, Address, Data); \
790     gcmENDSTATEBATCH(CommandBuffer, Memory); \
791 }
792
793
794 /*******************************************************************************
795 **
796 **  gcmSETSTARTDECOMMAND
797 **
798 **      Form a START_DE command.
799 **
800 **  ARGUMENTS:
801 **
802 **      Memory          Destination memory pointer of gctUINT32_PTR type.
803 **      Count           Number of the rectangles.
804 */
805
806 #define gcmSETSTARTDECOMMAND(Memory, Count) \
807 { \
808     *Memory++ \
809         = gcmSETFIELDVALUE(0, AQ_COMMAND_START_DE_COMMAND, OPCODE,     START_DE) \
810         | gcmSETFIELD     (0, AQ_COMMAND_START_DE_COMMAND, COUNT,      Count) \
811         | gcmSETFIELD     (0, AQ_COMMAND_START_DE_COMMAND, DATA_COUNT, 0); \
812     \
813     *Memory++ = 0xDEADDEED; \
814 }
815
816 /******************************************************************************\
817 ******************************** Ceiling Macro ********************************
818 \******************************************************************************/
819 #define gcmCEIL(x) ((x - (gctUINT32)x) == 0 ? (gctUINT32)x : (gctUINT32)x + 1)
820
821 /******************************************************************************\
822 ******************************** Min/Max Macros ********************************
823 \******************************************************************************/
824
825 #define gcmMIN(x, y)            (((x) <= (y)) ?  (x) :  (y))
826 #define gcmMAX(x, y)            (((x) >= (y)) ?  (x) :  (y))
827 #define gcmCLAMP(x, min, max)   (((x) < (min)) ? (min) : \
828                                  ((x) > (max)) ? (max) : (x))
829 #define gcmABS(x)               (((x) < 0)    ? -(x) :  (x))
830 #define gcmNEG(x)               (((x) < 0)    ?  (x) : -(x))
831
832 /*******************************************************************************
833 **
834 **  gcmPTR2INT
835 **
836 **      Convert a pointer to an integer value.
837 **
838 **  ARGUMENTS:
839 **
840 **      p       Pointer value.
841 */
842 #if defined(_WIN32) || (defined(__LP64__) && __LP64__)
843 #   define gcmPTR2INT(p) \
844     ( \
845         (gctUINT32) (gctUINT64) (p) \
846     )
847 #else
848 #   define gcmPTR2INT(p) \
849     ( \
850         (gctUINT32) (p) \
851     )
852 #endif
853
854 /*******************************************************************************
855 **
856 **  gcmINT2PTR
857 **
858 **      Convert an integer value into a pointer.
859 **
860 **  ARGUMENTS:
861 **
862 **      v       Integer value.
863 */
864 #ifdef __LP64__
865 #   define gcmINT2PTR(i) \
866     ( \
867         (gctPOINTER) (gctINT64) (i) \
868     )
869 #else
870 #   define gcmINT2PTR(i) \
871     ( \
872         (gctPOINTER) (i) \
873     )
874 #endif
875
876 /*******************************************************************************
877 **
878 **  gcmOFFSETOF
879 **
880 **      Compute the byte offset of a field inside a structure.
881 **
882 **  ARGUMENTS:
883 **
884 **      s       Structure name.
885 **      field   Field name.
886 */
887 #define gcmOFFSETOF(s, field) \
888 ( \
889     gcmPTR2INT(& (((struct s *) 0)->field)) \
890 )
891
892 #define gcmSWAB32(x) ((gctUINT32)( \
893         (((gctUINT32)(x) & (gctUINT32)0x000000FFUL) << 24) | \
894         (((gctUINT32)(x) & (gctUINT32)0x0000FF00UL) << 8)  | \
895         (((gctUINT32)(x) & (gctUINT32)0x00FF0000UL) >> 8)  | \
896         (((gctUINT32)(x) & (gctUINT32)0xFF000000UL) >> 24)))
897
898 /*******************************************************************************
899 ***** Database ****************************************************************/
900
901 typedef struct _gcsDATABASE_COUNTERS
902 {
903     /* Number of currently allocated bytes. */
904     gctUINT64                   bytes;
905
906     /* Maximum number of bytes allocated (memory footprint). */
907     gctUINT64                   maxBytes;
908
909     /* Total number of bytes allocated. */
910     gctUINT64                   totalBytes;
911 }
912 gcsDATABASE_COUNTERS;
913
914 typedef struct _gcuDATABASE_INFO
915 {
916     /* Counters. */
917     gcsDATABASE_COUNTERS        counters;
918
919     /* Time value. */
920     gctUINT64                   time;
921 }
922 gcuDATABASE_INFO;
923
924 /*******************************************************************************
925 ***** Frame database **********************************************************/
926
927 /* gcsHAL_FRAME_INFO */
928 typedef struct _gcsHAL_FRAME_INFO
929 {
930     /* Current timer tick. */
931     OUT gctUINT64               ticks;
932
933     /* Bandwidth counters. */
934     OUT gctUINT                 readBytes8[8];
935     OUT gctUINT                 writeBytes8[8];
936
937     /* Counters. */
938     OUT gctUINT                 cycles[8];
939     OUT gctUINT                 idleCycles[8];
940     OUT gctUINT                 mcCycles[8];
941     OUT gctUINT                 readRequests[8];
942     OUT gctUINT                 writeRequests[8];
943
944     /* 3D counters. */
945     OUT gctUINT                 vertexCount;
946     OUT gctUINT                 primitiveCount;
947     OUT gctUINT                 rejectedPrimitives;
948     OUT gctUINT                 culledPrimitives;
949     OUT gctUINT                 clippedPrimitives;
950     OUT gctUINT                 outPrimitives;
951     OUT gctUINT                 inPrimitives;
952     OUT gctUINT                 culledQuadCount;
953     OUT gctUINT                 totalQuadCount;
954     OUT gctUINT                 quadCount;
955     OUT gctUINT                 totalPixelCount;
956
957     /* PE counters. */
958     OUT gctUINT                 colorKilled[8];
959     OUT gctUINT                 colorDrawn[8];
960     OUT gctUINT                 depthKilled[8];
961     OUT gctUINT                 depthDrawn[8];
962
963     /* Shader counters. */
964     OUT gctUINT                 shaderCycles;
965     OUT gctUINT                 vsInstructionCount;
966     OUT gctUINT                 vsTextureCount;
967     OUT gctUINT                 psInstructionCount;
968     OUT gctUINT                 psTextureCount;
969
970     /* Texture counters. */
971     OUT gctUINT                 bilinearRequests;
972     OUT gctUINT                 trilinearRequests;
973     OUT gctUINT                 txBytes8;
974     OUT gctUINT                 txHitCount;
975     OUT gctUINT                 txMissCount;
976 }
977 gcsHAL_FRAME_INFO;
978
979 #if gcdLINK_QUEUE_SIZE
980 typedef struct _gckLINKDATA * gckLINKDATA;
981 struct _gckLINKDATA
982 {
983     gctUINT32                   start;
984     gctUINT32                   end;
985     gctINT                      pid;
986 };
987
988 typedef struct _gckLINKQUEUE * gckLINKQUEUE;
989 struct _gckLINKQUEUE
990 {
991     struct _gckLINKDATA         data[gcdLINK_QUEUE_SIZE];
992     gctUINT32                   rear;
993     gctUINT32                   front;
994     gctUINT32                   count;
995 };
996 #endif
997
998 #ifdef __cplusplus
999 }
1000 #endif
1001
1002 #endif /* __gc_hal_types_h_ */