Unichrome DRI:
authorThomas Hellström <thomas@tungstengraphics.com>
Wed, 15 Dec 2004 21:59:25 +0000 (21:59 +0000)
committerThomas Hellström <thomas@tungstengraphics.com>
Wed, 15 Dec 2004 21:59:25 +0000 (21:59 +0000)
Updated the driver to the new VIA security mechanisms in DRM. All command
submissions now passes through DRM ioctls. If the DRM AGP ring-buffer is
not enabled, it will use a DRM mechanism for submitting commands to the
hardware via a PCI bus mechanism.

Removed all direct write accesses to the hardware. Among other things the
VQ was previously turned off for the PCI path, apparently for Tuxracer.
That seemed unneeded and was removed. No visible impact on Tuxracer.

Abstracted all buffer blit operations in via_ioctl.c. The blitter context
is now reprogrammed before each blitting operation.

Updated driver date and drm version requirement.
(Bugzilla Bug #1950, Thomas Hellström)

src/mesa/drivers/dri/unichrome/via_context.c
src/mesa/drivers/dri/unichrome/via_context.h
src/mesa/drivers/dri/unichrome/via_fb.c
src/mesa/drivers/dri/unichrome/via_ioctl.c
src/mesa/drivers/dri/unichrome/via_render.c
src/mesa/drivers/dri/unichrome/via_screen.c
src/mesa/drivers/dri/unichrome/via_tex.c
src/mesa/drivers/dri/unichrome/xf86drmVIA.c
src/mesa/drivers/dri/unichrome/xf86drmVIA.h

index 62f4a5fc3a4a31420a8aa25f90947bcdac9e1709..e5705f214373fd929c877a398405fd7ac01b5487 100644 (file)
@@ -60,7 +60,7 @@
 #include <stdio.h>
 #include "macros.h"
 
-#define DRIVER_DATE    "20040923"
+#define DRIVER_DATE    "20041215"
 
 #include "utils.h"
 
@@ -252,7 +252,7 @@ void viaReAllocateBuffers(GLframebuffer *drawbuffer)
 {
     GLcontext *ctx;
     viaContextPtr vmesa = current_mesa;
-    
+
     ctx = vmesa->glCtx;
     ctx->DrawBuffer->Width = drawbuffer->Width;
     ctx->DrawBuffer->Height = drawbuffer->Height;
@@ -326,7 +326,7 @@ AllocateDmaBuffer(const GLvisual *visual, viaContextPtr vmesa)
 #ifdef DEBUG
     if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
 #endif
-    if (vmesa->dma[0].map && vmesa->dma[1].map)
+    if (vmesa->dma)
         via_free_dma_buffer(vmesa);
     
     if (!via_alloc_dma_buffer(vmesa)) {
@@ -350,22 +350,15 @@ InitVertexBuffer(viaContextPtr vmesa)
 {
     GLuint *addr;
 
-    addr = (GLuint *)vmesa->dma[0].map;
-    *addr = 0xF210F110;
-    *addr = (HC_ParaType_NotTex << 16);
-    *addr = 0xcccccccc;
-    *addr = 0xdddddddd;
-    
-    addr = (GLuint *)vmesa->dma[1].map;
+    addr = (GLuint *)vmesa->dma;
     *addr = 0xF210F110;
     *addr = (HC_ParaType_NotTex << 16);
     *addr = 0xcccccccc;
     *addr = 0xdddddddd;
 
-    vmesa->dmaIndex = 0;
     vmesa->dmaLow = DMA_OFFSET;
-    vmesa->dmaHigh = vmesa->dma[0].size;
-    vmesa->dmaAddr = (unsigned char *)vmesa->dma[0].map;
+    vmesa->dmaHigh = VIA_DMA_BUFSIZ;
+    vmesa->dmaAddr = (unsigned char *)vmesa->dma;
     vmesa->dmaLastPrim = vmesa->dmaLow;
 }
 
@@ -381,7 +374,7 @@ FreeBuffer(viaContextPtr vmesa)
     if (vmesa->depth.map)
         via_free_depth_buffer(vmesa);
 
-    if (vmesa->dma[0].map && vmesa->dma[1].map)
+    if (vmesa->dma)
         via_free_dma_buffer(vmesa);
 }
 
@@ -534,9 +527,6 @@ viaCreateContext(const __GLcontextModes *mesaVis,
     vmesa->CurrentTexObj[0] = 0;
     vmesa->CurrentTexObj[1] = 0;
     
-    vmesa->dma[0].size = DMA_SIZE * 1024 * 1024;
-    vmesa->dma[1].size = DMA_SIZE * 1024 * 1024;
-
     _math_matrix_ctr(&vmesa->ViewportMatrix);
 
    driInitExtensions( ctx, card_extensions, GL_TRUE );
@@ -640,34 +630,14 @@ void
 viaDestroyContext(__DRIcontextPrivate *driContextPriv)
 {
     viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
-    /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-    __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
-    viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private;
 #ifdef DEBUG
     if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);    
 #endif
     assert(vmesa); /* should never be null */
     viaFlushPrimsLocked(vmesa);
     WAIT_IDLE
-    /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-    /* Enable VQ */
-    if (viaScreen->VQEnable) {
-       *vmesa->regTranSet = 0x00fe0000;
-       *vmesa->regTranSet = 0x00fe0000;
-       *vmesa->regTranSpace = 0x00000006;
-       *vmesa->regTranSpace = 0x40008c0f;
-       *vmesa->regTranSpace = 0x44000000;
-       *vmesa->regTranSpace = 0x45080c04;
-       *vmesa->regTranSpace = 0x46800408;
-    }
+
     if (vmesa) {
-       /*=* John Sheng [2003.5.31] flip *=*/
-       if(vmesa->doPageFlip) {
-           *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x43c)) = 0x00fe0000;
-           *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x440)) = 0x00001004;
-           WAIT_IDLE
-           *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x214)) = 0;
-       }
        /*=* John Sheng [2003.5.31]  agp tex *=*/
        if(VIA_DEBUG) fprintf(stderr, "agpFullCount = %d\n", agpFullCount);    
        
index 5b2855a834751bbe24ed5bdc4ddc4d47ac4fb7f1..d0a96581e45dadd8559f48783dd7be7dc470259c 100644 (file)
@@ -70,6 +70,8 @@ typedef struct via_texture_object_t *viaTextureObjectPtr;
 #define VIA_UPLOAD_ENABLE              0x0800
 #define VIA_UPLOAD_ALL                         0x1000
                
+#define VIA_DMA_BUFSIZ                  500000
+
 /* Use the templated vertex formats:
  */
 #define TAG(x) via##x
@@ -99,13 +101,6 @@ typedef struct {
     char *map;
 } viaBuffer, *viaBufferPtr;
 
