Module Name:    xsrc
Committed By:   macallan
Date:           Fri Dec  2 22:58:26 UTC 2016

Modified Files:
        xsrc/external/mit/xf86-video-glint/dist/src: glint.h glint_driver.c
            pm2_accel.c pm3_accel.c pm3_regs.h
Added Files:
        xsrc/external/mit/xf86-video-glint/dist/src: pm3_exa.c

Log Message:
add crude but working EXA support for Permedia 3


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.4 -r1.2 \
    xsrc/external/mit/xf86-video-glint/dist/src/glint.h
cvs rdiff -u -r1.7 -r1.8 \
    xsrc/external/mit/xf86-video-glint/dist/src/glint_driver.c
cvs rdiff -u -r1.2 -r1.3 \
    xsrc/external/mit/xf86-video-glint/dist/src/pm2_accel.c
cvs rdiff -u -r1.1.1.3 -r1.2 \
    xsrc/external/mit/xf86-video-glint/dist/src/pm3_accel.c \
    xsrc/external/mit/xf86-video-glint/dist/src/pm3_regs.h
cvs rdiff -u -r0 -r1.1 xsrc/external/mit/xf86-video-glint/dist/src/pm3_exa.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xf86-video-glint/dist/src/glint.h
diff -u xsrc/external/mit/xf86-video-glint/dist/src/glint.h:1.1.1.4 xsrc/external/mit/xf86-video-glint/dist/src/glint.h:1.2
--- xsrc/external/mit/xf86-video-glint/dist/src/glint.h:1.1.1.4	Sun Jun  2 07:25:12 2013
+++ xsrc/external/mit/xf86-video-glint/dist/src/glint.h	Fri Dec  2 22:58:26 2016
@@ -38,6 +38,8 @@
 #ifdef HAVE_XAA_H
 #include "xaa.h"
 #endif
+#include "exa.h"
+
 #include "xf86fbman.h"
 #include "xf86RamDac.h"
 #include "xf86cmap.h"
@@ -148,6 +150,9 @@ typedef struct {
 #ifdef HAVE_XAA_H
     XAAInfoRecPtr	AccelInfoRec;
 #endif
+    ExaDriverPtr 	pExa;
+    int			srcoff;
+
     CloseScreenProcPtr	CloseScreen;
     ScreenBlockHandlerProcPtr BlockHandler;
     GCPtr		CurrentGC;
@@ -240,6 +245,7 @@ void Permedia3Restore(ScrnInfoPtr pScrn,
 void Permedia3Save(ScrnInfoPtr pScrn, GLINTRegPtr glintReg);
 Bool Permedia3Init(ScrnInfoPtr pScrn, DisplayModePtr mode, GLINTRegPtr pReg);
 Bool Permedia3AccelInit(ScreenPtr pScreen);
+Bool Pm3InitEXA(ScreenPtr pScreen);
 void Permedia3InitializeEngine(ScrnInfoPtr pScrn);
 void Permedia3EnableOffscreen(ScreenPtr pScreen);
 void Permedia3Sync(ScrnInfoPtr pScrn);

Index: xsrc/external/mit/xf86-video-glint/dist/src/glint_driver.c
diff -u xsrc/external/mit/xf86-video-glint/dist/src/glint_driver.c:1.7 xsrc/external/mit/xf86-video-glint/dist/src/glint_driver.c:1.8
--- xsrc/external/mit/xf86-video-glint/dist/src/glint_driver.c:1.7	Tue Aug 16 01:27:46 2016
+++ xsrc/external/mit/xf86-video-glint/dist/src/glint_driver.c	Fri Dec  2 22:58:26 2016
@@ -941,6 +941,7 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
      * The first thing we should figure out is the depth, bpp, etc.
      * We support both 24bpp and 32bpp layouts, so indicate that.
      */
+#ifndef __NetBSD__
     if (FBDevProbed) {
 	int default_depth, fbbpp;
 	
@@ -951,7 +952,9 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
 	default_depth = fbdevHWGetDepth(pScrn,&fbbpp);
 	if (!xf86SetDepthBpp(pScrn, default_depth, default_depth, fbbpp,0))
 		return FALSE;
-    } else {
+    } else
+#endif /* __NetBSD__ */
+    {
 	if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support24bppFb | Support32bppFb 
 	 	/*| SupportConvert32to24 | PreferConvert32to24*/))
 		return FALSE;
@@ -1068,6 +1071,7 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
 			    ((pScrn->mask.blue - 1) << 0);
     }
 
