sis_accel.c 11.9 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
T
Thomas Winischhofer 已提交
2 3 4 5
 * SiS 300/540/630[S]/730[S],
 * SiS 315[E|PRO]/550/[M]650/651/[M]661[F|M]X/740/[M]741[GX]/330/[M]760[GX],
 * XGI V3XT/V5/V8, Z7
 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
L
Linus Torvalds 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 2D acceleration part
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the named License,
 * or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
 *
 * Based on the XFree86/X.org driver which is
T
Thomas Winischhofer 已提交
24
 *     Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
L
Linus Torvalds 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
 *
 * Author: Thomas Winischhofer <thomas@winischhofer.net>
 *			(see http://www.winischhofer.net/
 *			for more information and updates)
 */

#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fb.h>
#include <linux/ioport.h>
#include <linux/types.h>
#include <asm/io.h>

#include "sis.h"
#include "sis_accel.h"

static const u8 sisALUConv[] =
{
    0x00,       /* dest = 0;            0,      GXclear,        0 */
    0x88,       /* dest &= src;         DSa,    GXand,          0x1 */
    0x44,       /* dest = src & ~dest;  SDna,   GXandReverse,   0x2 */
    0xCC,       /* dest = src;          S,      GXcopy,         0x3 */
    0x22,       /* dest &= ~src;        DSna,   GXandInverted,  0x4 */
    0xAA,       /* dest = dest;         D,      GXnoop,         0x5 */
    0x66,       /* dest = ^src;         DSx,    GXxor,          0x6 */
    0xEE,       /* dest |= src;         DSo,    GXor,           0x7 */
    0x11,       /* dest = ~src & ~dest; DSon,   GXnor,          0x8 */
    0x99,       /* dest ^= ~src ;       DSxn,   GXequiv,        0x9 */
    0x55,       /* dest = ~dest;        Dn,     GXInvert,       0xA */
    0xDD,       /* dest = src|~dest ;   SDno,   GXorReverse,    0xB */
    0x33,       /* dest = ~src;         Sn,     GXcopyInverted, 0xC */
    0xBB,       /* dest |= ~src;        DSno,   GXorInverted,   0xD */
    0x77,       /* dest = ~src|~dest;   DSan,   GXnand,         0xE */
    0xFF,       /* dest = 0xFF;         1,      GXset,          0xF */
};
/* same ROP but with Pattern as Source */
static const u8 sisPatALUConv[] =
{
    0x00,       /* dest = 0;            0,      GXclear,        0 */
    0xA0,       /* dest &= src;         DPa,    GXand,          0x1 */
    0x50,       /* dest = src & ~dest;  PDna,   GXandReverse,   0x2 */
    0xF0,       /* dest = src;          P,      GXcopy,         0x3 */
    0x0A,       /* dest &= ~src;        DPna,   GXandInverted,  0x4 */
    0xAA,       /* dest = dest;         D,      GXnoop,         0x5 */
    0x5A,       /* dest = ^src;         DPx,    GXxor,          0x6 */
    0xFA,       /* dest |= src;         DPo,    GXor,           0x7 */
    0x05,       /* dest = ~src & ~dest; DPon,   GXnor,          0x8 */
    0xA5,       /* dest ^= ~src ;       DPxn,   GXequiv,        0x9 */
    0x55,       /* dest = ~dest;        Dn,     GXInvert,       0xA */
    0xF5,       /* dest = src|~dest ;   PDno,   GXorReverse,    0xB */
    0x0F,       /* dest = ~src;         Pn,     GXcopyInverted, 0xC */
    0xAF,       /* dest |= ~src;        DPno,   GXorInverted,   0xD */
    0x5F,       /* dest = ~src|~dest;   DPan,   GXnand,         0xE */
    0xFF,       /* dest = 0xFF;         1,      GXset,          0xF */
};

static const int myrops[] = {
   	3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};

/* 300 series ----------------------------------------------------- */
#ifdef CONFIG_FB_SIS_300
static void
SiS300Sync(struct sis_video_info *ivideo)
{
	SiS300Idle
}

