1 /*
2  * Copyright (C) Thomas Hellstrom (2005)
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sub license,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef VIA_DMABUFFER_H
25 #define VIA_DMABUFFER_H
26 
27 #include "via_3d_reg.h"
28 
29 typedef struct _ViaCommandBuffer
30 {
31     ScrnInfoPtr pScrn;
32     CARD32 *buf;
33     CARD32 waitFlags;
34     unsigned pos;
35     unsigned bufSize;
36     int mode;
37     int header_start;
38     int rindex;
39     Bool has3dState;
40     void (*flushFunc) (struct _ViaCommandBuffer * cb);
41 } ViaCommandBuffer;
42 
43 #define VIA_DMASIZE 16384
44 
45 #define H1_ADDR(val) (((val) >> 2) | 0xF0000000)
46 #define WAITFLAGS(flags)			\
47     (cb)->waitFlags |= (flags)
48 
49 #define BEGIN_RING(size)					\
50     do {								\
51 	if (cb->flushFunc && (cb->pos > (cb->bufSize-(size)))) {	\
52 	    cb->flushFunc(cb);					\
53 	}								\
54     } while(0)
55 
56 #define BEGIN_H2(paraType, h2size)			\
57   do{							\
58     BEGIN_RING((h2size)+6);				\
59     if (cb->mode == 2 && (paraType) == cb->rindex)	\
60       break;						\
61     if (cb->pos & 1)					\
62       OUT_RING(HC_DUMMY);				\
63     cb->header_start = cb->pos;				\
64     cb->rindex = paraType;				\
65     cb->mode = 2;					\
66     OUT_RING(HALCYON_HEADER2);				\
67     OUT_RING((paraType) << 16);						\
68     if (!cb->has3dState && ((paraType) != HC_ParaType_CmdVdata)) {	\
69       cb->has3dState = TRUE;						\
70     }									\
71   } while(0);
72 
73 #define OUT_RING(val) do{	\
74 	(cb)->buf[(cb)->pos++] = (val);	\
75     } while(0);
76 
77 #define OUT_RING_QW(val1, val2)			\
78     do {						\
79 	(cb)->buf[(cb)->pos++] = (val1);		\
80 	(cb)->buf[(cb)->pos++] = (val2);		\
81     } while (0)
82 
83 #define ADVANCE_RING \
84   cb->flushFunc(cb)
85 
86 #define RING_VARS \
87   ViaCommandBuffer *cb = &pVia->cb
88 
89 #define OUT_RING_H1(val1, val2) \
90   OUT_RING_QW(H1_ADDR(val1), val2)
91 
92 #define OUT_RING_SubA(val1, val2) \
93   OUT_RING(((val1) << HC_SubA_SHIFT) | ((val2) & HC_Para_MASK))
94 
95 #endif
96