s3v_dga.c revision eb61724e
11d54945dSmrg 21d54945dSmrg/* 31d54945dSmrgCopyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 41d54945dSmrg 51d54945dSmrgPermission is hereby granted, free of charge, to any person obtaining a copy of 61d54945dSmrgthis software and associated documentation files (the "Software"), to deal in 71d54945dSmrgthe Software without restriction, including without limitation the rights to 81d54945dSmrguse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 91d54945dSmrgof the Software, and to permit persons to whom the Software is furnished to do 101d54945dSmrgso, subject to the following conditions: 111d54945dSmrg 121d54945dSmrgThe above copyright notice and this permission notice shall be included in all 131d54945dSmrgcopies or substantial portions of the Software. 141d54945dSmrg 151d54945dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161d54945dSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 171d54945dSmrgNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 181d54945dSmrgXFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 191d54945dSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 201d54945dSmrgWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 211d54945dSmrg 221d54945dSmrgExcept as contained in this notice, the name of the XFree86 Project shall not 231d54945dSmrgbe used in advertising or otherwise to promote the sale, use or other dealings 241d54945dSmrgin this Software without prior written authorization from the XFree86 Project. 251d54945dSmrg*/ 261d54945dSmrg 271d54945dSmrg/* 281d54945dSmrgCopyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 291d54945dSmrg 301d54945dSmrgPermission is hereby granted, free of charge, to any person obtaining a copy of 311d54945dSmrgthis software and associated documentation files (the "Software"), to deal in 321d54945dSmrgthe Software without restriction, including without limitation the rights to 331d54945dSmrguse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 341d54945dSmrgof the Software, and to permit persons to whom the Software is furnished to do 351d54945dSmrgso, subject to the following conditions: 361d54945dSmrg 371d54945dSmrgThe above copyright notice and this permission notice shall be included in all 381d54945dSmrgcopies or substantial portions of the Software. 391d54945dSmrg 401d54945dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 411d54945dSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 421d54945dSmrgNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 431d54945dSmrgXFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 441d54945dSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 451d54945dSmrgWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 461d54945dSmrg 471d54945dSmrgExcept as contained in this notice, the name of the XFree86 Project shall not 481d54945dSmrgbe used in advertising or otherwise to promote the sale, use or other dealings 491d54945dSmrgin this Software without prior written authorization from the XFree86 Project. 501d54945dSmrg*/ 511d54945dSmrg 521d54945dSmrg/* 531d54945dSmrg * file: s3v_dga.c 541d54945dSmrg * ported from mga 551d54945dSmrg * 561d54945dSmrg */ 571d54945dSmrg 581d54945dSmrg#ifdef HAVE_CONFIG_H 591d54945dSmrg#include "config.h" 601d54945dSmrg#endif 611d54945dSmrg 621d54945dSmrg#include "xf86.h" 631d54945dSmrg#include "xf86_OSproc.h" 641d54945dSmrg#include "xf86Pci.h" 651d54945dSmrg#include "xf86PciInfo.h" 661d54945dSmrg#include "xaa.h" 671d54945dSmrg#include "xaalocal.h" 681d54945dSmrg#include "s3v.h" 69ba85709eSmrg 701d54945dSmrg#include "dgaproc.h" 711d54945dSmrg 721d54945dSmrg 731d54945dSmrgstatic Bool S3V_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **, 741d54945dSmrg int *, int *, int *); 751d54945dSmrgstatic Bool S3V_SetMode(ScrnInfoPtr, DGAModePtr); 761d54945dSmrgstatic int S3V_GetViewport(ScrnInfoPtr); 771d54945dSmrgstatic void S3V_SetViewport(ScrnInfoPtr, int, int, int); 781d54945dSmrgstatic void S3V_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long); 791d54945dSmrgstatic void S3V_BlitRect(ScrnInfoPtr, int, int, int, int, int, int); 801d54945dSmrg/* dummy... */ 81ba85709eSmrg 821d54945dSmrg 831d54945dSmrgstatic 841d54945dSmrgDGAFunctionRec S3V_DGAFuncs = { 851d54945dSmrg S3V_OpenFramebuffer, 861d54945dSmrg NULL, 871d54945dSmrg S3V_SetMode, 881d54945dSmrg S3V_SetViewport, 891d54945dSmrg S3V_GetViewport, 901d54945dSmrg S3VAccelSync, 911d54945dSmrg S3V_FillRect, 921d54945dSmrg S3V_BlitRect, 931d54945dSmrg NULL 941d54945dSmrg /* dummy... MGA_BlitTransRect */ 951d54945dSmrg}; 961d54945dSmrg 971d54945dSmrg 981d54945dSmrgBool 991d54945dSmrgS3VDGAInit(ScreenPtr pScreen) 1001d54945dSmrg{ 1011d54945dSmrg ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 1021d54945dSmrg S3VPtr ps3v = S3VPTR(pScrn); 1031d54945dSmrg DGAModePtr modes = NULL, newmodes = NULL, currentMode; 1041d54945dSmrg DisplayModePtr pMode, firstMode; 1051d54945dSmrg int Bpp = pScrn->bitsPerPixel >> 3; 1061d54945dSmrg int num = 0; 1071d54945dSmrg Bool oneMore; 1081d54945dSmrg 1091d54945dSmrg PVERB5(" S3VDGAInit\n"); 1101d54945dSmrg 1111d54945dSmrg pMode = firstMode = pScrn->modes; 1121d54945dSmrg 1131d54945dSmrg while(pMode) { 1141d54945dSmrg /* The MGA driver wasn't designed with switching depths in 1151d54945dSmrg mind. Subsequently, large chunks of it will probably need 1161d54945dSmrg to be rewritten to accommodate depth changes in DGA mode */ 1171d54945dSmrg 1181d54945dSmrg if(0 /*pScrn->displayWidth != pMode->HDisplay*/) { 1191d54945dSmrg newmodes = xrealloc(modes, (num + 2) * sizeof(DGAModeRec)); 1201d54945dSmrg oneMore = TRUE; 1211d54945dSmrg } else { 1221d54945dSmrg newmodes = xrealloc(modes, (num + 1) * sizeof(DGAModeRec)); 1231d54945dSmrg oneMore = FALSE; 1241d54945dSmrg } 1251d54945dSmrg 1261d54945dSmrg if(!newmodes) { 1271d54945dSmrg xfree(modes); 1281d54945dSmrg return FALSE; 1291d54945dSmrg } 1301d54945dSmrg modes = newmodes; 1311d54945dSmrg 1321d54945dSmrgSECOND_PASS: 1331d54945dSmrg 1341d54945dSmrg currentMode = modes + num; 1351d54945dSmrg num++; 1361d54945dSmrg 1371d54945dSmrg currentMode->mode = pMode; 1381d54945dSmrg currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE; 1391d54945dSmrg if(!ps3v->NoAccel) 1401d54945dSmrg currentMode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT; 1411d54945dSmrg if(pMode->Flags & V_DBLSCAN) 1421d54945dSmrg currentMode->flags |= DGA_DOUBLESCAN; 1431d54945dSmrg if(pMode->Flags & V_INTERLACE) 1441d54945dSmrg currentMode->flags |= DGA_INTERLACED; 1451d54945dSmrg currentMode->byteOrder = pScrn->imageByteOrder; 1461d54945dSmrg currentMode->depth = pScrn->depth; 1471d54945dSmrg currentMode->bitsPerPixel = pScrn->bitsPerPixel; 1481d54945dSmrg currentMode->red_mask = pScrn->mask.red; 1491d54945dSmrg currentMode->green_mask = pScrn->mask.green; 1501d54945dSmrg currentMode->blue_mask = pScrn->mask.blue; 1511d54945dSmrg currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor; 1521d54945dSmrg currentMode->viewportWidth = pMode->HDisplay; 1531d54945dSmrg currentMode->viewportHeight = pMode->VDisplay; 1541d54945dSmrg /* currentMode->xViewportStep = (3 - ps3v->BppShift); */ 1551d54945dSmrg /* always 1 on ViRGE ? */ 1561d54945dSmrg currentMode->xViewportStep = 1; 1571d54945dSmrg currentMode->yViewportStep = 1; 1581d54945dSmrg currentMode->viewportFlags = DGA_FLIP_RETRACE; 1591d54945dSmrg /* currentMode->offset = ps3v->YDstOrg * (pScrn->bitsPerPixel / 8); 1601d54945dSmrg * MGA, 0 for ViRGE */ 1611d54945dSmrg currentMode->offset = 0; 1621d54945dSmrg /* currentMode->address = pMga->FbStart; MGA */ 1631d54945dSmrg currentMode->address = ps3v->FBBase; 1641d54945dSmrg/*cep*/ 1651d54945dSmrg xf86ErrorFVerb(VERBLEV, 1661d54945dSmrg " S3VDGAInit firstone vpWid=%d, vpHgt=%d, Bpp=%d, mdbitsPP=%d\n", 1671d54945dSmrg currentMode->viewportWidth, 1681d54945dSmrg currentMode->viewportHeight, 1691d54945dSmrg Bpp, 1701d54945dSmrg currentMode->bitsPerPixel 1711d54945dSmrg ); 1721d54945dSmrg 1731d54945dSmrg 1741d54945dSmrg if(oneMore) { /* first one is narrow width */ 1751d54945dSmrg currentMode->bytesPerScanline = ((pMode->HDisplay * Bpp) + 3) & ~3L; 1761d54945dSmrg currentMode->imageWidth = pMode->HDisplay; 1771d54945dSmrg /* currentMode->imageHeight = pMga->FbUsableSize / 1781d54945dSmrg currentMode->bytesPerScanline; 1791d54945dSmrg MGA above */ 1801d54945dSmrg currentMode->imageHeight = pMode->VDisplay; 1811d54945dSmrg currentMode->pixmapWidth = currentMode->imageWidth; 1821d54945dSmrg currentMode->pixmapHeight = currentMode->imageHeight; 1831d54945dSmrg currentMode->maxViewportX = currentMode->imageWidth - 1841d54945dSmrg currentMode->viewportWidth; 1851d54945dSmrg /* this might need to get clamped to some maximum */ 1861d54945dSmrg currentMode->maxViewportY = currentMode->imageHeight - 1871d54945dSmrg currentMode->viewportHeight; 1881d54945dSmrg oneMore = FALSE; 1891d54945dSmrg 1901d54945dSmrg/*cep*/ 1911d54945dSmrg xf86ErrorFVerb(VERBLEV, 1921d54945dSmrg " S3VDGAInit imgHgt=%d, ram=%d, bytesPerScanl=%d\n", 1931d54945dSmrg currentMode->imageHeight, 1941d54945dSmrg ps3v->videoRambytes, 1951d54945dSmrg currentMode->bytesPerScanline ); 1961d54945dSmrg 1971d54945dSmrg goto SECOND_PASS; 1981d54945dSmrg } else { 1991d54945dSmrg currentMode->bytesPerScanline = 2001d54945dSmrg ((pScrn->displayWidth * Bpp) + 3) & ~3L; 2011d54945dSmrg currentMode->imageWidth = pScrn->displayWidth; 2021d54945dSmrg /* currentMode->imageHeight = pMga->FbUsableSize / 2031d54945dSmrg currentMode->bytesPerScanline; 2041d54945dSmrg */ 2051d54945dSmrg currentMode->imageHeight = ps3v->videoRambytes / 2061d54945dSmrg currentMode->bytesPerScanline; 2071d54945dSmrg currentMode->pixmapWidth = currentMode->imageWidth; 2081d54945dSmrg currentMode->pixmapHeight = currentMode->imageHeight; 2091d54945dSmrg currentMode->maxViewportX = currentMode->imageWidth - 2101d54945dSmrg currentMode->viewportWidth; 2111d54945dSmrg /* this might need to get clamped to some maximum */ 2121d54945dSmrg currentMode->maxViewportY = currentMode->imageHeight - 2131d54945dSmrg currentMode->viewportHeight; 2141d54945dSmrg } 2151d54945dSmrg 2161d54945dSmrg pMode = pMode->next; 2171d54945dSmrg if(pMode == firstMode) 2181d54945dSmrg break; 2191d54945dSmrg } 2201d54945dSmrg 2211d54945dSmrg ps3v->numDGAModes = num; 2221d54945dSmrg ps3v->DGAModes = modes; 2231d54945dSmrg 2241d54945dSmrg return DGAInit(pScreen, &S3V_DGAFuncs, modes, num); 2251d54945dSmrg} 2261d54945dSmrg 2271d54945dSmrg 2281d54945dSmrgstatic Bool 2291d54945dSmrgS3V_SetMode( 2301d54945dSmrg ScrnInfoPtr pScrn, 2311d54945dSmrg DGAModePtr pMode 2321d54945dSmrg){ 2331d54945dSmrg static int OldDisplayWidth[MAXSCREENS]; 2341d54945dSmrg int index = pScrn->pScreen->myNum; 2351d54945dSmrg 2361d54945dSmrg S3VPtr ps3v = S3VPTR(pScrn); 2371d54945dSmrg 2381d54945dSmrg if(!pMode) { /* restore the original mode */ 2391d54945dSmrg /* put the ScreenParameters back */ 2401d54945dSmrg 2411d54945dSmrg pScrn->displayWidth = OldDisplayWidth[index]; 2421d54945dSmrg 2431d54945dSmrg S3VSwitchMode(index, pScrn->currentMode, 0); 2441d54945dSmrg ps3v->DGAactive = FALSE; 2451d54945dSmrg } else { 2461d54945dSmrg if(!ps3v->DGAactive) { /* save the old parameters */ 2471d54945dSmrg OldDisplayWidth[index] = pScrn->displayWidth; 2481d54945dSmrg 2491d54945dSmrg ps3v->DGAactive = TRUE; 2501d54945dSmrg } 2511d54945dSmrg 2521d54945dSmrg pScrn->displayWidth = pMode->bytesPerScanline / 2531d54945dSmrg (pMode->bitsPerPixel >> 3); 2541d54945dSmrg 2551d54945dSmrg S3VSwitchMode(index, pMode->mode, 0); 2561d54945dSmrg } 2571d54945dSmrg 2581d54945dSmrg return TRUE; 2591d54945dSmrg} 2601d54945dSmrg 2611d54945dSmrg 2621d54945dSmrg 2631d54945dSmrgstatic int 2641d54945dSmrgS3V_GetViewport( 2651d54945dSmrg ScrnInfoPtr pScrn 2661d54945dSmrg){ 2671d54945dSmrg S3VPtr ps3v = S3VPTR(pScrn); 2681d54945dSmrg 2691d54945dSmrg return ps3v->DGAViewportStatus; 2701d54945dSmrg} 2711d54945dSmrg 2721d54945dSmrgstatic void 2731d54945dSmrgS3V_SetViewport( 2741d54945dSmrg ScrnInfoPtr pScrn, 2751d54945dSmrg int x, int y, 2761d54945dSmrg int flags 2771d54945dSmrg){ 2781d54945dSmrg S3VPtr ps3v = S3VPTR(pScrn); 2791d54945dSmrg 2801d54945dSmrg S3VAdjustFrame(pScrn->pScreen->myNum, x, y, flags); 2811d54945dSmrg ps3v->DGAViewportStatus = 0; /* MGAAdjustFrame loops until finished */ 2821d54945dSmrg} 2831d54945dSmrg 2841d54945dSmrgstatic void 2851d54945dSmrgS3V_FillRect ( 2861d54945dSmrg ScrnInfoPtr pScrn, 2871d54945dSmrg int x, int y, int w, int h, 2881d54945dSmrg unsigned long color 2891d54945dSmrg){ 2901d54945dSmrg S3VPtr ps3v = S3VPTR(pScrn); 2911d54945dSmrg 2921d54945dSmrg if(ps3v->AccelInfoRec) { 2931d54945dSmrg (*ps3v->AccelInfoRec->SetupForSolidFill)(pScrn, color, GXcopy, ~0); 2941d54945dSmrg (*ps3v->AccelInfoRec->SubsequentSolidFillRect)(pScrn, x, y, w, h); 2951d54945dSmrg SET_SYNC_FLAG(ps3v->AccelInfoRec); 2961d54945dSmrg } 2971d54945dSmrg} 2981d54945dSmrg 2991d54945dSmrgstatic void 3001d54945dSmrgS3V_BlitRect( 3011d54945dSmrg ScrnInfoPtr pScrn, 3021d54945dSmrg int srcx, int srcy, 3031d54945dSmrg int w, int h, 3041d54945dSmrg int dstx, int dsty 3051d54945dSmrg){ 3061d54945dSmrg S3VPtr ps3v = S3VPTR(pScrn); 3071d54945dSmrg 3081d54945dSmrg if(ps3v->AccelInfoRec) { 3091d54945dSmrg int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1; 3101d54945dSmrg int ydir = (srcy < dsty) ? -1 : 1; 3111d54945dSmrg 3121d54945dSmrg (*ps3v->AccelInfoRec->SetupForScreenToScreenCopy)( 3131d54945dSmrg pScrn, xdir, ydir, GXcopy, ~0, -1); 3141d54945dSmrg (*ps3v->AccelInfoRec->SubsequentScreenToScreenCopy)( 3151d54945dSmrg pScrn, srcx, srcy, dstx, dsty, w, h); 3161d54945dSmrg SET_SYNC_FLAG(ps3v->AccelInfoRec); 3171d54945dSmrg } 3181d54945dSmrg} 3191d54945dSmrg 320ba85709eSmrg 3211d54945dSmrg 3221d54945dSmrgstatic Bool 3231d54945dSmrgS3V_OpenFramebuffer( 3241d54945dSmrg ScrnInfoPtr pScrn, 3251d54945dSmrg char **name, 3261d54945dSmrg unsigned char **mem, 3271d54945dSmrg int *size, 3281d54945dSmrg int *offset, 3291d54945dSmrg int *flags 3301d54945dSmrg){ 3311d54945dSmrg S3VPtr ps3v = S3VPTR(pScrn); 3321d54945dSmrg 3331d54945dSmrg *name = NULL; /* no special device */ 334eb61724eSmrg *mem = (unsigned char*)(uintptr_t)PCI_REGION_BASE(ps3v->PciInfo, 0, REGION_MEM); 3351d54945dSmrg *size = ps3v->videoRambytes; 3361d54945dSmrg *offset = 0; 3371d54945dSmrg *flags = DGA_NEED_ROOT; 3381d54945dSmrg 3391d54945dSmrg return TRUE; 3401d54945dSmrg} 341