static void
SiS300SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int xdir, int ydir,
                                 int rop, int trans_color)
{
	SiS300SetupDSTColorDepth(ivideo->DstColor);
	SiS300SetupSRCPitch(ivideo->video_linelength)
	SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)

	if(trans_color != -1) {
		SiS300SetupROP(0x0A)
		SiS300SetupSRCTrans(trans_color)
		SiS300SetupCMDFlag(TRANSPARENT_BITBLT)
	} else {
	        SiS300SetupROP(sisALUConv[rop])
	}
	if(xdir > 0) {
		SiS300SetupCMDFlag(X_INC)
	}
	if(ydir > 0) {
		SiS300SetupCMDFlag(Y_INC)
	}
}

static void
SiS300SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x,
				   int src_y, int dst_x, int dst_y, int width, int height)
{
	u32 srcbase = 0, dstbase = 0;

	if(src_y >= 2048) {
		srcbase = ivideo->video_linelength * src_y;
		src_y = 0;
	}
	if(dst_y >= 2048) {
		dstbase = ivideo->video_linelength * dst_y;
		dst_y = 0;
	}

	SiS300SetupSRCBase(srcbase);
	SiS300SetupDSTBase(dstbase);

	if(!(ivideo->CommandReg & X_INC))  {
		src_x += width-1;
		dst_x += width-1;
	}
	if(!(ivideo->CommandReg & Y_INC))  {
		src_y += height-1;
		dst_y += height-1;
	}
	SiS300SetupRect(width, height)
	SiS300SetupSRCXY(src_x, src_y)
	SiS300SetupDSTXY(dst_x, dst_y)
	SiS300DoCMD
}

static void
SiS300SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
{
	SiS300SetupPATFG(color)
	SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
	SiS300SetupDSTColorDepth(ivideo->DstColor);
	SiS300SetupROP(sisPatALUConv[rop])
	SiS300SetupCMDFlag(PATFG)
}

static void
SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
{
	u32 dstbase = 0;

	if(y >= 2048) {
		dstbase = ivideo->video_linelength * y;
		y = 0;
	}
	SiS300SetupDSTBase(dstbase)
	SiS300SetupDSTXY(x,y)
	SiS300SetupRect(w,h)
	SiS300SetupCMDFlag(X_INC | Y_INC | BITBLT)
	SiS300DoCMD
}
#endif

T
Thomas Winischhofer 已提交
176
/* 315/330/340 series ---------------------------------------------- */
L
Linus Torvalds 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189

#ifdef CONFIG_FB_SIS_315
static void
SiS310Sync(struct sis_video_info *ivideo)
{
	SiS310Idle
}

static void
SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int trans_color)
{
	SiS310SetupDSTColorDepth(ivideo->DstColor);
	SiS310SetupSRCPitch(ivideo->video_linelength)
T
Thomas Winischhofer 已提交
190
	SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
L
Linus Torvalds 已提交
191 192 193 194 195 196 197 198 199 200
	if(trans_color != -1) {
		SiS310SetupROP(0x0A)
		SiS310SetupSRCTrans(trans_color)
		SiS310SetupCMDFlag(TRANSPARENT_BITBLT)
	} else {
	        SiS310SetupROP(sisALUConv[rop])
		/* Set command - not needed, both 0 */
		/* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
	}
	SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
T
Thomas Winischhofer 已提交
201
	/* The chip is smart enough to know the direction */
L
Linus Torvalds 已提交
202 203 204 205 206 207 208 209 210
}

static void
SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int src_y,
			 int dst_x, int dst_y, int width, int height)
{
	u32 srcbase = 0, dstbase = 0;
	int mymin = min(src_y, dst_y);
	int mymax = max(src_y, dst_y);
T
Thomas Winischhofer 已提交
211

L
Linus Torvalds 已提交
212
	/* Although the chip knows the direction to use
T
Thomas Winischhofer 已提交
213
	 * if the source and destination areas overlap,
L
Linus Torvalds 已提交
214 215
	 * that logic fails if we fiddle with the bitmap
	 * addresses. Therefore, we check if the source
T
Thomas Winischhofer 已提交
216 217
	 * and destination blitting areas overlap and
	 * adapt the bitmap addresses synchronously
L
Linus Torvalds 已提交
218
	 * if the coordinates exceed the valid range.
T
Thomas Winischhofer 已提交
219
	 * The the areas do not overlap, we do our
L
Linus Torvalds 已提交
220 221
	 * normal check.
	 */
T
Thomas Winischhofer 已提交
222 223 224 225 226 227 228
	if((mymax - mymin) < height) {
		if((src_y >= 2048) || (dst_y >= 2048)) {
			srcbase = ivideo->video_linelength * mymin;
			dstbase = ivideo->video_linelength * mymin;
			src_y -= mymin;
			dst_y -= mymin;
		}
L
Linus Torvalds 已提交
229
	} else {
T
Thomas Winischhofer 已提交
230 231 232 233 234 235 236 237
		if(src_y >= 2048) {
			srcbase = ivideo->video_linelength * src_y;
			src_y = 0;
		}
		if(dst_y >= 2048) {
			dstbase = ivideo->video_linelength * dst_y;
			dst_y = 0;
		}
L
Linus Torvalds 已提交
238 239
	}

T
Thomas Winischhofer 已提交
240 241 242
	srcbase += ivideo->video_offset;
	dstbase += ivideo->video_offset;

L
Linus Torvalds 已提交
243 244 245 246 247 248 249 250 251 252 253 254
	SiS310SetupSRCBase(srcbase);
	SiS310SetupDSTBase(dstbase);
	SiS310SetupRect(width, height)
	SiS310SetupSRCXY(src_x, src_y)
	SiS310SetupDSTXY(dst_x, dst_y)
	SiS310DoCMD
}