-typedef struct {
-    drm_handle_t handle;
-    drmSize size;
-    GLuint offset;
-    GLuint index;
-    unsigned char* map;
-} viaDmaBuffer, *viaDmaBufferPtr;
 
 struct via_context_t {
     GLint refcount;   
@@ -121,7 +116,7 @@ struct via_context_t {
     GLboolean hasAccum;
     GLuint    depthBits;
     GLuint    stencilBits;
-    viaDmaBuffer dma[2];
+    GLuint    *dma;
     viaRegion tex;
     
     GLuint isAGP;
@@ -157,7 +152,6 @@ struct via_context_t {
     /* drmBufPtr dma_buffer;
     */
     unsigned char* dmaAddr;
-    GLuint dmaIndex;
     GLuint dmaLow;
     GLuint dmaHigh;
     GLuint dmaLastPrim;
@@ -297,8 +291,6 @@ struct via_context_t {
     volatile GLuint* regTranSpace;
     GLuint* agpBase;
     GLuint drawType;
-    /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-    int VQEnable;
 };
 /*#define DMA_OFFSET 16*/
 #define DMA_OFFSET 32
index 44503c7288c3b8c101de85a2ab0fc2d67d41e19d..73a06cb0bad4e6fc9b56834ff33e63e1e4a224f1 100644 (file)
@@ -27,6 +27,7 @@
 #include "via_context.h"
 #include "via_ioctl.h"
 #include "via_fb.h"
+#include "xf86drm.h"
 #include <sys/ioctl.h>
 
 GLboolean
@@ -170,101 +171,38 @@ via_free_depth_buffer(viaContextPtr vmesa)
 GLboolean
 via_alloc_dma_buffer(viaContextPtr vmesa)
 {
-    drm_via_mem_t fb;
-    drmVIADMABuf dma;
+  drmVIADMAInit init;
+
 #ifdef DEBUG    
     if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
 #endif
-    if (vmesa->viaScreen->agpLinearStart) {
-       /* Allocate DMA in AGP memory*/
-       fb.context = vmesa->hHWContext;
-       fb.size = vmesa->dma[0].size;
-       fb.type = AGP;
-       if (!ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
-           vmesa->dma[0].offset = fb.offset;
-           vmesa->dma[0].index = fb.index;
-           vmesa->dma[0].map = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset);
-           if (!ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
-               vmesa->dma[1].offset = fb.offset;
-               vmesa->dma[1].index = fb.index;
-               vmesa->dma[1].map = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset);    
-               vmesa->useAgp = GL_TRUE;
-               
-               return GL_TRUE;
-           } 
-           else {
-               /* release dma[0]*/
-               return GL_FALSE;                
-           }
-       }
-       return GL_FALSE;        
-    } 
-    else {
-       /* Allocate DMA in System memory */
-       dma.size = vmesa->dma[0].size;
-
-       if (drmVIAAllocateDMA(vmesa->driFd,&dma) < 0) {
-           return GL_FALSE;
-       }
-
-       vmesa->dma[0].offset = 0;
-       vmesa->dma[0].map = (unsigned char *)dma.address;
-       vmesa->dma[0].index = dma.index;
-
-       drmVIAAllocateDMA(vmesa->driFd, &dma);
+    vmesa->dma = (GLuint *) malloc(VIA_DMA_BUFSIZ);
+    
+    /*
+     * Check whether AGP DMA has been initialized.
+     */
 
-       vmesa->dma[1].offset = 0;
-       vmesa->dma[1].map = (unsigned char *)dma.address;
-       vmesa->dma[1].index = dma.index;
-       vmesa->useAgp = GL_FALSE;
-       
-       return GL_TRUE;
-    }
+    init.func = VIA_DMA_INITIALIZED;
+    vmesa->useAgp = 
+      ( 0 == drmCommandWrite(vmesa->driFd, DRM_VIA_DMA_INIT, 
+                            &init, sizeof(init)));
+    if (vmesa->useAgp) 
+        printf("unichrome_dri.so: Using AGP.\n");
+    else
+        printf("unichrome_dri.so: Using PCI.\n");
+      
 #ifdef DEBUG    
     if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
 #endif
+    return ((vmesa->dma) ? GL_TRUE : GL_FALSE);
 }
 
 void
 via_free_dma_buffer(viaContextPtr vmesa)
 {
-    drmVIADMABuf dma;
-    drm_via_mem_t fb;
-    
-    
     if (!vmesa) return;
-    
-    /* Release AGP command buffer */
-    if (vmesa->useAgp) {
-       fb.context = vmesa->hHWContext;
-       fb.index = vmesa->dma[0].index;
-       fb.type = AGP;
-       ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
-       vmesa->dma[0].map = NULL;    
-       fb.index = vmesa->dma[1].index;
-       ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
-       vmesa->dma[1].map = NULL;    
-    }
-    /* Release System command buffer */
-    else {
-       /*=* John Sheng [2003.7.18] viewperf frames/sec *=*/
-       /*dma.address = (unsigned long *)vmesa->dma[0].offset;*/
-       dma.address = (unsigned long *)vmesa->dma[0].map;
-       /*=* John Sheng [2003.6.16] fix pci path *=*/
-       dma.size = (unsigned int)vmesa->dma[0].size;
-       drmVIAReleaseDMA(vmesa->driFd, &dma);
-       /*=* John Sheng [2003.7.18] viewperf frames/sec *=*/
-       /*dma.address = (unsigned long *)vmesa->dma[1].offset;*/
-       dma.address = (unsigned long *)vmesa->dma[1].map;
-       /*=* John Sheng [2003.6.16] fix pci path *=*/
-       dma.size = (unsigned int)vmesa->dma[1].size;
-       drmVIAReleaseDMA(vmesa->driFd, &dma);
-       /*=* John Sheng [2003.7.18] viewperf frames/sec *=*/
-       /*vmesa->dma[0].offset = 0;
-       vmesa->dma[1].offset = 0;*/
-       vmesa->dma[0].map = 0;
-       vmesa->dma[1].map = 0;
-    }
+    free(vmesa->dma);
+    vmesa->dma = 0;
 } 
 
 GLboolean
index 1e210b7b93aac2a8619ff0a4efd9fcb1b25f0559..4efa3d9ad579ef24e1e804751bc373a616457f79 100644 (file)
@@ -1,9 +1,9 @@
-#/*
+/*
  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
+v * copy of this software and associated documentation files (the "Software"),
  * to deal in the Software without restriction, including without limitation
  * the rights to use, copy, modify, merge, publish, distribute, sub license,
  * and/or sell copies of the Software, and to permit persons to whom the
 #include "via_state.h"
 
 #include "drm.h"
+#include "xf86drm.h"
 #include <sys/ioctl.h>
+#include <errno.h>
+
+
+#define VIA_REG_STATUS          0x400
+#define VIA_REG_GEMODE          0x004
+#define VIA_REG_SRCBASE         0x030
+#define VIA_REG_DSTBASE         0x034
+#define VIA_REG_PITCH           0x038      
+#define VIA_REG_SRCCOLORKEY     0x01C      
+#define VIA_REG_KEYCONTROL      0x02C       
+#define VIA_REG_SRCPOS          0x008
+#define VIA_REG_DSTPOS          0x00C
+#define VIA_REG_GECMD           0x000
+#define VIA_REG_DIMENSION       0x010       /* width and height */
+#define VIA_REG_FGCOLOR         0x018
+
+#define VIA_GEM_8bpp            0x00000000
+#define VIA_GEM_16bpp           0x00000100
+#define VIA_GEM_32bpp           0x00000300
+#define VIA_GEC_BLT             0x00000001
+#define VIA_PITCH_ENABLE        0x80000000
+#define VIA_GEC_INCX            0x00000000
+#define VIA_GEC_DECY            0x00004000
+#define VIA_GEC_INCY            0x00000000
+#define VIA_GEC_DECX            0x00008000
+#define VIA_GEC_FIXCOLOR_PAT    0x00002000
+
+
+#define VIA_BLIT_CLEAR 0x00
+#define VIA_BLIT_COPY 0xCC
+#define VIA_BLIT_FILL 0xF0
+#define VIA_BLIT_SET 0xFF
+#define VIA_BLITSIZE 96
+
+
+typedef enum {VIABLIT_TRANSCOPY, VIABLIT_COPY, VIABLIT_FILL} ViaBlitOps;
+
 
 GLuint FrameCount = 0;
 GLuint dmaLow = 0;
@@ -526,7 +564,6 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
     drm_clip_rect_t *pbox = (drm_clip_rect_t *)vmesa->pClipRects;
     int nbox = vmesa->numClipRects;
     drm_via_sarea_t *sarea = vmesa->sarea;
-    drm_via_flush_agp_t agpCmd;
     drm_via_flush_sys_t sysCmd;
     GLuint *vb = viaCheckDma(vmesa, 0);
     int i;
@@ -534,7 +571,7 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
     if (vmesa->dmaLow == DMA_OFFSET) {
        return;
     }
-    if (vmesa->dmaLow > 2097152)
+    if (vmesa->dmaLow > (VIA_DMA_BUFSIZ - 256))
        fprintf(stderr, "buffer overflow in Flush Prims = %d\n",vmesa->dmaLow);
     
     switch (vmesa->dmaLow & 0x1F) {    
@@ -573,26 +610,15 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
        break;
     }
     
-    if (vmesa->useAgp) {
-       agpCmd.offset = 0x0;
-       agpCmd.size = vmesa->dmaLow;
-       agpCmd.index = vmesa->dma[vmesa->dmaIndex].index;
-       agpCmd.discard = 0;
-    } 
-    else {
-       sysCmd.offset = 0x0;
-       sysCmd.size = vmesa->dmaLow;
-       sysCmd.index = (GLuint)vmesa->dma[vmesa->dmaIndex].map;
-       sysCmd.discard = 0;
-    }
+    sysCmd.offset = 0x0;
+    sysCmd.size = vmesa->dmaLow;
+    sysCmd.index = (GLuint)vmesa->dma;
+    sysCmd.discard = 0;
     
     sarea->vertexPrim = vmesa->hwPrimitive;
 
     if (!nbox) {
-       if (vmesa->useAgp)
-           agpCmd.size = 0;
-       else
-           sysCmd.size = 0;
+      sysCmd.size = 0;
     }
     else if (nbox > VIA_NR_SAREA_CLIPRECTS) {
         vmesa->uploadCliprects = GL_TRUE;
@@ -617,14 +643,8 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
         else
             sarea->nbox = nbox;
 
-       if (vmesa->useAgp) {
-           agpCmd.discard = 1;
-           flush_agp(vmesa, &agpCmd);
-       }
-       else {
-           sysCmd.discard = 1;
-           flush_sys(vmesa, &sysCmd);
-       }
+       sysCmd.discard = 1;
+       flush_sys(vmesa, &sysCmd);
     }
     else {
        GLuint scrn;
@@ -652,7 +672,7 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
                    }
                    if (!sarea->nbox) {
                        if (nr < nbox) continue;
-                       agpCmd.size = 0;
+                       sysCmd.size = 0;
                    }
                }
                else {
@@ -680,7 +700,7 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
                    }
                    if (!sarea->nbox) {
                        if (nr < nbox) continue;
-                       agpCmd.size = 0;
+                       sysCmd.size = 0;
                    }
                }
                else {
@@ -711,7 +731,7 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
                    }
                    if (!sarea->nbox) {
                        if (nr < nbox) continue;
-                       agpCmd.size = 0;
+                       sysCmd.size = 0;
                    }
                }
                else {
@@ -726,14 +746,8 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
            }
 
             if (nr == nbox) {
-               if (vmesa->useAgp) {
-                   agpCmd.discard = 1;
-                   flush_agp(vmesa, &agpCmd);
-               } 
-               else {
-                   sysCmd.discard = 1;
-                   flush_sys(vmesa, &sysCmd);
-               }
+             sysCmd.discard = 1;
+             flush_sys(vmesa, &sysCmd);
            }
 
            if (scrn == (S0 | S1)) {
@@ -757,7 +771,7 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
                        }
                        if (!sarea->nbox) {
                            if (nr < nbox) continue;
-                           agpCmd.size = 0;
+                           sysCmd.size = 0;
                        }
                    }
                    else {
@@ -770,7 +784,7 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
                        }
                    }
                }
-               flush_agp_saam(vmesa, &agpCmd);
+               flush_sys(vmesa, &sysCmd);
            }
         }
     }
@@ -790,18 +804,9 @@ void viaFlushPrimsLocked(viaContextPtr vmesa)
     /* Reset vmesa vars:
      */
     vmesa->dmaLow = DMA_OFFSET;
-    if (vmesa->dmaIndex) {
-        vmesa->dmaAddr = vmesa->dma[0].map;
-        vmesa->dmaHigh = vmesa->dma[0].size;
-        vmesa->dmaLastPrim = DMA_OFFSET;
-       vmesa->dmaIndex = 0;
-    }
-    else {
-        vmesa->dmaAddr = vmesa->dma[1].map;
-        vmesa->dmaHigh = vmesa->dma[1].size;
-        vmesa->dmaLastPrim = DMA_OFFSET;
-       vmesa->dmaIndex = 1;    
-    }
+    vmesa->dmaAddr = (unsigned char *)vmesa->dma;
+    vmesa->dmaHigh = VIA_DMA_BUFSIZ;
+    vmesa->dmaLastPrim = DMA_OFFSET;
 }
 
 void viaFlushPrims(viaContextPtr vmesa)
@@ -809,10 +814,11 @@ void viaFlushPrims(viaContextPtr vmesa)
 #ifdef DEBUG    
     if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__);
 #endif
+
     if (vmesa->dmaLow) {
-        LOCK_HARDWARE(vmesa);
+      LOCK_HARDWARE(vmesa); 
         viaFlushPrimsLocked(vmesa);
-        UNLOCK_HARDWARE(vmesa);
+      UNLOCK_HARDWARE(vmesa);
     }
 #ifdef DEBUG    
     if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__);
@@ -853,45 +859,97 @@ void viaInitIoctlFuncs(GLcontext *ctx)
     ctx->Driver.ClearStencil = viaClearStencil;
 }
 
