summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/drivers/i128/i128accel.c
blob: 27ad796ccbf8faf46e8e036a13aa8d66b0948fe1 (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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i128/i128accel.c,v 1.4 2000/10/24 02:00:06 robin Exp $ */

/*
 * Copyright 1997-2000 by Robin Cutshaw <robin@XFree86.Org>
 *
 * 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 Robin Cutshaw not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Robin Cutshaw makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as is" without express or implied warranty.
 *
 * ROBIN CUTSHAW DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL ROBIN CUTSHAW 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.
 *
 */

#include "xaa.h"
#include "xaalocal.h"
#include "xf86fbman.h"
#include "miline.h"
#include "servermd.h"

#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "xf86Pci.h"
#include "xf86PciInfo.h"

#include "i128.h"
#include "i128reg.h"

void I128EngineDone(ScrnInfoPtr pScrn);
void I128BitBlit(ScrnInfoPtr pScrn, int x1, int y1, int x2, int y2,
	int w, int h);
void I128SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir,
	int rop, unsigned planemask, int transparency_color);
void I128SubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int x1, int y1,
	int x2, int y2, int w, int h);
void I128SetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop,
	unsigned planemask);
void I128SubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h);
void I128SubsequentSolidTwoPointLine(ScrnInfoPtr pScrn, int x1, int y1, int x2,
	int y2, int flags);
void I128SetClippingRectangle(ScrnInfoPtr pScrn, int x1, int y1,
	int x2, int y2);
void I128FillSolidRects(ScrnInfoPtr pScrn, int fg, int rop,
	unsigned int planemask, int nBox, register BoxPtr pBoxI);
void I128ScreenToScreenBitBlt(ScrnInfoPtr pScrn, int nbox, DDXPointPtr pptSrc,
	BoxPtr pbox, int xdir, int ydir, int alu, unsigned planemask);


#define ENG_PIPELINE_READY() { while (pI128->mem.rbase_a[BUSY] & BUSY_BUSY) ; }
#define ENG_DONE() { while (pI128->mem.rbase_a[FLOW] & (FLOW_DEB | FLOW_MCB | FLOW_PRV)) ;}


/* pre-shift rops and just or in as needed */

static CARD32 i128alu[16] =
{
   CR_CLEAR<<8,
   CR_AND<<8,
   CR_AND_REV<<8,
   CR_COPY<<8,
   CR_AND_INV<<8,
   CR_NOOP<<8,
   CR_XOR<<8,
   CR_OR<<8,
   CR_NOR<<8,
   CR_EQUIV<<8,
   CR_INVERT<<8,
   CR_OR_REV<<8,
   CR_COPY_INV<<8,
   CR_OR_INV<<8,
   CR_NAND<<8,
   CR_SET<<8
};
                        /*  8bpp   16bpp  32bpp unused */
static int min_size[]   = { 0x62,  0x32,  0x1A, 0x00 };
static int max_size[]   = { 0x80,  0x40,  0x20, 0x00 };
static int split_size[] = { 0x20,  0x10,  0x08, 0x00 };


void
I128EngineDone(ScrnInfoPtr pScrn)
{
	I128Ptr pI128 = I128PTR(pScrn);
	ENG_DONE();
}


void
I128BitBlit(ScrnInfoPtr pScrn, int x1, int y1, int x2, int y2, int w, int h)
{
	I128Ptr pI128 = I128PTR(pScrn);

#if 0
	if (pI128->Debug)
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "BB %d,%d %d,%d %d,%d\n", x1, y1, x2, y2, w, h);
#endif

	ENG_PIPELINE_READY();

	pI128->mem.rbase_a[CMD] = pI128->cmd;
	/*pI128->mem.rbase_a[XY3_DIR] = pI128->blitdir;*/

	if (pI128->blitdir & DIR_RL_TB) {
		x1 += w; x1--;
		x2 += w; x2--;
	}
	if (pI128->blitdir & DIR_LR_BT) {
		y1 += h; y1--;
		y2 += h; y2--;
	}



	if (pI128->Chipset == PCI_CHIP_I128) {
		int bppi;

		static int first_time_through = 1;

		/* The I128-1 has a nasty bitblit bug
		 * that occurs when dest is exactly 8 pages wide
		 */
		
		bppi = (pI128->mem.rbase_a[BUF_CTRL] & BC_PSIZ_MSK) >> 24;

		if ((w >= min_size[bppi]) && (w <= max_size[bppi])) {
			if (first_time_through) {
	    			xf86DrvMsg(pScrn->scrnIndex, X_INFO,
            				"Using I128-1 workarounds.\n");
				first_time_through = 0;
			}

			bppi = split_size[bppi];
#if 1
			/* split method */

			pI128->mem.rbase_a[XY2_WH] = (bppi<<16) | h;
			pI128->mem.rbase_a[XY0_SRC] = (x1<<16) | y1;	MB;
			pI128->mem.rbase_a[XY1_DST] = (x2<<16) | y2;	MB;

			ENG_PIPELINE_READY();

			w -= bppi;

			if (pI128->blitdir & DIR_RL_TB) {
				/* right to left blit */
				x1 -= bppi;
				x2 -= bppi;
			} else {
				/* left to right blit */
				x1 += bppi;
				x2 += bppi;
			}
#else
			/* clip method */
			pI128->mem.rbase_a[CLPTL] = (x2<<16) | y2;
			pI128->mem.rbase_a[CLPBR] = ((x2+w)<<16) | (y2+h);
			w += bppi;
#endif
		}
	}

	pI128->mem.rbase_a[XY2_WH] = (w<<16) | h;
	pI128->mem.rbase_a[XY0_SRC] = (x1<<16) | y1;			MB;
	pI128->mem.rbase_a[XY1_DST] = (x2<<16) | y2;			MB;
}