static void
SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
{
	SiS310SetupPATFG(color)
T
Thomas Winischhofer 已提交
255
	SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
L
Linus Torvalds 已提交
256 257 258 259 260 261 262 263 264 265 266 267 268 269
	SiS310SetupDSTColorDepth(ivideo->DstColor);
	SiS310SetupROP(sisPatALUConv[rop])
	SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
}

static void
SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
{
	u32 dstbase = 0;

	if(y >= 2048) {
		dstbase = ivideo->video_linelength * y;
		y = 0;
	}
T
Thomas Winischhofer 已提交
270
	dstbase += ivideo->video_offset;
L
Linus Torvalds 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
	SiS310SetupDSTBase(dstbase)
	SiS310SetupDSTXY(x,y)
	SiS310SetupRect(w,h)
	SiS310SetupCMDFlag(BITBLT)
	SiS310DoCMD
}
#endif

/* --------------------------------------------------------------------- */

/* The exported routines */

int sisfb_initaccel(struct sis_video_info *ivideo)
{
#ifdef SISFB_USE_SPINLOCKS
T
Thomas Winischhofer 已提交
286
	spin_lock_init(&ivideo->lockaccel);
L
Linus Torvalds 已提交
287
#endif
T
Thomas Winischhofer 已提交
288
	return 0;
L
Linus Torvalds 已提交
289 290 291 292
}

void sisfb_syncaccel(struct sis_video_info *ivideo)
{
T
Thomas Winischhofer 已提交
293
	if(ivideo->sisvga_engine == SIS_300_VGA) {
L
Linus Torvalds 已提交
294
#ifdef CONFIG_FB_SIS_300
T
Thomas Winischhofer 已提交
295
		SiS300Sync(ivideo);
L
Linus Torvalds 已提交
296
#endif
T
Thomas Winischhofer 已提交
297
	} else {
L
Linus Torvalds 已提交
298
#ifdef CONFIG_FB_SIS_315
T
Thomas Winischhofer 已提交
299
		SiS310Sync(ivideo);
L
Linus Torvalds 已提交
300
#endif
T
Thomas Winischhofer 已提交
301
	}
L
Linus Torvalds 已提交
302 303 304 305
}

int fbcon_sis_sync(struct fb_info *info)
{
T
Thomas Winischhofer 已提交
306 307
	struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
	CRITFLAGS
L
Linus Torvalds 已提交
308

T
Thomas Winischhofer 已提交
309 310
	if((!ivideo->accel) || (!ivideo->engineok))
		return 0;
L
Linus Torvalds 已提交
311

T
Thomas Winischhofer 已提交
312 313 314 315 316
	CRITBEGIN
	sisfb_syncaccel(ivideo);
	CRITEND

	return 0;
L
Linus Torvalds 已提交
317 318 319 320
}

