summaryrefslogtreecommitdiff
path: root/src/imstt_accel.c
blob: e62868adf1280d26f6297aa3ace6f624dd79f65d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/imstt/imstt_accel.c,v 1.5 2001/04/05 21:29:14 dawes Exp $ */

/*
 *	Copyright 2000	Ani Joshi <ajoshi@unixbox.com>
 *
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation and
 * that the name of Ani Joshi not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  Ani Joshi makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as-is" without express or implied warranty.
 *
 * ANI JOSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL ANI JOSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <X11/Xarch.h>
#include "xf86.h"
#include "xf86_ansic.h"
#include "compiler.h"
#include "xf86_OSproc.h"
#include "xaa.h"
#include "xf86PciInfo.h"

#include "imstt.h"
#include "imstt_reg.h"



static void IMSTTSync(ScrnInfoPtr pScrn)
{
	IMSTTPtr iptr = IMSTTPTR(pScrn);
/*	IMSTTMMIO_VARS(); */

	while(INREG(IMSTT_SSTATUS) & 0x80);
	while(INREG(IMSTT_SSTATUS) & 0x40);
	
	return;
}


static void IMSTTSetupForSolidFill(ScrnInfoPtr pScrn, int color,
				   int rop, unsigned int planemask)
{
	IMSTTPtr iptr = IMSTTPTR(pScrn);
/*	IMSTTMMIO_VARS(); */

	switch (pScrn->depth) {
		case 8:
			iptr->color = color | (color << 8) | (color << 16) | (color << 24);
			break;
		case 15:
		case 16:
			iptr->color = color | (color << 8) | (color << 16);
			break;
		default:
			iptr->color = color;
			break;
	}
}


static void IMSTTSubsequentSolidFillRect(ScrnInfoPtr pScrn,
					 int x, int y, int w, int h)
{
	IMSTTPtr iptr = IMSTTPTR(pScrn);
/*	IMSTTMMIO_VARS(); */

	x *= (pScrn->bitsPerPixel >> 3);
	y *= iptr->ll;
	w *= (pScrn->bitsPerPixel >> 3);
	h--;
	w--;

	while(INREG(IMSTT_SSTATUS) & 0x80);
	OUTREG(IMSTT_DSA, x + y);
	OUTREG(IMSTT_CNT, (h << 16) | w);
	OUTREG(IMSTT_DP_OCTL, iptr->ll);
	OUTREG(IMSTT_SP, iptr->ll);
	OUTREG(IMSTT_BI, 0xffffffff);
	OUTREG(IMSTT_MBC, 0xffffffff);
	OUTREG(IMSTT_CLR, iptr->color);

	if (iptr->rev == 2)
		OUTREG(IMSTT_BLTCTL, 0x200000);
	else
		OUTREG(IMSTT_BLTCTL, 0x840);

	while(INREG(IMSTT_SSTATUS) & 0x80);
	while(INREG(IMSTT_SSTATUS) & 0x40);
}


static void IMSTTSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir,
					    int ydir, int rop, unsigned int planemask,
					    int trans_color)
{
	IMSTTPtr iptr = IMSTTPTR(pScrn);
/*	IMSTTMMIO_VARS(); */
	unsigned long sp, dp, ll;

	iptr->bltctl = 0x05;

	ll = pScrn->displayWidth * (pScrn->bitsPerPixel >> 3);
	ll = iptr->ll;

	sp = ll << 16;

	if (xdir < 0) {
		iptr->bltctl |= 0x80;
		iptr->cnt = 1;
	} else {
		iptr->cnt = 0;
	}

	if (ydir < 0) {
		sp |= -(ll) & 0xffff;
		dp = -(ll) & 0xffff;
		iptr->ydir = 1;
	} else {
		sp |= ll;
		dp = ll;
		iptr->ydir = 0;
	}

	iptr->sp = sp;
	iptr->dp = dp;
	iptr->ll = ll;
}


static void IMSTTSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn,
					      int x1, int y1,
					      int x2, int y2,
					      int w, int h)
{
	IMSTTPtr iptr = IMSTTPTR(pScrn);
/*	IMSTTMMIO_VARS(); */
	unsigned long cnt;

	x1 *= (pScrn->bitsPerPixel >> 3);
	x2 *= (pScrn->bitsPerPixel >> 3);
	w *= (pScrn->bitsPerPixel >> 3);
	w--;
	h--;
	cnt = h << 16;

	if (iptr->cnt) {
		x1 += w;
		x2 += w;
		cnt |= -(w) & 0xffff;
	}
	else
		cnt |= w;

	if (iptr->ydir) {
		y1 += h;
		y2 += h;
	}

	OUTREG(IMSTT_S1SA, y1 * iptr->ll + x1);
	OUTREG(IMSTT_SP, iptr->sp);
	OUTREG(IMSTT_DSA, y2 * iptr->ll + x2);
	OUTREG(IMSTT_CNT, cnt);
	OUTREG(IMSTT_DP_OCTL, iptr->dp);
	OUTREG(IMSTT_BLTCTL, iptr->bltctl);
	while(INREG(IMSTT_SSTATUS) & 0x80);
	while(INREG(IMSTT_SSTATUS) & 0x40);
}



Bool IMSTTAccelInit(ScreenPtr pScreen)
{
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
	IMSTTPtr iptr = IMSTTPTR(pScrn);
	XAAInfoRecPtr xaaptr;

	if (!(xaaptr = iptr->AccelInfoRec = XAACreateInfoRec()))
		return FALSE;

	iptr->ll = pScrn->displayWidth * (pScrn->bitsPerPixel >> 3);

	switch (pScrn->bitsPerPixel) {
		case 16:
			iptr->screen_width = iptr->pitch >> 1;
			break;
		case 24:
		case 32:
			iptr->screen_width = iptr->pitch >> 2;
			break;
		default:
			iptr->screen_width = iptr->pitch = iptr->ll;
			break;
	}

	xaaptr->Flags = (PIXMAP_CACHE | OFFSCREEN_PIXMAPS | LINEAR_FRAMEBUFFER);

	xaaptr->Sync = IMSTTSync;

	if (pScrn->bitsPerPixel == 8) {
		/* FIXME fills are broken > 8bpp, iptr->color needs to be setup right */
		xaaptr->SetupForSolidFill = IMSTTSetupForSolidFill;
		xaaptr->SubsequentSolidFillRect = IMSTTSubsequentSolidFillRect;
	}

	xaaptr->ScreenToScreenCopyFlags = NO_TRANSPARENCY;
	xaaptr->SetupForScreenToScreenCopy = IMSTTSetupForScreenToScreenCopy;
	xaaptr->SubsequentScreenToScreenCopy = IMSTTSubsequentScreenToScreenCopy;

	return XAAInit(pScreen, xaaptr);
}