void
I128SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir,
	int rop, unsigned planemask, int transparency_color)
{
	I128Ptr pI128 = I128PTR(pScrn);

#if 0
	if (pI128->Debug)
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "SFSSC %d,%d %d 0x%x %d\n", xdir, ydir, rop, planemask, transparency_color);
#endif

	ENG_PIPELINE_READY();

	if (planemask == -1)
		pI128->mem.rbase_a[MASK] = -1;
	else switch (pI128->bitsPerPixel) {
		case 8:
			pI128->mem.rbase_a[MASK] = planemask |
					(planemask<<8) |
					(planemask<<16) |
					(planemask<<24);
			break;
		case 16:
			pI128->mem.rbase_a[MASK] = planemask | (planemask<<16);
			break;
		case 24:
		case 32:
		default:
			pI128->mem.rbase_a[MASK] = planemask;
			break;
	}


	pI128->mem.rbase_a[CLPTL] = 0x00000000;
	pI128->mem.rbase_a[CLPBR] = (4095<<16) | 2047;

	if (transparency_color != -1)
		pI128->mem.rbase_a[BACK] = transparency_color;


	if (xdir == -1) {
		if (ydir == -1) pI128->blitdir = DIR_RL_BT;
		else            pI128->blitdir = DIR_RL_TB;
	} else {
		if (ydir == -1) pI128->blitdir = DIR_LR_BT;
		else            pI128->blitdir = DIR_LR_TB;
	}
	pI128->mem.rbase_a[XY3_DIR] = pI128->blitdir;

	pI128->rop = i128alu[rop];
	pI128->cmd = (transparency_color != -1 ? (CS_TRNSP<<16) : 0) |
		  pI128->rop | CO_BITBLT;
	pI128->mem.rbase_a[CMD] = pI128->cmd;
}

void
I128SubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int x1, int y1,
	int x2, int y2, int w, int h)
{
	I128BitBlit(pScrn, x1, y1, x2, y2, w, h);
}

void
I128SetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop, unsigned planemask)
{
	I128Ptr pI128 = I128PTR(pScrn);

#if 0
	if (pI128->Debug)
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "SFSF color 0x%x rop 0x%x (I128rop 0x%x) pmask 0x%x\n", color, rop, i128alu[rop]>>8, planemask);
#endif

	ENG_PIPELINE_READY();

	if (planemask == -1)
		pI128->mem.rbase_a[MASK] = -1;
	else switch (pI128->bitsPerPixel) {
		case 8:
			pI128->mem.rbase_a[MASK] = planemask |
					(planemask<<8) |
					(planemask<<16) |
					(planemask<<24);
			break;
		case 16:
			pI128->mem.rbase_a[MASK] = planemask | (planemask<<16);
			break;
		case 24:
		case 32:
		default:
			pI128->mem.rbase_a[MASK] = planemask;
			break;
	}

	pI128->mem.rbase_a[FORE] = color;

	pI128->clptl = pI128->mem.rbase_a[CLPTL] = 0x00000000;
	pI128->clpbr = pI128->mem.rbase_a[CLPBR] = (4095<<16) | 2047 ;

	pI128->mem.rbase_a[XY3_DIR] = pI128->blitdir = DIR_LR_TB;

	pI128->rop = i128alu[rop];
	pI128->cmd = (CS_SOLID<<16) | pI128->rop | CO_BITBLT;
	pI128->mem.rbase_a[CMD] = pI128->cmd;
}