+
+
+GLuint *viaBlit(viaContextPtr vmesa, GLuint bpp,GLuint srcBase,
+               GLuint srcPitch,GLuint dstBase,GLuint dstPitch,
+               GLuint w,GLuint h,int xdir,int ydir, GLuint blitMode, 
+               GLuint color, GLuint nMask, GLuint *vb) 
+{
+
+    GLuint dwGEMode = 0, srcY=0, srcX, dstY=0, dstX;
+    GLuint cmd;
+
+    if (!w || !h)
+        return vb;
+
+    srcX = srcBase & 31;
+    dstX = dstBase & 31;
+    switch (bpp) {
+    case 16:
+        dwGEMode |= VIA_GEM_16bpp;
+       srcX >>= 1;
+       dstX >>= 1;
+        break;
+    case 32:
+        dwGEMode |= VIA_GEM_32bpp;
+       srcX >>= 2;
+       dstX >>= 2;
+       break;
+    default:
+        dwGEMode |= VIA_GEM_8bpp;
+        break;
+    }
+    SetReg2DAGP(VIA_REG_GEMODE, dwGEMode);
+
+    cmd = 0; 
+
+    if (xdir < 0) {
+        cmd |= VIA_GEC_DECX;
+        srcX += (w - 1);
+        dstX += (w - 1);
+    }
+    if (ydir < 0) {
+        cmd |= VIA_GEC_DECY;
+        srcY += (h - 1);
+        dstY += (h - 1);
+    }
+
+    switch(blitMode) {
+    case VIABLIT_TRANSCOPY:
+       SetReg2DAGP( VIA_REG_SRCCOLORKEY, color);
+       SetReg2DAGP( VIA_REG_KEYCONTROL, 0x4000);
+       cmd |= VIA_GEC_BLT | (VIA_BLIT_COPY << 24);
+       break;
+    case VIABLIT_FILL:
+       SetReg2DAGP( VIA_REG_FGCOLOR, color);
+       cmd |= VIA_GEC_BLT | VIA_GEC_FIXCOLOR_PAT | (VIA_BLIT_FILL << 24);
+       break;
+    default:
+       SetReg2DAGP( VIA_REG_KEYCONTROL, 0x0);
+       cmd |= VIA_GEC_BLT | (VIA_BLIT_COPY << 24);
+    }  
+
+    SetReg2DAGP( 0x2C, nMask);
+    SetReg2DAGP( VIA_REG_SRCBASE, (srcBase & ~31) >> 3);
+    SetReg2DAGP( VIA_REG_DSTBASE, (dstBase & ~31) >> 3);
+    SetReg2DAGP( VIA_REG_PITCH, VIA_PITCH_ENABLE |
+              (srcPitch >> 3) | (((dstPitch) >> 3) << 16));
+    SetReg2DAGP( VIA_REG_SRCPOS, ((srcY << 16) | srcX));
+    SetReg2DAGP( VIA_REG_DSTPOS, ((dstY << 16) | dstX));
+    SetReg2DAGP( VIA_REG_DIMENSION, (((h - 1) << 16) | (w - 1)));
+    SetReg2DAGP( VIA_REG_GECMD, cmd);
+    SetReg2DAGP( 0x2C, 0x00000000);
+    return vb;
+}
+
 void viaFillFrontBuffer(viaContextPtr vmesa)
 {
-    GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offsetX, offset,i; 
+    GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight,i; 
     drm_clip_rect_t *b = vmesa->sarea->boxes;
-    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*48);
-    GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
+    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*VIA_BLITSIZE);
     GLuint pixel = (GLuint)vmesa->ClearColor;
-
-    offset = vmesa->viaScreen->fbOffset + (vmesa->drawY * vmesa->front.pitch + vmesa->drawX * bytePerPixel);
-#ifdef DEBUG        
-    if (VIA_DEBUG) fprintf(stderr, "Fill Front offset = %08x\n", offset);
-#endif    
-    nDestBase = offset & 0xffffffe0;
+    GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
     nDestPitch = vmesa->front.pitch;
 
     for (i = 0; i < vmesa->sarea->nbox ; i++) {        
-        nDestWidth = b->x2 - b->x1 - 1;
-       nDestHeight = b->y2 - b->y1 - 1;
-       
-       if (bytePerPixel == 4)
-           offsetX = (b->x1 - vmesa->drawX) + (vmesa->drawX & 7);
-       else 
-           offsetX = (b->x1 - vmesa->drawX) + (vmesa->drawX & 15);
-    
-
-       if (GL_TRUE) {
-           /* GEFGCOLOR*/
-           SetReg2DAGP(0x18, pixel | 0x00000000);
-           /* GEWD*/
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST*/
-           SetReg2DAGP(0x0C, (offsetX | ((b->y1 - vmesa->drawY) << 16)));
-           /* GEDSTBASE*/
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH*/
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT*/
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-       }
+        nDestWidth = b->x2 - b->x1;
+       nDestHeight = b->y2 - b->y1;
+       nDestBase = vmesa->viaScreen->fbOffset + 
+           (b->y1* nDestPitch + b->x1 * bytePerPixel);
+       vb = viaBlit(vmesa,vmesa->viaScreen->bitsPerPixel, nDestBase, nDestPitch,
+                    nDestBase , nDestPitch, nDestWidth, nDestHeight,
+                    0,0,VIABLIT_FILL, pixel, 0x0, vb); 
        b++;
     }
 
@@ -900,40 +958,22 @@ void viaFillFrontBuffer(viaContextPtr vmesa)
 
 void viaFillFrontBufferSaam(viaContextPtr vmesa)
 {
-    GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offsetX, offset,i; 
+    GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight,i; 
     drm_clip_rect_t *b = vmesa->sarea->boxes;
-    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*48);
+    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*VIA_BLITSIZE);
     GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
     GLuint pixel = (GLuint)vmesa->ClearColor;
 
-    offset = vmesa->viaScreen->fbSize + 
-       (vmesa->drawYSaam * vmesa->front.pitch + vmesa->drawXSaam * bytePerPixel);
-    nDestBase = offset & 0xffffffe0;
     nDestPitch = vmesa->front.pitch;
 
     for (i = 0; i < vmesa->sarea->nbox ; i++) {        
-        nDestWidth = b->x2 - b->x1 - 1;
-       nDestHeight = b->y2 - b->y1 - 1;
-       
-       if (bytePerPixel == 4)
-           offsetX = (b->x1 - vmesa->drawXSaam) + (vmesa->drawXSaam & 7);
-       else 
-           offsetX = (b->x1 - vmesa->drawXSaam) + (vmesa->drawXSaam & 15);
-    
-       if (GL_TRUE) {
-           /* GEFGCOLOR*/
-           SetReg2DAGP(0x18, pixel | 0x00000000);
-           /* GEWD*/
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST*/
-           SetReg2DAGP(0x0C, (offsetX | ((b->y1 - vmesa->drawYSaam) << 16)));
-           /* GEDSTBASE*/
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH*/
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT*/
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-       }
+       nDestWidth = b->x2 - b->x1;
+       nDestHeight = b->y2 - b->y1;
+       nDestBase = vmesa->viaScreen->fbOffset + 
+           (vmesa->drawYSaam* nDestPitch + vmesa->drawXSaam * bytePerPixel);
+       vb = viaBlit(vmesa,vmesa->viaScreen->bitsPerPixel, nDestBase, nDestPitch,
+                    nDestBase , nDestPitch, nDestWidth, nDestHeight,
+                    0,0,VIABLIT_FILL, pixel, 0x0, vb); 
        b++;
     }
 
@@ -942,8 +982,8 @@ void viaFillFrontBufferSaam(viaContextPtr vmesa)
 
 void viaFillFrontPBuffer(viaContextPtr vmesa)
 {
-    GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offsetX, offset
-    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*48);
+    GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offset; 
+    GLuint *vb = viaCheckDma(vmesa, VIA_BLITSIZE);
     GLuint pixel = (GLuint)vmesa->ClearColor;
 
     offset = vmesa->front.offset;
@@ -953,24 +993,13 @@ void viaFillFrontPBuffer(viaContextPtr vmesa)
     nDestBase = offset;
     nDestPitch = vmesa->front.pitch;
 
-    nDestWidth = vmesa->driDrawable->w - 1;
-    nDestHeight = vmesa->driDrawable->h - 1;
+    nDestWidth = vmesa->driDrawable->w;
+    nDestHeight = vmesa->driDrawable->h;
+
+    viaBlit(vmesa,vmesa->viaScreen->bitsPerPixel, nDestBase, nDestPitch,
+           nDestBase , nDestPitch, nDestWidth, nDestHeight,
+           0,0,VIABLIT_FILL, pixel, 0x0, vb); 
        
-    offsetX = 0;
-
-    /* GEFGCOLOR*/
-    SetReg2DAGP(0x18, pixel | 0x00000000);
-    /* GEWD*/
-    SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-    /* GEDST*/
-    SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-    /* GEDSTBASE*/
-    SetReg2DAGP(0x34, (nDestBase >> 3));
-    /* GEPITCH*/
-    SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-    /* BITBLT*/
-    SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-    
     viaFlushPrimsLocked(vmesa);
 }
 
@@ -978,7 +1007,7 @@ void viaFillBackBuffer(viaContextPtr vmesa)
 {
     GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offsetX, offset; 
     GLcontext *ctx = vmesa->glCtx;
-    GLuint *vb = viaCheckDma(vmesa, 48);
+    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*VIA_BLITSIZE);
     GLuint pixel = (GLuint)vmesa->ClearColor;
     GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
 
@@ -990,67 +1019,41 @@ void viaFillBackBuffer(viaContextPtr vmesa)
     nDestPitch = vmesa->back.pitch;
     offsetX = vmesa->drawXoff;
     
