ast_accel.c revision 83cab373
1/*
2 * Copyright (c) 2005 ASPEED Technology Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the authors not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  The authors makes no representations
11 * about the suitability of this software for any purpose.  It is provided
12 * "as is" without express or implied warranty.
13 *
14 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26#include "xf86.h"
27#include "xf86_OSproc.h"
28#include "xf86cmap.h"
29#include "compiler.h"
30#include "mibstore.h"
31#include "vgaHW.h"
32#include "mipointer.h"
33#include "micmap.h"
34
35#include "fb.h"
36#include "regionstr.h"
37#include "xf86xv.h"
38#include <X11/extensions/Xv.h>
39#include "vbe.h"
40
41#include "xf86PciInfo.h"
42#include "xf86Pci.h"
43
44/* framebuffer offscreen manager */
45#include "xf86fbman.h"
46
47/* include xaa includes */
48#include "xaa.h"
49#include "xaarop.h"
50
51/* H/W cursor support */
52#include "xf86Cursor.h"
53
54/* Driver specific headers */
55#include "ast.h"
56
57#ifdef	Accel_2D
58/* ROP Translation Table */
59int ASTXAACopyROP[16] =
60{
61   ROP_0,               /* GXclear */
62   ROP_DSa,             /* GXand */
63   ROP_SDna,            /* GXandReverse */
64   ROP_S,               /* GXcopy */
65   ROP_DSna,            /* GXandInverted */
66   ROP_D,               /* GXnoop */
67   ROP_DSx,             /* GXxor */
68   ROP_DSo,             /* GXor */
69   ROP_DSon,            /* GXnor */
70   ROP_DSxn,            /* GXequiv */
71   ROP_Dn,              /* GXinvert*/
72   ROP_SDno,            /* GXorReverse */
73   ROP_Sn,              /* GXcopyInverted */
74   ROP_DSno,            /* GXorInverted */
75   ROP_DSan,            /* GXnand */
76   ROP_1                /* GXset */
77};
78
79int ASTXAAPatternROP[16]=
80{
81   ROP_0,
82   ROP_DPa,
83   ROP_PDna,
84   ROP_P,
85   ROP_DPna,
86   ROP_D,
87   ROP_DPx,
88   ROP_DPo,
89   ROP_DPon,
90   ROP_PDxn,
91   ROP_Dn,
92   ROP_PDno,
93   ROP_Pn,
94   ROP_DPno,
95   ROP_DPan,
96   ROP_1
97};
98
99/* extern function */
100extern void vWaitEngIdle(ScrnInfoPtr pScrn, ASTRecPtr pAST);
101extern UCHAR *pjRequestCMDQ(ASTRecPtr pAST, ULONG ulDataLen);
102extern Bool bGetLineTerm(_LINEInfo *LineInfo, LINEPARAM *dsLineParam);
103
104/* Prototype type declaration */
105Bool ASTAccelInit(ScreenPtr pScreen);
106static void ASTSync(ScrnInfoPtr pScrn);
107static void ASTSetupForScreenToScreenCopy(ScrnInfoPtr pScrn,
108                                          int xdir, int ydir, int rop,
109                                          unsigned int planemask, int trans_color);
110static void ASTSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int x1, int y1, int x2,
111                                            int y2, int w, int h);
112static void ASTSetupForSolidFill(ScrnInfoPtr pScrn,
113                                 int color, int rop, unsigned int planemask);
114static void ASTSubsequentSolidFillRect(ScrnInfoPtr pScrn,
115                                       int dst_x, int dst_y, int width, int height);
116static void ASTSetupForSolidLine(ScrnInfoPtr pScrn,
117                                 int color, int rop, unsigned int planemask);
118static void ASTSubsequentSolidHorVertLine(ScrnInfoPtr pScrn,
119                                          int x, int y, int len, int dir);
120static void ASTSubsequentSolidTwoPointLine(ScrnInfoPtr pScrn,
121                                           int x1, int y1, int x2, int y2, int flags);
122static void ASTSetupForDashedLine(ScrnInfoPtr pScrn,
123                                  int fg, int bg, int rop, unsigned int planemask,
124                                  int length, UCHAR *pattern);
125static void ASTSubsequentDashedTwoPointLine(ScrnInfoPtr pScrn,
126                                            int x1, int y1, int x2, int y2,
127                                            int flags, int phase);
128static void ASTSetupForMonoPatternFill(ScrnInfoPtr pScrn,
129                                       int patx, int paty, int fg, int bg,
130                                       int rop, unsigned int planemask);
131static void ASTSubsequentMonoPatternFill(ScrnInfoPtr pScrn,
132                                         int patx, int paty,
133                                         int x, int y, int w, int h);
134static void ASTSetupForColor8x8PatternFill(ScrnInfoPtr pScrn, int patx, int paty,
135			                   int rop, unsigned int planemask, int trans_col);
136static void ASTSubsequentColor8x8PatternFillRect(ScrnInfoPtr pScrn, int patx, int paty,
137                                                 int x, int y, int w, int h);
138static void ASTSetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
139                                                  int fg, int bg,
140                                                  int rop, unsigned int planemask);
141static void ASTSubsequentCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
142                                                    int x, int y,
143                                                    int width, int height, int skipleft);
144static void ASTSetupForScreenToScreenColorExpandFill(ScrnInfoPtr pScrn,
145                                                     int fg, int bg,
146                                                     int rop, unsigned int planemask);
147static void ASTSubsequentScreenToScreenColorExpandFill(ScrnInfoPtr pScrn,
148                                                       int x, int y, int width, int height,
149                                                       int src_x, int src_y, int offset);
150static void ASTSetClippingRectangle(ScrnInfoPtr pScrn,
151                                    int left, int top, int right, int bottom);
152static void ASTDisableClipping(ScrnInfoPtr pScrn);
153static void ASTSetHWClipping(ScrnInfoPtr pScrn, int delta_y);
154
155Bool
156ASTAccelInit(ScreenPtr pScreen)
157{
158    XAAInfoRecPtr  infoPtr;
159    ScrnInfoPtr    pScrn = xf86Screens[pScreen->myNum];
160    ASTRecPtr      pAST = ASTPTR(pScrn);
161
162    pAST->AccelInfoPtr = infoPtr = XAACreateInfoRec();
163    if (!infoPtr)  return FALSE;
164
165    infoPtr->Flags = LINEAR_FRAMEBUFFER |
166  		     OFFSCREEN_PIXMAPS |
167  		     PIXMAP_CACHE;
168
169    /* Sync */
170    if (pAST->ENGCaps & ENG_CAP_Sync)
171        infoPtr->Sync = ASTSync;
172
173    /* Screen To Screen copy */
174    if (pAST->ENGCaps & ENG_CAP_ScreenToScreenCopy)
175    {
176        infoPtr->SetupForScreenToScreenCopy =  ASTSetupForScreenToScreenCopy;
177        infoPtr->SubsequentScreenToScreenCopy = ASTSubsequentScreenToScreenCopy;
178        infoPtr->ScreenToScreenCopyFlags = NO_TRANSPARENCY | NO_PLANEMASK;
179    }
180
181    /* Solid fill */
182    if (pAST->ENGCaps & ENG_CAP_SolidFill)
183    {
184        infoPtr->SetupForSolidFill = ASTSetupForSolidFill;
185        infoPtr->SubsequentSolidFillRect = ASTSubsequentSolidFillRect;
186        infoPtr->SolidFillFlags = NO_PLANEMASK;
187    }
188
189    /* Solid Lines */
190    if (pAST->ENGCaps & ENG_CAP_SolidLine)
191    {
192        infoPtr->SetupForSolidLine = ASTSetupForSolidLine;
193        infoPtr->SubsequentSolidHorVertLine = ASTSubsequentSolidHorVertLine;
194        infoPtr->SubsequentSolidTwoPointLine = ASTSubsequentSolidTwoPointLine;
195        infoPtr->SolidLineFlags = NO_PLANEMASK;
196    }
197
198    /* Dashed Lines */
199    if (pAST->ENGCaps & ENG_CAP_DashedLine)
200    {
201        infoPtr->SetupForDashedLine = ASTSetupForDashedLine;
202        infoPtr->SubsequentDashedTwoPointLine = ASTSubsequentDashedTwoPointLine;
203        infoPtr->DashPatternMaxLength = 64;
204        infoPtr->DashedLineFlags = NO_PLANEMASK |
205			           LINE_PATTERN_MSBFIRST_LSBJUSTIFIED;
206    }
207
208    /* 8x8 mono pattern fill */
209    if (pAST->ENGCaps & ENG_CAP_Mono8x8PatternFill)
210    {
211        infoPtr->SetupForMono8x8PatternFill = ASTSetupForMonoPatternFill;
212        infoPtr->SubsequentMono8x8PatternFillRect = ASTSubsequentMonoPatternFill;
213        infoPtr->Mono8x8PatternFillFlags = NO_PLANEMASK |
214                                           NO_TRANSPARENCY |
215				           HARDWARE_PATTERN_SCREEN_ORIGIN |
216				           HARDWARE_PATTERN_PROGRAMMED_BITS |
217				           BIT_ORDER_IN_BYTE_MSBFIRST;
218    }
219
220    /* 8x8 color pattern fill */
221    if (pAST->ENGCaps & ENG_CAP_Color8x8PatternFill)
222    {
223        infoPtr->SetupForColor8x8PatternFill = ASTSetupForColor8x8PatternFill;
224        infoPtr->SubsequentColor8x8PatternFillRect = ASTSubsequentColor8x8PatternFillRect;
225        infoPtr->Color8x8PatternFillFlags = NO_PLANEMASK |
226					    NO_TRANSPARENCY |
227	 				    HARDWARE_PATTERN_SCREEN_ORIGIN;
228    }
229
230    /* CPU To Screen Color Expand */
231    if (pAST->ENGCaps & ENG_CAP_CPUToScreenColorExpand)
232    {
233        infoPtr->SetupForCPUToScreenColorExpandFill = ASTSetupForCPUToScreenColorExpandFill;
234        infoPtr->SubsequentCPUToScreenColorExpandFill = ASTSubsequentCPUToScreenColorExpandFill;
235        infoPtr->ColorExpandRange = MAX_PATReg_Size;
236        infoPtr->ColorExpandBase = MMIOREG_PAT;
237        infoPtr->CPUToScreenColorExpandFillFlags = NO_PLANEMASK |
238	   				           BIT_ORDER_IN_BYTE_MSBFIRST;
239    }
240
241    /* Screen To Screen Color Expand */
242    if (pAST->ENGCaps & ENG_CAP_ScreenToScreenColorExpand)
243    {
244        infoPtr->SetupForScreenToScreenColorExpandFill = ASTSetupForScreenToScreenColorExpandFill;
245        infoPtr->SubsequentScreenToScreenColorExpandFill = ASTSubsequentScreenToScreenColorExpandFill;
246        infoPtr->ScreenToScreenColorExpandFillFlags = NO_PLANEMASK |
247	                                              BIT_ORDER_IN_BYTE_MSBFIRST;
248    }
249
250    /* Clipping */
251    if (pAST->ENGCaps & ENG_CAP_Clipping)
252    {
253        infoPtr->SetClippingRectangle = ASTSetClippingRectangle;
254        infoPtr->DisableClipping = ASTDisableClipping;
255        infoPtr->ClippingFlags = HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY 	|
256                		 HARDWARE_CLIP_MONO_8x8_FILL		|
257                		 HARDWARE_CLIP_COLOR_8x8_FILL	 	|
258                		 HARDWARE_CLIP_SOLID_LINE 		|
259                		 HARDWARE_CLIP_DASHED_LINE 		|
260                		 HARDWARE_CLIP_SOLID_LINE;
261    }
262
263    return(XAAInit(pScreen, infoPtr));
264
265} /* end of ASTAccelInit */
266
267
268static void
269ASTSync(ScrnInfoPtr pScrn)
270{
271    ASTRecPtr pAST = ASTPTR(pScrn);
272
273    /* wait engle idle */
274    vWaitEngIdle(pScrn, pAST);
275
276} /* end of ASTSync */
277
278
279static void ASTSetupForScreenToScreenCopy(ScrnInfoPtr pScrn,
280                                          int xdir, int ydir, int rop,
281                                          unsigned int planemask, int trans_color)
282{
283
284    ASTRecPtr pAST = ASTPTR(pScrn);
285    PKT_SC *pSingleCMD;
286    ULONG  cmdreg;
287
288/*
289    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForScreenToScreenCopy\n");
290*/
291    /* Modify Reg. Value */
292    cmdreg = CMD_BITBLT;
293    switch (pAST->VideoModeInfo.bitsPerPixel)
294    {
295    case 8:
296        cmdreg |= CMD_COLOR_08;
297        break;
298    case 15:
299    case 16:
300        cmdreg |= CMD_COLOR_16;
301        break;
302    case 24:
303    case 32:
304        cmdreg |= CMD_COLOR_32;
305        break;
306    }
307    cmdreg |= (ASTXAACopyROP[rop] << 8);
308    pAST->ulCMDReg = cmdreg;
309
310    if (!pAST->MMIO2D)
311    {
312        /* Write to CMDQ */
313        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*2);
314
315        ASTSetupSRCPitch(pSingleCMD, pAST->VideoModeInfo.ScreenPitch);
316        pSingleCMD++;
317        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
318
319        /* Update Write Pointer */
320        mUpdateWritePointer;
321
322    }
323    else
324    {
325        /* Write to MMIO */
326        ASTSetupSRCPitch_MMIO(pAST->VideoModeInfo.ScreenPitch);
327        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
328    }
329
330} /* end of ASTSetupForScreenToScreenCopy */
331
332static void
333ASTSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int x1, int y1, int x2,
334                                int y2, int width, int height)
335{
336    ASTRecPtr pAST = ASTPTR(pScrn);
337    PKT_SC *pSingleCMD;
338    int src_x, src_y, dst_x, dst_y;
339    ULONG srcbase, dstbase, cmdreg;
340    int delta_y = 0;
341/*
342    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentScreenToScreenCopy\n");
343*/
344
345    if ((width != 0) && (height != 0))
346    {
347        /* Modify Reg. Value */
348        cmdreg = pAST->ulCMDReg;
349        if (pAST->EnableClip)
350            cmdreg |= CMD_ENABLE_CLIP;
351        else
352            cmdreg &= ~CMD_ENABLE_CLIP;
353        srcbase = dstbase = 0;
354
355        if (x1 < x2)
356            cmdreg |= CMD_X_DEC;
357
358        if (y1 < y2)
359            cmdreg |= CMD_Y_DEC;
360
361        if ((y1 + height) >= MAX_SRC_Y)
362        {
363            srcbase=pAST->VideoModeInfo.ScreenPitch*y1;
364            y1 = 0;
365        }
366
367        if ((y2 + height) >= pScrn->virtualY)
368        {
369            delta_y = y2;
370            dstbase=pAST->VideoModeInfo.ScreenPitch*y2;
371            y2 = 0;
372        }
373
374        if (cmdreg & CMD_X_DEC)
375        {
376            src_x = x1 + width - 1;
377            dst_x = x2 + width - 1;
378        }
379        else
380        {
381            src_x = x1;
382            dst_x = x2;
383        }
384
385        if (cmdreg & CMD_Y_DEC)
386        {
387            src_y = y1 + height - 1;
388            dst_y = y2 + height - 1;
389        }
390        else
391        {
392            src_y = y1;
393            dst_y = y2;
394        }
395
396        if (pAST->EnableClip)
397            ASTSetHWClipping(pScrn, delta_y);
398
399        if (!pAST->MMIO2D)
400        {
401            /* Write to CMDQ */
402            pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*6);
403
404            ASTSetupSRCBase(pSingleCMD, srcbase);
405            pSingleCMD++;
406            ASTSetupDSTBase(pSingleCMD, dstbase);
407            pSingleCMD++;
408            ASTSetupDSTXY(pSingleCMD, dst_x, dst_y);
409            pSingleCMD++;
410            ASTSetupSRCXY(pSingleCMD, src_x, src_y);
411            pSingleCMD++;
412            ASTSetupRECTXY(pSingleCMD, width, height);
413            pSingleCMD++;
414            ASTSetupCMDReg(pSingleCMD, cmdreg);
415
416            /* Update Write Pointer */
417            mUpdateWritePointer;
418
419        }
420        else
421        {
422            ASTSetupSRCBase_MMIO(srcbase);
423            ASTSetupDSTBase_MMIO(dstbase);
424            ASTSetupDSTXY_MMIO(dst_x, dst_y);
425            ASTSetupSRCXY_MMIO(src_x, src_y);
426            ASTSetupRECTXY_MMIO(width, height);
427            ASTSetupCMDReg_MMIO(cmdreg);
428
429            vWaitEngIdle(pScrn, pAST);
430        }
431
432    } /* width & height check */
433
434} /* end of ASTSubsequentScreenToScreenCopy */
435
436static void
437ASTSetupForSolidFill(ScrnInfoPtr pScrn,
438                     int color, int rop, unsigned int planemask)
439{
440
441    ASTRecPtr pAST = ASTPTR(pScrn);
442    PKT_SC *pSingleCMD;
443    ULONG cmdreg;
444
445/*
446    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForSolidFill\n");
447*/
448    /* Modify Reg. Value */
449    cmdreg = CMD_BITBLT | CMD_PAT_FGCOLOR;
450    switch (pAST->VideoModeInfo.bitsPerPixel)
451    {
452    case 8:
453        cmdreg |= CMD_COLOR_08;
454        break;
455    case 15:
456    case 16:
457        cmdreg |= CMD_COLOR_16;
458        break;
459    case 24:
460    case 32:
461        cmdreg |= CMD_COLOR_32;
462        break;
463    }
464    cmdreg |= (ASTXAAPatternROP[rop] << 8);
465    pAST->ulCMDReg = cmdreg;
466
467    if (!pAST->MMIO2D)
468    {
469        /* Write to CMDQ */
470        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*2);
471
472        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
473        pSingleCMD++;
474        ASTSetupFG(pSingleCMD, color);
475
476        /* Update Write Pointer */
477        mUpdateWritePointer;
478
479    }
480    else
481    {
482        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
483        ASTSetupFG_MMIO(color);
484    }
485
486} /* end of ASTSetupForSolidFill */
487
488
489static void
490ASTSubsequentSolidFillRect(ScrnInfoPtr pScrn,
491                           int dst_x, int dst_y, int width, int height)
492{
493    ASTRecPtr pAST = ASTPTR(pScrn);
494    PKT_SC *pSingleCMD;
495    ULONG dstbase, cmdreg;
496    int delta_y = 0;
497
498/*
499    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentSolidFillRect\n");
500*/
501
502    if ((width != 0) && (height != 0))
503    {
504        /* Modify Reg. Value */
505        cmdreg = pAST->ulCMDReg;
506        if (pAST->EnableClip)
507            cmdreg |= CMD_ENABLE_CLIP;
508        else
509            cmdreg &= ~CMD_ENABLE_CLIP;
510        dstbase = 0;
511
512        if (dst_y >= pScrn->virtualY)
513        {
514            delta_y = dst_y;
515            dstbase=pAST->VideoModeInfo.ScreenPitch*dst_y;
516            dst_y=0;
517        }
518
519        if (pAST->EnableClip)
520            ASTSetHWClipping(pScrn, delta_y);
521
522        if (!pAST->MMIO2D)
523        {
524            /* Write to CMDQ */
525            pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*4);
526
527            ASTSetupDSTBase(pSingleCMD, dstbase);
528            pSingleCMD++;
529            ASTSetupDSTXY(pSingleCMD, dst_x, dst_y);
530            pSingleCMD++;
531            ASTSetupRECTXY(pSingleCMD, width, height);
532            pSingleCMD++;
533            ASTSetupCMDReg(pSingleCMD, cmdreg);
534
535            /* Update Write Pointer */
536            mUpdateWritePointer;
537
538        }
539        else
540        {
541            ASTSetupDSTBase_MMIO(dstbase);
542            ASTSetupDSTXY_MMIO(dst_x, dst_y);
543            ASTSetupRECTXY_MMIO(width, height);
544            ASTSetupCMDReg_MMIO(cmdreg);
545
546            vWaitEngIdle(pScrn, pAST);
547
548        }
549
550    } /* width & height check */
551
552
553} /* end of ASTSubsequentSolidFillRect */
554
555/* Line */
556static void ASTSetupForSolidLine(ScrnInfoPtr pScrn,
557                                 int color, int rop, unsigned int planemask)
558{
559
560    ASTRecPtr pAST = ASTPTR(pScrn);
561    PKT_SC *pSingleCMD;
562    ULONG  cmdreg;
563/*
564    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForSolidLine\n");
565*/
566    /* Modify Reg. Value */
567    cmdreg = CMD_BITBLT;
568    switch (pAST->VideoModeInfo.bitsPerPixel)
569    {
570    case 8:
571        cmdreg |= CMD_COLOR_08;
572        break;
573    case 15:
574    case 16:
575        cmdreg |= CMD_COLOR_16;
576        break;
577    case 24:
578    case 32:
579        cmdreg |= CMD_COLOR_32;
580        break;
581    }
582    cmdreg |= (ASTXAAPatternROP[rop] << 8);
583    pAST->ulCMDReg = cmdreg;
584
585    if (!pAST->MMIO2D)
586    {
587        /* Write to CMDQ */
588        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*3);
589
590        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
591        pSingleCMD++;
592        ASTSetupFG(pSingleCMD, color);
593        pSingleCMD++;
594        ASTSetupBG(pSingleCMD, 0);
595
596        /* Update Write Pointer */
597        mUpdateWritePointer;
598
599    }
600    else
601    {
602        /* Write to MMIO */
603        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
604        ASTSetupFG_MMIO(color);
605        ASTSetupBG_MMIO(0);
606    }
607
608} /* end of ASTSetupForSolidLine */
609
610
611static void ASTSubsequentSolidHorVertLine(ScrnInfoPtr pScrn,
612                                          int x, int y, int len, int dir)
613{
614
615    ASTRecPtr pAST = ASTPTR(pScrn);
616    PKT_SC *pSingleCMD;
617    ULONG dstbase, cmdreg;
618    int width, height;
619    int delta_y = 0;
620/*
621    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentSolidHorVertLine\n");
622*/
623
624    if (len != 0)
625    {
626        /* Modify Reg. Value */
627        cmdreg = (pAST->ulCMDReg & (~CMD_MASK)) | CMD_BITBLT;
628        if (pAST->EnableClip)
629            cmdreg |= CMD_ENABLE_CLIP;
630        else
631            cmdreg &= ~CMD_ENABLE_CLIP;
632        dstbase = 0;
633
634        if(dir == DEGREES_0) {			/* horizontal */
635            width  = len;
636            height = 1;
637        } else {					/* vertical */
638            width  = 1;
639            height = len;
640        }
641
642        if ((y + height) >= pScrn->virtualY)
643        {
644            delta_y = y;
645            dstbase=pAST->VideoModeInfo.ScreenPitch*y;
646            y=0;
647        }
648
649        if (pAST->EnableClip)
650            ASTSetHWClipping(pScrn, delta_y);
651
652        if (!pAST->MMIO2D)
653        {
654            /* Write to CMDQ */
655            pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*4);
656
657            ASTSetupDSTBase(pSingleCMD, dstbase);
658            pSingleCMD++;
659            ASTSetupDSTXY(pSingleCMD, x, y);
660            pSingleCMD++;
661            ASTSetupRECTXY(pSingleCMD, width, height);
662            pSingleCMD++;
663            ASTSetupCMDReg(pSingleCMD, cmdreg);
664
665            /* Update Write Pointer */
666            mUpdateWritePointer;
667
668        }
669        else
670        {
671            ASTSetupDSTBase_MMIO(dstbase);
672            ASTSetupDSTXY_MMIO(x, y);
673            ASTSetupRECTXY_MMIO(width, height);
674            ASTSetupCMDReg_MMIO(cmdreg);
675
676            vWaitEngIdle(pScrn, pAST);
677
678        }
679
680    } /* len check */
681
682} /* end of ASTSubsequentSolidHorVertLine */
683
684static void ASTSubsequentSolidTwoPointLine(ScrnInfoPtr pScrn,
685                                           int x1, int y1, int x2, int y2, int flags)
686{
687
688    ASTRecPtr 	pAST = ASTPTR(pScrn);
689    PKT_SC 	*pSingleCMD;
690    LINEPARAM   dsLineParam;
691    _LINEInfo   LineInfo;
692    ULONG 	dstbase, ulCommand;
693    ULONG	miny, maxy;
694    USHORT      usXM;
695    int delta_y = 0;
696
697/*
698    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentSolidTwoPointLine\n");
699*/
700
701    /* Modify Reg. Value */
702    ulCommand = (pAST->ulCMDReg & (~CMD_MASK)) | CMD_LINEDRAW;
703    if(flags & OMIT_LAST)
704        ulCommand |= CMD_NOT_DRAW_LAST_PIXEL;
705    else
706        ulCommand &= ~CMD_NOT_DRAW_LAST_PIXEL;
707    if (pAST->EnableClip)
708        ulCommand |= CMD_ENABLE_CLIP;
709    else
710        ulCommand &= ~CMD_ENABLE_CLIP;
711    dstbase = 0;
712    miny = (y1 > y2) ? y2 : y1;
713    maxy = (y1 > y2) ? y1 : y2;
714    if(maxy >= pScrn->virtualY) {
715    	delta_y = miny;
716        dstbase = pAST->VideoModeInfo.ScreenPitch * miny;
717        y1 -= miny;
718        y2 -= miny;
719    }
720
721    LineInfo.X1 = x1;
722    LineInfo.Y1 = y1;
723    LineInfo.X2 = x2;
724    LineInfo.Y2 = y2;
725
726    bGetLineTerm(&LineInfo, &dsLineParam);		/* Get Line Parameter */
727
728    if (dsLineParam.dwLineAttributes & LINEPARAM_X_DEC)
729        ulCommand |= CMD_X_DEC;
730    if (dsLineParam.dwLineAttributes & LINEPARAM_Y_DEC)
731        ulCommand |= CMD_Y_DEC;
732
733    usXM = (dsLineParam.dwLineAttributes & LINEPARAM_XM) ? 1:0;
734
735    if (pAST->EnableClip)
736        ASTSetHWClipping(pScrn, delta_y);
737
738    if (!pAST->MMIO2D)
739    {
740        /* Write to CMDQ */
741        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*7);
742
743        ASTSetupDSTBase(pSingleCMD, dstbase);
744        pSingleCMD++;
745        ASTSetupLineXY(pSingleCMD, dsLineParam.dsLineX, dsLineParam.dsLineY);
746        pSingleCMD++;
747        ASTSetupLineXMErrTerm(pSingleCMD, usXM , dsLineParam.dwErrorTerm);
748        pSingleCMD++;
749        ASTSetupLineWidth(pSingleCMD, dsLineParam.dsLineWidth);
750        pSingleCMD++;
751        ASTSetupLineK1Term(pSingleCMD, dsLineParam.dwK1Term);
752        pSingleCMD++;
753        ASTSetupLineK2Term(pSingleCMD, dsLineParam.dwK2Term);
754        pSingleCMD++;
755        ASTSetupCMDReg(pSingleCMD, ulCommand);
756
757        /* Update Write Pointer */
758        mUpdateWritePointer;
759
760        /* Patch KDE pass abnormal point, ycchen@052507 */
761        vWaitEngIdle(pScrn, pAST);
762
763    }
764    else
765    {
766        ASTSetupDSTBase_MMIO(dstbase);
767        ASTSetupLineXY_MMIO(dsLineParam.dsLineX, dsLineParam.dsLineY);
768        ASTSetupLineXMErrTerm_MMIO( usXM , dsLineParam.dwErrorTerm);
769        ASTSetupLineWidth_MMIO(dsLineParam.dsLineWidth);
770        ASTSetupLineK1Term_MMIO(dsLineParam.dwK1Term);
771        ASTSetupLineK2Term_MMIO(dsLineParam.dwK2Term);
772        ASTSetupCMDReg_MMIO(ulCommand);
773
774        vWaitEngIdle(pScrn, pAST);
775
776    }
777
778
779} /* end of ASTSubsequentSolidTwoPointLine */
780
781/* Dash Line */
782static void
783ASTSetupForDashedLine(ScrnInfoPtr pScrn,
784                      int fg, int bg, int rop, unsigned int planemask,
785                      int length, UCHAR *pattern)
786{
787
788    ASTRecPtr pAST = ASTPTR(pScrn);
789    PKT_SC *pSingleCMD;
790    ULONG  cmdreg;
791/*
792    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForDashedLine\n");
793*/
794    /* Modify Reg. Value */
795    cmdreg = CMD_LINEDRAW | CMD_RESET_STYLE_COUNTER | CMD_ENABLE_LINE_STYLE;
796
797    switch (pAST->VideoModeInfo.bitsPerPixel)
798    {
799    case 8:
800        cmdreg |= CMD_COLOR_08;
801        break;
802    case 15:
803    case 16:
804        cmdreg |= CMD_COLOR_16;
805        break;
806    case 24:
807    case 32:
808        cmdreg |= CMD_COLOR_32;
809        break;
810    }
811    cmdreg |= (ASTXAAPatternROP[rop] << 8);
812    if(bg == -1) {
813        cmdreg |= CMD_TRANSPARENT;
814        bg = 0;
815    }
816    cmdreg |= (((length-1) & 0x3F) << 24);		/* line period */
817    pAST->ulCMDReg = cmdreg;
818
819    if (!pAST->MMIO2D)
820    {
821        /* Write to CMDQ */
822        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*5);
823
824        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
825        pSingleCMD++;
826        ASTSetupFG(pSingleCMD, fg);
827        pSingleCMD++;
828        ASTSetupBG(pSingleCMD, bg);
829        pSingleCMD++;
830        ASTSetupLineStyle1(pSingleCMD, *pattern);
831        pSingleCMD++;
832        ASTSetupLineStyle2(pSingleCMD, *(pattern+4));
833
834        /* Update Write Pointer */
835        mUpdateWritePointer;
836
837    }
838    else
839    {
840        /* Write to MMIO */
841        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
842        ASTSetupFG_MMIO(fg);
843        ASTSetupBG_MMIO(bg);
844        ASTSetupLineStyle1_MMIO(*pattern);
845        ASTSetupLineStyle2_MMIO(*(pattern+4));
846
847    }
848
849}
850
851static void
852ASTSubsequentDashedTwoPointLine(ScrnInfoPtr pScrn,
853                                int x1, int y1, int x2, int y2,
854                                int flags, int phase)
855{
856
857    ASTRecPtr 	pAST = ASTPTR(pScrn);
858    PKT_SC 	*pSingleCMD;
859    LINEPARAM   dsLineParam;
860    _LINEInfo   LineInfo;
861    ULONG 	dstbase, ulCommand;
862    ULONG	miny, maxy;
863    USHORT      usXM;
864    int delta_y = 0;
865
866/*
867    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentDashedTwoPointLine\n");
868*/
869
870    /* Modify Reg. Value */
871    ulCommand = pAST->ulCMDReg;
872    if(flags & OMIT_LAST)
873        ulCommand |= CMD_NOT_DRAW_LAST_PIXEL;
874    else
875        ulCommand &= ~CMD_NOT_DRAW_LAST_PIXEL;
876    if (pAST->EnableClip)
877        ulCommand |= CMD_ENABLE_CLIP;
878    else
879        ulCommand &= ~CMD_ENABLE_CLIP;
880    dstbase = 0;
881    miny = (y1 > y2) ? y2 : y1;
882    maxy = (y1 > y2) ? y1 : y2;
883    if(maxy >= pScrn->virtualY) {
884    	delta_y = miny;
885        dstbase = pAST->VideoModeInfo.ScreenPitch * miny;
886        y1 -= miny;
887        y2 -= miny;
888    }
889
890    LineInfo.X1 = x1;
891    LineInfo.Y1 = y1;
892    LineInfo.X2 = x2;
893    LineInfo.Y2 = y2;
894
895    bGetLineTerm(&LineInfo, &dsLineParam);		/* Get Line Parameter */
896
897    if (dsLineParam.dwLineAttributes & LINEPARAM_X_DEC)
898        ulCommand |= CMD_X_DEC;
899    if (dsLineParam.dwLineAttributes & LINEPARAM_Y_DEC)
900        ulCommand |= CMD_Y_DEC;
901
902    usXM = (dsLineParam.dwLineAttributes & LINEPARAM_XM) ? 1:0;
903
904    if (pAST->EnableClip)
905        ASTSetHWClipping(pScrn, delta_y);
906
907    if (!pAST->MMIO2D)
908    {
909        /* Write to CMDQ */
910        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*7);
911
912        ASTSetupDSTBase(pSingleCMD, dstbase);
913        pSingleCMD++;
914        ASTSetupLineXY(pSingleCMD, dsLineParam.dsLineX, dsLineParam.dsLineY);
915        pSingleCMD++;
916        ASTSetupLineXMErrTerm(pSingleCMD, usXM , dsLineParam.dwErrorTerm);
917        pSingleCMD++;
918        ASTSetupLineWidth(pSingleCMD, dsLineParam.dsLineWidth);
919        pSingleCMD++;
920        ASTSetupLineK1Term(pSingleCMD, dsLineParam.dwK1Term);
921        pSingleCMD++;
922        ASTSetupLineK2Term(pSingleCMD, dsLineParam.dwK2Term);
923        pSingleCMD++;
924        ASTSetupCMDReg(pSingleCMD, ulCommand);
925
926        /* Update Write Pointer */
927        mUpdateWritePointer;
928
929        /* Patch KDE pass abnormal point, ycchen@052507 */
930        vWaitEngIdle(pScrn, pAST);
931
932    }
933    else
934    {
935        ASTSetupDSTBase_MMIO(dstbase);
936        ASTSetupLineXY_MMIO(dsLineParam.dsLineX, dsLineParam.dsLineY);
937        ASTSetupLineXMErrTerm_MMIO( usXM , dsLineParam.dwErrorTerm);
938        ASTSetupLineWidth_MMIO(dsLineParam.dsLineWidth);
939        ASTSetupLineK1Term_MMIO(dsLineParam.dwK1Term);
940        ASTSetupLineK2Term_MMIO(dsLineParam.dwK2Term);
941        ASTSetupCMDReg_MMIO(ulCommand);
942
943        vWaitEngIdle(pScrn, pAST);
944
945    }
946
947}
948
949/* Mono Pattern Fill */
950static void
951ASTSetupForMonoPatternFill(ScrnInfoPtr pScrn,
952                           int patx, int paty, int fg, int bg,
953                           int rop, unsigned int planemask)
954{
955
956    ASTRecPtr pAST = ASTPTR(pScrn);
957    PKT_SC *pSingleCMD;
958    ULONG cmdreg;
959
960/*
961    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForMonoPatternFill\n");
962*/
963    /* Modify Reg. Value */
964    cmdreg = CMD_BITBLT | CMD_PAT_MONOMASK;
965    switch (pAST->VideoModeInfo.bitsPerPixel)
966    {
967    case 8:
968        cmdreg |= CMD_COLOR_08;
969        break;
970    case 15:
971    case 16:
972        cmdreg |= CMD_COLOR_16;
973        break;
974    case 24:
975    case 32:
976        cmdreg |= CMD_COLOR_32;
977        break;
978    }
979    cmdreg |= (ASTXAAPatternROP[rop] << 8);
980    pAST->ulCMDReg = cmdreg;
981
982    if (!pAST->MMIO2D)
983    {
984        /* Write to CMDQ */
985        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*5);
986
987        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
988        pSingleCMD++;
989        ASTSetupFG(pSingleCMD, fg);
990        pSingleCMD++;
991        ASTSetupBG(pSingleCMD, bg);
992        pSingleCMD++;
993        ASTSetupMONO1(pSingleCMD, patx);
994        pSingleCMD++;
995        ASTSetupMONO2(pSingleCMD, paty);
996
997        /* Update Write Pointer */
998        mUpdateWritePointer;
999
1000    }
1001    else
1002    {
1003        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
1004        ASTSetupFG_MMIO(fg);
1005        ASTSetupBG_MMIO(bg);
1006        ASTSetupMONO1_MMIO(patx);
1007        ASTSetupMONO2_MMIO(paty);
1008    }
1009
1010} /* end of ASTSetupForMonoPatternFill */
1011
1012
1013static void
1014ASTSubsequentMonoPatternFill(ScrnInfoPtr pScrn,
1015                             int patx, int paty,
1016                             int dst_x, int dst_y, int width, int height)
1017{
1018    ASTRecPtr pAST = ASTPTR(pScrn);
1019    PKT_SC *pSingleCMD;
1020    ULONG dstbase, cmdreg;
1021    int delta_y = 0;
1022
1023/*
1024    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentMonoPatternFill\n");
1025*/
1026
1027    /* Modify Reg. Value */
1028    cmdreg = pAST->ulCMDReg;
1029    if (pAST->EnableClip)
1030        cmdreg |= CMD_ENABLE_CLIP;
1031    else
1032        cmdreg &= ~CMD_ENABLE_CLIP;
1033    dstbase = 0;
1034
1035    if (dst_y >= pScrn->virtualY)
1036    {
1037    	delta_y = dst_y;
1038        dstbase=pAST->VideoModeInfo.ScreenPitch*dst_y;
1039        dst_y=0;
1040    }
1041
1042    if (pAST->EnableClip)
1043        ASTSetHWClipping(pScrn, delta_y);
1044
1045    if (!pAST->MMIO2D)
1046    {
1047        /* Write to CMDQ */
1048        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*4);
1049
1050        ASTSetupDSTBase(pSingleCMD, dstbase);
1051        pSingleCMD++;
1052        ASTSetupDSTXY(pSingleCMD, dst_x, dst_y);
1053        pSingleCMD++;
1054        ASTSetupRECTXY(pSingleCMD, width, height);
1055        pSingleCMD++;
1056        ASTSetupCMDReg(pSingleCMD, cmdreg);
1057
1058        /* Update Write Pointer */
1059        mUpdateWritePointer;
1060
1061    }
1062    else
1063    {
1064        ASTSetupDSTBase_MMIO(dstbase);
1065        ASTSetupDSTXY_MMIO(dst_x, dst_y);
1066        ASTSetupRECTXY_MMIO(width, height);
1067        ASTSetupCMDReg_MMIO(cmdreg);
1068
1069        vWaitEngIdle(pScrn, pAST);
1070    }
1071
1072} /* end of ASTSubsequentMonoPatternFill */
1073
1074static void
1075ASTSetupForColor8x8PatternFill(ScrnInfoPtr pScrn, int patx, int paty,
1076			       int rop, unsigned int planemask, int trans_col)
1077{
1078
1079    ASTRecPtr pAST = ASTPTR(pScrn);
1080    PKT_SC *pSingleCMD;
1081    ULONG cmdreg;
1082    CARD32 *pataddr;
1083    ULONG ulPatSize;
1084    int i, j, cpp;
1085/*
1086    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForColor8x8PatternFill\n");
1087*/
1088    /* Modify Reg. Value */
1089    cmdreg = CMD_BITBLT | CMD_PAT_PATREG;
1090    switch (pAST->VideoModeInfo.bitsPerPixel)
1091    {
1092    case 8:
1093        cmdreg |= CMD_COLOR_08;
1094        break;
1095    case 15:
1096    case 16:
1097        cmdreg |= CMD_COLOR_16;
1098        break;
1099    case 24:
1100    case 32:
1101        cmdreg |= CMD_COLOR_32;
1102        break;
1103    }
1104    cmdreg |= (ASTXAAPatternROP[rop] << 8);
1105    pAST->ulCMDReg = cmdreg;
1106    cpp = (pScrn->bitsPerPixel + 1) / 8;
1107    pataddr = (CARD32 *)(pAST->FBVirtualAddr +
1108                        (paty * pAST->VideoModeInfo.ScreenWidth) + (patx * cpp));
1109    ulPatSize = 8*8*cpp;
1110
1111    if (!pAST->MMIO2D)
1112    {
1113        /* Write to CMDQ */
1114        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*(1 + ulPatSize/4));
1115        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
1116        pSingleCMD++;
1117        for (i=0; i<8; i++)
1118        {
1119            for (j=0; j<8*cpp/4; j++)
1120            {
1121                ASTSetupPatReg(pSingleCMD, (i*j + j) , (*(CARD32 *) (pataddr++)));
1122                pSingleCMD++;
1123            }
1124        }
1125
1126        /* Update Write Pointer */
1127        mUpdateWritePointer;
1128
1129    }
1130    else
1131    {
1132        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
1133        for (i=0; i<8; i++)
1134        {
1135            for (j=0; j<8*cpp/4; j++)
1136            {
1137                ASTSetupPatReg_MMIO((i*j + j) , (*(CARD32 *) (pataddr++)));
1138            }
1139        }
1140
1141    }
1142
1143} /* end of ASTSetupForColor8x8PatternFill */
1144
1145static void
1146ASTSubsequentColor8x8PatternFillRect(ScrnInfoPtr pScrn, int patx, int paty,
1147                                     int dst_x, int dst_y, int width, int height)
1148{
1149    ASTRecPtr pAST = ASTPTR(pScrn);
1150    PKT_SC *pSingleCMD;
1151    ULONG dstbase, cmdreg;
1152    int delta_y = 0;
1153
1154/*
1155    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentColor8x8PatternFillRect\n");
1156*/
1157
1158    /* Modify Reg. Value */
1159    cmdreg = pAST->ulCMDReg;
1160    if (pAST->EnableClip)
1161        cmdreg |= CMD_ENABLE_CLIP;
1162    else
1163        cmdreg &= ~CMD_ENABLE_CLIP;
1164    dstbase = 0;
1165
1166    if (dst_y >= pScrn->virtualY)
1167    {
1168    	delta_y = dst_y;
1169        dstbase=pAST->VideoModeInfo.ScreenPitch*dst_y;
1170        dst_y=0;
1171    }
1172
1173    if (pAST->EnableClip)
1174        ASTSetHWClipping(pScrn, delta_y);
1175
1176    if (!pAST->MMIO2D)
1177    {
1178        /* Write to CMDQ */
1179        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*4);
1180
1181        ASTSetupDSTBase(pSingleCMD, dstbase);
1182        pSingleCMD++;
1183        ASTSetupDSTXY(pSingleCMD, dst_x, dst_y);
1184        pSingleCMD++;
1185        ASTSetupRECTXY(pSingleCMD, width, height);
1186        pSingleCMD++;
1187        ASTSetupCMDReg(pSingleCMD, cmdreg);
1188
1189        /* Update Write Pointer */
1190        mUpdateWritePointer;
1191
1192    }
1193    else
1194    {
1195        ASTSetupDSTBase_MMIO(dstbase);
1196        ASTSetupDSTXY_MMIO(dst_x, dst_y);
1197        ASTSetupRECTXY_MMIO(width, height);
1198        ASTSetupCMDReg_MMIO(cmdreg);
1199
1200        vWaitEngIdle(pScrn, pAST);
1201    }
1202
1203} /* ASTSubsequentColor8x8PatternFillRect */
1204
1205/* CPU to Screen Expand */
1206static void
1207ASTSetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
1208                                      int fg, int bg,
1209                                      int rop, unsigned int planemask)
1210{
1211
1212    ASTRecPtr pAST = ASTPTR(pScrn);
1213    PKT_SC *pSingleCMD;
1214    ULONG cmdreg;
1215
1216/*
1217    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForCPUToScreenColorExpandFill\n");
1218*/
1219    /* Modify Reg. Value */
1220    cmdreg = CMD_COLOREXP;
1221    switch (pAST->VideoModeInfo.bitsPerPixel)
1222    {
1223    case 8:
1224        cmdreg |= CMD_COLOR_08;
1225        break;
1226    case 15:
1227    case 16:
1228        cmdreg |= CMD_COLOR_16;
1229        break;
1230    case 24:
1231    case 32:
1232        cmdreg |= CMD_COLOR_32;
1233        break;
1234    }
1235    cmdreg |= (ASTXAAPatternROP[rop] << 8);
1236    if(bg == -1) {
1237        cmdreg |= CMD_FONT_TRANSPARENT;
1238        bg = 0;
1239    }
1240    pAST->ulCMDReg = cmdreg;
1241
1242    if (!pAST->MMIO2D)
1243    {
1244        /* Write to CMDQ */
1245        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*3);
1246
1247        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
1248        pSingleCMD++;
1249        ASTSetupFG(pSingleCMD, fg);
1250        pSingleCMD++;
1251        ASTSetupBG(pSingleCMD, bg);
1252
1253        /* Update Write Pointer */
1254        mUpdateWritePointer;
1255
1256    }
1257    else
1258    {
1259        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
1260        ASTSetupFG_MMIO(fg);
1261        ASTSetupBG_MMIO(bg);
1262
1263    }
1264
1265}
1266
1267static void
1268ASTSubsequentCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
1269                                        int dst_x, int dst_y,
1270                                        int width, int height, int offset)
1271{
1272
1273    ASTRecPtr pAST = ASTPTR(pScrn);
1274    PKT_SC *pSingleCMD;
1275    ULONG dstbase, cmdreg;
1276    int delta_y = 0;
1277
1278/*
1279    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentCPUToScreenColorExpandFill\n");
1280*/
1281
1282    /* Modify Reg. Value */
1283    cmdreg = pAST->ulCMDReg;
1284    if (pAST->EnableClip)
1285        cmdreg |= CMD_ENABLE_CLIP;
1286    else
1287        cmdreg &= ~CMD_ENABLE_CLIP;
1288    dstbase = 0;
1289
1290    if (dst_y >= pScrn->virtualY)
1291    {
1292    	delta_y = dst_y;
1293        dstbase=pAST->VideoModeInfo.ScreenPitch*dst_y;
1294        dst_y=0;
1295    }
1296
1297    if (pAST->EnableClip)
1298        ASTSetHWClipping(pScrn, delta_y);
1299
1300    if (!pAST->MMIO2D)
1301    {
1302        /* Write to CMDQ */
1303        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*5);
1304
1305        ASTSetupSRCPitch(pSingleCMD, ((width+7)/8));
1306        pSingleCMD++;
1307        ASTSetupDSTBase(pSingleCMD, dstbase);
1308        pSingleCMD++;
1309        ASTSetupDSTXY(pSingleCMD, dst_x, dst_y);
1310        pSingleCMD++;
1311        ASTSetupRECTXY(pSingleCMD, width, height);
1312        pSingleCMD++;
1313        ASTSetupCMDReg(pSingleCMD, cmdreg);
1314
1315        /* Update Write Pointer */
1316        mUpdateWritePointer;
1317
1318    }
1319    else
1320    {
1321        ASTSetupSRCPitch_MMIO((width+7)/8);
1322        ASTSetupDSTBase_MMIO(dstbase);
1323        ASTSetupDSTXY_MMIO(dst_x, dst_y);
1324        ASTSetupSRCXY_MMIO(0, 0);
1325
1326        ASTSetupRECTXY_MMIO(width, height);
1327        ASTSetupCMDReg_MMIO(cmdreg);
1328
1329        vWaitEngIdle(pScrn, pAST);
1330
1331    }
1332
1333}
1334
1335
1336/* Screen to Screen Color Expand */
1337static void
1338ASTSetupForScreenToScreenColorExpandFill(ScrnInfoPtr pScrn,
1339                                         int fg, int bg,
1340                                         int rop, unsigned int planemask)
1341{
1342
1343    ASTRecPtr pAST = ASTPTR(pScrn);
1344    PKT_SC *pSingleCMD;
1345    ULONG cmdreg;
1346
1347/*
1348    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetupForScreenToScreenColorExpandFill\n");
1349*/
1350
1351    /* Modify Reg. Value */
1352    cmdreg = CMD_ENHCOLOREXP;
1353    switch (pAST->VideoModeInfo.bitsPerPixel)
1354    {
1355    case 8:
1356        cmdreg |= CMD_COLOR_08;
1357        break;
1358    case 15:
1359    case 16:
1360        cmdreg |= CMD_COLOR_16;
1361        break;
1362    case 24:
1363    case 32:
1364        cmdreg |= CMD_COLOR_32;
1365        break;
1366    }
1367    cmdreg |= (ASTXAAPatternROP[rop] << 8);
1368    if(bg == -1) {
1369        cmdreg |= CMD_FONT_TRANSPARENT;
1370        bg = 0;
1371    }
1372    pAST->ulCMDReg = cmdreg;
1373
1374    if (!pAST->MMIO2D)
1375    {
1376        /* Write to CMDQ */
1377        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*3);
1378
1379        ASTSetupDSTPitchHeight(pSingleCMD, pAST->VideoModeInfo.ScreenPitch, -1);
1380        pSingleCMD++;
1381        ASTSetupFG(pSingleCMD, fg);
1382        pSingleCMD++;
1383        ASTSetupBG(pSingleCMD, bg);
1384
1385        /* Update Write Pointer */
1386        mUpdateWritePointer;
1387
1388    }
1389    else
1390    {
1391        ASTSetupDSTPitchHeight_MMIO(pAST->VideoModeInfo.ScreenPitch, -1);
1392        ASTSetupFG_MMIO(fg);
1393        ASTSetupBG_MMIO(bg);
1394
1395    }
1396
1397}
1398
1399
1400
1401static void
1402ASTSubsequentScreenToScreenColorExpandFill(ScrnInfoPtr pScrn,
1403                                           int dst_x, int dst_y, int width, int height,
1404                                           int src_x, int src_y, int offset)
1405{
1406   ASTRecPtr pAST = ASTPTR(pScrn);
1407    PKT_SC *pSingleCMD;
1408    ULONG srcbase, dstbase, cmdreg;
1409    USHORT srcpitch;
1410    int delta_y = 0;
1411
1412/*
1413    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSubsequentScreenToScreenColorExpandFill\n");
1414*/
1415
1416    /* Modify Reg. Value */
1417    cmdreg = pAST->ulCMDReg;
1418    if (pAST->EnableClip)
1419        cmdreg |= CMD_ENABLE_CLIP;
1420    else
1421        cmdreg &= ~CMD_ENABLE_CLIP;
1422    dstbase = 0;
1423    if (dst_y >= pScrn->virtualY)
1424    {
1425    	delta_y = dst_y;
1426        dstbase=pAST->VideoModeInfo.ScreenPitch*dst_y;
1427        dst_y=0;
1428    }
1429    srcbase = pAST->VideoModeInfo.ScreenPitch*src_y + ((pScrn->bitsPerPixel+1)/8)*src_x;
1430    srcpitch = (pScrn->displayWidth+7)/8;
1431
1432    if (pAST->EnableClip)
1433        ASTSetHWClipping(pScrn, delta_y);
1434
1435    if (!pAST->MMIO2D)
1436    {
1437        /* Write to CMDQ */
1438        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*6);
1439
1440        ASTSetupSRCBase(pSingleCMD, srcbase);
1441        pSingleCMD++;
1442        ASTSetupSRCPitch(pSingleCMD,srcpitch);
1443        pSingleCMD++;
1444        ASTSetupDSTBase(pSingleCMD, dstbase);
1445        pSingleCMD++;
1446        ASTSetupDSTXY(pSingleCMD, dst_x, dst_y);
1447        pSingleCMD++;
1448        ASTSetupRECTXY(pSingleCMD, width, height);
1449        pSingleCMD++;
1450        ASTSetupCMDReg(pSingleCMD, cmdreg);
1451
1452        /* Update Write Pointer */
1453        mUpdateWritePointer;
1454
1455    }
1456    else
1457    {
1458        ASTSetupSRCBase_MMIO(srcbase);
1459        ASTSetupSRCPitch_MMIO(srcpitch);
1460        ASTSetupDSTBase_MMIO(dstbase);
1461        ASTSetupDSTXY_MMIO(dst_x, dst_y);
1462        ASTSetupRECTXY_MMIO(width, height);
1463        ASTSetupCMDReg_MMIO(cmdreg);
1464
1465        vWaitEngIdle(pScrn, pAST);
1466
1467    }
1468
1469}
1470
1471
1472/* Clipping */
1473static void
1474ASTSetHWClipping(ScrnInfoPtr pScrn, int delta_y)
1475{
1476    ASTRecPtr pAST = ASTPTR(pScrn);
1477    PKT_SC *pSingleCMD;
1478
1479    if (!pAST->MMIO2D)
1480    {
1481        /* Write to CMDQ */
1482        pSingleCMD = (PKT_SC *) pjRequestCMDQ(pAST, PKT_SINGLE_LENGTH*2);
1483
1484        ASTSetupCLIP1(pSingleCMD, pAST->clip_left, pAST->clip_top - delta_y);
1485        pSingleCMD++;
1486        ASTSetupCLIP2(pSingleCMD, pAST->clip_right + 1, pAST->clip_bottom - delta_y + 1);
1487
1488        /* Update Write Pointer */
1489        mUpdateWritePointer;
1490
1491    }
1492    else
1493    {
1494        ASTSetupCLIP1_MMIO(pAST->clip_left, pAST->clip_top - delta_y);
1495        ASTSetupCLIP2_MMIO(pAST->clip_right + 1, pAST->clip_bottom - delta_y + 1);
1496    }
1497
1498}
1499
1500static void
1501ASTSetClippingRectangle(ScrnInfoPtr pScrn,
1502                        int left, int top, int right, int bottom)
1503{
1504
1505    ASTRecPtr pAST = ASTPTR(pScrn);
1506    PKT_SC *pSingleCMD;
1507/*
1508    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTSetClippingRectangle\n");
1509*/
1510    pAST->EnableClip = TRUE;
1511
1512    pAST->clip_left   = left;
1513    pAST->clip_top    = top;
1514    pAST->clip_right  = right;
1515    pAST->clip_bottom = bottom;
1516
1517}
1518
1519static void
1520ASTDisableClipping(ScrnInfoPtr pScrn)
1521{
1522    ASTRecPtr pAST = ASTPTR(pScrn);
1523/*
1524    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ASTDisableClipping\n");
1525*/
1526    pAST->EnableClip = FALSE;
1527}
1528
1529#endif	/* end of Accel_2D */
1530