Magellan Linux

Annotation of /trunk/xorg-old/patches-6.8.2-r10/5200_all_6.8.0-newport-accel-v4.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 167 - (hide annotations) (download)
Tue May 8 20:58:51 2007 UTC (17 years, 1 month ago) by niro
File size: 66330 byte(s)
-import

1 niro 167 diff -Nur xc.orig/programs/Xserver/hw/xfree86/drivers/newport/Imakefile xc/programs/Xserver/hw/xfree86/drivers/newport/Imakefile
2     --- xc.orig/programs/Xserver/hw/xfree86/drivers/newport/Imakefile 2004-11-11 08:52:59.559743184 -0500
3     +++ xc/programs/Xserver/hw/xfree86/drivers/newport/Imakefile 2004-11-11 08:52:32.848803864 -0500
4     @@ -3,9 +3,9 @@
5     #define IHaveModules
6     #include <Server.tmpl>
7    
8     -SRCS = newport_driver.c newport_regs.c newport_cmap.c newport_shadow.c newport_cursor.c
9     +SRCS = newport_driver.c newport_regs.c newport_cmap.c newport_shadow.c newport_cursor.c newport_accel.c
10    
11     -OBJS = newport_driver.o newport_regs.o newport_cmap.o newport_shadow.o newport_cursor.o
12     +OBJS = newport_driver.o newport_regs.o newport_cmap.o newport_shadow.o newport_cursor.o newport_accel.o
13    
14     XF86CONFIG = XF86Config.indy
15    
16     @@ -46,6 +46,7 @@
17     InstallDriverSDKNonExecFile(newport_cmap.c,$(DRIVERSDKDIR)/drivers/newport)
18     InstallDriverSDKNonExecFile(newport_shadow.c,$(DRIVERSDKDIR)/drivers/newport)
19     InstallDriverSDKNonExecFile(newport_cursor.c,$(DRIVERSDKDIR)/drivers/newport)
20     +InstallDriverSDKNonExecFile(newport_accel.c,$(DRIVERSDKDIR)/drivers/newport)
21     InstallDriverSDKNonExecFile(newport_regs.h,$(DRIVERSDKDIR)/drivers/newport)
22     InstallDriverSDKNonExecFile(newport.h,$(DRIVERSDKDIR)/drivers/newport)
23    
24     diff -Nur xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport.h xc/programs/Xserver/hw/xfree86/drivers/newport/newport.h
25     --- xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport.h 2004-11-11 08:52:59.561742880 -0500
26     +++ xc/programs/Xserver/hw/xfree86/drivers/newport/newport.h 2004-11-11 08:52:32.849803712 -0500
27     @@ -6,6 +6,17 @@
28     #ifndef __NEWPORT_H__
29     #define __NEWPORT_H__
30    
31     +/* use 32bpp shadow framebuffer surface instead of 24bpp */
32     +#define NEWPORT_USE32BPP
33     +/* enable accel patch */
34     +#define NEWPORT_ACCEL
35     +
36     +#ifdef NEWPORT_ACCEL
37     +#ifndef NEWPORT_USE32BPP
38     +#define NEWPORT_USE32BPP
39     +#endif
40     +#endif
41     +
42     /*
43     * All drivers should include these:
44     */
45     @@ -19,6 +30,7 @@
46    
47     /* xaa & hardware cursor */
48     #include "xaa.h"
49     +#include "xaalocal.h"
50     #include "xf86Cursor.h"
51    
52     /* register definitions of the Newport card */
53     @@ -45,6 +57,7 @@
54     typedef struct {
55     unsigned busID;
56     int bitplanes;
57     + Bool NoAccel;
58     /* revision numbers of the various pieces of silicon */
59     unsigned int board_rev, cmap_rev, rex3_rev, xmap9_rev, bt445_rev;
60     /* shadow copies of frequently used registers */
61     @@ -88,6 +101,43 @@
62    
63     LOCO txt_colormap[256];
64    
65     + /* XAA stuff */
66     + XAAInfoRecPtr pXAAInfoRec;
67     + /* writing to these regs causes pipeline stall
68     + so be smart and check the shadow before writing it */
69     + unsigned int shadow_drawmode1;
70     + unsigned int shadow_colorvram;
71     + unsigned int shadow_colorback;
72     + unsigned int shadow_xymove;
73     + unsigned int shadow_wrmask;
74     + unsigned int shadow_clipmode;
75     + unsigned int fifoleft; /* number of slots left in fifo */
76     +
77     + unsigned int shadow_drawmode0;
78     + unsigned int shadow_colori;
79     + unsigned int shadow_smask0x;
80     + unsigned int shadow_smask0y;
81     +
82     + unsigned int setup_drawmode0;
83     + unsigned int setup_drawmode1;
84     + unsigned char dashline_pat[2048/8];
85     + unsigned int dashline_patlen;
86     +
87     + int clipsx, clipex, clipsy, clipey;
88     + int skipleft;
89     +
90     + unsigned int pat8x8[8][8];
91     +
92     + unsigned int (*Color2Planes)(unsigned int color);
93     +
94     +#ifdef RENDER
95     + unsigned int uTextureWidth;
96     + unsigned int uTextureHeight;
97     + unsigned int uTextureSize;
98     + unsigned int *pTexture;
99     + unsigned int uTextureFlags;
100     +#endif
101     +
102     OptionInfoPtr Options;
103     } NewportRec, *NewportPtr;
104    
105     diff -Nur xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_accel.c xc/programs/Xserver/hw/xfree86/drivers/newport/newport_accel.c
106     --- xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_accel.c 1969-12-31 19:00:00.000000000 -0500
107     +++ xc/programs/Xserver/hw/xfree86/drivers/newport/newport_accel.c 2004-11-11 08:52:32.849803712 -0500
108     @@ -0,0 +1,1842 @@
109     +/*
110     + * Accelerated Driver for the SGI Indy's Newport graphics card
111     + *
112     + * (c) 2004 Dominik Behr <dominikbehr@yahoo.com>
113     + * this code is released under xfree 4.3.0 and xorg 6.8.0 license
114     + *
115     + */
116     +
117     +#include "newport.h"
118     +
119     +#ifdef NEWPORT_ACCEL
120     +
121     +#include "mi.h"
122     +#include "mizerarc.h"
123     +
124     +#define BARF(a) xf86DrvMsg(0, X_INFO, (a))
125     +#define BARF1(a,b) xf86DrvMsg(0, X_INFO, (a), (b))
126     +#define BARF2(a,b,c) xf86DrvMsg(0, X_INFO, (a), (b), (c))
127     +#define BARF3(a,b,c,d) xf86DrvMsg(0, X_INFO, (a), (b), (c), (d))
128     +#define BARF4(a,b,c,d,e) xf86DrvMsg(0, X_INFO, (a), (b), (c), (d), (e))
129     +#define BARF5(a,b,c,d,e,f) xf86DrvMsg(0, X_INFO, (a), (b), (c), (d), (e), (f))
130     +#define BARF6(a,b,c,d,e,f,g) xf86DrvMsg(0, X_INFO, (a), (b), (c), (d), (e), (f), (g))
131     +
132     +/* XAA Functions */
133     +
134     +#define NEWPORT_PREROTATE
135     +/*
136     + there is a bug in XAA which causes it to reference NULL pointer to pattern cache when
137     + using HARDWARE_PROGRAMMED_PATTERN only (try x11perf -strap1)
138     + thus we have to also set HARDWARE_PROGRAMMED_ORIGIN and prerotate the pattern
139     + in the setup function
140     +*/
141     +
142     +#define NEWPORT_GFIFO_ENTRIES 30
143     +/*
144     + I dont know how many entries are in the gfx FIFO, judging by 6 bits in the GFIFO
145     + level status register it can be at most 63. it must be at least 32 because
146     + otherwise they would use less bits for status
147     +
148     + for now 16 seems to be safe value
149     +*/
150     +#define NEWPORT_DELAY 128
151     +
152     +/*******************************************************************************
153     +
154     +*******************************************************************************/
155     +static void
156     +NewportWaitIdle(NewportPtr pNewport, unsigned int uEntries)
157     +{
158     + NewportRegsPtr pNewportRegs;
159     + pNewportRegs = pNewport->pNewportRegs;
160     + /* wait for the GFIFO to drain */
161     + while ((pNewportRegs->cset.stat & NPORT_STAT_GLMSK))
162     + {
163     + int i;
164     + volatile int x;
165     + for (x = 0, i = 0; i < NEWPORT_DELAY; i++)
166     + {
167     + x += i;
168     + }
169     + }
170     + /* and then wait for the graphic to be idle */
171     + while (pNewportRegs->cset.stat & NPORT_STAT_GBUSY)
172     + {
173     + int i;
174     + volatile int x;
175     + for (x = 0, i = 0; i < NEWPORT_DELAY; i++)
176     + {
177     + x += i;
178     + }
179     + }
180     + pNewport->fifoleft = NEWPORT_GFIFO_ENTRIES-uEntries;
181     +}
182     +
183     +
184     +#if 0
185     +/*******************************************************************************
186     +
187     +*******************************************************************************/
188     +static void
189     +NewportWaitGFIFO(NewportPtr pNewport, unsigned int uEntries)
190     +{
191     + unsigned int uWaitLevel;
192     +
193     +/* NewportWaitIdle(pNewport, NEWPORT_GFIFO_ENTRIES);
194     + return;*/
195     +
196     + if (uEntries >= NEWPORT_GFIFO_ENTRIES)
197     + {
198     + uWaitLevel = 0;
199     + }
200     + else
201     + {
202     + uWaitLevel = NEWPORT_GFIFO_ENTRIES-uEntries;
203     + }
204     + /* HACK */
205     + /*uWaitLevel = 0;*/
206     + while (((pNewport->pNewportRegs->cset.stat & NPORT_STAT_GLMSK) >> 7) > uWaitLevel)
207     + {
208     + int i;
209     + volatile int x;
210     + for (x = 0, i = 0; i < NEWPORT_DELAY; i++)
211     + {
212     + x += i;
213     + }
214     + }
215     +}
216     +#endif
217     +#if 1
218     +/*******************************************************************************
219     +
220     +*******************************************************************************/
221     +static void
222     +NewportWaitGFIFO(NewportPtr pNewport, unsigned int uEntries)
223     +{
224     + if (uEntries > NEWPORT_GFIFO_ENTRIES)
225     + {
226     + uEntries = NEWPORT_GFIFO_ENTRIES;
227     + }
228     +
229     + if (uEntries <= pNewport->fifoleft)
230     + {
231     + pNewport->fifoleft -= uEntries;
232     + return;
233     + }
234     +
235     + while (1)
236     + {
237     + unsigned int fifolevel;
238     + int i;
239     + volatile int x;
240     +
241     + fifolevel = (pNewport->pNewportRegs->cset.stat & NPORT_STAT_GLMSK) >> 7;
242     + if (fifolevel < NEWPORT_GFIFO_ENTRIES)
243     + {
244     + pNewport->fifoleft = NEWPORT_GFIFO_ENTRIES - fifolevel;
245     + }
246     + else
247     + {
248     + pNewport->fifoleft = 0;
249     + }
250     + if (uEntries <= pNewport->fifoleft)
251     + {
252     + pNewport->fifoleft -= uEntries;
253     + return;
254     + }
255     +
256     + for (x = 0, i = 0; i < NEWPORT_DELAY; i++)
257     + {
258     + x += i;
259     + }
260     + }
261     +}
262     +#endif
263     +
264     +
265     +/*******************************************************************************
266     +
267     +*******************************************************************************/
268     +static void
269     +NewportXAASync(ScrnInfoPtr pScrn)
270     +{
271     + NewportPtr pNewport;
272     + pNewport = NEWPORTPTR(pScrn);
273     +
274     + NewportWaitIdle(pNewport, 0);
275     +}
276     +
277     +
278     +/*******************************************************************************
279     +
280     +*******************************************************************************/
281     +static unsigned int
282     +Rop2LogicOp(int rop)
283     +{
284     + return (unsigned int)rop << 28;
285     +}
286     +
287     +/*******************************************************************************
288     +
289     +*******************************************************************************/
290     +static void
291     +NewportUpdateClipping(NewportPtr pNewport)
292     +{
293     + unsigned int smask0x, smask0y;
294     +
295     + if (pNewport->skipleft > pNewport->clipsx)
296     + {
297     + smask0x = ((pNewport->skipleft & 0xFFFF) << 16) | (pNewport->clipex & 0xFFFF);
298     + }
299     + else
300     + {
301     + smask0x = ((pNewport->clipsx & 0xFFFF) << 16) | (pNewport->clipex & 0xFFFF);
302     + }
303     +
304     + if (smask0x != pNewport->shadow_smask0x)
305     + {
306     + NewportWaitGFIFO(pNewport, 1);
307     + pNewport->shadow_smask0x = smask0x;
308     + pNewport->pNewportRegs->set.smask0x = smask0x;
309     + }
310     +
311     + smask0y = ((pNewport->clipsy & 0xFFFF) << 16) | (pNewport->clipey & 0xFFFF);
312     + if (smask0y != pNewport->shadow_smask0y)
313     + {
314     + NewportWaitGFIFO(pNewport, 1);
315     + pNewport->shadow_smask0y = smask0y;
316     + pNewport->pNewportRegs->set.smask0y = smask0y;
317     + }
318     +}
319     +
320     +/*******************************************************************************
321     +
322     +*******************************************************************************/
323     +static unsigned int
324     +NewportColor2HOSTRW(unsigned int color)
325     +{
326     + /*
327     + default XAA color is 0,R,G,B
328     + */
329     +#if 0
330     + return ((color & 0x0000FF) << 16)
331     + | ((color & 0xFF0000) >> 16)
332     + | ((color & 0x00FF00))
333     + ;
334     +#endif
335     +/* but we changed masks to match the native format */
336     + return color;
337     +}
338     +
339     +/*******************************************************************************
340     +
341     +*******************************************************************************/
342     +static unsigned int
343     +NewportColor2Planes24(unsigned int color)
344     +{
345     + unsigned int res;
346     + unsigned int i;
347     + unsigned int mr, mg, mb;
348     + unsigned int sr, sg, sb;
349     +
350     + /*
351     + XAA color is 0,R,G,B
352     + */
353     +
354     + res = 0;
355     +#if 0
356     + mr = 0x800000;
357     + mg = 0x008000;
358     + mb = 0x000080;
359     +#endif
360     + mr = 0x000080;
361     + mg = 0x008000;
362     + mb = 0x800000;
363     + sr = 2;
364     + sg = 1;
365     + sb = 4;
366     +
367     + for (i = 0; i < 8; i++)
368     + {
369     + res |= (color & mr)?sr:0;
370     + res |= (color & mg)?sg:0;
371     + res |= (color & mb)?sb:0;
372     +
373     + sr <<= 3;
374     + sg <<= 3;
375     + sb <<= 3;
376     + mr >>= 1;
377     + mg >>= 1;
378     + mb >>= 1;
379     + }
380     +
381     + return res;
382     +}
383     +
384     +/*******************************************************************************
385     +
386     +*******************************************************************************/
387     +static unsigned int
388     +NewportColor2Planes8(unsigned int color)
389     +{
390     + return color;
391     +}
392     +
393     +/*******************************************************************************
394     +
395     +*******************************************************************************/
396     +static void
397     +NewportUpdateCOLORI(NewportPtr pNewport, unsigned long colori)
398     +{
399     + if (colori != pNewport->shadow_colori)
400     + {
401     + NewportWaitGFIFO(pNewport, 1);
402     + pNewport->shadow_colori = colori;
403     + pNewport->pNewportRegs->set.colori = colori;
404     + }
405     +}
406     +
407     +
408     +/*******************************************************************************
409     +
410     +*******************************************************************************/
411     +static void
412     +NewportUpdateDRAWMODE0(NewportPtr pNewport, unsigned long drawmode0)
413     +{
414     + if (drawmode0 != pNewport->shadow_drawmode0)
415     + {
416     + NewportWaitGFIFO(pNewport, 1);
417     + pNewport->shadow_drawmode0 = drawmode0;
418     + pNewport->pNewportRegs->set.drawmode0 = drawmode0;
419     + }
420     +}
421     +
422     +
423     +/*******************************************************************************
424     +
425     +*******************************************************************************/
426     +static void
427     +NewportUpdateDRAWMODE1(NewportPtr pNewport, unsigned long drawmode1)
428     +{
429     + if (drawmode1 != pNewport->shadow_drawmode1)
430     + {
431     + NewportWaitIdle(pNewport, 1);
432     + pNewport->shadow_drawmode1 = drawmode1;
433     + pNewport->pNewportRegs->set.drawmode1 = drawmode1;
434     + }
435     +}
436     +
437     +/*******************************************************************************
438     +
439     +*******************************************************************************/
440     +static void
441     +NewportUpdateCOLORVRAM(NewportPtr pNewport, unsigned long colorvram)
442     +{
443     + if (colorvram != pNewport->shadow_colorvram)
444     + {
445     + NewportWaitIdle(pNewport, 1);
446     + pNewport->shadow_colorvram = colorvram;
447     + pNewport->pNewportRegs->set.colorvram = colorvram;
448     + }
449     +}
450     +
451     +/*******************************************************************************
452     +
453     +*******************************************************************************/
454     +static void
455     +NewportUpdateCOLORBACK(NewportPtr pNewport, unsigned long colorback)
456     +{
457     + if (colorback != pNewport->shadow_colorback)
458     + {
459     + NewportWaitIdle(pNewport, 1);
460     + pNewport->shadow_colorback = colorback;
461     + pNewport->pNewportRegs->set.colorback = colorback;
462     + }
463     +}
464     +
465     +/*******************************************************************************
466     +
467     +*******************************************************************************/
468     +static void
469     +NewportUpdateWRMASK(NewportPtr pNewport, unsigned long wrmask)
470     +{
471     + if (wrmask != pNewport->shadow_wrmask)
472     + {
473     + NewportWaitIdle(pNewport, 1);
474     + pNewport->shadow_wrmask = wrmask;
475     + pNewport->pNewportRegs->set.wrmask = wrmask;
476     + }
477     +}
478     +
479     +/*******************************************************************************
480     +
481     +*******************************************************************************/
482     +static void
483     +NewportUpdateXYMOVE(NewportPtr pNewport, unsigned long xymove)
484     +{
485     + if (xymove != pNewport->shadow_xymove)
486     + {
487     + NewportWaitIdle(pNewport, 1);
488     + pNewport->shadow_xymove = xymove;
489     + pNewport->pNewportRegs->set.xymove = xymove;
490     + }
491     +}
492     +
493     +
494     +/*******************************************************************************
495     +
496     +*******************************************************************************/
497     +static void
498     +NewportXAASetupForScreenToScreenCopy(ScrnInfoPtr pScrn,
499     + int xdir,
500     + int ydir,
501     + int rop,
502     + unsigned int planemask,
503     + int trans_color)
504     +{
505     + NewportRegsPtr pNewportRegs;
506     + NewportPtr pNewport;
507     + pNewport = NEWPORTPTR(pScrn);
508     + pNewportRegs = NEWPORTREGSPTR(pScrn);
509     +
510     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
511     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(planemask));
512     + pNewport->skipleft = 0;
513     + NewportUpdateClipping(pNewport);
514     + NewportUpdateDRAWMODE0(pNewport,
515     + 0
516     + | NPORT_DMODE0_S2S
517     + | NPORT_DMODE0_BLOCK
518     + | NPORT_DMODE0_DOSETUP
519     + | NPORT_DMODE0_STOPX
520     + | NPORT_DMODE0_STOPY
521     + );
522     +
523     +
524     +}
525     +
526     +/*******************************************************************************
527     +
528     +*******************************************************************************/
529     +static void
530     +NewportXAASubsequentScreenToScreenCopy(ScrnInfoPtr pScrn,
531     + int x1, int y1,
532     + int x2, int y2,
533     + int width, int height)
534     +{
535     + int dx, dy;
536     + unsigned int sx, sy, ex, ey;
537     + NewportRegsPtr pNewportRegs;
538     + NewportPtr pNewport;
539     + pNewport = NEWPORTPTR(pScrn);
540     + pNewportRegs = NEWPORTREGSPTR(pScrn);
541     +
542     + dx = x2 - x1;
543     + dy = y2 - y1;
544     + if (!dx && !dy)
545     + return;
546     +
547     + if (width)
548     + x2 = x1 + width - 1;
549     + else
550     + x2 = x1;
551     +
552     + if (height)
553     + y2 = y1 + height - 1;
554     + else
555     + y2 = y1;
556     +
557     + if (dx < 0)
558     + {
559     + sx = x1 & 0xFFFF;
560     + ex = x2 & 0xFFFF;
561     + }
562     + else
563     + {
564     + sx = x2 & 0xFFFF;
565     + ex = x1 & 0xFFFF;
566     + }
567     +
568     + if (dy < 0)
569     + {
570     + sy = y1 & 0xFFFF;
571     + ey = y2 & 0xFFFF;
572     + }
573     + else
574     + {
575     + sy = y2 & 0xFFFF;
576     + ey = y1 & 0xFFFF;
577     + }
578     +
579     + dx &= 0xFFFF;
580     + dy &= 0xFFFF;
581     +
582     + NewportUpdateXYMOVE(pNewport, (dx << 16) | dy); /* this is bad because it stalls the pipeline but nothing can be done about it */
583     + NewportWaitGFIFO(pNewport, 2);
584     + pNewportRegs->set.xystarti = (sx << 16) | sy;
585     + pNewportRegs->go.xyendi = (ex << 16) | ey;
586     +}
587     +
588     +/*******************************************************************************
589     +
590     +*******************************************************************************/
591     +static void
592     +NewportXAASetupForSolidFill(ScrnInfoPtr pScrn,
593     + int Color,
594     + int rop,
595     + unsigned int planemask)
596     +{
597     + NewportRegsPtr pNewportRegs;
598     + NewportPtr pNewport;
599     + pNewport = NEWPORTPTR(pScrn);
600     + pNewportRegs = NEWPORTREGSPTR(pScrn);
601     +
602     + if (rop == GXcopy
603     + || rop == GXclear
604     + || rop == GXset)
605     + {
606     + /* if possible try to set up a fast clear which is 4x faster */
607     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | NPORT_DMODE1_FCLR | Rop2LogicOp(GXcopy));
608     + if (rop == GXclear)
609     + NewportUpdateCOLORVRAM(pNewport, 0);
610     + else
611     + if (rop == GXset)
612     + NewportUpdateCOLORVRAM(pNewport, 0xFFFFFF);
613     + else
614     + NewportUpdateCOLORVRAM(pNewport, pNewport->Color2Planes((unsigned int)Color));
615     + }
616     + else
617     + {
618     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
619     + NewportUpdateCOLORI(pNewport, NewportColor2HOSTRW(Color));
620     + }
621     +
622     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(planemask));
623     + pNewport->skipleft = 0;
624     + NewportUpdateClipping(pNewport);
625     + NewportUpdateDRAWMODE0(pNewport,
626     + 0
627     + | NPORT_DMODE0_DRAW
628     + | NPORT_DMODE0_BLOCK
629     + | NPORT_DMODE0_DOSETUP
630     + | NPORT_DMODE0_STOPX
631     + | NPORT_DMODE0_STOPY
632     + );
633     +}
634     +
635     +/*******************************************************************************
636     +
637     +*******************************************************************************/
638     +static void
639     +NewportXAASubsequentSolidFillRect(ScrnInfoPtr pScrn,
640     + int x,
641     + int y,
642     + int w,
643     + int h)
644     +{
645     + int ex, ey;
646     + NewportRegsPtr pNewportRegs;
647     + NewportPtr pNewport;
648     + pNewport = NEWPORTPTR(pScrn);
649     + pNewportRegs = NEWPORTREGSPTR(pScrn);
650     +
651     + if (w == 0) w = 1;
652     + if (h == 0) h = 1;
653     + ex = x + w - 1;
654     + ey = y + h - 1;
655     +
656     + NewportWaitGFIFO(pNewport, 2);
657     + pNewportRegs->set.xystarti = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
658     + pNewportRegs->go.xyendi = ((ex & 0xFFFF) << 16) | (ey & 0xFFFF);
659     +}
660     +
661     +/*******************************************************************************
662     +
663     +*******************************************************************************/
664     +static void
665     +NewportXAASetupForSolidLine(ScrnInfoPtr pScrn,
666     + int Color,
667     + int rop,
668     + unsigned int planemask)
669     +{
670     + NewportRegsPtr pNewportRegs;
671     + NewportPtr pNewport;
672     + pNewport = NEWPORTPTR(pScrn);
673     + pNewportRegs = NEWPORTREGSPTR(pScrn);
674     +
675     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
676     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(planemask));
677     + NewportUpdateCOLORI(pNewport, NewportColor2HOSTRW(Color));
678     +
679     + pNewport->skipleft = 0;
680     + NewportUpdateClipping(pNewport);
681     + pNewport->setup_drawmode0 = (0
682     + | NPORT_DMODE0_DRAW
683     + | NPORT_DMODE0_ILINE
684     + | NPORT_DMODE0_DOSETUP
685     + | NPORT_DMODE0_STOPX
686     + | NPORT_DMODE0_STOPY
687     + );
688     +}
689     +
690     +/*******************************************************************************
691     +
692     +*******************************************************************************/
693     +static void
694     +NewportXAASubsequentSolidTwoPointLine(ScrnInfoPtr pScrn,
695     + int x1,
696     + int y1,
697     + int x2,
698     + int y2,
699     + int flags)
700     +{
701     + NewportRegsPtr pNewportRegs;
702     + NewportPtr pNewport;
703     + pNewport = NEWPORTPTR(pScrn);
704     + pNewportRegs = NEWPORTREGSPTR(pScrn);
705     +
706     + NewportUpdateDRAWMODE0(pNewport,
707     + pNewport->setup_drawmode0
708     + | ((flags & OMIT_LAST) ? NPORT_DMODE0_SKLST : 0)
709     + );
710     + NewportWaitGFIFO(pNewport, 2);
711     + pNewportRegs->set.xystarti = ((x1 & 0xFFFF) << 16) | (y1 & 0xFFFF);
712     + pNewportRegs->go.xyendi = ((x2 & 0xFFFF) << 16) | (y2 & 0xFFFF);
713     +}
714     +
715     +
716     +/*******************************************************************************
717     +
718     +*******************************************************************************/
719     +static void
720     +NewportXAASetupForDashedLine(ScrnInfoPtr pScrn,
721     + int fg,
722     + int bg,
723     + int rop,
724     + unsigned int planemask,
725     + int length,
726     + unsigned char *pattern)
727     +{
728     + NewportRegsPtr pNewportRegs;
729     + NewportPtr pNewport;
730     + int i;
731     +
732     + pNewport = NEWPORTPTR(pScrn);
733     + pNewportRegs = NEWPORTREGSPTR(pScrn);
734     +
735     + pNewport->dashline_patlen = length;
736     + for (i = 0; i < (length+7)>>3; i++)
737     + pNewport->dashline_pat[i] = pattern[i];
738     +
739     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
740     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(planemask));
741     + if (bg != -1)
742     + NewportUpdateCOLORBACK(pNewport, NewportColor2HOSTRW(bg));
743     + NewportUpdateCOLORI(pNewport, NewportColor2HOSTRW(fg));
744     + pNewport->skipleft = 0;
745     + NewportUpdateClipping(pNewport);
746     + pNewport->setup_drawmode0 = (0
747     + | NPORT_DMODE0_DRAW
748     + | NPORT_DMODE0_ILINE
749     + | NPORT_DMODE0_DOSETUP
750     + | NPORT_DMODE0_STOPX
751     + | NPORT_DMODE0_STOPY
752     + | NPORT_DMODE0_L32
753     + | NPORT_DMODE0_ZPENAB
754     + | ((bg == -1) ? 0 : NPORT_DMODE0_ZOPQ)
755     + );
756     +}
757     +
758     +/*******************************************************************************
759     +
760     +*******************************************************************************/
761     +static void
762     +NewportXAASubsequentDashedTwoPointLine(ScrnInfoPtr pScrn,
763     + int x1,
764     + int y1,
765     + int x2,
766     + int y2,
767     + int flags,
768     + int phase)
769     +{
770     + NewportRegsPtr pNewportRegs;
771     + NewportPtr pNewport;
772     + int dx, dy;
773     + unsigned int linelen;
774     + unsigned int dwords;
775     +
776     + pNewport = NEWPORTPTR(pScrn);
777     + pNewportRegs = NEWPORTREGSPTR(pScrn);
778     +
779     + dx = x2 - x1; if (dx < 0) dx = -dx; dx++;
780     + dy = y2 - y1; if (dy < 0) dy = -dy; dy++;
781     + if (dx > dy)
782     + linelen = dx;
783     + else
784     + linelen = dy;
785     + dwords = (linelen + 31) >> 5;
786     +
787     + NewportUpdateDRAWMODE0(pNewport,
788     + pNewport->setup_drawmode0
789     + | ((flags & OMIT_LAST) ? NPORT_DMODE0_SKLST : 0)
790     + );
791     +
792     + NewportWaitGFIFO(pNewport, 3);
793     + pNewportRegs->set.xystarti = ((x1 & 0xFFFF) << 16) | (y1 & 0xFFFF);
794     + pNewportRegs->set.xyendi = ((x2 & 0xFFFF) << 16) | (y2 & 0xFFFF);
795     + pNewportRegs->set._setup = 1;
796     +
797     + phase %= pNewport->dashline_patlen;
798     + while (dwords--) {
799     + unsigned int bit;
800     + unsigned int pat;
801     + unsigned int mask;
802     + pat = 0;
803     + mask = 0x80000000;
804     + for (bit = 0; bit < 32; bit++)
805     + {
806     + if (pNewport->dashline_pat[phase >> 3] & (0x80 >> (phase & 7)))
807     + pat |= mask;
808     + phase = (phase + 1) % pNewport->dashline_patlen;
809     + mask >>= 1;
810     + }
811     + NewportWaitGFIFO(pNewport, 1);
812     + pNewportRegs->go.zpattern = pat;
813     + }
814     +
815     +}
816     +
817     +/*******************************************************************************
818     +
819     +*******************************************************************************/
820     +static void
821     +NewportXAASetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
822     + int fg,
823     + int bg,
824     + int rop,
825     + unsigned int planemask)
826     +{
827     + NewportRegsPtr pNewportRegs;
828     + NewportPtr pNewport;
829     + pNewport = NEWPORTPTR(pScrn);
830     + pNewportRegs = NEWPORTREGSPTR(pScrn);
831     +
832     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
833     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(planemask));
834     + if (bg != -1)
835     + NewportUpdateCOLORBACK(pNewport, NewportColor2HOSTRW(bg));
836     + NewportUpdateCOLORI(pNewport, NewportColor2HOSTRW(fg));
837     + NewportUpdateDRAWMODE0(pNewport,
838     + 0
839     + | NPORT_DMODE0_DRAW
840     + | NPORT_DMODE0_BLOCK
841     + | NPORT_DMODE0_DOSETUP
842     + | NPORT_DMODE0_STOPX
843     + | NPORT_DMODE0_ZPENAB
844     + | ((bg == -1) ? 0 : NPORT_DMODE0_ZOPQ)
845     + | NPORT_DMODE0_L32
846     + );
847     +}
848     +
849     +/*******************************************************************************
850     +
851     +*******************************************************************************/
852     +static void
853     +NewportXAASubsequentCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
854     + int x,
855     + int y,
856     + int w,
857     + int h,
858     + int skipleft)
859     +{
860     + int ex, ey;
861     + NewportRegsPtr pNewportRegs;
862     + NewportPtr pNewport;
863     + pNewport = NEWPORTPTR(pScrn);
864     + pNewportRegs = NEWPORTREGSPTR(pScrn);
865     +
866     + if (w == 0) w = 1;
867     + if (h == 0) h = 1;
868     + ex = x + w - 1;
869     + ey = y + h - 1;
870     +
871     + if (skipleft)
872     + {
873     + pNewport->skipleft = x + skipleft;
874     + }
875     + else
876     + {
877     + pNewport->skipleft = 0;
878     + }
879     + NewportUpdateClipping(pNewport);
880     +
881     + NewportWaitGFIFO(pNewport, 3);
882     + pNewportRegs->set.xystarti = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
883     + pNewportRegs->set.xyendi = ((ex & 0xFFFF) << 16) | (ey & 0xFFFF);
884     + pNewportRegs->set._setup = 1;
885     +
886     + /* after return XAA will start blasting the pattern to go.zpattern register */
887     + /* we have to wait here for idle because if there is something in the pipeline that will take
888     + long time to complete and if following cpu transfers will overflow the FIFO causing GIO bus
889     + stall it will end up in bus error */
890     + NewportWaitIdle(pNewport, NEWPORT_GFIFO_ENTRIES);
891     +
892     +}
893     +
894     +/*******************************************************************************
895     +
896     +*******************************************************************************/
897     +static void
898     +NewportXAASetupForImageWrite(ScrnInfoPtr pScrn,
899     + int rop,
900     + unsigned int planemask,
901     + int trans_color,
902     + int bpp,
903     + int depth)
904     +{
905     + NewportRegsPtr pNewportRegs;
906     + NewportPtr pNewport;
907     + pNewport = NEWPORTPTR(pScrn);
908     + pNewportRegs = NEWPORTREGSPTR(pScrn);
909     +
910     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
911     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(planemask));
912     + NewportUpdateDRAWMODE0(pNewport,
913     + 0
914     + | NPORT_DMODE0_DRAW
915     + | NPORT_DMODE0_BLOCK
916     + | NPORT_DMODE0_CHOST
917     + | NPORT_DMODE0_DOSETUP
918     + );
919     +
920     +}
921     +
922     +/*******************************************************************************
923     +
924     +*******************************************************************************/
925     +static void
926     +NewportXAASubsequentImageWriteRect(ScrnInfoPtr pScrn,
927     + int x,
928     + int y,
929     + int w,
930     + int h,
931     + int skipleft)
932     +{
933     + int ex, ey;
934     + NewportRegsPtr pNewportRegs;
935     + NewportPtr pNewport;
936     + pNewport = NEWPORTPTR(pScrn);
937     + pNewportRegs = NEWPORTREGSPTR(pScrn);
938     +
939     + if (w == 0) w = 1;
940     + if (h == 0) h = 1;
941     +
942     + ex = x + w - 1;
943     + ey = y + h - 1;
944     +
945     + if (skipleft)
946     + {
947     + pNewport->skipleft = x + skipleft;
948     + }
949     + else
950     + {
951     + pNewport->skipleft = 0;
952     + }
953     + NewportUpdateClipping(pNewport);
954     +
955     + NewportWaitGFIFO(pNewport, 3);
956     + pNewportRegs->set.xystarti = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
957     + pNewportRegs->set.xyendi = ((ex & 0xFFFF) << 16) | (ey & 0xFFFF);
958     + pNewportRegs->set._setup = 1;
959     +
960     + /* after return XAA will start blasting the image to go.hostrw0 register */
961     + /* we have to wait here for idle because if there is something in the pipeline that will take
962     + long time to complete and if following cpu transfers will overflow the FIFO causing GIO bus
963     + stall it will end up in bus error */
964     + NewportWaitIdle(pNewport, NEWPORT_GFIFO_ENTRIES);
965     +}
966     +
967     +static unsigned int
968     +repbyte(unsigned int b)
969     +{
970     + b &= 0xFF;
971     + return b | (b << 8) | (b << 16) | (b << 24);
972     +}
973     +
974     +static void
975     +prerotatebyte(unsigned int b, unsigned int *p)
976     +{
977     + int i;
978     +
979     + b &= 0xFF;
980     +
981     + for (i = 0; i < 8; i++)
982     + {
983     + p[i] = repbyte(b);
984     + if (b & 1)
985     + b = (b >> 1) | 0x80;
986     + else
987     + b = b >> 1;
988     + }
989     +}
990     +
991     +/*******************************************************************************
992     +
993     +*******************************************************************************/
994     +static void
995     +NewportXAASetupForMono8x8PatternFill(ScrnInfoPtr pScrn,
996     + int patx,
997     + int paty,
998     + int fg,
999     + int bg,
1000     + int rop,
1001     + unsigned int planemask)
1002     +{
1003     + NewportRegsPtr pNewportRegs;
1004     + NewportPtr pNewport;
1005     + pNewport = NEWPORTPTR(pScrn);
1006     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1007     +
1008     +#ifdef NEWPORT_PREROTATE
1009     + /* prerotate the pattern */
1010     + prerotatebyte((unsigned int)patx >> 24, pNewport->pat8x8[0]);
1011     + prerotatebyte((unsigned int)patx >> 16, pNewport->pat8x8[1]);
1012     + prerotatebyte((unsigned int)patx >> 8, pNewport->pat8x8[2]);
1013     + prerotatebyte((unsigned int)patx, pNewport->pat8x8[3]);
1014     + prerotatebyte((unsigned int)paty >> 24, pNewport->pat8x8[4]);
1015     + prerotatebyte((unsigned int)paty >> 16, pNewport->pat8x8[5]);
1016     + prerotatebyte((unsigned int)paty >> 8, pNewport->pat8x8[6]);
1017     + prerotatebyte((unsigned int)paty, pNewport->pat8x8[7]);
1018     +#endif
1019     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
1020     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(planemask));
1021     + if (bg != -1)
1022     + NewportUpdateCOLORBACK(pNewport, NewportColor2HOSTRW(bg));
1023     + NewportUpdateCOLORI(pNewport, NewportColor2HOSTRW(fg));
1024     + pNewport->skipleft = 0;
1025     + NewportUpdateClipping(pNewport);
1026     + NewportUpdateDRAWMODE0(pNewport,
1027     + 0
1028     + | NPORT_DMODE0_DRAW
1029     + | NPORT_DMODE0_BLOCK
1030     + | NPORT_DMODE0_DOSETUP
1031     + | NPORT_DMODE0_STOPX
1032     + | NPORT_DMODE0_ZPENAB
1033     + | ((bg == -1) ? 0 : NPORT_DMODE0_ZOPQ)
1034     + | NPORT_DMODE0_L32
1035     + );
1036     +}
1037     +
1038     +
1039     +
1040     +/*******************************************************************************
1041     +
1042     +*******************************************************************************/
1043     +static void
1044     +NewportXAASubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn,
1045     + int patx,
1046     + int paty,
1047     + int x,
1048     + int y,
1049     + int w,
1050     + int h)
1051     +{
1052     + int ex, ey;
1053     + unsigned int d;
1054     +#ifndef NEWPORT_PREROTATE
1055     + unsigned int p;
1056     + unsigned int epat[8];
1057     +#endif
1058     +
1059     + NewportRegsPtr pNewportRegs;
1060     + NewportPtr pNewport;
1061     + pNewport = NEWPORTPTR(pScrn);
1062     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1063     +
1064     + if (w == 0) w = 1;
1065     + if (h == 0) h = 1;
1066     + ex = x + w - 1;
1067     + ey = y + h - 1;
1068     +
1069     + NewportWaitGFIFO(pNewport, 3);
1070     + pNewportRegs->set.xystarti = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
1071     + pNewportRegs->set.xyendi = ((ex & 0xFFFF) << 16) | (ey & 0xFFFF);
1072     + pNewportRegs->set._setup = 1;
1073     +
1074     +#ifdef NEWPORT_PREROTATE
1075     + patx &= 7;
1076     + paty &= 7;
1077     + while (h--)
1078     + {
1079     + for (d = (w + 31) >> 5; d; d--)
1080     + {
1081     + NewportWaitGFIFO(pNewport, 1);
1082     + pNewportRegs->go.zpattern = pNewport->pat8x8[paty][patx];
1083     + }
1084     + paty = (paty + 1) & 7;
1085     + }
1086     +#else
1087     + epat[0] = repbyte(patx >> 24);
1088     + epat[1] = repbyte(patx >> 16);
1089     + epat[2] = repbyte(patx >> 8);
1090     + epat[3] = repbyte(patx);
1091     + epat[4] = repbyte(paty >> 24);
1092     + epat[5] = repbyte(paty >> 16);
1093     + epat[6] = repbyte(paty >> 8);
1094     + epat[7] = repbyte(paty);
1095     +
1096     + p = 0;
1097     + while (h--)
1098     + {
1099     + for (d = (w + 31) >> 5; d; d--)
1100     + {
1101     + NewportWaitGFIFO(pNewport, 1);
1102     + pNewportRegs->go.zpattern = epat[p];
1103     + }
1104     + p = (p + 1) ^ 7;
1105     + }
1106     +#endif
1107     +}
1108     +
1109     +/*******************************************************************************
1110     +
1111     +*******************************************************************************/
1112     +static void
1113     +NewportXAAReadPixmap(ScrnInfoPtr pScrn,
1114     + int x,
1115     + int y,
1116     + int w,
1117     + int h,
1118     + unsigned char *dst,
1119     + int dstwidth,
1120     + int bpp,
1121     + int depth)
1122     +{
1123     + int ex, ey;
1124     + NewportRegsPtr pNewportRegs;
1125     + NewportPtr pNewport;
1126     + pNewport = NEWPORTPTR(pScrn);
1127     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1128     +
1129     + if (w == 0) w = 1;
1130     + if (h == 0) h = 1;
1131     + ex = x + w - 1;
1132     + ey = y + h - 1;
1133     +
1134     + NewportWaitIdle(pNewport, 0);
1135     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(GXcopy) | NPORT_DMODE1_PFENAB);
1136     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(0xFFFFFFFF));
1137     + NewportUpdateDRAWMODE0(pNewport,
1138     + 0
1139     + | NPORT_DMODE0_RD
1140     + | NPORT_DMODE0_BLOCK
1141     + | NPORT_DMODE0_CHOST
1142     + | NPORT_DMODE0_DOSETUP
1143     + );
1144     +
1145     + NewportWaitGFIFO(pNewport, 3);
1146     + pNewportRegs->set.xystarti = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
1147     + pNewportRegs->set.xyendi = ((ex & 0xFFFF) << 16) | (ey & 0xFFFF);
1148     + /* with prefetch enabled go has to be issued before we start reading */
1149     + pNewportRegs->go._setup = 1;
1150     +
1151     +
1152     + if (pScrn->bitsPerPixel == 8)
1153     + {
1154     + unsigned int d;
1155     + while (h--)
1156     + {
1157     + unsigned char *p;
1158     + p = (unsigned char *)dst;
1159     + for (x = 0; x < w; x += 4)
1160     + {
1161     + if (!h && x+4 >= w)
1162     + { /* the last dword does not need go */
1163     + d = pNewportRegs->set.hostrw0;
1164     + }
1165     + else
1166     + {
1167     + d = pNewportRegs->go.hostrw0;
1168     + }
1169     +
1170     + *p++ = (d & 0xFF000000) >> 24;
1171     + if (x+1 < w)
1172     + {
1173     + *p++ = (d & 0x00FF0000) >> 16;
1174     + }
1175     + if (x+2 < w)
1176     + {
1177     + *p++ = (d & 0x0000FF00) >> 8;
1178     + }
1179     + if (x+3 < w)
1180     + {
1181     + *p++ = d & 0x000000FF;
1182     + }
1183     + }
1184     + dst += dstwidth;
1185     + }
1186     + }
1187     + else
1188     + {
1189     + while (h--)
1190     + {
1191     + unsigned int *p;
1192     + p = (unsigned int *)dst;
1193     + for (x = 0; x < w; x++)
1194     + {
1195     + if (!h && x+1 == w)
1196     + { /* the last dword does not need go */
1197     + *p++ = pNewportRegs->set.hostrw0;
1198     + }
1199     + else
1200     + {
1201     + *p++ = pNewportRegs->go.hostrw0;
1202     + }
1203     + }
1204     + dst += dstwidth;
1205     + }
1206     + }
1207     +}
1208     +
1209     +/*******************************************************************************
1210     +
1211     +*******************************************************************************/
1212     +static void
1213     +NewportXAASetClippingRectangle(ScrnInfoPtr pScrn,
1214     + int left,
1215     + int top,
1216     + int right,
1217     + int bottom)
1218     +{
1219     + NewportPtr pNewport;
1220     + pNewport = NEWPORTPTR(pScrn);
1221     +
1222     + if (left < 0) left = 0;
1223     + if (right > pScrn->virtualX-1) right = pScrn->virtualX-1;
1224     +
1225     + if (top < 0) top = 0;
1226     + if (bottom > pScrn->virtualY-1) bottom = pScrn->virtualY-1;
1227     +
1228     + pNewport->clipsx = left;
1229     + pNewport->clipex = right;
1230     + pNewport->clipsy = top;
1231     + pNewport->clipey = bottom;
1232     +
1233     + NewportUpdateClipping(pNewport);
1234     +}
1235     +
1236     +/*******************************************************************************
1237     +
1238     +*******************************************************************************/
1239     +static void
1240     +NewportXAADisableClipping(ScrnInfoPtr pScrn)
1241     +{
1242     + NewportPtr pNewport;
1243     + pNewport = NEWPORTPTR(pScrn);
1244     +
1245     + pNewport->clipsx = 0;
1246     + pNewport->clipex = pScrn->virtualX-1;
1247     + pNewport->clipsy = 0;
1248     + pNewport->clipey = pScrn->virtualY-1;
1249     + NewportUpdateClipping(pNewport);
1250     +}
1251     +
1252     +/*******************************************************************************
1253     +
1254     +*******************************************************************************/
1255     +static void
1256     +NewportPolyPoint(DrawablePtr pDraw,
1257     + GCPtr pGC,
1258     + int mode,
1259     + int npt,
1260     + xPoint *ppt)
1261     +{
1262     + ScrnInfoPtr pScrn;
1263     + int numRects = REGION_NUM_RECTS(pGC->pCompositeClip);
1264     + int rect;
1265     + XAAInfoRecPtr infoRec;
1266     + BoxPtr pbox;
1267     + int x, y;
1268     + int rop;
1269     +
1270     + NewportRegsPtr pNewportRegs;
1271     + NewportPtr pNewport;
1272     +
1273     + infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
1274     + pScrn = infoRec->pScrn;
1275     +
1276     + if (!numRects)
1277     + return;
1278     +
1279     + pNewport = NEWPORTPTR(pScrn);
1280     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1281     +
1282     + x = pDraw->x;
1283     + y = pDraw->y;
1284     +
1285     + rop = pGC->alu;
1286     +
1287     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(pGC->planemask));
1288     + if (rop == GXcopy
1289     + || rop == GXclear
1290     + || rop == GXset)
1291     + {
1292     + /* if possible try to set up a fast clear which is 4x faster */
1293     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | NPORT_DMODE1_FCLR | Rop2LogicOp(GXcopy));
1294     + if (rop == GXclear)
1295     + NewportUpdateCOLORVRAM(pNewport, 0);
1296     + else
1297     + if (rop == GXset)
1298     + NewportUpdateCOLORVRAM(pNewport, 0xFFFFFF);
1299     + else
1300     + NewportUpdateCOLORVRAM(pNewport, pNewport->Color2Planes((unsigned int)(pGC->fgPixel)));
1301     + }
1302     + else
1303     + {
1304     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(rop));
1305     + NewportUpdateCOLORI(pNewport, NewportColor2HOSTRW(pGC->fgPixel));
1306     + }
1307     +
1308     + pNewport->skipleft = 0;
1309     + NewportUpdateClipping(pNewport);
1310     + NewportUpdateDRAWMODE0(pNewport,
1311     + 0
1312     + | NPORT_DMODE0_DRAW
1313     + | NPORT_DMODE0_BLOCK
1314     + | NPORT_DMODE0_DOSETUP
1315     + );
1316     +
1317     + pbox = REGION_RECTS(pGC->pCompositeClip);
1318     +
1319     + while (npt--) {
1320     + if (mode == CoordModePrevious)
1321     + {
1322     + x += ppt->x;
1323     + y += ppt->y;
1324     + }
1325     + else
1326     + {
1327     + x = pDraw->x + ppt->x;
1328     + y = pDraw->y + ppt->y;
1329     + }
1330     + for (rect = 0; rect < numRects; rect++)
1331     + if (x >= pbox[rect].x1 && x < pbox[rect].x2
1332     + && y >= pbox[rect].y1 && y < pbox[rect].y2)
1333     + { /* draw point */
1334     + unsigned int xy;
1335     + xy = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
1336     + NewportWaitGFIFO(pNewport, 2);
1337     + pNewportRegs->set.xystarti = xy;
1338     + pNewportRegs->go.xyendi = xy;
1339     + break;
1340     + }
1341     + ppt++;
1342     + }
1343     +}
1344     +
1345     +/*******************************************************************************
1346     +
1347     +*******************************************************************************/
1348     +static void
1349     +NewportValidatePolyPoint(GCPtr pGC,
1350     + unsigned long changes,
1351     + DrawablePtr pDraw)
1352     +{
1353     +
1354     + if (pDraw->type == DRAWABLE_WINDOW)
1355     + {
1356     + pGC->ops->PolyPoint = NewportPolyPoint;
1357     + }
1358     + else
1359     + {
1360     + pGC->ops->PolyPoint = XAAFallbackOps.PolyPoint;
1361     + }
1362     +}
1363     +
1364     +#if 1
1365     +/*******************************************************************************
1366     +
1367     +*******************************************************************************/
1368     +static void
1369     +NewportPolyArc(DrawablePtr pDraw,
1370     + GCPtr pGC,
1371     + int narcs,
1372     + xArc *parcs)
1373     +{
1374     + xArc *arc;
1375     + BoxRec box;
1376     + int i, x2, y2;
1377     + RegionPtr cclip;
1378     +
1379     + cclip = pGC->pCompositeClip;
1380     +
1381     + if(!REGION_NUM_RECTS(cclip))
1382     + return;
1383     +
1384     + for (arc = parcs, i = narcs; --i >= 0; arc++) {
1385     + if (miCanZeroArc(arc)) {
1386     + box.x1 = arc->x + pDraw->x;
1387     + box.y1 = arc->y + pDraw->y;
1388     + x2 = box.x1 + (int)arc->width + 1;
1389     + box.x2 = x2;
1390     + y2 = box.y1 + (int)arc->height + 1;
1391     + box.y2 = y2;
1392     + if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
1393     + (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
1394     + miZeroPolyArc(pDraw, pGC, 1, arc);
1395     + }
1396     + else
1397     + miPolyArc(pDraw, pGC, 1, arc);
1398     + }
1399     +}
1400     +#endif
1401     +
1402     +/*******************************************************************************
1403     +
1404     +*******************************************************************************/
1405     +static void
1406     +NewportValidatePolyArc(GCPtr pGC,
1407     + unsigned long changes,
1408     + DrawablePtr pDraw)
1409     +{
1410     + if (pDraw->type == DRAWABLE_WINDOW)
1411     + {
1412     + pGC->ops->PolyPoint = NewportPolyPoint;
1413     + /*pGC->ops->PolyArc = miPolyArc;*/
1414     + pGC->ops->PolyArc = NewportPolyArc;
1415     +
1416     + }
1417     + else
1418     + {
1419     + pGC->ops->PolyPoint = XAAFallbackOps.PolyPoint;
1420     + pGC->ops->PolyArc = XAAFallbackOps.PolyArc;
1421     + }
1422     +}
1423     +
1424     +
1425     +#ifdef RENDER
1426     +/*******************************************************************************
1427     +
1428     +*******************************************************************************/
1429     +static Bool
1430     +NewportXAASetupForCPUToScreenAlphaTexture(
1431     + ScrnInfoPtr pScrn,
1432     + int op,
1433     + CARD16 red,
1434     + CARD16 green,
1435     + CARD16 blue,
1436     + CARD16 alpha,
1437     + CARD32 maskFormat,
1438     + CARD32 dstFormat,
1439     + CARD8 *alphaPtr,
1440     + int alphaPitch,
1441     + int width,
1442     + int height,
1443     + int flags)
1444     +{
1445     + unsigned int col, a;
1446     + unsigned char *pSrc;
1447     + unsigned int *pDst;
1448     + unsigned int w;
1449     + NewportRegsPtr pNewportRegs;
1450     + NewportPtr pNewport;
1451     + pNewport = NEWPORTPTR(pScrn);
1452     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1453     +
1454     + if (width * height * sizeof(unsigned int) > pNewport->uTextureSize)
1455     + {
1456     + free(pNewport->pTexture);
1457     + pNewport->pTexture = xnfalloc(pNewport->uTextureSize = width * height * sizeof(unsigned int));
1458     + }
1459     + col = (((unsigned int)red & 0xFF00) << 8)
1460     + | ((unsigned int)green & 0xFF00)
1461     + | ((unsigned int)blue >> 8);
1462     +
1463     + pNewport->uTextureWidth = width;
1464     + pNewport->uTextureHeight = height;
1465     + pNewport->uTextureFlags = flags;
1466     +
1467     + /* copy texture */
1468     + pDst = pNewport->pTexture;
1469     + while (height--) {
1470     + pSrc = (unsigned char *)alphaPtr;
1471     +
1472     + for (w = width; w; w--)
1473     + {
1474     + /* premultiply alpha */
1475     + a = *pSrc++;
1476     + a *= alpha;
1477     + a /= 0xFFFF;
1478     + a <<= 24;
1479     + *pDst++ = col | a;
1480     + }
1481     + alphaPtr += alphaPitch;
1482     + }
1483     +#define SFACTOR (4 << 19)
1484     +#define DFACTOR (5 << 22)
1485     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(GXcopy) | NPORT_DMODE1_BENAB | SFACTOR | DFACTOR );
1486     +#undef SFACTOR
1487     +#undef DFACTOR
1488     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(0xFFFFFFFF));
1489     +
1490     + pNewport->skipleft = 0;
1491     + NewportUpdateClipping(pNewport);
1492     + NewportUpdateDRAWMODE0(pNewport,
1493     + 0
1494     + | NPORT_DMODE0_DRAW
1495     + | NPORT_DMODE0_BLOCK
1496     + | NPORT_DMODE0_CHOST
1497     + | NPORT_DMODE0_AHOST
1498     + | NPORT_DMODE0_DOSETUP
1499     + );
1500     + return TRUE;
1501     +}
1502     +
1503     +/*******************************************************************************
1504     +
1505     +*******************************************************************************/
1506     +static Bool
1507     +NewportXAASetupForCPUToScreenTexture(
1508     + ScrnInfoPtr pScrn,
1509     + int op,
1510     + CARD32 srcFormat,
1511     + CARD32 dstFormat,
1512     + CARD8 *texPtr,
1513     + int texPitch,
1514     + int width,
1515     + int height,
1516     + int flags)
1517     +{
1518     + unsigned int *pSrc, *pDst;
1519     + unsigned int w;
1520     + NewportRegsPtr pNewportRegs;
1521     + NewportPtr pNewport;
1522     + pNewport = NEWPORTPTR(pScrn);
1523     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1524     +
1525     + if (width * height * sizeof(unsigned int) > pNewport->uTextureSize)
1526     + {
1527     + free(pNewport->pTexture);
1528     + pNewport->pTexture = xnfalloc(pNewport->uTextureSize = width * height * sizeof(unsigned int));
1529     + }
1530     +
1531     + pNewport->uTextureWidth = width;
1532     + pNewport->uTextureHeight = height;
1533     + pNewport->uTextureFlags = flags;
1534     +
1535     + /* copy texture */
1536     + pDst = pNewport->pTexture;
1537     +
1538     + if (srcFormat == PICT_a8r8g8b8)
1539     + {
1540     + while (height--) {
1541     + pSrc = (unsigned int *)texPtr;
1542     +
1543     + for (w = width; w; w--)
1544     + {
1545     + unsigned int v;
1546     + v = *pSrc++;
1547     + *pDst++ = (v & 0xFF00FF00) | ((v & 0x00FF0000) >> 16) | ((v & 0x000000FF) << 16);
1548     + }
1549     + texPtr += texPitch;
1550     + }
1551     + }
1552     + else
1553     + if (srcFormat == PICT_a8b8g8r8)
1554     + {
1555     + while (height--) {
1556     + pSrc = (unsigned int *)texPtr;
1557     +
1558     + for (w = width; w; w--)
1559     + *pDst++ = *pSrc++;
1560     + texPtr += texPitch;
1561     + }
1562     + }
1563     + else
1564     + {
1565     + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Unknown texture format\n");
1566     + }
1567     +
1568     +#define SFACTOR (4 << 19)
1569     +#define DFACTOR (5 << 22)
1570     + NewportUpdateDRAWMODE1(pNewport, pNewport->setup_drawmode1 | Rop2LogicOp(GXcopy) | NPORT_DMODE1_BENAB | SFACTOR | DFACTOR );
1571     +#undef SFACTOR
1572     +#undef DFACTOR
1573     + NewportUpdateWRMASK(pNewport, pNewport->Color2Planes(0xFFFFFFFF));
1574     +
1575     + pNewport->skipleft = 0;
1576     + NewportUpdateClipping(pNewport);
1577     + NewportUpdateDRAWMODE0(pNewport,
1578     + 0
1579     + | NPORT_DMODE0_DRAW
1580     + | NPORT_DMODE0_BLOCK
1581     + | NPORT_DMODE0_CHOST
1582     + | NPORT_DMODE0_AHOST
1583     + | NPORT_DMODE0_DOSETUP
1584     + );
1585     +
1586     + return TRUE;
1587     +}
1588     +
1589     +/*******************************************************************************
1590     +
1591     +*******************************************************************************/
1592     +static void
1593     +NewportRenderTexture1to1(NewportPtr pNewport, int srcx, int srcy, int w, int h)
1594     +{
1595     + unsigned int *p;
1596     + unsigned int add, d;
1597     + NewportRegsPtr pNewportRegs;
1598     + pNewportRegs = pNewport->pNewportRegs;
1599     +
1600     + p = pNewport->pTexture + srcx + (srcy * pNewport->uTextureWidth);
1601     + add = pNewport->uTextureWidth - w + srcx;
1602     + while (h--)
1603     + {
1604     + for (d = w; d; d--)
1605     + {
1606     + /*NewportWaitGFIFO(pNewport, 1);*/
1607     + /* hopefully we cannot write faster than XL24 can blend */
1608     + pNewportRegs->go.hostrw0 = *p++;
1609     + }
1610     + p += add;
1611     + }
1612     +}
1613     +
1614     +/*******************************************************************************
1615     +
1616     +*******************************************************************************/
1617     +static void
1618     +NewportRenderTextureScale(NewportPtr pNewport, int srcx, int srcy, int w, int h)
1619     +{
1620     + int d;
1621     + int dx, dy;
1622     + int curx, cury;
1623     + unsigned int *pLine;
1624     + int l, p;
1625     + NewportRegsPtr pNewportRegs;
1626     + pNewportRegs = pNewport->pNewportRegs;
1627     +
1628     + dx = ((pNewport->uTextureWidth - srcx) << 16) / w;
1629     + dy = ((pNewport->uTextureHeight - srcy) << 16) / h;
1630     +
1631     + cury = srcy << 16;
1632     + while (h--)
1633     + {
1634     + l = (cury + 0x7FFF) >> 16;
1635     + if (l >= pNewport->uTextureHeight)
1636     + l = pNewport->uTextureHeight-1;
1637     + pLine = pNewport->pTexture + l * pNewport->uTextureWidth;
1638     +
1639     + curx = srcx << 16;
1640     + for (d = w; d; d--)
1641     + {
1642     + p = (curx + 0x7FFF) >> 16;
1643     + if (p >= pNewport->uTextureWidth)
1644     + p = pNewport->uTextureWidth-1;
1645     + pNewportRegs->go.hostrw0 = pLine[p];
1646     + curx += dx;
1647     + }
1648     + cury += dy;
1649     + }
1650     +}
1651     +
1652     +/*******************************************************************************
1653     +
1654     +*******************************************************************************/
1655     +static void
1656     +NewportRenderTextureRepeat(NewportPtr pNewport, int srcx, int srcy, int w, int h)
1657     +{
1658     + int d;
1659     + unsigned int *pLine;
1660     + NewportRegsPtr pNewportRegs;
1661     + pNewportRegs = pNewport->pNewportRegs;
1662     +
1663     + srcx %= pNewport->uTextureWidth;
1664     + srcy %= pNewport->uTextureHeight;
1665     +
1666     + while (h--)
1667     + {
1668     + pLine = pNewport->pTexture + pNewport->uTextureWidth * srcy;
1669     + for (d = w; d; d--)
1670     + {
1671     + pNewportRegs->go.hostrw0 = pLine[srcx];
1672     + srcx++;
1673     + if (srcx >= pNewport->uTextureWidth)
1674     + srcx = 0;
1675     + }
1676     + srcy++;
1677     + if (srcy >= pNewport->uTextureHeight)
1678     + srcy = 0;
1679     + }
1680     +
1681     +}
1682     +
1683     +
1684     +/*******************************************************************************
1685     +
1686     +*******************************************************************************/
1687     +static void
1688     +NewportXAASubsequentCPUToScreenTexture(
1689     + ScrnInfoPtr pScrn,
1690     + int x,
1691     + int y,
1692     + int srcx,
1693     + int srcy,
1694     + int w,
1695     + int h)
1696     +{
1697     + int ex, ey;
1698     + NewportRegsPtr pNewportRegs;
1699     + NewportPtr pNewport;
1700     + pNewport = NEWPORTPTR(pScrn);
1701     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1702     +
1703     + if (w == 0) w = 1;
1704     + if (h == 0) h = 1;
1705     + ex = x + w - 1;
1706     + ey = y + h - 1;
1707     +
1708     + NewportWaitGFIFO(pNewport, 3);
1709     + pNewportRegs->set.xystarti = ((x & 0xFFFF) << 16) | (y & 0xFFFF);
1710     + pNewportRegs->set.xyendi = ((ex & 0xFFFF) << 16) | (ey & 0xFFFF);
1711     + pNewportRegs->set._setup = 1;
1712     +
1713     + NewportWaitIdle(pNewport, NEWPORT_GFIFO_ENTRIES);
1714     +
1715     + if (srcx + w == pNewport->uTextureWidth
1716     + && srcy + h == pNewport->uTextureHeight)
1717     + NewportRenderTexture1to1(pNewport, srcx, srcy, w, h);
1718     + else
1719     + if (pNewport->uTextureFlags & XAA_RENDER_REPEAT)
1720     + NewportRenderTextureRepeat(pNewport, srcx, srcy, w, h);
1721     + else
1722     + NewportRenderTextureScale(pNewport, srcx, srcy, w, h);
1723     +
1724     + NewportWaitIdle(pNewport, NEWPORT_GFIFO_ENTRIES);
1725     +
1726     +}
1727     +
1728     +CARD32 NewportAlphaTextureFormats[2] = {PICT_a8, 0};
1729     +CARD32 NewportTextureFormats[3] = {PICT_a8r8g8b8, PICT_a8b8g8r8, 0};
1730     +/*CARD32 NewportTextureFormats[2] = {PICT_a8r8g8b8, 0};*/
1731     +CARD32 NewportDstFormats[7] = {PICT_a8r8g8b8, PICT_a8b8g8r8, PICT_x8r8g8b8, PICT_x8b8g8r8, PICT_r8g8b8, PICT_b8g8r8, 0};
1732     +
1733     +#endif
1734     +
1735     +/*******************************************************************************
1736     +
1737     +*******************************************************************************/
1738     +Bool
1739     +NewportXAAScreenInit(ScreenPtr pScreen)
1740     +{
1741     + ScrnInfoPtr pScrn;
1742     + NewportPtr pNewport;
1743     + NewportRegsPtr pNewportRegs;
1744     + XAAInfoRecPtr pXAAInfoRec;
1745     +
1746     + /* First get a pointer to our private info */
1747     + pScrn = xf86Screens[pScreen->myNum];
1748     + pNewport = NEWPORTPTR(pScrn);
1749     + pNewportRegs = NEWPORTREGSPTR(pScrn);
1750     +
1751     + pXAAInfoRec =
1752     + pNewport->pXAAInfoRec = XAACreateInfoRec();
1753     + /* initialize accelerated functions */
1754     + pXAAInfoRec->Sync = NewportXAASync;
1755     +
1756     + pXAAInfoRec->Flags = 0
1757     + /*| LINEAR_FRAMEBUFFER*/
1758     + ;
1759     + /* screen to screen copy */
1760     + pXAAInfoRec->ScreenToScreenCopyFlags = 0
1761     + | NO_TRANSPARENCY
1762     + ;
1763     + pXAAInfoRec->SetupForScreenToScreenCopy = NewportXAASetupForScreenToScreenCopy;
1764     + pXAAInfoRec->SubsequentScreenToScreenCopy = NewportXAASubsequentScreenToScreenCopy;
1765     +
1766     + /* solid fills */
1767     + pXAAInfoRec->SolidFillFlags = 0
1768     + ;
1769     + pXAAInfoRec->SetupForSolidFill = NewportXAASetupForSolidFill;
1770     + pXAAInfoRec->SubsequentSolidFillRect = NewportXAASubsequentSolidFillRect;
1771     +
1772     + /* solid lines */
1773     + pXAAInfoRec->SolidLineFlags = 0
1774     + ;
1775     + pXAAInfoRec->SetupForSolidLine = NewportXAASetupForSolidLine;
1776     + pXAAInfoRec->SubsequentSolidTwoPointLine = NewportXAASubsequentSolidTwoPointLine;
1777     +
1778     + /* dashed lines */
1779     + pXAAInfoRec->DashedLineFlags = 0
1780     + | LINE_PATTERN_MSBFIRST_MSBJUSTIFIED
1781     + ;
1782     + pXAAInfoRec->DashPatternMaxLength = 2048;
1783     + pXAAInfoRec->SetupForDashedLine = NewportXAASetupForDashedLine;
1784     + pXAAInfoRec->SubsequentDashedTwoPointLine = NewportXAASubsequentDashedTwoPointLine;
1785     +
1786     + /* cpu to screen expand color fill */
1787     + pXAAInfoRec->CPUToScreenColorExpandFillFlags = 0
1788     + | BIT_ORDER_IN_BYTE_LSBFIRST
1789     + | SCANLINE_PAD_DWORD
1790     + | CPU_TRANSFER_PAD_DWORD
1791     + | CPU_TRANSFER_BASE_FIXED
1792     + | LEFT_EDGE_CLIPPING
1793     + | LEFT_EDGE_CLIPPING_NEGATIVE_X
1794     + /*| SYNC_AFTER_COLOR_EXPAND*/
1795     + ;
1796     +
1797     + pXAAInfoRec->SetupForCPUToScreenColorExpandFill = NewportXAASetupForCPUToScreenColorExpandFill;
1798     + pXAAInfoRec->SubsequentCPUToScreenColorExpandFill = NewportXAASubsequentCPUToScreenColorExpandFill;
1799     + pXAAInfoRec->ColorExpandRange = 4;
1800     + pXAAInfoRec->ColorExpandBase = (unsigned char *)&(pNewportRegs->go.zpattern);
1801     +
1802     +
1803     + /* mono 8x8 pattern fill */
1804     + pXAAInfoRec->Mono8x8PatternFillFlags = 0
1805     + | BIT_ORDER_IN_BYTE_LSBFIRST
1806     + | HARDWARE_PATTERN_PROGRAMMED_BITS
1807     +#ifdef NEWPORT_PREROTATE
1808     + | HARDWARE_PATTERN_PROGRAMMED_ORIGIN
1809     +#endif
1810     + ;
1811     +
1812     + pXAAInfoRec->SetupForMono8x8PatternFill = NewportXAASetupForMono8x8PatternFill;
1813     + pXAAInfoRec->SubsequentMono8x8PatternFillRect = NewportXAASubsequentMono8x8PatternFillRect;
1814     +
1815     + /* Image write */
1816     + pXAAInfoRec->ImageWriteFlags = 0
1817     + | NO_TRANSPARENCY
1818     + | CPU_TRANSFER_BASE_FIXED
1819     + | CPU_TRANSFER_PAD_DWORD
1820     + | SCANLINE_PAD_DWORD
1821     + | LEFT_EDGE_CLIPPING
1822     + | LEFT_EDGE_CLIPPING_NEGATIVE_X
1823     + /*| SYNC_AFTER_IMAGE_WRITE*/
1824     + ;
1825     + pXAAInfoRec->SetupForImageWrite = NewportXAASetupForImageWrite;
1826     + pXAAInfoRec->SubsequentImageWriteRect = NewportXAASubsequentImageWriteRect;
1827     + pXAAInfoRec->ImageWriteRange = 4;
1828     + pXAAInfoRec->ImageWriteBase = (unsigned char *)&(pNewportRegs->go.hostrw0);
1829     +
1830     + /* read pixmap */
1831     + pXAAInfoRec->ReadPixmapFlags = 0
1832     + | CPU_TRANSFER_PAD_DWORD
1833     + ;
1834     + pXAAInfoRec->ReadPixmap = NewportXAAReadPixmap;
1835     +
1836     + /* clipping */
1837     + pXAAInfoRec->ClippingFlags = 0
1838     + /*| HARDWARE_CLIP_SCREEN_TO_SCREEN_COLOR_EXPAND*/
1839     + | HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY
1840     + | HARDWARE_CLIP_MONO_8x8_FILL
1841     + /*| HARDWARE_CLIP_COLOR_8x8_FILL*/
1842     + | HARDWARE_CLIP_SOLID_FILL
1843     + | HARDWARE_CLIP_DASHED_LINE
1844     + | HARDWARE_CLIP_SOLID_LINE
1845     + ;
1846     + pXAAInfoRec->SetClippingRectangle = NewportXAASetClippingRectangle;
1847     + pXAAInfoRec->DisableClipping = NewportXAADisableClipping;
1848     +
1849     + /* make it draw points using our function */
1850     + pXAAInfoRec->ValidatePolyPoint = NewportValidatePolyPoint;
1851     + pXAAInfoRec->PolyPointMask = GCFunction | GCPlaneMask;
1852     + /*pXAAInfoRec->PolyPointMask = 0xFFFFFFFF;*/
1853     +
1854     + pXAAInfoRec->ValidatePolyArc = NewportValidatePolyArc;
1855     + pXAAInfoRec->PolyArcMask = GCFunction | GCLineWidth;
1856     +#ifdef RENDER
1857     + if (pScrn->bitsPerPixel > 8)
1858     + {
1859     + pXAAInfoRec->CPUToScreenTextureFlags = 0
1860     + ;
1861     + pXAAInfoRec->CPUToScreenTextureFormats = NewportTextureFormats;
1862     + pXAAInfoRec->CPUToScreenTextureDstFormats = NewportDstFormats;
1863     + pXAAInfoRec->SetupForCPUToScreenTexture2 = NewportXAASetupForCPUToScreenTexture;
1864     + pXAAInfoRec->SubsequentCPUToScreenTexture = NewportXAASubsequentCPUToScreenTexture;
1865     +
1866     + pXAAInfoRec->CPUToScreenAlphaTextureFlags = 0
1867     + ;
1868     + pXAAInfoRec->CPUToScreenAlphaTextureFormats = NewportAlphaTextureFormats;
1869     + pXAAInfoRec->CPUToScreenAlphaTextureDstFormats = NewportDstFormats;
1870     + pXAAInfoRec->SetupForCPUToScreenAlphaTexture2 = NewportXAASetupForCPUToScreenAlphaTexture;
1871     + pXAAInfoRec->SubsequentCPUToScreenAlphaTexture = NewportXAASubsequentCPUToScreenTexture; /* this is the same for both */
1872     + pNewport->pTexture = (unsigned int *)xnfalloc(pNewport->uTextureSize = 16*16*sizeof(unsigned int));
1873     + }
1874     +#endif
1875     +
1876     + pNewport->Color2Planes = NewportColor2Planes24;
1877     + if (pScrn->bitsPerPixel == 8)
1878     + {
1879     + pNewport->Color2Planes = NewportColor2Planes8;
1880     + }
1881     +
1882     + if (!XAAInit(pScreen, pXAAInfoRec))
1883     + {
1884     + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "XAAInit Failed!\n");
1885     + return FALSE;
1886     + }
1887     +
1888     + pNewport->fifoleft = 0;
1889     + /* init bunch of registers */
1890     +
1891     + pNewport->shadow_drawmode0 = pNewportRegs->set.drawmode0;
1892     + pNewport->shadow_colori = pNewportRegs->set.colori;
1893     + pNewport->shadow_smask0x = pNewportRegs->set.smask0x;
1894     + pNewport->shadow_smask0y = pNewportRegs->set.smask0y;
1895     +
1896     + pNewport->shadow_drawmode1 = pNewport->drawmode1;
1897     + pNewportRegs->set.drawmode1 = pNewport->drawmode1;
1898     + pNewport->setup_drawmode1 = pNewport->drawmode1 & ~NPORT_DMODE1_LOMASK;
1899     +
1900     + pNewport->shadow_xymove = 0;
1901     + pNewportRegs->set.xymove = 0;
1902     +
1903     + pNewport->shadow_wrmask = 0xFFFFFF;
1904     + pNewportRegs->set.wrmask = 0xFFFFFF;
1905     +
1906     + pNewport->shadow_colorvram = 0;
1907     + pNewportRegs->set.colorvram = 0;
1908     +
1909     + pNewport->shadow_colorback = 0;
1910     + pNewportRegs->set.colorback = 0;
1911     +
1912     + pNewport->clipsx = 0;
1913     + pNewport->clipex = pScrn->virtualX-1;
1914     + pNewport->clipsy = 0;
1915     + pNewport->clipey = pScrn->virtualY-1;
1916     + pNewport->skipleft = 0;
1917     +
1918     + BARF1("CLIPMODE %08X\n", pNewportRegs->cset.clipmode);
1919     + BARF1("XYWIN %08X\n", pNewportRegs->cset.xywin);
1920     + BARF1("CONFIG %08X\n", pNewportRegs->cset.config);
1921     + BARF1("SMASK0X %08X\n", pNewportRegs->set.smask0x);
1922     + BARF1("SMASK0Y %08X\n", pNewportRegs->set.smask0y);
1923     +
1924     +/*
1925     + set GIO bus timeout to highest possible value 4.32us
1926     + this will allow for longer bus stalls without bus error
1927     +*/
1928     + {
1929     + unsigned int conf;
1930     + conf = pNewportRegs->cset.config;
1931     + conf &= ~NPORT_CFG_TOMSK;
1932     + conf |= NPORT_CFG_TOMSK;
1933     +
1934     + conf &= ~NPORT_CFG_GDMSK;
1935     + conf |= NPORT_CFG_GDMSK;
1936     +
1937     + pNewportRegs->cset.config = conf;
1938     + }
1939     +
1940     + BARF1("CONFIG %08X\n", pNewportRegs->cset.config);
1941     +
1942     + pNewport->shadow_clipmode = pNewportRegs->cset.clipmode;
1943     + pNewportRegs->cset.clipmode |= 1; /* enable clipping mask 0 */
1944     + NewportUpdateClipping(pNewport);
1945     +
1946     + return TRUE;
1947     +}
1948     +
1949     +#endif
1950     +/* NEWPORT_ACCEL */
1951     diff -Nur xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c xc/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c
1952     --- xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c 2004-11-11 08:52:59.559743184 -0500
1953     +++ xc/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c 2004-11-11 08:52:32.849803712 -0500
1954     @@ -117,6 +117,15 @@
1955     NULL
1956     };
1957    
1958     +static const char *xaaSymbols[] = {
1959     + "XAACreateInfoRec",
1960     + "XAADestroyInfoRec",
1961     + "XAAFallbackOps",
1962     + "XAAInit",
1963     + NULL
1964     +};
1965     +
1966     +
1967     #ifdef XFree86LOADER
1968    
1969     static MODULESETUPPROTO(newportSetup);
1970     @@ -128,6 +137,9 @@
1971     MODINFOSTRING1,
1972     MODINFOSTRING2,
1973     XORG_VERSION_CURRENT,
1974     +/*
1975     + XF86_VERSION_CURRENT,
1976     +*/
1977     NEWPORT_MAJOR_VERSION, NEWPORT_MINOR_VERSION, NEWPORT_PATCHLEVEL,
1978     ABI_CLASS_VIDEODRV,
1979     ABI_VIDEODRV_VERSION,
1980     @@ -156,7 +168,7 @@
1981     * might refer to.
1982     *
1983     */
1984     - LoaderRefSymLists( fbSymbols, ramdacSymbols, shadowSymbols, NULL);
1985     + LoaderRefSymLists( fbSymbols, ramdacSymbols, shadowSymbols, xaaSymbols, NULL);
1986    
1987    
1988     /*
1989     @@ -175,7 +187,8 @@
1990     typedef enum {
1991     OPTION_BITPLANES,
1992     OPTION_BUS_ID,
1993     - OPTION_HWCURSOR
1994     + OPTION_HWCURSOR,
1995     + OPTION_NOACCEL
1996     } NewportOpts;
1997    
1998     /* Supported options */
1999     @@ -183,6 +196,7 @@
2000     { OPTION_BITPLANES, "bitplanes", OPTV_INTEGER, {0}, FALSE },
2001     { OPTION_BUS_ID, "BusID", OPTV_INTEGER, {0}, FALSE },
2002     { OPTION_HWCURSOR, "HWCursor", OPTV_BOOLEAN, {0}, FALSE },
2003     + { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE },
2004     { -1, NULL, OPTV_NONE, {0}, FALSE }
2005     };
2006    
2007     @@ -297,11 +311,15 @@
2008     /* Fill in the monitor field */
2009     pScrn->monitor = pScrn->confScreen->monitor;
2010    
2011     +#ifdef NEWPORT_USE32BPP
2012     + if (!xf86SetDepthBpp(pScrn, 24, 32, 32, Support32bppFb))
2013     + return FALSE;
2014     +#else
2015     if (!xf86SetDepthBpp(pScrn, 24, 0, 0,
2016     Support24bppFb | SupportConvert32to24 |
2017     PreferConvert32to24 ))
2018     return FALSE;
2019     -
2020     +#endif
2021     switch( pScrn->depth ) {
2022     /* check if the returned depth is one we support */
2023     case 8:
2024     @@ -322,9 +340,16 @@
2025    
2026     /* Set Default Weight */
2027     if( pScrn->depth > 8 ) {
2028     +#ifdef NEWPORT_USE32BPP
2029     + rgb w = {8, 8, 8};
2030     + rgb m = {0x0000FF, 0x00FF00, 0xFF0000};
2031     + if (!xf86SetWeight(pScrn, w, m))
2032     + return FALSE;
2033     +#else
2034     rgb zeros = {0, 0, 0};
2035     if (!xf86SetWeight(pScrn, zeros, zeros))
2036     return FALSE;
2037     +#endif
2038     }
2039    
2040     if (!xf86SetDefaultVisual(pScrn, -1)) {
2041     @@ -474,6 +499,11 @@
2042     return TRUE;
2043     }
2044    
2045     +
2046     +Bool
2047     +NewportXAAScreenInit(ScreenPtr pScreen);
2048     +
2049     +
2050     static Bool
2051     NewportScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
2052     {
2053     @@ -529,18 +559,48 @@
2054     visual->redMask = pScrn->mask.red;
2055     visual->greenMask = pScrn->mask.green;
2056     visual->blueMask = pScrn->mask.blue;
2057     + /*
2058     + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Bitplanes R:%d:%08X G:%d:%08X B:%d:%08X\n",
2059     + visual->offsetRed, visual->redMask,
2060     + visual->offsetGreen, visual->greenMask,
2061     + visual->offsetBlue, visual->blueMask);
2062     + */
2063     }
2064     }
2065     }
2066    
2067     /* must be after RGB ordering fixed */
2068     - fbPictureInit (pScreen, 0, 0);
2069     + if (!fbPictureInit(pScreen, NULL, 0))
2070     + xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
2071     + "RENDER extension initialisation failed.\n");
2072    
2073     miInitializeBackingStore(pScreen);
2074     xf86SetBackingStore(pScreen);
2075    
2076     xf86SetBlackWhitePixels(pScreen);
2077     -
2078     +#ifdef NEWPORT_ACCEL
2079     + pNewport->NoAccel = FALSE;
2080     + if (xf86ReturnOptValBool(pNewport->Options, OPTION_NOACCEL, FALSE))
2081     + {
2082     + if (!xf86LoadSubModule(pScrn, "xaa"))
2083     + return FALSE;
2084     + xf86LoaderReqSymLists(xaaSymbols, NULL);
2085     + pNewport->NoAccel = TRUE;
2086     + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
2087     + }
2088     +#if 0
2089     + if (pScrn->bitsPerPixel < 24)
2090     + { /* not implemented yet */
2091     + pNewport->NoAccel = TRUE;
2092     + }
2093     +#endif
2094     + pNewport->pXAAInfoRec = NULL;
2095     + if (!pNewport->NoAccel)
2096     + {
2097     + if (!NewportXAAScreenInit(pScreen))
2098     + return FALSE;
2099     + }
2100     +#endif
2101     /* Initialize software cursor */
2102     if(!miDCInitialize(pScreen, xf86GetPointerScreenFuncs()))
2103     return FALSE;
2104     @@ -564,7 +624,9 @@
2105     "Colormap initialization failed\n");
2106     return FALSE;
2107     }
2108     -
2109     +#ifdef NEWPORT_ACCEL
2110     + if (pNewport->NoAccel)
2111     +#endif
2112     /* Initialise shadow frame buffer */
2113     if(!ShadowFBInit(pScreen, (pNewport->Bpp == 1) ? &NewportRefreshArea8 :
2114     &NewportRefreshArea24)) {
2115     @@ -617,6 +679,13 @@
2116     {
2117     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
2118     NewportPtr pNewport = NEWPORTPTR(pScrn);
2119     +#ifdef NEWPORT_ACCEL
2120     + if (pNewport->pXAAInfoRec && !pNewport->NoAccel)
2121     + {
2122     + XAADestroyInfoRec(pNewport->pXAAInfoRec);
2123     + pNewport->pXAAInfoRec = NULL;
2124     + }
2125     +#endif
2126    
2127     NewportRestore(pScrn, TRUE);
2128     if (pNewport->ShadowPtr)
2129     diff -Nur xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_regs.h xc/programs/Xserver/hw/xfree86/drivers/newport/newport_regs.h
2130     --- xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_regs.h 2004-11-11 08:52:59.558743336 -0500
2131     +++ xc/programs/Xserver/hw/xfree86/drivers/newport/newport_regs.h 2004-11-11 08:52:32.848803864 -0500
2132     @@ -8,13 +8,6 @@
2133    
2134     typedef volatile unsigned long npireg_t;
2135    
2136     -union npfloat {
2137     - volatile float f;
2138     - npireg_t i;
2139     -};
2140     -
2141     -typedef union npfloat npfreg_t;
2142     -
2143     union np_dcb {
2144     npireg_t all;
2145     struct { volatile unsigned short s0, s1; } hwords;
2146     @@ -150,44 +143,44 @@
2147     unsigned long _pad1[0x30];
2148    
2149     /* Iterators, full state for context switch */
2150     - npfreg_t _xstart; /* X-start point (current) */
2151     - npfreg_t _ystart; /* Y-start point (current) */
2152     - npfreg_t _xend; /* x-end point */
2153     - npfreg_t _yend; /* y-end point */
2154     + npireg_t _xstart; /* X-start point (current) */
2155     + npireg_t _ystart; /* Y-start point (current) */
2156     + npireg_t _xend; /* x-end point */
2157     + npireg_t _yend; /* y-end point */
2158     npireg_t xsave; /* copy of xstart integer value for BLOCk addressing MODE */
2159     npireg_t xymove; /* x.y offset from xstart, ystart for relative operations */
2160     - npfreg_t bresd;
2161     - npfreg_t bress1;
2162     + npireg_t bresd;
2163     + npireg_t bress1;
2164     npireg_t bresoctinc1;
2165     - volatile int bresrndinc2;
2166     + npireg_t bresrndinc2;
2167     npireg_t brese1;
2168     npireg_t bress2;
2169     npireg_t aweight0;
2170     npireg_t aweight1;
2171     - npfreg_t xstartf;
2172     - npfreg_t ystartf;
2173     - npfreg_t xendf;
2174     - npfreg_t yendf;
2175     + npireg_t xstartf;
2176     + npireg_t ystartf;
2177     + npireg_t xendf;
2178     + npireg_t yendf;
2179     npireg_t xstarti;
2180     - npfreg_t xendf1;
2181     + npireg_t xendf1;
2182     npireg_t xystarti;
2183     npireg_t xyendi;
2184     npireg_t xstartendi;
2185    
2186     unsigned long _unused2[0x29];
2187    
2188     - npfreg_t colorred;
2189     - npfreg_t coloralpha;
2190     - npfreg_t colorgrn;
2191     - npfreg_t colorblue;
2192     - npfreg_t slopered;
2193     - npfreg_t slopealpha;
2194     - npfreg_t slopegrn;
2195     - npfreg_t slopeblue;
2196     + npireg_t colorred;
2197     + npireg_t coloralpha;
2198     + npireg_t colorgrn;
2199     + npireg_t colorblue;
2200     + npireg_t slopered;
2201     + npireg_t slopealpha;
2202     + npireg_t slopegrn;
2203     + npireg_t slopeblue;
2204     npireg_t wrmask;
2205     npireg_t colori;
2206     - npfreg_t colorx;
2207     - npfreg_t slopered1;
2208     + npireg_t colorx;
2209     + npireg_t slopered1;
2210     npireg_t hostrw0;
2211     npireg_t hostrw1;
2212     npireg_t dcbmode;
2213     @@ -247,21 +240,22 @@
2214     #define NPORT_CMODE_CMSK 0x00001e00
2215    
2216     unsigned long _unused0;
2217     - unsigned long config;
2218     + npireg_t config;
2219     #define NPORT_CFG_G32MD 0x00000001
2220     #define NPORT_CFG_BWIDTH 0x00000002
2221     #define NPORT_CFG_ERCVR 0x00000004
2222     #define NPORT_CFG_BDMSK 0x00000078
2223     -#define NPORT_CFG_GDMSK 0x00000f80
2224     -#define NPORT_CFG_GD0 0x00000080
2225     -#define NPORT_CFG_GD1 0x00000100
2226     -#define NPORT_CFG_GD2 0x00000200
2227     -#define NPORT_CFG_GD3 0x00000400
2228     -#define NPORT_CFG_GD4 0x00000800
2229     -#define NPORT_CFG_GFAINT 0x00001000
2230     -#define NPORT_CFG_TOMSK 0x0000e000
2231     -#define NPORT_CFG_VRMSK 0x00070000
2232     -#define NPORT_CFG_FBTYP 0x00080000
2233     +#define NPORT_CFG_BFAINT 0x00000080
2234     +#define NPORT_CFG_GDMSK 0x00001f00
2235     +#define NPORT_CFG_GD0 0x00000100
2236     +#define NPORT_CFG_GD1 0x00000200
2237     +#define NPORT_CFG_GD2 0x00000400
2238     +#define NPORT_CFG_GD3 0x00000800
2239     +#define NPORT_CFG_GD4 0x00001000
2240     +#define NPORT_CFG_GFAINT 0x00002000
2241     +#define NPORT_CFG_TOMSK 0x0001C000
2242     +#define NPORT_CFG_VRMSK 0x000E0000
2243     +#define NPORT_CFG_FBTYP 0x00100000
2244    
2245     npireg_t _unused1;
2246     npireg_t stat;
2247     diff -Nur xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_shadow.c xc/programs/Xserver/hw/xfree86/drivers/newport/newport_shadow.c
2248     --- xc.orig/programs/Xserver/hw/xfree86/drivers/newport/newport_shadow.c 2004-11-11 08:52:59.558743336 -0500
2249     +++ xc/programs/Xserver/hw/xfree86/drivers/newport/newport_shadow.c 2004-11-11 08:52:32.848803864 -0500
2250     @@ -52,7 +52,9 @@
2251     {
2252     int dx, dy;
2253     CARD8 *src, *base;
2254     +#ifndef NEWPORT_USE32BPP
2255     CARD32 dest;
2256     +#endif
2257     NewportPtr pNewport = NEWPORTPTR(pScrn);
2258     NewportRegsPtr pNewportRegs = pNewport->pNewportRegs;
2259    
2260     @@ -65,8 +67,13 @@
2261     NPORT_DMODE0_CHOST);
2262    
2263     while(num--) {
2264     - base = (CARD8*)pNewport->ShadowPtr + pbox->y1 * pNewport->ShadowPitch + pbox->x1 * 3;
2265     -
2266     +
2267     + base = (CARD8*)pNewport->ShadowPtr + pbox->y1 * pNewport->ShadowPitch + pbox->x1
2268     +#ifdef NEWPORT_USE32BPP
2269     + * 4;
2270     +#else
2271     + * 3;
2272     +#endif
2273     pNewportRegs->set.xystarti = (pbox->x1 << 16) | pbox->y1;
2274     pNewportRegs->set.xyendi = ((pbox->x2-1) << 16) | (pbox->y2-1);
2275    
2276     @@ -76,9 +83,14 @@
2277     /* Removing these shifts by using 32bpp fb
2278     * yields < 2% percent performance gain and wastes 25% memory
2279     */
2280     +#ifdef NEWPORT_USE32BPP
2281     + pNewportRegs->go.hostrw0 = *(CARD32 *)src;
2282     + src += 4;
2283     +#else
2284     dest = src[0] | src[1] << 8 | src[2] << 16;
2285     pNewportRegs->go.hostrw0 = dest;
2286     src+=3;
2287     +#endif
2288     }
2289     base += pNewport->ShadowPitch;
2290     }