-    {
-       if (!ctx->Scissor.Enabled) {
-           
-           nDestWidth = (vmesa->back.pitch / vmesa->viaScreen->bitsPerPixel * 8) - 1;
-           nDestHeight = vmesa->driDrawable->h -1;
-           
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel | 0x00000000);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-       }
-       /*=* John Sheng [2003.7.18] texenv *=*/
-       else {
-           int i;
-           drm_clip_rect_t *b = vmesa->sarea->boxes;
-           for (i = 0; i < vmesa->sarea->nbox ; i++) {        
-               nDestWidth = b->x2 - b->x1 - 1;
-               nDestHeight = b->y2 - b->y1 - 1;
-               
-               if (bytePerPixel == 4)
-                   offsetX = (b->x1 - vmesa->drawX) + (vmesa->drawX & 7);
-               else 
-                   offsetX = (b->x1 - vmesa->drawX) + (vmesa->drawX & 15);
-               
-               /* GEFGCOLOR */
-               SetReg2DAGP(0x18, pixel | 0x00000000);
-               /* GEWD */
-               SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-               /* GEDST */
-               SetReg2DAGP(0x0C, ((offsetX + (b->x1 - vmesa->drawX)) | ((b->y1 - vmesa->drawY) << 16)));
-               /* GEDSTBASE */
-               SetReg2DAGP(0x34, (nDestBase >> 3));
-               /* GEPITCH */
-               SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-               /* BITBLT */
-               SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-               b++;
-           }
+    if (!ctx->Scissor.Enabled) {
+       nDestWidth = (vmesa->back.pitch / bytePerPixel);
+       nDestHeight = vmesa->driDrawable->h;
+       viaBlit(vmesa,vmesa->viaScreen->bitsPerPixel, nDestBase, nDestPitch,
+               nDestBase , nDestPitch, nDestWidth, nDestHeight,
+               0,0,VIABLIT_FILL, pixel, 0x0, vb); 
+       
+    }
+    /*=* John Sheng [2003.7.18] texenv *=*/
+    else {
+       int i;
+       drm_clip_rect_t *b = vmesa->sarea->boxes;
+       for (i = 0; i < vmesa->sarea->nbox ; i++) {        
+           nDestWidth = b->x2 - b->x1;
+           nDestHeight = b->y2 - b->y1;
+           nDestBase = offset + ((b->y1 - vmesa->drawY) * nDestPitch) + 
+               (b->x1 - vmesa->drawX + vmesa->drawXoff) * bytePerPixel;
+           vb = viaBlit(vmesa,vmesa->viaScreen->bitsPerPixel, nDestBase, nDestPitch,
+                        nDestBase , nDestPitch, nDestWidth, nDestHeight,
+                        0,0,VIABLIT_FILL, pixel, 0x0, vb); 
+           b++;
        }
+    }
 #ifdef DEBUG           
-       if (VIA_DEBUG) {
-           fprintf(stderr," width = %08x\n", nDestWidth);      
-           fprintf(stderr," height = %08x\n", nDestHeight);    
-       }            
+    if (VIA_DEBUG) {
+       fprintf(stderr," width = %08x\n", nDestWidth);  
+       fprintf(stderr," height = %08x\n", nDestHeight);        
+    }       
 #endif
-    }
 }
 
 void viaFillStencilDepthBuffer(viaContextPtr vmesa, GLuint pixel)
 {
     GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offsetX, offset; 
-    GLuint *vb = viaCheckDma(vmesa, 80);
-    GLuint nMask;
+    GLuint *vb = viaCheckDma(vmesa, VIA_BLITSIZE);
     
     offset = vmesa->depth.offset;
 #ifdef DEBUG    
@@ -1060,56 +1063,12 @@ void viaFillStencilDepthBuffer(viaContextPtr vmesa, GLuint pixel)
     nDestPitch = vmesa->depth.pitch;
     offsetX = vmesa->drawXoff;
     pixel = pixel & 0xffffff00;
-    nMask = 0x10000000;
-    
-    {        
-       nDestWidth = (vmesa->depth.pitch / vmesa->depthBits * 8) - 1 - offsetX;
-       nDestHeight = vmesa->driDrawable->h -1;
-       
-       if (vmesa->viaScreen->bitsPerPixel == vmesa->depth.bpp) {
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, nMask);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, 0x00000000);
-       }
-       else {
-           GLuint EngStatus = *(vmesa->pnGEMode);
-           /* GEMODE */
-           SetReg2DAGP(0x04, (EngStatus & 0xFFFFFCFF) | 0x300);
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, nMask);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-           /* GEMODE */
-           SetReg2DAGP(0x04, EngStatus);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, 0x00000000);
-           
-           WAIT_IDLE
-       }
-    }
+    nDestWidth = (vmesa->depth.pitch / vmesa->depthBits * 8) - offsetX;
+    nDestHeight = vmesa->driDrawable->h;
+
+    viaBlit(vmesa, vmesa->depth.bpp , nDestBase, nDestPitch,
+           nDestBase , nDestPitch, nDestWidth, nDestHeight,
+           0,0,VIABLIT_FILL, pixel, 0x10000000, vb); 
 
     if (vmesa->glCtx->Color._DrawDestMask[0] == __GL_BACK_BUFFER_MASK) {
        viaFlushPrimsLocked(vmesa);
@@ -1119,8 +1078,7 @@ void viaFillStencilDepthBuffer(viaContextPtr vmesa, GLuint pixel)
 void viaFillStencilBuffer(viaContextPtr vmesa, GLuint pixel)
 {
     GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offsetX, offset; 
-    GLuint *vb = viaCheckDma(vmesa, 80);
-    GLuint nMask;
+    GLuint *vb = viaCheckDma(vmesa, VIA_BLITSIZE);
     
     offset = vmesa->depth.offset;
 #ifdef DEBUG    
@@ -1130,54 +1088,12 @@ void viaFillStencilBuffer(viaContextPtr vmesa, GLuint pixel)
     nDestPitch = vmesa->depth.pitch;
     offsetX = vmesa->drawXoff; 
     pixel = pixel & 0x000000ff;
-    nMask = 0xe0000000;
-    
-    {        
-       nDestWidth = (vmesa->depth.pitch / vmesa->depthBits * 8) - 1 - offsetX;
-       nDestHeight = vmesa->driDrawable->h -1;
-       
-       if (vmesa->viaScreen->bitsPerPixel == vmesa->depth.bpp) {
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, nMask);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, 0x00000000);
-       }
-       else {
-           GLuint EngStatus = *(vmesa->pnGEMode);
-           /* GEMODE */
-           SetReg2DAGP(0x04, (EngStatus & 0xFFFFFCFF) | 0x300);
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, nMask);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-           /* GEMODE */
-           SetReg2DAGP(0x04, EngStatus);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, 0x00000000);
-       }
-    }
+    nDestWidth = (vmesa->depth.pitch / vmesa->depthBits * 8) - offsetX;
+    nDestHeight = vmesa->driDrawable->h;
+
+    viaBlit(vmesa, vmesa->depth.bpp , nDestBase, nDestPitch,
+           nDestBase , nDestPitch, nDestWidth, nDestHeight,
+           0,0,VIABLIT_FILL, pixel, 0xe0000000, vb); 
 
     if (vmesa->glCtx->Color._DrawDestMask[0] == __GL_BACK_BUFFER_MASK) {
        viaFlushPrimsLocked(vmesa);
@@ -1187,7 +1103,8 @@ void viaFillStencilBuffer(viaContextPtr vmesa, GLuint pixel)
 void viaFillDepthBuffer(viaContextPtr vmesa, GLuint pixel)
 {
     GLuint nDestBase, nDestPitch, nDestWidth, nDestHeight, offsetX, offset;
-    GLuint *vb = viaCheckDma(vmesa, 72);
+    GLuint *vb = viaCheckDma(vmesa, VIA_BLITSIZE);
+
     offset = vmesa->depth.offset;
 #ifdef DEBUG    
     if (VIA_DEBUG) fprintf(stderr, "Fill Depth offset = %08x\n", offset);
@@ -1195,74 +1112,13 @@ void viaFillDepthBuffer(viaContextPtr vmesa, GLuint pixel)
     nDestBase = offset;
     nDestPitch = vmesa->depth.pitch;
     offsetX = vmesa->drawXoff;
-    
-    {
-       nDestWidth = (vmesa->depth.pitch / vmesa->depthBits * 8) - 1 - offsetX;
-       nDestHeight = vmesa->driDrawable->h -1;
-       
-       if (vmesa->viaScreen->bitsPerPixel == vmesa->depth.bpp) {
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, 0x0);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-       }
-       /* depth = 16, color = 32 */
-       else if (vmesa->depth.bpp == 16) {
-           GLuint EngStatus = *(vmesa->pnGEMode);
-           
-           /* GEMODE */
-           SetReg2DAGP(0x04, (EngStatus & 0xFFFFFCFF) | 0x100);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, 0x0);
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-           /* GEMODE */
-           SetReg2DAGP(0x04, EngStatus);
-       }
-       /* depth = 32, color = 16 */
-       else {
-           GLuint EngStatus = *(vmesa->pnGEMode);
-           
-           /* GEMODE */
-           SetReg2DAGP(0x04, (EngStatus & 0xFFFFFCFF) | 0x300);
-           /* GEMASK */
-           SetReg2DAGP(0x2C, 0x0);
-           /* GEFGCOLOR */
-           SetReg2DAGP(0x18, pixel);
-           /* GEWD */
-           SetReg2DAGP(0x10, nDestWidth | (nDestHeight << 16));
-           /* GEDST */
-           SetReg2DAGP(0x0C, (offsetX | (0 << 16)));
-           /* GEDSTBASE */
-           SetReg2DAGP(0x34, (nDestBase >> 3));
-           /* GEPITCH */
-           SetReg2DAGP(0x38, (((nDestPitch >> 3) << 16) & 0x7FF0000) | 0x80000000);
-           /* BITBLT */
-           SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xF0000000);
-           /* GEMODE */
-           SetReg2DAGP(0x04, EngStatus);
-       }
-    }
+    nDestWidth = (vmesa->depth.pitch / vmesa->depthBits * 8) - offsetX;
+    nDestHeight = vmesa->driDrawable->h;
+
+    viaBlit(vmesa, vmesa->depth.bpp , nDestBase, nDestPitch,
+           nDestBase , nDestPitch, nDestWidth, nDestHeight,
+           0,0,VIABLIT_FILL, pixel, 0, vb); 
+
     
     if (vmesa->glCtx->Color._DrawDestMask[0] == __GL_BACK_BUFFER_MASK) {
        viaFlushPrimsLocked(vmesa);
@@ -1271,12 +1127,11 @@ void viaFillDepthBuffer(viaContextPtr vmesa, GLuint pixel)
 
 void viaDoSwapBuffers(viaContextPtr vmesa)
 {    
-    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*56);
+    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*VIA_BLITSIZE );
     GLuint nFrontPitch;
     GLuint nBackPitch;
-    GLuint nFrontWidth, nFrontHeight, nBackWidth, nBackHeight;
+    GLuint nFrontWidth, nFrontHeight;
     GLuint nFrontBase, nBackBase;
-    GLuint nFrontOffsetX, nFrontOffsetY, nBackOffsetX, nBackOffsetY;
     drm_clip_rect_t *b = vmesa->sarea->boxes;
     GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
     GLuint i;
@@ -1284,41 +1139,24 @@ void viaDoSwapBuffers(viaContextPtr vmesa)
     nFrontPitch = vmesa->front.pitch;
     nBackPitch = vmesa->back.pitch;
     
-    /* Caculate Base */
-    nFrontBase = vmesa->viaScreen->fbOffset + (vmesa->drawY * nFrontPitch + vmesa->drawX * bytePerPixel);
-    nBackBase = vmesa->back.offset;
-    /* 128 bit alignment*/
-    nFrontBase = nFrontBase & 0xffffffe0;
-    
     /*=* [DBG] make draw to front buffer *=*/
     if(DRAW_FRONT)
        return;
