? mga-exa-1.patch ? man/mga.4 Index: src/Makefile.am =================================================================== RCS file: /cvs/xorg/driver/xf86-video-mga/src/Makefile.am,v retrieving revision 1.4 diff -u -r1.4 Makefile.am --- src/Makefile.am 14 Aug 2005 00:18:25 -0000 1.4 +++ src/Makefile.am 9 Mar 2006 15:48:36 -0000 @@ -56,6 +56,7 @@ mga_dh.c \ mga_driver.c \ mga_esc.c \ + mga_exa.c \ mga_g450pll.c \ mga.h \ mga_halmod.c \ Index: src/mga.h =================================================================== RCS file: /cvs/xorg/driver/xf86-video-mga/src/mga.h,v retrieving revision 1.11 diff -u -r1.11 mga.h --- src/mga.h 9 Nov 2005 21:31:20 -0000 1.11 +++ src/mga.h 9 Mar 2006 15:48:36 -0000 @@ -16,6 +16,7 @@ #include "compiler.h" #include "xaa.h" +#include "exa.h" #include "xf86Cursor.h" #include "vgaHW.h" #include "colormapst.h" @@ -87,7 +88,8 @@ OPTION_MONITOR2POS, OPTION_METAMODES, OPTION_OLDDMA, - OPTION_PCIDMA + OPTION_PCIDMA, + OPTION_ACCELMETHOD } MGAOpts; @@ -407,6 +409,8 @@ MGARamdacRec Dac; Bool HasSDRAM; Bool NoAccel; + Bool Exa; + ExaDriverPtr ExaDriver; Bool SyncOnGreen; Bool Dac6Bit; Bool HWCursor; Index: src/mga_driver.c =================================================================== RCS file: /cvs/xorg/driver/xf86-video-mga/src/mga_driver.c,v retrieving revision 1.18 diff -u -r1.18 mga_driver.c --- src/mga_driver.c 9 Sep 2005 23:15:45 -0000 1.18 +++ src/mga_driver.c 9 Mar 2006 15:48:37 -0000 @@ -225,6 +225,7 @@ { OPTION_METAMODES, "MetaModes", OPTV_ANYSTR, {0}, FALSE }, { OPTION_OLDDMA, "OldDmaInit", OPTV_BOOLEAN, {0}, FALSE }, { OPTION_PCIDMA, "ForcePciDma", OPTV_BOOLEAN, {0}, FALSE }, + { OPTION_ACCELMETHOD, "AccelMethod", OPTV_ANYSTR, {0}, FALSE }, { -1, NULL, OPTV_NONE, {0}, FALSE } }; @@ -269,6 +270,14 @@ NULL }; +static const char *exaSymbols[] = { + "exaDriverInit", + "exaDriverFini", + "exaGetPixmapOffset", + "exaGetVersion", + NULL +}; + static const char *xaaSymbols[] = { "XAACachePlanarMonoStipple", "XAACreateInfoRec", @@ -446,7 +455,7 @@ * Tell the loader about symbols from other modules that this module * might refer to. */ - LoaderRefSymLists(vgahwSymbols, xaaSymbols, + LoaderRefSymLists(vgahwSymbols, xaaSymbols, exaSymbols, xf8_32bppSymbols, ramdacSymbols, ddcSymbols, i2cSymbols, shadowSymbols, fbdevHWSymbols, vbeSymbols, @@ -1432,6 +1441,17 @@ if (xf86ReturnOptValBool(pMga->Options, OPTION_NOACCEL, FALSE)) { pMga->NoAccel = TRUE; xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n"); + } else { + int from = X_DEFAULT; + char *s = xf86GetOptValString(pMga->Options, OPTION_ACCELMETHOD); + pMga->NoAccel = FALSE; + pMga->Exa = FALSE; + if (!xf86NameCmp(s, "EXA")) { + pMga->Exa = TRUE; + from = X_CONFIG; + } + xf86DrvMsg(pScrn->scrnIndex, from, "Using %s acceleration\n", + pMga->Exa ? "EXA" : "XAA"); } if (xf86ReturnOptValBool(pMga->Options, OPTION_PCI_RETRY, FALSE)) { pMga->UsePCIRetry = TRUE; @@ -2255,11 +2275,17 @@ /* Load XAA if needed */ if (!pMga->NoAccel) { - if (!xf86LoadSubModule(pScrn, "xaa")) { - MGAFreeRec(pScrn); - return FALSE; + if (pMga->Exa) { + if (!xf86LoadSubModule(pScrn, "exa")) { + MGAFreeRec(pScrn); + return FALSE; + } else xf86LoaderReqSymLists(exaSymbols, NULL); + } else { + if (!xf86LoadSubModule(pScrn, "xaa")) { + MGAFreeRec(pScrn); + return FALSE; + } else xf86LoaderReqSymLists(xaaSymbols, NULL); } - xf86LoaderReqSymLists(xaaSymbols, NULL); } /* Load ramdac if needed */ @@ -3237,8 +3263,12 @@ if(!pMga->ShadowFB) /* hardware cursor needs to wrap this layer */ MGADGAInit(pScreen); - if (!pMga->NoAccel) - MGAStormAccelInit(pScreen); + if (!pMga->NoAccel) { + if (pMga->Exa) + mgaExaInit(pScreen); + else + MGAStormAccelInit(pScreen); + } miInitializeBackingStore(pScreen); xf86SetBackingStore(pScreen); @@ -3745,6 +3775,10 @@ if (pMga->AccelInfoRec) XAADestroyInfoRec(pMga->AccelInfoRec); + if (pMga->ExaDriver) { + exaDriverFini(pScreen); + xfree(pMga->ExaDriver); + } if (pMga->CursorInfoRec) xf86DestroyCursorInfoRec(pMga->CursorInfoRec); if (pMga->ShadowPtr) Index: src/mga_exa.c =================================================================== RCS file: src/mga_exa.c diff -N src/mga_exa.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/mga_exa.c 9 Mar 2006 15:48:37 -0000 @@ -0,0 +1,312 @@ +/* + * Copyright 2006 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software") + * to deal in the software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * them Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTIBILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Adam Jackson + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "xf86.h" + +#include "mga.h" +#include "mga_reg.h" +#include "mga_macros.h" + +#include "exa.h" +#ifdef XF86DRI +#include "mga_dri.h" +#endif + +#if 0 +#define DEBUG_MSG(x) ErrorF x +#else +#define DEBUG_MSG(x) +#endif + +#define PMGA(x) \ + MGAPtr pMga = xf86Screens[x->drawable.pScreen->myNum]->driverPrivate; +#define QUIESCE_DMA(x) + +/* stuff stolen from mga_storm.c */ +#define BLIT_LEFT 1 +#define BLIT_UP 4 + +static const CARD32 mgaRop[16] = { + /* GXclear */ MGADWG_RPL | 0x00000000, /* 0 */ + /* GXand */ MGADWG_RSTR | 0x00080000, /* src AND dst */ + /* GXandReverse */ MGADWG_RSTR | 0x00040000, /* src AND NOT dst */ + /* GXcopy */ MGADWG_RSTR | 0x000c0000, /* src */ + /* GXandInverted */ MGADWG_RSTR | 0x00020000, /* NOT src AND dst */ + /* GXnoop */ MGADWG_RSTR | 0x000a0000, /* dst */ + /* GXxor */ MGADWG_RSTR | 0x00060000, /* src XOR dst */ + /* GXor */ MGADWG_RSTR | 0x000e0000, /* src OR dst */ + /* GXnor */ MGADWG_RSTR | 0x00010000, /* NOT src AND NOT dst */ + /* GXequiv */ MGADWG_RSTR | 0x00090000, /* NOT src XOR dst */ + /* GXinvert */ MGADWG_RSTR | 0x00050000, /* NOT dst */ + /* GXorReverse */ MGADWG_RSTR | 0x000d0000, /* src OR NOT dst */ + /* GXcopyInverted */ MGADWG_RPL | 0x00030000, /* NOT src */ + /* GXorInverted */ MGADWG_RSTR | 0x000b0000, /* NOT src OR dst */ + /* GXnand */ MGADWG_RSTR | 0x00070000, /* NOT src OR NOT dst */ + /* GXset */ MGADWG_RPL | 0x000f0000 /* 1 */ +}; + +static const CARD32 atype[16] = { + MGADWG_RPL | 0x00000000, MGADWG_RSTR | 0x00080000, + MGADWG_RSTR | 0x00040000, MGADWG_BLK | 0x000c0000, + MGADWG_RSTR | 0x00020000, MGADWG_RSTR | 0x000a0000, + MGADWG_RSTR | 0x00060000, MGADWG_RSTR | 0x000e0000, + MGADWG_RSTR | 0x00010000, MGADWG_RSTR | 0x00090000, + MGADWG_RSTR | 0x00050000, MGADWG_RSTR | 0x000d0000, + MGADWG_RPL | 0x00030000, MGADWG_RSTR | 0x000b0000, + MGADWG_RSTR | 0x00070000, MGADWG_RPL | 0x000f0000 +}; + + +static const CARD32 atype_noblk[16] = { + MGADWG_RPL | 0x00000000, MGADWG_RSTR | 0x00080000, + MGADWG_RSTR | 0x00040000, MGADWG_RPL | 0x000c0000, + MGADWG_RSTR | 0x00020000, MGADWG_RSTR | 0x000a0000, + MGADWG_RSTR | 0x00060000, MGADWG_RSTR | 0x000e0000, + MGADWG_RSTR | 0x00010000, MGADWG_RSTR | 0x00090000, + MGADWG_RSTR | 0x00050000, MGADWG_RSTR | 0x000d0000, + MGADWG_RPL | 0x00030000, MGADWG_RSTR | 0x000b0000, + MGADWG_RSTR | 0x00070000, MGADWG_RPL | 0x000f0000 +}; + +static void +mgaNoopDone(PixmapPtr pPixmap) +{ +} + +static Bool +mgaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planemask, Pixel fg) +{ + PMGA(pPixmap); + QUIESCE_DMA(); + +#if 0 + if (!RGBEQUAL(fg)) + pMga->FilledRectCMD = MGADWG_TRAP | MGADWG_SOLID | MGADWG_ARZERO | + MGADWG_SGNZERO | MGADWG_SHIFTZERO | + MGADWG_BMONOLEF | pMga->AtypeNoBLK[alu]; + else + pMga->FilledRectCMD = MGADWG_TRAP | MGADWG_SOLID | MGADWG_ARZERO | + MGADWG_SGNZERO | MGADWG_SHIFTZERO | + MGADWG_BMONOLEF | pMga->Atype[alu]; +#endif + pMga->FilledRectCMD = MGADWG_TRAP | MGADWG_SOLID | MGADWG_ARZERO | + MGADWG_SGNZERO | MGADWG_SHIFTZERO | mgaRop[alu]; + + WAITFIFO(5); + OUTREG(MGAREG_PITCH, exaGetPixmapPitch(pPixmap) / + (pPixmap->drawable.bitsPerPixel >> 3)); + OUTREG(MGAREG_DSTORG, exaGetPixmapOffset(pPixmap)); + OUTREG(MGAREG_FCOL, fg); + OUTREG(MGAREG_PLNWT, planemask); + OUTREG(MGAREG_DWGCTL, pMga->FilledRectCMD); + + return TRUE; +} + +static void +mgaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2) +{ + PMGA(pPixmap); + + WAITFIFO(2); + OUTREG(MGAREG_FXBNDRY, (x2 << 16) | (x1 & 0xffff)); + OUTREG(MGAREG_YDSTLEN | MGAREG_EXEC, (y1 << 16) | (y2 - y1)); +} + +static CARD32 src_pitch; /* kill me */ + +static Bool +mgaPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int xdir, int ydir, int alu, + Pixel planemask) +{ + PMGA(pSrc); + int blit_direction = 0; + int dwgctl = 0; + + QUIESCE_DMA(); + + DEBUG_MSG(("s: %x@%x d: %x@%x xdir %d ydir %d alu %d pm %d\n", + exaGetPixmapOffset(pSrc), exaGetPixmapPitch(pSrc), + exaGetPixmapOffset(pDst), exaGetPixmapPitch(pDst), + xdir, ydir, alu, planemask)); + + if (xdir < 0) blit_direction |= BLIT_LEFT; + if (ydir < 0) blit_direction |= BLIT_UP; + pMga->BltScanDirection = blit_direction; + + dwgctl = mgaRop[alu] | MGADWG_SHIFTZERO | MGADWG_BITBLT | MGADWG_BFCOL; + src_pitch = exaGetPixmapPitch(pSrc) / (pSrc->drawable.bitsPerPixel >> 3); + + WAITFIFO(7); + OUTREG(MGAREG_PITCH, exaGetPixmapPitch(pDst) / + (pDst->drawable.bitsPerPixel >> 3)); + OUTREG(MGAREG_SRCORG, exaGetPixmapOffset(pSrc)); + OUTREG(MGAREG_DSTORG, exaGetPixmapOffset(pDst)); + OUTREG(MGAREG_DWGCTL, dwgctl); + OUTREG(MGAREG_SGN, blit_direction); + OUTREG(MGAREG_PLNWT, planemask); + /* this is crap */ + OUTREG(MGAREG_AR5, (ydir < -0 ? -1 : 1) * src_pitch); + + return TRUE; +} + +/* this whole thing is bogus. */ +static void +mgaCopy(PixmapPtr pDst, int srcx, int srcy, int dstx, int dsty, int w, int h) +{ + PMGA(pDst); + int start, end; + + DEBUG_MSG((" %d,%d -> %d,%d %dx%d\n", srcx, srcy, dstx,dsty, w, h)); + + w--; + if (pMga->BltScanDirection & BLIT_UP) { + srcy += h - 1; + dsty += h - 1; + } + start = end = srcy * src_pitch + srcx; + if (pMga->BltScanDirection & BLIT_LEFT) + start += w; + else + end += w; + + DEBUG_MSG((" end %d start %d dstx %d dsty %d w %d h %d\n", + end, start, dstx, dsty, w, h)); + WAITFIFO(4); + OUTREG(MGAREG_AR0, end); + OUTREG(MGAREG_AR3, start); + OUTREG(MGAREG_FXBNDRY, ((dstx + w) << 16) | (dstx & 0xffff)); + OUTREG(MGAREG_YDSTLEN | MGAREG_EXEC, (dsty << 16) | h); +} + +static Bool +mgaCheckComposite(int op, PicturePtr pSrcPict, PicturePtr pMaskPict, + PicturePtr pDstPict) +{ +} + +static Bool +mgaPrepareComposite(int op, PicturePtr pSrcPict, PicturePtr pMaskPict, + PicturePtr pDstPict, PixmapPtr pSrc, PixmapPtr pMask, + PixmapPtr pDst) +{ +} + +static void +mgaComposite(PixmapPtr pDst, int srcx, int srcy, int maskx, int masky, + int dstx, int dsty, int w, int h) +{ +} + +static Bool +mgaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, + int src_pitch) +{ +} + +static Bool +mgaDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, char *dst, + int dst_pitch) +{ +} + +static void +mgaWaitMarker(ScreenPtr pScreen, int marker) +{ +} + +Bool +mgaExaInit(ScreenPtr pScreen) +{ + ExaDriverPtr pExa; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = pScrn->driverPrivate; + + if (exaGetVersion() < EXA_MAKE_VERSION(0, 2, 0)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "EXA version is too old " + "(got 0x%3x, need >= 0x020)\n", exaGetVersion()); + return FALSE; + } + + if (!(pExa = calloc(1, sizeof(*pExa)))) { + pMga->NoAccel = TRUE; + return FALSE; + } + pMga->ExaDriver = pExa; + + pExa->card.flags = EXA_OFFSCREEN_PIXMAPS | EXA_OFFSCREEN_ALIGN_POT; + pExa->card.memoryBase = pMga->FbStart; + pExa->card.memorySize = pMga->FbUsableSize - 4096; + pExa->card.offScreenBase = (pScrn->virtualX * pScrn->virtualY * + pScrn->bitsPerPixel/8) + 4096; + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "X %d Y %d bpp %d\n", + pScrn->virtualX, pScrn->virtualY, pScrn->bitsPerPixel); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Start at %p, size %x, osb %x\n", + pExa->card.memoryBase, pExa->card.memorySize, + pExa->card.offScreenBase); + + pExa->card.pixmapOffsetAlign = 64; + pExa->card.pixmapPitchAlign = 64; + pExa->card.maxX = 2048; + pExa->card.maxY = 2048; + + pExa->accel.WaitMarker = mgaWaitMarker; + pExa->accel.PrepareSolid = mgaPrepareSolid; + pExa->accel.Solid = mgaSolid; + pExa->accel.DoneSolid = mgaNoopDone; + pExa->accel.PrepareCopy = mgaPrepareCopy; + pExa->accel.Copy = mgaCopy; + pExa->accel.DoneCopy = mgaNoopDone; + + if (0) { + pExa->accel.CheckComposite = mgaCheckComposite; + pExa->accel.PrepareComposite = mgaPrepareComposite; + pExa->accel.Composite = mgaComposite; + pExa->accel.DoneComposite = mgaNoopDone; + } + + if (0) { + pExa->accel.DownloadFromScreen = mgaDownloadFromScreen; + pExa->accel.UploadToScreen = mgaUploadToScreen; + } + + /* XXX fill in the XAA setup code here */ +#if 0 + if(pMga->HasSDRAM) { + pMga->Atype = pMga->AtypeNoBLK = atype_noblk; + } else { + pMga->Atype = atype; + pMga->AtypeNoBLK = atype_noblk; + } +#endif + + return exaDriverInit(pScreen, pExa); +}