2 * Author: Max Lingua <sunmax@libero.it>
12 #define GENERIC_DEBUG 0
14 #define DMABUFS_DEBUG 0
16 /* Note: The argument to DEBUG*() _must_ be enclosed in parenthesis */
18 #if (GENERIC_DEBUG || FLOW_DEBUG || DMABUFS_DEBUG)
23 #define DEBUG(str) printf str
29 #define DEBUG_WHERE(str) printf str
31 #define DEBUG_WHERE(str)
35 #define DEBUG_BUFS(str) printf str
37 #define DEBUG_BUFS(str)
42 #define S3V_DMA_SEND_FLAGS DRM_DMA_PRIORITY
43 #define S3V_DMA_SEND_FLAGS DRM_DMA_BLOCK
45 #define S3V_DMA_SEND_FLAGS 0
49 #define S3V_DMA_GET_FLAGS \
50 (DRM_DMA_SMALLER_OK | DRM_DMA_LARGER_OK | DRM_DMA_WAIT)
52 #define S3V_DMA_GET_FLAGS DRM_DMA_WAIT
56 #define DMAOUT_CHECK(reg,len) \
58 DEBUG(("DMAOUT_CHECK: reg = 0x%x\n", S3V_##reg##_REG)); \
59 DEBUG_BUFS(("DMAOUT_CHECK (was): ")); \
60 DEBUG_BUFS(("vmesa->bufCount=%i of vmesa->bufSize=%i\n", \
61 vmesa->bufCount, vmesa->bufSize)); \
62 /* FIXME: > or >= */ \
63 if (vmesa->bufCount+(len+1) >= vmesa->bufSize) \
66 vmesa->bufCount += (len+1); \
67 DEBUG_BUFS(("DMAOUT_CHECK (is): vmesa->bufCount=%i len=%i, reg=%x\n", \
68 vmesa->bufCount, len, S3V_##reg##_REG)); \
69 DMAOUT( ((len & 0xffff) | ((S3V_##reg##_REG & 0xfffc) << 14)) ); \
74 *(vmesa->buf++)=val; \
75 DEBUG_BUFS(("DMAOUT: val=0x%x\n", (unsigned int)val)); \
80 /* NOTE: it does nothing - it just prints some summary infos */ \
81 DEBUG(("DMAFINISH: vmesa->bufCount=%i\n", vmesa->bufCount)); \
82 DEBUG(("buf: index=%i; addr=%p\n", vmesa->bufIndex[vmesa->_bufNum], \
83 vmesa->s3vScreen->bufs->list[vmesa->bufIndex[vmesa->_bufNum]].address)); \
88 if (vmesa->bufCount) { \
89 SEND_DMA(vmesa->driFd, vmesa->hHWContext, 1, \
90 &vmesa->bufIndex[vmesa->_bufNum], &vmesa->bufCount); \
92 GET_DMA(vmesa->driFd, vmesa->hHWContext, 1, \
93 &vmesa->bufIndex, &vmesa->bufSize); \
95 vmesa->_bufNum = !(vmesa->_bufNum); \
96 vmesa->buf = vmesa->_buf[vmesa->_bufNum]; \
99 vmesa->s3vScreen->bufs->list[vmesa->bufIndex].address; \
101 vmesa->bufCount = 0; \
105 #define CMDCHANGE() \
107 DMAOUT_CHECK(3DTRI_CMDSET, 1); /* FIXME: TRI/LINE */ \
108 DMAOUT(vmesa->CMD); \
113 #define GET_DMA(fd, hHWCtx, n, idx, size)
114 #define SEND_DMA(fd, hHWCtx,n, idx, cnt)
116 #define GET_DMA(fd, hHWCtx, n, idx, size) \
121 DEBUG(("GET_DMA: ")); \
122 DEBUG(("req_count=%i; req_list[#0]=%i; req_size[#0]=%i\n", \
123 n, (idx)[n-1], (size)[n-1])); \
125 dma.context = (hHWCtx); \
126 dma.send_count = 0; \
127 dma.send_list = NULL; \
128 dma.send_sizes = NULL; \
129 dma.flags = S3V_DMA_GET_FLAGS; \
130 dma.request_count = (n); \
131 dma.request_size = S3V_DMA_BUF_SZ; \
132 dma.request_list = (idx); \
133 dma.request_sizes = (size); \
136 if ((retcode = drmDMA((fd), &dma))) { \
137 DEBUG_BUFS(("drmDMA (get) returned %d\n", retcode)); \
139 } while (!(dma).granted_count); \
141 for (i = 0; i < (n); i++) { \
142 DEBUG(("Got buffer %i (index #%i)\n", (idx)[i], i)); \
143 DEBUG(("of %i bytes (%i words) size\n", \
144 (size)[i], (size)[i] >>2)); \
145 /* Convert from bytes to words */ \
150 #define SEND_DMA(fd, hHWCtx, n, idx, cnt) \
155 DEBUG(("SEND_DMA: ")); \
156 DEBUG(("send_count=%i; send_list[#0]=%i; send_sizes[#0]=%i\n", \
157 n, (idx)[n-1], (cnt)[n-1])); \
159 for (i = 0; i < (n); i++) { \
160 /* Convert from words to bytes */ \
164 dma.context = (hHWCtx); \
165 dma.send_count = (n); \
166 dma.send_list = (idx); \
167 dma.send_sizes = (cnt); \
168 dma.flags = S3V_DMA_SEND_FLAGS; \
169 dma.request_count = 0; \
170 dma.request_size = 0; \
171 dma.request_list = NULL; \
172 dma.request_sizes = NULL; \
174 if ((retcode = drmDMA((fd), &dma))) { \
175 DEBUG_BUFS(("drmDMA (send) returned %d\n", retcode)); \
178 for (i = 0; i < (n); i++) { \
179 DEBUG(("Sent buffer %i (index #%i)\n", (idx)[i], i)); \
180 DEBUG(("of %i bytes (%i words) size\n", \
181 (cnt)[i], (cnt)[i] >>2)); \
185 #endif /* DONT_SEND_DMA */
187 #define GET_FIRST_DMA(fd, hHWCtx, n, idx, size, buf, cnt, vPriv) \
190 DEBUG_BUFS(("GET_FIRST_DMA\n")); \
191 DEBUG_BUFS(("n=%i idx=%i size=%i\n", n, *idx, *size)); \
192 DEBUG_BUFS(("going to GET_DMA\n")); \
193 GET_DMA(fd, hHWCtx, n, idx, size); \
194 DEBUG_BUFS(("coming from GET_DMA\n")); \
195 DEBUG_BUFS(("n=%i idx=%i size=%i\n", n, (idx)[0], (size)[0])); \
196 for (i = 0; i < (n); i++) { \
197 DEBUG_BUFS(("buf #%i @%p\n", \
198 i, (vPriv)->bufs->list[(idx)[i]].address)); \
199 (buf)[i] = (vPriv)->bufs->list[(idx)[i]].address; \
202 DEBUG(("GOING HOME\n")); \
205 /**************************/
206 /* generic, global macros */
207 /**************************/
209 #define CALC_LOG2(l2,s) \
213 while (__s > 1) { ++l2; __s >>= 1; } \
216 #define PrimType_Null 0x00000000
217 #define PrimType_Points 0x10000000
218 #define PrimType_Lines 0x20000000
219 #define PrimType_LineLoop 0x30000000
220 #define PrimType_LineStrip 0x40000000
221 #define PrimType_Triangles 0x50000000
222 #define PrimType_TriangleStrip 0x60000000
223 #define PrimType_TriangleFan 0x70000000
224 #define PrimType_Quads 0x80000000
225 #define PrimType_QuadStrip 0x90000000
226 #define PrimType_Polygon 0xa0000000
227 #define PrimType_Mask 0xf0000000
229 #endif /* _S3V_MACROS_H_ */