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"
51 static const int XGIALUConv
[] =
53 0x00, /* dest = 0; 0, GXclear, 0 */
54 0x88, /* dest &= src; DSa, GXand, 0x1 */
55 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */
56 0xCC, /* dest = src; S, GXcopy, 0x3 */
57 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */
58 0xAA, /* dest = dest; D, GXnoop, 0x5 */
59 0x66, /* dest = ^src; DSx, GXxor, 0x6 */
60 0xEE, /* dest |= src; DSo, GXor, 0x7 */
61 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */
62 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */
63 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
64 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */
65 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */
66 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */
67 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */
68 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
70 /* same ROP but with Pattern as Source */
71 static const int XGIPatALUConv
[] =
73 0x00, /* dest = 0; 0, GXclear, 0 */
74 0xA0, /* dest &= src; DPa, GXand, 0x1 */
75 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */
76 0xF0, /* dest = src; P, GXcopy, 0x3 */
77 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */
78 0xAA, /* dest = dest; D, GXnoop, 0x5 */
79 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */
80 0xFA, /* dest |= src; DPo, GXor, 0x7 */
81 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */
82 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */
83 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
84 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */
85 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */
86 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */
87 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */
88 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
91 static const unsigned char myrops
[] = {
92 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
102 /* 310/325 series ------------------------------------------------ */
105 XGI310SetupForScreenToScreenCopy(int xdir
, int ydir
, int rop
,
106 unsigned int planemask
, int trans_color
)
108 XGI310SetupDSTColorDepth(xgi_video_info
.DstColor
);
109 XGI310SetupSRCPitch(xgi_video_info
.video_linelength
)
110 XGI310SetupDSTRect(xgi_video_info
.video_linelength
, 0xFFF)
111 if (trans_color
!= -1) {
113 XGI310SetupSRCTrans(trans_color
)
114 XGI310SetupCMDFlag(TRANSPARENT_BITBLT
)
116 XGI310SetupROP(XGIALUConv
[rop
])
117 /* Set command - not needed, both 0 */
118 /* XGISetupCMDFlag(BITBLT | SRCVIDEO) */
120 XGI310SetupCMDFlag(xgi_video_info
.XGI310_AccelDepth
)
121 /* TW: The 310/325 series is smart enough to know the direction */
125 XGI310SubsequentScreenToScreenCopy(int src_x
, int src_y
, int dst_x
, int dst_y
,
126 int width
, int height
)
128 long srcbase
, dstbase
;
131 srcbase
= dstbase
= 0;
132 mymin
= min(src_y
, dst_y
);
133 mymax
= max(src_y
, dst_y
);
135 /* Although the chip knows the direction to use
136 * if the source and destination areas overlap,
137 * that logic fails if we fiddle with the bitmap
138 * addresses. Therefore, we check if the source
139 * and destination blitting areas overlap and
140 * adapt the bitmap addresses synchronously
141 * if the coordinates exceed the valid range.
142 * The the areas do not overlap, we do our
145 if((mymax
- mymin
) < height
) {
146 if((src_y
>= 2048) || (dst_y
>= 2048)) {
147 srcbase
= xgi_video_info
.video_linelength
* mymin
;
148 dstbase
= xgi_video_info
.video_linelength
* mymin
;
154 srcbase
= xgi_video_info
.video_linelength
* src_y
;
158 dstbase
= xgi_video_info
.video_linelength
* dst_y
;
163 XGI310SetupSRCBase(srcbase
);
164 XGI310SetupDSTBase(dstbase
);
165 XGI310SetupRect(width
, height
)
166 XGI310SetupSRCXY(src_x
, src_y
)
167 XGI310SetupDSTXY(dst_x
, dst_y
)
172 XGI310SetupForSolidFill(int color
, int rop
, unsigned int planemask
)
174 XGI310SetupPATFG(color
)
175 XGI310SetupDSTRect(xgi_video_info
.video_linelength
, 0xFFF)
176 XGI310SetupDSTColorDepth(xgi_video_info
.DstColor
);
177 XGI310SetupROP(XGIPatALUConv
[rop
])
178 XGI310SetupCMDFlag(PATFG
| xgi_video_info
.XGI310_AccelDepth
)
182 XGI310SubsequentSolidFillRect(int x
, int y
, int w
, int h
)
188 dstbase
= xgi_video_info
.video_linelength
* y
;
191 XGI310SetupDSTBase(dstbase
)
192 XGI310SetupDSTXY(x
,y
)
194 XGI310SetupCMDFlag(BITBLT
)
198 /* --------------------------------------------------------------------- */
200 /* The exported routines */
202 int XGIfb_initaccel(void)
204 #ifdef XGIFB_USE_SPINLOCKS
205 spin_lock_init(&xgi_video_info
.lockaccel
);
210 void XGIfb_syncaccel(void)
217 int fbcon_XGI_sync(struct fb_info
*info
)
219 if(!XGIfb_accel
) return 0;
228 void fbcon_XGI_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
234 if(!rect
->width
|| !rect
->height
)
238 cfb_fillrect(info
, rect
);
242 switch(info
->var
.bits_per_pixel
) {
243 case 8: col
= rect
->color
;
245 case 16: col
= ((u32
*)(info
->pseudo_palette
))[rect
->color
];
247 case 32: col
= ((u32
*)(info
->pseudo_palette
))[rect
->color
];
253 XGI310SetupForSolidFill(col
, myrops
[rect
->rop
], 0);
254 XGI310SubsequentSolidFillRect(rect
->dx
, rect
->dy
, rect
->width
, rect
->height
);
261 void fbcon_XGI_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
268 cfb_copyarea(info
, area
);
272 if(!area
->width
|| !area
->height
)
275 if(area
->sx
< area
->dx
) xdir
= 0;
277 if(area
->sy
< area
->dy
) ydir
= 0;
281 XGI310SetupForScreenToScreenCopy(xdir
, ydir
, 3, 0, -1);
282 XGI310SubsequentScreenToScreenCopy(area
->sx
, area
->sy
, area
->dx
, area
->dy
, area
->width
, area
->height
);