void
I128SubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
{
#if 0
	I128Ptr pI128 = I128PTR(pScrn);

	if (pI128->Debug)
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "SSFR %d,%d %d,%d\n", x, y, w, h);
#endif
	I128BitBlit(pScrn, 0, 0, x, y, w, h);
}

void
I128SubsequentSolidTwoPointLine(ScrnInfoPtr pScrn, int x1, int y1, int x2,
	int y2, int flags)
{
	I128Ptr pI128 = I128PTR(pScrn);

#if 0
	if (pI128->Debug)
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "STPL I128rop 0x%x  %d,%d %d,%d   clip %d,%d %d,%d\n", pI128->rop, x1, y1, x2, y2, pI128->clptl>>16, pI128->clptl&0xffff, (pI128->clpbr>>16)&0xffff, pI128->clpbr&0xffff);
#endif

	ENG_PIPELINE_READY();

	pI128->mem.rbase_a[CMD] =
			((flags&0x0100) ? (CP_NLST<<24) : 0) |
			(CC_CLPRECI<<21) |
			(CS_SOLID<<16) |
			pI128->rop |
			CO_LINE;

	pI128->mem.rbase_a[CLPTL] = pI128->clptl;
	pI128->mem.rbase_a[CLPBR] = pI128->clpbr;

	pI128->mem.rbase_a[XY0_SRC] = (x1<<16) | y1;			MB;
	pI128->mem.rbase_a[XY1_DST] = (x2<<16) | y2;			MB;
}

void
I128SetClippingRectangle(ScrnInfoPtr pScrn, int x1, int y1, int x2, int y2)
{
	I128Ptr pI128 = I128PTR(pScrn);
	int tmp;

#if 0
	if (pI128->Debug)
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "SCR  %d,%d %d,%d\n", x1, y1, x2, y2);
#endif

	if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; }
	if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; }

	pI128->clptl = (x1<<16) | y1;
	pI128->clpbr = (x2<<16) | y2;
}


void
I128FillSolidRects(ScrnInfoPtr pScrn, int fg, int rop, unsigned int planemask,
	int nBox, register BoxPtr pBoxI)
{
	I128Ptr pI128 = I128PTR(pScrn);
	register int w, h;

#if 0
	if (pI128->Debug)
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FSR color 0x%x rop 0x%x (I128rop 0x%x) pmask 0x%x\n", fg, rop, i128alu[rop]>>8, planemask);
#endif

	ENG_PIPELINE_READY();

	if (planemask != -1) {
		if (pI128->bitsPerPixel == 8) {
			planemask |= (planemask<<8)  |
				     (planemask<<16) |
				     (planemask<<24);
		} else if (pI128->bitsPerPixel == 16)
			planemask |= planemask<<16;
	}

	pI128->mem.rbase_a[MASK] = planemask;
	pI128->mem.rbase_a[FORE] = fg;
	pI128->mem.rbase_a[CMD] = (CS_SOLID<<16) | i128alu[rop] | CO_BITBLT;
	pI128->mem.rbase_a[CLPTL] = 0x00000000;
	pI128->mem.rbase_a[CLPBR] = (4095<<16) | 2047;

	pI128->mem.rbase_a[XY3_DIR] = DIR_LR_TB;
	pI128->mem.rbase_a[XY0_SRC] = 0x00000000;

	while (nBox > 0) {
		w = pBoxI->x2 - pBoxI->x1;
		h = pBoxI->y2 - pBoxI->y1;
		if (w > 0 && h > 0) {
			pI128->mem.rbase_a[XY2_WH] = (w<<16) | h;	MB;
			pI128->mem.rbase_a[XY1_DST] =
				(pBoxI->x1<<16) | pBoxI->y1;		MB;

			ENG_PIPELINE_READY();
#if 0
			if (pI128->Debug)
				xf86DrvMsg(pScrn->scrnIndex, X_INFO, "FSR x,y %d,%d w,h %d,%d\n", pBoxI->x1, pBoxI->y1, w, h);
#endif

		}
		pBoxI++;
		nBox--;
	}

	ENG_DONE();

}


