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