-    
+
     for (i = 0; i < vmesa->sarea->nbox; i++) {        
+
        /* Width, Height */
-        nFrontWidth = nBackWidth = b->x2 - b->x1 - 1;
-       nFrontHeight = nBackHeight = b->y2 - b->y1 - 1;
-       /* Offset */
-       nFrontOffsetX = (b->x1 - vmesa->drawX) + vmesa->drawXoff;
-       nFrontOffsetY = b->y1 - vmesa->drawY;
+        nFrontWidth = b->x2 - b->x1;
+       nFrontHeight = b->y2 - b->y1;
        
-       nBackOffsetX = nFrontOffsetX;
-       nBackOffsetY = nFrontOffsetY;
-       /* GEWD */
-       SetReg2DAGP(0x10, nFrontWidth | (nFrontHeight << 16));
-        /* GEDST */
-        SetReg2DAGP(0x0C, nFrontOffsetX | (nFrontOffsetY << 16));
-        /* GESRC */
-        SetReg2DAGP(0x08, nBackOffsetX | (nBackOffsetY << 16));
-        /* GEDSTBASE */
-        SetReg2DAGP(0x34, (nFrontBase >> 3));
-        /* GESCRBASE */
-        SetReg2DAGP(0x30, (nBackBase >> 3));
-        /* GEPITCH */
-        SetReg2DAGP(0x38, (((nFrontPitch >> 3) << 16) & 0x7FF0000) | 0x80000000 |
-                          ((nBackPitch >> 3) & 0x7FF));
-       /* BITBLT */
-       SetReg2DAGP(0x0, 0x1 | 0xCC000000);
+       nFrontBase = vmesa->viaScreen->fbOffset + (b->y1* nFrontPitch + 
+                                                  b->x1 * bytePerPixel);
+       nBackBase = vmesa->back.offset + ((b->y1 - vmesa->drawY) * nBackPitch) + 
+           (b->x1 - vmesa->drawX + vmesa->drawXoff) * bytePerPixel;
+       
+       vb = viaBlit(vmesa, bytePerPixel << 3 , nBackBase, nBackPitch,
+                    nFrontBase , nFrontPitch, nFrontWidth, nFrontHeight,
+                    0,0,VIABLIT_COPY, 0, 0, vb); 
        b++;
     }
 
@@ -1330,7 +1168,7 @@ void viaDoSwapBuffers(viaContextPtr vmesa)
 
 void viaDoSwapBuffersSaam(viaContextPtr vmesa)
 {    
-    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*56);
+    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*56 + 8);
     GLuint nFrontPitch;
     GLuint nBackPitch;
     GLuint nFrontWidth, nFrontHeight, nBackWidth, nBackHeight;
@@ -1338,7 +1176,24 @@ void viaDoSwapBuffersSaam(viaContextPtr vmesa)
     GLuint nFrontOffsetX, nFrontOffsetY, nBackOffsetX, nBackOffsetY;
     drm_clip_rect_t *b = vmesa->sarea->boxes;
     GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
-    GLuint i;
+    GLuint i, blitMode;
+    GLuint EngStatus = *(vmesa->pnGEMode);
+
+    switch(bytePerPixel) {
+    case 4:
+       blitMode = 0x300;
+       break;
+    case 2:
+       blitMode = 0x100;
+       break;
+    default:
+       blitMode = 0x000;
+       break;
+    }
+
+    /* Restore mode */
+    SetReg2DAGP(0x04, (EngStatus & 0xFFFFFCFF) | blitMode);
+
     
     nFrontPitch = vmesa->front.pitch;
     nBackPitch = vmesa->back.pitch;
@@ -1389,14 +1244,32 @@ void viaDoSwapBuffersSaam(viaContextPtr vmesa)
 
 void viaDoSwapPBuffers(viaContextPtr vmesa)
 {    
-    GLuint *vb = viaCheckDma(vmesa, vmesa->sarea->nbox*56);
+    GLuint *vb = viaCheckDma(vmesa, 64 );
     GLuint nFrontPitch;
     GLuint nBackPitch;
     GLuint nFrontWidth, nFrontHeight;
     GLuint nFrontBase, nBackBase;
     GLuint nFrontOffsetX, nFrontOffsetY, nBackOffsetX, nBackOffsetY;
     GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
-    
+    GLuint EngStatus = *(vmesa->pnGEMode);
+    GLuint blitMode; 
+
+    switch(bytePerPixel) {
+    case 4:
+       blitMode = 0x300;
+       break;
+    case 2:
+       blitMode = 0x100;
+       break;
+    default:
+       blitMode = 0x000;
+       break;
+    }
+
+    /* Restore mode */
+    SetReg2DAGP(0x04, (EngStatus & 0xFFFFFCFF) | blitMode);
+
+
     nFrontPitch = vmesa->front.pitch;
     nBackPitch = vmesa->back.pitch;
     
@@ -1436,55 +1309,33 @@ void viaDoSwapPBuffers(viaContextPtr vmesa)
 }
 
 
-int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd) 
-{   
-    GLuint *pnAGPCurrentPhysStart;
-    GLuint *pnAGPCurrentPhysEnd;
-    GLuint *pnAGPCurrentStart;
-    GLuint *pnAGPCurrentEnd;
+#define VIA_CMDBUF_MAX_LAG 50000
+
+int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) 
+
+{
+    GLuint *pnBuf;
+    GLuint *pnEnd;
     volatile GLuint *pnMMIOBase;
-    volatile GLuint *pnEngBaseTranSet;
-    volatile GLuint *pnEngBaseTranSpace;
-    GLuint *agpBase;
-    GLuint ofs = vmesa->dma[vmesa->dmaIndex].offset;
     GLuint *vb = (GLuint *)vmesa->dmaAddr; 
     GLuint i = 0;
-    
-    pnMMIOBase = vmesa->regMMIOBase;
-    pnEngBaseTranSet = vmesa->regTranSet;
-    pnEngBaseTranSpace = vmesa->regTranSpace;
-    *pnEngBaseTranSet = (0x0010 << 16);
-    agpBase = vmesa->agpBase;
-
-    if (!agpCmd->size) {
-        return -1;
-    }  
-
-    {
-        volatile GLuint *pnEngBase = vmesa->regEngineStatus;
-        int nStatus;
-       
-        while (1) {
-            nStatus = *pnEngBase;
-           if ((nStatus & 0xFFFEFFFF) == 0x00020000)
-               break;
-           i++;
-        }
-    }
-
-    pnAGPCurrentStart = (GLuint *)(ofs + agpCmd->offset);
-    pnAGPCurrentEnd = (GLuint *)((GLuint)pnAGPCurrentStart + vmesa->dmaHigh);
-    pnAGPCurrentPhysStart = (GLuint *)( (GLuint)pnAGPCurrentStart + (GLuint)agpBase );
-    pnAGPCurrentPhysEnd = (GLuint *)( (GLuint)pnAGPCurrentEnd + (GLuint)agpBase );
+    drmVIACommandBuffer bufI;
+    drmVIACmdBufSize bSiz;
+    int ret;
 
+    pnMMIOBase = vmesa->regMMIOBase;
+    
+    pnBuf = (GLuint *)(buf->index + buf->offset);
+    pnEnd = (GLuint *)((GLuint)pnBuf + buf->size);     
+    
     /*=* [DBG] make draw to front buffer *=*/
     if(DRAW_FRONT)
        vmesa->glCtx->Color._DrawDestMask[0] = __GL_FRONT_BUFFER_MASK;
     
     if (vmesa->glCtx->Color._DrawDestMask[0] == __GL_BACK_BUFFER_MASK) {
-       
        *vb++ = HC_HEADER2;
        *vb++ = (HC_ParaType_NotTex << 16);
+         
        if (vmesa->driDrawable->w == 0 || vmesa->driDrawable->h == 0) {
            *vb++ = (HC_SubA_HClipTB << 24) | 0x0;
            *vb++ = (HC_SubA_HClipLR << 24) | 0x0;
@@ -1493,7 +1344,8 @@ int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd)
            *vb++ = ((HC_SubA_HClipTB << 24) | (0x0 << 12) | vmesa->driDrawable->h);
            *vb++ = ((HC_SubA_HClipLR << 24) | (vmesa->drawXoff << 12) | (vmesa->driDrawable->w + vmesa->drawXoff));
        }
-
+       
+       /*=* John Sheng [2003.6.16] fix pci path *=*/
        {    
            GLuint pitch, format, offset;
         
@@ -1502,11 +1354,9 @@ int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd)
            }           
            else if (vmesa->viaScreen->bitsPerPixel == 0x10) {
                format = HC_HDBFM_RGB565;
-           }
+           }           
            else
-           {
                return -1;
-           }
 
            offset = vmesa->back.offset;
            pitch = vmesa->back.pitch;
@@ -1517,79 +1367,73 @@ int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd)
            *vb++ = 0xcccccccc;
        }
        
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBstL << 24) |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBendL << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpH << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpL << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFFFFFF) |
-           HC_HAGPBpID_STOP;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-                ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-                ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24 |
-                HC_HAGPCMNT_MASK;
+       bufI.buf = (char *) pnBuf;
+       bufI.size = buf->size;
+
+       /*
+        * If AGP is enabled, try it. Otherwise or if it fails, use PCI MMIO.
+        */
+       
+       ret = 1;
+       if (vmesa->useAgp) {
+
+           /*
+            * Prevent command regulator from lagging to far behind by waiting.
+            * Otherwise some applications become unresponsive and jumpy.
+            * The VIA_CMDBUF_MAX_LAG size may be tuned. We could also wait for idle
+            * but that would severely lower performance of some very important
+            * applications. (for example glxgears :).
+            */
+
+           bSiz.func = VIA_CMDBUF_LAG;
+           bSiz.wait = 1;
+           bSiz.size = VIA_CMDBUF_MAX_LAG;
+           while ( -EAGAIN == (ret = drmCommandWriteRead(vmesa->driFd, DRM_VIA_CMDBUF_SIZE, 
+                                                         &bSiz, sizeof(bSiz))));
+           if (ret) 
+               _mesa_error(vmesa->glCtx, GL_INVALID_OPERATION, "viaCommandBufferLag"); 
+           while ( -EAGAIN == (ret = drmCommandWrite(vmesa->driFd, DRM_VIA_CMDBUFFER, 
+                                                     &bufI, sizeof(bufI))));
+       }
+       if (ret) {
+           if (vmesa->useAgp) WAIT_IDLE;
+           if (drmCommandWrite(vmesa->driFd, DRM_VIA_PCICMD, &bufI, sizeof(bufI))) {
+               _mesa_error(vmesa->glCtx, GL_INVALID_OPERATION, "viaCommandBufferFlush");
+           }
+       }
     }
     else {
        GLuint *head;
        GLuint clipL, clipR, clipT, clipB;
        drm_clip_rect_t *b = vmesa->sarea->boxes;
+       GLuint *pnTmp;
+       
        *vb++ = HC_HEADER2;
        *vb++ = (HC_ParaType_NotTex << 16);
-       head = vb;
-       
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBstL << 24) |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBendL << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpH << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpL << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFFFFFF) |
-           HC_HAGPBpID_STOP;
        
