diff options
Diffstat (limited to 'src/mesa/drivers/dri/unichrome/via_ioctl.c')
-rw-r--r-- | src/mesa/drivers/dri/unichrome/via_ioctl.c | 1325 |
1 files changed, 327 insertions, 998 deletions
diff --git a/src/mesa/drivers/dri/unichrome/via_ioctl.c b/src/mesa/drivers/dri/unichrome/via_ioctl.c index 1e210b7b93a..4efa3d9ad57 100644 --- a/src/mesa/drivers/dri/unichrome/via_ioctl.c +++ b/src/mesa/drivers/dri/unichrome/via_ioctl.c @@ -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 @@ -36,7 +36,45 @@ #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,505 +1309,7 @@ void viaDoSwapPBuffers(viaContextPtr vmesa) } -int flush_agp(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 = (volatile 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_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; -} +#define VIA_CMDBUF_MAX_LAG 50000 int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) @@ -1942,16 +1317,13 @@ 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; - + drmVIACommandBuffer bufI; + drmVIACmdBufSize bSiz; + int ret; + pnMMIOBase = vmesa->regMMIOBase; - pnEngBaseTranSet = vmesa->regTranSet; - pnEngBaseTranSpace = vmesa->regTranSpace; pnBuf = (GLuint *)(buf->index + buf->offset); pnEnd = (GLuint *)((GLuint)pnBuf + buf->size); @@ -1960,37 +1332,10 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) 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; @@ -2022,37 +1367,38 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) *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++; + 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"); } } } @@ -2070,7 +1416,7 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) for (i = 0; i < vmesa->sarea->nbox; i++) { clipL = b->x1 + vmesa->drawXoff; - clipR = b->x2 + vmesa->drawXoff; + clipR = b->x2 + vmesa->drawXoff; /* FIXME: is this correct? */ clipT = b->y1; clipB = b->y2; @@ -2099,7 +1445,7 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) format = HC_HDBFM_RGB565; } else - return -1; + return -1; pitch = vmesa->front.pitch; offset = vmesa->viaScreen->fbOffset + (vmesa->drawY * pitch + vmesa->drawX * bytePerPixel); @@ -2113,42 +1459,32 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) 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++; + 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"); } } + b++; vb = head; } + } /*=* John Sheng [2003.6.20] debug pci *=*/ if (VIA_DEBUG) { @@ -2164,7 +1500,6 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) else { GLuint j; GLuint *data; - /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/ GLuint k; GLuint *ES; @@ -2172,7 +1507,6 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) 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); @@ -2187,12 +1521,7 @@ int flush_sys(viaContextPtr vmesa, drm_via_flush_sys_t* buf) 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); |