Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / s3v / s3v_macros.h
1 /*
2 * Author: Max Lingua <sunmax@libero.it>
3 */
4
5 #ifndef _S3V_MACROS_H_
6 #define _S3V_MACROS_H_
7
8 /**************/
9 /* DRI macros */
10 /**************/
11
12 #define GENERIC_DEBUG 0
13 #define FLOW_DEBUG 0
14 #define DMABUFS_DEBUG 0
15
16 /* Note: The argument to DEBUG*() _must_ be enclosed in parenthesis */
17
18 #if (GENERIC_DEBUG || FLOW_DEBUG || DMABUFS_DEBUG)
19 #include <stdio.h>
20 #endif
21
22 #undef DEBUG
23 #if GENERIC_DEBUG
24 #define DEBUG(str) printf str
25 #else
26 #define DEBUG(str)
27 #endif
28
29 #if FLOW_DEBUG
30 #define DEBUG_WHERE(str) printf str
31 #else
32 #define DEBUG_WHERE(str)
33 #endif
34
35 #if DMABUFS_DEBUG
36 #define DEBUG_BUFS(str) printf str
37 #else
38 #define DEBUG_BUFS(str)
39 #endif
40
41
42 #if 0
43 #define S3V_DMA_SEND_FLAGS DRM_DMA_PRIORITY
44 #define S3V_DMA_SEND_FLAGS DRM_DMA_BLOCK
45 #else
46 #define S3V_DMA_SEND_FLAGS 0
47 #endif
48
49 #if 0
50 #define S3V_DMA_GET_FLAGS \
51 (DRM_DMA_SMALLER_OK | DRM_DMA_LARGER_OK | DRM_DMA_WAIT)
52 #else
53 #define S3V_DMA_GET_FLAGS DRM_DMA_WAIT
54 #endif
55
56
57 #define DMAOUT_CHECK(reg,len) \
58 do { \
59 DEBUG(("DMAOUT_CHECK: reg = 0x%x\n", S3V_##reg##_REG)); \
60 DEBUG_BUFS(("DMAOUT_CHECK (was): ")); \
61 DEBUG_BUFS(("vmesa->bufCount=%i of vmesa->bufSize=%i\n", \
62 vmesa->bufCount, vmesa->bufSize)); \
63 /* FIXME: > or >= */ \
64 if (vmesa->bufCount+(len+1) >= vmesa->bufSize) \
65 DMAFLUSH(); \
66 \
67 vmesa->bufCount += (len+1); \
68 DEBUG_BUFS(("DMAOUT_CHECK (is): vmesa->bufCount=%i len=%i, reg=%x\n", \
69 vmesa->bufCount, len, S3V_##reg##_REG)); \
70 DMAOUT( ((len & 0xffff) | ((S3V_##reg##_REG & 0xfffc) << 14)) ); \
71 } while (0)
72
73 #define DMAOUT(val) \
74 do { \
75 *(vmesa->buf++)=val; \
76 DEBUG_BUFS(("DMAOUT: val=0x%x\n", (unsigned int)val)); \
77 } while(0)
78
79 #define DMAFINISH() \
80 do { \
81 /* NOTE: it does nothing - it just prints some summary infos */ \
82 DEBUG(("DMAFINISH: vmesa->bufCount=%i\n", vmesa->bufCount)); \
83 DEBUG(("buf: index=%i; addr=%p\n", vmesa->bufIndex[vmesa->_bufNum], \
84 vmesa->s3vScreen->bufs->list[vmesa->bufIndex[vmesa->_bufNum]].address)); \
85 } while(0)
86
87 #define DMAFLUSH() \
88 do { \
89 if (vmesa->bufCount) { \
90 SEND_DMA(vmesa->driFd, vmesa->hHWContext, 1, \
91 &vmesa->bufIndex[vmesa->_bufNum], &vmesa->bufCount); \
92 /*
93 GET_DMA(vmesa->driFd, vmesa->hHWContext, 1, \
94 &vmesa->bufIndex, &vmesa->bufSize); \
95 */ \
96 vmesa->_bufNum = !(vmesa->_bufNum); \
97 vmesa->buf = vmesa->_buf[vmesa->_bufNum]; \
98 /*
99 vmesa->buf = \
100 vmesa->s3vScreen->bufs->list[vmesa->bufIndex].address; \
101 */ \
102 vmesa->bufCount = 0; \
103 } \
104 } while (0)
105
106 #define CMDCHANGE() \
107 do { \
108 DMAOUT_CHECK(3DTRI_CMDSET, 1); /* FIXME: TRI/LINE */ \
109 DMAOUT(vmesa->CMD); \
110 DMAFINISH(); \
111 } while (0)
112
113 #ifdef DONT_SEND_DMA
114 #define GET_DMA(fd, hHWCtx, n, idx, size)
115 #define SEND_DMA(fd, hHWCtx,n, idx, cnt)
116 #else
117 #define GET_DMA(fd, hHWCtx, n, idx, size) \
118 do { \
119 drmDMAReq dma; \
120 int retcode, i; \
121 \
122 DEBUG(("GET_DMA: ")); \
123 DEBUG(("req_count=%i; req_list[#0]=%i; req_size[#0]=%i\n", \
124 n, (idx)[n-1], (size)[n-1])); \
125 \
126 dma.context = (hHWCtx); \
127 dma.send_count = 0; \
128 dma.send_list = NULL; \
129 dma.send_sizes = NULL; \
130 dma.flags = S3V_DMA_GET_FLAGS; \
131 dma.request_count = (n); \
132 dma.request_size = S3V_DMA_BUF_SZ; \
133 dma.request_list = (idx); \
134 dma.request_sizes = (size); \
135 \
136 do { \
137 if ((retcode = drmDMA((fd), &dma))) { \
138 DEBUG_BUFS(("drmDMA (get) returned %d\n", retcode)); \
139 } \
140 } while (!(dma).granted_count); \
141 \
142 for (i = 0; i < (n); i++) { \
143 DEBUG(("Got buffer %i (index #%i)\n", (idx)[i], i)); \
144 DEBUG(("of %i bytes (%i words) size\n", \
145 (size)[i], (size)[i] >>2)); \
146 /* Convert from bytes to words */ \
147 (size)[i] >>= 2; \
148 } \
149 } while (0)
150
151 #define SEND_DMA(fd, hHWCtx, n, idx, cnt) \
152 do { \
153 drmDMAReq dma; \
154 int retcode, i; \
155 \
156 DEBUG(("SEND_DMA: ")); \
157 DEBUG(("send_count=%i; send_list[#0]=%i; send_sizes[#0]=%i\n", \
158 n, (idx)[n-1], (cnt)[n-1])); \
159 \
160 for (i = 0; i < (n); i++) { \
161 /* Convert from words to bytes */ \
162 (cnt)[i] <<= 2; \
163 } \
164 \
165 dma.context = (hHWCtx); \
166 dma.send_count = (n); \
167 dma.send_list = (idx); \
168 dma.send_sizes = (cnt); \
169 dma.flags = S3V_DMA_SEND_FLAGS; \
170 dma.request_count = 0; \
171 dma.request_size = 0; \
172 dma.request_list = NULL; \
173 dma.request_sizes = NULL; \
174 \
175 if ((retcode = drmDMA((fd), &dma))) { \
176 DEBUG_BUFS(("drmDMA (send) returned %d\n", retcode)); \
177 } \
178 \
179 for (i = 0; i < (n); i++) { \
180 DEBUG(("Sent buffer %i (index #%i)\n", (idx)[i], i)); \
181 DEBUG(("of %i bytes (%i words) size\n", \
182 (cnt)[i], (cnt)[i] >>2)); \
183 (cnt)[i] = 0; \
184 } \
185 } while (0)
186 #endif /* DONT_SEND_DMA */
187
188 #define GET_FIRST_DMA(fd, hHWCtx, n, idx, size, buf, cnt, vPriv) \
189 do { \
190 int i; \
191 DEBUG_BUFS(("GET_FIRST_DMA\n")); \
192 DEBUG_BUFS(("n=%i idx=%i size=%i\n", n, *idx, *size)); \
193 DEBUG_BUFS(("going to GET_DMA\n")); \
194 GET_DMA(fd, hHWCtx, n, idx, size); \
195 DEBUG_BUFS(("coming from GET_DMA\n")); \
196 DEBUG_BUFS(("n=%i idx=%i size=%i\n", n, (idx)[0], (size)[0])); \
197 for (i = 0; i < (n); i++) { \
198 DEBUG_BUFS(("buf #%i @%p\n", \
199 i, (vPriv)->bufs->list[(idx)[i]].address)); \
200 (buf)[i] = (vPriv)->bufs->list[(idx)[i]].address; \
201 (cnt)[i] = 0; \
202 } \
203 DEBUG(("GOING HOME\n")); \
204 } while (0)
205
206 /**************************/
207 /* generic, global macros */
208 /**************************/
209
210 #define CALC_LOG2(l2,s) \
211 do { \
212 int __s = s; \
213 l2 = 0; \
214 while (__s > 1) { ++l2; __s >>= 1; } \
215 } while (0)
216
217 #define PrimType_Null 0x00000000
218 #define PrimType_Points 0x10000000
219 #define PrimType_Lines 0x20000000
220 #define PrimType_LineLoop 0x30000000
221 #define PrimType_LineStrip 0x40000000
222 #define PrimType_Triangles 0x50000000
223 #define PrimType_TriangleStrip 0x60000000
224 #define PrimType_TriangleFan 0x70000000
225 #define PrimType_Quads 0x80000000
226 #define PrimType_QuadStrip 0x90000000
227 #define PrimType_Polygon 0xa0000000
228 #define PrimType_Mask 0xf0000000
229
230 #endif /* _S3V_MACROS_H_ */