2 * XGI 300/630/730/540/315/550/650/740 frame buffer driver
3 * for Linux kernels 2.4.x and 2.5.x
7 * Based on the X driver's XGI300_accel.c which is
8 * Copyright Xavier Ducoin <x.ducoin@lectra.com>
9 * Copyright 2002 by Thomas Winischhofer, Vienna, Austria
10 * and XGI310_accel.c 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 //#include <linux/config.h>
19 #include <linux/version.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
25 #include <linux/tty.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
29 #include <linux/console.h>
30 #include <linux/selection.h>
31 #include <linux/ioport.h>
32 #include <linux/init.h>
33 #include <linux/pci.h>
34 #include <linux/vt_kern.h>
35 #include <linux/capability.h>
37 #include <linux/agp_backend.h>
39 #include <linux/types.h>
47 #include "vb_struct.h"
49 #include "XGI_accel.h"
52 extern struct video_info xgi_video_info
;
53 extern int XGIfb_accel
;
55 static const int XGIALUConv
[] =
57 0x00, /* dest = 0; 0, GXclear, 0 */
58 0x88, /* dest &= src; DSa, GXand, 0x1 */
59 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */
60 0xCC, /* dest = src; S, GXcopy, 0x3 */
61 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */
62 0xAA, /* dest = dest; D, GXnoop, 0x5 */
63 0x66, /* dest = ^src; DSx, GXxor, 0x6 */
64 0xEE, /* dest |= src; DSo, GXor, 0x7 */
65 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */
66 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */
67 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
68 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */
69 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */
70 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */
71 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */
72 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
74 /* same ROP but with Pattern as Source */
75 static const int XGIPatALUConv
[] =
77 0x00, /* dest = 0; 0, GXclear, 0 */
78 0xA0, /* dest &= src; DPa, GXand, 0x1 */
79 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */
80 0xF0, /* dest = src; P, GXcopy, 0x3 */
81 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */
82 0xAA, /* dest = dest; D, GXnoop, 0x5 */
83 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */
84 0xFA, /* dest |= src; DPo, GXor, 0x7 */
85 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */
86 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */
87 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
88 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */
89 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */
90 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */
91 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */
92 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
95 static const unsigned char myrops
[] = {
96 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
114 XGI300SetupForScreenToScreenCopy(int xdir
, int ydir
, int rop
,
115 unsigned int planemask
, int trans_color
)
117 XGI300SetupDSTColorDepth(xgi_video_info
.DstColor
);
118 XGI300SetupSRCPitch(xgi_video_info
.video_linelength
)
119 XGI300SetupDSTRect(xgi_video_info
.video_linelength
, 0xFFF)
121 if(trans_color
!= -1) {
123 XGI300SetupSRCTrans(trans_color
)
124 XGI300SetupCMDFlag(TRANSPARENT_BITBLT
)
126 XGI300SetupROP(XGIALUConv
[rop
])
129 XGI300SetupCMDFlag(X_INC
)
132 XGI300SetupCMDFlag(Y_INC
)
137 XGI300SubsequentScreenToScreenCopy(int src_x
, int src_y
, int dst_x
, int dst_y
,
138 int width
, int height
)
140 long srcbase
, dstbase
;
142 srcbase
= dstbase
= 0;
144 srcbase
= xgi_video_info
.video_linelength
* src_y
;
148 dstbase
= xgi_video_info
.video_linelength
* dst_y
;
152 XGI300SetupSRCBase(srcbase
);
153 XGI300SetupDSTBase(dstbase
);
155 if(!(xgi_video_info
.CommandReg
& X_INC
)) {
159 if(!(xgi_video_info
.CommandReg
& Y_INC
)) {
163 XGI300SetupRect(width
, height
)
164 XGI300SetupSRCXY(src_x
, src_y
)
165 XGI300SetupDSTXY(dst_x
, dst_y
)
170 XGI300SetupForSolidFill(int color
, int rop
, unsigned int planemask
)
172 XGI300SetupPATFG(color
)
173 XGI300SetupDSTRect(xgi_video_info
.video_linelength
, 0xFFF)
174 XGI300SetupDSTColorDepth(xgi_video_info
.DstColor
);
175 XGI300SetupROP(XGIPatALUConv
[rop
])
176 XGI300SetupCMDFlag(PATFG
)
180 XGI300SubsequentSolidFillRect(int x
, int y
, int w
, int h
)
186 dstbase
= xgi_video_info
.video_linelength
* y
;
189 XGI300SetupDSTBase(dstbase
)
190 XGI300SetupDSTXY(x
,y
)
192 XGI300SetupCMDFlag(X_INC
| Y_INC
| BITBLT
)
196 /* 310/325 series ------------------------------------------------ */
199 XGI310SetupForScreenToScreenCopy(int xdir
, int ydir
, int rop
,
200 unsigned int planemask
, int trans_color
)
202 XGI310SetupDSTColorDepth(xgi_video_info
.DstColor
);
203 XGI310SetupSRCPitch(xgi_video_info
.video_linelength
)
204 XGI310SetupDSTRect(xgi_video_info
.video_linelength
, 0xFFF)
205 if (trans_color
!= -1) {
207 XGI310SetupSRCTrans(trans_color
)
208 XGI310SetupCMDFlag(TRANSPARENT_BITBLT
)
210 XGI310SetupROP(XGIALUConv
[rop
])
211 /* Set command - not needed, both 0 */
212 /* XGISetupCMDFlag(BITBLT | SRCVIDEO) */
214 XGI310SetupCMDFlag(xgi_video_info
.XGI310_AccelDepth
)
215 /* TW: The 310/325 series is smart enough to know the direction */
219 XGI310SubsequentScreenToScreenCopy(int src_x
, int src_y
, int dst_x
, int dst_y
,
220 int width
, int height
)
222 long srcbase
, dstbase
;
225 srcbase
= dstbase
= 0;
226 mymin
= min(src_y
, dst_y
);
227 mymax
= max(src_y
, dst_y
);
229 /* Although the chip knows the direction to use
230 * if the source and destination areas overlap,
231 * that logic fails if we fiddle with the bitmap
232 * addresses. Therefore, we check if the source
233 * and destination blitting areas overlap and
234 * adapt the bitmap addresses synchronously
235 * if the coordinates exceed the valid range.
236 * The the areas do not overlap, we do our
239 if((mymax
- mymin
) < height
) {
240 if((src_y
>= 2048) || (dst_y
>= 2048)) {
241 srcbase
= xgi_video_info
.video_linelength
* mymin
;
242 dstbase
= xgi_video_info
.video_linelength
* mymin
;
248 srcbase
= xgi_video_info
.video_linelength
* src_y
;
252 dstbase
= xgi_video_info
.video_linelength
* dst_y
;
257 XGI310SetupSRCBase(srcbase
);
258 XGI310SetupDSTBase(dstbase
);
259 XGI310SetupRect(width
, height
)
260 XGI310SetupSRCXY(src_x
, src_y
)
261 XGI310SetupDSTXY(dst_x
, dst_y
)
266 XGI310SetupForSolidFill(int color
, int rop
, unsigned int planemask
)
268 XGI310SetupPATFG(color
)
269 XGI310SetupDSTRect(xgi_video_info
.video_linelength
, 0xFFF)
270 XGI310SetupDSTColorDepth(xgi_video_info
.DstColor
);
271 XGI310SetupROP(XGIPatALUConv
[rop
])
272 XGI310SetupCMDFlag(PATFG
| xgi_video_info
.XGI310_AccelDepth
)
276 XGI310SubsequentSolidFillRect(int x
, int y
, int w
, int h
)
282 dstbase
= xgi_video_info
.video_linelength
* y
;
285 XGI310SetupDSTBase(dstbase
)
286 XGI310SetupDSTXY(x
,y
)
288 XGI310SetupCMDFlag(BITBLT
)
292 /* --------------------------------------------------------------------- */
294 /* The exported routines */
296 int XGIfb_initaccel(void)
298 #ifdef XGIFB_USE_SPINLOCKS
299 spin_lock_init(&xgi_video_info
.lockaccel
);
304 void XGIfb_syncaccel(void)
311 int fbcon_XGI_sync(struct fb_info
*info
)
313 if(!XGIfb_accel
) return 0;
322 void fbcon_XGI_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
328 if(!rect
->width
|| !rect
->height
)
332 cfb_fillrect(info
, rect
);
336 switch(info
->var
.bits_per_pixel
) {
337 case 8: col
= rect
->color
;
339 case 16: col
= ((u32
*)(info
->pseudo_palette
))[rect
->color
];
341 case 32: col
= ((u32
*)(info
->pseudo_palette
))[rect
->color
];
347 XGI310SetupForSolidFill(col
, myrops
[rect
->rop
], 0);
348 XGI310SubsequentSolidFillRect(rect
->dx
, rect
->dy
, rect
->width
, rect
->height
);
355 void fbcon_XGI_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
362 cfb_copyarea(info
, area
);
366 if(!area
->width
|| !area
->height
)
369 if(area
->sx
< area
->dx
) xdir
= 0;
371 if(area
->sy
< area
->dy
) ydir
= 0;
375 XGI310SetupForScreenToScreenCopy(xdir
, ydir
, 3, 0, -1);
376 XGI310SubsequentScreenToScreenCopy(area
->sx
, area
->sy
, area
->dx
, area
->dy
, area
->width
, area
->height
);