blob: 3b7ce032e2ed6af47599e9336c01d37bdc864e8c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * 2D acceleration part
8 *
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.
13 *
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.
18 *
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
22 *
23 * Based on the XFree86/X.org driver which is
Thomas Winischhofer544393f2005-09-09 13:04:45 -070024 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
26 * Author: Thomas Winischhofer <thomas@winischhofer.net>
27 * (see http://www.winischhofer.net/
28 * for more information and updates)
29 */
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/version.h>
32#include <linux/module.h>
33#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/fb.h>
Thomas Winischhofer544393f2005-09-09 13:04:45 -070035#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/console.h>
Thomas Winischhofer544393f2005-09-09 13:04:45 -070037#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/types.h>
40
41#include <asm/io.h>
42
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
50
51#include "sis.h"
52#include "sis_accel.h"
53
54static const u8 sisALUConv[] =
55{
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 */
72};
73/* same ROP but with Pattern as Source */
74static const u8 sisPatALUConv[] =
75{
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 */
92};
93
94#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
95static const int myrops[] = {
96 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
97};
98#endif
99
100/* 300 series ----------------------------------------------------- */
101#ifdef CONFIG_FB_SIS_300
102static void
103SiS300Sync(struct sis_video_info *ivideo)
104{
105 SiS300Idle
106}
107
108static void
109SiS300SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int xdir, int ydir,
110 int rop, int trans_color)
111{
112 SiS300SetupDSTColorDepth(ivideo->DstColor);
113 SiS300SetupSRCPitch(ivideo->video_linelength)
114 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
115
116 if(trans_color != -1) {
117 SiS300SetupROP(0x0A)
118 SiS300SetupSRCTrans(trans_color)
119 SiS300SetupCMDFlag(TRANSPARENT_BITBLT)
120 } else {
121 SiS300SetupROP(sisALUConv[rop])
122 }
123 if(xdir > 0) {
124 SiS300SetupCMDFlag(X_INC)
125 }
126 if(ydir > 0) {
127 SiS300SetupCMDFlag(Y_INC)
128 }
129}
130
131static void
132SiS300SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x,
133 int src_y, int dst_x, int dst_y, int width, int height)
134{
135 u32 srcbase = 0, dstbase = 0;
136
137 if(src_y >= 2048) {
138 srcbase = ivideo->video_linelength * src_y;
139 src_y = 0;
140 }
141 if(dst_y >= 2048) {
142 dstbase = ivideo->video_linelength * dst_y;
143 dst_y = 0;
144 }
145
146 SiS300SetupSRCBase(srcbase);
147 SiS300SetupDSTBase(dstbase);
148
149 if(!(ivideo->CommandReg & X_INC)) {
150 src_x += width-1;
151 dst_x += width-1;
152 }
153 if(!(ivideo->CommandReg & Y_INC)) {
154 src_y += height-1;
155 dst_y += height-1;
156 }
157 SiS300SetupRect(width, height)
158 SiS300SetupSRCXY(src_x, src_y)
159 SiS300SetupDSTXY(dst_x, dst_y)
160 SiS300DoCMD
161}
162
163static void
164SiS300SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
165{
166 SiS300SetupPATFG(color)
167 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
168 SiS300SetupDSTColorDepth(ivideo->DstColor);
169 SiS300SetupROP(sisPatALUConv[rop])
170 SiS300SetupCMDFlag(PATFG)
171}
172
173static void
174SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
175{
176 u32 dstbase = 0;
177
178 if(y >= 2048) {
179 dstbase = ivideo->video_linelength * y;
180 y = 0;
181 }
182 SiS300SetupDSTBase(dstbase)
183 SiS300SetupDSTXY(x,y)
184 SiS300SetupRect(w,h)
185 SiS300SetupCMDFlag(X_INC | Y_INC | BITBLT)
186 SiS300DoCMD
187}
188#endif
189
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700190/* 315/330/340 series ---------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192#ifdef CONFIG_FB_SIS_315
193static void
194SiS310Sync(struct sis_video_info *ivideo)
195{
196 SiS310Idle
197}
198
199static void
200SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int trans_color)
201{
202 SiS310SetupDSTColorDepth(ivideo->DstColor);
203 SiS310SetupSRCPitch(ivideo->video_linelength)
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700204 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 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) */
213 }
214 SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700215 /* The chip is smart enough to know the direction */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218static void
219SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int src_y,
220 int dst_x, int dst_y, int width, int height)
221{
222 u32 srcbase = 0, dstbase = 0;
223 int mymin = min(src_y, dst_y);
224 int mymax = max(src_y, dst_y);
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 /* Although the chip knows the direction to use
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700227 * if the source and destination areas overlap,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 * that logic fails if we fiddle with the bitmap
229 * addresses. Therefore, we check if the source
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700230 * and destination blitting areas overlap and
231 * adapt the bitmap addresses synchronously
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 * if the coordinates exceed the valid range.
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700233 * The the areas do not overlap, we do our
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 * normal check.
235 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700236 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;
242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700244 if(src_y >= 2048) {
245 srcbase = ivideo->video_linelength * src_y;
246 src_y = 0;
247 }
248 if(dst_y >= 2048) {
249 dstbase = ivideo->video_linelength * dst_y;
250 dst_y = 0;
251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700254 srcbase += ivideo->video_offset;
255 dstbase += ivideo->video_offset;
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 SiS310SetupSRCBase(srcbase);
258 SiS310SetupDSTBase(dstbase);
259 SiS310SetupRect(width, height)
260 SiS310SetupSRCXY(src_x, src_y)
261 SiS310SetupDSTXY(dst_x, dst_y)
262 SiS310DoCMD
263}
264
265static void
266SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
267{
268 SiS310SetupPATFG(color)
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700269 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 SiS310SetupDSTColorDepth(ivideo->DstColor);
271 SiS310SetupROP(sisPatALUConv[rop])
272 SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
273}
274
275static void
276SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
277{
278 u32 dstbase = 0;
279
280 if(y >= 2048) {
281 dstbase = ivideo->video_linelength * y;
282 y = 0;
283 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700284 dstbase += ivideo->video_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 SiS310SetupDSTBase(dstbase)
286 SiS310SetupDSTXY(x,y)
287 SiS310SetupRect(w,h)
288 SiS310SetupCMDFlag(BITBLT)
289 SiS310DoCMD
290}
291#endif
292
293/* --------------------------------------------------------------------- */
294
295/* The exported routines */
296
297int sisfb_initaccel(struct sis_video_info *ivideo)
298{
299#ifdef SISFB_USE_SPINLOCKS
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700300 spin_lock_init(&ivideo->lockaccel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700302 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
304
305void sisfb_syncaccel(struct sis_video_info *ivideo)
306{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700307 if(ivideo->sisvga_engine == SIS_300_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700309 SiS300Sync(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700311 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700313 SiS310Sync(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
318#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */
319
320int fbcon_sis_sync(struct fb_info *info)
321{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700322 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
323 CRITFLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700325 if((!ivideo->accel) || (!ivideo->engineok))
326 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700328 CRITBEGIN
329 sisfb_syncaccel(ivideo);
330 CRITEND
331
332 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
335void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
336{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700337 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700344 if(info->state != FBINFO_STATE_RUNNING)
345 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700347 if((!ivideo->accel) || (!ivideo->engineok)) {
348 cfb_fillrect(info, rect);
349 return;
350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700352 if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
353 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700355 /* 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;
358
359 switch(info->var.bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 case 8: col = rect->color;
361 break;
362 case 16:
363 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
364 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700367 if(ivideo->sisvga_engine == SIS_300_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700369 CRITBEGIN
370 SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
371 SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
372 CRITEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700374 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700376 CRITBEGIN
377 SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
378 SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
379 CRITEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700383 sisfb_syncaccel(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
386void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
387{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700388 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700395 if(info->state != FBINFO_STATE_RUNNING)
396 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700398 if((!ivideo->accel) || (!ivideo->engineok)) {
399 cfb_copyarea(info, area);
400 return;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700403 if(!width || !height ||
404 area->sx >= vxres || area->sy >= vyres ||
405 area->dx >= vxres || area->dy >= vyres)
406 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700408 /* 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700414 if(ivideo->sisvga_engine == SIS_300_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700416 int xdir, ydir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700418 if(area->sx < area->dx) xdir = 0;
419 else xdir = 1;
420 if(area->sy < area->dy) ydir = 0;
421 else ydir = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700423 CRITBEGIN
424 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
425 SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
426 area->dx, area->dy, width, height);
427 CRITEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700429 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700431 CRITBEGIN
432 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
433 SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
434 area->dx, area->dy, width, height);
435 CRITEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700437 }
438
439 sisfb_syncaccel(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442#endif
443
444#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
445
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700446#include "sisfb_accel_2_4.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448#endif /* KERNEL VERSION */
449
450