void
I128ScreenToScreenBitBlt(ScrnInfoPtr pScrn, int nbox, DDXPointPtr pptSrc,
	BoxPtr pbox, int xdir, int ydir, int alu, unsigned planemask)
{
	I128Ptr pI128 = I128PTR(pScrn);
        I128SetupForScreenToScreenCopy(pScrn, xdir, ydir, alu, planemask, -1);
        for (; nbox; pbox++, pptSrc++, nbox--)
            I128SubsequentScreenToScreenCopy(pScrn, pptSrc->x, pptSrc->y,
                pbox->x1, pbox->y1, pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
	ENG_DONE();
}


Bool
I128AccelInit(ScreenPtr pScreen)
{
	XAAInfoRecPtr infoPtr;
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
	I128Ptr pI128 = I128PTR(pScrn);
	BoxRec AvailFBArea;
	CARD32 buf_ctrl;
	int maxlines;

	pI128->AccelInfoRec = infoPtr = XAACreateInfoRec();
	if (!infoPtr) return FALSE;

	infoPtr->Flags = 	PIXMAP_CACHE |
				OFFSCREEN_PIXMAPS |
				LINEAR_FRAMEBUFFER ;

	infoPtr->Sync = I128EngineDone;

	/* screen to screen copy */
	infoPtr->ScreenToScreenCopyFlags = 0;
	if (pI128->Chipset == PCI_CHIP_I128_T2R)
		infoPtr->ScreenToScreenCopyFlags |= ONLY_LEFT_TO_RIGHT_BITBLT;

	infoPtr->SetupForScreenToScreenCopy = I128SetupForScreenToScreenCopy;
	infoPtr->SubsequentScreenToScreenCopy =
					    I128SubsequentScreenToScreenCopy;

	/* solid fills */
	infoPtr->SetupForSolidFill = I128SetupForSolidFill;
	infoPtr->SubsequentSolidFillRect = I128SubsequentSolidFillRect;

	infoPtr->FillSolidRects = I128FillSolidRects;

	/* solid lines */
	infoPtr->SubsequentSolidTwoPointLine = I128SubsequentSolidTwoPointLine;

	/* clipping */
	infoPtr->ClippingFlags = HARDWARE_CLIP_LINE;
	infoPtr->SetClippingRectangle = I128SetClippingRectangle;

	infoPtr->PolyFillRectSolidFlags = 0;

	maxlines = ((pI128->MemorySize * 1024) - 1024) /
			  (pScrn->displayWidth * pI128->bitsPerPixel / 8);
	AvailFBArea.x1 = 0;
	AvailFBArea.x2 = pI128->displayWidth;
	AvailFBArea.y1 = 0;
	AvailFBArea.y2 = maxlines;
	xf86InitFBManager(pScreen, &AvailFBArea);
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		"Using %d lines for offscreen memory\n",
		maxlines - pScrn->virtualY);

	switch (pI128->bitsPerPixel) {
		case 8:  buf_ctrl = BC_PSIZ_8B;  break;
		case 16: buf_ctrl = BC_PSIZ_16B; break;
		case 24:
		case 32: buf_ctrl = BC_PSIZ_32B; break;
		default: buf_ctrl = 0;           break; /* error */
	}
	if (pI128->Chipset == PCI_CHIP_I128_T2R) {
		if (pI128->MemoryType == I128_MEMORY_SGRAM)
			buf_ctrl |= BC_MDM_PLN;
		else
			buf_ctrl |= BC_BLK_ENA;
	}
	pI128->mem.rbase_a[BUF_CTRL] = buf_ctrl;

	pI128->mem.rbase_a[DE_PGE] = 0x00;
	pI128->mem.rbase_a[DE_SORG] = pI128->displayOffset;
	pI128->mem.rbase_a[DE_DORG] = pI128->displayOffset;
	pI128->mem.rbase_a[DE_MSRC] = 0x00;
	pI128->mem.rbase_a[DE_WKEY] = 0x00;
	pI128->mem.rbase_a[DE_SPTCH] = pI128->mem.rbase_g[DB_PTCH];
	pI128->mem.rbase_a[DE_DPTCH] = pI128->mem.rbase_g[DB_PTCH];
	if (pI128->Chipset == PCI_CHIP_I128_T2R4)
		pI128->mem.rbase_a[DE_ZPTCH] = pI128->mem.rbase_g[DB_PTCH];
	pI128->mem.rbase_a[RMSK] = 0x00000000;
	pI128->mem.rbase_a[XY4_ZM] = ZOOM_NONE;
	pI128->mem.rbase_a[LPAT] = 0xffffffff;  /* for lines */
	pI128->mem.rbase_a[PCTRL] = 0x00000000; /* for lines */
	pI128->mem.rbase_a[CLPTL] = 0x00000000;
	pI128->mem.rbase_a[CLPBR] = (4095<<16) | 2047 ;
	pI128->mem.rbase_a[ACNTRL] = 0x00000000;
	pI128->mem.rbase_a[INTM] = 0x03;

	if (pI128->Debug) {
		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "I128AccelInit done\n");
		I128DumpActiveRegisters(pScrn);
	}

	return(XAAInit(pScreen, infoPtr));
}