+#ifndef __NetBSD__
     /* Check whether to use the FBDev stuff and fill in the rest of pScrn */
     if (xf86ReturnOptValBool(pGlint->Options, OPTION_FBDEV, FALSE)) {
     	if (!FBDevProbed && !xf86LoadSubModule(pScrn, "fbdevhw"))
@@ -1089,7 +1093,9 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
 	pScrn->LeaveVT		= fbdevHWLeaveVTWeak();
 	pScrn->ValidMode	= fbdevHWValidModeWeak();
 	
-    } else {
+    } else
+#endif /* !__NetBSD__ */
+    {
     	/* Only use FBDev if requested */
 	pGlint->FBDev = FALSE;
         from = X_PROBED;
@@ -1460,10 +1466,12 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
 		}
         	GLINTUnmapMem(pScrn);
     	}
-    } else {
+    }
+#ifndef __NetBSD__
+     else {
     	pScrn->videoRam = fbdevHWGetVidmem(pScrn)/1024;
     }
-
+#endif /* !__NetBSD__ */
     pGlint->FbMapSize = pScrn->videoRam * 1024;
 
     /* OVERRIDE videoRam/FbMapSize, for Multiply connected chips to GAMMA */
@@ -2000,10 +2008,12 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
 			      LOOKUP_BEST_REFRESH);
     }
 
+#ifndef __NetBSD__
     if (i < 1 && pGlint->FBDev) {
 	fbdevHWUseBuildinMode(pScrn);
 	i = 1;
     }
+#endif /* !__NetBSD__ */
 
     if (i == -1) {
 	GLINTFreeRec(pScrn);
@@ -2248,6 +2258,7 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
     }
 
     /* Load XAA if needed */
+#ifdef HAVE_XAA_H    
     if (!pGlint->NoAccel) {
 	if (!xf86LoadSubModule(pScrn, "xaa")) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Falling back to shadowfb\n");
@@ -2255,6 +2266,16 @@ GLINTPreInit(ScrnInfoPtr pScrn, int flag
 	    pGlint->ShadowFB = 1;
 	}
     }
