imstt_accel.c revision 53e90a53
153e90a53Smrg/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/imstt/imstt_accel.c,v 1.5 2001/04/05 21:29:14 dawes Exp $ */
253e90a53Smrg
353e90a53Smrg/*
453e90a53Smrg *	Copyright 2000	Ani Joshi <ajoshi@unixbox.com>
553e90a53Smrg *
653e90a53Smrg *
753e90a53Smrg * Permission to use, copy, modify, distribute, and sell this software and its
853e90a53Smrg * documentation for any purpose is hereby granted without fee, provided that
953e90a53Smrg * the above copyright notice appear in all copies and that both that copyright
1053e90a53Smrg * notice and this permission notice appear in supporting documentation and
1153e90a53Smrg * that the name of Ani Joshi not be used in advertising or
1253e90a53Smrg * publicity pertaining to distribution of the software without specific,
1353e90a53Smrg * written prior permission.  Ani Joshi makes no representations
1453e90a53Smrg * about the suitability of this software for any purpose.  It is provided
1553e90a53Smrg * "as-is" without express or implied warranty.
1653e90a53Smrg *
1753e90a53Smrg * ANI JOSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1853e90a53Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1953e90a53Smrg * EVENT SHALL ANI JOSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2053e90a53Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
2153e90a53Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
2253e90a53Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2353e90a53Smrg * PERFORMANCE OF THIS SOFTWARE.
2453e90a53Smrg *
2553e90a53Smrg */
2653e90a53Smrg
2753e90a53Smrg#ifdef HAVE_CONFIG_H
2853e90a53Smrg#include "config.h"
2953e90a53Smrg#endif
3053e90a53Smrg
3153e90a53Smrg#include <X11/Xarch.h>
3253e90a53Smrg#include "xf86.h"
3353e90a53Smrg#include "compiler.h"
3453e90a53Smrg#include "xf86_OSproc.h"
3553e90a53Smrg#include "xaa.h"
3653e90a53Smrg#include "xf86PciInfo.h"
3753e90a53Smrg
3853e90a53Smrg#include "imstt.h"
3953e90a53Smrg#include "imstt_reg.h"
4053e90a53Smrg
4153e90a53Smrg
4253e90a53Smrg
4353e90a53Smrgstatic void IMSTTSync(ScrnInfoPtr pScrn)
4453e90a53Smrg{
4553e90a53Smrg	IMSTTPtr iptr = IMSTTPTR(pScrn);
4653e90a53Smrg/*	IMSTTMMIO_VARS(); */
4753e90a53Smrg
4853e90a53Smrg	while(INREG(IMSTT_SSTATUS) & 0x80);
4953e90a53Smrg	while(INREG(IMSTT_SSTATUS) & 0x40);
5053e90a53Smrg
5153e90a53Smrg	return;
5253e90a53Smrg}
5353e90a53Smrg
5453e90a53Smrg
5553e90a53Smrgstatic void IMSTTSetupForSolidFill(ScrnInfoPtr pScrn, int color,
5653e90a53Smrg				   int rop, unsigned int planemask)
5753e90a53Smrg{
5853e90a53Smrg	IMSTTPtr iptr = IMSTTPTR(pScrn);
5953e90a53Smrg/*	IMSTTMMIO_VARS(); */
6053e90a53Smrg
6153e90a53Smrg	switch (pScrn->depth) {
6253e90a53Smrg		case 8:
6353e90a53Smrg			iptr->color = color | (color << 8) | (color << 16) | (color << 24);
6453e90a53Smrg			break;
6553e90a53Smrg		case 15:
6653e90a53Smrg		case 16:
6753e90a53Smrg			iptr->color = color | (color << 8) | (color << 16);
6853e90a53Smrg			break;
6953e90a53Smrg		default:
7053e90a53Smrg			iptr->color = color;
7153e90a53Smrg			break;
7253e90a53Smrg	}
7353e90a53Smrg}
7453e90a53Smrg
7553e90a53Smrg
7653e90a53Smrgstatic void IMSTTSubsequentSolidFillRect(ScrnInfoPtr pScrn,
7753e90a53Smrg					 int x, int y, int w, int h)
7853e90a53Smrg{
7953e90a53Smrg	IMSTTPtr iptr = IMSTTPTR(pScrn);
8053e90a53Smrg/*	IMSTTMMIO_VARS(); */
8153e90a53Smrg
8253e90a53Smrg	x *= (pScrn->bitsPerPixel >> 3);
8353e90a53Smrg	y *= iptr->ll;
8453e90a53Smrg	w *= (pScrn->bitsPerPixel >> 3);
8553e90a53Smrg	h--;
8653e90a53Smrg	w--;
8753e90a53Smrg
8853e90a53Smrg	while(INREG(IMSTT_SSTATUS) & 0x80);
8953e90a53Smrg	OUTREG(IMSTT_DSA, x + y);
9053e90a53Smrg	OUTREG(IMSTT_CNT, (h << 16) | w);
9153e90a53Smrg	OUTREG(IMSTT_DP_OCTL, iptr->ll);
9253e90a53Smrg	OUTREG(IMSTT_SP, iptr->ll);
9353e90a53Smrg	OUTREG(IMSTT_BI, 0xffffffff);
9453e90a53Smrg	OUTREG(IMSTT_MBC, 0xffffffff);
9553e90a53Smrg	OUTREG(IMSTT_CLR, iptr->color);
9653e90a53Smrg
9753e90a53Smrg	if (iptr->rev == 2)
9853e90a53Smrg		OUTREG(IMSTT_BLTCTL, 0x200000);
9953e90a53Smrg	else
10053e90a53Smrg		OUTREG(IMSTT_BLTCTL, 0x840);
10153e90a53Smrg
10253e90a53Smrg	while(INREG(IMSTT_SSTATUS) & 0x80);
10353e90a53Smrg	while(INREG(IMSTT_SSTATUS) & 0x40);
10453e90a53Smrg}
10553e90a53Smrg
10653e90a53Smrg
10753e90a53Smrgstatic void IMSTTSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir,
10853e90a53Smrg					    int ydir, int rop, unsigned int planemask,
10953e90a53Smrg					    int trans_color)
11053e90a53Smrg{
11153e90a53Smrg	IMSTTPtr iptr = IMSTTPTR(pScrn);
11253e90a53Smrg/*	IMSTTMMIO_VARS(); */
11353e90a53Smrg	unsigned long sp, dp, ll;
11453e90a53Smrg
11553e90a53Smrg	iptr->bltctl = 0x05;
11653e90a53Smrg
11753e90a53Smrg	ll = pScrn->displayWidth * (pScrn->bitsPerPixel >> 3);
11853e90a53Smrg	ll = iptr->ll;
11953e90a53Smrg
12053e90a53Smrg	sp = ll << 16;
12153e90a53Smrg
12253e90a53Smrg	if (xdir < 0) {
12353e90a53Smrg		iptr->bltctl |= 0x80;
12453e90a53Smrg		iptr->cnt = 1;
12553e90a53Smrg	} else {
12653e90a53Smrg		iptr->cnt = 0;
12753e90a53Smrg	}
12853e90a53Smrg
12953e90a53Smrg	if (ydir < 0) {
13053e90a53Smrg		sp |= -(ll) & 0xffff;
13153e90a53Smrg		dp = -(ll) & 0xffff;
13253e90a53Smrg		iptr->ydir = 1;
13353e90a53Smrg	} else {
13453e90a53Smrg		sp |= ll;
13553e90a53Smrg		dp = ll;
13653e90a53Smrg		iptr->ydir = 0;
13753e90a53Smrg	}
13853e90a53Smrg
13953e90a53Smrg	iptr->sp = sp;
14053e90a53Smrg	iptr->dp = dp;
14153e90a53Smrg	iptr->ll = ll;
14253e90a53Smrg}
14353e90a53Smrg
14453e90a53Smrg
14553e90a53Smrgstatic void IMSTTSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn,
14653e90a53Smrg					      int x1, int y1,
14753e90a53Smrg					      int x2, int y2,
14853e90a53Smrg					      int w, int h)
14953e90a53Smrg{
15053e90a53Smrg	IMSTTPtr iptr = IMSTTPTR(pScrn);
15153e90a53Smrg/*	IMSTTMMIO_VARS(); */
15253e90a53Smrg	unsigned long cnt;
15353e90a53Smrg
15453e90a53Smrg	x1 *= (pScrn->bitsPerPixel >> 3);
15553e90a53Smrg	x2 *= (pScrn->bitsPerPixel >> 3);
15653e90a53Smrg	w *= (pScrn->bitsPerPixel >> 3);
15753e90a53Smrg	w--;
15853e90a53Smrg	h--;
15953e90a53Smrg	cnt = h << 16;
16053e90a53Smrg
16153e90a53Smrg	if (iptr->cnt) {
16253e90a53Smrg		x1 += w;
16353e90a53Smrg		x2 += w;
16453e90a53Smrg		cnt |= -(w) & 0xffff;
16553e90a53Smrg	}
16653e90a53Smrg	else
16753e90a53Smrg		cnt |= w;
16853e90a53Smrg
16953e90a53Smrg	if (iptr->ydir) {
17053e90a53Smrg		y1 += h;
17153e90a53Smrg		y2 += h;
17253e90a53Smrg	}
17353e90a53Smrg
17453e90a53Smrg	OUTREG(IMSTT_S1SA, y1 * iptr->ll + x1);
17553e90a53Smrg	OUTREG(IMSTT_SP, iptr->sp);
17653e90a53Smrg	OUTREG(IMSTT_DSA, y2 * iptr->ll + x2);
17753e90a53Smrg	OUTREG(IMSTT_CNT, cnt);
17853e90a53Smrg	OUTREG(IMSTT_DP_OCTL, iptr->dp);
17953e90a53Smrg	OUTREG(IMSTT_BLTCTL, iptr->bltctl);
18053e90a53Smrg	while(INREG(IMSTT_SSTATUS) & 0x80);
18153e90a53Smrg	while(INREG(IMSTT_SSTATUS) & 0x40);
18253e90a53Smrg}
18353e90a53Smrg
18453e90a53Smrg
18553e90a53Smrg
18653e90a53SmrgBool IMSTTAccelInit(ScreenPtr pScreen)
18753e90a53Smrg{
18853e90a53Smrg	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
18953e90a53Smrg	IMSTTPtr iptr = IMSTTPTR(pScrn);
19053e90a53Smrg	XAAInfoRecPtr xaaptr;
19153e90a53Smrg
19253e90a53Smrg	if (!(xaaptr = iptr->AccelInfoRec = XAACreateInfoRec()))
19353e90a53Smrg		return FALSE;
19453e90a53Smrg
19553e90a53Smrg	iptr->ll = pScrn->displayWidth * (pScrn->bitsPerPixel >> 3);
19653e90a53Smrg
19753e90a53Smrg	switch (pScrn->bitsPerPixel) {
19853e90a53Smrg		case 16:
19953e90a53Smrg			iptr->screen_width = iptr->pitch >> 1;
20053e90a53Smrg			break;
20153e90a53Smrg		case 24:
20253e90a53Smrg		case 32:
20353e90a53Smrg			iptr->screen_width = iptr->pitch >> 2;
20453e90a53Smrg			break;
20553e90a53Smrg		default:
20653e90a53Smrg			iptr->screen_width = iptr->pitch = iptr->ll;
20753e90a53Smrg			break;
20853e90a53Smrg	}
20953e90a53Smrg
21053e90a53Smrg	xaaptr->Flags = (PIXMAP_CACHE | OFFSCREEN_PIXMAPS | LINEAR_FRAMEBUFFER);
21153e90a53Smrg
21253e90a53Smrg	xaaptr->Sync = IMSTTSync;
21353e90a53Smrg
21453e90a53Smrg	if (pScrn->bitsPerPixel == 8) {
21553e90a53Smrg		/* FIXME fills are broken > 8bpp, iptr->color needs to be setup right */
21653e90a53Smrg		xaaptr->SetupForSolidFill = IMSTTSetupForSolidFill;
21753e90a53Smrg		xaaptr->SubsequentSolidFillRect = IMSTTSubsequentSolidFillRect;
21853e90a53Smrg	}
21953e90a53Smrg
22053e90a53Smrg	xaaptr->ScreenToScreenCopyFlags = NO_TRANSPARENCY;
22153e90a53Smrg	xaaptr->SetupForScreenToScreenCopy = IMSTTSetupForScreenToScreenCopy;
22253e90a53Smrg	xaaptr->SubsequentScreenToScreenCopy = IMSTTSubsequentScreenToScreenCopy;
22353e90a53Smrg
22453e90a53Smrg	return XAAInit(pScreen, xaaptr);
22553e90a53Smrg}
22653e90a53Smrg
227