summaryrefslogtreecommitdiff
path: root/src/alp_xaa.c
blob: 417f81694069a8b617420f38bb02df0e6ce18ca5 (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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/* (c) Itai Nahshon */

/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/cirrus/alp_xaa.c,v 1.8 2002/01/25 21:56:00 tsi Exp $ */

#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "compiler.h"

#include "xf86Pci.h"
#include "xf86PciInfo.h"

#include "vgaHW.h"

#include "cir.h"
#define _ALP_PRIVATE_
#include "alp.h"

#define WAIT	outb(pCir->PIOReg, 0x31); \
		while(inb(pCir->PIOReg + 1) & pCir->chip.alp->waitMsk){};
#define WAIT_1	outb(pCir->PIOReg, 0x31); \
		while(inb(pCir->PIOReg + 1) & 0x1){};

static const CARD16 translated_rop[] =
{
  /* GXclear */        0x0032U,
  /* GXand   */        0x0532U,
  /* GXandreverse */   0x0932U,
  /* GXcopy */         0x0D32U,
  /* GXandinversted */ 0x5032U,
  /* GXnoop */         0x0632U,
  /* GXxor */          0x5932U,
  /* GXor */           0x6D32U,
  /* GXnor */          0x9032U,
  /* GXequiv */        0x9532U,
  /* GXinvert */       0x0B32U,
  /* GXorReverse */    0xAD32U,
  /* GXcopyInverted */ 0xD032U,
  /* GXorInverted */   0xD632U,
  /* GXnand */         0xDA32U,
  /* GXset */          0x0E32U
};

#if 1
#define SetupForRop(rop) outw(pCir->PIOReg, translated_rop[rop])
#else
#define SetupForRop(rop) outw(pCir->PIOReg, 0x0D32)
#endif

static void AlpSync(ScrnInfoPtr pScrn)
{
	CirPtr pCir = CIRPTR(pScrn);

#ifdef ALP_DEBUG
	ErrorF("AlpSync\n");
#endif
	WAIT_1;
	return;
}

static void
AlpSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir,
			      int rop, unsigned int planemask,
			      int trans_color)
{
	CirPtr pCir = CIRPTR(pScrn);
	int pitch = pCir->pitch;

#ifdef ALP_DEBUG
	ErrorF("AlpSetupForScreenToScreenCopy xdir=%d ydir=%d rop=%x planemask=%x trans_color=%x\n",
		xdir, ydir, rop, planemask, trans_color);
#endif
	WAIT;
	SetupForRop(rop);
	/* Set dest pitch */
	outw(pCir->PIOReg, ((pitch << 8) & 0xff00) | 0x24);
	outw(pCir->PIOReg, ((pitch) & 0x1f00) | 0x25);
	/* Set source pitch */
	outw(pCir->PIOReg, ((pitch << 8) & 0xff00) | 0x26);
	outw(pCir->PIOReg, ((pitch) & 0x1f00) | 0x27);
}

static void
AlpSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int x1, int y1, int x2,
								int y2, int w, int h)
{
	CirPtr pCir = CIRPTR(pScrn);
	int source, dest;
	int  hh, ww;
	int decrement = 0;
	int pitch = pCir->pitch;

	ww = (w * pScrn->bitsPerPixel / 8) - 1;
	hh = h - 1;
	dest = y2 * pitch + x2 * pScrn->bitsPerPixel / 8;
	source = y1 * pitch + x1 * pScrn->bitsPerPixel / 8;
	if (dest > source) {
		decrement = 1 << 8;
		dest += hh * pitch + ww;
		source += hh * pitch + ww;
	}

	WAIT;

	outw(pCir->PIOReg, decrement | 0x30);

	/* Width */
	outw(pCir->PIOReg, ((ww << 8) & 0xff00) | 0x20);
	outw(pCir->PIOReg, ((ww) & 0x1f00) | 0x21);
	/* Height */
	outw(pCir->PIOReg, ((hh << 8) & 0xff00) | 0x22);
	outw(pCir->PIOReg, ((hh) & 0x0700) | 0x23);


	/* source */
	outw(pCir->PIOReg, ((source << 8) & 0xff00) | 0x2C);
	outw(pCir->PIOReg, ((source) & 0xff00) | 0x2D);
	outw(pCir->PIOReg, ((source >> 8) & 0x3f00)| 0x2E);

	/* dest */
	outw(pCir->PIOReg, ((dest  << 8) & 0xff00) | 0x28);
	outw(pCir->PIOReg, ((dest) & 0xff00) | 0x29);
	outw(pCir->PIOReg, ((dest >> 8) & 0x3f00) | 0x2A);
	if (!pCir->chip.alp->autoStart)
	  outw(pCir->PIOReg, 0x0231);

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequentScreenToScreenCopy x1=%d y1=%d x2=%d y2=%d w=%d h=%d\n",
			x1, y1, x2, y2, w, h);
	ErrorF("AlpSubsequentScreenToScreenCopy s=%d d=%d ww=%d hh=%d\n",
			source, dest, ww, hh);