+#else
+    if (!pGlint->NoAccel) {
+	if (!xf86LoadSubModule(pScrn, "exa")) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Falling back to shadowfb\n");
+	    pGlint->NoAccel = 1;
+	    pGlint->ShadowFB = 1;
+	}
+    }
+
+#endif
 
     /* Load shadowfb if needed */
     if (pGlint->ShadowFB) {
@@ -2281,6 +2302,7 @@ GLINTMapMem(ScrnInfoPtr pScrn)
     pGlint = GLINTPTR(pScrn);
 
     TRACE_ENTER("GLINTMapMem");
+#ifndef __NetBSD__
     if (pGlint->FBDev) {
     	pGlint->FbBase = fbdevHWMapVidmem(pScrn);
     	if (pGlint->FbBase == NULL)
@@ -2293,7 +2315,8 @@ GLINTMapMem(ScrnInfoPtr pScrn)
 	TRACE_EXIT("GLINTMapMem");
 	return TRUE;
     }
-    
+#endif /* !__NetBSD__ */
+
     /*
      * Map IO registers to virtual address space
      * We always map VGA IO registers - even if we don't need them
@@ -2360,6 +2383,7 @@ GLINTUnmapMem(ScrnInfoPtr pScrn)
     pGlint = GLINTPTR(pScrn);
 
     TRACE_ENTER("GLINTUnmapMem");
+#ifndef __NetBSD__
     if (pGlint->FBDev) {
     	fbdevHWUnmapVidmem(pScrn);
     	pGlint->FbBase = NULL;
@@ -2369,7 +2393,8 @@ GLINTUnmapMem(ScrnInfoPtr pScrn)
 	TRACE_EXIT("GLINTUnmapMem");
     	return TRUE;
     }
-    
+#endif /* !__NetBSD__ */
+
     /*
      * Unmap IO registers to virtual address space
      */ 
@@ -2728,6 +2753,7 @@ GLINTScreenInit(SCREEN_INIT_ARGS_DECL)
     if (!GLINTMapMem(pScrn))
 	return FALSE;
 
+#ifndef __NetBSD__
     if (pGlint->FBDev) {
 	fbdevHWSave(pScrn);
  	if (!fbdevHWModeInit(pScrn, pScrn->currentMode)) {
@@ -2736,6 +2762,7 @@ GLINTScreenInit(SCREEN_INIT_ARGS_DECL)
 		return FALSE;
 	}
     } else
+#endif /* !__NetBSD__ */
     /* Save the current state */
     GLINTSave(pScrn);
 
@@ -2865,7 +2892,11 @@ GLINTScreenInit(SCREEN_INIT_ARGS_DECL)
 	case PCI_VENDOR_3DLABS_CHIP_PERMEDIA3:
 	case PCI_VENDOR_3DLABS_CHIP_PERMEDIA4:
 	case PCI_VENDOR_3DLABS_CHIP_R4:
+#ifdef HAVE_XAA_H
 	    Permedia3AccelInit(pScreen);
+#else
+	    Pm3InitEXA(pScreen);
+#endif
 	    break;
 	case PCI_VENDOR_TI_CHIP_PERMEDIA:
 	case PCI_VENDOR_3DLABS_CHIP_PERMEDIA:
@@ -3036,7 +3067,8 @@ GLINTSwitchMode(SWITCH_MODE_ARGS_DECL)
 
     pGlint = GLINTPTR(pScrn);
     TRACE_ENTER("GLINTSwitchMode");
-	
+
+#ifndef __NetBSD__
     if (pGlint->FBDev) {
 	Bool ret = fbdevHWSwitchMode(SWITCH_MODE_ARGS(pScrn, mode));
 
@@ -3090,6 +3122,7 @@ GLINTSwitchMode(SWITCH_MODE_ARGS_DECL)
 	TRACE_EXIT("GLINTSwitchMode (fbdev ?)");
 	return ret;
     }
+#endif /* !__NetBSD__ */
 
     TRACE_EXIT("GLINTSwitchMode (normal)");
     return GLINTModeInit(pScrn, mode);
@@ -3110,12 +3143,14 @@ GLINTAdjustFrame(ADJUST_FRAME_ARGS_DECL)
 
     pGlint = GLINTPTR(pScrn);
     TRACE_ENTER("GLINTAdjustFrame");
-    
+
+#ifndef __NetBSD__
     if (pGlint->FBDev) {
     	fbdevHWAdjustFrame(ADJUST_FRAME_ARGS(pScrn, x, y));
 	TRACE_EXIT("GLINTAdjustFrame (fbdev)");
 	return;
     }
+#endif /* !__NetBSD__ */
 
     base = ((y * pScrn->displayWidth + x) >> 1) >> pGlint->BppShift;
     if (pScrn->bitsPerPixel == 24) base *= 3;
@@ -3171,9 +3206,11 @@ GLINTEnterVT(VT_FUNC_ARGS_DECL)
 
     TRACE_ENTER("GLINTEnterVT");
 
+#ifndef __NetBSD__
     if (pGlint->FBDev)
     	fbdevHWEnterVT(VT_FUNC_ARGS);
     else
+#endif /* !__NetBSD__ */
     	/* Should we re-save the text mode on each VT enter? */
     	if (!GLINTModeInit(pScrn, pScrn->currentMode))
 		return FALSE;
@@ -3290,9 +3327,12 @@ GLINTCloseScreen(CLOSE_SCREEN_ARGS_DECL)
     if (pScrn->vtSema) {
 	if(pGlint->CursorInfoRec)
     	    pGlint->CursorInfoRec->HideCursor(pScrn);
+#ifndef __NetBSD__
 	if (pGlint->FBDev)
 	    fbdevHWRestore(pScrn);
-	else {	
+	else
+#endif /* !__NetBSD__ */
+	{	
 	    pGlint->STATE = TRUE;
             GLINTRestore(pScrn);
 	}
@@ -3331,8 +3371,10 @@ GLINTFreeScreen(FREE_SCREEN_ARGS_DECL)
 {
     SCRN_INFO_PTR(arg);
     TRACE_ENTER("GLINTFreeScreen");
+#ifndef __NetBSD__
     if (xf86LoaderCheckSymbol("fbdevHWFreeRec"))
         fbdevHWFreeRec(pScrn);
+#endif /* !__NetBSD__ */
     if (xf86LoaderCheckSymbol("RamDacFreeRec"))
 	RamDacFreeRec(pScrn);
     GLINTFreeRec(pScrn);

Index: xsrc/external/mit/xf86-video-glint/dist/src/pm2_accel.c
diff -u xsrc/external/mit/xf86-video-glint/dist/src/pm2_accel.c:1.2 xsrc/external/mit/xf86-video-glint/dist/src/pm2_accel.c:1.3
--- xsrc/external/mit/xf86-video-glint/dist/src/pm2_accel.c:1.2	Sun Aug 21 18:19:25 2016
+++ xsrc/external/mit/xf86-video-glint/dist/src/pm2_accel.c	Fri Dec  2 22:58:26 2016
@@ -397,22 +397,6 @@ static void Permedia2LoadCoord(
 }
 
 
-void
-Permedia2Sync(ScrnInfoPtr pScrn)
-{
-    GLINTPtr pGlint = GLINTPTR(pScrn);
-
-    CHECKCLIPPING;
-
-    while (GLINT_READ_REG(DMACount) != 0);
-    GLINT_WAIT(2);
-    GLINT_WRITE_REG(0x400, FilterMode);
-    GLINT_WRITE_REG(0, GlintSync);
-    do {
-   	while(GLINT_READ_REG(OutFIFOWords) == 0);
-    } while (GLINT_READ_REG(OutputFIFO) != Sync_tag);
-}
-
 static void
 Permedia2SetClippingRectangle(ScrnInfoPtr pScrn, int x1, int y1, int x2, int y2)
 {

Index: xsrc/external/mit/xf86-video-glint/dist/src/pm3_accel.c
diff -u xsrc/external/mit/xf86-video-glint/dist/src/pm3_accel.c:1.1.1.3 xsrc/external/mit/xf86-video-glint/dist/src/pm3_accel.c:1.2
--- xsrc/external/mit/xf86-video-glint/dist/src/pm3_accel.c:1.1.1.3	Sun Jun  2 07:25:12 2013
+++ xsrc/external/mit/xf86-video-glint/dist/src/pm3_accel.c	Fri Dec  2 22:58:26 2016
@@ -45,9 +45,6 @@
 #include "pm3_regs.h"
 #include "glint.h"
 
-#ifdef HAVE_XAA_H
-#include "xaalocal.h"		/* For replacements */
-
 #define DEBUG 0
 
 #if DEBUG
@@ -60,19 +57,11 @@
 # define TRACE(str)
 #endif
 
-#define PM3_WRITEMASK \
-  (pGlint->PM3_UsingSGRAM ? PM3FBHardwareWriteMask : PM3FBSoftwareWriteMask )
-#define PM3_OTHERWRITEMASK \
-  (pGlint->PM3_UsingSGRAM ? PM3FBSoftwareWriteMask : PM3FBHardwareWriteMask )
-
-#define PM3_PLANEMASK(planemask)				\
-{ 								\
-	if (planemask != pGlint->planemask) {			\
-		pGlint->planemask = planemask;			\
-		REPLICATE(planemask); 				\
-		GLINT_WRITE_REG(planemask, PM3_WRITEMASK);	\
-	}							\
-} 
+#ifdef HAVE_XAA_H
+#include "xaalocal.h"		/* For replacements */
+#endif
+
+#ifdef HAVE_XAA_H
 
 /* Clipping */
 static void Permedia3SetClippingRectangle(ScrnInfoPtr pScrn, int x, int y,
@@ -122,6 +111,7 @@ static void Permedia3WritePixmap(ScrnInf
 static void Permedia3WriteBitmap(ScrnInfoPtr pScrn, int x, int y, int w, int h, 
 				unsigned char *src, int srcwidth, int skipleft, 
 				int fg, int bg, int rop,unsigned int planemask);
+#endif /* HAVE_XAA_H */
 
 void
 Permedia3InitializeEngine(ScrnInfoPtr pScrn)
@@ -377,11 +367,13 @@ Permedia3InitializeEngine(ScrnInfoPtr pS
     GLINT_SLOW_WRITE_REG(0, StartXSub);
     GLINT_SLOW_WRITE_REG(0, StartY);
     GLINT_SLOW_WRITE_REG(0, GLINTCount);
+#ifdef HAVE_XAA_H
     if (*pGlint->AccelInfoRec->Sync != NULL)
     	(*pGlint->AccelInfoRec->Sync)(pScrn);
+#endif
     TRACE_EXIT("Permedia3InitializeEngine");
 }
-#endif
+
 Bool
 Permedia3AccelInit(ScreenPtr pScreen)
 {
@@ -516,7 +508,6 @@ Permedia3EnableOffscreen (ScreenPtr pScr
     xf86InitFBManager(pScreen, &AvailFBArea);
 }
 
-#ifdef HAVE_XAA_H
 
 #define CHECKCLIPPING				\
 {						\
@@ -543,6 +534,7 @@ Permedia3Sync(ScrnInfoPtr pScrn)
     } while (GLINT_READ_REG(OutputFIFO) != Sync_tag);
 }
 
+#ifdef HAVE_XAA_H
 void
 DualPermedia3Sync(
 	ScrnInfoPtr pScrn
Index: xsrc/external/mit/xf86-video-glint/dist/src/pm3_regs.h
diff -u xsrc/external/mit/xf86-video-glint/dist/src/pm3_regs.h:1.1.1.3 xsrc/external/mit/xf86-video-glint/dist/src/pm3_regs.h:1.2
--- xsrc/external/mit/xf86-video-glint/dist/src/pm3_regs.h:1.1.1.3	Sun Jun  2 07:25:12 2013
+++ xsrc/external/mit/xf86-video-glint/dist/src/pm3_regs.h	Fri Dec  2 22:58:26 2016
@@ -1049,6 +1049,20 @@
 #	define PM3FillRectanglePosition_XOffset(x)            ((x)&0xffff)
 #	define PM3FillRectanglePosition_YOffset(y)            (((y)&0xffff)<<16)
 
+#define PM3_WRITEMASK \
+  (pGlint->PM3_UsingSGRAM ? PM3FBHardwareWriteMask : PM3FBSoftwareWriteMask )
+#define PM3_OTHERWRITEMASK \
+  (pGlint->PM3_UsingSGRAM ? PM3FBSoftwareWriteMask : PM3FBHardwareWriteMask )
+
+#define PM3_PLANEMASK(planemask)				\
+{ 								\
+	if (planemask != pGlint->planemask) {			\
+		pGlint->planemask = planemask;			\
+		REPLICATE(planemask); 				\
+		GLINT_WRITE_REG(planemask, PM3_WRITEMASK);	\
+	}							\
+} 
+
 #if 0
 
 /**********************************************

Added files:

Index: xsrc/external/mit/xf86-video-glint/dist/src/pm3_exa.c
diff -u /dev/null xsrc/external/mit/xf86-video-glint/dist/src/pm3_exa.c:1.1
--- /dev/null	Fri Dec  2 22:58:26 2016
+++ xsrc/external/mit/xf86-video-glint/dist/src/pm3_exa.c	Fri Dec  2 22:58:26 2016
@@ -0,0 +1,353 @@
+/* $NetBSD: pm3_exa.c,v 1.1 2016/12/02 22:58:26 macallan Exp $ */
+/*
+ * Copyright (c) 2016 Michael Lorenz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *    - Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* all driver need this */
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "compiler.h"
+#include "exa.h"
+
+#include "glint_regs.h"
+#include "pm3_regs.h"
+#include "glint.h"
+
+/*#define PM3_DEBUG*/
+
+#ifdef PM3_DEBUG
+#define ENTER xf86Msg(X_ERROR, "%s>\n", __func__);
+#define DPRINTF xf86Msg
+#else
+#define ENTER
+#define DPRINTF while (0) xf86Msg
+#endif
+
+static void
+Pm3WaitMarker(ScreenPtr pScreen, int Marker)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+	Permedia3Sync(pScrn);
+}
+
+static Bool
+Pm3PrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap,
+		int xdir, int ydir, int rop, Pixel planemask)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+
+	ENTER;
+
+	pGlint->PM3_Render2D =
+		PM3Render2D_SpanOperation |
+		PM3Render2D_Operation_Normal;
+
+	pGlint->PM3_Config2D =
+		PM3Config2D_UserScissorEnable |
+		PM3Config2D_ForegroundROPEnable |
+		PM3Config2D_ForegroundROP(rop) |
+		PM3Config2D_FBWriteEnable;
+
+	if (xdir == 1) pGlint->PM3_Render2D |= PM3Render2D_XPositive;
+	if (ydir == 1) pGlint->PM3_Render2D |= PM3Render2D_YPositive;
+
+	if ((rop!=GXclear)&&(rop!=GXset)&&(rop!=GXnoop)&&(rop!=GXinvert)) {
+		pGlint->PM3_Render2D |= PM3Render2D_FBSourceReadEnable;
+		pGlint->PM3_Config2D |= PM3Config2D_Blocking;
+	}
+
+	if ((rop!=GXclear)&&(rop!=GXset)&&(rop!=GXcopy)&&(rop!=GXcopyInverted))
+		pGlint->PM3_Config2D |= PM3Config2D_FBDestReadEnable;
+
+	pGlint->srcoff = exaGetPixmapOffset(pSrcPixmap);
+
+	GLINT_WAIT(2);
+	PM3_PLANEMASK(planemask);
+	GLINT_WRITE_REG(pGlint->PM3_Config2D, PM3Config2D);
+	return TRUE;
+}
+
+static void
+Pm3Copy(PixmapPtr pDstPixmap,
+         int srcX, int srcY, int dstX, int dstY, int w, int h)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+	/* Spans needs to be 32 bit aligned. */
+	int x_align = srcX & 0x1f;
+	int dstoff = exaGetPixmapOffset(pDstPixmap);
+	int pitch = exaGetPixmapPitch(pDstPixmap);
+	
+	ENTER;
+
+	/* assuming constant pitch for now */	
+	srcY += pGlint->srcoff / pitch;
+	dstY += dstoff / pitch;
+
+	GLINT_WAIT(5);
+	GLINT_WRITE_REG(((dstY & 0x0fff) << 16) | (dstX & 0x0fff), ScissorMinXY);
+	GLINT_WRITE_REG((((dstY + h) & 0x0fff) << 16) | ((dstX + w) & 0x0fff), ScissorMaxXY);
+	GLINT_WRITE_REG(
+		PM3RectanglePosition_XOffset(dstX - x_align) |
+		PM3RectanglePosition_YOffset(dstY),
+		PM3RectanglePosition);
+	GLINT_WRITE_REG(
+		PM3FBSourceReadBufferOffset_XOffset(srcX - dstX)|
+		PM3FBSourceReadBufferOffset_YOffset(srcY - dstY),
+		PM3FBSourceReadBufferOffset);
+	GLINT_WRITE_REG(pGlint->PM3_Render2D |
+		PM3Render2D_Width(w + x_align)|
+		PM3Render2D_Height(h),
+		PM3Render2D);
+	exaMarkSync(pDstPixmap->drawable.pScreen);
+}
+
+static void
+Pm3DoneCopy(PixmapPtr pPixmap)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+
+	GLINT_WRITE_REG(0, ScissorMinXY);
+	GLINT_WRITE_REG(0x0fff0fff, ScissorMaxXY);
+}
+
+static Bool
+Pm3PrepareSolid(PixmapPtr pPixmap, int rop, Pixel planemask, Pixel color)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+
+	ENTER;
+
+	/* Prepare Common Render2D & Config2D data */
+	pGlint->PM3_Render2D =
+		PM3Render2D_XPositive |
+		PM3Render2D_YPositive |
+		PM3Render2D_Operation_Normal;
+	pGlint->PM3_Config2D =
+		PM3Config2D_UseConstantSource |
+		PM3Config2D_ForegroundROPEnable |
+		PM3Config2D_ForegroundROP(rop) |
+		PM3Config2D_FBWriteEnable;
+	GLINT_WAIT(3);
+	REPLICATE(color);
+
+	/* We can't do block fills properly at 32bpp, so we can stick the chip
+	 * into 16bpp and double the width and xcoord, but it seems that at
+	 * extremely high resolutions (above 1600) it doesn't fill.
+	 * so, we fall back to the slower span filling method.
+	 */
+#if 0
+	if ((rop == GXcopy) && (pScrn->bitsPerPixel == 32) && 
+	    (pScrn->displayWidth <= 1600)) {
+		pGlint->AccelInfoRec->SubsequentSolidFillRect = 
+		    Permedia3SubsequentFillRectSolid32bpp;
+
+		if (pGlint->PM3_UsingSGRAM) {
+			GLINT_WRITE_REG(color, PM3FBBlockColor);
+		} else {
+			pGlint->PM3_Render2D |= PM3Render2D_SpanOperation;
+			GLINT_WRITE_REG(color, PM3ForegroundColor);
+		}
+	} else {
+	    	pGlint->AccelInfoRec->SubsequentSolidFillRect = 
+			Permedia3SubsequentFillRectSolid;
+#endif
+	    	/* Can't do block fills at 8bpp either */
+	    	if ((rop == GXcopy) && (pScrn->bitsPerPixel == 16)) {
+			if (pGlint->PM3_UsingSGRAM) {
+				GLINT_WRITE_REG(color, PM3FBBlockColor);
+			} else {
+	        		pGlint->PM3_Render2D |= PM3Render2D_SpanOperation;
+				GLINT_WRITE_REG(color, PM3ForegroundColor);
+			}
+        	} else {
+			pGlint->PM3_Render2D |= PM3Render2D_SpanOperation;
+			GLINT_WRITE_REG(color, PM3ForegroundColor);
+    		}
+#if 0
+	}
+#endif
+	PM3_PLANEMASK(planemask);
+	if (((rop != GXclear) && 
+	     (rop != GXset) &&
+	     (rop != GXcopy) &&
+	     (rop != GXcopyInverted)) ||
+	    ((planemask != 0xffffffff) && !(pGlint->PM3_UsingSGRAM)))
+		pGlint->PM3_Config2D |= PM3Config2D_FBDestReadEnable;
+	GLINT_WRITE_REG(pGlint->PM3_Config2D, PM3Config2D);
+	return TRUE;
+}
+
+static void
+Pm3Solid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+	int offset = exaGetPixmapOffset(pPixmap);
+	int pitch = exaGetPixmapPitch(pPixmap);
+	int w = x2 - x1, h = y2 - y1;
+
+	ENTER;
+
+	y1 += offset / pitch;
+
+	GLINT_WAIT(2);
+	GLINT_WRITE_REG(
+		PM3RectanglePosition_XOffset(x1) |
+		PM3RectanglePosition_YOffset(y1),
+		PM3RectanglePosition);
+	GLINT_WRITE_REG(pGlint->PM3_Render2D |
+		PM3Render2D_Width(w) | PM3Render2D_Height(h),
+		PM3Render2D);
+
+	exaMarkSync(pPixmap->drawable.pScreen);
+}
+
+/*
+ * Memcpy-based UTS.
+ */
+static Bool
+Pm3UploadToScreen(PixmapPtr pDst, int x, int y, int w, int h,
+    char *src, int src_pitch)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+	char  *dst        = pGlint->FbBase + exaGetPixmapOffset(pDst);
+	int    dst_pitch  = exaGetPixmapPitch(pDst);
+
+	int bpp    = pDst->drawable.bitsPerPixel;
+	int cpp    = (bpp + 7) >> 3;
+	int wBytes = w * cpp;
+
+	ENTER;
+	dst += (x * cpp) + (y * dst_pitch);
+
+	Permedia3Sync(pScrn);
+
+	while (h--) {
+		memcpy(dst, src, wBytes);
+		src += src_pitch;
+		dst += dst_pitch;
+	}
+	return TRUE;
+}
+
+/*
+ * Memcpy-based DFS.
+ */
+static Bool
+Pm3DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h,
+    char *dst, int dst_pitch)
+{
+ 	ScrnInfoPtr pScrn = xf86Screens[pSrc->drawable.pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+	char  *src        = pGlint->FbBase + exaGetPixmapOffset(pSrc);
+	int    src_pitch  = exaGetPixmapPitch(pSrc);
+
+	ENTER;
+	int bpp    = pSrc->drawable.bitsPerPixel;
+	int cpp    = (bpp + 7) >> 3;
+	int wBytes = w * cpp;
+
+	src += (x * cpp) + (y * src_pitch);
+
+	Permedia3Sync(pScrn);
+
+	while (h--) {
+		memcpy(dst, src, wBytes);
+		src += src_pitch;
+		dst += dst_pitch;
+	}
+
+	return TRUE;
+}
+
+Bool
+Pm3InitEXA(ScreenPtr pScreen)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	GLINTPtr pGlint = GLINTPTR(pScrn);
+	ExaDriverPtr pExa;
+	int stride;
+
+	ENTER;
+
+	pExa = exaDriverAlloc();
+	if (!pExa)
+		return FALSE;
+
+	pGlint->pExa = pExa;
+
+	pExa->exa_major = EXA_VERSION_MAJOR;
+	pExa->exa_minor = EXA_VERSION_MINOR;
+
+	pExa->memoryBase = pGlint->FbBase;
+	stride = pScrn->displayWidth * (pScrn->bitsPerPixel >> 3);
+	pExa->memorySize = min(pGlint->FbMapSize, 4095 * stride);
+	xf86Msg(X_ERROR, "stride: %d\n", stride);
+	pExa->offScreenBase = stride * pScrn->virtualY;
+
+	/* for now, until I figure out how to do variable stride */
+	pExa->pixmapOffsetAlign = stride;
+	pExa->pixmapPitchAlign = stride;
+
+	pExa->flags = EXA_OFFSCREEN_PIXMAPS
+		      /* | EXA_SUPPORTS_OFFSCREEN_OVERLAPS |*/
+		      | EXA_MIXED_PIXMAPS;
+
+	pExa->maxX = 4095;
+	pExa->maxY = 4095;
+
+	pExa->WaitMarker = Pm3WaitMarker;
+
+	pExa->PrepareSolid = Pm3PrepareSolid;
+	pExa->Solid = Pm3Solid;
+	pExa->DoneSolid = Pm3DoneCopy;
+	pExa->PrepareCopy = Pm3PrepareCopy;
+	pExa->Copy = Pm3Copy;
+	pExa->DoneCopy = Pm3DoneCopy;
+
+	/* EXA hits more optimized paths when it does not have to fallback 
+	 * because of missing UTS/DFS, hook memcpy-based UTS/DFS.
+	 */
+	pExa->UploadToScreen = Pm3UploadToScreen;
+	pExa->DownloadFromScreen = Pm3DownloadFromScreen;
+
+	Permedia3InitializeEngine(pScrn);
+
+	return exaDriverInit(pScreen, pExa);
+}

Reply via email to