-       for (i = 0; i < vmesa->sarea->nbox; i++) {        
-           if (1) {
-               volatile GLuint *pnEngBase = vmesa->regEngineStatus;
-               int nStatus;
+       head = vb;
+       pnTmp = pnBuf;
                
-               while (1) {
-                   nStatus = *pnEngBase;
-                   if ((nStatus & 0xFFFEFFFF) == 0x00020000)
-                       break;
-               }
-           }
-           
+       for (i = 0; i < vmesa->sarea->nbox; i++) {        
            clipL = b->x1 + vmesa->drawXoff;
-           clipR = b->x2;          
+           clipR = b->x2 + vmesa->drawXoff; /* FIXME: is this correct? */
            clipT = b->y1;
            clipB = b->y2;
-#ifdef DEBUG
-           if (VIA_DEBUG) fprintf(stderr, "clip = %d\n", i);
-#endif
+           
            if (vmesa->driDrawable->w == 0 || vmesa->driDrawable->h == 0) {
-
                *vb = (HC_SubA_HClipTB << 24) | 0x0;
                vb++;
-               
                *vb = (HC_SubA_HClipLR << 24) | 0x0;
                vb++;
            }
            else {
                *vb = (HC_SubA_HClipTB << 24) | (clipT << 12) | clipB;
                vb++;
-               
                *vb = (HC_SubA_HClipLR << 24) | (clipL << 12) | clipR;
                vb++;
            }
-
+           
+           /*=* John Sheng [2003.6.16] fix pci path *=*/
            {    
                GLuint pitch, format, offset;
                GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
@@ -1598,10 +1442,10 @@ int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd)
                    format = HC_HDBFM_ARGB8888;
                }           
                else if (vmesa->viaScreen->bitsPerPixel == 0x10) {
-                   format = HC_HDBFM_RGB565;
+                   format = HC_HDBFM_RGB565;
                }           
                else
-                       return -1;
+                   return -1;
         
                pitch = vmesa->front.pitch;
                offset = vmesa->viaScreen->fbOffset + (vmesa->drawY * pitch + vmesa->drawX * bytePerPixel);
@@ -1612,31 +1456,39 @@ int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd)
                *vb++ = ((HC_SubA_HDBFM << 24) | HC_HDBLoc_Local | format | pitch);            
                *vb++ = 0xcccccccc;
            }
-           *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-                ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-                ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24 |
-                HC_HAGPCMNT_MASK;
-#ifdef DEBUG           
-           if (VIA_DEBUG) {
-               GLuint i;
-               GLuint *data = (GLuint *)vmesa->dmaAddr;
-               for (i = 0; i < vmesa->dmaLow; i += 16) {
-                   fprintf(stderr, "%08x  ", *data++);
-                   fprintf(stderr, "%08x  ", *data++);
-                   fprintf(stderr, "%08x  ", *data++);
-                   fprintf(stderr, "%08x\n", *data++);
+           
+           pnBuf = pnTmp;
+           
+           bufI.buf = (char *) pnBuf;
+           bufI.size = buf->size;
+           ret = 1;
+           if (vmesa->useAgp) {
+               bSiz.func = VIA_CMDBUF_LAG;
+               bSiz.wait = 1;
+               bSiz.size = VIA_CMDBUF_MAX_LAG;
+               while ( -EAGAIN == (ret = drmCommandWriteRead(vmesa->driFd, DRM_VIA_CMDBUF_SIZE, 
+                                                             &bSiz, sizeof(bSiz))));
+               if (ret) 
+                   _mesa_error(vmesa->glCtx, GL_INVALID_OPERATION, "viaCommandBufferLag"); 
+                   while ( -EAGAIN == (ret = drmCommandWrite(vmesa->driFd, DRM_VIA_CMDBUFFER, 
+                                                         &bufI, sizeof(bufI))));
+           }
+           
+           if (ret) {
+               if (vmesa->useAgp) WAIT_IDLE;
+               if (drmCommandWrite(vmesa->driFd, DRM_VIA_PCICMD, &bufI, sizeof(bufI))) {
+                   _mesa_error(vmesa->glCtx, GL_INVALID_OPERATION, "viaCommandBufferFlush");
                }
-               fprintf(stderr, "******************************************\n");
            }
-#endif
+
            b++;        
            vb = head;
        }
-    }
 