#endif

}

static void
AlpSetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop,
						unsigned int planemask)
{
	CirPtr pCir = CIRPTR(pScrn);
	AlpPtr pAlp = ALPPTR(pCir);
	int pitch = pCir->pitch;

#ifdef ALP_DEBUG
	ErrorF("AlpSetupForSolidFill color=%x rop=%x planemask=%x\n",
			color, rop, planemask);
#endif
	WAIT;

	SetupForRop(rop);

	switch (pCir -> Chipset)
	{
	case PCI_CHIP_GD7548:
	  /* The GD7548 does not (apparently) support solid filling
	     directly, it always need an actual source.
	     We therefore use it as a pattern fill with a solid
	     pattern */
	  {
	    int source = pAlp->monoPattern8x8;
	    /* source = 8x8 solid mono pattern */
	    outw(pCir->PIOReg, ((source << 8) & 0xff00) | 0x2C);
	    outw(pCir->PIOReg, ((source) & 0xff00) | 0x2D);
	    outw(pCir->PIOReg, ((source >> 8) & 0x3f00) | 0x2E);
	    /* memset() may not be the fastest */
	    memset(pCir->FbBase + pAlp->monoPattern8x8, 0xFF, 8);
	    write_mem_barrier();
	    break;
	  }
        default:
          /* GR33 = 0x04 => does not exist on GD7548 */
	  outw(pCir->PIOReg, 0x0433);
	}

        /* GR30 = color expansion, pattern copy */
	/* Choses 8bpp / 16bpp color expansion */
	outw(pCir->PIOReg, 0xC030 |((pScrn->bitsPerPixel - 8) << 9));

	outw(pCir->PIOReg, ((color << 8) & 0xff00) | 0x01);
	outw(pCir->PIOReg, ((color) & 0xff00) | 0x11);
	outw(pCir->PIOReg, ((color >> 8) & 0xff00) | 0x13);
	outw(pCir->PIOReg, 0x15);

	/* Set dest pitch */
	outw(pCir->PIOReg, ((pitch << 8) & 0xff00) | 0x24);
	outw(pCir->PIOReg, ((pitch) & 0x1f00) | 0x25);
}

static void
AlpSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
{
	CirPtr pCir = CIRPTR(pScrn);
	int dest;
	int hh, ww;
	int pitch = pCir->pitch;

	ww = (w * pScrn->bitsPerPixel / 8) - 1;
	hh = h - 1;
	dest = y * pitch + x * pScrn->bitsPerPixel / 8;

	WAIT;

	/* Width */
	outw(pCir->PIOReg, ((ww << 8) & 0xff00) | 0x20);
	outw(pCir->PIOReg, ((ww) & 0x1f00) | 0x21);
	/* Height */
	outw(pCir->PIOReg, ((hh << 8) & 0xff00) | 0x22);
	outw(pCir->PIOReg, ((hh) & 0x0700) | 0x23);

	/* dest */
	outw(pCir->PIOReg, ((dest << 8) & 0xff00) | 0x28);
	outw(pCir->PIOReg, ((dest) & 0xff00) | 0x29);
	outw(pCir->PIOReg, ((dest >> 8) & 0x3f00) | 0x2A);
	if (!pCir->chip.alp->autoStart)
	  outw(pCir->PIOReg, 0x0231);

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequentSolidFillRect x=%d y=%d w=%d h=%d\n",
			x, y, w, h);
#endif

}

