[MIPS] Use common definitions from asm-generic/signal.h
[linux-2.6/linux-mips/linux-dm7025.git] / drivers / video / sis / sis_accel.c
blob3b7ce032e2ed6af47599e9336c01d37bdc864e8c
1 /*
2 * SiS 300/540/630[S]/730[S],
3 * SiS 315[E|PRO]/550/[M]650/651/[M]661[F|M]X/740/[M]741[GX]/330/[M]760[GX],
4 * XGI V3XT/V5/V8, Z7
5 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
7 * 2D acceleration part
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the named License,
12 * or any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
23 * Based on the XFree86/X.org driver which is
24 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
26 * Author: Thomas Winischhofer <thomas@winischhofer.net>
27 * (see http://www.winischhofer.net/
28 * for more information and updates)
31 #include <linux/version.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/fb.h>
35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
36 #include <linux/console.h>
37 #endif
38 #include <linux/ioport.h>
39 #include <linux/types.h>
41 #include <asm/io.h>
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
44 #include <video/fbcon.h>
45 #include <video/fbcon-cfb8.h>
46 #include <video/fbcon-cfb16.h>
47 #include <video/fbcon-cfb24.h>
48 #include <video/fbcon-cfb32.h>
49 #endif
51 #include "sis.h"
52 #include "sis_accel.h"
54 static const u8 sisALUConv[] =
56 0x00, /* dest = 0; 0, GXclear, 0 */
57 0x88, /* dest &= src; DSa, GXand, 0x1 */
58 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */
59 0xCC, /* dest = src; S, GXcopy, 0x3 */
60 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */
61 0xAA, /* dest = dest; D, GXnoop, 0x5 */
62 0x66, /* dest = ^src; DSx, GXxor, 0x6 */
63 0xEE, /* dest |= src; DSo, GXor, 0x7 */
64 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */
65 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */
66 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
67 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */
68 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */
69 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */
70 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */
71 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
73 /* same ROP but with Pattern as Source */
74 static const u8 sisPatALUConv[] =
76 0x00, /* dest = 0; 0, GXclear, 0 */
77 0xA0, /* dest &= src; DPa, GXand, 0x1 */
78 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */
79 0xF0, /* dest = src; P, GXcopy, 0x3 */
80 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */
81 0xAA, /* dest = dest; D, GXnoop, 0x5 */
82 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */
83 0xFA, /* dest |= src; DPo, GXor, 0x7 */
84 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */
85 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */
86 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
87 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */
88 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */
89 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */
90 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */
91 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
94 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
95 static const int myrops[] = {
96 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
98 #endif
100 /* 300 series ----------------------------------------------------- */
101 #ifdef CONFIG_FB_SIS_300
102 static void
103 SiS300Sync(struct sis_video_info *ivideo)
105 SiS300Idle
108 static void
109 SiS300SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int xdir, int ydir,
110 int rop, int trans_color)
112 SiS300SetupDSTColorDepth(ivideo->DstColor);
113 SiS300SetupSRCPitch(ivideo->video_linelength)
114 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
116 if(trans_color != -1) {
117 SiS300SetupROP(0x0A)
118 SiS300SetupSRCTrans(trans_color)
119 SiS300SetupCMDFlag(TRANSPARENT_BITBLT)
120 } else {
121 SiS300SetupROP(sisALUConv[rop])
123 if(xdir > 0) {
124 SiS300SetupCMDFlag(X_INC)
126 if(ydir > 0) {
127 SiS300SetupCMDFlag(Y_INC)
131 static void
132 SiS300SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x,
133 int src_y, int dst_x, int dst_y, int width, int height)
135 u32 srcbase = 0, dstbase = 0;
137 if(src_y >= 2048) {
138 srcbase = ivideo->video_linelength * src_y;
139 src_y = 0;
141 if(dst_y >= 2048) {
142 dstbase = ivideo->video_linelength * dst_y;
143 dst_y = 0;
146 SiS300SetupSRCBase(srcbase);
147 SiS300SetupDSTBase(dstbase);
149 if(!(ivideo->CommandReg & X_INC)) {
150 src_x += width-1;
151 dst_x += width-1;
153 if(!(ivideo->CommandReg & Y_INC)) {
154 src_y += height-1;
155 dst_y += height-1;
157 SiS300SetupRect(width, height)
158 SiS300SetupSRCXY(src_x, src_y)
159 SiS300SetupDSTXY(dst_x, dst_y)
160 SiS300DoCMD
163 static void
164 SiS300SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
166 SiS300SetupPATFG(color)
167 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
168 SiS300SetupDSTColorDepth(ivideo->DstColor);
169 SiS300SetupROP(sisPatALUConv[rop])
170 SiS300SetupCMDFlag(PATFG)
173 static void
174 SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
176 u32 dstbase = 0;
178 if(y >= 2048) {
179 dstbase = ivideo->video_linelength * y;
180 y = 0;
182 SiS300SetupDSTBase(dstbase)
183 SiS300SetupDSTXY(x,y)
184 SiS300SetupRect(w,h)
185 SiS300SetupCMDFlag(X_INC | Y_INC | BITBLT)
186 SiS300DoCMD
188 #endif
190 /* 315/330/340 series ---------------------------------------------- */
192 #ifdef CONFIG_FB_SIS_315
193 static void
194 SiS310Sync(struct sis_video_info *ivideo)
196 SiS310Idle
199 static void
200 SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int trans_color)
202 SiS310SetupDSTColorDepth(ivideo->DstColor);
203 SiS310SetupSRCPitch(ivideo->video_linelength)
204 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
205 if(trans_color != -1) {
206 SiS310SetupROP(0x0A)
207 SiS310SetupSRCTrans(trans_color)
208 SiS310SetupCMDFlag(TRANSPARENT_BITBLT)
209 } else {
210 SiS310SetupROP(sisALUConv[rop])
211 /* Set command - not needed, both 0 */
212 /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
214 SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
215 /* The chip is smart enough to know the direction */
218 static void
219 SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int src_y,
220 int dst_x, int dst_y, int width, int height)
222 u32 srcbase = 0, dstbase = 0;
223 int mymin = min(src_y, dst_y);
224 int mymax = max(src_y, dst_y);
226 /* Although the chip knows the direction to use
227 * if the source and destination areas overlap,
228 * that logic fails if we fiddle with the bitmap
229 * addresses. Therefore, we check if the source
230 * and destination blitting areas overlap and
231 * adapt the bitmap addresses synchronously
232 * if the coordinates exceed the valid range.
233 * The the areas do not overlap, we do our
234 * normal check.
236 if((mymax - mymin) < height) {
237 if((src_y >= 2048) || (dst_y >= 2048)) {
238 srcbase = ivideo->video_linelength * mymin;
239 dstbase = ivideo->video_linelength * mymin;
240 src_y -= mymin;
241 dst_y -= mymin;
243 } else {
244 if(src_y >= 2048) {
245 srcbase = ivideo->video_linelength * src_y;
246 src_y = 0;
248 if(dst_y >= 2048) {
249 dstbase = ivideo->video_linelength * dst_y;
250 dst_y = 0;
254 srcbase += ivideo->video_offset;
255 dstbase += ivideo->video_offset;
257 SiS310SetupSRCBase(srcbase);
258 SiS310SetupDSTBase(dstbase);
259 SiS310SetupRect(width, height)
260 SiS310SetupSRCXY(src_x, src_y)
261 SiS310SetupDSTXY(dst_x, dst_y)
262 SiS310DoCMD
265 static void
266 SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
268 SiS310SetupPATFG(color)
269 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
270 SiS310SetupDSTColorDepth(ivideo->DstColor);
271 SiS310SetupROP(sisPatALUConv[rop])
272 SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
275 static void
276 SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
278 u32 dstbase = 0;
280 if(y >= 2048) {
281 dstbase = ivideo->video_linelength * y;
282 y = 0;
284 dstbase += ivideo->video_offset;
285 SiS310SetupDSTBase(dstbase)
286 SiS310SetupDSTXY(x,y)
287 SiS310SetupRect(w,h)
288 SiS310SetupCMDFlag(BITBLT)
289 SiS310DoCMD
291 #endif
293 /* --------------------------------------------------------------------- */
295 /* The exported routines */
297 int sisfb_initaccel(struct sis_video_info *ivideo)
299 #ifdef SISFB_USE_SPINLOCKS
300 spin_lock_init(&ivideo->lockaccel);
301 #endif
302 return 0;
305 void sisfb_syncaccel(struct sis_video_info *ivideo)
307 if(ivideo->sisvga_engine == SIS_300_VGA) {
308 #ifdef CONFIG_FB_SIS_300
309 SiS300Sync(ivideo);
310 #endif
311 } else {
312 #ifdef CONFIG_FB_SIS_315
313 SiS310Sync(ivideo);
314 #endif
318 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */
320 int fbcon_sis_sync(struct fb_info *info)
322 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
323 CRITFLAGS
325 if((!ivideo->accel) || (!ivideo->engineok))
326 return 0;
328 CRITBEGIN
329 sisfb_syncaccel(ivideo);
330 CRITEND
332 return 0;
335 void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
337 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
338 u32 col = 0;
339 u32 vxres = info->var.xres_virtual;
340 u32 vyres = info->var.yres_virtual;
341 int width, height;
342 CRITFLAGS
344 if(info->state != FBINFO_STATE_RUNNING)
345 return;
347 if((!ivideo->accel) || (!ivideo->engineok)) {
348 cfb_fillrect(info, rect);
349 return;
352 if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
353 return;
355 /* Clipping */
356 width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width;
357 height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height;
359 switch(info->var.bits_per_pixel) {
360 case 8: col = rect->color;
361 break;
362 case 16:
363 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
364 break;
367 if(ivideo->sisvga_engine == SIS_300_VGA) {
368 #ifdef CONFIG_FB_SIS_300
369 CRITBEGIN
370 SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
371 SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
372 CRITEND
373 #endif
374 } else {
375 #ifdef CONFIG_FB_SIS_315
376 CRITBEGIN
377 SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
378 SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
379 CRITEND
380 #endif
383 sisfb_syncaccel(ivideo);
386 void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
388 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
389 u32 vxres = info->var.xres_virtual;
390 u32 vyres = info->var.yres_virtual;
391 int width = area->width;
392 int height = area->height;
393 CRITFLAGS
395 if(info->state != FBINFO_STATE_RUNNING)
396 return;
398 if((!ivideo->accel) || (!ivideo->engineok)) {
399 cfb_copyarea(info, area);
400 return;
403 if(!width || !height ||
404 area->sx >= vxres || area->sy >= vyres ||
405 area->dx >= vxres || area->dy >= vyres)
406 return;
408 /* Clipping */
409 if((area->sx + width) > vxres) width = vxres - area->sx;
410 if((area->dx + width) > vxres) width = vxres - area->dx;
411 if((area->sy + height) > vyres) height = vyres - area->sy;
412 if((area->dy + height) > vyres) height = vyres - area->dy;
414 if(ivideo->sisvga_engine == SIS_300_VGA) {
415 #ifdef CONFIG_FB_SIS_300
416 int xdir, ydir;
418 if(area->sx < area->dx) xdir = 0;
419 else xdir = 1;
420 if(area->sy < area->dy) ydir = 0;
421 else ydir = 1;
423 CRITBEGIN
424 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
425 SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
426 area->dx, area->dy, width, height);
427 CRITEND
428 #endif
429 } else {
430 #ifdef CONFIG_FB_SIS_315
431 CRITBEGIN
432 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
433 SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
434 area->dx, area->dy, width, height);
435 CRITEND
436 #endif
439 sisfb_syncaccel(ivideo);
442 #endif
444 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
446 #include "sisfb_accel_2_4.h"
448 #endif /* KERNEL VERSION */