ENGR00156850 gpu-viv: add gpu-viv driver source
[wandboard.git] / drivers / mxc / gpu-viv / hal / kernel / inc / gc_hal_types.h
blob8b97268084df0aa6582866619f44bf0bc551f1f8
1 /****************************************************************************
3 * Copyright (C) 2005 - 2011 by Vivante Corp.
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.
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.
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.
19 *****************************************************************************/
24 #ifndef __gc_hal_types_h_
25 #define __gc_hal_types_h_
27 #include "gc_hal_version.h"
28 #include "gc_hal_options.h"
30 #ifdef _WIN32
31 #pragma warning(disable:4127) /* Conditional expression is constant (do { }
32 ** while(0)). */
33 #pragma warning(disable:4100) /* Unreferenced formal parameter. */
34 #pragma warning(disable:4204) /* Non-constant aggregate initializer (C99). */
35 #pragma warning(disable:4131) /* Uses old-style declarator (for Bison and
36 ** Flex generated files). */
37 #pragma warning(disable:4206) /* Translation unit is empty. */
38 #endif
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 /******************************************************************************\
45 ** Platform macros.
48 #if defined(__GNUC__)
49 # define gcdHAS_ELLIPSES 1 /* GCC always has it. */
50 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
51 # define gcdHAS_ELLIPSES 1 /* C99 has it. */
52 #elif defined(_MSC_VER) && (_MSC_VER >= 1500)
53 # define gcdHAS_ELLIPSES 1 /* MSVC 2007+ has it. */
54 #elif defined(UNDER_CE)
55 #if UNDER_CE >= 600
56 # define gcdHAS_ELLIPSES 1
57 # else
58 # define gcdHAS_ELLIPSES 0
59 # endif
60 #else
61 # error "gcdHAS_ELLIPSES: Platform could not be determined"
62 #endif
64 /******************************************************************************\
65 ************************************ Keyword ***********************************
66 \******************************************************************************/
68 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
69 # define gcmINLINE inline /* C99 keyword. */
70 #elif defined(__GNUC__)
71 # define gcmINLINE __inline__ /* GNU keyword. */
72 #elif defined(_MSC_VER) || defined(UNDER_CE)
73 # define gcmINLINE __inline /* Internal keyword. */
74 #else
75 # error "gcmINLINE: Platform could not be determined"
76 #endif
78 /* Possible debug flags. */
79 #define gcdDEBUG_NONE 0
80 #define gcdDEBUG_ALL (1 << 0)
81 #define gcdDEBUG_FATAL (1 << 1)
82 #define gcdDEBUG_TRACE (1 << 2)
83 #define gcdDEBUG_BREAK (1 << 3)
84 #define gcdDEBUG_ASSERT (1 << 4)
85 #define gcdDEBUG_CODE (1 << 5)
86 #define gcdDEBUG_STACK (1 << 6)
88 #define gcmIS_DEBUG(flag) ( gcdDEBUG & (flag | gcdDEBUG_ALL) )
90 #ifndef gcdDEBUG
91 #if (defined(DBG) && DBG) || defined(DEBUG) || defined(_DEBUG)
92 # define gcdDEBUG gcdDEBUG_ALL
93 # else
94 # define gcdDEBUG gcdDEBUG_NONE
95 # endif
96 #endif
98 #ifdef _USRDLL
99 #ifdef _MSC_VER
100 #ifdef HAL_EXPORTS
101 # define HALAPI __declspec(dllexport)
102 # else
103 # define HALAPI __declspec(dllimport)
104 # endif
105 # define HALDECL __cdecl
106 # else
107 #ifdef HAL_EXPORTS
108 # define HALAPI
109 # else
110 # define HALAPI extern
111 # endif
112 # endif
113 #else
114 # define HALAPI
115 # define HALDECL
116 #endif
118 /******************************************************************************\
119 ********************************** Common Types ********************************
120 \******************************************************************************/
122 #define gcvFALSE 0
123 #define gcvTRUE 1
125 #define gcvINFINITE ((gctUINT32) ~0U)
127 #define gcvINVALID_HANDLE ((gctHANDLE) ~0U)
129 typedef int gctBOOL;
130 typedef gctBOOL * gctBOOL_PTR;
132 typedef int gctINT;
133 typedef signed char gctINT8;
134 typedef signed short gctINT16;
135 typedef signed int gctINT32;
136 typedef signed long long gctINT64;
138 typedef gctINT * gctINT_PTR;
139 typedef gctINT8 * gctINT8_PTR;
140 typedef gctINT16 * gctINT16_PTR;
141 typedef gctINT32 * gctINT32_PTR;
142 typedef gctINT64 * gctINT64_PTR;
144 typedef unsigned int gctUINT;
145 typedef unsigned char gctUINT8;
146 typedef unsigned short gctUINT16;
147 typedef unsigned int gctUINT32;
148 typedef unsigned long long gctUINT64;
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;
156 typedef unsigned long gctSIZE_T;
157 typedef gctSIZE_T * gctSIZE_T_PTR;
159 #ifdef __cplusplus
160 # define gcvNULL 0
161 #else
162 # define gcvNULL ((void *) 0)
163 #endif
165 typedef float gctFLOAT;
166 typedef signed int gctFIXED_POINT;
167 typedef float * gctFLOAT_PTR;
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;
176 typedef void * gctSEMAPHORE;
178 typedef void * gctPOINTER;
179 typedef const void * gctCONST_POINTER;
181 typedef char gctCHAR;
182 typedef char * gctSTRING;
183 typedef const char * gctCONST_STRING;
185 typedef struct _gcsCOUNT_STRING
187 gctSIZE_T Length;
188 gctCONST_STRING String;
190 gcsCOUNT_STRING;
192 typedef union _gcuFLOAT_UINT32
194 gctFLOAT f;
195 gctUINT32 u;
197 gcuFLOAT_UINT32;
199 /* Fixed point constants. */
200 #define gcvZERO_X ((gctFIXED_POINT) 0x00000000)
201 #define gcvHALF_X ((gctFIXED_POINT) 0x00008000)
202 #define gcvONE_X ((gctFIXED_POINT) 0x00010000)
203 #define gcvNEGONE_X ((gctFIXED_POINT) 0xFFFF0000)
204 #define gcvTWO_X ((gctFIXED_POINT) 0x00020000)
206 /* Stringizing macro. */
207 #define gcmSTRING(Value) #Value
209 /******************************************************************************\
210 ******************************* Fixed Point Math *******************************
211 \******************************************************************************/
213 #define gcmXMultiply(x1, x2) gcoMATH_MultiplyFixed(x1, x2)
214 #define gcmXDivide(x1, x2) gcoMATH_DivideFixed(x1, x2)
215 #define gcmXMultiplyDivide(x1, x2, x3) gcoMATH_MultiplyDivideFixed(x1, x2, x3)
217 /* 2D Engine profile. */
218 typedef struct _gcs2D_PROFILE
220 /* Cycle count.
221 32bit counter incremented every 2D clock cycle.
222 Wraps back to 0 when the counter overflows.
224 gctUINT32 cycleCount;
226 /* Pixels rendered by the 2D engine.
227 Resets to 0 every time it is read. */
228 gctUINT32 pixelsRendered;
230 gcs2D_PROFILE;
232 /* Macro to combine four characters into a Charcater Code. */
233 #define gcmCC(c1, c2, c3, c4) \
235 (char) (c1) \
237 ((char) (c2) << 8) \
239 ((char) (c3) << 16) \
241 ((char) (c4) << 24) \
244 #define gcmPRINTABLE(c) ((((c) >= ' ') && ((c) <= '}')) ? ((c) != '%' ? (c) : ' ') : ' ')
246 #define gcmCC_PRINT(cc) \
247 gcmPRINTABLE((char) ( (cc) & 0xFF)), \
248 gcmPRINTABLE((char) (((cc) >> 8) & 0xFF)), \
249 gcmPRINTABLE((char) (((cc) >> 16) & 0xFF)), \
250 gcmPRINTABLE((char) (((cc) >> 24) & 0xFF))
252 /******************************************************************************\
253 ****************************** Function Parameters *****************************
254 \******************************************************************************/
256 #define IN
257 #define OUT
258 #define OPTIONAL
260 /******************************************************************************\
261 ********************************* Status Codes *********************************
262 \******************************************************************************/
264 typedef enum _gceSTATUS
266 gcvSTATUS_OK = 0,
267 gcvSTATUS_FALSE = 0,
268 gcvSTATUS_TRUE = 1,
269 gcvSTATUS_NO_MORE_DATA = 2,
270 gcvSTATUS_CACHED = 3,
271 gcvSTATUS_MIPMAP_TOO_LARGE = 4,
272 gcvSTATUS_NAME_NOT_FOUND = 5,
273 gcvSTATUS_NOT_OUR_INTERRUPT = 6,
274 gcvSTATUS_MISMATCH = 7,
275 gcvSTATUS_MIPMAP_TOO_SMALL = 8,
276 gcvSTATUS_LARGER = 9,
277 gcvSTATUS_SMALLER = 10,
278 gcvSTATUS_CHIP_NOT_READY = 11,
279 gcvSTATUS_NEED_CONVERSION = 12,
280 gcvSTATUS_SKIP = 13,
281 gcvSTATUS_DATA_TOO_LARGE = 14,
282 gcvSTATUS_INVALID_CONFIG = 15,
283 gcvSTATUS_CHANGED = 16,
284 gcvSTATUS_NOT_SUPPORT_DITHER = 17,
285 gcvSTATUS_EXECUTED = 18,
286 gcvSTATUS_TERMINATE = 19,
288 gcvSTATUS_INVALID_ARGUMENT = -1,
289 gcvSTATUS_INVALID_OBJECT = -2,
290 gcvSTATUS_OUT_OF_MEMORY = -3,
291 gcvSTATUS_MEMORY_LOCKED = -4,
292 gcvSTATUS_MEMORY_UNLOCKED = -5,
293 gcvSTATUS_HEAP_CORRUPTED = -6,
294 gcvSTATUS_GENERIC_IO = -7,
295 gcvSTATUS_INVALID_ADDRESS = -8,
296 gcvSTATUS_CONTEXT_LOSSED = -9,
297 gcvSTATUS_TOO_COMPLEX = -10,
298 gcvSTATUS_BUFFER_TOO_SMALL = -11,
299 gcvSTATUS_INTERFACE_ERROR = -12,
300 gcvSTATUS_NOT_SUPPORTED = -13,
301 gcvSTATUS_MORE_DATA = -14,
302 gcvSTATUS_TIMEOUT = -15,
303 gcvSTATUS_OUT_OF_RESOURCES = -16,
304 gcvSTATUS_INVALID_DATA = -17,
305 gcvSTATUS_INVALID_MIPMAP = -18,
306 gcvSTATUS_NOT_FOUND = -19,
307 gcvSTATUS_NOT_ALIGNED = -20,
308 gcvSTATUS_INVALID_REQUEST = -21,
309 gcvSTATUS_GPU_NOT_RESPONDING = -22,
310 gcvSTATUS_TIMER_OVERFLOW = -23,
311 gcvSTATUS_VERSION_MISMATCH = -24,
312 gcvSTATUS_LOCKED = -25,
313 gcvSTATUS_INTERRUPTED = -26,
314 gcvSTATUS_DEVICE = -27,
316 /* Linker errors. */
317 gcvSTATUS_GLOBAL_TYPE_MISMATCH = -1000,
318 gcvSTATUS_TOO_MANY_ATTRIBUTES = -1001,
319 gcvSTATUS_TOO_MANY_UNIFORMS = -1002,
320 gcvSTATUS_TOO_MANY_VARYINGS = -1003,
321 gcvSTATUS_UNDECLARED_VARYING = -1004,
322 gcvSTATUS_VARYING_TYPE_MISMATCH = -1005,
323 gcvSTATUS_MISSING_MAIN = -1006,
324 gcvSTATUS_NAME_MISMATCH = -1007,
325 gcvSTATUS_INVALID_INDEX = -1008,
327 gceSTATUS;
329 /******************************************************************************\
330 ********************************* Status Macros ********************************
331 \******************************************************************************/
333 #define gcmIS_ERROR(status) (status < 0)
334 #define gcmNO_ERROR(status) (status >= 0)
335 #define gcmIS_SUCCESS(status) (status == gcvSTATUS_OK)
337 /******************************************************************************\
338 ********************************* Field Macros *********************************
339 \******************************************************************************/
341 #define __gcmSTART(reg_field) \
342 (0 ? reg_field)
344 #define __gcmEND(reg_field) \
345 (1 ? reg_field)
347 #define __gcmGETSIZE(reg_field) \
348 (__gcmEND(reg_field) - __gcmSTART(reg_field) + 1)
350 #define __gcmALIGN(data, reg_field) \
351 (((gctUINT32) (data)) << __gcmSTART(reg_field))
353 #define __gcmMASK(reg_field) \
354 ((gctUINT32) ((__gcmGETSIZE(reg_field) == 32) \
355 ? ~0 \
356 : (~(~0 << __gcmGETSIZE(reg_field)))))
358 /*******************************************************************************
360 ** gcmFIELDMASK
362 ** Get aligned field mask.
364 ** ARGUMENTS:
366 ** reg Name of register.
367 ** field Name of field within register.
369 #define gcmFIELDMASK(reg, field) \
371 __gcmALIGN(__gcmMASK(reg##_##field), reg##_##field) \
374 /*******************************************************************************
376 ** gcmGETFIELD
378 ** Extract the value of a field from specified data.
380 ** ARGUMENTS:
382 ** data Data value.
383 ** reg Name of register.
384 ** field Name of field within register.
386 #define gcmGETFIELD(data, reg, field) \
388 ((((gctUINT32) (data)) >> __gcmSTART(reg##_##field)) \
389 & __gcmMASK(reg##_##field)) \
392 /*******************************************************************************
394 ** gcmSETFIELD
396 ** Set the value of a field within specified data.
398 ** ARGUMENTS:
400 ** data Data value.
401 ** reg Name of register.
402 ** field Name of field within register.
403 ** value Value for field.
405 #define gcmSETFIELD(data, reg, field, value) \
407 (((gctUINT32) (data)) \
408 & ~__gcmALIGN(__gcmMASK(reg##_##field), reg##_##field)) \
409 | __gcmALIGN((gctUINT32) (value) \
410 & __gcmMASK(reg##_##field), reg##_##field) \
413 /*******************************************************************************
415 ** gcmSETFIELDVALUE
417 ** Set the value of a field within specified data with a
418 ** predefined value.
420 ** ARGUMENTS:
422 ** data Data value.
423 ** reg Name of register.
424 ** field Name of field within register.
425 ** value Name of the value within the field.
427 #define gcmSETFIELDVALUE(data, reg, field, value) \
429 (((gctUINT32) (data)) \
430 & ~__gcmALIGN(__gcmMASK(reg##_##field), reg##_##field)) \
431 | __gcmALIGN(reg##_##field##_##value \
432 & __gcmMASK(reg##_##field), reg##_##field) \
435 /*******************************************************************************
437 ** gcmGETMASKEDFIELDMASK
439 ** Determine field mask of a masked field.
441 ** ARGUMENTS:
443 ** reg Name of register.
444 ** field Name of field within register.
446 #define gcmGETMASKEDFIELDMASK(reg, field) \
448 gcmSETFIELD(0, reg, field, ~0) | \
449 gcmSETFIELD(0, reg, MASK_ ## field, ~0) \
452 /*******************************************************************************
454 ** gcmSETMASKEDFIELD
456 ** Set the value of a masked field with specified data.
458 ** ARGUMENTS:
460 ** reg Name of register.
461 ** field Name of field within register.
462 ** value Value for field.
464 #define gcmSETMASKEDFIELD(reg, field, value) \
466 gcmSETFIELD (~0, reg, field, value) & \
467 gcmSETFIELDVALUE(~0, reg, MASK_ ## field, ENABLED) \
470 /*******************************************************************************
472 ** gcmSETMASKEDFIELDVALUE
474 ** Set the value of a masked field with specified data.
476 ** ARGUMENTS:
478 ** reg Name of register.
479 ** field Name of field within register.
480 ** value Value for field.
482 #define gcmSETMASKEDFIELDVALUE(reg, field, value) \
484 gcmSETFIELDVALUE(~0, reg, field, value) & \
485 gcmSETFIELDVALUE(~0, reg, MASK_ ## field, ENABLED) \
488 /*******************************************************************************
490 ** gcmVERIFYFIELDVALUE
492 ** Verify if the value of a field within specified data equals a
493 ** predefined value.
495 ** ARGUMENTS:
497 ** data Data value.
498 ** reg Name of register.
499 ** field Name of field within register.
500 ** value Name of the value within the field.
502 #define gcmVERIFYFIELDVALUE(data, reg, field, value) \
504 (((gctUINT32) (data)) >> __gcmSTART(reg##_##field) & \
505 __gcmMASK(reg##_##field)) \
506 == \
507 (reg##_##field##_##value & __gcmMASK(reg##_##field)) \
510 /*******************************************************************************
511 ** Bit field macros.
514 #define __gcmSTARTBIT(Field) \
515 ( 1 ? Field )
517 #define __gcmBITSIZE(Field) \
518 ( 0 ? Field )
520 #define __gcmBITMASK(Field) \
522 (1 << __gcmBITSIZE(Field)) - 1 \
525 #define gcmGETBITS(Value, Type, Field) \
527 ( ((Type) (Value)) >> __gcmSTARTBIT(Field) ) \
529 __gcmBITMASK(Field) \
532 #define gcmSETBITS(Value, Type, Field, NewValue) \
534 ( ((Type) (Value)) \
535 & ~(__gcmBITMASK(Field) << __gcmSTARTBIT(Field)) \
538 ( ( ((Type) (NewValue)) \
539 & __gcmBITMASK(Field) \
540 ) << __gcmSTARTBIT(Field) \
544 /*******************************************************************************
546 ** gcmISINREGRANGE
548 ** Verify whether the specified address is in the register range.
550 ** ARGUMENTS:
552 ** Address Address to be verified.
553 ** Name Name of a register.
556 #define gcmISINREGRANGE(Address, Name) \
558 ((Address & (~0U << Name ## _LSB)) == (Name ## _Address >> 2)) \
561 /*******************************************************************************
563 ** A set of macros to aid state loading.
565 ** ARGUMENTS:
567 ** CommandBuffer Pointer to a gcoCMDBUF object.
568 ** StateDelta Pointer to a gcsSTATE_DELTA state delta structure.
569 ** Memory Destination memory pointer of gctUINT32_PTR type.
570 ** PartOfContext Whether or not the state is a part of the context.
571 ** FixedPoint Whether or not the state is of the fixed point format.
572 ** Count Number of consecutive states to be loaded.
573 ** Address State address.
574 ** Data Data to be set to the state.
577 /*----------------------------------------------------------------------------*/
579 #if gcmIS_DEBUG(gcdDEBUG_CODE)
581 # define gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count) \
582 CommandBuffer->lastLoadStatePtr = Memory; \
583 CommandBuffer->lastLoadStateAddress = Address; \
584 CommandBuffer->lastLoadStateCount = Count
586 # define gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address) \
587 gcmASSERT( \
588 (gctUINT) (Memory - CommandBuffer->lastLoadStatePtr - 1) \
589 == \
590 (gctUINT) (Address - CommandBuffer->lastLoadStateAddress) \
591 ); \
593 gcmASSERT(CommandBuffer->lastLoadStateCount > 0); \
595 CommandBuffer->lastLoadStateCount -= 1
597 # define gcmVERIFYLOADSTATEDONE(CommandBuffer) \
598 gcmASSERT(CommandBuffer->lastLoadStateCount == 0)
600 #else
602 # define gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count)
603 # define gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address)
604 # define gcmVERIFYLOADSTATEDONE(CommandBuffer)
606 #endif
608 #if gcdSECURE_USER
610 # define gcmDEFINESECUREUSER() \
611 gctUINT __secure_user_offset__; \
612 gctUINT32_PTR __secure_user_hintArray__;
614 # define gcmBEGINSECUREUSER() \
615 __secure_user_offset__ = reserve->lastOffset; \
617 __secure_user_hintArray__ = reserve->hintArrayTail
619 # define gcmENDSECUREUSER() \
620 reserve->hintArrayTail = __secure_user_hintArray__
622 # define gcmSKIPSECUREUSER() \
623 __secure_user_offset__ += gcmSIZEOF(gctUINT32)
625 # define gcmUPDATESECUREUSER() \
626 *__secure_user_hintArray__ = __secure_user_offset__; \
628 __secure_user_offset__ += gcmSIZEOF(gctUINT32); \
629 __secure_user_hintArray__ += 1
631 #else
633 # define gcmDEFINESECUREUSER()
634 # define gcmBEGINSECUREUSER()
635 # define gcmENDSECUREUSER()
636 # define gcmSKIPSECUREUSER()
637 # define gcmUPDATESECUREUSER()
639 #endif
641 /*----------------------------------------------------------------------------*/
643 #if gcdDUMP
644 # define gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, Data) \
645 if (FixedPoint) \
647 gcmDUMP(StateDelta->os, "@[state.x 0x%04X 0x%08X]", \
648 Address, Data \
649 ); \
651 else \
653 gcmDUMP(StateDelta->os, "@[state 0x%04X 0x%08X]", \
654 Address, Data \
655 ); \
657 #else
658 # define gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, Data)
659 #endif
661 /*----------------------------------------------------------------------------*/
663 #define gcmDEFINESTATEBUFFER(CommandBuffer, StateDelta, Memory, ReserveSize) \
664 gcmDEFINESECUREUSER() \
665 gctSIZE_T ReserveSize; \
666 gcoCMDBUF CommandBuffer; \
667 gctUINT32_PTR Memory; \
668 gcsSTATE_DELTA_PTR StateDelta
670 #define gcmBEGINSTATEBUFFER(Hardware, CommandBuffer, StateDelta, Memory, ReserveSize) \
672 gcmONERROR(gcoBUFFER_Reserve( \
673 Hardware->buffer, ReserveSize, gcvTRUE, &CommandBuffer \
674 )); \
676 Memory = (gctUINT32_PTR) CommandBuffer->lastReserve; \
678 StateDelta = Hardware->delta; \
680 gcmBEGINSECUREUSER(); \
683 #define gcmENDSTATEBUFFER(CommandBuffer, Memory, ReserveSize) \
685 gcmENDSECUREUSER(); \
687 gcmASSERT( \
688 ((gctUINT8_PTR) CommandBuffer->lastReserve) + ReserveSize \
689 == \
690 (gctUINT8_PTR) Memory \
691 ); \
694 /*----------------------------------------------------------------------------*/
696 #define gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, Count) \
698 gcmASSERT(((Memory - (gctUINT32_PTR) CommandBuffer->lastReserve) & 1) == 0); \
700 gcmVERIFYLOADSTATEDONE(CommandBuffer); \
702 gcmSTORELOADSTATE(CommandBuffer, Memory, Address, Count); \
704 *Memory++ \
705 = gcmSETFIELDVALUE(0, AQ_COMMAND_LOAD_STATE_COMMAND, OPCODE, LOAD_STATE) \
706 | gcmSETFIELD (0, AQ_COMMAND_LOAD_STATE_COMMAND, FLOAT, FixedPoint) \
707 | gcmSETFIELD (0, AQ_COMMAND_LOAD_STATE_COMMAND, COUNT, Count) \
708 | gcmSETFIELD (0, AQ_COMMAND_LOAD_STATE_COMMAND, ADDRESS, Address); \
710 gcmSKIPSECUREUSER(); \
713 #define gcmENDSTATEBATCH(CommandBuffer, Memory) \
715 gcmVERIFYLOADSTATEDONE(CommandBuffer); \
717 gcmASSERT(((Memory - (gctUINT32_PTR) CommandBuffer->lastReserve) & 1) == 0); \
720 /*----------------------------------------------------------------------------*/
722 #define gcmSETSTATEDATA(StateDelta, CommandBuffer, Memory, FixedPoint, \
723 Address, Data) \
725 gctUINT32 __temp_data32__; \
727 gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address); \
729 __temp_data32__ = Data; \
731 *Memory++ = __temp_data32__; \
733 gcoHARDWARE_UpdateDelta( \
734 StateDelta, FixedPoint, Address, 0, __temp_data32__ \
735 ); \
737 gcmDUMPSTATEDATA(StateDelta, FixedPoint, Address, __temp_data32__); \
739 gcmUPDATESECUREUSER(); \
742 #define gcmSETCTRLSTATE(StateDelta, CommandBuffer, Memory, Address, Data) \
744 gctUINT32 __temp_data32__; \
746 gcmVERIFYLOADSTATE(CommandBuffer, Memory, Address); \
748 __temp_data32__ = Data; \
750 *Memory++ = __temp_data32__; \
752 gcmDUMPSTATEDATA(StateDelta, gcvFALSE, Address, __temp_data32__); \
754 gcmSKIPSECUREUSER(); \
757 #define gcmSETFILLER(CommandBuffer, Memory) \
759 gcmVERIFYLOADSTATEDONE(CommandBuffer); \
761 Memory += 1; \
763 gcmSKIPSECUREUSER(); \
766 /*----------------------------------------------------------------------------*/
768 #define gcmSETSINGLESTATE(StateDelta, CommandBuffer, Memory, FixedPoint, \
769 Address, Data) \
771 gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, 1); \
772 gcmSETSTATEDATA(StateDelta, CommandBuffer, Memory, FixedPoint, \
773 Address, Data); \
774 gcmENDSTATEBATCH(CommandBuffer, Memory); \
777 #define gcmSETSINGLECTRLSTATE(StateDelta, CommandBuffer, Memory, FixedPoint, \
778 Address, Data) \
780 gcmBEGINSTATEBATCH(CommandBuffer, Memory, FixedPoint, Address, 1); \
781 gcmSETCTRLSTATE(StateDelta, CommandBuffer, Memory, Address, Data); \
782 gcmENDSTATEBATCH(CommandBuffer, Memory); \
786 /*******************************************************************************
788 ** gcmSETSTARTDECOMMAND
790 ** Form a START_DE command.
792 ** ARGUMENTS:
794 ** Memory Destination memory pointer of gctUINT32_PTR type.
795 ** Count Number of the rectangles.
798 #define gcmSETSTARTDECOMMAND(Memory, Count) \
800 *Memory++ \
801 = gcmSETFIELDVALUE(0, AQ_COMMAND_START_DE_COMMAND, OPCODE, START_DE) \
802 | gcmSETFIELD (0, AQ_COMMAND_START_DE_COMMAND, COUNT, Count) \
803 | gcmSETFIELD (0, AQ_COMMAND_START_DE_COMMAND, DATA_COUNT, 0); \
805 *Memory++ = 0xDEADDEED; \
808 /******************************************************************************\
809 ******************************** Ceiling Macro ********************************
810 \******************************************************************************/
811 #define gcmCEIL(x) ((x - (gctUINT32)x) == 0 ? (gctUINT32)x : (gctUINT32)x + 1)
813 /******************************************************************************\
814 ******************************** Min/Max Macros ********************************
815 \******************************************************************************/
817 #define gcmMIN(x, y) (((x) <= (y)) ? (x) : (y))
818 #define gcmMAX(x, y) (((x) >= (y)) ? (x) : (y))
819 #define gcmCLAMP(x, min, max) (((x) < (min)) ? (min) : \
820 ((x) > (max)) ? (max) : (x))
821 #define gcmABS(x) (((x) < 0) ? -(x) : (x))
822 #define gcmNEG(x) (((x) < 0) ? (x) : -(x))
824 /*******************************************************************************
826 ** gcmPTR2INT
828 ** Convert a pointer to an integer value.
830 ** ARGUMENTS:
832 ** p Pointer value.
834 #if defined(_WIN32) || (defined(__LP64__) && __LP64__)
835 # define gcmPTR2INT(p) \
837 (gctUINT32) (gctUINT64) (p) \
839 #else
840 # define gcmPTR2INT(p) \
842 (gctUINT32) (p) \
844 #endif
846 /*******************************************************************************
848 ** gcmINT2PTR
850 ** Convert an integer value into a pointer.
852 ** ARGUMENTS:
854 ** v Integer value.
856 #ifdef __LP64__
857 # define gcmINT2PTR(i) \
859 (gctPOINTER) (gctINT64) (i) \
861 #else
862 # define gcmINT2PTR(i) \
864 (gctPOINTER) (i) \
866 #endif
868 /*******************************************************************************
870 ** gcmOFFSETOF
872 ** Compute the byte offset of a field inside a structure.
874 ** ARGUMENTS:
876 ** s Structure name.
877 ** field Field name.
879 #define gcmOFFSETOF(s, field) \
881 gcmPTR2INT(& (((struct s *) 0)->field)) \
884 /*******************************************************************************
885 ***** Database ****************************************************************/
887 typedef struct _gcsDATABASE_COUNTERS
889 /* Number of currently allocated bytes. */
890 gctSIZE_T bytes;
892 /* Maximum number of bytes allocated (memory footprint). */
893 gctSIZE_T maxBytes;
895 /* Total number of bytes allocated. */
896 gctSIZE_T totalBytes;
898 gcsDATABASE_COUNTERS;
900 typedef struct _gcuDATABASE_INFO
902 /* Counters. */
903 gcsDATABASE_COUNTERS counters;
905 /* Time value. */
906 gctUINT64 time;
908 gcuDATABASE_INFO;
910 /*******************************************************************************
911 ***** Frame database **********************************************************/
913 /* gcsHAL_FRAME_INFO */
914 typedef struct _gcsHAL_FRAME_INFO
916 /* Current timer tick. */
917 OUT gctUINT64 ticks;
919 /* Bandwidth counters. */
920 OUT gctUINT readBytes8[8];
921 OUT gctUINT writeBytes8[8];
923 /* Counters. */
924 OUT gctUINT cycles[8];
925 OUT gctUINT idleCycles[8];
926 OUT gctUINT mcCycles[8];
927 OUT gctUINT readRequests[8];
928 OUT gctUINT writeRequests[8];
930 /* 3D counters. */
931 OUT gctUINT vertexCount;
932 OUT gctUINT primitiveCount;
933 OUT gctUINT rejectedPrimitives;
934 OUT gctUINT culledPrimitives;
935 OUT gctUINT clippedPrimitives;
936 OUT gctUINT outPrimitives;
937 OUT gctUINT inPrimitives;
938 OUT gctUINT culledQuadCount;
939 OUT gctUINT totalQuadCount;
940 OUT gctUINT quadCount;
941 OUT gctUINT totalPixelCount;
943 /* PE counters. */
944 OUT gctUINT colorKilled[8];
945 OUT gctUINT colorDrawn[8];
946 OUT gctUINT depthKilled[8];
947 OUT gctUINT depthDrawn[8];
949 /* Shader counters. */
950 OUT gctUINT shaderCycles;
951 OUT gctUINT vsInstructionCount;
952 OUT gctUINT vsTextureCount;
953 OUT gctUINT psInstructionCount;
954 OUT gctUINT psTextureCount;
956 /* Texture counters. */
957 OUT gctUINT bilinearRequests;
958 OUT gctUINT trilinearRequests;
959 OUT gctUINT txBytes8;
960 OUT gctUINT txHitCount;
961 OUT gctUINT txMissCount;
963 gcsHAL_FRAME_INFO;
965 #ifdef __cplusplus
967 #endif
969 #endif /* __gc_hal_types_h_ */