static void
AlpSetupForMono8x8PatternFill(ScrnInfoPtr pScrn,
			      int patx, int paty,
			      int fg, int bg,
			      int rop, unsigned int planemask)
{
	CirPtr pCir = CIRPTR(pScrn);
	AlpPtr pAlp = ALPPTR(pCir);
	int pitch = pCir->pitch;

#ifdef ALP_DEBUG
	ErrorF("AlpSetupFor8x8PatternFill pattern=%8x%8x"
	       "fg=%x bg=%x rop=%x planemask=%x\n",
			patx, paty, fg, bg, rop, planemask);
#endif
	WAIT;

	SetupForRop(rop);

	{
	  int source = pAlp->monoPattern8x8;
	  /* source = 8x8 solid mono pattern */
	  outw(pCir->PIOReg, ((source << 8) & 0xff00) | 0x2C);
	  outw(pCir->PIOReg, ((source) & 0xff00) | 0x2D);
	  outw(pCir->PIOReg, ((source >> 8) & 0x3f00) | 0x2E);
	}

        /* GR30 = color expansion, pattern copy */
	/* Choses 8bpp / 16bpp color expansion */
	if (bg == -1)
	{ /* transparency requested */
	  outw(pCir->PIOReg, 0xC830 |((pScrn->bitsPerPixel - 8) << 9));

	  bg = ~fg;
	  /* transparent color compare */
	  outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x34);
	  outw(pCir->PIOReg, ((bg) & 0xff00) | 0x35);

	  /* transparent color mask = 0 (all bits matters) */
	  outw(pCir->PIOReg, 0x38);
	  outw(pCir->PIOReg, 0x39);
	}
	else
	{
	  outw(pCir->PIOReg, 0xC030 |((pScrn->bitsPerPixel - 8) << 9));
	}

	outw(pCir->PIOReg, ((fg << 8) & 0xff00) | 0x01);
	outw(pCir->PIOReg, ((fg) & 0xff00) | 0x11);

	outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x00);
	outw(pCir->PIOReg, ((bg) & 0xff00) | 0x10);

	/* Set dest pitch */
	outw(pCir->PIOReg, ((pitch << 8) & 0xff00) | 0x24);
	outw(pCir->PIOReg, ((pitch) & 0x1f00) | 0x25);
}

static void
AlpSubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn, int patx, int paty,
			   int x, int y, int w, int h)
{
	CirPtr pCir = CIRPTR(pScrn);
	AlpPtr pAlp = ALPPTR(pCir);
	int dest;
	int hh, ww;
	int pitch = pCir->pitch;

	ww = (w * pScrn->bitsPerPixel / 8) - 1;
	hh = h - 1;
	dest = y * pitch + x * pScrn->bitsPerPixel / 8;

	WAIT;
	/* memcpy() may not be the fastest */
	memcpy(pCir->FbBase + pAlp->monoPattern8x8, &patx, 4);
	memcpy(pCir->FbBase + pAlp->monoPattern8x8 + 4, &paty, 4);
	write_mem_barrier();

	/* Width */
	outw(pCir->PIOReg, ((ww << 8) & 0xff00) | 0x20);
	outw(pCir->PIOReg, ((ww) & 0x1f00) | 0x21);
	/* Height */
	outw(pCir->PIOReg, ((hh << 8) & 0xff00) | 0x22);
	outw(pCir->PIOReg, ((hh) & 0x0700) | 0x23);

	/* dest */
	outw(pCir->PIOReg, ((dest << 8) & 0xff00) | 0x28);
	outw(pCir->PIOReg, ((dest) & 0xff00) | 0x29);
	outw(pCir->PIOReg, ((dest >> 8) & 0x3f00) | 0x2A);
	if (!pCir->chip.alp->autoStart)
	  outw(pCir->PIOReg, 0x0231);

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequent8x8PatternFill x=%d y=%d w=%d h=%d\n",
			x, y, w, h);
#endif

}

#if 0
/* XF86 does not support byte-padded scanlines */

