GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / xgifb / XGI_accel.h
blobd7cef6ef44a17261a176f7b99a997712f4de0528
1 /*
2 * XGI 300/630/730/540/315/550/650/740 frame buffer driver
3 * for Linux kernels 2.4.x and 2.5.x
5 * 2D acceleration part
7 * Based on the X driver's XGI300_accel.h which is
8 * Copyright Xavier Ducoin <x.ducoin@lectra.com>
9 * Copyright 2002 by Thomas Winischhofer, Vienna, Austria
10 * and XGI310_accel.h which is
11 * Copyright 2002 by Thomas Winischhofer, Vienna, Austria
13 * Author: Thomas Winischhofer <thomas@winischhofer.net>:
14 * (see http://www.winischhofer.net/
15 * for more information and updates)
18 #ifndef _XGIFB_ACCEL_H
19 #define _XGIFB_ACCEL_H
21 /* Guard accelerator accesses with spin_lock_irqsave? Works well without. */
22 #undef XGIFB_USE_SPINLOCKS
24 #ifdef XGIFB_USE_SPINLOCKS
25 #include <linux/spinlock.h>
26 #define CRITBEGIN spin_lock_irqsave(&xgi_video_info.lockaccel), critflags);
27 #define CRITEND spin_unlock_irqrestore(&xgi_video_info.lockaccel), critflags);
28 #define CRITFLAGS unsigned long critflags;
29 #else
30 #define CRITBEGIN
31 #define CRITEND
32 #define CRITFLAGS
33 #endif
35 /* Definitions for the XGI engine communication. */
37 #define PATREGSIZE 384 /* Pattern register size. 384 bytes @ 0x8300 */
38 #define BR(x) (0x8200 | (x) << 2)
39 #define PBR(x) (0x8300 | (x) << 2)
41 /* XGI300 engine commands */
42 #define BITBLT 0x00000000 /* Blit */
43 #define COLOREXP 0x00000001 /* Color expand */
44 #define ENCOLOREXP 0x00000002 /* Enhanced color expand */
45 #define MULTIPLE_SCANLINE 0x00000003 /* ? */
46 #define LINE 0x00000004 /* Draw line */
47 #define TRAPAZOID_FILL 0x00000005 /* Fill trapezoid */
48 #define TRANSPARENT_BITBLT 0x00000006 /* Transparent Blit */
50 /* Additional engine commands for 310/325 */
51 #define ALPHA_BLEND 0x00000007 /* Alpha blend ? */
52 #define A3D_FUNCTION 0x00000008 /* 3D command ? */
53 #define CLEAR_Z_BUFFER 0x00000009 /* ? */
54 #define GRADIENT_FILL 0x0000000A /* Gradient fill */
55 #define STRETCH_BITBLT 0x0000000B /* Stretched Blit */
57 /* source select */
58 #define SRCVIDEO 0x00000000 /* source is video RAM */
59 #define SRCSYSTEM 0x00000010 /* source is system memory */
60 #define SRCCPUBLITBUF SRCSYSTEM /* source is CPU-driven BitBuffer (for color expand) */
61 #define SRCAGP 0x00000020 /* source is AGP memory (?) */
63 /* Pattern flags */
64 #define PATFG 0x00000000 /* foreground color */
65 #define PATPATREG 0x00000040 /* pattern in pattern buffer (0x8300) */
66 #define PATMONO 0x00000080 /* mono pattern */
68 /* blitting direction (300 series only) */
69 #define X_INC 0x00010000
70 #define X_DEC 0x00000000
71 #define Y_INC 0x00020000
72 #define Y_DEC 0x00000000
74 /* Clipping flags */
75 #define NOCLIP 0x00000000
76 #define NOMERGECLIP 0x04000000
77 #define CLIPENABLE 0x00040000
78 #define CLIPWITHOUTMERGE 0x04040000
80 /* Transparency */
81 #define OPAQUE 0x00000000
82 #define TRANSPARENT 0x00100000
84 /* ? */
85 #define DSTAGP 0x02000000
86 #define DSTVIDEO 0x02000000
88 /* Line */
89 #define LINE_STYLE 0x00800000
90 #define NO_RESET_COUNTER 0x00400000
91 #define NO_LAST_PIXEL 0x00200000
93 /* Subfunctions for Color/Enhanced Color Expansion (310/325 only) */
94 #define COLOR_TO_MONO 0x00100000
95 #define AA_TEXT 0x00200000
97 /* Some general registers for 310/325 series */
98 #define SRC_ADDR 0x8200
99 #define SRC_PITCH 0x8204
100 #define AGP_BASE 0x8206 /* color-depth dependent value */
101 #define SRC_Y 0x8208
102 #define SRC_X 0x820A
103 #define DST_Y 0x820C
104 #define DST_X 0x820E
105 #define DST_ADDR 0x8210
106 #define DST_PITCH 0x8214
107 #define DST_HEIGHT 0x8216
108 #define RECT_WIDTH 0x8218
109 #define RECT_HEIGHT 0x821A
110 #define PAT_FGCOLOR 0x821C
111 #define PAT_BGCOLOR 0x8220
112 #define SRC_FGCOLOR 0x8224
113 #define SRC_BGCOLOR 0x8228
114 #define MONO_MASK 0x822C
115 #define LEFT_CLIP 0x8234
116 #define TOP_CLIP 0x8236
117 #define RIGHT_CLIP 0x8238
118 #define BOTTOM_CLIP 0x823A
119 #define COMMAND_READY 0x823C
120 #define FIRE_TRIGGER 0x8240
122 #define PATTERN_REG 0x8300 /* 384 bytes pattern buffer */
124 /* Line registers */
125 #define LINE_X0 SRC_Y
126 #define LINE_X1 DST_Y
127 #define LINE_Y0 SRC_X
128 #define LINE_Y1 DST_X
129 #define LINE_COUNT RECT_WIDTH
130 #define LINE_STYLE_PERIOD RECT_HEIGHT
131 #define LINE_STYLE_0 MONO_MASK
132 #define LINE_STYLE_1 0x8230
133 #define LINE_XN PATTERN_REG
134 #define LINE_YN PATTERN_REG+2
136 /* Transparent bitblit registers */
137 #define TRANS_DST_KEY_HIGH PAT_FGCOLOR
138 #define TRANS_DST_KEY_LOW PAT_BGCOLOR
139 #define TRANS_SRC_KEY_HIGH SRC_FGCOLOR
140 #define TRANS_SRC_KEY_LOW SRC_BGCOLOR
142 /* Queue */
143 #define Q_BASE_ADDR 0x85C0 /* Base address of software queue (?) */
144 #define Q_WRITE_PTR 0x85C4 /* Current write pointer (?) */
145 #define Q_READ_PTR 0x85C8 /* Current read pointer (?) */
146 #define Q_STATUS 0x85CC /* queue status */
149 #define MMIO_IN8(base, offset) \
150 *(volatile u8 *)(((u8*)(base)) + (offset))
151 #define MMIO_IN16(base, offset) \
152 *(volatile u16 *)(void *)(((u8*)(base)) + (offset))
153 #define MMIO_IN32(base, offset) \
154 *(volatile u32 *)(void *)(((u8*)(base)) + (offset))
155 #define MMIO_OUT8(base, offset, val) \
156 *(volatile u8 *)(((u8*)(base)) + (offset)) = (val)
157 #define MMIO_OUT16(base, offset, val) \
158 *(volatile u16 *)(void *)(((u8*)(base)) + (offset)) = (val)
159 #define MMIO_OUT32(base, offset, val) \
160 *(volatile u32 *)(void *)(((u8*)(base)) + (offset)) = (val)
164 /* ------------- XGI 300 series -------------- */
166 /* Macros to do useful things with the XGI BitBLT engine */
168 /* BR(16) (0x8420):
170 bit 31 2D engine: 1 is idle,
171 bit 30 3D engine: 1 is idle,
172 bit 29 Command queue: 1 is empty
174 bits 28:24: Current CPU driven BitBlt buffer stage bit[4:0]
176 bits 15:0: Current command queue length
180 /* TW: BR(16)+2 = 0x8242 */
182 int xgiCmdQueLen;
184 #define XGI300Idle \
186 while( (MMIO_IN16(xgi_video_info.mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
187 while( (MMIO_IN16(xgi_video_info.mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
188 while( (MMIO_IN16(xgi_video_info.mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
189 xgiCmdQueLen=MMIO_IN16(xgi_video_info.mmio_vbase, 0x8240); \
191 /* TW: (do three times, because 2D engine seems quite unsure about whether or not it's idle) */
193 #define XGI300SetupSRCBase(base) \
194 if (xgiCmdQueLen <= 0) XGI300Idle;\
195 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(0), base);\
196 xgiCmdQueLen --;
198 #define XGI300SetupSRCPitch(pitch) \
199 if (xgiCmdQueLen <= 0) XGI300Idle;\
200 MMIO_OUT16(xgi_video_info.mmio_vbase, BR(1), pitch);\
201 xgiCmdQueLen --;
203 #define XGI300SetupSRCXY(x,y) \
204 if (xgiCmdQueLen <= 0) XGI300Idle;\
205 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(2), (x)<<16 | (y) );\
206 xgiCmdQueLen --;
208 #define XGI300SetupDSTBase(base) \
209 if (xgiCmdQueLen <= 0) XGI300Idle;\
210 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(4), base);\
211 xgiCmdQueLen --;
213 #define XGI300SetupDSTXY(x,y) \
214 if (xgiCmdQueLen <= 0) XGI300Idle;\
215 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(3), (x)<<16 | (y) );\
216 xgiCmdQueLen --;
218 #define XGI300SetupDSTRect(x,y) \
219 if (xgiCmdQueLen <= 0) XGI300Idle;\
220 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(5), (y)<<16 | (x) );\
221 xgiCmdQueLen --;
223 #define XGI300SetupDSTColorDepth(bpp) \
224 if (xgiCmdQueLen <= 0) XGI300Idle;\
225 MMIO_OUT16(xgi_video_info.mmio_vbase, BR(1)+2, bpp);\
226 xgiCmdQueLen --;
228 #define XGI300SetupRect(w,h) \
229 if (xgiCmdQueLen <= 0) XGI300Idle;\
230 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(6), (h)<<16 | (w) );\
231 xgiCmdQueLen --;
233 #define XGI300SetupPATFG(color) \
234 if (xgiCmdQueLen <= 0) XGI300Idle;\
235 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(7), color);\
236 xgiCmdQueLen --;
238 #define XGI300SetupPATBG(color) \
239 if (xgiCmdQueLen <= 0) XGI300Idle;\
240 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(8), color);\
241 xgiCmdQueLen --;
243 #define XGI300SetupSRCFG(color) \
244 if (xgiCmdQueLen <= 0) XGI300Idle;\
245 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(9), color);\
246 xgiCmdQueLen --;
248 #define XGI300SetupSRCBG(color) \
249 if (xgiCmdQueLen <= 0) XGI300Idle;\
250 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(10), color);\
251 xgiCmdQueLen --;
253 /* 0x8224 src colorkey high */
254 /* 0x8228 src colorkey low */
255 /* 0x821c dest colorkey high */
256 /* 0x8220 dest colorkey low */
257 #define XGI300SetupSRCTrans(color) \
258 if (xgiCmdQueLen <= 1) XGI300Idle;\
259 MMIO_OUT32(xgi_video_info.mmio_vbase, 0x8224, color);\
260 MMIO_OUT32(xgi_video_info.mmio_vbase, 0x8228, color);\
261 xgiCmdQueLen -= 2;
263 #define XGI300SetupDSTTrans(color) \
264 if (xgiCmdQueLen <= 1) XGI300Idle;\
265 MMIO_OUT32(xgi_video_info.mmio_vbase, 0x821C, color); \
266 MMIO_OUT32(xgi_video_info.mmio_vbase, 0x8220, color); \
267 xgiCmdQueLen -= 2;
269 #define XGI300SetupMONOPAT(p0,p1) \
270 if (xgiCmdQueLen <= 1) XGI300Idle;\
271 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(11), p0);\
272 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(12), p1);\
273 xgiCmdQueLen -= 2;
275 #define XGI300SetupClipLT(left,top) \
276 if (xgiCmdQueLen <= 0) XGI300Idle;\
277 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(13), ((left) & 0xFFFF) | (top)<<16 );\
278 xgiCmdQueLen--;
280 #define XGI300SetupClipRB(right,bottom) \
281 if (xgiCmdQueLen <= 0) XGI300Idle;\
282 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(14), ((right) & 0xFFFF) | (bottom)<<16 );\
283 xgiCmdQueLen--;
285 /* General */
286 #define XGI300SetupROP(rop) \
287 xgi_video_info.CommandReg = (rop) << 8;
289 #define XGI300SetupCMDFlag(flags) \
290 xgi_video_info.CommandReg |= (flags);
292 #define XGI300DoCMD \
293 if (xgiCmdQueLen <= 1) XGI300Idle;\
294 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(15), xgi_video_info.CommandReg); \
295 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(16), 0);\
296 xgiCmdQueLen -= 2;
298 /* Line */
299 #define XGI300SetupX0Y0(x,y) \
300 if (xgiCmdQueLen <= 0) XGI300Idle;\
301 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(2), (y)<<16 | (x) );\
302 xgiCmdQueLen--;
304 #define XGI300SetupX1Y1(x,y) \
305 if (xgiCmdQueLen <= 0) XGI300Idle;\
306 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(3), (y)<<16 | (x) );\
307 xgiCmdQueLen--;
309 #define XGI300SetupLineCount(c) \
310 if (xgiCmdQueLen <= 0) XGI300Idle;\
311 MMIO_OUT16(xgi_video_info.mmio_vbase, BR(6), c);\
312 xgiCmdQueLen--;
314 #define XGI300SetupStylePeriod(p) \
315 if (xgiCmdQueLen <= 0) XGI300Idle;\
316 MMIO_OUT16(xgi_video_info.mmio_vbase, BR(6)+2, p);\
317 xgiCmdQueLen--;
319 #define XGI300SetupStyleLow(ls) \
320 if (xgiCmdQueLen <= 0) XGI300Idle;\
321 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(11), ls);\
322 xgiCmdQueLen--;
324 #define XGI300SetupStyleHigh(ls) \
325 if (xgiCmdQueLen <= 0) XGI300Idle;\
326 MMIO_OUT32(xgi_video_info.mmio_vbase, BR(12), ls);\
327 xgiCmdQueLen--;
331 /* ----------- XGI 310/325 series --------------- */
333 /* Q_STATUS:
334 bit 31 = 1: All engines idle and all queues empty
335 bit 30 = 1: Hardware Queue (=HW CQ, 2D queue, 3D queue) empty
336 bit 29 = 1: 2D engine is idle
337 bit 28 = 1: 3D engine is idle
338 bit 27 = 1: HW command queue empty
339 bit 26 = 1: 2D queue empty
340 bit 25 = 1: 3D queue empty
341 bit 24 = 1: SW command queue empty
342 bits 23:16: 2D counter 3
343 bits 15:8: 2D counter 2
344 bits 7:0: 2D counter 1
346 Where is the command queue length (current amount of commands the queue
347 can accept) on the 310/325 series? (The current implementation is taken
348 from 300 series and certainly wrong...)
351 #define XGI310Idle \
353 while( (MMIO_IN16(xgi_video_info.mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
354 while( (MMIO_IN16(xgi_video_info.mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
355 xgiCmdQueLen=MMIO_IN16(xgi_video_info.mmio_vbase, Q_STATUS); \
358 #define XGI310SetupSRCBase(base) \
359 if (xgiCmdQueLen <= 0) XGI310Idle;\
360 MMIO_OUT32(xgi_video_info.mmio_vbase, SRC_ADDR, base);\
361 xgiCmdQueLen--;
363 #define XGI310SetupSRCPitch(pitch) \
364 if (xgiCmdQueLen <= 0) XGI310Idle;\
365 MMIO_OUT16(xgi_video_info.mmio_vbase, SRC_PITCH, pitch);\
366 xgiCmdQueLen--;
368 #define XGI310SetupSRCXY(x,y) \
369 if (xgiCmdQueLen <= 0) XGI310Idle;\
370 MMIO_OUT32(xgi_video_info.mmio_vbase, SRC_Y, (x)<<16 | (y) );\
371 xgiCmdQueLen--;
373 #define XGI310SetupDSTBase(base) \
374 if (xgiCmdQueLen <= 0) XGI310Idle;\
375 MMIO_OUT32(xgi_video_info.mmio_vbase, DST_ADDR, base);\
376 xgiCmdQueLen--;
378 #define XGI310SetupDSTXY(x,y) \
379 if (xgiCmdQueLen <= 0) XGI310Idle;\
380 MMIO_OUT32(xgi_video_info.mmio_vbase, DST_Y, (x)<<16 | (y) );\
381 xgiCmdQueLen--;
383 #define XGI310SetupDSTRect(x,y) \
384 if (xgiCmdQueLen <= 0) XGI310Idle;\
385 MMIO_OUT32(xgi_video_info.mmio_vbase, DST_PITCH, (y)<<16 | (x) );\
386 xgiCmdQueLen--;
388 #define XGI310SetupDSTColorDepth(bpp) \
389 if (xgiCmdQueLen <= 0) XGI310Idle;\
390 MMIO_OUT16(xgi_video_info.mmio_vbase, AGP_BASE, bpp);\
391 xgiCmdQueLen--;
393 #define XGI310SetupRect(w,h) \
394 if (xgiCmdQueLen <= 0) XGI310Idle;\
395 MMIO_OUT32(xgi_video_info.mmio_vbase, RECT_WIDTH, (h)<<16 | (w) );\
396 xgiCmdQueLen--;
398 #define XGI310SetupPATFG(color) \
399 if (xgiCmdQueLen <= 0) XGI310Idle;\
400 MMIO_OUT32(xgi_video_info.mmio_vbase, PAT_FGCOLOR, color);\
401 xgiCmdQueLen--;
403 #define XGI310SetupPATBG(color) \
404 if (xgiCmdQueLen <= 0) XGI310Idle;\
405 MMIO_OUT32(xgi_video_info.mmio_vbase, PAT_BGCOLOR, color);\
406 xgiCmdQueLen--;
408 #define XGI310SetupSRCFG(color) \
409 if (xgiCmdQueLen <= 0) XGI310Idle;\
410 MMIO_OUT32(xgi_video_info.mmio_vbase, SRC_FGCOLOR, color);\
411 xgiCmdQueLen--;
413 #define XGI310SetupSRCBG(color) \
414 if (xgiCmdQueLen <= 0) XGI310Idle;\
415 MMIO_OUT32(xgi_video_info.mmio_vbase, SRC_BGCOLOR, color);\
416 xgiCmdQueLen--;
418 #define XGI310SetupSRCTrans(color) \
419 if (xgiCmdQueLen <= 1) XGI310Idle;\
420 MMIO_OUT32(xgi_video_info.mmio_vbase, TRANS_SRC_KEY_HIGH, color);\
421 MMIO_OUT32(xgi_video_info.mmio_vbase, TRANS_SRC_KEY_LOW, color);\
422 xgiCmdQueLen -= 2;
424 #define XGI310SetupDSTTrans(color) \
425 if (xgiCmdQueLen <= 1) XGI310Idle;\
426 MMIO_OUT32(xgi_video_info.mmio_vbase, TRANS_DST_KEY_HIGH, color); \
427 MMIO_OUT32(xgi_video_info.mmio_vbase, TRANS_DST_KEY_LOW, color); \
428 xgiCmdQueLen -= 2;
430 #define XGI310SetupMONOPAT(p0,p1) \
431 if (xgiCmdQueLen <= 1) XGI310Idle;\
432 MMIO_OUT32(xgi_video_info.mmio_vbase, MONO_MASK, p0);\
433 MMIO_OUT32(xgi_video_info.mmio_vbase, MONO_MASK+4, p1);\
434 xgiCmdQueLen -= 2;
436 #define XGI310SetupClipLT(left,top) \
437 if (xgiCmdQueLen <= 0) XGI310Idle;\
438 MMIO_OUT32(xgi_video_info.mmio_vbase, LEFT_CLIP, ((left) & 0xFFFF) | (top)<<16 );\
439 xgiCmdQueLen--;
441 #define XGI310SetupClipRB(right,bottom) \
442 if (xgiCmdQueLen <= 0) XGI310Idle;\
443 MMIO_OUT32(xgi_video_info.mmio_vbase, RIGHT_CLIP, ((right) & 0xFFFF) | (bottom)<<16 );\
444 xgiCmdQueLen--;
446 #define XGI310SetupROP(rop) \
447 xgi_video_info.CommandReg = (rop) << 8;
449 #define XGI310SetupCMDFlag(flags) \
450 xgi_video_info.CommandReg |= (flags);
452 #define XGI310DoCMD \
453 if (xgiCmdQueLen <= 1) XGI310Idle;\
454 MMIO_OUT32(xgi_video_info.mmio_vbase, COMMAND_READY, xgi_video_info.CommandReg); \
455 MMIO_OUT32(xgi_video_info.mmio_vbase, FIRE_TRIGGER, 0); \
456 xgiCmdQueLen -= 2;
458 #define XGI310SetupX0Y0(x,y) \
459 if (xgiCmdQueLen <= 0) XGI310Idle;\
460 MMIO_OUT32(xgi_video_info.mmio_vbase, LINE_X0, (y)<<16 | (x) );\
461 xgiCmdQueLen--;
463 #define XGI310SetupX1Y1(x,y) \
464 if (xgiCmdQueLen <= 0) XGI310Idle;\
465 MMIO_OUT32(xgi_video_info.mmio_vbase, LINE_X1, (y)<<16 | (x) );\
466 xgiCmdQueLen--;
468 #define XGI310SetupLineCount(c) \
469 if (xgiCmdQueLen <= 0) XGI310Idle;\
470 MMIO_OUT16(xgi_video_info.mmio_vbase, LINE_COUNT, c);\
471 xgiCmdQueLen--;
473 #define XGI310SetupStylePeriod(p) \
474 if (xgiCmdQueLen <= 0) XGI310Idle;\
475 MMIO_OUT16(xgi_video_info.mmio_vbase, LINE_STYLE_PERIOD, p);\
476 xgiCmdQueLen--;
478 #define XGI310SetupStyleLow(ls) \
479 if (xgiCmdQueLen <= 0) XGI310Idle;\
480 MMIO_OUT32(xgi_video_info.mmio_vbase, LINE_STYLE_0, ls);\
481 xgiCmdQueLen--;
483 #define XGI310SetupStyleHigh(ls) \
484 if (xgiCmdQueLen <= 0) XGI310Idle;\
485 MMIO_OUT32(xgi_video_info.mmio_vbase, LINE_STYLE_1, ls);\
486 xgiCmdQueLen--;
488 int XGIfb_initaccel(void);
489 void XGIfb_syncaccel(void);
491 extern struct video_info xgi_video_info;
493 extern int XGIfb_accel;
494 void fbcon_XGI_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
495 void fbcon_XGI_copyarea(struct fb_info *info, const struct fb_copyarea *area);
498 #endif