void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
{
T
Thomas Winischhofer 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
	u32 col = 0;
	u32 vxres = info->var.xres_virtual;
	u32 vyres = info->var.yres_virtual;
	int width, height;
	CRITFLAGS

	if(info->state != FBINFO_STATE_RUNNING)
		return;

	if((!ivideo->accel) || (!ivideo->engineok)) {
		cfb_fillrect(info, rect);
		return;
	}

	if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
		return;

	/* Clipping */
	width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width;
	height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height;

	switch(info->var.bits_per_pixel) {
L
Linus Torvalds 已提交
344 345 346 347 348
	case 8:  col = rect->color;
		 break;
	case 16:
	case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
		 break;
T
Thomas Winischhofer 已提交
349
	}
L
Linus Torvalds 已提交
350

T
Thomas Winischhofer 已提交
351
	if(ivideo->sisvga_engine == SIS_300_VGA) {
L
Linus Torvalds 已提交
352
#ifdef CONFIG_FB_SIS_300
T
Thomas Winischhofer 已提交
353 354 355 356
		CRITBEGIN
		SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
		SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
		CRITEND
L
Linus Torvalds 已提交
357
#endif
T
Thomas Winischhofer 已提交
358
	} else {
L
Linus Torvalds 已提交
359
#ifdef CONFIG_FB_SIS_315
T
Thomas Winischhofer 已提交
360 361 362 363
		CRITBEGIN
		SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
		SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
		CRITEND
L
Linus Torvalds 已提交
364
#endif
T
Thomas Winischhofer 已提交
365
	}
L
Linus Torvalds 已提交
366

T
Thomas Winischhofer 已提交
367
	sisfb_syncaccel(ivideo);
L
Linus Torvalds 已提交
368 369 370 371
}

void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
{
T
Thomas Winischhofer 已提交
372 373 374 375 376
	struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
	u32 vxres = info->var.xres_virtual;
	u32 vyres = info->var.yres_virtual;
	int width = area->width;
	int height = area->height;
L
Linus Torvalds 已提交
377 378
	CRITFLAGS

T
Thomas Winischhofer 已提交
379 380
	if(info->state != FBINFO_STATE_RUNNING)
		return;
L
Linus Torvalds 已提交
381

T
Thomas Winischhofer 已提交
382 383 384
	if((!ivideo->accel) || (!ivideo->engineok)) {
		cfb_copyarea(info, area);
		return;
L
Linus Torvalds 已提交
385 386
	}

T
Thomas Winischhofer 已提交
387 388 389 390
	if(!width || !height ||
	   area->sx >= vxres || area->sy >= vyres ||
	   area->dx >= vxres || area->dy >= vyres)
		return;
L
Linus Torvalds 已提交
391

T
Thomas Winischhofer 已提交
392 393 394 395 396
	/* Clipping */
	if((area->sx + width) > vxres) width = vxres - area->sx;
	if((area->dx + width) > vxres) width = vxres - area->dx;
	if((area->sy + height) > vyres) height = vyres - area->sy;
	if((area->dy + height) > vyres) height = vyres - area->dy;
L
Linus Torvalds 已提交
397 398 399

	if(ivideo->sisvga_engine == SIS_300_VGA) {
#ifdef CONFIG_FB_SIS_300
T
Thomas Winischhofer 已提交
400 401 402 403 404 405 406 407 408 409 410 411
		int xdir, ydir;

		if(area->sx < area->dx) xdir = 0;
		else                    xdir = 1;
		if(area->sy < area->dy) ydir = 0;
		else                    ydir = 1;

		CRITBEGIN
		SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
		SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
					area->dx, area->dy, width, height);
		CRITEND
L
Linus Torvalds 已提交
412 413 414
#endif
	} else {
#ifdef CONFIG_FB_SIS_315
T
Thomas Winischhofer 已提交
415 416 417 418 419
		CRITBEGIN
		SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
		SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
					area->dx, area->dy, width, height);
		CRITEND
L
Linus Torvalds 已提交
420 421 422
#endif
	}

T
Thomas Winischhofer 已提交
423
	sisfb_syncaccel(ivideo);
L
Linus Torvalds 已提交
424
}