static void
AlpSetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
                        int fg, int bg,
                        int rop,
                        unsigned int planemask)
{
	CirPtr pCir = CIRPTR(pScrn);
	AlpPtr pAlp = ALPPTR(pCir);
	int pitch = pCir->pitch;

#ifdef ALP_DEBUG
	ErrorF("AlpSetupForCPUToScreenColorExpandFill "
	       "fg=%x bg=%x rop=%x planemask=%x\n",
			fg, bg, rop, planemask);
#endif
	WAIT;

	SetupForRop(rop);

        /* GR30 = color expansion, CPU->display copy */
	/* Choses 8bpp / 16bpp color expansion */
	if (bg == -1)
	{ /* transparency requested */
	  outw(pCir->PIOReg, 0x8C30 |((pScrn->bitsPerPixel - 8) << 9));

	  bg = ~fg;
	  /* transparent color compare */
	  outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x34);
	  outw(pCir->PIOReg, ((bg) & 0xff00) | 0x35);

	  /* transparent color mask = 0 (all bits matters) */
	  outw(pCir->PIOReg, 0x38);
	  outw(pCir->PIOReg, 0x39);
	}
	else
	{
	  outw(pCir->PIOReg, 0x8430 |((pScrn->bitsPerPixel - 8) << 9));
	}

	outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x00);
	outw(pCir->PIOReg, ((bg) & 0xff00) | 0x10);

	outw(pCir->PIOReg, ((fg << 8) & 0xff00) | 0x01);
	outw(pCir->PIOReg, ((fg) & 0xff00) | 0x11);

	/* Set dest pitch */
	outw(pCir->PIOReg, ((pitch << 8) & 0xff00) | 0x24);
	outw(pCir->PIOReg, ((pitch) & 0x1f00) | 0x25);  
}

static void
AlpSubsequentCPUToScreenColorExpandFill(
	ScrnInfoPtr pScrn,
	int x, int y, int w, int h,
	int skipleft)
{
	CirPtr pCir = CIRPTR(pScrn);
	int dest;
	int hh, ww;
	int pitch = pCir->pitch;

	ww = (((w+7) & ~7) * pScrn->bitsPerPixel / 8) - 1;
	hh = h - 1;
	dest = y * pitch + x * pScrn->bitsPerPixel / 8;

	WAIT;

	/* Width */
	outw(pCir->PIOReg, ((ww << 8) & 0xff00) | 0x20);
	outw(pCir->PIOReg, ((ww) & 0x1f00) | 0x21);
	/* Height */
	outw(pCir->PIOReg, ((hh << 8) & 0xff00) | 0x22);
	outw(pCir->PIOReg, ((hh) & 0x0700) | 0x23);

	/* source = CPU ; description of bit 2 of GR30 in the 7548 manual
	   says that if we do color expansion we must zero the source
	   adress registers (GR2C, GR2D, GR2E) */
	outw(pCir->PIOReg, 0x2C);
	outw(pCir->PIOReg, 0x2D);
	outw(pCir->PIOReg, 0x2E);

	/* dest */
	outw(pCir->PIOReg, ((dest << 8) & 0xff00) | 0x28);
	outw(pCir->PIOReg, ((dest) & 0xff00) | 0x29);
	outw(pCir->PIOReg, ((dest >> 8) & 0x3f00) | 0x2A);
	if (!pCir->chip.alp->autoStart)
	  outw(pCir->PIOReg, 0x0231);

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequentCPUToScreenColorExpandFill x=%d y=%d w=%d h=%d\n",
			x, y, w, h);
#endif
}
#endif

#if 1
static void
AlpSetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
                        int fg, int bg,
                        int rop,
                        unsigned int planemask)
{
	CirPtr pCir = CIRPTR(pScrn);
	int pitch = pCir->pitch;

#ifdef ALP_DEBUG
	ErrorF("AlpSetupForCPUToScreenColorExpandFill "
	       "fg=%x bg=%x rop=%x planemask=%x, bpp=%d\n",
			fg, bg, rop, planemask, pScrn->bitsPerPixel);
#endif
	WAIT;

	SetupForRop(rop);

        /* GR30 = color expansion, CPU->display copy */
	/* Choses 8bpp / 16bpp color expansion */
	if (bg == -1)
	{ /* transparency requested */
	  if (pScrn->bitsPerPixel > 8) /* 16 bpp */
	  {
	    outw(pCir->PIOReg, 0x9C30);

	    bg = ~fg;
	    /* transparent color compare */
	    outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x34);
	    outw(pCir->PIOReg, ((bg) & 0xff00) | 0x35);
	  } else /* 8 bpp */
	  {
	    outw(pCir->PIOReg, 0x8C30);

	    bg = ~fg;
	    /* transparent color compare */
	    outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x34);
	    outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x35);
	  }

	  /* transparent color mask = 0 (all bits matters) */
	  outw(pCir->PIOReg, 0x38);
	  outw(pCir->PIOReg, 0x39);
	}
	else
	{
	  outw(pCir->PIOReg, 0x8430 |((pScrn->bitsPerPixel - 8) << 9));
	}

	outw(pCir->PIOReg, ((bg << 8) & 0xff00) | 0x00);
	outw(pCir->PIOReg, ((bg) & 0xff00) | 0x10);

	outw(pCir->PIOReg, ((fg << 8) & 0xff00) | 0x01);
	outw(pCir->PIOReg, ((fg) & 0xff00) | 0x11);

	/* Set dest pitch */
	outw(pCir->PIOReg, ((pitch << 8) & 0xff00) | 0x24);
	outw(pCir->PIOReg, ((pitch) & 0x1f00) | 0x25);  
}