-#ifdef DEBUG
+    }
+    /*=* John Sheng [2003.6.20] debug pci *=*/
     if (VIA_DEBUG) {
-        volatile GLuint *pnEngBase = (volatile GLuint *)((GLuint)pnMMIOBase + 0x400);
+        GLuint *pnEngBase = (GLuint *)((GLuint)pnMMIOBase + 0x400);
         int nStatus;
        int i = 0;
 
@@ -1648,10 +1500,18 @@ int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd)
            else {
                GLuint j;
                GLuint *data;
-               /* dump current command buffer */
+               GLuint k;
+               GLuint *ES;
+
                data = (GLuint *)vmesa->dmaAddr;
+               ES = pnEngBase;
 
                if (i == 500000) {
+                   for (k =0 ; k < 35; k++) {
+                       fprintf(stderr, "%02xh - %02xh\n", k*4 + 3, k*4);
+                       fprintf(stderr, "%08x\n", *ES);
+                       ES++;
+                   }
                    fprintf(stderr, "current command buffer");
                    fprintf(stderr, "i = %d\n", i);
                    for (j = 0; j < vmesa->dmaLow; j += 16) {
@@ -1661,538 +1521,7 @@ int flush_agp(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd)
                        fprintf(stderr, "%08x\n", *data++);
                    }
                }
-               /* dump previous command buffer */
-               if (vmesa->dmaIndex) {
-                   data = (GLuint *)vmesa->dma[0].map;
-               }
-               else {
-                   data = (GLuint *)vmesa->dma[1].map;
-               }
-               if (i == 500000) {
-                   fprintf(stderr, "previous command buffer");
-                   fprintf(stderr, "i = %d\n", i);
-                   for (j = 0; j < dmaLow; j += 16) {
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x\n", *data++);
-                   }
-               }
-           }
-           i++;
-        }
-    }
-#endif
-    dmaLow = vmesa->dmaLow; 
-    return 0;
-}
-
-int flush_agp_saam(viaContextPtr vmesa, drm_via_flush_agp_t* agpCmd) 
-{   
-    GLuint *pnAGPCurrentPhysStart;
-    GLuint *pnAGPCurrentPhysEnd;
-    GLuint *pnAGPCurrentStart;
-    GLuint *pnAGPCurrentEnd;
-    volatile GLuint *pnMMIOBase;
-    volatile GLuint *pnEngBaseTranSet;
-    volatile GLuint *pnEngBaseTranSpace;
-    GLuint *agpBase;
-    GLuint ofs = vmesa->dma[vmesa->dmaIndex].offset;
-    GLuint *vb = (GLuint *)vmesa->dmaAddr; 
-    GLuint i = 0;
-    
-    pnMMIOBase = vmesa->regMMIOBase;
-    pnEngBaseTranSet = vmesa->regTranSet;
-    pnEngBaseTranSpace = vmesa->regTranSpace;
-    *pnEngBaseTranSet = (0x0010 << 16);
-    agpBase = vmesa->agpBase;
-
-    if (!agpCmd->size) {
-        return -1;
-    }  
-
-    {
-        volatile GLuint *pnEngBase = vmesa->regEngineStatus;
-        int nStatus;
-       
-        while (1) {
-            nStatus = *pnEngBase;
-           if ((nStatus & 0xFFFEFFFF) == 0x00020000)
-               break;
-           i++;
-        }
-    }
-
-    pnAGPCurrentStart = (GLuint *)(ofs + agpCmd->offset);
-    pnAGPCurrentEnd = (GLuint *)((GLuint)pnAGPCurrentStart + vmesa->dmaHigh);
-    pnAGPCurrentPhysStart = (GLuint *)( (GLuint)pnAGPCurrentStart + (GLuint)agpBase );
-    pnAGPCurrentPhysEnd = (GLuint *)( (GLuint)pnAGPCurrentEnd + (GLuint)agpBase );
-
-    /*=* [DBG] make draw to front buffer *=*/
-    if(DRAW_FRONT)
-       vmesa->glCtx->Color._DrawDestMask[0] = __GL_FRONT_BUFFER_MASK;
-    
-    if (vmesa->glCtx->Color._DrawDestMask[0] == __GL_BACK_BUFFER_MASK) {
-       
-       *vb++ = HC_HEADER2;
-       *vb++ = (HC_ParaType_NotTex << 16);
-       if (vmesa->driDrawable->w == 0 || vmesa->driDrawable->h == 0) {
-           *vb++ = (HC_SubA_HClipTB << 24) | 0x0;
-           *vb++ = (HC_SubA_HClipLR << 24) | 0x0;
-       }
-       else {
-           *vb++ = ((HC_SubA_HClipTB << 24) | (0x0 << 12) | vmesa->driDrawable->h);
-           *vb++ = ((HC_SubA_HClipLR << 24) | (vmesa->drawXoff << 12) | (vmesa->driDrawable->w + vmesa->drawXoff));
-       }
-
-       {    
-           GLuint pitch, format, offset;
-        
-           if (vmesa->viaScreen->bitsPerPixel == 0x20) {
-               format = HC_HDBFM_ARGB8888;
-           }           
-           else if (vmesa->viaScreen->bitsPerPixel == 0x10) {
-               format = HC_HDBFM_RGB565;
-           }           
-           else
-               return -1;
-        
-           offset = vmesa->back.offset;
-           pitch = vmesa->back.pitch;
-            
-           *vb++ = ((HC_SubA_HDBBasL << 24) | (offset & 0xFFFFFF));
-           *vb++ = ((HC_SubA_HDBBasH << 24) | ((offset & 0xFF000000)) >> 24);      
-           *vb++ = ((HC_SubA_HDBFM << 24) | HC_HDBLoc_Local | format | pitch);            
-           *vb++ = 0xcccccccc;
-       }
-       
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBstL << 24) |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBendL << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpH << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpL << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFFFFFF) |
-           HC_HAGPBpID_STOP;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-                ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-                ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24 |
-                HC_HAGPCMNT_MASK;
-    }
-    else {
-       GLuint *head;
-       GLuint clipL, clipR, clipT, clipB;
-       drm_clip_rect_t *b = vmesa->sarea->boxes;
-       *vb++ = HC_HEADER2;
-       *vb++ = (HC_ParaType_NotTex << 16);
-       head = vb;
-       
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBstL << 24) |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBendL << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFFFFFF);
-       *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-           ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-           ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpH << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFF000000) >> 24;
-       *pnEngBaseTranSpace = (HC_SubA_HAGPBpL << 24) |
-           ((GLuint)((GLbyte *)pnAGPCurrentPhysStart + agpCmd->size - 4) & 0xFFFFFF) |
-           HC_HAGPBpID_STOP;
-       
-       for (i = 0; i < vmesa->sarea->nbox; i++) {        
-           if (1) {
-               volatile GLuint *pnEngBase = vmesa->regEngineStatus;
-               int nStatus;
-               
-               while (1) {
-                   nStatus = *pnEngBase;
-                   if ((nStatus & 0xFFFEFFFF) == 0x00020000)
-                       break;
-               }
-           }
-           
-           clipL = b->x1 + vmesa->drawXoff;
-           clipR = b->x2;
-           clipT = b->y1;
-           clipB = b->y2;
-#ifdef DEBUG
-           if (VIA_DEBUG) fprintf(stderr, "clip = %d\n", i);
-#endif
-           if (vmesa->driDrawable->w == 0 || vmesa->driDrawable->h == 0) {
-
-               *vb = (HC_SubA_HClipTB << 24) | 0x0;
-               vb++;
-               
-               *vb = (HC_SubA_HClipLR << 24) | 0x0;
-               vb++;
-           }
-           else {
-               *vb = (HC_SubA_HClipTB << 24) | (clipT << 12) | clipB;
-               vb++;
-               
-               *vb = (HC_SubA_HClipLR << 24) | (clipL << 12) | clipR;
-               vb++;
-           }
-
-           {    
-               GLuint pitch, format, offset;
-               GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
-        
-               if (vmesa->viaScreen->bitsPerPixel == 0x20) {
-                   format = HC_HDBFM_ARGB8888;
-               }           
-               else if (vmesa->viaScreen->bitsPerPixel == 0x10) {
-                   format = HC_HDBFM_RGB565;
-               }           
-               else
-                       return -1;
-        
-               pitch = vmesa->front.pitch;
-               offset = vmesa->viaScreen->fbOffset + (vmesa->drawY * pitch + vmesa->drawX * bytePerPixel);
-               offset = offset & 0xffffffe0;
-            
-               *vb++ = ((HC_SubA_HDBBasL << 24) | (offset & 0xFFFFFF));
-               *vb++ = ((HC_SubA_HDBBasH << 24) | ((offset & 0xFF000000)) >> 24);      
-               *vb++ = ((HC_SubA_HDBFM << 24) | HC_HDBLoc_Local | format | pitch);            
-               *vb++ = 0xcccccccc;
-           }
-           *pnEngBaseTranSpace = (HC_SubA_HAGPCMNT << 24) |
-                ((GLuint)(pnAGPCurrentPhysEnd) & 0xFF000000) >> 16 |
-                ((GLuint)(pnAGPCurrentPhysStart) & 0xFF000000) >> 24 |
-                HC_HAGPCMNT_MASK;
-#ifdef DEBUG           
-           if (VIA_DEBUG) {
-               GLuint i;
-               GLuint *data = (GLuint *)vmesa->dmaAddr;
-               for (i = 0; i < vmesa->dmaLow; i += 16) {
-                   fprintf(stderr, "%08x  ", *data++);
-                   fprintf(stderr, "%08x  ", *data++);
-                   fprintf(stderr, "%08x  ", *data++);
-                   fprintf(stderr, "%08x\n", *data++);
-               }
-               fprintf(stderr, "******************************************\n");
-           }
-#endif
-           b++;        
-           vb = head;
-       }
-    }
-    
-#ifdef DEBUG
-    if (VIA_DEBUG) {
-        volatile GLuint *pnEngBase = (GLuint *)((GLuint)pnMMIOBase + 0x400);
-        int nStatus;
-       int i = 0;
-
-        while (1) {
-            nStatus = *pnEngBase;
-           if ((nStatus & 0xFFFEFFFF) == 0x00020000) {
-               break;
-           }
-           else {
-               GLuint j;
-               GLuint *data;
-               /* dump current command buffer */
-               data = (GLuint *)vmesa->dmaAddr;
-
-               if (i == 500000) {
-                   fprintf(stderr, "current command buffer");
-                   fprintf(stderr, "i = %d\n", i);
-                   for (j = 0; j < vmesa->dmaLow; j += 16) {
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x\n", *data++);
-                   }
-               }
-               /* dump previous command buffer */
-               if (vmesa->dmaIndex) {
-                   data = (GLuint *)vmesa->dma[0].map;
-               }
-               else {
-                   data = (GLuint *)vmesa->dma[1].map;
-               }
-               if (i == 500000) {
-                   fprintf(stderr, "previous command buffer");
-                   fprintf(stderr, "i = %d\n", i);
-                   for (j = 0; j < dmaLow; j += 16) {
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x\n", *data++);
-                   }
-               }
-           }
-           i++;
-        }
-    }
-#endif
-    dmaLow = vmesa->dmaLow; 
-    return 0;
-}
-
-int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) 
-
-{
-    GLuint *pnBuf;
-    GLuint *pnEnd;
-    volatile GLuint *pnMMIOBase;
-    volatile GLuint *pnEngBaseTranSet;
-    volatile GLuint *pnEngBaseTranSpace;
-    GLuint uCheck2DCmd = GL_TRUE;
-    GLuint addr;
-    GLuint *vb = (GLuint *)vmesa->dmaAddr; 
-    GLuint i = 0;
-    
-    pnMMIOBase = vmesa->regMMIOBase;
-    pnEngBaseTranSet = vmesa->regTranSet;
-    pnEngBaseTranSpace = vmesa->regTranSpace;
-    
-    pnBuf = (GLuint *)(buf->index + buf->offset);
-    pnEnd = (GLuint *)((GLuint)pnBuf + buf->size);     
-    
-    /*=* [DBG] make draw to front buffer *=*/
-    if(DRAW_FRONT)
-       vmesa->glCtx->Color._DrawDestMask[0] = __GL_FRONT_BUFFER_MASK;
-    
-    
-    /*=* John Sheng [2003.6.20] fix pci *=*/
-    {
-        volatile GLuint *pnEngBase = vmesa->regEngineStatus;
-        int nStatus;
-       
-        while (1) {
-            nStatus = *pnEngBase;
-           if ((nStatus & 0xFFFEFFFF) == 0x00020000)
-               break;
-           i++;
-        }
-    }
-    /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-    /*=* Disable VQ *=*/
-    if (vmesa->VQEnable)
-    {
-       WAIT_IDLE
-       *vmesa->regTranSet = 0x00fe0000;
-       *vmesa->regTranSet = 0x00fe0000;
-       *vmesa->regTranSpace = 0x00000004;
-       *vmesa->regTranSpace = 0x40008c0f;
-       *vmesa->regTranSpace = 0x44000000;
-       *vmesa->regTranSpace = 0x45080c04;
-       *vmesa->regTranSpace = 0x46800408;
-       vmesa->VQEnable = 0;
-    }
-    if (vmesa->glCtx->Color._DrawDestMask[0] == __GL_BACK_BUFFER_MASK) {
-       *vb++ = HC_HEADER2;
-       *vb++ = (HC_ParaType_NotTex << 16);
-       
-       if (vmesa->driDrawable->w == 0 || vmesa->driDrawable->h == 0) {
-           *vb++ = (HC_SubA_HClipTB << 24) | 0x0;
-           *vb++ = (HC_SubA_HClipLR << 24) | 0x0;
-       }
-       else {
-           *vb++ = ((HC_SubA_HClipTB << 24) | (0x0 << 12) | vmesa->driDrawable->h);
-           *vb++ = ((HC_SubA_HClipLR << 24) | (vmesa->drawXoff << 12) | (vmesa->driDrawable->w + vmesa->drawXoff));
-       }
-       
-       /*=* John Sheng [2003.6.16] fix pci path *=*/
-       {    
-           GLuint pitch, format, offset;
-        
-           if (vmesa->viaScreen->bitsPerPixel == 0x20) {
-               format = HC_HDBFM_ARGB8888;
-           }           
-           else if (vmesa->viaScreen->bitsPerPixel == 0x10) {
-               format = HC_HDBFM_RGB565;
-           }           
-           else
-               return -1;
-
-           offset = vmesa->back.offset;
-           pitch = vmesa->back.pitch;
-           
-           *vb++ = ((HC_SubA_HDBBasL << 24) | (offset & 0xFFFFFF));
-           *vb++ = ((HC_SubA_HDBBasH << 24) | ((offset & 0xFF000000)) >> 24);      
-           *vb++ = ((HC_SubA_HDBFM << 24) | HC_HDBLoc_Local | format | pitch);            
-           *vb++ = 0xcccccccc;
-       }
-       
-       while (pnBuf != pnEnd) {        
-           if (*pnBuf == HALCYON_HEADER2) {
-               pnBuf++;
-               if (*pnBuf == HALCYON_SUB_ADDR0) {
-                   *pnEngBaseTranSet = *pnBuf;
-                   pnBuf++;
-                   uCheck2DCmd = GL_FALSE;
-               }
-               else {
-                   *pnEngBaseTranSet = *pnBuf;
-                   pnBuf++;
-                   uCheck2DCmd = GL_TRUE;
-               }
-           }
-           else if (uCheck2DCmd && ((*pnBuf&HALCYON_HEADER1MASK)==HALCYON_HEADER1)) {
-               addr = ((*pnBuf)&0x0000001f) << 2;
-               pnBuf++;
-               *((GLuint*)((GLuint)pnMMIOBase+addr)) = *pnBuf;
-               pnBuf++;
-           }
-           else if ((*pnBuf&HALCYON_FIREMASK) == HALCYON_FIRECMD) {
-               *pnEngBaseTranSpace = *pnBuf;
-               pnBuf++;
-               if ((pnBuf!=pnEnd)&&((*pnBuf&HALCYON_FIREMASK)==HALCYON_FIRECMD))
-                   pnBuf++;
-               if ((*pnBuf&HALCYON_CMDBMASK) != HC_ACMD_HCmdB)
-                   uCheck2DCmd = GL_TRUE;
-           }
-           else {
-               *pnEngBaseTranSpace = *pnBuf;
-               pnBuf++;
-           }
-       }
-    }
-    else {
-       GLuint *head;
-       GLuint clipL, clipR, clipT, clipB;
-       drm_clip_rect_t *b = vmesa->sarea->boxes;
-       GLuint *pnTmp;
-       
-       *vb++ = HC_HEADER2;
-       *vb++ = (HC_ParaType_NotTex << 16);
-       
-       head = vb;
-       pnTmp = pnBuf;
-               
-       for (i = 0; i < vmesa->sarea->nbox; i++) {        
-           clipL = b->x1 + vmesa->drawXoff;
-           clipR = b->x2 + vmesa->drawXoff;
-           clipT = b->y1;
-           clipB = b->y2;
-           
-           if (vmesa->driDrawable->w == 0 || vmesa->driDrawable->h == 0) {
-               *vb = (HC_SubA_HClipTB << 24) | 0x0;
-               vb++;
-               *vb = (HC_SubA_HClipLR << 24) | 0x0;
-               vb++;
-           }
-           else {
-               *vb = (HC_SubA_HClipTB << 24) | (clipT << 12) | clipB;
-               vb++;
-               *vb = (HC_SubA_HClipLR << 24) | (clipL << 12) | clipR;
-               vb++;
-           }
-           
-           /*=* John Sheng [2003.6.16] fix pci path *=*/
-           {    
-               GLuint pitch, format, offset;
-               GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
-        
-               if (vmesa->viaScreen->bitsPerPixel == 0x20) {
-                   format = HC_HDBFM_ARGB8888;
-               }           
-               else if (vmesa->viaScreen->bitsPerPixel == 0x10) {
-                   format = HC_HDBFM_RGB565;
-               }           
-               else
-                       return -1;
-        
-               pitch = vmesa->front.pitch;
-               offset = vmesa->viaScreen->fbOffset + (vmesa->drawY * pitch + vmesa->drawX * bytePerPixel);
-               offset = offset & 0xffffffe0;
-            
-               *vb++ = ((HC_SubA_HDBBasL << 24) | (offset & 0xFFFFFF));
-               *vb++ = ((HC_SubA_HDBBasH << 24) | ((offset & 0xFF000000)) >> 24);      
-               *vb++ = ((HC_SubA_HDBFM << 24) | HC_HDBLoc_Local | format | pitch);            
-               *vb++ = 0xcccccccc;
-           }
-           
-           pnBuf = pnTmp;
-           
-           while (pnBuf != pnEnd) {    
-               if (*pnBuf == HALCYON_HEADER2) {
-                   pnBuf++;
-                   if (*pnBuf == HALCYON_SUB_ADDR0) {
-                       *pnEngBaseTranSet = *pnBuf;
-                       pnBuf++;
-                       uCheck2DCmd = GL_FALSE;
-                   }
-                   else {
-                       *pnEngBaseTranSet = *pnBuf;
-                       pnBuf++;
-                       uCheck2DCmd = GL_TRUE;
-                   }
-               }
-               else if (uCheck2DCmd && ((*pnBuf&HALCYON_HEADER1MASK)==HALCYON_HEADER1)) {
-                   addr = ((*pnBuf)&0x0000001f) << 2;
-                   pnBuf++;
-                   *((GLuint*)((GLuint)pnMMIOBase+addr)) = *pnBuf;
-                   pnBuf++;
-               }
-               else if ((*pnBuf&HALCYON_FIREMASK) == HALCYON_FIRECMD) {
-                   *pnEngBaseTranSpace = *pnBuf;
-                   pnBuf++;
-                   if ((pnBuf!=pnEnd)&&((*pnBuf&HALCYON_FIREMASK)==HALCYON_FIRECMD))
-                       pnBuf++;
-                   if ((*pnBuf&HALCYON_CMDBMASK) != HC_ACMD_HCmdB)
-                       uCheck2DCmd = GL_TRUE;
-               }
-               else {
-                   *pnEngBaseTranSpace = *pnBuf;
-                   pnBuf++;
-               }
-           }
-           b++;        
-           vb = head;
-       }
-    }
-    /*=* John Sheng [2003.6.20] debug pci *=*/
-    if (VIA_DEBUG) {
-        GLuint *pnEngBase = (GLuint *)((GLuint)pnMMIOBase + 0x400);
-        int nStatus;
-       int i = 0;
-
-        while (1) {
-            nStatus = *pnEngBase;
-           if ((nStatus & 0xFFFEFFFF) == 0x00020000) {
-               break;
-           }
-           else {
-               GLuint j;
-               GLuint *data;
-               /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-               GLuint k;
-               GLuint *ES;
-
-               data = (GLuint *)vmesa->dmaAddr;
-               ES = pnEngBase;
-
-               if (i == 500000) {
-                   /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-                   for (k =0 ; k < 35; k++) {
-                       fprintf(stderr, "%02xh - %02xh\n", k*4 + 3, k*4);
-                       fprintf(stderr, "%08x\n", *ES);
-                       ES++;
-                   }
-                   fprintf(stderr, "current command buffer");
-                   fprintf(stderr, "i = %d\n", i);
-                   for (j = 0; j < vmesa->dmaLow; j += 16) {
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x  ", *data++);
-                       fprintf(stderr, "%08x\n", *data++);
-                   }
-               }
-               if (vmesa->dmaIndex) {
-                   data = (GLuint *)vmesa->dma[0].map;
-               }
-               else {
-                   data = (GLuint *)vmesa->dma[1].map;
-               }
+               data = (GLuint *)vmesa->dma;
                if (i == 500000) {
                    fprintf(stderr, "previous command buffer");
                    fprintf(stderr, "i = %d\n", i);
index 210248ff4beec53e5c474d70befceaafe67b960a..9a97eeca800ad2a039a14ffac8aa54d6de313db3 100644 (file)
@@ -179,7 +179,7 @@ static GLboolean via_run_fastrender(GLcontext *ctx,
     tnl->Driver.Render.Finish(ctx);
     
     /*=* DBG - viewperf7.0 : fix command buffer overflow *=*/
-    if (vmesa->dmaLow > (vmesa->dma[0].size / 2))
+    if (vmesa->dmaLow > (VIA_DMA_BUFSIZ / 2))
        viaFlushPrims(vmesa);
 #ifdef DEBUG
     if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);    
@@ -468,7 +468,7 @@ static GLboolean via_run_render(GLcontext *ctx,
     }*/
     
     /*=* DBG viewperf7.0 : fix command buffer overflow *=*/
-    if (vmesa->dmaLow > (vmesa->dma[0].size / 2))
+    if (vmesa->dmaLow > (VIA_DMA_BUFSIZ / 2))
        viaFlushPrims(vmesa);
 #ifdef DEBUG
     if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);    
index 283dec140366fccd8c2d28624a80166223547c52..192d62e647e5e1710917944577b3e774ca0ccfa6 100644 (file)
@@ -95,8 +95,6 @@ viaInitDriver(__DRIscreenPrivate *sPriv)
 #ifdef USE_XINERAMA
     viaScreen->drixinerama = gDRIPriv->drixinerama;
 #endif
-    /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
-    viaScreen->VQEnable = gDRIPriv->VQEnable;
 #ifdef DEBUG    
     if (VIA_DEBUG) {
        fprintf(stderr, "deviceID = %08x\n", viaScreen->deviceID);
@@ -390,7 +388,7 @@ void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc
    __DRIscreenPrivate *psp;
    static const __DRIversion ddx_expected = { 4, 0, 0 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
-   static const __DRIversion drm_expected = { 2, 0, 0 };
+   static const __DRIversion drm_expected = { 2, 3, 0 };
 
    if ( ! driCheckDriDdxDrmVersions2( "Unichrome",
                                      dri_version, & dri_expected,
index 8a2b6b1abc12aa0ec81c38c45398ac05e8bdd2ac..c8cc1347eef1df1311fd1e78fb20c9c42cd90f02 100644 (file)
@@ -253,7 +253,7 @@ static void viaDeleteTexture(GLcontext *ctx, struct gl_texture_object *texObj)
         if (vmesa) {
            /*=* John Sheng [2003.7.18] viewperf frames/sec *=*/
            /*VIA_FIREVERTICES(vmesa);*/
-           if (vmesa->dma[0].map) { /* imply vmesa is not under destroying */
+           if (vmesa->dma) { /* imply vmesa is not under destroying */
                VIA_FIREVERTICES(vmesa);
            }
            viaDestroyTexObj(vmesa, t);
index 50fc6b9cbe448cb34a913463ad5b4e704f36c5c6..ebe368b2b7e3c2e05b3d9d44077e72de448e4c16 100644 (file)
@@ -131,3 +131,13 @@ int drmVIAReleaseDMA(int fd, drmVIADMABuf *buf)
     
     return 0;
 }
+
+int drmVIACmdBuffer(int fd, drmVIACommandBuffer *buf)
+{
+    if (ioctl(fd, 0x48, buf ) < 0) {
+        return -errno;
+    }
+    else
+        return 0;
+}
+  
index 4b64579336b77f43e26712a9c236ef512421793a..e8c62bf4a7c108081d287738cc04f396e23d7c24 100644 (file)
 #ifndef __XF86DRI_VIA_H__
 #define __XF86DRI_VIA_H__
 
+#define DRM_VIA_ALLOCMEM       0x00
+#define DRM_VIA_FREEMEM                0x01
+#define DRM_VIA_AGP_INIT       0x02
+#define DRM_VIA_FB_INIT                0x03
+#define DRM_VIA_MAP_INIT       0x04
+#define DRM_VIA_DEC_FUTEX       0x05
+#define NOT_USED
+#define DRM_VIA_DMA_INIT       0x07
+#define DRM_VIA_CMDBUFFER      0x08
+#define DRM_VIA_FLUSH          0x09
+#define DRM_VIA_PCICMD         0x0a
+#define DRM_VIA_CMDBUF_SIZE    0x0b
+
 typedef struct {
     unsigned long sarea_priv_offset;
     unsigned long fb_offset;
@@ -45,10 +58,44 @@ typedef struct {
     unsigned long *address;
 } drmVIADMABuf;
 
+typedef struct {
+  char *buf;
+  unsigned long size;
+} drmVIACommandBuffer;
+
+typedef struct {
+       enum {
+               VIA_CMDBUF_SPACE = 0x01,
+               VIA_CMDBUF_LAG = 0x02
+       } func;
+       int wait;
+       unsigned size;
+} drmVIACmdBufSize;
+
+typedef struct {
+       unsigned int offset;
+       unsigned int size;
+       unsigned long index;
+       int discard;            /* client is finished with the buffer? */
+} drmVIAFlush;
+
+typedef struct{
+       enum {
+               VIA_INIT_DMA = 0x01,
+               VIA_CLEANUP_DMA = 0x02,
+                VIA_DMA_INITIALIZED = 0x03
+       } func;
+
+       unsigned long offset;
+       unsigned long size;
+       unsigned long reg_pause_addr;
+} drmVIADMAInit;
+
 extern int drmVIAAgpInit(int fd, int offset, int size);
 extern int drmVIAFBInit(int fd, int offset, int size);
 extern int drmVIAInitMAP(int fd, drmVIAInit *info);
 extern int drmVIAAllocateDMA(int fd, drmVIADMABuf *buf);
 extern int drmVIAReleaseDMA(int fd, drmVIADMABuf *buf);
 
+
 #endif