85af55c320912fedfcfff8ae80bcecf481c396ce
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / xgifb / XGI_accel.c
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
4 *
5 * 2D acceleration part
6 *
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
12 *
13 * Author: Thomas Winischhofer <thomas@winischhofer.net>
14 * (see http://www.winischhofer.net/
15 * for more information and updates)
16 */
17
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>
24 #include <linux/mm.h>
25 #include <linux/tty.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
28 #include <linux/fb.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>
36 #include <linux/fs.h>
37 #include <linux/agp_backend.h>
38
39 #include <linux/types.h>
40 #include <asm/io.h>
41
42 #ifdef CONFIG_MTRR
43 #include <asm/mtrr.h>
44 #endif
45
46 #include "vgatypes.h"
47 #include "vb_struct.h"
48 #include "XGIfb.h"
49 #include "XGI_accel.h"
50
51
52 extern struct video_info xgi_video_info;
53 extern int XGIfb_accel;
54
55 static const int XGIALUConv[] =
56 {
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 */
73 };
74 /* same ROP but with Pattern as Source */
75 static const int XGIPatALUConv[] =
76 {
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 */
93 };
94
95 static const unsigned char myrops[] = {
96 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
97 };
98
99 /* 300 series */
100 #if 0
101 static void
102 XGI300Sync(void)
103 {
104 XGI300Idle
105 }
106 #endif
107 static void
108 XGI310Sync(void)
109 {
110 XGI310Idle
111 }
112 #if 0
113 static void
114 XGI300SetupForScreenToScreenCopy(int xdir, int ydir, int rop,
115 unsigned int planemask, int trans_color)
116 {
117 XGI300SetupDSTColorDepth(xgi_video_info.DstColor);
118 XGI300SetupSRCPitch(xgi_video_info.video_linelength)
119 XGI300SetupDSTRect(xgi_video_info.video_linelength, 0xFFF)
120
121 if(trans_color != -1) {
122 XGI300SetupROP(0x0A)
123 XGI300SetupSRCTrans(trans_color)
124 XGI300SetupCMDFlag(TRANSPARENT_BITBLT)
125 } else {
126 XGI300SetupROP(XGIALUConv[rop])
127 }
128 if(xdir > 0) {
129 XGI300SetupCMDFlag(X_INC)
130 }
131 if(ydir > 0) {
132 XGI300SetupCMDFlag(Y_INC)
133 }
134 }
135
136 static void
137 XGI300SubsequentScreenToScreenCopy(int src_x, int src_y, int dst_x, int dst_y,
138 int width, int height)
139 {
140 long srcbase, dstbase;
141
142 srcbase = dstbase = 0;
143 if (src_y >= 2048) {
144 srcbase = xgi_video_info.video_linelength * src_y;
145 src_y = 0;
146 }
147 if (dst_y >= 2048) {
148 dstbase = xgi_video_info.video_linelength * dst_y;
149 dst_y = 0;
150 }
151
152 XGI300SetupSRCBase(srcbase);
153 XGI300SetupDSTBase(dstbase);
154
155 if(!(xgi_video_info.CommandReg & X_INC)) {
156 src_x += width-1;
157 dst_x += width-1;
158 }
159 if(!(xgi_video_info.CommandReg & Y_INC)) {
160 src_y += height-1;
161 dst_y += height-1;
162 }
163 XGI300SetupRect(width, height)
164 XGI300SetupSRCXY(src_x, src_y)
165 XGI300SetupDSTXY(dst_x, dst_y)
166 XGI300DoCMD
167 }
168
169 static void
170 XGI300SetupForSolidFill(int color, int rop, unsigned int planemask)
171 {
172 XGI300SetupPATFG(color)
173 XGI300SetupDSTRect(xgi_video_info.video_linelength, 0xFFF)
174 XGI300SetupDSTColorDepth(xgi_video_info.DstColor);
175 XGI300SetupROP(XGIPatALUConv[rop])
176 XGI300SetupCMDFlag(PATFG)
177 }
178
179 static void
180 XGI300SubsequentSolidFillRect(int x, int y, int w, int h)
181 {
182 long dstbase;
183
184 dstbase = 0;
185 if(y >= 2048) {
186 dstbase = xgi_video_info.video_linelength * y;
187 y = 0;
188 }
189 XGI300SetupDSTBase(dstbase)
190 XGI300SetupDSTXY(x,y)
191 XGI300SetupRect(w,h)
192 XGI300SetupCMDFlag(X_INC | Y_INC | BITBLT)
193 XGI300DoCMD
194 }
195 #endif
196 /* 310/325 series ------------------------------------------------ */
197
198 static void
199 XGI310SetupForScreenToScreenCopy(int xdir, int ydir, int rop,
200 unsigned int planemask, int trans_color)
201 {
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) {
206 XGI310SetupROP(0x0A)
207 XGI310SetupSRCTrans(trans_color)
208 XGI310SetupCMDFlag(TRANSPARENT_BITBLT)
209 } else {
210 XGI310SetupROP(XGIALUConv[rop])
211 /* Set command - not needed, both 0 */
212 /* XGISetupCMDFlag(BITBLT | SRCVIDEO) */
213 }
214 XGI310SetupCMDFlag(xgi_video_info.XGI310_AccelDepth)
215 /* TW: The 310/325 series is smart enough to know the direction */
216 }
217
218 static void
219 XGI310SubsequentScreenToScreenCopy(int src_x, int src_y, int dst_x, int dst_y,
220 int width, int height)
221 {
222 long srcbase, dstbase;
223 int mymin, mymax;
224
225 srcbase = dstbase = 0;
226 mymin = min(src_y, dst_y);
227 mymax = max(src_y, dst_y);
228
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
237 * normal check.
238 */
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;
243 src_y -= mymin;
244 dst_y -= mymin;
245 }
246 } else {
247 if(src_y >= 2048) {
248 srcbase = xgi_video_info.video_linelength * src_y;
249 src_y = 0;
250 }
251 if(dst_y >= 2048) {
252 dstbase = xgi_video_info.video_linelength * dst_y;
253 dst_y = 0;
254 }
255 }
256
257 XGI310SetupSRCBase(srcbase);
258 XGI310SetupDSTBase(dstbase);
259 XGI310SetupRect(width, height)
260 XGI310SetupSRCXY(src_x, src_y)
261 XGI310SetupDSTXY(dst_x, dst_y)
262 XGI310DoCMD
263 }
264
265 static void
266 XGI310SetupForSolidFill(int color, int rop, unsigned int planemask)
267 {
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)
273 }
274
275 static void
276 XGI310SubsequentSolidFillRect(int x, int y, int w, int h)
277 {
278 long dstbase;
279
280 dstbase = 0;
281 if(y >= 2048) {
282 dstbase = xgi_video_info.video_linelength * y;
283 y = 0;
284 }
285 XGI310SetupDSTBase(dstbase)
286 XGI310SetupDSTXY(x,y)
287 XGI310SetupRect(w,h)
288 XGI310SetupCMDFlag(BITBLT)
289 XGI310DoCMD
290 }
291
292 /* --------------------------------------------------------------------- */
293
294 /* The exported routines */
295
296 int XGIfb_initaccel(void)
297 {
298 #ifdef XGIFB_USE_SPINLOCKS
299 spin_lock_init(&xgi_video_info.lockaccel);
300 #endif
301 return(0);
302 }
303
304 void XGIfb_syncaccel(void)
305 {
306
307 XGI310Sync();
308
309 }
310
311 int fbcon_XGI_sync(struct fb_info *info)
312 {
313 if(!XGIfb_accel) return 0;
314 CRITFLAGS
315
316 XGI310Sync();
317
318 CRITEND
319 return 0;
320 }
321
322 void fbcon_XGI_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
323 {
324 int col=0;
325 CRITFLAGS
326
327
328 if(!rect->width || !rect->height)
329 return;
330
331 if(!XGIfb_accel) {
332 cfb_fillrect(info, rect);
333 return;
334 }
335
336 switch(info->var.bits_per_pixel) {
337 case 8: col = rect->color;
338 break;
339 case 16: col = ((u32 *)(info->pseudo_palette))[rect->color];
340 break;
341 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
342 break;
343 }
344
345
346 CRITBEGIN
347 XGI310SetupForSolidFill(col, myrops[rect->rop], 0);
348 XGI310SubsequentSolidFillRect(rect->dx, rect->dy, rect->width, rect->height);
349 CRITEND
350 XGI310Sync();
351
352
353 }
354
355 void fbcon_XGI_copyarea(struct fb_info *info, const struct fb_copyarea *area)
356 {
357 int xdir, ydir;
358 CRITFLAGS
359
360
361 if(!XGIfb_accel) {
362 cfb_copyarea(info, area);
363 return;
364 }
365
366 if(!area->width || !area->height)
367 return;
368
369 if(area->sx < area->dx) xdir = 0;
370 else xdir = 1;
371 if(area->sy < area->dy) ydir = 0;
372 else ydir = 1;
373
374 CRITBEGIN
375 XGI310SetupForScreenToScreenCopy(xdir, ydir, 3, 0, -1);
376 XGI310SubsequentScreenToScreenCopy(area->sx, area->sy, area->dx, area->dy, area->width, area->height);
377 CRITEND
378 XGI310Sync();
379
380 }
381
382
383