static void
AlpSubsequentScanlineCPUToScreenColorExpandFill(
	ScrnInfoPtr pScrn,
	int x, int y, int w, int h,
	int skipleft)
{
	CirPtr pCir = CIRPTR(pScrn);
	AlpPtr pAlp = ALPPTR(pCir);

	int pitch = pCir->pitch;

	pAlp->SubsequentColorExpandScanlineByteWidth =
	  (w * pScrn->bitsPerPixel / 8) - 1;
	pAlp->SubsequentColorExpandScanlineDWordWidth =
	  (w + 31) >> 5;
	pAlp->SubsequentColorExpandScanlineDest =
	  y * pitch + x * pScrn->bitsPerPixel / 8;

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequentScanlineCPUToScreenColorExpandFill x=%d y=%d w=%d h=%d skipleft=%d\n",
			x, y, w, h, skipleft);
#endif
}

static void 
AlpSubsequentColorExpandScanline(
	ScrnInfoPtr pScrn,
	int bufno)
{
        CirPtr pCir = CIRPTR(pScrn);
	AlpPtr pAlp = ALPPTR(pCir);
	int dest=pAlp->SubsequentColorExpandScanlineDest;
	int ww=pAlp->SubsequentColorExpandScanlineByteWidth;
	int width=pAlp->SubsequentColorExpandScanlineDWordWidth;
	CARD32* from;
	volatile CARD32 *to;

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequentColorExpandScanline\n");
#endif

	pAlp->SubsequentColorExpandScanlineDest += pCir->pitch;

	to   = (CARD32*) pCir->FbBase;
	from = (CARD32*) (pCir->ScanlineColorExpandBuffers[bufno]);
	WAIT_1;

	/* Width */
	outw(pCir->PIOReg, ((ww << 8) & 0xff00) | 0x20);
	outw(pCir->PIOReg, ((ww) & 0x1f00) | 0x21);

	/* Height = 1 */
	outw(pCir->PIOReg, 0x22);
	outw(pCir->PIOReg, 0x23);

	/* source = CPU ; description of bit 2 of GR30 in the 7548 manual
	   says that if we do color expansion we must zero the source
	   adress registers (GR2C, GR2D, GR2E) */
	outw(pCir->PIOReg, 0x2C);
	outw(pCir->PIOReg, 0x2D);
	outw(pCir->PIOReg, 0x2E);

	/* dest */
	outw(pCir->PIOReg, ((dest << 8) & 0xff00) | 0x28);
	outw(pCir->PIOReg, ((dest) & 0xff00) | 0x29);
	write_mem_barrier();

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequentColorExpandScanline (2)\n");
#endif

	outw(pCir->PIOReg, ((dest >> 8) & 0x3f00) | 0x2A);
	if (!pCir->chip.alp->autoStart)
	  outw(pCir->PIOReg, 0x0231);

	{
	  int i;
	  for (i=0; i<width; i++)
	    *to=*(from++);
	  write_mem_barrier();
	}

#ifdef ALP_DEBUG
	ErrorF("AlpSubsequentColorExpandScanline (3)\n");
#endif
}
#endif

static void
AlpAccelEngineInit(ScrnInfoPtr pScrn)
{
    CirPtr pCir = CIRPTR(pScrn);

    outw(pCir->PIOReg, 0x200E); /* enable writes to gr33 */
    /* Setup things for autostart */
    if (pCir->properties & ACCEL_AUTOSTART) {
        outw(pCir->PIOReg, 0x8031); /* enable autostart */
	pCir->chip.alp->waitMsk = 0x10;
	pCir->chip.alp->autoStart = TRUE;
    } else {
        pCir->chip.alp->waitMsk = 0x1;
	pCir->chip.alp->autoStart = FALSE;
    }
}

Bool
AlpXAAInit(ScreenPtr pScreen)
{
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    CirPtr pCir = CIRPTR(pScrn);
    AlpPtr pAlp = ALPPTR(pCir);
    XAAInfoRecPtr XAAPtr;

    pCir->InitAccel =  AlpAccelEngineInit;
#ifdef ALP_DEBUG
    ErrorF("AlpXAAInit\n");
#endif

    XAAPtr = XAACreateInfoRec();
    if (!XAAPtr) return FALSE;

    /* Pixmap cache */
    XAAPtr->Flags |= LINEAR_FRAMEBUFFER;
    XAAPtr->Sync = AlpSync;
    
    XAAPtr->SetupForScreenToScreenCopy = AlpSetupForScreenToScreenCopy;
    XAAPtr->SubsequentScreenToScreenCopy = AlpSubsequentScreenToScreenCopy;
    XAAPtr->ScreenToScreenCopyFlags =
        NO_TRANSPARENCY | NO_PLANEMASK;

    XAAPtr->SetupForSolidFill = AlpSetupForSolidFill;
    XAAPtr->SubsequentSolidFillRect = AlpSubsequentSolidFillRect;
    XAAPtr->SubsequentSolidFillTrap = NULL;
    XAAPtr->SolidFillFlags = NO_PLANEMASK;

    if (pCir->Chipset == PCI_CHIP_GD7548) {
        if (pAlp->monoPattern8x8) {
	    XAAPtr->SetupForMono8x8PatternFill 
	        = AlpSetupForMono8x8PatternFill;
	    XAAPtr->SubsequentMono8x8PatternFillRect 
	        = AlpSubsequentMono8x8PatternFillRect;
	    XAAPtr->SubsequentMono8x8PatternFillTrap = NULL;
	    XAAPtr->Mono8x8PatternFillFlags =
	        NO_PLANEMASK |
		HARDWARE_PATTERN_PROGRAMMED_BITS | BIT_ORDER_IN_BYTE_MSBFIRST;
	}
#if 1
	/* kludge: since XF86 does not support byte-padded
	   mono bitmaps (only dword-padded), use the
	   scanline version */
	XAAPtr->SetupForScanlineCPUToScreenColorExpandFill =
	    AlpSetupForScanlineCPUToScreenColorExpandFill;
	XAAPtr->SubsequentScanlineCPUToScreenColorExpandFill =
	    AlpSubsequentScanlineCPUToScreenColorExpandFill;
	XAAPtr->SubsequentColorExpandScanline =
	    AlpSubsequentColorExpandScanline;
	{
	  const int NumScanlineColorExpandBuffers = 2;
	  int i;
	  int buffer_size = (pCir->pScrn->virtualX + 31) & ~31;
#ifdef ALP_DEBUG
	  ErrorF("Computing buffers for %d pixel lines\n",
		 pCir->pScrn->virtualX);
#endif
	  XAAPtr->NumScanlineColorExpandBuffers =
	      NumScanlineColorExpandBuffers;
	  XAAPtr->ScanlineColorExpandBuffers =
	      pCir->ScanlineColorExpandBuffers = (unsigned char **)
	      (malloc(sizeof(unsigned char *) *
		      NumScanlineColorExpandBuffers));
	    /* TODO: are those mallocs to be freed ? */

	  for(i=0; i<NumScanlineColorExpandBuffers; i++)
	      pCir->ScanlineColorExpandBuffers[i] = (unsigned char *)
		malloc(buffer_size);
	}
	XAAPtr->ScanlineCPUToScreenColorExpandFillFlags =
	    NO_PLANEMASK | BIT_ORDER_IN_BYTE_MSBFIRST |
	    SCANLINE_PAD_DWORD | ROP_NEEDS_SOURCE;
#endif
#if 0
	/* Currently disabled: XF86 sends DWORD-padded data,
	   not byte-padded */
	XAAPtr->SetupForCPUToScreenColorExpandFill =
	  AlpSetupForCPUToScreenColorExpandFill;
	XAAPtr->SubsequentCPUToScreenColorExpandFill =
	  AlpSubsequentCPUToScreenColorExpandFill;
	XAAPtr->ColorExpandBase = pCir->FbBase + 4;
	XAAPtr->CPUToScreenColorExpandFillFlags =
	  NO_PLANEMASK | BIT_ORDER_IN_BYTE_MSBFIRST |
	  SCANLINE_PAD_DWORD | ROP_NEEDS_SOURCE |
	  CPU_TRANSFER_PAD_DWORD | CPU_TRANSFER_BASE_FIXED;
#endif
    }

    AlpAccelEngineInit(pScrn);

    pCir->AccelInfoRec = XAAPtr;

    if (!XAAInit(pScreen, XAAPtr))
        return FALSE;

    return TRUE;
}