diff options
author | kem <kem> | 2001-04-05 20:57:33 +0000 |
---|---|---|
committer | kem <kem> | 2001-04-05 20:57:33 +0000 |
commit | 204c65b47ff797d974d351bdd22d6816bda412e0 (patch) | |
tree | fef8f2f0279316ad5bab80f725b8bb114b77002c | |
parent | a80b3a6025d8044b0cd94799efb4814ccc19a834 (diff) |
- Merge from trunk into pcigart branchati-pcigart-1-0-0-20010405
37 files changed, 3652 insertions, 1895 deletions
diff --git a/xc/config/cf/X11.tmpl b/xc/config/cf/X11.tmpl index d34fcb8aa..99ad3c539 100644 --- a/xc/config/cf/X11.tmpl +++ b/xc/config/cf/X11.tmpl @@ -79,6 +79,15 @@ VENDORMANVERSION = XVendorManVersionString #ifndef BuildServersOnly #define BuildServersOnly NO #endif +#ifndef BuildClients +#define BuildClients !BuildServersOnly +#endif +#ifndef BuildDocs +#define BuildDocs !BuildServersOnly +#endif +#ifndef BuildLibraries +#define BuildLibraries (!BuildServersOnly || BuildClients) +#endif #ifndef BuildFontServer #define BuildFontServer YES #endif @@ -188,7 +197,7 @@ VENDORMANVERSION = XVendorManVersionString #define BuildFontCache YES #endif #ifndef BuildFontCacheLib -#define BuildFontCacheLib BuildFontCache +#define BuildFontCacheLib (BuildFontCache && !BuildServersOnly) #endif #ifndef BuildLowMem #define BuildLowMem NO @@ -208,16 +217,16 @@ VENDORMANVERSION = XVendorManVersionString #endif #endif #ifndef BuildXIElib -#define BuildXIElib BuildXIE +#define BuildXIElib (BuildXIE && !BuildServersOnly) #endif #ifndef BuildXKB #define BuildXKB YES #endif #ifndef BuildXKBlib -#define BuildXKBlib BuildXKB +#define BuildXKBlib (BuildXKB && !BuildServersOnly) #endif #ifndef BuildXKBuilib -#define BuildXKBuilib BuildXKB +#define BuildXKBuilib (BuildXKB && !BuildServersOnly) #endif /* * WARNING: Setting UseXKBInClients to YES cause incompatibilities @@ -240,7 +249,7 @@ VENDORMANVERSION = XVendorManVersionString #define BuildXinerama NO #endif #ifndef BuildXineramaLibrary -#define BuildXineramaLibrary BuildXinerama +#define BuildXineramaLibrary (BuildXinerama && !BuildServersOnly) #endif #ifndef BuildXCSecurity #define BuildXCSecurity YES @@ -284,13 +293,13 @@ VENDORMANVERSION = XVendorManVersionString #define BuildXF86VidModeExt NO #endif #ifndef BuildXF86VidModeLibrary -#define BuildXF86VidModeLibrary BuildXF86VidModeExt +#define BuildXF86VidModeLibrary (BuildXF86VidModeExt && !BuildServersOnly) #endif #ifndef BuildXF86MiscExt #define BuildXF86MiscExt NO #endif #ifndef BuildXF86MiscLibrary -#define BuildXF86MiscLibrary BuildXF86MiscExt +#define BuildXF86MiscLibrary (BuildXF86MiscExt && !BuildServersOnly) #endif #ifndef BuildXF86BigfontExt #define BuildXF86BigfontExt NO @@ -299,31 +308,31 @@ VENDORMANVERSION = XVendorManVersionString #define BuildXF86DGA NO #endif #ifndef BuildXF86DGALibrary -#define BuildXF86DGALibrary BuildXF86DGA +#define BuildXF86DGALibrary (BuildXF86DGA && !BuildServersOnly) #endif #ifndef BuildXvExt #define BuildXvExt NO #endif #ifndef BuildXvLibrary -#define BuildXvLibrary BuildXvExt -#endif -#ifndef BuildGLULibrary -#define BuildGLULibrary NO +#define BuildXvLibrary (BuildXvExt && !BuildServersOnly) #endif #ifndef BuildGlxExt #define BuildGlxExt NO #endif #ifndef BuildGLXLibrary -#define BuildGLXLibrary BuildGlxExt +#define BuildGLXLibrary (BuildGlxExt && !BuildServersOnly) +#endif +#ifndef BuildGLULibrary +#define BuildGLULibrary BuildGLXLibrary #endif #ifndef BuildXF86RushExt #define BuildXF86RushExt NO #endif #ifndef BuildXF86RushLibrary -#define BuildXF86RushLibrary BuildXF86RushExt +#define BuildXF86RushLibrary (BuildXF86RushExt && !BuildServersOnly) #endif #ifndef BuildDPSLibraries -#define BuildDPSLibraries YES +#define BuildDPSLibraries !BuildServersOnly #endif #ifndef BuildDPSLibrary #define BuildDPSLibrary BuildDPSLibraries @@ -338,7 +347,7 @@ VENDORMANVERSION = XVendorManVersionString #define BuildRender NO #endif #ifndef BuildRenderLibrary -#define BuildRenderLibrary YES +#define BuildRenderLibrary !BuildServersOnly #endif #ifndef BuildXftLibrary #define BuildXftLibrary BuildRenderLibrary @@ -2364,7 +2373,7 @@ ProjectUnsharedLibReferences(XFT,Xft,$(XFTLIBSRC),XBuildLibDir) #define LdLibraryPath LD_LIBRARY_PATH #endif -#ifdef BuildXKBlib +#if BuildXKBlib XKBFILELIBSRC = $(LIBSRC)/xkbfile ProjectUnsharedLibReferences(XKBFILE,xkbfile,$(XKBFILELIBSRC),XBuildLibDir) #ifndef XkbClientDepLibs @@ -2396,7 +2405,7 @@ ProjectUnsharedLibReferences(XKBFILE,xkbfile,$(XKBFILELIBSRC),XBuildLibDir) #endif #endif /* BuildXKBlib */ -#ifdef BuildXKBuilib +#if BuildXKBuilib XKBUILIBSRC = $(LIBSRC)/xkbui ProjectUnsharedLibReferences(XKBUI,xkbui,$(XKBUILIBSRC),XBuildLibDir) #ifndef XkbuiLibs diff --git a/xc/config/cf/host.def b/xc/config/cf/host.def index 13da5d4a9..3c6c69c89 100644 --- a/xc/config/cf/host.def +++ b/xc/config/cf/host.def @@ -12,6 +12,10 @@ #endif #endif #define BuildServersOnly YES +/* + * Turn this on to build xf86cfg and xf86config. It has the side-effect of + * building lots of libraries in xc/lib. + */ #define BuildXFree86ConfigTools NO #define XF86CardDrivers vga tdfx i810 mga ati glint #define LinuxDistribution LinuxRedHat @@ -60,3 +64,6 @@ #define XVirtualFramebufferServer NO #define XprtServer NO +/* No need to build these extensions */ +#define BuildXIE NO +#define BuildPexExt NO diff --git a/xc/config/cf/xfree86.cf b/xc/config/cf/xfree86.cf index 8e3e621ac..1035b0133 100644 --- a/xc/config/cf/xfree86.cf +++ b/xc/config/cf/xfree86.cf @@ -105,6 +105,30 @@ XCOMM $Xorg: xfree86.cf,v 1.4 2000/08/17 19:41:49 cpqbld Exp $ #endif /* + * BuildXFree86ConfigTools: + * + * Turning this on allows the XFree86 config tools to build when + * BuildServersOnly is YES. This requires more than the servonly CVS + * module. This cannot be used to disable building the config tools with + * a full build. + */ +#ifndef BuildXFree86ConfigTools +#ifdef BuildServersOnly +#define BuildXFree86ConfigTools !BuildServersOnly +#else +#define BuildXFree86ConfigTools YES +#endif +#endif + +#if BuildXFree86ConfigTools +#define BuildLibraries YES +#define BuildXF86MiscLibrary YES +#define BuildXF86VidModeLibrary YES +#define BuildXKBlib YES +#define BuildXKBuilib YES +#endif + +/* * Default settings for which X Servers to build. */ @@ -689,6 +713,10 @@ IPLAN2P8_DEFS = -DUSE_IPLAN2P8 #if BuildXF86DRI +#ifndef BuildGLXLibrary +#define BuildGLXLibrary YES +#endif + /* * One and ONLY one of the GlxBuiltIn* drivers can be defined to be YES. * If more than one are defined, the compilation will fail with multiply @@ -869,6 +897,7 @@ IPLAN2P8_DEFS = -DUSE_IPLAN2P8 #endif #endif +#if 0 /* * Build the extra extension libs even when not including the extra extensions * in the servers @@ -888,12 +917,10 @@ IPLAN2P8_DEFS = -DUSE_IPLAN2P8 #ifndef BuildXvLibrary # define BuildXvLibrary YES #endif -#ifndef BuildGLULibrary -# define BuildGLULibrary HasCplusplus -#endif #ifndef BuildGLXLibrary # define BuildGLXLibrary YES #endif +#endif /* * Build the XFree86-VidMode extension diff --git a/xc/lib/GL/dri/dri_glx.c b/xc/lib/GL/dri/dri_glx.c index 20884c16b..0a68a7409 100644 --- a/xc/lib/GL/dri/dri_glx.c +++ b/xc/lib/GL/dri/dri_glx.c @@ -68,6 +68,43 @@ extern void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, #endif +static void InfoMessageF(const char *f, ...) +{ + va_list args; + const char *env; + + if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) { + fprintf(stderr, "libGL: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } +} + +static void ErrorMessageF(const char *f, ...) +{ + va_list args; + + if (getenv("LIBGL_DEBUG")) { + fprintf(stderr, "libGL error: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } +} + +static void PrintF(const char *f, ...) +{ + va_list args; + const char *env; + + if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) { + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } +} + static void ErrorMessage(const char *msg) { if (getenv("LIBGL_DEBUG")) { @@ -180,22 +217,19 @@ static void *OpenDriver(const char *driverName) libPaths = DEFAULT_DRIVER_DIR; for (i = 0; ; i++) { - char libDir[1000], info[1000], realDriverName[100]; + char libDir[1000], realDriverName[200]; void *handle; ExtractDir(i, libPaths, 1000, libDir); if (!libDir[0]) return NULL; - sprintf(realDriverName, "%s/%s_dri.so", libDir, driverName); - sprintf(info, "trying %s", realDriverName); - InfoMessage(info); + snprintf(realDriverName, 200, "%s/%s_dri.so", libDir, driverName); + InfoMessageF("trying %s\n", realDriverName); handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); if (handle) { return handle; } else { - char message[1000]; - snprintf(message, 1000, "dlopen failed: %s", dlerror()); - ErrorMessage(message); + ErrorMessageF("dlopen failed: %s\n", dlerror()); } } @@ -246,9 +280,7 @@ static void Find_CreateScreenFuncs(Display *dpy, b = XF86DRIGetClientDriverName(dpy, scrn, &driverMajor, &driverMinor, &driverPatch, &driverName); if (!b) { - char message[1000]; - snprintf(message, 1000, "Cannot determine driver name for screen %d", scrn); - ErrorMessage(message); + ErrorMessageF("Cannot determine driver name for screen %d\n", scrn); continue; } @@ -265,7 +297,7 @@ static void Find_CreateScreenFuncs(Display *dpy, /* success! */ createFuncs[scrn] = createScreenFunc; libraryHandles[scrn] = handle; - break; /* onto the next screen */ + continue; /* onto the next screen */ } else { ErrorMessage("driCreateScreen() not defined in driver!"); @@ -366,7 +398,6 @@ void *driCreateDisplay(Display *dpy, __DRIdisplay *pdisp) static void register_extensions_on_screen(Display *dpy, int scrNum) { - GLboolean verbose = GL_FALSE; /* for debugging only */ int eventBase, errorBase; Bool b, b2; int driMajor, driMinor, driPatch; @@ -380,34 +411,29 @@ register_extensions_on_screen(Display *dpy, int scrNum) */ b = XF86DRIQueryExtension(dpy, &eventBase, &errorBase); if (!b) { - if (verbose) - fprintf(stderr, "XF86DRIQueryExtension failed\n"); + InfoMessage("XF86DRIQueryExtension failed"); return; } b = XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &b2); if (!b || !b2) { - if (verbose) - fprintf(stderr, "XF86DRIQueryDirectRenderingCapable failed\n"); + InfoMessage("XF86DRIQueryDirectRenderingCapable failed"); return; } b = XF86DRIQueryVersion(dpy, &driMajor, &driMinor, &driPatch); if (!b) { - if (verbose) - fprintf(stderr, "XF86DRIQueryVersion failed\n"); - return; + InfoMessage("XF86DRIQueryVersion failed"); } b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor, &driverPatch, &driverName); if (!b) { - if (verbose) - fprintf(stderr, "XF86DRIGetClientDriverName failed\n"); + InfoMessage("XF86DRIGetClientDriverName failed"); return; } - else if (verbose) { - printf("XF86DRIGetClientDriverName: %d.%d.%d %s\n", driverMajor, + else { + InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s\n", driverMajor, driverMinor, driverPatch, driverName); } @@ -446,8 +472,10 @@ void __glXRegisterExtensions(void) { static GLboolean alreadyCalled = GL_FALSE; - if (alreadyCalled) + + if (alreadyCalled) { return; + } #ifndef BUILT_IN_DRI_DRIVER { diff --git a/xc/lib/GL/glx/glxext.c b/xc/lib/GL/glx/glxext.c index b1fcd38a6..125b8ea45 100644 --- a/xc/lib/GL/glx/glxext.c +++ b/xc/lib/GL/glx/glxext.c @@ -1,38 +1,55 @@ /* $XFree86: xc/lib/GL/glx/glxext.c,v 1.10 2001/01/16 05:10:55 martin Exp $ */ /* -** The contents of this file are subject to the GLX Public License Version 1.0 -** (the "License"). You may not use this file except in compliance with the -** License. You may obtain a copy of the License at Silicon Graphics, Inc., -** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043 -** or at http://www.sgi.com/software/opensource/glx/license.html. -** -** Software distributed under the License is distributed on an "AS IS" -** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY -** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR -** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific -** language governing rights and limitations under the License. -** -** The Original Software is GLX version 1.2 source code, released February, -** 1999. The developer of the Original Software is Silicon Graphics, Inc. -** Those portions of the Subject Software created by Silicon Graphics, Inc. -** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved. +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. ** +** $Date: 2001/04/05 20:57:33 $ $Revision: 1.17.2.1 $ +** $Header: /home/ajax/dri-backup/xc/xc/lib/GL/glx/glxext.c,v 1.17.2.1 2001/04/05 20:57:33 kem Exp $ */ -/* - * Direct rendering support added by Precision Insight, Inc. - * - * Authors: - * Kevin E. Martin <kevin@precisioninsight.com> - * - */ +/* < + * Direct rendering support added by Precision Insight, Inc. < + * < + * Authors: < + * Kevin E. Martin <kevin@precisioninsight.com> < + * < + */ #include "packrender.h" +#include <stdio.h> #include <Xext.h> #include <extutil.h> #include <assert.h> -#include <stdio.h> #include "indirect_init.h" #include "glapi.h" #ifdef XTHREADS @@ -433,11 +450,14 @@ static Bool AllocAndFetchScreenConfigs(Display *dpy, __GLXdisplayPrivate *priv) #ifdef GLX_DIRECT_RENDERING /* Initialize the direct rendering per screen data and functions */ - if (priv->driDisplay.private) + if (priv->driDisplay.private && + priv->driDisplay.createScreen && + priv->driDisplay.createScreen[i]) { psc->driScreen.private = - (*priv->driDisplay.createScreen)(dpy, i, &psc->driScreen, + (*(priv->driDisplay.createScreen[i]))(dpy, i, &psc->driScreen, psc->numConfigs, psc->configs); + } #endif } SyncHandle(); @@ -557,9 +577,7 @@ __GLXdisplayPrivate *__glXInitialize(Display* dpy) XAddToExtensionList(privList, private); if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1) { -#if 0 __glXClientInfo(dpy, dpyPriv->majorOpcode); -#endif } __glXUnlock(); diff --git a/xc/lib/GL/mesa/dri/Imakefile b/xc/lib/GL/mesa/dri/Imakefile index 23e4ea50e..a6c7744e4 100644 --- a/xc/lib/GL/mesa/dri/Imakefile +++ b/xc/lib/GL/mesa/dri/Imakefile @@ -12,7 +12,7 @@ ALLOC_DEFINES = -DMALLOC_0_RETURNS_NULL #if BuildXF86DRI DRI_DEFINES = GlxDefines - DRI_INCLUDES = -I../../glx -I../../dri \ + DRI_INCLUDES = -I../../glx -I../../dri -I../../include/GL \ -I$(TOP)/include -I$(TOP)/include/GL \ -I$(XF86OSSRC) -I$(SERVERSRC)/GL/dri #endif diff --git a/xc/lib/GL/mesa/dri/dri_mesa.c b/xc/lib/GL/mesa/dri/dri_mesa.c index cfdbb2799..c50fe78fe 100644 --- a/xc/lib/GL/mesa/dri/dri_mesa.c +++ b/xc/lib/GL/mesa/dri/dri_mesa.c @@ -32,6 +32,27 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * Brian E. Paul <brian@precisioninsight.com> */ +/* + * This file gets compiled into each of the DRI 3D drivers. The + * functions defined here are called from the GL library via + * function pointers in the __DRIdisplayRec, __DRIscreenRec, + * __DRIcontextRec, __DRIdrawableRec structures defined in glxclient.h + * + * Those function pointers are initialized by code in this file. + * The process starts when libGL calls the __driCreateScreen() function + * at the end of this file. + * + * The above-mentioned DRI structures have no dependencies on Mesa. + * Each structure instead has a generic (void *) private pointer that + * points to a private structure. For Mesa drivers, these private + * structures are the __DRIdrawablePrivateRec, __DRIcontextPrivateRec, + * __DRIscreenPrivateRec, and __DRIvisualPrivateRec structures defined + * in dri_mesaint.h. We allocate and attach those structs here in + * this file. + */ + + + #ifdef GLX_DIRECT_RENDERING #include <unistd.h> @@ -58,19 +79,19 @@ static Bool driMesaUnbindContext(Display *dpy, int scrn, static void *driMesaCreateDrawable(Display *dpy, int scrn, GLXDrawable draw, VisualID vid, __DRIdrawable *pdraw); static __DRIdrawable *driMesaGetDrawable(Display *dpy, GLXDrawable draw, - void *private); -static void driMesaSwapBuffers(Display *dpy, void *private); -static void driMesaDestroyDrawable(Display *dpy, void *private); + void *screenPrivate); +static void driMesaSwapBuffers(Display *dpy, void *drawPrivate); +static void driMesaDestroyDrawable(Display *dpy, void *drawPrivate); /* Context methods */ static void *driMesaCreateContext(Display *dpy, XVisualInfo *vis, void *shared, __DRIcontext *pctx); -static void driMesaDestroyContext(Display *dpy, int scrn, void *private); +static void driMesaDestroyContext(Display *dpy, int scrn, void *screenPrivate); /* Screen methods */ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, int numConfigs, __GLXvisualConfig *config); -static void driMesaDestroyScreen(Display *dpy, int scrn, void *private); +static void driMesaDestroyScreen(Display *dpy, int scrn, void *screenPrivate); static Bool driFeatureOn(const char *name) { @@ -184,10 +205,15 @@ static void __driMesaGarbageCollectDrawables(void *drawHash) /*****************************************************************/ +/* + * XXX get rid of this level of indirection? + * Since the code in this file is compiled into each DRI 3D driver + * this layer of indirection serves no purpose. + */ static void driMesaInitAPI(__MesaAPI *MesaAPI) { - MesaAPI->InitDriver = XMesaInitDriver; - MesaAPI->ResetDriver = XMesaResetDriver; + MesaAPI->InitDriver = XMesaInitDriver; /* XXX rename as CreateScreen? */ + MesaAPI->ResetDriver = XMesaResetDriver; /* rename as DestroyScreen? */ MesaAPI->CreateVisual = XMesaCreateVisual; MesaAPI->CreateContext = XMesaCreateContext; MesaAPI->DestroyContext = XMesaDestroyContext; @@ -283,9 +309,15 @@ static Bool driMesaUnbindContext(Display *dpy, int scrn, #endif } + /* XXX this is disabled so that if we call SwapBuffers on an unbound + * window we can determine the last context bound to the window and + * use that context's lock. (BrianP, 2-Dec-2000) + */ +#if 0 /* Unbind the drawable */ pcp->driDrawablePriv = NULL; pdp->driContextPriv = &psp->dummyContextPriv; +#endif return GL_TRUE; } @@ -427,7 +459,7 @@ static Bool driMesaBindContext(Display *dpy, int scrn, if (try) { if (psp->fullscreen && !psp->pSAREA->frame.fullscreen) { /* Server has closed fullscreen mode */ - __driMesaMessage("server closed fullscreen mode\n"); + __driMesaMessage("server closed fullscreen mode"); psp->fullscreen = NULL; } if (XF86DRIOpenFullScreen(dpy, scrn, draw)) { @@ -444,10 +476,11 @@ static Bool driMesaBindContext(Display *dpy, int scrn, /* * This function basically updates the __DRIdrawablePrivate struct's - * cliprect information by calling XF86DRIGetDrawableInfo(). - * This is usually called by a macro which compares the - * __DRIdrwablePrivate pStamp and lastStamp values. If the values - * are different that means we have to update the clipping info. + * cliprect information by calling XF86DRIGetDrawableInfo(). This is + * usually called by the DRI_MESA_VALIDATE_DRAWABLE_INFO macro which + * compares the __DRIdrwablePrivate pStamp and lastStamp values. If + * the values are different that means we have to update the clipping + * info. */ void driMesaUpdateDrawableInfo(Display *dpy, int scrn, __DRIdrawablePrivate *pdp) @@ -571,9 +604,9 @@ static void *driMesaCreateDrawable(Display *dpy, int scrn, GLXDrawable draw, } static __DRIdrawable *driMesaGetDrawable(Display *dpy, GLXDrawable draw, - void *private) + void *screenPrivate) { - __DRIscreenPrivate *psp = (__DRIscreenPrivate *)private; + __DRIscreenPrivate *psp = (__DRIscreenPrivate *) screenPrivate; /* ** Make sure this routine returns NULL if the drawable is not bound @@ -582,17 +615,22 @@ static __DRIdrawable *driMesaGetDrawable(Display *dpy, GLXDrawable draw, return __driMesaFindDrawable(psp->drawHash, draw); } -static void driMesaSwapBuffers(Display *dpy, void *private) +/* + * XXX if we get rid of the XMesa function table then we should probably + * get rid of this function and require each driver to implement a + * driMesaSwapBuffers function. + */ +static void driMesaSwapBuffers(Display *dpy, void *drawPrivate) { - __DRIdrawablePrivate *pdp = (__DRIdrawablePrivate *)private; + __DRIdrawablePrivate *pdp = (__DRIdrawablePrivate *) drawPrivate; __DRIscreenPrivate *psp = pdp->driScreenPriv; (*psp->MesaAPI.SwapBuffers)(pdp); } -static void driMesaDestroyDrawable(Display *dpy, void *private) +static void driMesaDestroyDrawable(Display *dpy, void *drawPrivate) { - __DRIdrawablePrivate *pdp = (__DRIdrawablePrivate *)private; + __DRIdrawablePrivate *pdp = (__DRIdrawablePrivate *)drawPrivate; __DRIscreenPrivate *psp = pdp->driScreenPriv; int scrn = psp->myNum; @@ -625,18 +663,6 @@ static void *driMesaCreateContext(Display *dpy, XVisualInfo *vis, void *shared, return NULL; } - if (!psp->dummyContextPriv.driScreenPriv) { - if (!XF86DRICreateContext(dpy, vis->screen, vis->visual, - &psp->dummyContextPriv.contextID, - &psp->dummyContextPriv.hHWContext)) { - return NULL; - } - psp->dummyContextPriv.driScreenPriv = psp; - psp->dummyContextPriv.mesaContext = NULL; - psp->dummyContextPriv.driDrawablePriv = NULL; - /* No other fields should be used! */ - } - /* Create the hash table */ if (!psp->drawHash) psp->drawHash = drmHashCreate(); @@ -656,6 +682,29 @@ static void *driMesaCreateContext(Display *dpy, XVisualInfo *vis, void *shared, return NULL; } + /* This is moved because the Xserver creates a global dummy context + * the first time XF86DRICreateContext is called. + */ + + if (!psp->dummyContextPriv.driScreenPriv) { +#if 0 + /* We no longer use this cause we have the shared dummyContext + * in the SAREA. + */ + if (!XF86DRICreateContext(dpy, vis->screen, vis->visual, + &psp->dummyContextPriv.contextID, + &psp->dummyContextPriv.hHWContext)) { + return NULL; + } +#endif + psp->dummyContextPriv.hHWContext = psp->pSAREA->dummy_context; + psp->dummyContextPriv.driScreenPriv = psp; + psp->dummyContextPriv.mesaContext = NULL; + psp->dummyContextPriv.driDrawablePriv = NULL; + psp->dummyContextPriv.driverPrivate = NULL; + /* No other fields should be used! */ + } + for (i = 0; i < psp->numVisuals; i++) { if (psp->visuals[i].vid == vis->visualid) { GLvisual *mesaVis = psp->visuals[i].mesaVisual; @@ -672,6 +721,7 @@ static void *driMesaCreateContext(Display *dpy, XVisualInfo *vis, void *shared, else { gl_destroy_context(pcp->mesaContext); pcp->mesaContext = NULL; + pcp->driverPrivate = NULL; } } } @@ -692,9 +742,9 @@ static void *driMesaCreateContext(Display *dpy, XVisualInfo *vis, void *shared, return pcp; } -static void driMesaDestroyContext(Display *dpy, int scrn, void *private) +static void driMesaDestroyContext(Display *dpy, int scrn, void *contextPrivate) { - __DRIcontextPrivate *pcp = (__DRIcontextPrivate *)private; + __DRIcontextPrivate *pcp = (__DRIcontextPrivate *) contextPrivate; __DRIscreenPrivate *psp; __DRIdrawablePrivate *pdp; @@ -708,9 +758,9 @@ static void driMesaDestroyContext(Display *dpy, int scrn, void *private) } } __driMesaGarbageCollectDrawables(pcp->driScreenPriv->drawHash); - (void)XF86DRIDestroyContext(dpy, scrn, pcp->contextID); (*pcp->driScreenPriv->MesaAPI.DestroyContext)(pcp); gl_destroy_context(pcp->mesaContext); + (void)XF86DRIDestroyContext(dpy, scrn, pcp->contextID); Xfree(pcp); } } @@ -757,6 +807,8 @@ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, psp->fd = drmOpen(NULL,BusID); if (psp->fd < 0) { + fprintf(stderr, "libGL error: failed to open DRM: %s\n", strerror(-psp->fd)); + fprintf(stderr, "libGL error: reverting to (slow) indirect rendering\n"); Xfree(BusID); Xfree(psp); (void)XF86DRICloseConnection(dpy, scrn); @@ -793,6 +845,11 @@ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, return NULL; } + /* + * Get device name (like "tdfx") and the ddx version numbers. + * We'll check the version in each DRI driver's "createScreen" + * function. + */ if (!XF86DRIGetClientDriverName(dpy, scrn, &psp->ddxMajor, &psp->ddxMinor, @@ -804,8 +861,17 @@ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, return NULL; } + /* + * XXX this XMesa indirection may go away. + */ driMesaInitAPI(&psp->MesaAPI); + /* + * Get device-specific info. pDevPriv will point to a struct + * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h) + * that has information about the screen size, depth, pitch, + * ancilliary buffers, DRM mmap handles, etc. + */ if (!XF86DRIGetDeviceInfo(dpy, scrn, &hFB, &psp->fbOrigin, @@ -822,6 +888,9 @@ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, psp->fbHeight = DisplayHeight(dpy, scrn); psp->fbBPP = 32; /* NOT_DONE: Get this from X server */ + /* + * Map the framebuffer region. + */ if (drmMap(psp->fd, hFB, psp->fbSize, (drmAddressPtr)&psp->pFB)) { Xfree(psp->pDevPriv); (void)drmClose(psp->fd); @@ -830,6 +899,10 @@ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, return NULL; } + /* + * Map the SAREA region. Further mmap regions may be setup in + * each DRI driver's "createScreen" function. + */ if (drmMap(psp->fd, hSAREA, SAREA_MAX, (drmAddressPtr)&psp->pSAREA)) { (void)drmUnmap((drmAddress)psp->pFB, psp->fbSize); Xfree(psp->pDevPriv); @@ -839,6 +912,9 @@ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, return NULL; } + /* + * Allocate space for an array of visual records and initialize them. + */ psp->numVisuals = numConfigs; psp->visuals = (__DRIvisualPrivate *)Xmalloc(numConfigs * sizeof(__DRIvisualPrivate)); @@ -922,9 +998,9 @@ static void *driMesaCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, return (void *)psp; } -static void driMesaDestroyScreen(Display *dpy, int scrn, void *private) +static void driMesaDestroyScreen(Display *dpy, int scrn, void *screenPrivate) { - __DRIscreenPrivate *psp = (__DRIscreenPrivate *)private; + __DRIscreenPrivate *psp = (__DRIscreenPrivate *) screenPrivate; if (psp) { #if 0 @@ -965,13 +1041,14 @@ static void driMesaDestroyScreen(Display *dpy, int scrn, void *private) /* - * This is the entrypoint into the driver. - * The driCreateScreen name is the symbol that libGL.so fetches. + * This is the entrypoint into the DRI 3D driver. + * The driCreateScreen name is the symbol that libGL.so fetches via + * dlsym() in order to bootstrap the driver. */ void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, int numConfigs, __GLXvisualConfig *config) { - return driMesaCreateScreen(dpy, scrn, psc, numConfigs, config); + return driMesaCreateScreen(dpy, scrn, psc, numConfigs, config); } diff --git a/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c b/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c index 46ff452b1..2d402e10b 100644 --- a/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c +++ b/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c @@ -1,4 +1,31 @@ /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgaioctl.c,v 1.9 2001/01/08 01:07:18 martin Exp $ */ +/* + * Copyright 2000-2001 VA Linux Systems, 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"), + * 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 + * the 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 MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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: + * Keith Whitwell <keithw@valinux.com> + * Gareth Hughes <gareth@valinux.com> + */ #include <stdio.h> @@ -20,67 +47,29 @@ #include <sys/ioctl.h> static void mga_iload_dma_ioctl(mgaContextPtr mmesa, - unsigned long dest, + unsigned long dest, int length) { - int retcode; - drm_mga_iload_t iload; drmBufPtr buf = mmesa->iload_buffer; - - iload.idx = buf->idx; - iload.destOrg = dest; - iload.length = length; + int ret; - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) + if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "DRM_IOCTL_MGA_ILOAD idx %d dst %x length %d\n", - iload.idx, iload.destOrg, iload.length); - - - if ((retcode = ioctl(mmesa->driFd, DRM_IOCTL_MGA_ILOAD, &iload))) { - printf("send iload retcode = %d\n", retcode); + buf->idx, (int) dest, length); + + ret = drmMGATextureLoad( mmesa->driFd, buf->idx, dest, length ); + if ( ret < 0 ) { + printf("send iload retcode = %d\n", ret); exit(1); } mmesa->iload_buffer = 0; - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) + if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "finished iload dma put\n"); } -int mgaUpdateLock( mgaContextPtr mmesa, drmLockFlags flags ) -{ - drm_lock_t lock; - int retcode; - - lock.flags = 0; - - if (mmesa->sarea->last_quiescent != mmesa->sarea->last_enqueue && - flags & DRM_LOCK_QUIESCENT) { - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) - fprintf(stderr, "mgaLockQuiescent\n"); - lock.flags |= _DRM_LOCK_QUIESCENT; - } - - if (flags & DRM_LOCK_FLUSH) lock.flags |= _DRM_LOCK_FLUSH; - if (flags & DRM_LOCK_FLUSH_ALL) lock.flags |= _DRM_LOCK_FLUSH_ALL; - - if (!lock.flags) - return 0; - - retcode = ioctl(mmesa->driFd, DRM_IOCTL_MGA_FLUSH, &lock); - if(retcode != 0) { - fprintf(stderr, "Lockupdate failed\n"); - if(retcode == EACCES) exit(1); - else return -1; - } - - if(flags & DRM_LOCK_QUIESCENT) - mmesa->sarea->last_quiescent = mmesa->sarea->last_enqueue; - - return 0; -} - drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa ) { int idx = 0; @@ -88,17 +77,17 @@ drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa ) drmDMAReq dma; int retcode; drmBufPtr buf; - + if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "Getting dma buffer\n"); - + dma.context = mmesa->hHWContext; dma.send_count = 0; dma.send_list = NULL; dma.send_sizes = NULL; dma.flags = 0; dma.request_count = 1; - dma.request_size = MGA_DMA_BUF_SZ; + dma.request_size = MGA_BUFFER_SIZE; dma.request_list = &idx; dma.request_sizes = &size; dma.granted_count = 0; @@ -106,34 +95,35 @@ drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa ) if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "drmDMA (get) ctx %d count %d size 0x%x\n", - dma.context, dma.request_count, + dma.context, dma.request_count, dma.request_size); while (1) { retcode = drmDMA(mmesa->driFd, &dma); if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) - fprintf(stderr, "retcode %d sz %d idx %d count %d\n", + fprintf(stderr, "retcode %d sz %d idx %d count %d\n", retcode, dma.request_sizes[0], dma.request_list[0], dma.granted_count); - if (retcode == 0 && + if (retcode == 0 && dma.request_sizes[0] && - dma.granted_count) + dma.granted_count) break; - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) + if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "\n\nflush"); - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH ); + + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT ); } buf = &(mmesa->mgaScreen->bufs->list[idx]); buf->used = 0; if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) - fprintf(stderr, + fprintf(stderr, "drmDMA (get) returns size[0] 0x%x idx[0] %d\n" "dma_buffer now: buf idx: %d size: %d used: %d addr %p\n", dma.request_sizes[0], dma.request_list[0], @@ -149,73 +139,71 @@ drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa ) -GLbitfield mgaClear( GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint cx, GLint cy, GLint cw, GLint ch ) +static GLbitfield +mgaDDClear( GLcontext *ctx, GLbitfield mask, GLboolean all, + GLint cx, GLint cy, GLint cw, GLint ch ) { - mgaContextPtr mmesa = MGA_CONTEXT( ctx ); + mgaContextPtr mmesa = MGA_CONTEXT(ctx); __DRIdrawablePrivate *dPriv = mmesa->driDrawable; - drm_mga_clear_t clear; - int retcode; + GLuint flags = 0; + GLuint clear_color = mmesa->ClearColor; + GLuint clear_depth = 0; + GLuint color_mask = 0; + GLuint depth_mask = 0; + int ret; int i; static int nrclears; - clear.flags = 0; - clear.clear_color = mmesa->ClearColor; - clear.clear_depth = 0; - clear.clear_depth_mask = 0; - FLUSH_BATCH( mmesa ); - - if (mask & DD_FRONT_LEFT_BIT) { - clear.flags |= MGA_FRONT; - clear.clear_color_mask = mmesa->Setup[MGA_CTXREG_PLNWT]; + + if ( mask & DD_FRONT_LEFT_BIT ) { + flags |= MGA_FRONT; + color_mask = mmesa->setup.plnwt; mask &= ~DD_FRONT_LEFT_BIT; } - if (mask & DD_BACK_LEFT_BIT) { - clear.flags |= MGA_BACK; - clear.clear_color_mask = mmesa->Setup[MGA_CTXREG_PLNWT]; + if ( mask & DD_BACK_LEFT_BIT ) { + flags |= MGA_BACK; + color_mask = mmesa->setup.plnwt; mask &= ~DD_BACK_LEFT_BIT; } - if ((mask & DD_DEPTH_BIT) && ctx->Depth.Mask) { - clear.flags |= MGA_DEPTH; - clear.clear_depth_mask |= mmesa->depth_clear_mask; - clear.clear_depth = (mmesa->ClearDepth & - mmesa->depth_clear_mask); + if ( (mask & DD_DEPTH_BIT) && ctx->Depth.Mask ) { + flags |= MGA_DEPTH; + clear_depth = (mmesa->ClearDepth & mmesa->depth_clear_mask); + depth_mask |= mmesa->depth_clear_mask; mask &= ~DD_DEPTH_BIT; } - if ((mask & DD_STENCIL_BIT) && mmesa->hw_stencil) { - clear.flags |= MGA_DEPTH; - clear.clear_depth_mask |= mmesa->stencil_clear_mask; - clear.clear_depth |= (ctx->Stencil.Clear & - mmesa->stencil_clear_mask); + if ( (mask & DD_STENCIL_BIT) && mmesa->hw_stencil ) { + flags |= MGA_DEPTH; + clear_depth |= (ctx->Stencil.Clear & mmesa->stencil_clear_mask); + depth_mask |= mmesa->stencil_clear_mask; mask &= ~DD_STENCIL_BIT; } - if (!clear.flags) + if ( !flags ) return mask; LOCK_HARDWARE( mmesa ); - if (mmesa->dirty_cliprects) - mgaUpdateRects( mmesa, (MGA_FRONT|MGA_BACK)); + if ( mmesa->dirty_cliprects ) + mgaUpdateRects( mmesa, (MGA_FRONT | MGA_BACK) ); /* flip top to bottom */ cy = dPriv->h-cy-ch; cx += mmesa->drawX; cy += mmesa->drawY; - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) - fprintf(stderr, "Clear, bufs %x nbox %d\n", - (int)clear.flags, (int)mmesa->numClipRects); + if ( MGA_DEBUG & DEBUG_VERBOSE_IOCTL ) + fprintf( stderr, "Clear, bufs %x nbox %d\n", + (int)flags, (int)mmesa->numClipRects ); - for (i = 0 ; i < mmesa->numClipRects ; ) - { + for (i = 0 ; i < mmesa->numClipRects ; ) + { int nr = MIN2(i + MGA_NR_SAREA_CLIPRECTS, mmesa->numClipRects); - XF86DRIClipRectRec *box = mmesa->pClipRects; - drm_clip_rect_t *b = mmesa->sarea->boxes; + XF86DRIClipRectPtr box = mmesa->pClipRects; + XF86DRIClipRectPtr b = mmesa->sarea->boxes; int n = 0; if (!all) { @@ -225,7 +213,7 @@ GLbitfield mgaClear( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint w = box[i].x2 - x; GLint h = box[i].y2 - y; - if (x < cx) w -= cx - x, x = cx; + if (x < cx) w -= cx - x, x = cx; if (y < cy) h -= cy - y, y = cy; if (x + w > cx + cw) w = cx + cw - x; if (y + h > cy + ch) h = cy + ch - y; @@ -241,28 +229,28 @@ GLbitfield mgaClear( GLcontext *ctx, GLbitfield mask, GLboolean all, } } else { for ( ; i < nr ; i++) { - *b++ = *(drm_clip_rect_t *)&box[i]; + *b++ = *(XF86DRIClipRectPtr)&box[i]; n++; } } - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) - fprintf(stderr, - "DRM_IOCTL_MGA_CLEAR flag 0x%x color %x depth %x nbox %d\n", - clear.flags, clear.clear_color, - clear.clear_depth, mmesa->sarea->nbox); - + if ( MGA_DEBUG & DEBUG_VERBOSE_IOCTL ) + fprintf( stderr, + "DRM_IOCTL_MGA_CLEAR flag 0x%x color %x depth %x nbox %d\n", + flags, clear_color, clear_depth, mmesa->sarea->nbox ); mmesa->sarea->nbox = n; - retcode = ioctl(mmesa->driFd, DRM_IOCTL_MGA_CLEAR, &clear); - if (retcode) { - printf("send clear retcode = %d\n", retcode); - exit(1); + ret = drmMGAClear( mmesa->driFd, flags, + clear_color, clear_depth, + color_mask, depth_mask ); + if ( ret ) { + fprintf( stderr, "send clear retcode = %d\n", ret ); + exit( 1 ); } - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) - fprintf(stderr, "finished clear %d\n", ++nrclears); + if ( MGA_DEBUG & DEBUG_VERBOSE_IOCTL ) + fprintf( stderr, "finished clear %d\n", ++nrclears ); } UNLOCK_HARDWARE( mmesa ); @@ -277,28 +265,55 @@ int nrswaps; /* - * Copy the back buffer to the front buffer. + * Copy the back buffer to the front buffer. */ -void mgaSwapBuffers( mgaContextPtr mmesa ) +void mgaSwapBuffers( mgaContextPtr mmesa ) { __DRIdrawablePrivate *dPriv = mmesa->driDrawable; XF86DRIClipRectPtr pbox; - int nbox; - drm_mga_swap_t swap; - int retcode; - int i; - int tmp; - + GLint nbox; + GLint ret, wait = 0; + GLint i; + GLuint last_frame, last_wrap; FLUSH_BATCH( mmesa ); LOCK_HARDWARE( mmesa ); - + + last_frame = mmesa->sarea->last_frame.head; + last_wrap = mmesa->sarea->last_frame.wrap; + + /* FIXME: Add a timeout to this loop... + */ + while ( 1 ) { + if ( last_wrap < mmesa->sarea->last_wrap || + ( last_wrap == mmesa->sarea->last_wrap && + last_frame <= (MGA_READ( MGAREG_PRIMADDRESS ) - + mmesa->primary_offset) ) ) { + break; + } + if ( 0 ) { + wait++; + fprintf( stderr, " last: head=0x%06x wrap=%d\n", + last_frame, last_wrap ); + fprintf( stderr, " head: head=0x%06x wrap=%d\n", + MGA_READ( MGAREG_PRIMADDRESS ) - mmesa->primary_offset, + mmesa->sarea->last_wrap ); + } + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH ); + + for ( i = 0 ; i < 1024 ; i++ ) { + /* Don't just hammer the register... */ + } + } + if ( wait ) + fprintf( stderr, "\n" ); + /* Use the frontbuffer cliprects */ - if (mmesa->dirty_cliprects & MGA_FRONT) + if (mmesa->dirty_cliprects & MGA_FRONT) mgaUpdateRects( mmesa, MGA_FRONT ); - + pbox = dPriv->pClipRects; nbox = dPriv->numClipRects; @@ -306,83 +321,80 @@ void mgaSwapBuffers( mgaContextPtr mmesa ) for (i = 0 ; i < nbox ; ) { int nr = MIN2(i + MGA_NR_SAREA_CLIPRECTS, dPriv->numClipRects); - XF86DRIClipRectRec *b = (XF86DRIClipRectRec *)mmesa->sarea->boxes; + XF86DRIClipRectPtr b = mmesa->sarea->boxes; mmesa->sarea->nbox = nr - i; - - for ( ; i < nr ; i++) + + for ( ; i < nr ; i++) *b++ = pbox[i]; - - if((retcode = ioctl(mmesa->driFd, DRM_IOCTL_MGA_SWAP, &swap))) { - printf("send swap retcode = %d\n", retcode); - UNLOCK_HARDWARE( mmesa ); + + if (0) + fprintf(stderr, "DRM_IOCTL_MGA_SWAP\n"); + + ret = drmMGASwapBuffers( mmesa->driFd ); + if ( ret ) { + printf("send swap retcode = %d\n", ret); exit(1); } } - tmp = GET_ENQUEUE_AGE(mmesa); - UNLOCK_HARDWARE( mmesa ); - if (GET_DISPATCH_AGE(mmesa) < mmesa->lastSwap) - mgaWaitAge(mmesa, mmesa->lastSwap); - - mmesa->lastSwap = tmp; mmesa->dirty |= MGA_UPLOAD_CLIPRECTS; } /* This is overkill */ -void mgaDDFinish( GLcontext *ctx ) +void mgaDDFinish( GLcontext *ctx ) { mgaContextPtr mmesa = MGA_CONTEXT(ctx); FLUSH_BATCH( mmesa ); - if (mmesa->sarea->last_quiescent != mmesa->sarea->last_enqueue) { + if (1/*mmesa->sarea->last_quiescent != mmesa->sarea->last_enqueue*/) { if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "mgaRegetLockQuiescent\n"); LOCK_HARDWARE( mmesa ); - mgaUpdateLock( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH); + UPDATE_LOCK( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH ); UNLOCK_HARDWARE( mmesa ); mmesa->sarea->last_quiescent = mmesa->sarea->last_enqueue; } } -void mgaWaitAgeLocked( mgaContextPtr mmesa, int age ) +void mgaWaitAgeLocked( mgaContextPtr mmesa, int age ) { if (GET_DISPATCH_AGE(mmesa) < age) { - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH ); + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH ); } } -void mgaWaitAge( mgaContextPtr mmesa, int age ) +void mgaWaitAge( mgaContextPtr mmesa, int age ) { if (GET_DISPATCH_AGE(mmesa) < age) { LOCK_HARDWARE(mmesa); if (GET_DISPATCH_AGE(mmesa) < age) { - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH ); + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH ); } UNLOCK_HARDWARE(mmesa); } } -static int intersect_rect( drm_clip_rect_t *out, - drm_clip_rect_t *a, - drm_clip_rect_t *b ) +static int intersect_rect( XF86DRIClipRectPtr out, + XF86DRIClipRectPtr a, + XF86DRIClipRectPtr b ) { *out = *a; if (b->x1 > out->x1) out->x1 = b->x1; if (b->y1 > out->y1) out->y1 = b->y1; if (b->x2 < out->x2) out->x2 = b->x2; if (b->y2 < out->y2) out->y2 = b->y2; - if (out->x1 >= out->x2) return 0; - if (out->y1 >= out->y2) return 0; + if (out->x1 > out->x2) return 0; + if (out->y1 > out->y2) return 0; return 1; } @@ -395,12 +407,13 @@ static void age_mmesa( mgaContextPtr mmesa, int age ) if (mmesa->CurrentTexObj[1]) mmesa->CurrentTexObj[1]->age = age; } +static int __break_vertex = 0; + void mgaFlushVerticesLocked( mgaContextPtr mmesa ) { - drm_clip_rect_t *pbox = (drm_clip_rect_t *)mmesa->pClipRects; + XF86DRIClipRectPtr pbox = mmesa->pClipRects; int nbox = mmesa->numClipRects; drmBufPtr buffer = mmesa->vertex_dma_buffer; - drm_mga_vertex_t vertex; int i; mmesa->vertex_dma_buffer = 0; @@ -411,104 +424,108 @@ void mgaFlushVerticesLocked( mgaContextPtr mmesa ) if (mmesa->dirty_cliprects & mmesa->draw_buffer) mgaUpdateRects( mmesa, mmesa->draw_buffer ); - if (mmesa->dirty & ~MGA_UPLOAD_CLIPRECTS) + if (mmesa->dirty & ~MGA_UPLOAD_CLIPRECTS) mgaEmitHwStateLocked( mmesa ); /* FIXME: Workaround bug in kernel module. */ - mmesa->sarea->dirty |= MGA_UPLOAD_CTX; - - vertex.idx = buffer->idx; - vertex.used = buffer->used; - vertex.discard = 0; + mmesa->sarea->dirty |= MGA_UPLOAD_CONTEXT; if (!nbox) - vertex.used = 0; + buffer->used = 0; if (nbox >= MGA_NR_SAREA_CLIPRECTS) mmesa->dirty |= MGA_UPLOAD_CLIPRECTS; #if 0 - if (!vertex.used || !(mmesa->dirty & MGA_UPLOAD_CLIPRECTS)) + if (!buffer->used || !(mmesa->dirty & MGA_UPLOAD_CLIPRECTS)) { - if (nbox == 1) + if (nbox == 1) mmesa->sarea->nbox = 0; else mmesa->sarea->nbox = nbox; - if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) + if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "Firing vertex -- case a nbox %d\n", nbox); - vertex.discard = 1; - ioctl(mmesa->driFd, DRM_IOCTL_MGA_VERTEX, &vertex); + drmMGAFlushVertexBuffer( mmesa->driFd, buffer->idx, buffer->used, 1 ); age_mmesa(mmesa, mmesa->sarea->last_enqueue); - } - else + } + else #endif - { + { for (i = 0 ; i < nbox ; ) { int nr = MIN2(i + MGA_NR_SAREA_CLIPRECTS, nbox); - drm_clip_rect_t *b = mmesa->sarea->boxes; + XF86DRIClipRectPtr b = mmesa->sarea->boxes; + int discard = 0; if (mmesa->scissor) { - mmesa->sarea->nbox = 0; + mmesa->sarea->nbox = 0; - for ( ; i < nr ; i++) { + for ( ; i < nr ; i++) { *b = pbox[i]; if (intersect_rect(b, b, &mmesa->scissor_rect)) { mmesa->sarea->nbox++; b++; - } + } } /* Culled? */ if (!mmesa->sarea->nbox) { if (nr < nbox) continue; - vertex.used = 0; + buffer->used = 0; } } else { mmesa->sarea->nbox = nr - i; - for ( ; i < nr ; i++) + for ( ; i < nr ; i++) *b++ = pbox[i]; } /* Finished with the buffer? */ - if (nr == nbox) - vertex.discard = 1; + if (nr == nbox) + discard = 1; mmesa->sarea->dirty |= MGA_UPLOAD_CLIPRECTS; - ioctl(mmesa->driFd, DRM_IOCTL_MGA_VERTEX, &vertex); + drmMGAFlushVertexBuffer( mmesa->driFd, buffer->idx, + buffer->used, discard ); age_mmesa(mmesa, mmesa->sarea->last_enqueue); } } + /* Do we really need to do this ? */ +#ifdef __i386__ + if ( __break_vertex ) { + __asm__ __volatile__ ( "int $3" ); + } +#endif + mmesa->dirty &= ~MGA_UPLOAD_CLIPRECTS; } -void mgaFlushVertices( mgaContextPtr mmesa ) +void mgaFlushVertices( mgaContextPtr mmesa ) { LOCK_HARDWARE( mmesa ); mgaFlushVerticesLocked( mmesa ); UNLOCK_HARDWARE( mmesa ); } -void mgaFlushEltsLocked( mgaContextPtr mmesa ) +void mgaFlushEltsLocked( mgaContextPtr mmesa ) { if (mmesa->first_elt != mmesa->next_elt) { - mgaFireEltsLocked( mmesa, - ((char *)mmesa->first_elt - + mgaFireEltsLocked( mmesa, + ((char *)mmesa->first_elt - (char *)mmesa->elt_buf->address), - ((char *)mmesa->next_elt - + ((char *)mmesa->next_elt - (char *)mmesa->elt_buf->address), 0 ); mmesa->first_elt = mmesa->next_elt; } } -void mgaFlushElts( mgaContextPtr mmesa ) +void mgaFlushElts( mgaContextPtr mmesa ) { LOCK_HARDWARE( mmesa ); mgaFlushEltsLocked( mmesa ); @@ -524,12 +541,12 @@ GLuint *mgaAllocVertexDwords( mgaContextPtr mmesa, int dwords ) if (!mmesa->vertex_dma_buffer) { LOCK_HARDWARE( mmesa ); - if (mmesa->first_elt != mmesa->next_elt) + if (mmesa->first_elt != mmesa->next_elt) mgaFlushEltsLocked(mmesa); mmesa->vertex_dma_buffer = mga_get_buffer_ioctl( mmesa ); UNLOCK_HARDWARE( mmesa ); - } else if (mmesa->vertex_dma_buffer->used + bytes > + } else if (mmesa->vertex_dma_buffer->used + bytes > mmesa->vertex_dma_buffer->total) { LOCK_HARDWARE( mmesa ); mgaFlushVerticesLocked( mmesa ); @@ -537,7 +554,7 @@ GLuint *mgaAllocVertexDwords( mgaContextPtr mmesa, int dwords ) UNLOCK_HARDWARE( mmesa ); } - head = (GLuint *)((char *)mmesa->vertex_dma_buffer->address + + head = (GLuint *)((char *)mmesa->vertex_dma_buffer->address + mmesa->vertex_dma_buffer->used); mmesa->vertex_dma_buffer->used += bytes; @@ -545,7 +562,7 @@ GLuint *mgaAllocVertexDwords( mgaContextPtr mmesa, int dwords ) } -void mgaFireILoadLocked( mgaContextPtr mmesa, +void mgaFireILoadLocked( mgaContextPtr mmesa, GLuint offset, GLuint length ) { if (!mmesa->iload_buffer) { @@ -556,10 +573,7 @@ void mgaFireILoadLocked( mgaContextPtr mmesa, if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "mgaFireILoad idx %d ofs 0x%x length %d\n", mmesa->iload_buffer->idx, (int)offset, (int)length ); - - /* HACK - */ - mgaUpdateLock( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH); + mga_iload_dma_ioctl( mmesa, offset, length ); } @@ -597,22 +611,21 @@ void mgaDDFlush( GLcontext *ctx ) */ if (1 || GET_DISPATCH_AGE( mmesa ) < mmesa->sarea->last_enqueue) { LOCK_HARDWARE( mmesa ); - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH ); + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH ); UNLOCK_HARDWARE( mmesa ); } } -void mgaFireEltsLocked( mgaContextPtr mmesa, - GLuint start, +void mgaFireEltsLocked( mgaContextPtr mmesa, + GLuint start, GLuint end, GLuint discard ) { - drm_clip_rect_t *pbox = (drm_clip_rect_t *)mmesa->pClipRects; + XF86DRIClipRectPtr pbox = mmesa->pClipRects; int nbox = mmesa->numClipRects; drmBufPtr buffer = mmesa->elt_buf; - drm_mga_indices_t elts; int i; if (!buffer) @@ -621,74 +634,69 @@ void mgaFireEltsLocked( mgaContextPtr mmesa, if (mmesa->dirty_cliprects & mmesa->draw_buffer) mgaUpdateRects( mmesa, mmesa->draw_buffer ); - if (mmesa->dirty & ~MGA_UPLOAD_CLIPRECTS) + if (mmesa->dirty & ~MGA_UPLOAD_CLIPRECTS) mgaEmitHwStateLocked( mmesa ); /* FIXME: Workaround bug in kernel module. */ - mmesa->sarea->dirty |= MGA_UPLOAD_CTX; - - elts.idx = buffer->idx; - elts.start = start; - elts.end = end; - elts.discard = 0; + mmesa->sarea->dirty |= MGA_UPLOAD_CONTEXT; if (!nbox) - elts.end = start; + end = start; if (nbox >= MGA_NR_SAREA_CLIPRECTS) mmesa->dirty |= MGA_UPLOAD_CLIPRECTS; - if (elts.end == start || !(mmesa->dirty & MGA_UPLOAD_CLIPRECTS)) + if ( end == start || !(mmesa->dirty & MGA_UPLOAD_CLIPRECTS)) { - if (nbox == 1) + if (nbox == 1) mmesa->sarea->nbox = 0; else mmesa->sarea->nbox = nbox; - elts.discard = discard; - ioctl(mmesa->driFd, DRM_IOCTL_MGA_INDICES, &elts); + drmMGAFlushIndices( mmesa->driFd, buffer->idx, start, end, discard ); age_mmesa(mmesa, mmesa->sarea->last_enqueue); - } - else - { + } + else + { for (i = 0 ; i < nbox ; ) { int nr = MIN2(i + MGA_NR_SAREA_CLIPRECTS, nbox); - drm_clip_rect_t *b = mmesa->sarea->boxes; + XF86DRIClipRectPtr b = mmesa->sarea->boxes; + int d = 0; if (mmesa->scissor) { - mmesa->sarea->nbox = 0; + mmesa->sarea->nbox = 0; - for ( ; i < nr ; i++) { + for ( ; i < nr ; i++) { *b = pbox[i]; if (intersect_rect(b, b, &mmesa->scissor_rect)) { mmesa->sarea->nbox++; b++; - } + } } /* Culled? */ if (!mmesa->sarea->nbox) { if (nr < nbox) continue; - elts.end = start; + end = start; } } else { mmesa->sarea->nbox = nr - i; - for ( ; i < nr ; i++) + for ( ; i < nr ; i++) *b++ = pbox[i]; } /* Potentially finished with the buffer? */ - if (nr == nbox) - elts.discard = discard; + if (nr == nbox) + d = discard; mmesa->sarea->dirty |= MGA_UPLOAD_CLIPRECTS; - ioctl(mmesa->driFd, DRM_IOCTL_MGA_INDICES, &elts); + drmMGAFlushIndices( mmesa->driFd, buffer->idx, start, end, d ); age_mmesa(mmesa, mmesa->sarea->last_enqueue); } } @@ -699,20 +707,15 @@ void mgaFireEltsLocked( mgaContextPtr mmesa, void mgaReleaseBufLocked( mgaContextPtr mmesa, drmBufPtr buffer ) { - drm_mga_vertex_t vertex; - if (!buffer) return; - - vertex.idx = buffer->idx; - vertex.used = 0; - vertex.discard = 1; - ioctl(mmesa->driFd, DRM_IOCTL_MGA_VERTEX, &vertex); + + drmMGAFlushVertexBuffer( mmesa->driFd, buffer->idx, 0, 1 ); } void mgaDDInitIoctlFuncs( GLcontext *ctx ) { - ctx->Driver.Clear = mgaClear; - ctx->Driver.Flush = mgaDDFlush; - ctx->Driver.Finish = mgaDDFinish; + ctx->Driver.Clear = mgaDDClear; + ctx->Driver.Flush = mgaDDFlush; + ctx->Driver.Finish = mgaDDFinish; } diff --git a/xc/lib/GL/mesa/src/drv/radeon/radeon_dd.c b/xc/lib/GL/mesa/src/drv/radeon/radeon_dd.c index 63f91a1f0..85bb9bab5 100644 --- a/xc/lib/GL/mesa/src/drv/radeon/radeon_dd.c +++ b/xc/lib/GL/mesa/src/drv/radeon/radeon_dd.c @@ -46,7 +46,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "X86/common_x86_asm.h" #endif -#define RADEON_DATE "20010326" +#define RADEON_DATE "20010402" /* Return the width and height of the current color buffer. diff --git a/xc/lib/GL/mesa/src/drv/radeon/radeon_xmesa.c b/xc/lib/GL/mesa/src/drv/radeon/radeon_xmesa.c index 1f24b8409..ffdbbbb81 100644 --- a/xc/lib/GL/mesa/src/drv/radeon/radeon_xmesa.c +++ b/xc/lib/GL/mesa/src/drv/radeon/radeon_xmesa.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_xmesa.c,v 1.2 2001/01/23 18:14:39 alanh Exp $ */ +/* $XFree86$ */ /************************************************************************** Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and @@ -61,33 +61,31 @@ GLboolean XMesaInitDriver( __DRIscreenPrivate *sPriv ) /* Check the DRI version */ { int major, minor, patch; - if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) { - if (major != 3 || minor != 1 || patch < 0) { - char msg[1000]; - sprintf(msg, "RADEON DRI driver expected DRI version 3.1.x but got version %d.%d.%d", major, minor, patch); - __driMesaMessage(msg); + if ( XF86DRIQueryVersion( sPriv->display, &major, &minor, &patch ) ) { + if ( major != 4 || minor < 0 ) { + char msg[128]; + sprintf( msg, "RADEON DRI driver expected DRI version 4.0.x but got version %d.%d.%d", major, minor, patch ); + __driMesaMessage( msg ); return GL_FALSE; } } } /* Check that the DDX driver version is compatible */ - if (sPriv->ddxMajor != 4 || - sPriv->ddxMinor != 0 || - sPriv->ddxPatch < 0) { - char msg[1000]; - sprintf(msg, "RADEON DRI driver expected DDX driver version 4.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch); - __driMesaMessage(msg); + if ( sPriv->ddxMajor != 4 || + sPriv->ddxMinor < 0 ) { + char msg[128]; + sprintf( msg, "RADEON DRI driver expected DDX driver version 4.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch ); + __driMesaMessage( msg ); return GL_FALSE; } /* Check that the DRM driver version is compatible */ - if (sPriv->drmMajor != 1 || - sPriv->drmMinor != 0 || - sPriv->drmPatch < 0) { - char msg[1000]; - sprintf(msg, "RADEON DRI driver expected DRM driver version 1.0.x but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch); - __driMesaMessage(msg); + if ( sPriv->drmMajor != 1 || + sPriv->drmMinor < 1 ) { + char msg[128]; + sprintf( msg, "RADEON DRI driver expected DRM driver version 1.0.x but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch ); + __driMesaMessage( msg ); return GL_FALSE; } diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.c new file mode 100644 index 000000000..08de9775b --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.c @@ -0,0 +1,908 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * 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 MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS 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. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_tex.h" +#include "tdfx_texman.h" + +#define BAD_ADDRESS ((FxU32) -1) + +/* Verify the consistancy of the texture memory manager. + * This involves: + * Traversing all texture objects and computing total memory used. + * Traverse the free block list and computing total memory free. + * Compare the total free and total used amounts to the total memory size. + * Make various assertions about the results. + */ +static void tdfxTMVerifyFreeList( tdfxContextPtr fxMesa, FxU32 unit ) +{ + struct gl_shared_state *ss = fxMesa->glCtx->Shared; + struct gl_texture_object *texObj; + tdfxSharedStatePtr tss = (tdfxSharedStatePtr)ss->DriverData; + tdfxMemRange *block; + int prevStart = -1, prevEnd = -1; + int totalFree = 0; + int numObj = 0, numRes = 0; + int totalUsed = 0; + + for ( block = tss->freeRanges[unit] ; block ; block = block->next ) { + assert( block->endAddr > 0 ); + assert( block->startAddr <= tss->totalTexMem[unit] ); + assert( block->endAddr <= tss->totalTexMem[unit] ); + assert( (int) block->startAddr > prevStart ); + assert( (int) block->startAddr >= prevEnd ); + prevStart = (int) block->startAddr; + prevEnd = (int) block->endAddr; + totalFree += (block->endAddr - block->startAddr); + } + assert( totalFree == tss->freeTexMem[unit] ); + + for ( texObj = ss->TexObjectList ; texObj ; texObj = texObj->Next ) { + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(texObj); + numObj++; + if ( t ) { + if ( t->isInTM ) { + numRes++; + assert( t->range[0] ); + if ( t->range[unit] ) + totalUsed += (t->range[unit]->endAddr - t->range[unit]->startAddr); + } else { + assert(!t->range[0]); + } + } + } + + fprintf( stderr, + "totalFree: %d totalUsed: %d totalMem: %d #objs=%d #res=%d\n", + tss->freeTexMem[unit], totalUsed, tss->totalTexMem[unit], + numObj, numRes ); + + assert( totalUsed + totalFree == tss->totalTexMem[unit] ); +} + +static void tdfxTMDumpTexMem( tdfxContextPtr fxMesa ) +{ + struct gl_shared_state *ss = fxMesa->glCtx->Shared; + tdfxSharedStatePtr tss = (tdfxSharedStatePtr)ss->DriverData; + struct gl_texture_object *texObj; + tdfxMemRange *r; + FxU32 prev; + + printf( "DUMP Objects:\n" ); + for ( texObj = ss->TexObjectList ; texObj ; texObj = texObj->Next ) { + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(texObj); + + if ( t && t->isInTM ) { + printf( "Obj %8p: %4d info = %p\n", texObj, texObj->Name, t ); + + printf( " isInTM=%d whichTMU=%ld lastTimeUsed=%d\n", + t->isInTM, t->whichTMU, t->lastTimeUsed ); + printf( " tm[0] = %p", t->range[0] ); + assert( t->range[0] ); + if ( t->range[0] ) { + printf( " tm startAddr = %ld endAddr = %ld", + t->range[0]->startAddr, + t->range[0]->endAddr ); + } + printf( "\n" ); + printf( " tm[1] = %p", t->range[1] ); + if ( t->range[1] ) { + printf( " tm startAddr = %ld endAddr = %ld", + t->range[1]->startAddr, + t->range[1]->endAddr ); + } + printf( "\n" ); + } + } + + tdfxTMVerifyFreeList( fxMesa, 0 ); + tdfxTMVerifyFreeList( fxMesa, 1 ); + + printf( "Free memory unit 0: %d bytes\n", tss->freeTexMem[0] ); + prev = 0; + for ( r = tss->freeRanges[0] ; r ; r = r->next ) { + printf( "%8p: start %8ld end %8ld size %8ld gap %8ld\n", + r, r->startAddr, r->endAddr, r->endAddr - r->startAddr, + r->startAddr - prev ); + prev = r->endAddr; + } + + printf( "Free memory unit 1: %d bytes\n", tss->freeTexMem[1] ); + prev = 0; + for ( r = tss->freeRanges[1] ; r ; r = r->next ) { + printf( "%8p: start %8ld end %8ld size %8ld gap %8ld\n", + r, r->startAddr, r->endAddr, r->endAddr - r->startAddr, + r->startAddr - prev ); + prev = r->endAddr; + } +} + + +#ifdef TEXSANITY +static void fubar( void ) +{ + /* GH: What am I meant to do??? */ +} + +/* Sanity Check + */ +static void sanity( tdfxContextPtr fxMesa ) +{ + tdfxMemRange *tmp, *prev, *pos; + + prev = 0; + tmp = fxMesa->freeRanges[0]; + while ( tmp ) { + if ( !tmp->startAddr && !tmp->endAddr ) { + fprintf( stderr, "Textures fubar\n" ); + fubar(); + } + if ( tmp->startAddr >= tmp->endAddr ) { + fprintf( stderr, "Node fubar\n" ); + fubar(); + } + if ( prev && ( prev->startAddr >= tmp->startAddr || + prev->endAddr > tmp->startAddr ) ) { + fprintf( stderr, "Sorting fubar\n" ); + fubar(); + } + prev = tmp; + tmp = tmp->next; + } + + prev = 0; + tmp = fxMesa->freeRanges[1]; + while ( tmp ) { + if ( !tmp->startAddr && !tmp->endAddr ) { + fprintf( stderr, "Textures fubar\n" ); + fubar(); + } + if ( tmp->startAddr >= tmp->endAddr ) { + fprintf( stderr, "Node fubar\n" ); + fubar(); + } + if ( prev && ( prev->startAddr >= tmp->startAddr || + prev->endAddr > tmp->startAddr ) ) { + fprintf( stderr, "Sorting fubar\n" ); + fubar(); + } + prev = tmp; + tmp = tmp->next; + } +} +#endif + + +/* Allocate and initialize a new MemRange struct. Try to allocate it + * from the pool of free MemRange nodes rather than malloc. + */ +static tdfxMemRange * +tdfxTMNewRangeNode( tdfxContextPtr fxMesa, FxU32 start, FxU32 end ) +{ + struct gl_shared_state *ss = fxMesa->glCtx->Shared; + tdfxSharedStatePtr tss = (tdfxSharedStatePtr)ss->DriverData; + tdfxMemRange *range; + + _glthread_LOCK_MUTEX( ss->Mutex ); + if ( tss && tss->rangePool ) { + range = tss->rangePool; + tss->rangePool = tss->rangePool->next; + } else { + range = MALLOC( sizeof(tdfxMemRange) ); + } + _glthread_UNLOCK_MUTEX( ss->Mutex ); + + if ( !range ) { + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, __FUNCTION__ ": out of memory!\n" ); + return NULL; + } + + range->startAddr = start; + range->endAddr = end; + range->next = NULL; + + return range; +} + + +/* Initialize texture memory. We take care of one or both TMU's here. + */ +void tdfxTMInit( tdfxContextPtr fxMesa ) +{ + GLcontext *ctx = fxMesa->glCtx; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, __FUNCTION__ "\n" ); + + if ( !ctx->Shared->DriverData ) { + const char *extensions; + tdfxSharedStatePtr tss = CALLOC_STRUCT( tdfx_shared_state ); + + if ( !tss ) + return; + + LOCK_HARDWARE( fxMesa ); + + extensions = grGetString( GR_EXTENSION ); + + if ( strstr( extensions, " TEXUMA " ) ) { + FxU32 start, end; + + tss->umaTexMemory = GL_TRUE; + + grEnable( GR_TEXTURE_UMA_EXT ); + + start = grTexMinAddress( 0 ); + end = grTexMaxAddress( 0 ); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, " UMA tex memory: %d\n", (int)(end - start) ); + + tss->totalTexMem[0] = end - start; + tss->totalTexMem[1] = 0; + tss->freeTexMem[0] = end - start; + tss->freeTexMem[1] = 0; + tss->freeRanges[0] = tdfxTMNewRangeNode( fxMesa, start, end ); + tss->freeRanges[1] = NULL; + } else { + int unit; + + tss->umaTexMemory = GL_FALSE; + + for ( unit = 0 ; unit < fxMesa->numTMUs ; unit++ ) { + FxU32 start, end; + + start = grTexMinAddress( unit ); + end = grTexMaxAddress( unit ); + + tss->totalTexMem[unit] = end - start; + tss->freeTexMem[unit] = end - start; + tss->freeRanges[unit] = tdfxTMNewRangeNode( fxMesa, start, end ); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, " Split tex memory: %d\n", + (int)(end - start) ); + } + } + + UNLOCK_HARDWARE( fxMesa ); + + tss->rangePool = NULL; + ctx->Shared->DriverData = tss; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, " init UMA: %d\n", tss->umaTexMemory ); + } +} + + +/* Clean-up texture memory before destroying context. + */ +void tdfxTMClose( tdfxContextPtr fxMesa ) +{ + GLcontext *ctx = fxMesa->glCtx; + + if ( ctx->Shared->RefCount == 1 ) { + /* RefCount will soon go to zero, free our 3dfx stuff */ + tdfxSharedStatePtr tss = (tdfxSharedStatePtr)ctx->Shared->DriverData; + int unit; + tdfxMemRange *tmp, *next; + + /* Deallocate the pool of free tdfxMemRange nodes */ + tmp = tss->rangePool; + while ( tmp ) { + next = tmp->next; + FREE( tmp ); + tmp = next; + } + + /* Delete the texture memory block tdfxMemRange nodes */ + for ( unit = 0 ; unit < fxMesa->numTMUs ; unit++ ) { + tmp = tss->freeRanges[unit]; + while ( tmp ) { + next = tmp->next; + FREE( tmp ); + tmp = next; + } + } + + FREE( tss ); + ctx->Shared->DriverData = NULL; + } +} + + + +/* Delete a tdfxMemRange struct. + * We keep a linked list of free/available tdfxMemRange structs to + * avoid extra malloc/free calls. + */ +#define DELETE_RANGE_NODE( tss, range ) \ +do { \ + (range)->next = (tss)->rangePool; \ + (tss)->rangePool = (range); \ +} while (0) + +/* When we've run out of texture memory we have to throw out an + * existing texture to make room for the new one. This function + * determins the texture to throw out. + */ +static struct gl_texture_object * +tdfxTMFindOldestObject( tdfxContextPtr fxMesa, FxU32 unit ) +{ + struct gl_shared_state *ss = fxMesa->glCtx->Shared; + const GLuint bindNumber = fxMesa->texBindNumber; + struct gl_texture_object *oldestObj, *texObj, *lowestPriorityObj; + GLfloat lowestPriority; + GLuint oldestAge; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, __FUNCTION__ "\n" ); + + oldestObj = NULL; + oldestAge = 0; + + lowestPriority = 1.0F; + lowestPriorityObj = NULL; + + for ( texObj = ss->TexObjectList ; texObj ; texObj = texObj->Next ) { + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(texObj); + + if ( t && t->isInTM && + ( ( t->whichTMU == unit ) || + ( t->whichTMU == TDFX_TMU_BOTH ) || + ( t->whichTMU == TDFX_TMU_SPLIT ) ) ) { + GLuint age, lastTime; + + assert( t->range[0] ); + lastTime = t->lastTimeUsed; + + if ( lastTime > bindNumber ) { + /* TODO: check wrap around */ + age = bindNumber + (UINT_MAX - lastTime + 1); + } else { + age = bindNumber - lastTime; + } + if ( age >= oldestAge ) { + oldestAge = age; + oldestObj = texObj; + } + + /* examine priority */ + if ( texObj->Priority < lowestPriority ) { + lowestPriority = texObj->Priority; + lowestPriorityObj = texObj; + } + } + } + + if ( lowestPriority < 1.0 ) { + ASSERT( lowestPriorityObj ); + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, "discard %d pri=%f\n", + lowestPriorityObj->Name, lowestPriority ); + return lowestPriorityObj; + } else { + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) + fprintf( stderr, "discard %d age=%d\n", + oldestObj->Name, oldestAge ); + return oldestObj; + } +} + + +/* Find the address (offset?) at which we can store a new texture. + * <unit> is the texture unit. + * <size> is the texture size in bytes. + */ +static FxU32 tdfxTMFindStartAddr( tdfxContextPtr fxMesa, + FxU32 unit, FxU32 size ) +{ + struct gl_shared_state *ss = fxMesa->glCtx->Shared; + tdfxSharedStatePtr tss = (tdfxSharedStatePtr)ss->DriverData; + struct gl_texture_object *texObj; + tdfxMemRange *prev, *block; + FxU32 result; + + if ( tss->umaTexMemory ) { + assert( unit == TDFX_TMU0 ); + } + + _glthread_LOCK_MUTEX( ss->Mutex ); + while ( 1 ) { + prev = NULL; + block = tss->freeRanges[unit]; + + while ( block ) { + if ( block->endAddr - block->startAddr >= size ) { + /* The texture will fit here */ + result = block->startAddr; + block->startAddr += size; + if ( block->startAddr == block->endAddr ) { + /* Remove this node since it's empty */ + if ( prev ) { + prev->next = block->next; + } else { + tss->freeRanges[unit] = block->next; + } + DELETE_RANGE_NODE( tss, block ); + } + tss->freeTexMem[unit] -= size; + _glthread_UNLOCK_MUTEX( ss->Mutex ); + return result; + } + prev = block; + block = block->next; + } + + /* We failed to find a block large enough to accomodate <size> bytes. + * Find the oldest texObject and free it. + */ + texObj = tdfxTMFindOldestObject( fxMesa, unit ); + if ( texObj ) { + tdfxTMMoveOutTMLocked( fxMesa, texObj ); + fxMesa->stats.texSwaps++; + } else { + gl_problem( NULL, "tdfx driver: extreme texmem fragmentation" ); + _glthread_UNLOCK_MUTEX( ss->Mutex ); + return BAD_ADDRESS; + } + } + + /* never get here, but play it safe */ + _glthread_UNLOCK_MUTEX( ss->Mutex ); + return BAD_ADDRESS; +} + + +/* Remove the given tdfxMemRange node from hardware texture memory. + */ +static void tdfxTMRemoveRangeLocked( tdfxContextPtr fxMesa, + FxU32 unit, tdfxMemRange *range ) +{ + struct gl_shared_state *ss = fxMesa->glCtx->Shared; + tdfxSharedStatePtr tss = (tdfxSharedStatePtr)ss->DriverData; + tdfxMemRange *block, *prev; + + if ( tss->umaTexMemory ) { + assert( unit == TDFX_TMU0 ); + } + + if ( !range ) + return; + + if ( range->startAddr == range->endAddr ) { + DELETE_RANGE_NODE( tss, range ); + return; + } + tss->freeTexMem[unit] += range->endAddr - range->startAddr; + + /* find position in linked list to insert this tdfxMemRange node */ + prev = NULL; + block = tss->freeRanges[unit]; + while ( block ) { + assert( range->startAddr != block->startAddr ); + if ( range->startAddr > block->startAddr ) { + prev = block; + block = block->next; + } else { + break; + } + } + + /* Insert the free block, combine with adjacent blocks when possible */ + range->next = block; + if ( block ) { + if ( range->endAddr == block->startAddr ) { + /* Combine */ + block->startAddr = range->startAddr; + DELETE_RANGE_NODE( tss, range ); + range = block; + } + } + if ( prev ) { + if ( prev->endAddr == range->startAddr ) { + /* Combine */ + prev->endAddr = range->endAddr; + prev->next = range->next; + DELETE_RANGE_NODE( tss, range ); + } else { + prev->next = range; + } + } else { + tss->freeRanges[unit] = range; + } +} + + +/* Allocate space for a texture image. + * <tmu> is the texture unit + * <texmemsize> is the number of bytes to allocate + */ +static tdfxMemRange * +tdfxTMAllocTexMem( tdfxContextPtr fxMesa, FxU32 unit, FxU32 size ) +{ + tdfxMemRange *range = NULL; + FxU32 start; + + start = tdfxTMFindStartAddr( fxMesa, unit, size ); + + if ( start != BAD_ADDRESS ) { + range = tdfxTMNewRangeNode( fxMesa, start, start + size ); + } else { + fprintf( stderr, + "tdfxTMAllocTexMem returned NULL! unit=%ld size=%ld\n", + unit, size ); + } + return range; +} + + +/* Download (copy) the given texture data (all mipmap levels) into the + * Voodoo's texture memory. The texture memory must have already been + * allocated. + */ +void tdfxTMDownloadTextureLocked( tdfxContextPtr fxMesa, + struct gl_texture_object *tObj ) +{ + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(tObj); + FxU32 targetTMU; + GLint l; + + assert( tObj ); + assert( t ); + + targetTMU = t->whichTMU; + + switch ( targetTMU ) { + case TDFX_TMU0: + case TDFX_TMU1: + if ( t->range[targetTMU] ) { + for ( l = t->minLevel ; l <= t->maxLevel && t->image[l].data ; l++ ) { + GrLOD_t glideLod = t->info.largeLodLog2 - l + tObj->BaseLevel; + + grTexDownloadMipMapLevel( targetTMU, + t->range[targetTMU]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_BOTH, + t->image[l].data ); + } + } + break; + + case TDFX_TMU_SPLIT: + if ( t->range[TDFX_TMU0] && t->range[TDFX_TMU1] ) { + for ( l = t->minLevel ; l <= t->maxLevel && t->image[l].data ; l++ ) { + GrLOD_t glideLod = t->info.largeLodLog2 - l + tObj->BaseLevel; + + grTexDownloadMipMapLevel( GR_TMU0, + t->range[TDFX_TMU0]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_ODD, + t->image[l].data ); + + grTexDownloadMipMapLevel( GR_TMU1, + t->range[TDFX_TMU1]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_EVEN, + t->image[l].data ); + } + } + break; + + case TDFX_TMU_BOTH: + if ( t->range[TDFX_TMU0] && t->range[TDFX_TMU1] ) { + for ( l = t->minLevel ; l <= t->maxLevel && t->image[l].data ; l++ ) { + GrLOD_t glideLod = t->info.largeLodLog2 - l + tObj->BaseLevel; + + grTexDownloadMipMapLevel( GR_TMU0, + t->range[TDFX_TMU0]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_BOTH, + t->image[l].data ); + + grTexDownloadMipMapLevel( GR_TMU1, + t->range[TDFX_TMU1]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_BOTH, + t->image[l].data ); + } + } + break; + + default: + gl_problem( NULL, "error in tdfxTMDownloadTexture: bad unit" ); + return; + } +} + + +void tdfxTMReloadMipMapLevelLocked( GLcontext *ctx, + struct gl_texture_object *tObj, + GLint level ) +{ + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(tObj); + GrLOD_t glideLod; + FxU32 unit; + + ASSERT( t->isInTM ); + + unit = t->whichTMU; + glideLod = t->info.largeLodLog2 - level + tObj->BaseLevel; + + switch ( unit ) { + case TDFX_TMU0: + case TDFX_TMU1: + grTexDownloadMipMapLevel( unit, + t->range[unit]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_BOTH, + t->image[level].data ); + break; + + case TDFX_TMU_SPLIT: + grTexDownloadMipMapLevel( GR_TMU0, + t->range[GR_TMU0]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_ODD, + t->image[level].data ); + + grTexDownloadMipMapLevel( GR_TMU1, + t->range[GR_TMU1]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_EVEN, + t->image[level].data ); + break; + + case TDFX_TMU_BOTH: + grTexDownloadMipMapLevel( GR_TMU0, + t->range[GR_TMU0]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_BOTH, + t->image[level].data ); + + grTexDownloadMipMapLevel( GR_TMU1, + t->range[GR_TMU1]->startAddr, + glideLod, + t->info.largeLodLog2, + t->info.aspectRatioLog2, + t->info.format, + GR_MIPMAPLEVELMASK_BOTH, + t->image[level].data ); + break; + + default: + gl_problem( ctx, "error in tdfxTMReloadMipMapLevel(): wrong unit" ); + break; + } +} + + +/* Allocate space for the given texture in texture memory then + * download (copy) it into that space. + */ +void tdfxTMMoveInTMLocked( tdfxContextPtr fxMesa, + struct gl_texture_object *tObj, FxU32 targetTMU ) +{ + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(tObj); + FxU32 size; + + fxMesa->stats.reqTexUpload++; + + if ( t->isInTM ) { + if ( t->whichTMU == targetTMU ) + return; + + if ( targetTMU == TDFX_TMU_SPLIT || t->whichTMU == TDFX_TMU_SPLIT ) { + tdfxTMMoveOutTMLocked( fxMesa, tObj ); + } else { + if ( t->whichTMU == TDFX_TMU_BOTH ) + return; + targetTMU = TDFX_TMU_BOTH; + } + } + + t->whichTMU = targetTMU; + + switch ( targetTMU ) { + case TDFX_TMU0: + case TDFX_TMU1: + size = grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH, &t->info ); + t->range[targetTMU] = tdfxTMAllocTexMem(fxMesa, targetTMU, size); + break; + + case TDFX_TMU_SPLIT: + size = grTexTextureMemRequired( GR_MIPMAPLEVELMASK_ODD, &t->info ); + t->range[TDFX_TMU0] = tdfxTMAllocTexMem( fxMesa, TDFX_TMU0, size ); + if ( t->range[TDFX_TMU0] ) + fxMesa->stats.memTexUpload += size; + + size = grTexTextureMemRequired( GR_MIPMAPLEVELMASK_EVEN, &t->info ); + t->range[TDFX_TMU1] = tdfxTMAllocTexMem( fxMesa, TDFX_TMU1, size ); + break; + + case TDFX_TMU_BOTH: + size = grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH, &t->info ); + t->range[TDFX_TMU0] = tdfxTMAllocTexMem( fxMesa, TDFX_TMU0, size ); + if ( t->range[TDFX_TMU0] ) + fxMesa->stats.memTexUpload += size; + + size = grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH, &t->info ); + t->range[TDFX_TMU1] = tdfxTMAllocTexMem( fxMesa, TDFX_TMU1, size ); + break; + + default: + gl_problem( NULL, "error in tdfxTMMoveInTM() -> bad unit (%d)" ); + return; + } + + t->reloadImages = GL_TRUE; + t->isInTM = GL_TRUE; + + fxMesa->stats.texUpload++; +} + + +/* Move the given texture out of hardware texture memory. + * This deallocates the texture's memory space. + */ +void tdfxTMMoveOutTMLocked( tdfxContextPtr fxMesa, + struct gl_texture_object *tObj ) +{ + struct gl_shared_state *ss = fxMesa->glCtx->Shared; + tdfxSharedStatePtr tss = (tdfxSharedStatePtr)ss->DriverData; + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(tObj); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) { + fprintf( stderr, __FUNCTION__ "( %p (%d) )\n", tObj, tObj->Name ); + tdfxTMVerifyFreeList( fxMesa, 0 ); + tdfxTMVerifyFreeList( fxMesa, 1 ); + } + + if ( !t || !t->isInTM ) + return; + + switch ( t->whichTMU ) { + case TDFX_TMU0: + case TDFX_TMU1: + tdfxTMRemoveRangeLocked( fxMesa, t->whichTMU, t->range[t->whichTMU] ); + break; + + case TDFX_TMU_SPLIT: + case TDFX_TMU_BOTH: + assert( !tss->umaTexMemory ); + tdfxTMRemoveRangeLocked( fxMesa, TDFX_TMU0, t->range[TDFX_TMU0] ); + tdfxTMRemoveRangeLocked( fxMesa, TDFX_TMU1, t->range[TDFX_TMU1] ); + break; + + default: + gl_problem( NULL, "tdfx driver: bad unit in tdfxTMMOveOutTM()" ); + return; + } + + t->isInTM = GL_FALSE; + t->range[0] = NULL; + t->range[1] = NULL; + t->whichTMU = TDFX_TMU_NONE; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) { + tdfxTMVerifyFreeList( fxMesa, 0 ); + tdfxTMVerifyFreeList( fxMesa, 1 ); + } +} + + +void tdfxTMFreeTextureLocked( tdfxContextPtr fxMesa, + struct gl_texture_object *tObj ) +{ + tdfxTexObjPtr t = TDFX_TEXTURE_DATA(tObj); + + if ( t ) { + int i; + tdfxTMMoveOutTMLocked( fxMesa, tObj ); + for ( i = 0 ; i < MAX_TEXTURE_LEVELS ; i++ ) { + if ( t->image[i].original.data ) FREE( t->image[i].original.data ); + if ( t->image[i].rescaled.data ) FREE( t->image[i].rescaled.data ); + } + FREE( t ); + tObj->DriverData = NULL; + } + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) { + tdfxTMVerifyFreeList( fxMesa, 0 ); + tdfxTMVerifyFreeList( fxMesa, 1 ); + } +} + + +/* After a context switch this function will be called to restore + * texture memory for the new context. + */ +void tdfxTMRestoreTexturesLocked( tdfxContextPtr fxMesa ) +{ + GLcontext *ctx = fxMesa->glCtx; + struct gl_texture_object *tObj; + int i; + + for ( tObj = ctx->Shared->TexObjectList ; tObj ; tObj = tObj->Next ) { + tdfxTexObjPtr t = TDFX_TEXTURE_DATA( tObj ); + if ( t && t->isInTM ) { + for ( i = 0 ; i < MAX_TEXTURE_UNITS ; i++ ) { + if ( ctx->Texture.Unit[i].Current == tObj ) { + tdfxTMDownloadTextureLocked( fxMesa, tObj ); + break; + } + } + if ( i == MAX_TEXTURE_UNITS ) { + tdfxTMMoveOutTMLocked( fxMesa, tObj ); + } + } + } + + if ( TDFX_DEBUG & DEBUG_VERBOSE_TEXTURE ) { + tdfxTMVerifyFreeList( fxMesa, 0 ); + tdfxTMVerifyFreeList( fxMesa, 1 ); + } +} diff --git a/xc/lib/Imakefile b/xc/lib/Imakefile index aa4bbfad8..092a96532 100644 --- a/xc/lib/Imakefile +++ b/xc/lib/Imakefile @@ -32,6 +32,10 @@ XKBUILIBDIR = xkbui THRSTUBLIBDIR = XThrStub #endif +#if BuildXIElib +XIELIBDIR = XIE +#endif + #if BuildScreenSaverLibrary SSLIBDIR = Xss #endif @@ -118,10 +122,11 @@ FONTCACHELIBDIR = Xfontcache FONTSUBDIR = font -#if !BuildServersOnly +#if BuildLibraries LINTSUBDIRS = Xau Xdmcp $(THRSTUBLIBDIR) X11 oldX ICE SM Xext Xt \ $(SSLIBDIR) $(XF86MISCLIBDIR) $(XF86VMLIBDIR) $(XF86DGALIBDIR) \ - $(XF86RUSHLIBDIR) Xmu Xpm Xaw $(XAW6LIBDIR) XIE Xi Xtst FS \ + $(XF86RUSHLIBDIR) Xmu Xpm Xaw $(XAW6LIBDIR) $(XIELIBDIR) Xi \ + Xtst FS \ PEX5 $(XKBLIBDIR) $(XKBUILIBDIR) $(LBXUTILDIR) $(XALIBDIR) \ Xp $(XVLIBDIR) $(GLXLIBDIR) $(GLULIBDIR) $(GLWLIBDIR) \ $(DPSLIBDIR) $(DPSTKLIBDIR) $(PSRESLIBDIR) $(XINERAMADIR) \ @@ -132,8 +137,11 @@ LINTSUBDIRS = Xau Xdmcp $(THRSTUBLIBDIR) X11 oldX ICE SM Xext Xt \ XEXTDIR = Xext #endif -LINTSUBDIRS = Xau Xdmcp X11 $(LBXUTILDIR) $(ZLIBDIR) $(REGEXDIR) \ - $(XKBLIBDIR) +LINTSUBDIRS = Xau Xdmcp X11 $(XEXTDIR) $(LBXUTILDIR) $(ZLIBDIR) $(REGEXDIR) \ + $(XKBLIBDIR) $(XF86MISCLIBDIR) $(XF86VMLIBDIR) $(XF86DGALIBDIR) \ + $(XVLIBDIR) $(GLXLIBDIR) $(GLULIBDIR) $(GLWLIBDIR) \ + $(DPSLIBDIR) $(DPSTKLIBDIR) $(PSRESLIBDIR) $(XINERAMADIR) \ + $(RENDERLIBDIR) $(FREETYPE2LIBDIR) $(XFTLIBDIR) #endif diff --git a/xc/programs/Xserver/GL/dri/dri.c b/xc/programs/Xserver/GL/dri/dri.c index 1085aaf64..567d6f1a0 100644 --- a/xc/programs/Xserver/GL/dri/dri.c +++ b/xc/programs/Xserver/GL/dri/dri.c @@ -65,7 +65,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "glxserver.h" #include "mi.h" #include "mipointer.h" -#include "xf86Priv.h" + +#if defined(XFree86LOADER) || defined(PANORAMIX) +extern Bool noPanoramiXExtension; +#endif static int DRIScreenPrivIndex = -1; static int DRIWindowPrivIndex = -1; @@ -81,21 +84,27 @@ static RESTYPE DRIFullScreenResType; static RESTYPE DRIDrawablePrivResType; static RESTYPE DRIContextPrivResType; +static void DRIDestroyDummyContext(ScreenPtr pScreen, Bool hasCtxPriv); /* Wrapper just like xf86DrvMsg, but without the verbosity level checking. This will make it easy to turn off some messages later, based on verbosity level. */ +/* + * Since we're already referencing things from the XFree86 common layer in + * this file, we'd might as well just call xf86VDrvMsgVerb, and have + * consistent message formatting. The verbosity of these messages can be + * easily changed here. + */ +#define DRI_MSG_VERBOSITY 1 static void DRIDrvMsg(int scrnIndex, MessageType type, const char *format, ...) { va_list ap; - static char buffer[1024]; va_start(ap, format); - vsprintf(buffer, format, ap); - ErrorF("(%d): %s", scrnIndex, buffer); + xf86VDrvMsgVerb(scrnIndex, type, DRI_MSG_VERBOSITY, format, ap); va_end(ap); } @@ -106,6 +115,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) drmContextPtr reserved; int reserved_count; int i, fd, drmWasAvailable; + Bool xineramaInCore = FALSE; if (DRIGeneration != serverGeneration) { if ((DRIScreenPrivIndex = AllocateScreenPrivateIndex()) < 0) @@ -113,10 +123,31 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) DRIGeneration = serverGeneration; } + /* + * If Xinerama is on, don't allow DRI to initialise. It won't be usable + * anyway. + */ +#if defined(PANORAMIX) && !defined(XFree86LOADER) + xineramaInCore = TRUE; +#elif defined(XFree86LOADER) + if (xf86LoaderCheckSymbol("noPanoramiXExtension")) + xineramaInCore = TRUE; +#endif + +#if defined(PANORAMIX) || defined(XFree86LOADER) + if (xineramaInCore) { + if (!noPanoramiXExtension) { + DRIDrvMsg(pScreen->myNum, X_WARNING, + "Direct rendering is not supported when Xinerama is enabled\n"); + return FALSE; + } + } +#endif + drmWasAvailable = drmAvailable(); /* Note that drmOpen will try to load the kernel module, if needed. */ - fd = drmOpen(pDRIInfo->drmDriverName, NULL); + fd = drmOpen(pDRIInfo->drmDriverName, NULL /*pDRIInfo->busIdString*/); if (fd < 0) { /* failed to open DRM */ pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; @@ -145,6 +176,9 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) pDRIPriv->nrWindows = 0; pDRIPriv->fullscreen = NULL; + pDRIPriv->createDummyCtx = pDRIInfo->createDummyCtx; + pDRIPriv->createDummyCtxPriv = pDRIInfo->createDummyCtxPriv; + if (drmSetBusid(pDRIPriv->drmFD, pDRIPriv->pDriverInfo->busIdString) < 0) { pDRIPriv->directRenderingSupport = FALSE; pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; @@ -165,7 +199,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) 0, pDRIPriv->pDriverInfo->SAREASize, DRM_SHM, - DRM_CONTAINS_LOCK, + DRM_CONTAINS_LOCK, &pDRIPriv->hSAREA) < 0) { pDRIPriv->directRenderingSupport = FALSE; @@ -179,7 +213,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) "[drm] added %d byte SAREA at 0x%08lx\n", pDRIPriv->pDriverInfo->SAREASize, pDRIPriv->hSAREA); - if (drmMap( pDRIPriv->drmFD, + if (drmMap( pDRIPriv->drmFD, pDRIPriv->hSAREA, pDRIPriv->pDriverInfo->SAREASize, (drmAddressPtr)(&pDRIPriv->pSAREA)) < 0) @@ -194,12 +228,12 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) memset(pDRIPriv->pSAREA, 0, pDRIPriv->pDriverInfo->SAREASize); DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] mapped SAREA 0x%08lx to %p\n", pDRIPriv->hSAREA, pDRIPriv->pSAREA); - - if (drmAddMap( pDRIPriv->drmFD, + + if (drmAddMap( pDRIPriv->drmFD, (drmHandle)pDRIPriv->pDriverInfo->frameBufferPhysicalAddress, pDRIPriv->pDriverInfo->frameBufferSize, - DRM_FRAME_BUFFER, - 0, + DRM_FRAME_BUFFER, + 0, &pDRIPriv->hFrameBuffer) < 0) { pDRIPriv->directRenderingSupport = FALSE; @@ -234,7 +268,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) /* validate max drawable table entry set by driver */ if ((pDRIPriv->pDriverInfo->maxDrawableTableEntry <= 0) || (pDRIPriv->pDriverInfo->maxDrawableTableEntry > SAREA_MAX_DRAWABLES)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "Invalid max drawable table size set by driver: %d\n", pDRIPriv->pDriverInfo->maxDrawableTableEntry); } @@ -266,7 +300,7 @@ DRIFinishScreenInit(ScreenPtr pScreen) if (!(pDRIContextPriv = DRICreateContextPriv(pScreen, &pDRIPriv->myContext, flags))) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "failed to create server context\n"); return FALSE; } @@ -289,12 +323,12 @@ DRIFinishScreenInit(ScreenPtr pScreen) /* Server will handle 3D swaps, and hide 2D swaps from kernel. * Register server context as a preserved context. */ - + /* allocate memory for hidden context store */ pDRIPriv->hiddenContextStore = (void *)xcalloc(1, pDRIInfo->contextSize); if (!pDRIPriv->hiddenContextStore) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "failed to allocate hidden context\n"); DRIDestroyContextPriv(pDRIContextPriv); return FALSE; @@ -304,17 +338,17 @@ DRIFinishScreenInit(ScreenPtr pScreen) pDRIPriv->partial3DContextStore = (void *)xcalloc(1, pDRIInfo->contextSize); if (!pDRIPriv->partial3DContextStore) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "[DRI] failed to allocate partial 3D context\n"); xfree(pDRIPriv->hiddenContextStore); DRIDestroyContextPriv(pDRIContextPriv); return FALSE; } - + /* save initial context store */ if (pDRIInfo->SwapContext) { (*pDRIInfo->SwapContext)( - pScreen, + pScreen, DRI_NO_SYNC, DRI_2D_CONTEXT, pDRIPriv->hiddenContextStore, @@ -328,7 +362,7 @@ DRIFinishScreenInit(ScreenPtr pScreen) * setup signal handler for receiving swap requests from kernel */ if (!drmInstallSIGIOHandler(pDRIPriv->drmFD, DRISwapContext)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "[drm] failed to setup DRM signal handler\n"); if (pDRIPriv->hiddenContextStore) xfree(pDRIPriv->hiddenContextStore); @@ -337,7 +371,7 @@ DRIFinishScreenInit(ScreenPtr pScreen) DRIDestroyContextPriv(pDRIContextPriv); return FALSE; } else { - DRIDrvMsg(pScreen->myNum, X_INFO, + DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] installed DRM signal handler\n"); } @@ -371,7 +405,7 @@ DRIFinishScreenInit(ScreenPtr pScreen) pDRIPriv->wrap.AdjustFrame = pScrn->AdjustFrame; pScrn->AdjustFrame = pDRIInfo->wrap.AdjustFrame; } - + DRIDrvMsg(pScreen->myNum, X_INFO, "[DRI] installation complete\n"); return TRUE; @@ -394,13 +428,17 @@ DRICloseScreen(ScreenPtr pScreen) if (pDRIPriv->pDriverInfo->driverSwapMethod != DRI_KERNEL_SWAP) { if (!drmRemoveSIGIOHandler(pDRIPriv->drmFD)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "[drm] failed to remove DRM signal handler\n"); } } + if (pDRIPriv->dummyCtxPriv && pDRIPriv->createDummyCtx) { + DRIDestroyDummyContext(pScreen, pDRIPriv->createDummyCtxPriv); + } + if (!DRIDestroyContextPriv(pDRIPriv->myContextPriv)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "failed to destroy server context\n"); } @@ -434,7 +472,7 @@ DRICloseScreen(ScreenPtr pScreen) pDRIPriv->hSAREA, pDRIPriv->pSAREA); } - + drmClose(pDRIPriv->drmFD); xfree(pDRIPriv); pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; @@ -451,7 +489,7 @@ DRIExtensionInit(void) return FALSE; } - /* Allocate a window private index with a zero sized private area for + /* Allocate a window private index with a zero sized private area for * each window, then should a window become a DRI window, we'll hang * a DRIWindowPrivateRec off of this private index. */ @@ -544,7 +582,7 @@ DRIGetClientDriverName(ScreenPtr pScreen, /* DRICreateContextPriv and DRICreateContextPrivFromHandle are helper functions that layer on drmCreateContext and drmAddContextTag. - + DRICreateContextPriv always creates a kernel drmContext and then calls DRICreateContextPrivFromHandle to create a DRIContextPriv structure for DRI tracking. For the SIGIO handler, the drmContext is associated with @@ -585,7 +623,7 @@ DRICreateContextPrivFromHandle(ScreenPtr pScreen, pDRIContextPriv->pContextStore = (void *)(pDRIContextPriv + 1); drmAddContextTag(pDRIPriv->drmFD, hHWContext, pDRIContextPriv); - + pDRIContextPriv->hwContext = hHWContext; pDRIContextPriv->pScreen = pScreen; pDRIContextPriv->flags = flags; @@ -595,7 +633,7 @@ DRICreateContextPrivFromHandle(ScreenPtr pScreen, if (drmSetContextFlags(pDRIPriv->drmFD, hHWContext, DRM_CONTEXT_2DONLY)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "[drm] failed to set 2D context flag\n"); DRIDestroyContextPriv(pDRIContextPriv); return NULL; @@ -605,7 +643,7 @@ DRICreateContextPrivFromHandle(ScreenPtr pScreen, if (drmSetContextFlags(pDRIPriv->drmFD, hHWContext, DRM_CONTEXT_PRESERVED)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "[drm] failed to set preserved flag\n"); DRIDestroyContextPriv(pDRIContextPriv); return NULL; @@ -620,7 +658,7 @@ DRIDestroyContextPriv(DRIContextPrivPtr pDRIContextPriv) DRIScreenPrivPtr pDRIPriv; if (!pDRIContextPriv) return TRUE; - + pDRIPriv = DRI_SCREEN_PRIV(pDRIContextPriv->pScreen); if (!(pDRIContextPriv->flags & DRI_CONTEXT_RESERVED)) { @@ -641,10 +679,72 @@ DRIDestroyContextPriv(DRIContextPrivPtr pDRIContextPriv) return TRUE; } +static Bool +DRICreateDummyContext(ScreenPtr pScreen, Bool needCtxPriv) +{ + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + __GLXscreenInfo *pGLXScreen = &__glXActiveScreens[pScreen->myNum]; + __GLXvisualConfig *pGLXVis = pGLXScreen->pGlxVisual; + void **pVisualConfigPriv = pGLXScreen->pVisualPriv; + DRIContextPrivPtr pDRIContextPriv; + void *contextStore; + VisualPtr visual; + int visNum; + + visual = pScreen->visuals; + + /* Find the X visual that corresponds the the first GLX visual */ + for (visNum = 0; + visNum < pScreen->numVisuals; + visNum++, visual++) { + if (pGLXVis->vid == visual->vid) + break; + } + if (visNum == pScreen->numVisuals) return FALSE; + + if (!(pDRIContextPriv = + DRICreateContextPriv(pScreen, + &pDRIPriv->pSAREA->dummy_context, 0))) { + return FALSE; + } + + contextStore = DRIGetContextStore(pDRIContextPriv); + if (pDRIPriv->pDriverInfo->CreateContext && needCtxPriv) { + if (!pDRIPriv->pDriverInfo->CreateContext(pScreen, visual, + pDRIPriv->pSAREA->dummy_context, + *pVisualConfigPriv, + (DRIContextType)(long)contextStore)) { + DRIDestroyContextPriv(pDRIContextPriv); + return FALSE; + } + } + + pDRIPriv->dummyCtxPriv = pDRIContextPriv; + return TRUE; +} + +static void +DRIDestroyDummyContext(ScreenPtr pScreen, Bool hasCtxPriv) +{ + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + DRIContextPrivPtr pDRIContextPriv = pDRIPriv->dummyCtxPriv; + void *contextStore; + + if (!pDRIContextPriv) return; + if (pDRIPriv->pDriverInfo->DestroyContext && hasCtxPriv) { + contextStore = DRIGetContextStore(pDRIContextPriv); + pDRIPriv->pDriverInfo->DestroyContext(pDRIContextPriv->pScreen, + pDRIContextPriv->hwContext, + (DRIContextType)(long)contextStore); + } + + DRIDestroyContextPriv(pDRIPriv->dummyCtxPriv); + pDRIPriv->dummyCtxPriv = NULL; +} + Bool DRICreateContext(ScreenPtr pScreen, VisualPtr visual, - XID context, drmContextPtr pHWContext -) + XID context, drmContextPtr pHWContext) { DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); __GLXscreenInfo *pGLXScreen = &__glXActiveScreens[pScreen->myNum]; @@ -654,6 +754,14 @@ DRICreateContext(ScreenPtr pScreen, VisualPtr visual, void *contextStore; int visNum; + if (pDRIPriv->createDummyCtx && !pDRIPriv->dummyCtxPriv) { + if (!DRICreateDummyContext(pScreen, pDRIPriv->createDummyCtxPriv)) { + DRIDrvMsg(pScreen->myNum, X_INFO, + "[drm] Could not create dummy context\n"); + return FALSE; + } + } + /* Find the GLX visual associated with the one requested */ for (visNum = 0; visNum < pGLXScreen->numVisuals; @@ -664,14 +772,14 @@ DRICreateContext(ScreenPtr pScreen, VisualPtr visual, /* No matching GLX visual found */ return FALSE; } - + if (!(pDRIContextPriv = DRICreateContextPriv(pScreen, pHWContext, 0))) { return FALSE; } - contextStore=DRIGetContextStore(pDRIContextPriv); + contextStore = DRIGetContextStore(pDRIContextPriv); if (pDRIPriv->pDriverInfo->CreateContext) { - if (!((*pDRIPriv->pDriverInfo->CreateContext)(pScreen, visual, + if (!((*pDRIPriv->pDriverInfo->CreateContext)(pScreen, visual, *pHWContext, *pVisualConfigPriv, (DRIContextType)(long)contextStore))) { DRIDestroyContextPriv(pDRIContextPriv); @@ -703,9 +811,10 @@ DRIContextPrivDelete(pointer pResource, XID id) pDRIPriv = DRI_SCREEN_PRIV(pDRIContextPriv->pScreen); if (pDRIPriv->pDriverInfo->DestroyContext) { - contextStore=DRIGetContextStore(pDRIContextPriv); - (pDRIPriv->pDriverInfo->DestroyContext)(pDRIContextPriv->pScreen, - pDRIContextPriv->hwContext, (DRIContextType)(long)contextStore); + contextStore = DRIGetContextStore(pDRIContextPriv); + pDRIPriv->pDriverInfo->DestroyContext(pDRIContextPriv->pScreen, + pDRIContextPriv->hwContext, + (DRIContextType)(long)contextStore); } return DRIDestroyContextPriv(pDRIContextPriv); } @@ -715,9 +824,9 @@ DRIContextPrivDelete(pointer pResource, XID id) * in the case of transition from private to shared backbuffers. It's * not necessary for correctness, because DRIClipNotify gets called in * time to prevent any conflict, but the transition from - * shared->private is sometimes missed if we don't do this. + * shared->private is sometimes missed if we don't do this. */ -static void +static void DRIClipNotifyAllDrawables(ScreenPtr pScreen) { int i; @@ -725,48 +834,42 @@ DRIClipNotifyAllDrawables(ScreenPtr pScreen) for( i=0; i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; i++) { pDRIPriv->pSAREA->drawableTable[i].stamp = DRIDrawableValidationStamp++; - } + } } -static void +static void DRITransitionToSharedBuffers(ScreenPtr pScreen) { -/* ErrorF("DRITransitionToSharedBuffers\n"); */ - DRIClipNotifyAllDrawables( pScreen ); + DRIClipNotifyAllDrawables( pScreen ); } -static void +static void DRITransitionToPrivateBuffers(ScreenPtr pScreen) { -/* ErrorF("DRITransitionToPrivateBuffers\n"); */ - DRIClipNotifyAllDrawables( pScreen ); + DRIClipNotifyAllDrawables( pScreen ); } static void DRITransitionTo3d(ScreenPtr pScreen) { - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - -/* ErrorF("DRITransitionTo3d\n"); */ + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - if (pDRIInfo->TransitionTo3d) - pDRIInfo->TransitionTo3d( pScreen ); + if (pDRIInfo->TransitionTo3d) + pDRIInfo->TransitionTo3d( pScreen ); } static void DRITransitionTo2d(ScreenPtr pScreen) { - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - -/* ErrorF("DRITransitionTo2d\n"); */ + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - if (pDRIInfo->TransitionTo2d) - pDRIInfo->TransitionTo2d( pScreen ); + if (pDRIInfo->TransitionTo2d) + pDRIInfo->TransitionTo2d( pScreen ); } @@ -802,7 +905,7 @@ DRICreateDrawable(ScreenPtr pScreen, Drawable id, pDRIDrawablePriv->drawableIndex = -1; /* save private off of preallocated index */ - pWin->devPrivates[DRIWindowPrivIndex].ptr = + pWin->devPrivates[DRIWindowPrivIndex].ptr = (pointer)pDRIDrawablePriv; switch (++pDRIPriv->nrWindows) { @@ -841,7 +944,7 @@ DRIDestroyDrawable(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable) pDRIDrawablePriv->refCount--; if (pDRIDrawablePriv->refCount <= 0) { /* This calls back DRIDrawablePrivDelete which frees private area */ - FreeResourceByType(id, DRIDrawablePrivResType, FALSE); + FreeResourceByType(id, DRIDrawablePrivResType, FALSE); } } else { /* pixmap (or for GLX 1.3, a PBuffer) */ @@ -869,7 +972,7 @@ DRIDrawablePrivDelete(pointer pResource, XID id) pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL; } - if (drmDestroyDrawable(pDRIPriv->drmFD, + if (drmDestroyDrawable(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable)) { return FALSE; } @@ -931,7 +1034,7 @@ DRIGetDrawableInfo(ScreenPtr pScreen, if (!(pDRIPriv->DRIDrawables[i])) { pDRIPriv->DRIDrawables[i] = pDrawable; pDRIDrawablePriv->drawableIndex = i; - pDRIPriv->pSAREA->drawableTable[i].stamp = + pDRIPriv->pSAREA->drawableTable[i].stamp = DRIDrawableValidationStamp++; break; } @@ -944,10 +1047,10 @@ DRIGetDrawableInfo(ScreenPtr pScreen, int oldestIndex = 0; i = pDRIPriv->pDriverInfo->maxDrawableTableEntry; while (i--) { - if (pDRIPriv->pSAREA->drawableTable[i].stamp < + if (pDRIPriv->pSAREA->drawableTable[i].stamp < oldestStamp) { oldestIndex = i; - oldestStamp = + oldestStamp = pDRIPriv->pSAREA->drawableTable[i].stamp; } } @@ -962,15 +1065,15 @@ DRIGetDrawableInfo(ScreenPtr pScreen, pDRIPriv->DRIDrawables[oldestIndex] = pDrawable; /* validate SAREA entry */ - pDRIPriv->pSAREA->drawableTable[oldestIndex].stamp = + pDRIPriv->pSAREA->drawableTable[oldestIndex].stamp = DRIDrawableValidationStamp++; /* check for stamp wrap around */ if (oldestStamp > DRIDrawableValidationStamp) { /* walk SAREA table and invalidate all drawables */ - for( i=0; - i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; + for( i=0; + i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; i++) { pDRIPriv->pSAREA->drawableTable[i].stamp = DRIDrawableValidationStamp++; @@ -986,10 +1089,10 @@ DRIGetDrawableInfo(ScreenPtr pScreen, pDRIDrawablePriv->drawableIndex); /* reinit drawable ID if window is visible */ - if ((pWin->viewable) && + if ((pWin->viewable) && (pDRIPriv->pDriverInfo->bufferRequests != DRI_NO_WINDOWS)) { - (*pDRIPriv->pDriverInfo->InitBuffers)(pWin, + (*pDRIPriv->pDriverInfo->InitBuffers)(pWin, &pWin->clipList, pDRIDrawablePriv->drawableIndex); } } @@ -1017,7 +1120,7 @@ DRIGetDrawableInfo(ScreenPtr pScreen, *numClipRects = 1; *pClipRects = &pDRIPriv->fullscreen_rect; } - + *backX = *X; *backY = *Y; @@ -1166,7 +1269,7 @@ DRIDoWakeupHandler(int screenNum, pointer wakeupData, } } -void +void DRIDoBlockHandler(int screenNum, pointer blockData, pointer pTimeout, pointer pReadmask) { @@ -1185,7 +1288,7 @@ DRIDoBlockHandler(int screenNum, pointer blockData, DRIUnlock(pScreen); } -void +void DRISwapContext(int drmFD, void *oldctx, void *newctx) { DRIContextPrivPtr oldContext = (DRIContextPrivPtr)oldctx; @@ -1228,7 +1331,7 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx) #endif if (!pDRIPriv->pDriverInfo->SwapContext) { - DRIDrvMsg(pScreen->myNum, X_ERROR, + DRIDrvMsg(pScreen->myNum, X_ERROR, "[DRI] DDX driver missing context swap call back\n"); return; } @@ -1244,7 +1347,7 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx) oldContextType = DRI_NO_CONTEXT; } newContextStore = DRIGetContextStore(newContext); - if ((newContext->valid3D) && + if ((newContext->valid3D) && (newContext->hwContext != pDRIPriv->myContext)) { newContextType = DRI_3D_CONTEXT; } @@ -1258,8 +1361,8 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx) /* optimize 2D context swaps */ if (newContext->flags & DRI_CONTEXT_2DONLY) { - /* go from 3D context to 2D context and only save 2D - * subset of 3D state + /* go from 3D context to 2D context and only save 2D + * subset of 3D state */ oldContextStore = DRIGetContextStore(oldContext); oldContextType = DRI_2D_CONTEXT; @@ -1270,8 +1373,8 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx) } else if (oldContext->flags & DRI_CONTEXT_2DONLY) { if (pDRIPriv->lastPartial3DContext == newContext) { - /* go from 2D context back to previous 3D context and - * only restore 2D subset of previous 3D state + /* go from 2D context back to previous 3D context and + * only restore 2D subset of previous 3D state */ oldContextStore = DRIGetContextStore(oldContext); oldContextType = DRI_2D_CONTEXT; @@ -1284,7 +1387,7 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx) /* call DDX driver to do partial restore */ oldContextStore = DRIGetContextStore(oldContext); - newContextStore = + newContextStore = DRIGetContextStore(pDRIPriv->lastPartial3DContext); (*pDRIPriv->pDriverInfo->SwapContext)(pScreen, DRI_2D_SYNC, @@ -1298,7 +1401,7 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx) oldContext->valid3D = TRUE; oldContextType = DRI_3D_CONTEXT; newContextStore = DRIGetContextStore(newContext); - if ((newContext->valid3D) && + if ((newContext->valid3D) && (newContext->hwContext != pDRIPriv->myContext)) { newContextType = DRI_3D_CONTEXT; } @@ -1314,7 +1417,7 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx) oldContext->valid3D = TRUE; oldContextType = DRI_3D_CONTEXT; newContextStore = DRIGetContextStore(newContext); - if ((newContext->valid3D) && + if ((newContext->valid3D) && (newContext->hwContext != pDRIPriv->myContext)) { newContextType = DRI_3D_CONTEXT; } @@ -1380,7 +1483,7 @@ DRITreeTraversal(WindowPtr pWin, pointer data) return WT_WALKCHILDREN; } -void +void DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) { ScreenPtr pScreen = pWin->drawable.pScreen; @@ -1613,7 +1716,7 @@ DRIClipNotify(WindowPtr pWin, int dx, int dy) } } -CARD32 +CARD32 DRIGetDrawableIndex(WindowPtr pWin) { ScreenPtr pScreen = pWin->drawable.pScreen; @@ -1631,7 +1734,7 @@ DRIGetDrawableIndex(WindowPtr pWin) return index; } -unsigned int +unsigned int DRIGetDrawableStamp(ScreenPtr pScreen, CARD32 drawable_index) { DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); @@ -1643,56 +1746,62 @@ void DRIPrintDrawableLock(ScreenPtr pScreen, char *msg) { DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - + ErrorF("%s: %d\n", msg, pDRIPriv->pSAREA->drawable_lock.lock); } void -DRILock(ScreenPtr pScreen, int flags) { +DRILock(ScreenPtr pScreen, int flags) +{ DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - + if (!lockRefCount) - DRM_LOCK(pDRIPriv->drmFD, pDRIPriv->pSAREA, pDRIPriv->myContext, flags); + DRM_LOCK(pDRIPriv->drmFD, pDRIPriv->pSAREA, pDRIPriv->myContext, flags); lockRefCount++; } void -DRIUnlock(ScreenPtr pScreen) { +DRIUnlock(ScreenPtr pScreen) +{ DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - if (lockRefCount>0) lockRefCount--; + if (lockRefCount > 0) { + lockRefCount--; + } else { - ErrorF("DRIUnlock called when not locked\n"); - return; + ErrorF("DRIUnlock called when not locked\n"); + return; } if (!lockRefCount) - DRM_UNLOCK(pDRIPriv->drmFD, pDRIPriv->pSAREA, pDRIPriv->myContext); + DRM_UNLOCK(pDRIPriv->drmFD, pDRIPriv->pSAREA, pDRIPriv->myContext); } void * DRIGetSAREAPrivate(ScreenPtr pScreen) { - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - if (!pDRIPriv) return 0; - return (void *)(((char*)pDRIPriv->pSAREA)+sizeof(XF86DRISAREARec)); + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + if (!pDRIPriv) + return 0; + return (void *)(((char*)pDRIPriv->pSAREA)+sizeof(XF86DRISAREARec)); } drmContext DRIGetContext(ScreenPtr pScreen) { - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - if (!pDRIPriv) return 0; - return pDRIPriv->myContext; + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + if (!pDRIPriv) + return 0; + return pDRIPriv->myContext; } - + /* This lets get at the unwrapped functions so that they can correctly * call the lowerlevel functions, and choose whether they will be - * called at every level of recursion (eg in validatetree). + * called at every level of recursion (eg in validatetree). */ DRIWrappedFuncsRec * DRIGetWrappedFuncs(ScreenPtr pScreen) { - return &(DRI_SCREEN_PRIV(pScreen)->wrap); + return &(DRI_SCREEN_PRIV(pScreen)->wrap); } void @@ -1700,9 +1809,9 @@ DRIQueryVersion(int *majorVersion, int *minorVersion, int *patchVersion) { - *majorVersion = XF86DRI_MAJOR_VERSION; - *minorVersion = XF86DRI_MINOR_VERSION; - *patchVersion = XF86DRI_PATCH_VERSION; + *majorVersion = XF86DRI_MAJOR_VERSION; + *minorVersion = XF86DRI_MINOR_VERSION; + *patchVersion = XF86DRI_PATCH_VERSION; } static void @@ -1774,7 +1883,7 @@ DRIOpenFullScreen(ScreenPtr pScreen, DrawablePtr pDrawable) ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; WindowPtr pWin = (WindowPtr)pDrawable; XF86DRIClipRectPtr pClipRects = (void *)REGION_RECTS(&pWin->clipList); - + _DRIAdjustFrame(pScrn, pDRIPriv, pScrn->frameX0, pScrn->frameY0); if (pDrawable->type != DRAWABLE_WINDOW) return FALSE; @@ -1803,7 +1912,7 @@ DRIOpenFullScreen(ScreenPtr pScreen, DrawablePtr pDrawable) pScrn->vtSema = FALSE; pDRIPriv->fullscreen = pDrawable; DRIClipNotify(pWin, 0, 0); - + if (pDRIPriv->pDriverInfo->OpenFullScreen) pDRIPriv->pDriverInfo->OpenFullScreen(pScreen); @@ -1834,7 +1943,7 @@ _DRICloseFullScreen(pointer pResource, XID id) pScrn->EnableDisableFBAccess(pScreen->myNum, TRUE); pWin->eventMask = mask; pWin->optional = optional; - + xf86EnableVTSwitch(TRUE); pDRIPriv->pSAREA->frame.fullscreen = 0; return TRUE; diff --git a/xc/programs/Xserver/hw/xfree86/common/xf86.h b/xc/programs/Xserver/hw/xfree86/common/xf86.h index 3abc4cf8f..1003b292b 100644 --- a/xc/programs/Xserver/hw/xfree86/common/xf86.h +++ b/xc/programs/Xserver/hw/xfree86/common/xf86.h @@ -42,6 +42,8 @@ extern Bool fbSlotClaimed; #ifdef __sparc__ extern Bool sbusSlotClaimed; #endif +extern confDRIRec xf86ConfigDRI; + #define XF86SCRNINFO(p) ((ScrnInfoPtr)((p)->devPrivates[xf86ScreenIndex].ptr)) #define XF86FLIP_PIXELS() \ @@ -134,6 +136,7 @@ pciVideoPtr xf86FindPciDeviceVendor(CARD16 vendorID, CARD16 deviceID, char n, pciVideoPtr pvp_exclude); pciVideoPtr xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 class, char n, pciVideoPtr pvp_exclude); +void xf86EnablePciBusMaster(pciVideoPtr pPci, Bool enable); void xf86RegisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func, pointer arg); Bool xf86DeregisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func); #ifdef async diff --git a/xc/programs/Xserver/hw/xfree86/common/xf86Priv.h b/xc/programs/Xserver/hw/xfree86/common/xf86Priv.h index 9bd5beb7e..e4b20e86e 100644 --- a/xc/programs/Xserver/hw/xfree86/common/xf86Priv.h +++ b/xc/programs/Xserver/hw/xfree86/common/xf86Priv.h @@ -63,7 +63,6 @@ extern const char *xf86LogFile; extern MessageType xf86LogFileFrom; extern serverLayoutRec xf86ConfigLayout; extern Pix24Flags xf86ConfigPix24; -extern confDRIRec xf86ConfigDRI; extern unsigned short xf86MouseCflags[]; extern Bool xf86SupportedMouseTypes[]; diff --git a/xc/programs/Xserver/hw/xfree86/doc/sgml/DRI.sgml b/xc/programs/Xserver/hw/xfree86/doc/sgml/DRI.sgml index 7f7208065..5bd6fa155 100644 --- a/xc/programs/Xserver/hw/xfree86/doc/sgml/DRI.sgml +++ b/xc/programs/Xserver/hw/xfree86/doc/sgml/DRI.sgml @@ -10,7 +10,7 @@ <author> <htmlurl url="http://www.valinux.com/" name="VA Linux Systems, Inc."> Professional Services - Graphics. - <date>5 January 2001 + <date>15 March 2001 <ident> $XFree86: xc/programs/Xserver/hw/xfree86/doc/sgml/DRI.sgml,v 1.16 2001/01/08 01:07:33 martin Exp $ @@ -22,7 +22,7 @@ <p> <sect1>Copyright <p> - <bf>Copyright © 2000 by VA Linux Systems, Inc. + <bf>Copyright © 2000-2001 by VA Linux Systems, Inc. All Rights Reserved.</bf> <p> <bf>Permission is granted to make and distribute verbatim copies @@ -94,35 +94,9 @@ Like the SSE optimizations, a runtime check is made to determine if the CPU can execute 3DNow! instructions. - The build environment for both of these new architectures - have a pre-build environment that will correctly build the - DRI drivers and Mesa meaning no extra configuration is necessary - to build the DRI for these architectures. - - <sect2>Alpha Features - <p> - On newer Alpha processors, it should be noted that a - significant performance increase can be seen with the - addition of the -mcpu= command that should be passed to - GCC upon compilation. Dependent of the architecture of the - processor, for example -mcpu=ev6 will build specifically - for the EV6 based AXP's, giving both byte and word alignment - access to the DRI/Mesa drivers. - - Use this as an example of compiling with this extra speed. - In your host.def file that should reside in the xc/config - directory, add the line. - - #define DefaultGcc2AxpOpt -O2 -mcpu=ev6 - - Additional speed improvements to 3D rendering can be achieved - by installing Compaq's Math Libraries (CPML) which can be - obtained from the following URL. - - http://www.support.compaq.com/alpha-tools/software/index.html - - Alpha systems can benefit from several compile-time optimizations - which are described in the DRI Compile Guide. + Alpha-based systems can use Compaq's optimized math library for + improved 3D performance. See the DRI Compilation Guide for + details. <sect1> Graphics Hardware <p> @@ -251,9 +225,13 @@ Next, the DRI section can be used to restrict access to direct rendering. + A client can only use direct rendering if it has permission to + open the <tt>/dev/dri/card?</tt> file(s). + The permissions on these DRI device files is controlled by the "DRI" + section in the XF86Config file. <p> If you want all of the users on your system to be able to use - direct-rendering, then use a simple DRI section: + direct-rendering, then use a simple DRI section like this: <verb> Section "DRI" Mode 0666 @@ -476,8 +454,70 @@ <sect>General Trouble Shooting <p> This section contains information to help you diagnose general - problems. - See below for additional information for specific hardware. + problems. + See below for additional information for specific hardware. + + <sect1>Bus Mastering +<p> + DMA-based DRI drivers (that's most DRI drivers) cannot function + unless bus mastering is enabled for your graphics card. + By default, some systems don't having bus mastering on. + You should enable it in your BIOS. + <p> + Alternately, you can check the status of bus mastering and change + the setting from within Linux. There may be similar procedures for + other operating systems. + <p> + Run <tt>lspci</tt> (as root) and find the information + describing your graphics adapter. For example: + <P> + + <verb> + 00:00.0 Host bridge: Intel Corporation 440BX/ZX - 82443BX/ZX Host bridge (rev 03) + 00:01.0 PCI bridge: Intel Corporation 440BX/ZX - 82443BX/ZX AGP bridge (rev 03) + 00:07.0 ISA bridge: Intel Corporation 82371AB PIIX4 ISA (rev 02) + 00:07.1 IDE interface: Intel Corporation 82371AB PIIX4 IDE (rev 01) + 00:07.2 USB Controller: Intel Corporation 82371AB PIIX4 USB (rev 01) + 00:07.3 Bridge: Intel Corporation 82371AB PIIX4 ACPI (rev 02) + 00:11.0 Ethernet controller: Intel Corporation 82557 [Ethernet Pro 100] (rev 08) + 00:12.0 SCSI storage controller: Symbios Logic Inc. (formerly NCR) 53c895 (rev 02) + 00:14.0 Multimedia audio controller: Ensoniq ES1371 [AudioPCI-97] (rev 08) + 01:00.0 VGA compatible controller: 3Dfx Interactive, Inc.: Unknown device 0009 (rev 01) + </verb> + <p> + The bus, device, and function number comprise the device id, + which is conventionally written in the form bus:dev.func, or + in this case 01:00.0. + <p> + Use the <tt>setpci</tt> command to examine bit two of register 4 for + your graphics card. This will indicate whether or not bus mastering + is enabled. + <p> + <verb> + setpci -s 01:00.0 4.w + </verb> + <p> + A hexidecimal value will be printed. Convert the least significant + digit to binary. For example, if you see 3, that's 0011 in binary + (bit two is 0). If you see 7, that's 0111 in binary (bit two is 1). + In the first example, bus mastering is disabled. It's enabled in + the second example. + <p> + The following shell script will enabled bus mastering for your + graphics card and host bridge. Run it as root. + <verb> + #!/bin/bash + dev=01:00.0 # change as appropriate + echo Enabling bus mastering on device $dev + setpci -s $dev 4.w=$(printf %x $((0x$(setpci -s $dev 4.w)|4))) + dev=00:00.0 + echo Enabling bus mastering on host bridge $dev + setpci -s $dev 4.w=$(printf %x $((0x$(setpci -s $dev 4.w)|4))) + </verb> + <p> + You can check if this worked by running the first setpci command again. + <p> + <sect1>The X Server <p> @@ -706,14 +746,22 @@ </verb> <p> - The kernel module for the Voodoo3 is named <tt>tdfx.o</tt> and + The kernel module for 3dfx hardware is named <tt>tdfx.o</tt> and should be installed in /lib/modules/2.4.x/kernel/driver/char/drm/. It will be automatically loaded by the Xserver if needed. <p> - The DRI 3D driver for the Voodoo3 should be in + The DRI 3D driver for 3dfx hardware should be in <tt>/usr/X11R6/lib/modules/dri/tdfx_dri.so</tt>. This will be automatically loaded by libGL.so. <p> + The Voodoo5 supports 3D rendering in 16 and 32 bpp modes. + When running in 32bpp mode an 8-bit stencil buffer and 24-bit + Z (depth) buffer are offered. + When running in 16bpp mode only a 16-bit Z (depth) buffer is + offered and stencil is implemented in software. + <p> + A software-based accumulation buffer is available in both + 16 and 32bpp modes. <sect2>Troubleshooting <p> @@ -731,9 +779,17 @@ the 16 bit/pixel screen mode. Use <tt/xdpyinfo/ to verify that all your visuals are depth 16. Edit your XF86Config file if needed. - <item> + <item> The <tt>/dev/3dfx</tt> device is not used for DRI; it's only for Glide on older 3dfx hardware. + <item> + Different versions of Glide are needed for Voodoo3 and Voodoo5. + See the DRI website's resources page to download the right + version of Glide. + <item> + Voodoo4/5 may be run at 24bpp (instead of 32bpp, the default) + but 3D acceleration is not supported in that mode. + 32bpp mode is fully 3D accelerated. </itemize> <sect2>Performance @@ -742,7 +798,7 @@ <item> Normally, buffer swapping in double-buffered applications is synchronized to your monitor's refresh rate. - This may be overridden by setting the <tt/FX_GLIDE_SWAPINTERNVAL/ + This may be overridden by setting the <tt/FX_GLIDE_SWAPINTERVAL/ environment variable. The value of this variable indicates the maximum number of swap buffer commands can be buffered. @@ -798,97 +854,6 @@ Using <tt/glColorMask(r, g, b, a)/ when r!=g or g!=b. </itemize> <item> - The lowest mipmap level is sometimes miscolored in trilinear- - sampled polygons. - </itemize> - - - <sect1>3dfx Voodoo5 Series -<p> - <sect2>Dependencies -<p> - The Voodoo5 DRI driver requires a special versions of - the 3dfx Glide library, different than that used for Voodoo3 - hardware. - It can be downloaded from the DRI website. -<p> - <sect2>Configuration -<p> - Your XF86Config file's device section must specify the - <tt>tdfx</tt> device: - <verb> - Section "Device" - Identifier "Voodoo5" - VendorName "3dfx" - Driver "tdfx" - EndSection - </verb> - The Screen section should then reference the Voodoo3 device: - <verb> - Section "Screen" - Identifier "Screen 1" - Device "Voodoo5" - Monitor "High Res Monitor" - DefaultDepth 24 - Subsection "Display" - Depth 16 - Modes "1280x1024" "1024x768" "800x600" "640x480" - ViewPort 0 0 - EndSubsection - Subsection "Display" - Depth 24 - Modes "1280x1024" "1024x768" "800x600" "640x480" - ViewPort 0 0 - EndSubsection - EndSection - </verb> - <p> - The kernel module for the Voodoo5 is named <tt>tdfx.o</tt> and - should be installed in /lib/modules/2.4.x/kernel/driver/char/drm/. - It will be automatically loaded by the Xserver if needed. - <p> - The DRI 3D driver for the Voodoo5 should be in - <tt>/usr/X11R6/lib/modules/dri/tdfx_dri.so</tt>. - This will be automatically loaded by libGL.so. - <p> - The Voodoo5 supports 3D rendering in 16 and 32 bpp modes. - When running in 32bpp mode an 8-bit stencil buffer and 24-bit - Z (depth) buffer are offered. - When running in 16bpp mode only a 16-bit Z (depth) buffer is - offered and stencil is implemented in software. - <p> - A software-based accumulation buffer is available in both - 16 and 32bpp modes. - <p> - - <sect2>Troubleshooting -<p> - <itemize> - <item> - The <tt>/dev/3dfx</tt> device is not used for DRI; it's only for - Glide on older 3dfx hardware. - <item> - Different versions of Glide are needed for Voodoo3 and Voodoo5. - See the DRI website's resources page to download the right - version of Glide. - </itemize> - - <sect2>Performance -<p> - <itemize> - <item> - Normally, buffer swapping in double-buffered applications is - synchronized to your monitor's refresh rate. - This may be overridden by setting the <tt/FX_GLIDE_SWAPINTERNVAL/ - environment variable. - The value of this variable indicates the maximum number of - swap buffer commands can be buffered. - Zero allows maximum frame rate. - <item> - Rendering with 16-bit per texel textures is faster than using - 32-bit per texel textures. The <tt/internalFormat/ parameter - to <tt/glTexImage2D/ can be used to control texel size. - <item> The Voodoo5 driver reverts to software rendering under the same conditions Voodoo3 with three exceptions. First, stencil operations are implemented in hardware when the @@ -897,6 +862,18 @@ hardware. Third, <tt/glColorMask/ is fully supported in hardware when the screen is configured for 32 bits/pixel. + <item> + As of January, 2001 the second VSA-100 chip on the Voodoo5 is + not yet operational. + Therefore, the board isn't being used to its full capacity. + The second VSA-100 chip will allow Scan-Line Interleave (SLI) + mode for full-screen applications and games, potentially doubling + the system's fill rate. + When the second VSA-100 chip is activated + glGetString(GL_RENDERER) will report Voodoo5 instead of Voodoo4. + <item> + The lowest mipmap level is sometimes miscolored in trilinear- + sampled polygons. </itemize> <sect2>Known Problems @@ -906,25 +883,12 @@ The lowest mipmap level is sometimes miscolored in trilinear- sampled polygons (Voodoo3/Banshee). <item> - Voodoo4/5 may be run at 24bpp (instead of 32bpp, the default) - but 3D acceleration is not supported in that mode. - 32bpp mode is fully 3D accelerated. - <item> Fog doesn't work with orthographic projections. <item> The accuracy of blending operations on Voodoo4/5 isn't always very good. If you run Glean, you'll find some test failures. <item> - As of October, 2000 the second VSA-100 chip on the Voodoo5 is - not yet operational. - Therefore, the board isn't being used to its full capacity. - The second VSA-100 chip will allow Scan-Line Interleave (SLI) - mode for full-screen applications and games, potentially doubling - the system's fill rate. - When the second VSA-100 chip is activated - glGetString(GL_RENDERER) will report Voodoo5 instead of Voodoo4. - <item> The Glide library cannot be used directly; it's only meant to be used via the tdfx DRI driver. <item> @@ -954,6 +918,7 @@ Identifier "i810" VendorName "Intel" Driver "i810" + Option "AGPMode" "1" VideoRam 10000 EndSection </verb> @@ -1019,6 +984,7 @@ Identifier "MGA" VendorName "Matrox" Driver "mga" + Option "AGPMode" "1" VideoRam 32768 EndSection </verb> @@ -1072,8 +1038,38 @@ <item>Using glLogicOp. <item>Using glPolygonStipple or glLineStipple. <item>Using 1D or 3D textures. + <item>Using texture borders. + <item>Using glDepthFunc(GL_NEVER). <item>Using the accumulation buffer. </itemize> +<p> + The AGP mode may be set to 1, 2, or 4. One is used by default. + Higher AGP speeds may result in unreliable performance depending + on your motherboard. + +<p> + Compaq has funded the implementation of AGP acclerated + ReadPixels and DrawPixels in this driver. With this + implementation, on a G400 drawing directly from AGP memory + (exported to the client), throughput of up to 1 GB/sec has + been measured. + +<p> + Additionally Compaq's funding has produced several new + extensions in Mesa, including one (packed_depth_stencil_MESA) + which enables Read/DrawPixels functionality to operate + directly on the packed 24/8 depth/stencil buffers of this + hardware. + +<p> + In order to access this functionality, the application must + ensure that all pixel processing operations are disabled. + There are in addition a fairly complex set of rules regarding + which packing/unpacking modes must be used, and which data + formats are supported, and alignment constraints. See the + files in lib/GL/mesa/src/drv/mga/DOCS for a summary of these. + The extension definitions are included in the Mesa 3.4 source + distribution. <sect2>IRQ Assignment @@ -1144,6 +1140,8 @@ Identifier "Rage128" VendorName "ATI" Driver "ati" + Option "AGPMode" "1" + Option "UseCCEFor2D" "false" EndSection </verb> The Screen section should then reference the Rage 128 device: @@ -1182,10 +1180,19 @@ While PCI Rage 128 based cards are supported, they do not yet support PCI GART, so they will not perform as well as their AGP counterparts. +<p> + For AGP cards, the AGP mode may be set to 1, 2, or 4. One is + used by default. + Higher AGP speeds may result in unreliable performance depending + on your motherboard. <sect2>Known Problems <p> - None. + If you experience stability problems you may try setting the + <tt>UseCCEFor2D</tt> option to <tt>true</tt>. This will + effectively disable 2D hardware acceleration. Performance will + be degraded, of course. +<p> <sect1>ATI Radeon @@ -1204,6 +1211,7 @@ Identifier "Radeon" VendorName "ATI" Driver "ati" + Option "AGPMode" "1" EndSection </verb> The Screen section should then reference the Radeon device: @@ -1242,6 +1250,10 @@ While this driver supports many of the features of ATI Radeon cards, we do not <em/yet/ fully support the card's TCL features. This work is progressing, but is not yet ready. +<p> + The AGP mode may be set to 1, 2, or 4. One is used by default. + Higher AGP speeds may result in unreliable performance depending + on your motherboard. <sect2>Known Problems <p> diff --git a/xc/programs/Xserver/hw/xfree86/drivers/ati/r128_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/ati/r128_dri.c index 753022509..a7c7cdf42 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/ati/r128_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/ati/r128_dri.c @@ -94,18 +94,18 @@ static Bool R128InitVisualConfigs(ScreenPtr pScreen) if (R128_USE_STENCIL) numConfigs *= 2; if (!(pConfigs - = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), + = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } if (!(pR128Configs - = (R128ConfigPrivPtr)xnfcalloc(sizeof(R128ConfigPrivRec), + = (R128ConfigPrivPtr)xcalloc(sizeof(R128ConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } if (!(pR128ConfigPtrs - = (R128ConfigPrivPtr*)xnfcalloc(sizeof(R128ConfigPrivPtr), + = (R128ConfigPrivPtr*)xcalloc(sizeof(R128ConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pR128Configs); @@ -171,18 +171,18 @@ static Bool R128InitVisualConfigs(ScreenPtr pScreen) if (R128_USE_STENCIL) numConfigs *= 2; if (!(pConfigs - = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), + = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } if (!(pR128Configs - = (R128ConfigPrivPtr)xnfcalloc(sizeof(R128ConfigPrivRec), + = (R128ConfigPrivPtr)xcalloc(sizeof(R128ConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } if (!(pR128ConfigPtrs - = (R128ConfigPrivPtr*)xnfcalloc(sizeof(R128ConfigPrivPtr), + = (R128ConfigPrivPtr*)xcalloc(sizeof(R128ConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pR128Configs); @@ -949,7 +949,7 @@ Bool R128DRIScreenInit(ScreenPtr pScreen) pDRIInfo->SAREASize = SAREA_MAX; #endif - if (!(pR128DRI = (R128DRIPtr)xnfcalloc(sizeof(R128DRIRec),1))) { + if (!(pR128DRI = (R128DRIPtr)xcalloc(sizeof(R128DRIRec),1))) { DRIDestroyInfoRec(info->pDRIInfo); info->pDRIInfo = NULL; return FALSE; diff --git a/xc/programs/Xserver/hw/xfree86/drivers/ati/radeon_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/ati/radeon_dri.c index b94669ab6..31ad8b126 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/ati/radeon_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/ati/radeon_dri.c @@ -89,18 +89,18 @@ static Bool RADEONInitVisualConfigs(ScreenPtr pScreen) if (RADEON_USE_STENCIL) numConfigs *= 2; if (!(pConfigs - = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), + = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } if (!(pRADEONConfigs - = (RADEONConfigPrivPtr)xnfcalloc(sizeof(RADEONConfigPrivRec), + = (RADEONConfigPrivPtr)xcalloc(sizeof(RADEONConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } if (!(pRADEONConfigPtrs - = (RADEONConfigPrivPtr*)xnfcalloc(sizeof(RADEONConfigPrivPtr), + = (RADEONConfigPrivPtr*)xcalloc(sizeof(RADEONConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pRADEONConfigs); @@ -165,18 +165,18 @@ static Bool RADEONInitVisualConfigs(ScreenPtr pScreen) if (RADEON_USE_STENCIL) numConfigs *= 2; if (!(pConfigs - = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), + = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } if (!(pRADEONConfigs - = (RADEONConfigPrivPtr)xnfcalloc(sizeof(RADEONConfigPrivRec), + = (RADEONConfigPrivPtr)xcalloc(sizeof(RADEONConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } if (!(pRADEONConfigPtrs - = (RADEONConfigPrivPtr*)xnfcalloc(sizeof(RADEONConfigPrivPtr), + = (RADEONConfigPrivPtr*)xcalloc(sizeof(RADEONConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pRADEONConfigs); @@ -1372,7 +1372,7 @@ Bool RADEONDRIScreenInit(ScreenPtr pScreen) pDRIInfo->SAREASize = SAREA_MAX; #endif - if (!(pRADEONDRI = (RADEONDRIPtr)xnfcalloc(sizeof(RADEONDRIRec),1))) { + if (!(pRADEONDRI = (RADEONDRIPtr)xcalloc(sizeof(RADEONDRIRec),1))) { DRIDestroyInfoRec(info->pDRIInfo); info->pDRIInfo = NULL; return FALSE; @@ -1404,11 +1404,11 @@ Bool RADEONDRIScreenInit(ScreenPtr pScreen) version = drmGetVersion(info->drmFD); if (version) { if (version->version_major != 1 || - version->version_minor < 0) { + version->version_minor < 1) { /* incompatible drm version */ xf86DrvMsg(pScreen->myNum, X_ERROR, "RADEONDRIScreenInit failed " - "(DRM version = %d.%d.%d, expected 1.0.x). " + "(DRM version = %d.%d.%d, expected 1.1.x). " "Disabling DRI.\n", version->version_major, version->version_minor, diff --git a/xc/programs/Xserver/hw/xfree86/drivers/glint/glint_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/glint/glint_dri.c index 67ac50088..9b2efd113 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/glint/glint_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/glint/glint_dri.c @@ -92,20 +92,20 @@ GLINTInitVisualConfigs(ScreenPtr pScreen) either alpha buffer or 3D rendering in Overlay */ numConfigs = 5; - if (!(pConfigs = (__GLXvisualConfig *)xnfcalloc( + if (!(pConfigs = (__GLXvisualConfig *)xcalloc( sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } - if (!(pGlintConfigs = (GLINTConfigPrivPtr)xnfcalloc( + if (!(pGlintConfigs = (GLINTConfigPrivPtr)xcalloc( sizeof(GLINTConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } - if (!(pGlintConfigPtrs = (GLINTConfigPrivPtr *)xnfcalloc( + if (!(pGlintConfigPtrs = (GLINTConfigPrivPtr *)xcalloc( sizeof(GLINTConfigPrivPtr), numConfigs))) { xfree(pGlintConfigs); @@ -353,9 +353,9 @@ GLINTDRIScreenInit(ScreenPtr pScreen) { int major, minor, patch; DRIQueryVersion(&major, &minor, &patch); - if (major != 3 || minor != 1 || patch < 0) { + if (major != 4 || minor < 0) { xf86DrvMsg(pScreen->myNum, X_ERROR, - "GLINTDRIScreenInit failed (DRI version = %d.%d.%d, expected 3.1.x). Disabling DRI.\n", + "GLINTDRIScreenInit failed (DRI version = %d.%d.%d, expected 4.0.x). Disabling DRI.\n", major, minor, patch); return FALSE; } @@ -410,7 +410,7 @@ GLINTDRIScreenInit(ScreenPtr pScreen) pDRIInfo->SAREASize = SAREA_MAX; #endif - if (!(pGlintDRI = (GLINTDRIPtr)xnfcalloc(sizeof(GLINTDRIRec),1))) { + if (!(pGlintDRI = (GLINTDRIPtr)xcalloc(sizeof(GLINTDRIRec),1))) { DRIDestroyInfoRec(pGlint->pDRIInfo); return FALSE; } @@ -427,6 +427,9 @@ GLINTDRIScreenInit(ScreenPtr pScreen) pDRIInfo->MoveBuffers = GLINTDRIMoveBuffers; pDRIInfo->bufferRequests = DRI_ALL_WINDOWS; + pDRIInfo->createDummyCtx = TRUE; + pDRIInfo->createDummyCtxPriv = FALSE; + if (!DRIScreenInit(pScreen, pDRIInfo, &(pGlint->drmSubFD))) { DRIDestroyInfoRec(pGlint->pDRIInfo); xfree(pGlintDRI); @@ -438,8 +441,7 @@ GLINTDRIScreenInit(ScreenPtr pScreen) drmVersionPtr version = drmGetVersion(pGlint->drmSubFD); if (version) { if (version->version_major != 1 || - version->version_minor != 0 || - version->version_patchlevel < 0) { + version->version_minor < 0) { /* incompatible drm version */ xf86DrvMsg(pScreen->myNum, X_ERROR, "GLINTDRIScreenInit failed (DRM version = %d.%d.%d, expected 1.0.x). Disabling DRI.\n", @@ -587,6 +589,8 @@ GLINTDRIScreenInit(ScreenPtr pScreen) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] %d DMA buffers mapped\n", pGlint->drmBufs->count); + xf86EnablePciBusMaster(pGlint->PciInfo, TRUE); + /* tell the generic kernel driver how to handle Gamma DMA */ if (pGlint->irq <= 0) { pGlint->irq = drmGetInterruptFromBusID(pGlint->drmSubFD, diff --git a/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_dri.c index 81a54dcb0..99c7f5a02 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_dri.c @@ -68,14 +68,15 @@ Bool I810InitDma(ScrnInfoPtr pScrn) { I810Ptr pI810 = I810PTR(pScrn); I810RingBuffer *ring = &(pI810->LpRing); + I810DRIPtr pI810DRI = (I810DRIPtr) pI810->pDRIInfo->devPrivate; drmI810Init info; Bool ret_val; info.start = ring->mem.Start; info.end = ring->mem.End; info.size = ring->mem.Size; - info.ring_map_idx = 6; - info.buffer_map_idx = 5; + info.mmio_offset = (unsigned int)pI810DRI->regs; + info.buffers_offset = (unsigned int)pI810->buffer_map; info.sarea_off = sizeof(XF86DRISAREARec); info.front_offset = 0; @@ -111,17 +112,17 @@ I810InitVisualConfigs(ScreenPtr pScreen) case 16: numConfigs = 8; - pConfigs = (__GLXvisualConfig *) xnfcalloc(sizeof(__GLXvisualConfig), numConfigs); + pConfigs = (__GLXvisualConfig *) xcalloc(sizeof(__GLXvisualConfig), numConfigs); if (!pConfigs) return FALSE; - pI810Configs = (I810ConfigPrivPtr) xnfcalloc(sizeof(I810ConfigPrivRec), numConfigs); + pI810Configs = (I810ConfigPrivPtr) xcalloc(sizeof(I810ConfigPrivRec), numConfigs); if (!pI810Configs) { xfree(pConfigs); return FALSE; } - pI810ConfigPtrs = (I810ConfigPrivPtr *) xnfcalloc(sizeof(I810ConfigPrivPtr), numConfigs); + pI810ConfigPtrs = (I810ConfigPrivPtr *) xcalloc(sizeof(I810ConfigPrivPtr), numConfigs); if (!pI810ConfigPtrs) { xfree(pConfigs); xfree(pI810Configs); @@ -203,7 +204,6 @@ static unsigned int mylog2(unsigned int n) return log2; } - Bool I810DRIScreenInit(ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; @@ -240,9 +240,9 @@ Bool I810DRIScreenInit(ScreenPtr pScreen) { int major, minor, patch; DRIQueryVersion(&major, &minor, &patch); - if (major != 3 || minor != 1 || patch < 0) { + if (major != 4 || minor < 0) { xf86DrvMsg(pScreen->myNum, X_ERROR, - "I810DRIScreenInit failed (DRI version = %d.%d.%d, expected 3.1.x). Disabling DRI.\n", + "I810DRIScreenInit failed (DRI version = %d.%d.%d, expected 4.0.x). Disabling DRI.\n", major, minor, patch); return FALSE; } @@ -294,7 +294,7 @@ Bool I810DRIScreenInit(ScreenPtr pScreen) } pDRIInfo->SAREASize = SAREA_MAX; - if (!(pI810DRI = (I810DRIPtr)xnfcalloc(sizeof(I810DRIRec),1))) { + if (!(pI810DRI = (I810DRIPtr)xcalloc(sizeof(I810DRIRec),1))) { DRIDestroyInfoRec(pI810->pDRIInfo); pI810->pDRIInfo=0; return FALSE; @@ -310,6 +310,8 @@ Bool I810DRIScreenInit(ScreenPtr pScreen) pDRIInfo->MoveBuffers = I810DRIMoveBuffers; pDRIInfo->bufferRequests = DRI_ALL_WINDOWS; + pDRIInfo->createDummyCtx = TRUE; + pDRIInfo->createDummyCtxPriv = FALSE; /* This adds the framebuffer as a drm map *before* we have asked agp * to allocate it. Scary stuff, hold on... @@ -328,8 +330,7 @@ Bool I810DRIScreenInit(ScreenPtr pScreen) drmVersionPtr version = drmGetVersion(pI810->drmSubFD); if (version) { if (version->version_major != 1 || - version->version_minor != 1 || - version->version_patchlevel < 0) { + version->version_minor < 1) { /* incompatible drm version */ xf86DrvMsg(pScreen->myNum, X_ERROR, "I810DRIScreenInit failed (DRM version = %d.%d.%d, expected 1.0.x). Disabling DRI.\n", @@ -683,6 +684,7 @@ Bool I810DRIScreenInit(ScreenPtr pScreen) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] added %d %d byte DMA buffers\n", bufs, I810_DMA_BUF_SZ); + xf86EnablePciBusMaster(pI810->PciInfo, TRUE); I810InitDma(pScrn); @@ -733,6 +735,7 @@ Bool I810DRIScreenInit(ScreenPtr pScreen) pI810DRI->auxPitch = pI810->auxPitch; pI810DRI->auxPitchBits = pI810->auxPitchBits; + pI810DRI->sarea_priv_offset = sizeof(XF86DRISAREARec); if (!(I810InitVisualConfigs(pScreen))) { xf86DrvMsg(pScreen->myNum, X_ERROR, "I810InitVisualConfigs failed\n"); diff --git a/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_driver.c b/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_driver.c index 985ff3f10..d5bda3113 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_driver.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_driver.c @@ -520,14 +520,6 @@ I810PreInit(ScrnInfoPtr pScrn, int flags) { if (!xf86SetDefaultVisual(pScrn, -1)) return FALSE; - /* We don't currently support DirectColor at > 8bpp */ - if ((pScrn->depth > 8) && (pScrn->defaultVisual != TrueColor)) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual" - " (%s) is not supported at depth %d\n", - xf86GetVisualName(pScrn->defaultVisual), pScrn->depth); - return FALSE; - } - /* We use a programamble clock */ pScrn->progClock = TRUE; @@ -1345,6 +1337,9 @@ I810SetMode(ScrnInfoPtr pScrn, DisplayModePtr mode) pVga->CRTC[0x13] = pScrn->displayWidth >> 2; i810Reg->ExtOffset = pScrn->displayWidth >> 10; i810Reg->BitBLTControl = COLEXP_16BPP; + + /* Enable Palette Programming for Direct Color visuals. -jens */ + i810Reg->PixelPipeCfg2 = DISPLAY_GAMMA_ENABLE; break; case 24: pVga->CRTC[0x13] = (pScrn->displayWidth * 3) >> 3; @@ -1352,6 +1347,9 @@ I810SetMode(ScrnInfoPtr pScrn, DisplayModePtr mode) i810Reg->PixelPipeCfg1 = DISPLAY_24BPP_MODE; i810Reg->BitBLTControl = COLEXP_24BPP; + + /* Enable Palette Programming for Direct Color visuals. -jens */ + i810Reg->PixelPipeCfg2 = DISPLAY_GAMMA_ENABLE; break; default: break; @@ -1500,23 +1498,58 @@ I810LoadPalette16(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, pI810 = I810PTR(pScrn); hwp = VGAHWPTR(pScrn); + + /* Load all four entries in each of the 64 color ranges. -jens */ for (i=0; i<numColors; i++) { index=indices[i/2]; r=colors[index].red; b=colors[index].blue; index=indices[i]; g=colors[index].green; + hwp->writeDacWriteAddr(hwp, index<<2); hwp->writeDacData(hwp, r); hwp->writeDacData(hwp, g); hwp->writeDacData(hwp, b); + + hwp->writeDacWriteAddr(hwp, (index<<2)+1); + hwp->writeDacData(hwp, r); + hwp->writeDacData(hwp, g); + hwp->writeDacData(hwp, b); + + hwp->writeDacWriteAddr(hwp, (index<<2)+2); + hwp->writeDacData(hwp, r); + hwp->writeDacData(hwp, g); + hwp->writeDacData(hwp, b); + + hwp->writeDacWriteAddr(hwp, (index<<2)+3); + hwp->writeDacData(hwp, r); + hwp->writeDacData(hwp, g); + hwp->writeDacData(hwp, b); + i++; index=indices[i]; g=colors[index].green; + hwp->writeDacWriteAddr(hwp, index<<2); hwp->writeDacData(hwp, r); hwp->writeDacData(hwp, g); hwp->writeDacData(hwp, b); + + hwp->writeDacWriteAddr(hwp, (index<<2)+1); + hwp->writeDacData(hwp, r); + hwp->writeDacData(hwp, g); + hwp->writeDacData(hwp, b); + + hwp->writeDacWriteAddr(hwp, (index<<2)+2); + hwp->writeDacData(hwp, r); + hwp->writeDacData(hwp, g); + hwp->writeDacData(hwp, b); + + hwp->writeDacWriteAddr(hwp, (index<<2)+3); + hwp->writeDacData(hwp, r); + hwp->writeDacData(hwp, g); + hwp->writeDacData(hwp, b); } } @@ -1530,12 +1563,12 @@ I810LoadPalette24(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, pI810 = I810PTR(pScrn); hwp = VGAHWPTR(pScrn); + for (i=0; i<numColors; i++) { index=indices[i]; r=colors[index].red; - b=colors[index].blue; - index=indices[i]; g=colors[index].green; + b=colors[index].blue; hwp->writeDacWriteAddr(hwp, index); hwp->writeDacData(hwp, r); hwp->writeDacData(hwp, g); @@ -1625,6 +1658,7 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { vgaHWPtr hwp; I810Ptr pI810; VisualPtr visual; + MessageType driFrom = X_DEFAULT; pScrn = xf86Screens[pScreen->myNum]; pI810 = I810PTR(pScrn); @@ -1634,18 +1668,10 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { miClearVisualTypes(); -#if 1 /* disable DirectColor */ - if(pScrn->depth > 8) { - if (!miSetVisualTypes(pScrn->depth, TrueColorMask, - pScrn->rgbBits, pScrn->defaultVisual)) - return FALSE; - } else -#endif - { - if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth), - pScrn->rgbBits, pScrn->defaultVisual)) - return FALSE; - } + /* Re-implemented Direct Color support, -jens */ + if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual)) + return FALSE; if (!miSetPixmapDepths ()) return FALSE; @@ -1671,11 +1697,12 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { * InitGLXVisuals call back. */ - if (!xf86ReturnOptValBool(I810Options, OPTION_NOACCEL, FALSE) && - xf86ReturnOptValBool(I810Options, OPTION_DRI, TRUE)) { - pI810->directRenderingEnabled = I810DRIScreenInit(pScreen); - } else { + if (xf86ReturnOptValBool(I810Options, OPTION_NOACCEL, FALSE) || + !xf86ReturnOptValBool(I810Options, OPTION_DRI, TRUE)) { pI810->directRenderingEnabled = FALSE; + driFrom = X_CONFIG; + } else { + pI810->directRenderingEnabled = I810DRIScreenInit(pScreen); } #else @@ -1729,7 +1756,8 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { #ifdef XF86DRI if (pI810->LpRing.mem.Start == 0 && pI810->directRenderingEnabled) { - pI810->directRenderingEnabled = 0; + pI810->directRenderingEnabled = FALSE; + driFrom = X_PROBED; I810DRICloseScreen(pScreen); } @@ -1776,7 +1804,7 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { if (!miCreateDefColormap(pScreen)) return FALSE; -#if 0 /* palettes do not work */ + /* Use driver specific palette load routines for Direct Color support. -jens */ if (pScrn->bitsPerPixel==16) { if (!xf86HandleColormaps(pScreen, 256, 8, I810LoadPalette16, 0, CMAP_PALETTED_TRUECOLOR| @@ -1788,10 +1816,6 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { CMAP_RELOAD_ON_MODE_SWITCH)) return FALSE; } -#else - if (!vgaHWHandleColormaps(pScreen)) - return FALSE; -#endif xf86DPMSInit(pScreen, I810DisplayPowerManagementSet, 0); @@ -1807,15 +1831,9 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { #endif if (pI810->directRenderingEnabled) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Enabled\n"); + xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering enabled\n"); } else { - if(pI810->agpAcquired2d == TRUE) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Disabled\n"); - } - else { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Failed\n"); - return FALSE; - } + xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering disabled\n"); } pScreen->SaveScreen = I810SaveScreen; diff --git a/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c index 10ad53bc9..a257b96b1 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c @@ -1,5 +1,33 @@ /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c,v 1.16 2001/01/08 01:07:37 martin Exp $ */ +/* + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * 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 MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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: + * Keith WHitwell <keithw@valinux.com> + * Gareth Hughes <gareth@valinux.com> + */ + #include "xf86.h" #include "xf86_OSproc.h" #include "xf86_ansic.h" @@ -15,219 +43,172 @@ #include "miline.h" -#include "GL/glxtokens.h" + + #include "mga_bios.h" #include "mga_reg.h" #include "mga.h" #include "mga_macros.h" #include "mga_dri.h" -#include "mga_wrap.h" +#include "mga_sarea.h" -static char MGAKernelDriverName[] = "mga"; -static char MGAClientDriverName[] = "mga"; +#define _XF86DRI_SERVER_ +#include "GL/glxtokens.h" +#include "sarea.h" -static Bool MGAInitVisualConfigs(ScreenPtr pScreen); -static Bool MGACreateContext(ScreenPtr pScreen, VisualPtr visual, - drmContext hwContext, void *pVisualConfigPriv, - DRIContextType contextStore); -static void MGADestroyContext(ScreenPtr pScreen, drmContext hwContext, - DRIContextType contextStore); -static void MGADRISwapContext(ScreenPtr pScreen, DRISyncType syncType, - DRIContextType readContextType, - void *readContextStore, - DRIContextType writeContextType, - void *writeContextStore); -static void MGADRISwapContext_shared(ScreenPtr pScreen, DRISyncType syncType, - DRIContextType readContextType, - void *readContextStore, - DRIContextType writeContextType, - void *writeContextStore); -extern void Mga8DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index); -extern void Mga8DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, - RegionPtr prgnSrc, CARD32 index); -extern void Mga16DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index); -extern void Mga16DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, - RegionPtr prgnSrc, CARD32 index); -extern void Mga24DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index); -extern void Mga24DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, - RegionPtr prgnSrc, CARD32 index); -extern void Mga32DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index); -extern void Mga32DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, - RegionPtr prgnSrc, CARD32 index); - -Bool MgaCleanupDma(ScrnInfoPtr pScrn) -{ - MGAPtr pMGA = MGAPTR(pScrn); - Bool ret_val; - ret_val = drmMgaCleanupDma(pMGA->drmSubFD); - if (ret_val == FALSE) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Mga Dma Cleanup Failed\n"); - return ret_val; -} -Bool MgaLockUpdate(ScrnInfoPtr pScrn, drmLockFlags flags) -{ - MGAPtr pMGA = MGAPTR(pScrn); - Bool ret_val; - ret_val = drmMgaLockUpdate(pMGA->drmSubFD, flags); - if (ret_val == FALSE) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "LockUpdate failed\n"); +#include "GL/glxtokens.h" - return ret_val; -} +#include "mga_bios.h" +#include "mga_reg.h" +#include "mga.h" +#include "mga_macros.h" +#include "mga_dri.h" -Bool MgaInitDma(ScrnInfoPtr pScrn, int prim_size) -{ - MGAPtr pMGA = MGAPTR(pScrn); - MGADRIPtr pMGADRI = (MGADRIPtr)pMGA->pDRIInfo->devPrivate; - MGADRIServerPrivatePtr pMGADRIServer = pMGA->DRIServerInfo; - drmMgaInit init; - Bool ret_val; - - memset(&init, 0, sizeof(drmMgaInit)); - init.reserved_map_agpstart = 0; - init.reserved_map_idx = 3; - init.buffer_map_idx = 4; - init.sarea_priv_offset = sizeof(XF86DRISAREARec); - init.primary_size = prim_size; - init.warp_ucode_size = pMGADRIServer->warp_ucode_size; +#include "mga_sarea.h" - switch(pMGA->Chipset) { - case PCI_CHIP_MGAG400: - init.chipset = MGA_CARD_TYPE_G400; - break; - case PCI_CHIP_MGAG200: - case PCI_CHIP_MGAG200_PCI: - init.chipset = MGA_CARD_TYPE_G200; - break; - default: - return FALSE; - } - - init.frontOffset = pMGADRI->frontOffset; - init.backOffset = pMGADRI->backOffset; - init.depthOffset = pMGADRI->depthOffset; - init.textureOffset = pMGADRI->textureOffset; - init.textureSize = pMGADRI->textureSize; - init.agpTextureSize = pMGADRI->agpTextureSize; - init.cpp = pMGADRI->cpp; - init.stride = pMGADRI->frontPitch; - init.mAccess = pMGA->MAccess; - init.sgram = !pMGA->HasSDRAM; - - memcpy(&init.WarpIndex, &pMGADRIServer->WarpIndex, - sizeof(drmMgaWarpIndex) * MGA_MAX_WARP_PIPES); - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Mga Dma Initialization start\n"); - - ret_val = drmMgaInitDma(pMGA->drmSubFD, &init); - if (ret_val == FALSE) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[drm] Mga Dma Initialization Failed\n"); - else - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Mga Dma Initialization done\n"); - return ret_val; -} +static char MGAKernelDriverName[] = "mga"; +static char MGAClientDriverName[] = "mga"; -static Bool -MGAInitVisualConfigs(ScreenPtr pScreen) +/* DRI buffer management + */ +extern void Mga8DRIInitBuffers( WindowPtr pWin, RegionPtr prgn, + CARD32 index ); +extern void Mga8DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg, + RegionPtr prgnSrc, CARD32 index ); + +extern void Mga16DRIInitBuffers( WindowPtr pWin, RegionPtr prgn, + CARD32 index ); +extern void Mga16DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg, + RegionPtr prgnSrc, CARD32 index ); + +extern void Mga24DRIInitBuffers( WindowPtr pWin, RegionPtr prgn, + CARD32 index ); +extern void Mga24DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg, + RegionPtr prgnSrc, CARD32 index ); + +extern void Mga32DRIInitBuffers( WindowPtr pWin, RegionPtr prgn, + CARD32 index ); +extern void Mga32DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg, + RegionPtr prgnSrc, CARD32 index ); + + +/* Initialize the visual configs that are supported by the hardware. + * These are combined with the visual configs that the indirect + * rendering core supports, and the intersection is exported to the + * client. + */ +static Bool MGAInitVisualConfigs( ScreenPtr pScreen ) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - MGAPtr pMGA = MGAPTR(pScrn); + MGAPtr pMga = MGAPTR(pScrn); int numConfigs = 0; __GLXvisualConfig *pConfigs = 0; MGAConfigPrivPtr pMGAConfigs = 0; MGAConfigPrivPtr *pMGAConfigPtrs = 0; int i, db, depth, stencil, accum; - switch (pScrn->bitsPerPixel) { + switch ( pScrn->bitsPerPixel ) { case 8: case 24: break; + case 16: numConfigs = 8; - if (!(pConfigs = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), - numConfigs))) { + pConfigs = (__GLXvisualConfig*)xcalloc( sizeof(__GLXvisualConfig), + numConfigs ); + if ( !pConfigs ) { return FALSE; } - if (!(pMGAConfigs = (MGAConfigPrivPtr)xnfcalloc(sizeof(MGAConfigPrivRec), - numConfigs))) { - xfree(pConfigs); + + pMGAConfigs = (MGAConfigPrivPtr)xcalloc( sizeof(MGAConfigPrivRec), + numConfigs ); + if ( !pMGAConfigs ) { + xfree( pConfigs ); return FALSE; } - if (!(pMGAConfigPtrs = (MGAConfigPrivPtr*)xnfcalloc(sizeof(MGAConfigPrivPtr), - numConfigs))) { - xfree(pConfigs); - xfree(pMGAConfigs); + + pMGAConfigPtrs = (MGAConfigPrivPtr*)xcalloc( sizeof(MGAConfigPrivPtr), + numConfigs ); + if ( !pMGAConfigPtrs ) { + xfree( pConfigs ); + xfree( pMGAConfigs ); return FALSE; } - for (i=0; i<numConfigs; i++) + + for ( i = 0 ; i < numConfigs ; i++ ) { pMGAConfigPtrs[i] = &pMGAConfigs[i]; + } i = 0; depth = 1; - for (accum = 0; accum <= 1; accum++) { - for (stencil = 0; stencil <= 1; stencil++) { /* no stencil for now */ - for (db=1; db>=0; db--) { - pConfigs[i].vid = -1; - pConfigs[i].class = -1; - pConfigs[i].rgba = TRUE; - pConfigs[i].redSize = 5; - pConfigs[i].greenSize = 6; - pConfigs[i].blueSize = 5; - pConfigs[i].alphaSize = 0; - pConfigs[i].redMask = 0x0000F800; - pConfigs[i].greenMask = 0x000007E0; - pConfigs[i].blueMask = 0x0000001F; - pConfigs[i].alphaMask = 0; - if (accum) { - pConfigs[i].accumRedSize = 16; - pConfigs[i].accumGreenSize = 16; - pConfigs[i].accumBlueSize = 16; - pConfigs[i].accumAlphaSize = 0; + for ( accum = 0 ; accum <= 1 ; accum++ ) { + for ( stencil = 0 ; stencil <= 1 ; stencil++ ) { + for ( db = 1 ; db >= 0 ; db-- ) { + pConfigs[i].vid = -1; + pConfigs[i].class = -1; + pConfigs[i].rgba = TRUE; + pConfigs[i].redSize = 5; + pConfigs[i].greenSize = 6; + pConfigs[i].blueSize = 5; + pConfigs[i].alphaSize = 0; + pConfigs[i].redMask = 0x0000F800; + pConfigs[i].greenMask = 0x000007E0; + pConfigs[i].blueMask = 0x0000001F; + pConfigs[i].alphaMask = 0; + if ( accum ) { + pConfigs[i].accumRedSize = 16; + pConfigs[i].accumGreenSize = 16; + pConfigs[i].accumBlueSize = 16; + pConfigs[i].accumAlphaSize = 0; } else { - pConfigs[i].accumRedSize = 0; - pConfigs[i].accumGreenSize = 0; - pConfigs[i].accumBlueSize = 0; - pConfigs[i].accumAlphaSize = 0; + pConfigs[i].accumRedSize = 0; + pConfigs[i].accumGreenSize = 0; + pConfigs[i].accumBlueSize = 0; + pConfigs[i].accumAlphaSize = 0; } - if (db) - pConfigs[i].doubleBuffer = TRUE; - else - pConfigs[i].doubleBuffer = FALSE; - pConfigs[i].stereo = FALSE; - pConfigs[i].bufferSize = 16; - if (depth) - pConfigs[i].depthSize = 16; - else - pConfigs[i].depthSize = 0; - if (stencil) - pConfigs[i].stencilSize = 8; - else - pConfigs[i].stencilSize = 0; - pConfigs[i].auxBuffers = 0; - pConfigs[i].level = 0; - if (stencil || accum) - pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT; - else - pConfigs[i].visualRating = GLX_NONE_EXT; - pConfigs[i].transparentPixel = 0; - pConfigs[i].transparentRed = 0; - pConfigs[i].transparentGreen = 0; - pConfigs[i].transparentBlue = 0; - pConfigs[i].transparentAlpha = 0; - pConfigs[i].transparentIndex = 0; + if ( db ) { + pConfigs[i].doubleBuffer = TRUE; + } else { + pConfigs[i].doubleBuffer = FALSE; + } + pConfigs[i].stereo = FALSE; + pConfigs[i].bufferSize = 16; + if ( depth ) { + pConfigs[i].depthSize = 16; + } else { + pConfigs[i].depthSize = 0; + } + if ( stencil ) { + pConfigs[i].stencilSize = 8; + } else { + pConfigs[i].stencilSize = 0; + } + pConfigs[i].auxBuffers = 0; + pConfigs[i].level = 0; + if ( accum || stencil ) { + pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT; + } else { + pConfigs[i].visualRating = GLX_NONE_EXT; + } + pConfigs[i].transparentPixel = 0; + pConfigs[i].transparentRed = 0; + pConfigs[i].transparentGreen = 0; + pConfigs[i].transparentBlue = 0; + pConfigs[i].transparentAlpha = 0; + pConfigs[i].transparentIndex = 0; i++; } } } - if (i != numConfigs) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "[drm] Incorrect initialization of visuals\n"); + if ( i != numConfigs ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "[drm] Incorrect initialization of visuals\n" ); return FALSE; } break; @@ -235,152 +216,689 @@ MGAInitVisualConfigs(ScreenPtr pScreen) case 32: numConfigs = 8; - if (!(pConfigs = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), - numConfigs))) { + pConfigs = (__GLXvisualConfig*)xcalloc( sizeof(__GLXvisualConfig), + numConfigs ); + if ( !pConfigs ) { return FALSE; } - if (!(pMGAConfigs = (MGAConfigPrivPtr)xnfcalloc(sizeof(MGAConfigPrivRec), - numConfigs))) { - xfree(pConfigs); + + pMGAConfigs = (MGAConfigPrivPtr)xcalloc( sizeof(MGAConfigPrivRec), + numConfigs ); + if ( !pMGAConfigs ) { + xfree( pConfigs ); return FALSE; } - if (!(pMGAConfigPtrs = (MGAConfigPrivPtr*)xnfcalloc(sizeof(MGAConfigPrivPtr), - numConfigs))) { - xfree(pConfigs); - xfree(pMGAConfigs); + + pMGAConfigPtrs = (MGAConfigPrivPtr*)xcalloc( sizeof(MGAConfigPrivPtr), + numConfigs ); + if ( !pMGAConfigPtrs ) { + xfree( pConfigs ); + xfree( pMGAConfigs ); return FALSE; } - for (i=0; i<numConfigs; i++) + + for ( i = 0 ; i < numConfigs ; i++ ) { pMGAConfigPtrs[i] = &pMGAConfigs[i]; + } i = 0; - for (accum = 0; accum <= 1; accum++) { - for (depth = 0; depth <= 1; depth++) { /* and stencil */ - for (db=1; db>=0; db--) { - pConfigs[i].vid = -1; - pConfigs[i].class = -1; - pConfigs[i].rgba = TRUE; - pConfigs[i].redSize = 8; - pConfigs[i].greenSize = 8; - pConfigs[i].blueSize = 8; - pConfigs[i].alphaSize = 0; - pConfigs[i].redMask = 0x00FF0000; - pConfigs[i].greenMask = 0x0000FF00; - pConfigs[i].blueMask = 0x000000FF; - pConfigs[i].alphaMask = 0; - if (accum) { - pConfigs[i].accumRedSize = 16; - pConfigs[i].accumGreenSize = 16; - pConfigs[i].accumBlueSize = 16; - pConfigs[i].accumAlphaSize = 0; + for ( accum = 0 ; accum <= 1 ; accum++ ) { + for ( depth = 0 ; depth <= 1 ; depth++ ) { /* and stencil */ + for ( db = 1 ; db >= 0 ; db-- ) { + pConfigs[i].vid = -1; + pConfigs[i].class = -1; + pConfigs[i].rgba = TRUE; + pConfigs[i].redSize = 8; + pConfigs[i].greenSize = 8; + pConfigs[i].blueSize = 8; + pConfigs[i].alphaSize = 8; + pConfigs[i].redMask = 0x00FF0000; + pConfigs[i].greenMask = 0x0000FF00; + pConfigs[i].blueMask = 0x000000FF; + pConfigs[i].alphaMask = 0; + if ( accum ) { + pConfigs[i].accumRedSize = 16; + pConfigs[i].accumGreenSize = 16; + pConfigs[i].accumBlueSize = 16; + pConfigs[i].accumAlphaSize = 0; } else { - pConfigs[i].accumRedSize = 0; - pConfigs[i].accumGreenSize = 0; - pConfigs[i].accumBlueSize = 0; - pConfigs[i].accumAlphaSize = 0; + pConfigs[i].accumRedSize = 0; + pConfigs[i].accumGreenSize = 0; + pConfigs[i].accumBlueSize = 0; + pConfigs[i].accumAlphaSize = 0; } - if (db) - pConfigs[i].doubleBuffer = TRUE; - else - pConfigs[i].doubleBuffer = FALSE; - pConfigs[i].stereo = FALSE; - pConfigs[i].bufferSize = 32; - if (depth) { - pConfigs[i].depthSize = 24; - pConfigs[i].stencilSize = 8; + if ( db ) { + pConfigs[i].doubleBuffer = TRUE; + } else { + pConfigs[i].doubleBuffer = FALSE; + } + pConfigs[i].stereo = FALSE; + pConfigs[i].bufferSize = 32; + if ( depth ) { + pConfigs[i].depthSize = 24; + pConfigs[i].stencilSize = 8; } else { - pConfigs[i].depthSize = 0; - pConfigs[i].stencilSize = 0; + pConfigs[i].depthSize = 0; + pConfigs[i].stencilSize = 0; } - pConfigs[i].auxBuffers = 0; - pConfigs[i].level = 0; - if (accum) - pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT; - else - pConfigs[i].visualRating = GLX_NONE_EXT; - pConfigs[i].transparentPixel = 0; - pConfigs[i].transparentRed = 0; - pConfigs[i].transparentGreen = 0; - pConfigs[i].transparentBlue = 0; - pConfigs[i].transparentAlpha = 0; - pConfigs[i].transparentIndex = 0; + pConfigs[i].auxBuffers = 0; + pConfigs[i].level = 0; + if ( accum ) { + pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT; + } else { + pConfigs[i].visualRating = GLX_NONE_EXT; + } + pConfigs[i].transparentPixel = 0; + pConfigs[i].transparentRed = 0; + pConfigs[i].transparentGreen = 0; + pConfigs[i].transparentBlue = 0; + pConfigs[i].transparentAlpha = 0; + pConfigs[i].transparentIndex = 0; i++; } } } - if (i != numConfigs) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "[drm] Incorrect initialization of visuals\n"); + if ( i != numConfigs ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "[drm] Incorrect initialization of visuals\n" ); return FALSE; } break; default: - ; /* unexpected bits/pixelx */ + /* Unexpected bits/pixels */ + break; } - pMGA->numVisualConfigs = numConfigs; - pMGA->pVisualConfigs = pConfigs; - pMGA->pVisualConfigsPriv = pMGAConfigs; - GlxSetVisualConfigs(numConfigs, pConfigs, (void**)pMGAConfigPtrs); + + pMga->numVisualConfigs = numConfigs; + pMga->pVisualConfigs = pConfigs; + pMga->pVisualConfigsPriv = pMGAConfigs; + + GlxSetVisualConfigs( numConfigs, pConfigs, (void **)pMGAConfigPtrs ); + + return TRUE; +} + +static Bool MGACreateContext( ScreenPtr pScreen, VisualPtr visual, + drmContext hwContext, void *pVisualConfigPriv, + DRIContextType contextStore ) +{ + /* Nothing yet */ return TRUE; } -static unsigned int mylog2(unsigned int n) +static void MGADestroyContext( ScreenPtr pScreen, drmContext hwContext, + DRIContextType contextStore ) +{ + /* Nothing yet */ +} + + +/* Quiescence, locking + */ +#define MGA_TIMEOUT 2048 + +static void MGAWaitForIdleDMA( ScrnInfoPtr pScrn ) +{ + MGAPtr pMga = MGAPTR(pScrn); + int ret; + int i = 0; + + for (;;) { + do { + ret = drmMGAFlushDMA( pMga->drmFD, + DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH ); + } while ( ( ret == -EBUSY ) && ( i++ < MGA_TIMEOUT ) ); + + if ( ret == 0 ) + return; + + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "Idle timed out, resetting engine...\n" ); + + drmMGAEngineReset( pMga->drmFD ); + } +} + + +void MGAGetQuiescence( ScrnInfoPtr pScrn ) +{ + MGAPtr pMga = MGAPTR(pScrn); + + DRILock( screenInfo.screens[pScrn->scrnIndex], 0 ); + pMga->haveQuiescense = 1; + + if ( pMga->directRenderingEnabled ) { + MGAFBLayout *pLayout = &pMga->CurrentLayout; + + MGAWaitForIdleDMA( pScrn ); + + WAITFIFO( 11 ); + OUTREG( MGAREG_MACCESS, pMga->MAccess ); + OUTREG( MGAREG_PITCH, pLayout->displayWidth ); + + pMga->PlaneMask = ~0; + OUTREG( MGAREG_PLNWT, pMga->PlaneMask ); + + pMga->BgColor = 0; + pMga->FgColor = 0; + OUTREG( MGAREG_BCOL, pMga->BgColor ); + OUTREG( MGAREG_FCOL, pMga->FgColor ); + OUTREG( MGAREG_SRCORG, pMga->realSrcOrg ); + + pMga->SrcOrg = 0; + OUTREG( MGAREG_DSTORG, pMga->DstOrg ); + OUTREG( MGAREG_OPMODE, MGAOPM_DMA_BLIT ); + OUTREG( MGAREG_CXBNDRY, 0xFFFF0000 ); /* (maxX << 16) | minX */ + OUTREG( MGAREG_YTOP, 0x00000000 ); /* minPixelPointer */ + OUTREG( MGAREG_YBOT, 0x007FFFFF ); /* maxPixelPointer */ + + pMga->AccelFlags &= ~CLIPPER_ON; + } +} + +void MGAGetQuiescenceShared( ScrnInfoPtr pScrn ) +{ + MGAPtr pMga = MGAPTR(pScrn); + MGAEntPtr pMGAEnt = pMga->entityPrivate; + MGAPtr pMGA2 = MGAPTR(pMGAEnt->pScrn_2); + + DRILock( screenInfo.screens[pMGAEnt->pScrn_1->scrnIndex], 0 ); + + pMga = MGAPTR(pMGAEnt->pScrn_1); + pMga->haveQuiescense = 1; + pMGA2->haveQuiescense = 1; + + if ( pMGAEnt->directRenderingEnabled ) { + MGAWaitForIdleDMA( pMGAEnt->pScrn_1 ); + pMga->RestoreAccelState( pScrn ); + xf86SetLastScrnFlag( pScrn->entityList[0], pScrn->scrnIndex ); + } +} + +static void MGASwapContext( ScreenPtr pScreen ) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = MGAPTR(pScrn); + + /* Arrange for dma_quiescence and xaa sync to be called as + * appropriate. + */ + pMga->haveQuiescense = 0; + pMga->AccelInfoRec->NeedToSync = TRUE; +} + +static void MGASwapContextShared( ScreenPtr pScreen ) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = MGAPTR(pScrn); + MGAEntPtr pMGAEnt = pMga->entityPrivate; + MGAPtr pMGA2 = MGAPTR(pMGAEnt->pScrn_2); + + pMga = MGAPTR(pMGAEnt->pScrn_1); + + pMga->haveQuiescense = 0; + pMga->AccelInfoRec->NeedToSync = TRUE; + + pMGA2->haveQuiescense = 0; + pMGA2->AccelInfoRec->NeedToSync = TRUE; +} + +/* This is really only called from validate/postvalidate as we + * override the dri lock/unlock. Want to remove validate/postvalidate + * processing, but need to remove all client-side use of drawable lock + * first (otherwise there is noone recover when a client dies holding + * the drawable lock). + * + * What does this mean? + * + * - The above code gets executed every time a + * window changes shape or the focus changes, which isn't really + * optimal. + * - The X server therefore believes it needs to do an XAA sync + * *and* a dma quiescense ioctl each time that happens. + * + * We don't wrap wakeuphandler any longer, so at least we can say that + * this doesn't happen *every time the mouse moves*... + */ +static void +MGADRISwapContext( ScreenPtr pScreen, DRISyncType syncType, + DRIContextType oldContextType, void *oldContext, + DRIContextType newContextType, void *newContext ) +{ +#if 0 + if ( syncType == DRI_3D_SYNC && + oldContextType == DRI_2D_CONTEXT && + newContextType == DRI_2D_CONTEXT ) + { + MGASwapContext( pScreen ); + } +#endif +} + +static void +MGADRISwapContextShared( ScreenPtr pScreen, DRISyncType syncType, + DRIContextType oldContextType, void *oldContext, + DRIContextType newContextType, void *newContext ) +{ +#if 0 + if ( syncType == DRI_3D_SYNC && + oldContextType == DRI_2D_CONTEXT && + newContextType == DRI_2D_CONTEXT ) + { + MGASwapContextShared( pScreen ); + } +#endif +} + + +static void MGAWakeupHandler( int screenNum, pointer wakeupData, + unsigned long result, pointer pReadmask ) +{ + ScreenPtr pScreen = screenInfo.screens[screenNum]; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + if ( xf86IsEntityShared( pScrn->entityList[0] ) ) { + MGASwapContextShared( pScreen ); + } else { + MGASwapContext( pScreen ); + } +} + +static void MGABlockHandler( int screenNum, pointer blockData, + pointer pTimeout, pointer pReadmask ) + +{ + ScreenPtr pScreen = screenInfo.screens[screenNum]; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = MGAPTR(pScrn); + MGAEntPtr pMGAEnt; + + if ( pMga->haveQuiescense ) { + if ( xf86IsEntityShared( pScrn->entityList[0] ) ) { + /* Restore to first screen */ + pMga->RestoreAccelState( pScrn ); + xf86SetLastScrnFlag( pScrn->entityList[0], pScrn->scrnIndex ); + pMGAEnt = pMga->entityPrivate; + + if ( pMGAEnt->directRenderingEnabled ) { + DRIUnlock( screenInfo.screens[pMGAEnt->pScrn_1->scrnIndex] ); + } + } else { + if ( pMga->directRenderingEnabled ) { + DRIUnlock( pScreen ); + } + } + pMga->haveQuiescense = 0; + } +} + +void MGASelectBuffer( ScrnInfoPtr pScrn, int which ) +{ + MGAPtr pMga = MGAPTR(pScrn); + MGADRIPtr pMGADRI = (MGADRIPtr)pMga->pDRIInfo->devPrivate; + + switch ( which ) { + case MGA_BACK: + OUTREG( MGAREG_DSTORG, pMGADRI->backOffset ); + OUTREG( MGAREG_SRCORG, pMGADRI->backOffset ); + break; + case MGA_DEPTH: + OUTREG( MGAREG_DSTORG, pMGADRI->depthOffset ); + OUTREG( MGAREG_SRCORG, pMGADRI->depthOffset ); + break; + default: + case MGA_FRONT: + OUTREG( MGAREG_DSTORG, pMGADRI->frontOffset ); + OUTREG( MGAREG_SRCORG, pMGADRI->frontOffset ); + break; + } +} + + +static unsigned int mylog2( unsigned int n ) { unsigned int log2 = 1; - while (n>1) n >>= 1, log2++; + while ( n > 1 ) n >>= 1, log2++; return log2; } -static unsigned long MGAParseAgpMode(ScreenPtr pScreen) +static Bool MGADRIAgpInit(ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; MGAPtr pMga = MGAPTR(pScrn); - unsigned long mode_mask; + MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; + unsigned long mode; + unsigned int vendor, device; + int ret, count; + + /* FIXME: Make these configurable... + */ + pMGADRIServer->agp.size = 12 * 1024 * 1024; - switch(pMga->agp_mode) { + pMGADRIServer->warp.offset = 0; + pMGADRIServer->warp.size = MGA_WARP_UCODE_SIZE; + + pMGADRIServer->primary.offset = (pMGADRIServer->warp.offset + + pMGADRIServer->warp.size); + pMGADRIServer->primary.size = 1024 * 1024; + + pMGADRIServer->buffers.offset = (pMGADRIServer->primary.offset + + pMGADRIServer->primary.size); + pMGADRIServer->buffers.size = MGA_NUM_BUFFERS * MGA_BUFFER_SIZE; + + if ( drmAgpAcquire( pMga->drmFD ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not available\n" ); + return FALSE; + } + + mode = drmAgpGetMode( pMga->drmFD ); /* Default mode */ + vendor = drmAgpVendorId( pMga->drmFD ); + device = drmAgpDeviceId( pMga->drmFD ); + + mode &= ~MGA_AGP_MODE_MASK; + switch ( pMga->agpMode ) { case 4: - mode_mask = ~0x00000003; - break; + mode |= MGA_AGP_4X_MODE; case 2: - if (pMga->Chipset == PCI_CHIP_MGAG200) { - xf86DrvMsg(pScreen->myNum, X_INFO, - "[drm] Enabling AGP 2x pll encoding\n"); - OUTREG(MGAREG_AGP_PLL, AGP_PLL_agp2xpllen_enable); - } - mode_mask = ~0x00000005; - break; - default: - /* Default to 1X agp mode */ + mode |= MGA_AGP_2X_MODE; case 1: - if (pMga->Chipset == PCI_CHIP_MGAG200) { - xf86DrvMsg(pScreen->myNum, X_INFO, - "[drm] Disabling AGP 2x pll encoding\n"); - OUTREG(MGAREG_AGP_PLL, AGP_PLL_agp2xpllen_disable); + default: + mode |= MGA_AGP_1X_MODE; + } + + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] Mode 0x%08lx [AGP 0x%04x/0x%04x; Card 0x%04x/0x%04x]\n", + mode, vendor, device, + pMga->PciInfo->vendor, + pMga->PciInfo->chipType ); + + if ( drmAgpEnable( pMga->drmFD, mode ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not enabled\n" ); + drmAgpRelease( pMga->drmFD ); + return FALSE; + } + + if ( pMga->Chipset == PCI_CHIP_MGAG200 ) { + switch ( pMga->agpMode ) { + case 2: + xf86DrvMsg( pScreen->myNum, X_INFO, + "[drm] Enabling AGP 2x PLL encoding\n" ); + OUTREG( MGAREG_AGP_PLL, MGA_AGP2XPLL_ENABLE ); + break; + + case 1: + default: + xf86DrvMsg( pScreen->myNum, X_INFO, + "[drm] Disabling AGP 2x PLL encoding\n" ); + OUTREG( MGAREG_AGP_PLL, MGA_AGP2XPLL_DISABLE ); + pMga->agpMode = 1; + break; } - pMga->agp_mode = 1; - mode_mask = ~0x00000006; + } + + ret = drmAgpAlloc( pMga->drmFD, pMGADRIServer->agp.size, + 0, NULL, &pMGADRIServer->agp.handle ); + if ( ret < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] Out of memory (%d)\n", ret ); + drmAgpRelease( pMga->drmFD ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] %d kB allocated with handle 0x%08x\n", + pMGADRIServer->agp.size/1024, pMGADRIServer->agp.handle ); + + if ( drmAgpBind( pMga->drmFD, pMGADRIServer->agp.handle, 0 ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] Could not bind memory\n" ); + drmAgpFree( pMga->drmFD, pMGADRIServer->agp.handle ); + drmAgpRelease( pMga->drmFD ); + return FALSE; + } + + /* WARP microcode space + */ + if ( drmAddMap( pMga->drmFD, + pMGADRIServer->warp.offset, + pMGADRIServer->warp.size, + DRM_AGP, DRM_READ_ONLY, + &pMGADRIServer->warp.handle ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[agp] Could not add WARP microcode mapping\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] WARP microcode handle = 0x%08lx\n", + pMGADRIServer->warp.handle ); + + if ( drmMap( pMga->drmFD, + pMGADRIServer->warp.handle, + pMGADRIServer->warp.size, + &pMGADRIServer->warp.map ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[agp] Could not map WARP microcode\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] WARP microcode mapped at 0x%08lx\n", + (unsigned long)pMGADRIServer->warp.map ); + + /* Primary DMA space + */ + if ( drmAddMap( pMga->drmFD, + pMGADRIServer->primary.offset, + pMGADRIServer->primary.size, + DRM_AGP, DRM_READ_ONLY, + &pMGADRIServer->primary.handle ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[agp] Could not add primary DMA mapping\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] Primary DMA handle = 0x%08lx\n", + pMGADRIServer->primary.handle ); + + if ( drmMap( pMga->drmFD, + pMGADRIServer->primary.handle, + pMGADRIServer->primary.size, + &pMGADRIServer->primary.map ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[agp] Could not map primary DMA\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] Primary DMA mapped at 0x%08lx\n", + (unsigned long)pMGADRIServer->primary.map ); + + /* DMA buffers + */ + if ( drmAddMap( pMga->drmFD, + pMGADRIServer->buffers.offset, + pMGADRIServer->buffers.size, + DRM_AGP, 0, + &pMGADRIServer->buffers.handle ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[agp] Could not add DMA buffers mapping\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] DMA buffers handle = 0x%08lx\n", + pMGADRIServer->buffers.handle ); + + if ( drmMap( pMga->drmFD, + pMGADRIServer->buffers.handle, + pMGADRIServer->buffers.size, + &pMGADRIServer->buffers.map ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[agp] Could not map DMA buffers\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] DMA buffers mapped at 0x%08lx\n", + (unsigned long)pMGADRIServer->buffers.map ); + + count = drmAddBufs( pMga->drmFD, + MGA_NUM_BUFFERS, MGA_BUFFER_SIZE, + DRM_AGP_BUFFER, pMGADRIServer->buffers.offset ); + if ( count <= 0 ) { + xf86DrvMsg( pScrn->scrnIndex, X_INFO, + "[drm] failure adding %d %d byte DMA buffers\n", + MGA_NUM_BUFFERS, MGA_BUFFER_SIZE ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[drm] Added %d %d byte DMA buffers\n", + count, MGA_BUFFER_SIZE ); + + xf86EnablePciBusMaster( pMga->PciInfo, TRUE ); + + return TRUE; +} + +static Bool MGADRIMapInit( ScreenPtr pScreen ) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = MGAPTR(pScrn); + MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; + + pMGADRIServer->registers.size = MGAIOMAPSIZE; + + if ( drmAddMap( pMga->drmFD, + (drmHandle)pMga->IOAddress, + pMGADRIServer->registers.size, + DRM_REGISTERS, DRM_READ_ONLY, + &pMGADRIServer->registers.handle ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] Could not add MMIO registers mapping\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[drm] Registers handle = 0x%08lx\n", + pMGADRIServer->registers.handle ); + + pMGADRIServer->status.size = SAREA_MAX; + + if ( drmAddMap( pMga->drmFD, 0, pMGADRIServer->status.size, + DRM_SHM, DRM_READ_ONLY | DRM_LOCKED | DRM_KERNEL, + &pMGADRIServer->status.handle ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] Could not add status page mapping\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[drm] Status handle = 0x%08lx\n", + pMGADRIServer->status.handle ); + + if ( drmMap( pMga->drmFD, + pMGADRIServer->status.handle, + pMGADRIServer->status.size, + &pMGADRIServer->status.map ) < 0 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[agp] Could not map status page\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[agp] Status page mapped at 0x%08lx\n", + (unsigned long)pMGADRIServer->status.map ); + + return TRUE; +} + +static Bool MGADRIKernelInit( ScreenPtr pScreen ) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = MGAPTR(pScrn); + MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; + drmMGAInit init; + int ret; + + memset( &init, 0, sizeof(drmMGAInit) ); + + init.sarea_priv_offset = sizeof(XF86DRISAREARec); + + switch ( pMga->Chipset ) { + case PCI_CHIP_MGAG400: + init.chipset = MGA_CARD_TYPE_G400; + break; + case PCI_CHIP_MGAG200: + case PCI_CHIP_MGAG200_PCI: + init.chipset = MGA_CARD_TYPE_G200; break; + default: + return FALSE; } + init.sgram = !pMga->HasSDRAM; - return mode_mask; + init.maccess = pMga->MAccess; + + init.fb_cpp = pScrn->bitsPerPixel / 8; + init.front_offset = pMGADRIServer->frontOffset; + init.front_pitch = pMGADRIServer->frontPitch / init.fb_cpp; + init.back_offset = pMGADRIServer->backOffset; + init.back_pitch = pMGADRIServer->backPitch / init.fb_cpp; + + init.depth_cpp = pScrn->bitsPerPixel / 8; + init.depth_offset = pMGADRIServer->depthOffset; + init.depth_pitch = pMGADRIServer->depthPitch / init.depth_cpp; + + init.texture_offset[0] = pMGADRIServer->textureOffset; + init.texture_size[0] = pMGADRIServer->textureSize; + + init.fb_offset = pMga->FbAddress; + init.mmio_offset = pMGADRIServer->registers.handle; + init.status_offset = pMGADRIServer->status.handle; + + init.warp_offset = pMGADRIServer->warp.handle; + init.primary_offset = pMGADRIServer->primary.handle; + init.buffers_offset = pMGADRIServer->buffers.handle; + + ret = drmMGAInitDMA( pMga->drmFD, &init ); + if ( ret < 0 ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "[drm] Failed to initialize DMA! (%d)\n", ret ); + return FALSE; + } + +#if 0 + /* FIXME: This is just here to clean up after the engine reset test + * in the kernel module. Please remove it later... + */ + pMga->GetQuiescence( pScrn ); +#endif + + return TRUE; } -Bool MGADRIScreenInit(ScreenPtr pScreen) +static Bool MGADRIBuffersInit( ScreenPtr pScreen ) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - MGAPtr pMGA = MGAPTR(pScrn); + MGAPtr pMga = MGAPTR(pScrn); + MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; + + + pMGADRIServer->drmBuffers = drmMapBufs( pMga->drmFD ); + if ( !pMGADRIServer->drmBuffers ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] Failed to map DMA buffers list\n" ); + return FALSE; + } + xf86DrvMsg( pScreen->myNum, X_INFO, + "[drm] Mapped %d DMA buffers\n", + pMGADRIServer->drmBuffers->count ); + + return TRUE; +} + + +Bool MGADRIScreenInit( ScreenPtr pScreen ) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = MGAPTR(pScrn); DRIInfoPtr pDRIInfo; MGADRIPtr pMGADRI; MGADRIServerPrivatePtr pMGADRIServer; - int bufs, size; - int prim_size; - int init_offset; - int i; - unsigned long mode_mask; - switch(pMGA->Chipset) { + switch ( pMga->Chipset ) { case PCI_CHIP_MGAG400: case PCI_CHIP_MGAG200: #if 0 @@ -388,112 +906,134 @@ Bool MGADRIScreenInit(ScreenPtr pScreen) #endif break; default: - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[drm] Direct rendering only supported with G200/G400 AGP\n"); + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "[drm] Direct rendering only supported with AGP G200/G400 cards!\n" ); return FALSE; } /* Check that the GLX, DRI, and DRM modules have been loaded by testing - * for canonical symbols in each module. */ - if (!xf86LoaderCheckSymbol("GlxSetVisualConfigs")) return FALSE; - if (!xf86LoaderCheckSymbol("DRIScreenInit")) return FALSE; - if (!xf86LoaderCheckSymbol("drmAvailable")) return FALSE; - if (!xf86LoaderCheckSymbol("DRIQueryVersion")) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "MGADRIScreenInit failed (libdri.a too old)\n"); + * for canonical symbols in each module. + */ + if ( !xf86LoaderCheckSymbol( "GlxSetVisualConfigs" ) ) return FALSE; + if ( !xf86LoaderCheckSymbol( "DRIScreenInit" ) ) return FALSE; + if ( !xf86LoaderCheckSymbol( "drmAvailable" ) ) return FALSE; + if ( !xf86LoaderCheckSymbol( "DRIQueryVersion" ) ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "MGADRIScreenInit failed (libdri.a too old)\n" ); return FALSE; } - + /* Check the DRI version */ { int major, minor, patch; - DRIQueryVersion(&major, &minor, &patch); - if (major != 3 || minor != 1 || patch < 0) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] MGADRIScreenInit failed (DRI version = %d.%d.%d, expected 3.1.x). Disabling DRI.\n", - major, minor, patch); + DRIQueryVersion( &major, &minor, &patch ); + if ( major != 4 || minor < 0) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] MGADRIScreenInit failed " + "(DRI version = %d.%d.%d, expected 4.0.x). " + "Disabling DRI.\n", + major, minor, patch ); return FALSE; } } - xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] bpp: %d depth: %d\n", pScrn->bitsPerPixel, pScrn->depth); + xf86DrvMsg( pScreen->myNum, X_INFO, + "[drm] bpp: %d depth: %d\n", + pScrn->bitsPerPixel, pScrn->depth ); - if ((pScrn->bitsPerPixel / 8) != 2 && - (pScrn->bitsPerPixel / 8) != 4) { - xf86DrvMsg(pScreen->myNum, X_INFO, - "[drm] Direct rendering only supported in 16 and 32 bpp modes\n"); + if ( (pScrn->bitsPerPixel / 8) != 2 && + (pScrn->bitsPerPixel / 8) != 4 ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] Direct rendering only supported in 16 and 32 bpp modes\n" ); return FALSE; } - + pDRIInfo = DRICreateInfoRec(); - if (!pDRIInfo) + if ( !pDRIInfo ) { + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] DRICreateInfoRec() failed\n" ); return FALSE; - pMGA->pDRIInfo = pDRIInfo; + } + pMga->pDRIInfo = pDRIInfo; pDRIInfo->drmDriverName = MGAKernelDriverName; pDRIInfo->clientDriverName = MGAClientDriverName; pDRIInfo->busIdString = xalloc(64); - sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d", - ((pciConfigPtr)pMGA->PciInfo->thisCard)->busnum, - ((pciConfigPtr)pMGA->PciInfo->thisCard)->devnum, - ((pciConfigPtr)pMGA->PciInfo->thisCard)->funcnum); + sprintf( pDRIInfo->busIdString, "PCI:%d:%d:%d", + ((pciConfigPtr)pMga->PciInfo->thisCard)->busnum, + ((pciConfigPtr)pMga->PciInfo->thisCard)->devnum, + ((pciConfigPtr)pMga->PciInfo->thisCard)->funcnum ); pDRIInfo->ddxDriverMajorVersion = MGA_MAJOR_VERSION; pDRIInfo->ddxDriverMinorVersion = MGA_MINOR_VERSION; pDRIInfo->ddxDriverPatchVersion = MGA_PATCHLEVEL; - pDRIInfo->frameBufferPhysicalAddress = pMGA->FbAddress; - pDRIInfo->frameBufferSize = pMGA->FbMapSize; + pDRIInfo->frameBufferPhysicalAddress = pMga->FbAddress; + pDRIInfo->frameBufferSize = pMga->FbMapSize; pDRIInfo->frameBufferStride = pScrn->displayWidth*(pScrn->bitsPerPixel/8); pDRIInfo->ddxDrawableTableEntry = MGA_MAX_DRAWABLES; - MGADRIWrapFunctions( pScreen, pDRIInfo ); + pDRIInfo->wrap.BlockHandler = MGABlockHandler; + pDRIInfo->wrap.WakeupHandler = MGAWakeupHandler; + pDRIInfo->wrap.ValidateTree = NULL; + pDRIInfo->wrap.PostValidateTree = NULL; + + pDRIInfo->createDummyCtx = TRUE; + pDRIInfo->createDummyCtxPriv = FALSE; - if (SAREA_MAX_DRAWABLES < MGA_MAX_DRAWABLES) + if ( SAREA_MAX_DRAWABLES < MGA_MAX_DRAWABLES ) { pDRIInfo->maxDrawableTableEntry = SAREA_MAX_DRAWABLES; - else + } else { pDRIInfo->maxDrawableTableEntry = MGA_MAX_DRAWABLES; + } /* For now the mapping works by using a fixed size defined - * in the SAREA header + * in the SAREA header. */ - if (sizeof(XF86DRISAREARec)+sizeof(MGASAREARec)>SAREA_MAX) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[drm] Data does not fit in SAREA\n"); + if ( sizeof(XF86DRISAREARec) + sizeof(MGASAREAPrivRec) > SAREA_MAX ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "[drm] Data does not fit in SAREA\n" ); return FALSE; } - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Sarea %d+%d: %d\n", - sizeof(XF86DRISAREARec), sizeof(MGASAREARec), - sizeof(XF86DRISAREARec) + sizeof(MGASAREARec)); + + xf86DrvMsg( pScrn->scrnIndex, X_INFO, + "[drm] Sarea %d+%d: %d\n", + sizeof(XF86DRISAREARec), sizeof(MGASAREAPrivRec), + sizeof(XF86DRISAREARec) + sizeof(MGASAREAPrivRec) ); pDRIInfo->SAREASize = SAREA_MAX; - if (!(pMGADRI = (MGADRIPtr)xnfcalloc(sizeof(MGADRIRec),1))) { - DRIDestroyInfoRec(pMGA->pDRIInfo); - pMGA->pDRIInfo=0; - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "[drm] Failed to allocate memory for private record\n"); + pMGADRI = (MGADRIPtr)xcalloc( sizeof(MGADRIRec), 1 ); + if ( !pMGADRI ) { + DRIDestroyInfoRec( pMga->pDRIInfo ); + pMga->pDRIInfo = 0; + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "[drm] Failed to allocate memory for private record\n" ); return FALSE; } - if (!(pMGADRIServer = (MGADRIServerPrivatePtr) - xnfcalloc(sizeof(MGADRIServerPrivateRec),1))) { - xfree(pMGADRI); - DRIDestroyInfoRec(pMGA->pDRIInfo); - pMGA->pDRIInfo=0; - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "[drm] Failed to allocate memory for private record\n"); + + pMGADRIServer = (MGADRIServerPrivatePtr) + xcalloc( sizeof(MGADRIServerPrivateRec), 1 ); + if ( !pMGADRIServer ) { + xfree( pMGADRI ); + DRIDestroyInfoRec( pMga->pDRIInfo ); + pMga->pDRIInfo = 0; + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "[drm] Failed to allocate memory for private record\n" ); return FALSE; } + pMga->DRIServerInfo = pMGADRIServer; pDRIInfo->devPrivate = pMGADRI; - pMGA->DRIServerInfo = pMGADRIServer; pDRIInfo->devPrivateSize = sizeof(MGADRIRec); pDRIInfo->contextSize = sizeof(MGADRIContextRec); pDRIInfo->CreateContext = MGACreateContext; pDRIInfo->DestroyContext = MGADestroyContext; - if (xf86IsEntityShared(pScrn->entityList[0])) - pDRIInfo->SwapContext = MGADRISwapContext_shared; - else + if ( xf86IsEntityShared( pScrn->entityList[0] ) ) { + pDRIInfo->SwapContext = MGADRISwapContextShared; + } else { pDRIInfo->SwapContext = MGADRISwapContext; - + } + switch( pScrn->bitsPerPixel ) { case 8: pDRIInfo->InitBuffers = Mga8DRIInitBuffers; @@ -508,141 +1048,115 @@ Bool MGADRIScreenInit(ScreenPtr pScreen) pDRIInfo->InitBuffers = Mga32DRIInitBuffers; pDRIInfo->MoveBuffers = Mga32DRIMoveBuffers; } - + pDRIInfo->bufferRequests = DRI_ALL_WINDOWS; - if (!DRIScreenInit(pScreen, pDRIInfo, &pMGA->drmSubFD)) { - xfree(pMGADRIServer); - pMGA->DRIServerInfo = 0; - xfree(pDRIInfo->devPrivate); + if ( !DRIScreenInit( pScreen, pDRIInfo, &pMga->drmFD ) ) { + xfree( pMGADRIServer ); + pMga->DRIServerInfo = 0; + xfree( pDRIInfo->devPrivate ); pDRIInfo->devPrivate = 0; - DRIDestroyInfoRec(pMGA->pDRIInfo); - pMGA->pDRIInfo = 0; - xf86DrvMsg(pScreen->myNum, X_ERROR, "[drm] DRIScreenInit Failed\n"); + DRIDestroyInfoRec( pMga->pDRIInfo ); + pMga->pDRIInfo = 0; + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] DRIScreenInit Failed\n" ); return FALSE; } /* Check the MGA DRM version */ { - drmVersionPtr version = drmGetVersion(pMGA->drmSubFD); - if (version) { - if (version->version_major != 2 || - version->version_minor != 1 || - version->version_patchlevel < 0) { + drmVersionPtr version = drmGetVersion(pMga->drmFD); + if ( version ) { + if ( version->version_major != 3 || + version->version_minor < 0) { /* incompatible drm version */ - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] MGADRIScreenInit failed (DRM version = %d.%d.%d, expected 2.1.x). Disabling DRI.\n", - version->version_major, - version->version_minor, - version->version_patchlevel); -/* MGADRICloseScreen(pScreen); */ - - drmFreeVersion(version); + xf86DrvMsg( pScreen->myNum, X_ERROR, + "[drm] MGADRIScreenInit failed " + "(DRM version = %d.%d.%d, expected 3.0.x). " + "Disabling DRI.\n", + version->version_major, + version->version_minor, + version->version_patchlevel ); + drmFreeVersion( version ); + MGADRICloseScreen( pScreen ); /* FIXME: ??? */ return FALSE; } - drmFreeVersion(version); + drmFreeVersion( version ); } } - pMGADRIServer->regsSize = MGAIOMAPSIZE; - if (drmAddMap(pMGA->drmSubFD, (drmHandle)pMGA->IOAddress, - pMGADRIServer->regsSize, DRM_REGISTERS, 0, - &pMGADRIServer->regs)<0) { - DRICloseScreen(pScreen); - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] drmAddMap failed Register MMIO region\n"); - return FALSE; +#if 0 + /* Calculate texture constants for AGP texture space. + * FIXME: move! + */ + { + CARD32 agpTextureOffset = MGA_DMA_BUF_SZ * MGA_DMA_BUF_NR; + CARD32 agpTextureSize = pMGADRI->agp.size - agpTextureOffset; + + i = mylog2(agpTextureSize / MGA_NR_TEX_REGIONS); + if (i < MGA_LOG_MIN_TEX_REGION_SIZE) + i = MGA_LOG_MIN_TEX_REGION_SIZE; + + pMGADRI->logAgpTextureGranularity = i; + pMGADRI->agpTextureSize = (agpTextureSize >> i) << i; + pMGADRI->agpTextureOffset = agpTextureOffset; } - xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] Registers = 0x%08lx\n", - pMGADRIServer->regs); - - /* Agp Support */ - pMGADRIServer->agpAcquired = FALSE; - pMGADRIServer->agpHandle = 0; - pMGADRIServer->agpSizep = 0; - pMGADRIServer->agp_map = 0; - - if (drmAgpAcquire(pMGA->drmSubFD) < 0) { - DRICloseScreen(pScreen); - xf86DrvMsg(pScreen->myNum, X_ERROR, "[drm] drmAgpAcquire failed\n"); +#endif + + if ( !MGADRIAgpInit( pScreen ) ) { + DRICloseScreen( pScreen ); return FALSE; } - pMGADRIServer->agpAcquired = TRUE; - pMGADRIServer->warp_ucode_size = mgaGetMicrocodeSize(pScreen); - if (pMGADRIServer->warp_ucode_size == 0) { - xf86DrvMsg(pScreen->myNum, X_ERROR, "[drm] microcodeSize is zero\n"); - DRICloseScreen(pScreen); + if ( !MGADRIMapInit( pScreen ) ) { + DRICloseScreen( pScreen ); return FALSE; } - mode_mask = MGAParseAgpMode(pScreen); - - pMGADRIServer->agpMode = drmAgpGetMode(pMGA->drmSubFD); - pMGADRIServer->agpMode &= mode_mask; - if (drmAgpEnable(pMGA->drmSubFD, pMGADRIServer->agpMode) < 0) { - xf86DrvMsg(pScreen->myNum, X_ERROR, "[drm] drmAgpEnable failed\n"); - DRICloseScreen(pScreen); + if ( !MGAInitVisualConfigs( pScreen ) ) { + DRICloseScreen( pScreen ); return FALSE; } - ErrorF("[drm] drmAgpEnabled succeeded for AGP mode %dx\n", pMGA->agp_mode); + xf86DrvMsg( pScrn->scrnIndex, X_INFO, "visual configs initialized\n" ); + + return TRUE; +} - prim_size = 65536; - init_offset = ((prim_size + pMGADRIServer->warp_ucode_size + - 4096 - 1) / 4096) * 4096; - - pMGADRIServer->agpSizep = init_offset; - pMGADRI->agpSize = (drmAgpSize(pMGA->drmSubFD)) - init_offset; - pMGADRIServer->agpBase = (drmAddress) drmAgpBase(pMGA->drmSubFD); - if (drmAddMap(pMGA->drmSubFD, 0, - init_offset, DRM_AGP, 0, - &pMGADRIServer->agp_private) < 0) { - DRICloseScreen(pScreen); - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] drmAddMap failed on AGP aperture\n"); - return FALSE; - } - - if (drmMap(pMGA->drmSubFD, (drmHandle)pMGADRIServer->agp_private, - init_offset, - (drmAddressPtr)&pMGADRIServer->agp_map) < -1) { - DRICloseScreen(pScreen); - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] drmMap failed on AGP aperture\n"); +Bool MGADRIFinishScreenInit( ScreenPtr pScreen ) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + MGAPtr pMga = MGAPTR(pScrn); + MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; + MGADRIPtr pMGADRI = (MGADRIPtr)pMga->pDRIInfo->devPrivate; + int i; + + if ( !pMga->pDRIInfo ) return FALSE; - } - - /* Now allocate and bind a default of 8 megs */ - drmAgpAlloc(pMGA->drmSubFD, 0x00800000, 0, 0, - &pMGADRIServer->agpHandle); - - if (pMGADRIServer->agpHandle == 0) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] drmAgpAlloc failed\n"); - DRICloseScreen(pScreen); + + pMga->pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT; + + /* NOTE: DRIFinishScreenInit must be called before *DRIKernelInit + * because *DRIKernelInit requires that the hardware lock is held by + * the X server, and the first time the hardware lock is grabbed is + * in DRIFinishScreenInit. + */ + if ( !DRIFinishScreenInit( pScreen ) ) { + MGADRICloseScreen( pScreen ); return FALSE; } - - if (drmAgpBind(pMGA->drmSubFD, pMGADRIServer->agpHandle, 0) < 0) { - DRICloseScreen(pScreen); - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] drmAgpBind failed\n"); + + if ( !MGADRIKernelInit( pScreen ) ) { + MGADRICloseScreen( pScreen ); return FALSE; } - mgaInstallMicrocode(pScreen, prim_size); - - if (drmAddMap(pMGA->drmSubFD, (drmHandle)init_offset, - pMGADRI->agpSize, DRM_AGP, 0, - &pMGADRI->agp) < 0) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] Failed to map public agp area\n"); - DRICloseScreen(pScreen); + if ( !MGADRIBuffersInit( pScreen ) ) { + MGADRICloseScreen( pScreen ); return FALSE; } - switch(pMGA->Chipset) { + switch ( pMga->Chipset ) { case PCI_CHIP_MGAG400: pMGADRI->chipset = MGA_CARD_TYPE_G400; break; @@ -653,356 +1167,97 @@ Bool MGADRIScreenInit(ScreenPtr pScreen) default: return FALSE; } - - pMGADRI->width = pScrn->virtualX; - pMGADRI->height = pScrn->virtualY; - pMGADRI->mem = pScrn->videoRam * 1024; - pMGADRI->cpp = pScrn->bitsPerPixel / 8; - pMGADRI->frontPitch = pScrn->displayWidth * (pScrn->bitsPerPixel / 8); - - - pMGADRI->frontOffset = 0; /* pMGA->YDstOrg * (pScrn->bitsPerPixel / 8) */ - pMGADRI->backOffset = ((pScrn->virtualY + pMGA->numXAALines + 1) * - pScrn->displayWidth * - pMGADRI->cpp + 4095) & ~0xFFF; - - - xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] calced backoffset: 0x%x\n", - pMGADRI->backOffset); - - - size = pMGADRI->cpp * pScrn->virtualX * pScrn->virtualY; - size += 4095; - size &= ~4095; - pMGADRI->depthOffset = pMGA->FbUsableSize - size; - pMGADRI->depthOffset &= ~4095; - pMGADRI->textureOffset = pMGADRI->backOffset + size; - pMGADRI->textureSize = pMGADRI->depthOffset - pMGADRI->textureOffset; - - if (pMGADRI->depthOffset < pMGADRI->textureOffset + 512*1024) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] Insufficient memory for direct rendering\n"); - DRICloseScreen(pScreen); - return FALSE; - } - - pMGADRI->mAccess = pMGA->MAccess; - - i = mylog2(pMGADRI->textureSize / MGA_NR_TEX_REGIONS); - if (i < MGA_LOG_MIN_TEX_REGION_SIZE) + pMGADRI->width = pScrn->virtualX; + pMGADRI->height = pScrn->virtualY; + pMGADRI->mem = pScrn->videoRam * 1024; + pMGADRI->cpp = pScrn->bitsPerPixel / 8; + + pMGADRI->agpMode = pMga->agpMode; + + pMGADRI->frontOffset = pMGADRIServer->frontOffset; + pMGADRI->frontPitch = pMGADRIServer->frontPitch; + pMGADRI->backOffset = pMGADRIServer->backOffset; + pMGADRI->backPitch = pMGADRIServer->backPitch; + pMGADRI->depthOffset = pMGADRIServer->depthOffset; + pMGADRI->depthPitch = pMGADRIServer->depthPitch; + pMGADRI->textureOffset = pMGADRIServer->textureOffset; + pMGADRI->textureSize = pMGADRIServer->textureSize; + + i = mylog2( pMGADRI->textureSize / MGA_NR_TEX_REGIONS ); + if ( i < MGA_LOG_MIN_TEX_REGION_SIZE ) i = MGA_LOG_MIN_TEX_REGION_SIZE; - + pMGADRI->logTextureGranularity = i; pMGADRI->textureSize = (pMGADRI->textureSize >> i) << i; /* truncate */ - - /* Here is where we need to do initialization of the dma engine */ - if((bufs = drmAddBufs(pMGA->drmSubFD, - MGA_DMA_BUF_NR, - MGA_DMA_BUF_SZ, - DRM_AGP_BUFFER, - init_offset)) <= 0) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "[drm] failure adding %d %d byte DMA buffers\n", - MGA_DMA_BUF_NR, - MGA_DMA_BUF_SZ); - DRICloseScreen(pScreen); - return FALSE; - } - - pMGADRI->agpBufferOffset = init_offset + pMGADRIServer->agp_private; - - /* Calculate texture constants for AGP texture space - */ - { - CARD32 agpTextureOffset = MGA_DMA_BUF_SZ * MGA_DMA_BUF_NR; - CARD32 agpTextureSize = pMGADRI->agpSize - agpTextureOffset; - - i = mylog2(agpTextureSize / MGA_NR_TEX_REGIONS); - if (i < MGA_LOG_MIN_TEX_REGION_SIZE) - i = MGA_LOG_MIN_TEX_REGION_SIZE; - - pMGADRI->logAgpTextureGranularity = i; - pMGADRI->agpTextureSize = (agpTextureSize >> i) << i; - pMGADRI->agpTextureOffset = agpTextureOffset; - } - - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "[drm] added %d %d byte DMA buffers\n", - bufs, MGA_DMA_BUF_SZ); - - - if ((MgaInitDma(pScrn, prim_size)) != TRUE) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] Failed to initialize dma engine\n"); - DRICloseScreen(pScreen); - return FALSE; - } - - xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] Initialized Dma Engine\n"); - - if (!pMGADRIServer->irq) { - pMGADRIServer->irq = drmGetInterruptFromBusID(pMGA->drmSubFD, - ((pciConfigPtr)pMGA->PciInfo - ->thisCard)->busnum, - ((pciConfigPtr)pMGA->PciInfo - ->thisCard)->devnum, - ((pciConfigPtr)pMGA->PciInfo - ->thisCard)->funcnum); - - if(!pMGADRIServer->irq && !pMGA->ReallyUseIrqZero) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "[drm] Your graphics card has Interrupt zero" - " assigned to it.\n" - "This is highly unlikely so I'm disabling the DRI.\n" - "If your graphics card really has Interrupt zero, please" - "add the config option UseIrqZero\n" - "to the device section in your XF86Config file.\n" - "Please be warned that Interrupt zero is normally " - "the timer interrupt on X86 systems.\n" - "Using this option could make your system unusable.\n" - "The more likely solution is that your graphics card has" - " no interrupt assigned to it.\nPlease consult your" - " system BIOS manual for instructions on how to enable " - "an interrupt for your graphics card.\n"); - MGADRICloseScreen(pScreen); - return FALSE; - } - drmCtlInstHandler(pMGA->drmSubFD, pMGADRIServer->irq); - } - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "[drm] dma control initialized, using IRQ %d\n", - pMGADRIServer->irq); - - - if (!(MGAInitVisualConfigs(pScreen))) { - DRICloseScreen(pScreen); - return FALSE; - } - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "visual configs initialized\n" ); - + pMGADRI->registers.handle = pMGADRIServer->registers.handle; + pMGADRI->registers.size = pMGADRIServer->registers.size; + pMGADRI->status.handle = pMGADRIServer->status.handle; + pMGADRI->status.size = pMGADRIServer->status.size; + pMGADRI->primary.handle = pMGADRIServer->primary.handle; + pMGADRI->primary.size = pMGADRIServer->primary.size; + pMGADRI->buffers.handle = pMGADRIServer->buffers.handle; + pMGADRI->buffers.size = pMGADRIServer->buffers.size; + pMGADRI->sarea_priv_offset = sizeof(XF86DRISAREARec); return TRUE; } -void -MGADRICloseScreen(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - MGAPtr pMGA = MGAPTR(pScrn); - MGADRIServerPrivatePtr pMGADRIServer = pMGA->DRIServerInfo; - -/* The DRI will automagically clean these up when driFD is closed */ - if(pMGADRIServer->agp_map) { - drmUnmap(pMGADRIServer->agp_map, pMGADRIServer->agpSizep); - pMGADRIServer->agp_map = 0; - } - if(pMGADRIServer->agpHandle) { - pMGADRIServer->agpHandle = 0; - pMGADRIServer->agpSizep = 0; - } - if(pMGADRIServer->agpAcquired == TRUE) { - pMGADRIServer->agpAcquired = FALSE; - } - - DRICloseScreen(pScreen); - - if (pMGA->pDRIInfo) { - if (pMGA->pDRIInfo->devPrivate) { - xfree(pMGA->pDRIInfo->devPrivate); - pMGA->pDRIInfo->devPrivate = 0; - } - DRIDestroyInfoRec(pMGA->pDRIInfo); - pMGA->pDRIInfo = 0; - } - if(pMGA->DRIServerInfo) { - xfree(pMGA->DRIServerInfo); - pMGA->DRIServerInfo = 0; - } - if (pMGA->pVisualConfigs) { - xfree(pMGA->pVisualConfigs); - } - if (pMGA->pVisualConfigsPriv) { - xfree(pMGA->pVisualConfigsPriv); - } -} -static Bool -MGACreateContext(ScreenPtr pScreen, VisualPtr visual, - drmContext hwContext, void *pVisualConfigPriv, - DRIContextType contextStore) -{ - return TRUE; -} - -static void -MGADestroyContext(ScreenPtr pScreen, drmContext hwContext, - DRIContextType contextStore) -{ -} - -Bool -MGADRIFinishScreenInit(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - MGASAREAPtr sPriv; - MGAPtr pMGA = MGAPTR(pScrn); - - if (!pMGA->pDRIInfo) return FALSE; - - sPriv = (MGASAREAPtr)DRIGetSAREAPrivate(pScreen); - pMGA->pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT; - - xf86memset( sPriv, 0, sizeof(MGASAREARec) ); - - return DRIFinishScreenInit(pScreen); -} - - -void -mgaGetQuiescence( ScrnInfoPtr pScrn ) +void MGADRICloseScreen( ScreenPtr pScreen ) { + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; MGAPtr pMga = MGAPTR(pScrn); + MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; - pMga->have_quiescense = 1; - - if (pMga->directRenderingEnabled) { - MGAFBLayout *pLayout = &pMga->CurrentLayout; - - MgaLockUpdate(pScrn, (DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH)); - - WAITFIFO(11); - OUTREG(MGAREG_MACCESS, pMga->MAccess); - OUTREG(MGAREG_PITCH, pLayout->displayWidth); - pMga->PlaneMask = ~0; - OUTREG(MGAREG_PLNWT, pMga->PlaneMask); - pMga->BgColor = 0; - pMga->FgColor = 0; - OUTREG(MGAREG_BCOL, pMga->BgColor); - OUTREG(MGAREG_FCOL, pMga->FgColor); - OUTREG(MGAREG_SRCORG, pMga->realSrcOrg); - pMga->SrcOrg = 0; - OUTREG(MGAREG_DSTORG, pMga->DstOrg); - OUTREG(MGAREG_OPMODE, MGAOPM_DMA_BLIT); - OUTREG(MGAREG_CXBNDRY, 0xFFFF0000); /* (maxX << 16) | minX */ - OUTREG(MGAREG_YTOP, 0x00000000); /* minPixelPointer */ - OUTREG(MGAREG_YBOT, 0x007FFFFF); /* maxPixelPointer */ - pMga->AccelFlags &= ~CLIPPER_ON; + if ( pMGADRIServer->drmBuffers ) { + drmUnmapBufs( pMGADRIServer->drmBuffers ); + pMGADRIServer->drmBuffers = NULL; } -} + drmMGACleanupDMA( pMga->drmFD ); -void -mgaGetQuiescence_shared( ScrnInfoPtr pScrn ) -{ - MGAPtr pMga = MGAPTR(pScrn); - MGAEntPtr pMgaEnt = pMga->entityPrivate; - MGAPtr pMga2 = MGAPTR(pMgaEnt->pScrn_2); - - pMga = MGAPTR(pMgaEnt->pScrn_1); - pMga->have_quiescense = 1; - pMga2->have_quiescense = 1; - - if (pMgaEnt->directRenderingEnabled) { - MgaLockUpdate(pMgaEnt->pScrn_1, (DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH)); - pMga->RestoreAccelState(pScrn); - xf86SetLastScrnFlag(pScrn->entityList[0], pScrn->scrnIndex); + if ( pMGADRIServer->status.map ) { + drmUnmap( pMGADRIServer->status.map, pMGADRIServer->status.size ); + pMGADRIServer->status.map = NULL; } -} - - -void -MGASwapContext(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - MGAPtr pMga = MGAPTR(pScrn); - - /* Arrange for dma_quiescence and xaa sync to be called as - * appropriate. - */ - pMga->have_quiescense = 0; - pMga->AccelInfoRec->NeedToSync = TRUE; -} - -void -MGASwapContext_shared(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - MGAPtr pMga = MGAPTR(pScrn); - MGAEntPtr pMgaEnt = pMga->entityPrivate; - MGAPtr pMga2 = MGAPTR(pMgaEnt->pScrn_2); - - pMga = MGAPTR(pMgaEnt->pScrn_1); - pMga->have_quiescense = 0; - pMga->AccelInfoRec->NeedToSync = TRUE; - pMga2->have_quiescense = 0; - pMga2->AccelInfoRec->NeedToSync = TRUE; -} - - -/* This is really only called from validate/postvalidate as we - * override the dri lock/unlock. Want to remove validate/postvalidate - * processing, but need to remove all client-side use of drawable lock - * first (otherwise there is noone recover when a client dies holding - * the drawable lock). - * - * What does this mean? - * - * - The above code gets executed every time a - * window changes shape or the focus changes, which isn't really - * optimal. - * - The X server therefore believes it needs to do an XAA sync - * *and* a dma quiescense ioctl each time that happens. - * - * We don't wrap wakeuphandler any longer, so at least we can say that - * this doesn't happen *every time the mouse moves*... - */ -static void -MGADRISwapContext(ScreenPtr pScreen, DRISyncType syncType, - DRIContextType oldContextType, void *oldContext, - DRIContextType newContextType, void *newContext) -{ - if (syncType == DRI_3D_SYNC && - oldContextType == DRI_2D_CONTEXT && - newContextType == DRI_2D_CONTEXT) - { - MGASwapContext(pScreen); + if ( pMGADRIServer->buffers.map ) { + drmUnmap( pMGADRIServer->buffers.map, pMGADRIServer->buffers.size ); + pMGADRIServer->buffers.map = NULL; + } + if ( pMGADRIServer->primary.map ) { + drmUnmap( pMGADRIServer->primary.map, pMGADRIServer->primary.size ); + pMGADRIServer->primary.map = NULL; + } + if ( pMGADRIServer->warp.map ) { + drmUnmap( pMGADRIServer->warp.map, pMGADRIServer->warp.size ); + pMGADRIServer->warp.map = NULL; } -} -static void -MGADRISwapContext_shared(ScreenPtr pScreen, DRISyncType syncType, - DRIContextType oldContextType, void *oldContext, - DRIContextType newContextType, void *newContext) -{ - if (syncType == DRI_3D_SYNC && - oldContextType == DRI_2D_CONTEXT && - newContextType == DRI_2D_CONTEXT) - { - MGASwapContext_shared(pScreen); + if ( pMGADRIServer->agp.handle ) { + drmAgpUnbind( pMga->drmFD, pMGADRIServer->agp.handle ); + drmAgpFree( pMga->drmFD, pMGADRIServer->agp.handle ); + pMGADRIServer->agp.handle = 0; + drmAgpRelease( pMga->drmFD ); } -} -void -MGASelectBuffer(ScrnInfoPtr pScrn, int which) -{ - MGAPtr pMga = MGAPTR(pScrn); - MGADRIPtr pMGADRI = (MGADRIPtr)pMga->pDRIInfo->devPrivate; + DRICloseScreen( pScreen ); - switch (which) { - case MGA_BACK: - OUTREG(MGAREG_DSTORG, pMGADRI->backOffset); - OUTREG(MGAREG_SRCORG, pMGADRI->backOffset); - break; - case MGA_DEPTH: - OUTREG(MGAREG_DSTORG, pMGADRI->depthOffset); - OUTREG(MGAREG_SRCORG, pMGADRI->depthOffset); - break; - default: - case MGA_FRONT: - OUTREG(MGAREG_DSTORG, pMGADRI->frontOffset); - OUTREG(MGAREG_SRCORG, pMGADRI->frontOffset); - break; + if ( pMga->pDRIInfo ) { + if ( pMga->pDRIInfo->devPrivate ) { + xfree( pMga->pDRIInfo->devPrivate ); + pMga->pDRIInfo->devPrivate = 0; + } + DRIDestroyInfoRec( pMga->pDRIInfo ); + pMga->pDRIInfo = 0; + } + if ( pMga->DRIServerInfo ) { + xfree( pMga->DRIServerInfo ); + pMga->DRIServerInfo = 0; + } + if ( pMga->pVisualConfigs ) { + xfree( pMga->pVisualConfigs ); + } + if ( pMga->pVisualConfigsPriv ) { + xfree( pMga->pVisualConfigsPriv ); } } diff --git a/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c b/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c index 5797babf1..a7eb5511b 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c @@ -42,7 +42,7 @@ * doug@netcom.com * Fixed 32bpp hires 8MB horizontal line glitch at middle right */ - + /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c,v 1.189 2001/02/15 18:16:18 eich Exp $ */ /* @@ -92,7 +92,7 @@ #include "shadowfb.h" #include "fbdevhw.h" -#ifdef XF86DRI +#ifdef XF86DRI #include "dri.h" #endif @@ -140,7 +140,7 @@ static void MGAG100BlackMagic(MGAPtr pMga); static int MGAEntityIndex = -1; -/* +/* * This contains the functions needed by the server after loading the * driver module. It must be supplied, and gets added the driver list by * the Module Setup funtion in the dynamic case. In the static case a @@ -202,19 +202,18 @@ typedef enum { OPTION_VIDEO_KEY, OPTION_ROTATE, OPTION_TEXTURED_VIDEO, - OPTION_XAALINES, OPTION_CRTC2HALF, OPTION_CRTC2RAM, OPTION_INT10, - OPTION_AGP_MODE_2X, - OPTION_AGP_MODE_4X, + OPTION_AGP_MODE, OPTION_DIGITAL, OPTION_TV, OPTION_TVSTANDARD, OPTION_CABLETYPE, OPTION_USEIRQZERO, OPTION_NOHAL, - OPTION_SWAPPED_HEAD + OPTION_SWAPPED_HEAD, + OPTION_DRI } MGAOpts; static OptionInfoRec MGAOptions[] = { @@ -234,19 +233,17 @@ static OptionInfoRec MGAOptions[] = { { OPTION_VIDEO_KEY, "VideoKey", OPTV_INTEGER, {0}, FALSE }, { OPTION_ROTATE, "Rotate", OPTV_ANYSTR, {0}, FALSE }, { OPTION_TEXTURED_VIDEO, "TexturedVideo",OPTV_BOOLEAN, {0}, FALSE }, - { OPTION_XAALINES, "XAALines", OPTV_INTEGER, {0}, FALSE }, { OPTION_CRTC2HALF, "Crtc2Half", OPTV_BOOLEAN, {0}, FALSE }, { OPTION_CRTC2RAM, "Crtc2Ram", OPTV_INTEGER, {0}, FALSE }, { OPTION_INT10, "Int10", OPTV_BOOLEAN, {0}, FALSE }, - { OPTION_AGP_MODE_2X, "AGPMode2x", OPTV_BOOLEAN, {0}, FALSE }, - { OPTION_AGP_MODE_4X, "AGPMode4x", OPTV_BOOLEAN, {0}, FALSE }, + { OPTION_AGP_MODE, "AGPMode", OPTV_INTEGER, {0}, FALSE }, { OPTION_DIGITAL, "DigitalScreen",OPTV_BOOLEAN, {0}, FALSE }, { OPTION_TV, "TV", OPTV_BOOLEAN, {0}, FALSE }, { OPTION_TVSTANDARD, "TVStandard", OPTV_ANYSTR, {0}, FALSE }, { OPTION_CABLETYPE, "CableType", OPTV_ANYSTR, {0}, FALSE }, - { OPTION_USEIRQZERO, "UseIrqZero", OPTV_BOOLEAN, {0}, FALSE }, { OPTION_NOHAL, "NoHal", OPTV_BOOLEAN, {0}, FALSE }, - { OPTION_SWAPPED_HEAD, "SwappedHead", OPTV_BOOLEAN, {0}, FALSE }, + { OPTION_SWAPPED_HEAD, "SwappedHead", OPTV_BOOLEAN, {0}, FALSE }, + { OPTION_DRI, "DRI", OPTV_BOOLEAN, {0}, FALSE }, { -1, NULL, OPTV_NONE, {0}, FALSE } }; @@ -311,27 +308,35 @@ static const char *ramdacSymbols[] = { NULL }; -#ifdef XF86DRI +#ifdef XF86DRI static const char *drmSymbols[] = { "drmAvailable", "drmAddBufs", "drmAddMap", "drmCtlInstHandler", "drmGetInterruptFromBusID", + "drmFreeVersion", + "drmGetVersion", + "drmMap", + "drmUnmap", + "drmMapBufs", + "drmUnmapBufs", "drmAgpAcquire", "drmAgpRelease", "drmAgpEnable", "drmAgpAlloc", "drmAgpFree", "drmAgpBind", + "drmAgpUnbind", "drmAgpGetMode", "drmAgpBase", "drmAgpSize", - "drmMgaCleanupDma", - "drmMgaLockUpdate", - "drmMgaInitDma", - "drmFreeVersion", - "drmGetVersion", + "drmAgpVendorId", + "drmAgpDeviceId", + "drmMGAInitDMA", + "drmMGACleanupDMA", + "drmMGAFlushDMA", + "drmMGAEngineReset", NULL }; @@ -415,7 +420,7 @@ static const char *fbdevHWSymbols[] = { "fbdevHWUnmapVidmem", "fbdevHWMapMMIO", "fbdevHWMapVidmem", - + NULL }; @@ -431,7 +436,7 @@ static const char *halSymbols[] = { "MGAGetBOARDHANDLESize", "MGAGetHardwareInfo", "MGAOpenLibrary", - NULL + NULL }; #endif #ifdef XFree86LOADER @@ -479,7 +484,7 @@ mgaSetup(pointer module, pointer opts, int *errmaj, int *errmin) ddcSymbols, i2cSymbols, shadowSymbols, fbdevHWSymbols, vbeSymbols, fbSymbols, int10Symbols, -#ifdef XF86DRI +#ifdef XF86DRI drmSymbols, driSymbols, #endif #ifdef USEMGAHAL @@ -501,14 +506,14 @@ mgaSetup(pointer module, pointer opts, int *errmaj, int *errmin) #endif /* XFree86LOADER */ -/* +/* * ramdac info structure initialization */ static MGARamdacRec DacInit = { FALSE, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 90000, /* maxPixelClock */ 0, X_DEFAULT, X_DEFAULT, FALSE -}; +}; static Bool MGAGetRec(ScrnInfoPtr pScrn) @@ -625,14 +630,14 @@ MGAProbe(DriverPtr drv, int flags) #ifdef DISABLE_VGA_IO MgaSavePtr smga; #endif - + /* Allocate a ScrnInfoRec and claim the slot */ pScrn = NULL; - + #ifndef DISABLE_VGA_IO if ((pScrn = xf86ConfigPciEntity(pScrn, 0,usedChips[i], MGAPciChipsets, NULL, NULL, - NULL, NULL, NULL))) + NULL, NULL, NULL))) #else smga = xnfalloc(sizeof(MgaSave)); smga->pvp = xf86GetPciInfoForEntity(usedChips[i]); @@ -641,7 +646,7 @@ MGAProbe(DriverPtr drv, int flags) VgaIOSave, VgaIORestore,smga))) #endif { - + /* Fill in what we can of the ScrnInfoRec */ pScrn->driverVersion = MGA_VERSION; pScrn->driverName = MGA_DRIVER_NAME; @@ -657,7 +662,7 @@ MGAProbe(DriverPtr drv, int flags) pScrn->ValidMode = MGAValidMode; foundScreen = TRUE; } - + /* * For cards that can do dual head per entity, mark the entity * as sharable. @@ -691,7 +696,7 @@ MGAProbe(DriverPtr drv, int flags) } xfree(usedChips); - + return foundScreen; } @@ -716,13 +721,13 @@ MGAProbe(DriverPtr drv, int flags) * HISTORY * August 31, 1997 - [ajv] Andrew van der Stock * Fixed to understand Mystique and Millennium II - * + * * January 11, 1997 - [aem] Andrew E. Mileski * Set default values for GCLK (= MCLK / pre-scale ). * * October 7, 1996 - [aem] Andrew E. Mileski * Written and tested. - */ + */ static void MGAReadBios(ScrnInfoPtr pScrn) @@ -730,12 +735,12 @@ MGAReadBios(ScrnInfoPtr pScrn) CARD8 tmp[ 64 ]; CARD16 offset; CARD8 chksum; - CARD8 *pPINSInfo; + CARD8 *pPINSInfo; MGAPtr pMga; MGABiosInfo *pBios; MGABios2Info *pBios2; Bool pciBIOS = TRUE; - + pMga = MGAPTR(pScrn); pBios = &pMga->Bios; pBios2 = &pMga->Bios2; @@ -754,7 +759,7 @@ MGAReadBios(ScrnInfoPtr pScrn) (pciBIOS ? \ xf86ReadPciBIOS(offset, pMga->PciTag, pMga->FbBaseReg, buf, len) : \ xf86ReadBIOS(pMga->BiosAddress, offset, buf, len)) - + MGADoBIOSRead(0, tmp, sizeof( tmp )); if ( tmp[ 0 ] != 0x55 @@ -786,9 +791,9 @@ MGAReadBios(ScrnInfoPtr pScrn) ( CARD8 * ) & pBios2->PinID, sizeof( MGABios2Info )); } - + /* matrox millennium-2 and mystique pins info */ - if ( pBios2->PinID == 0x412e ) { + if ( pBios2->PinID == 0x412e ) { int i; /* check that the pins info is correct */ if ( pBios2->StructLen != 0x40 ) { @@ -879,8 +884,8 @@ MGASoftReset(ScrnInfoPtr pScrn) /* wait until drawing engine is ready */ while ( MGAISBUSY() ) usleep(1000); - - /* flush FIFO */ + + /* flush FIFO */ i = 32; WAITFIFO(i); while ( i-- ) @@ -893,7 +898,7 @@ MGASoftReset(ScrnInfoPtr pScrn) /* * MGACountRAM -- * - * Counts amount of installed RAM + * Counts amount of installed RAM */ static int MGACountRam(ScrnInfoPtr pScrn) @@ -906,7 +911,7 @@ MGACountRam(ScrnInfoPtr pScrn) #if 0 /* This isn't correct. It looks like this can have arbitrary data for the memconfig even when the bios has initialized - it. At least, my cards don't advertise the documented + it. At least, my cards don't advertise the documented values (my 8 and 16 Meg G200s have the same values) */ if(pMga->Primary) /* can only trust this for primary cards */ biosInfo = pciReadLong(pMga->PciTag, PCI_OPTION_REG); @@ -915,7 +920,7 @@ MGACountRam(ScrnInfoPtr pScrn) switch(pMga->Chipset) { case PCI_CHIP_MGA2164: case PCI_CHIP_MGA2164_AGP: - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Unable to probe memory amount due to hardware bug. " "Assuming 4096 KB\n"); return 4096; @@ -925,12 +930,12 @@ MGACountRam(ScrnInfoPtr pScrn) case 0: return (biosInfo & (1 << 14)) ? 32768 : 16384; case 1: - case 2: + case 2: return 16384; - case 3: - case 5: + case 3: + case 5: return 65536; - case 4: + case 4: return 32768; } } @@ -964,11 +969,11 @@ MGACountRam(ScrnInfoPtr pScrn) volatile unsigned char* base; unsigned char tmp; int i; - + pMga->FbMapSize = ProbeSize * 1024; MGAMapMem(pScrn); base = pMga->FbBase; - + /* turn MGA mode on - enable linear frame buffer (CRTCEXT3) */ OUTREG8(0x1FDE, 3); tmp = INREG8(0x1FDF); @@ -984,7 +989,7 @@ MGACountRam(ScrnInfoPtr pScrn) break; } } - + /* restore CRTCEXT3 state */ OUTREG8(0x1FDE, 3); OUTREG8(0x1FDF, tmp); @@ -1026,7 +1031,7 @@ MGAdoDDC(ScrnInfoPtr pScrn) xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "DDC1 disabled - chip not in VGA mode\n"); } - } + } /* Save the current state */ MGASave(pScrn); @@ -1080,7 +1085,7 @@ VgaIOSave(int i, void *arg) #ifdef DEBUG ErrorF("mga: VgaIOSave: %d:%d:%d\n", sMga->pvp->bus, sMga->pvp->device, - sMga->pvp->func); + sMga->pvp->func); #endif sMga->enable = (pciReadLong(tag, PCI_OPTION_REG) & 0x100) != 0; } @@ -1166,7 +1171,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) * not at the start of each server generation. This means that * only things that are persistent across server generations can * be initialised here. xf86Screens[] is (pScrn is a pointer to one - * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex() + * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex() * are too, and should be used for data that must persist across * server generations. * @@ -1186,7 +1191,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga = MGAPTR(pScrn); /* Set here until dri is enabled */ #ifdef XF86DRI - pMga->have_quiescense = 1; + pMga->haveQuiescense = 1; #endif /* Get the entity, and make sure it is PCI. */ pMga->pEnt = xf86GetEntityInfo(pScrn->entityList[0]); @@ -1256,7 +1261,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) xf86SetAccessFuncs(pMga->pEnt, &pMga->Access, &pMga->Access, &pMga->Access, NULL); #endif - + /* Set pScrn->monitor */ pScrn->monitor = pScrn->confScreen->monitor; @@ -1267,7 +1272,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) * unexpected behaviour when the config file marks the primary CRTC * as the second screen. */ - if(xf86IsEntityShared(pScrn->entityList[0]) && + if(xf86IsEntityShared(pScrn->entityList[0]) && xf86IsPrimInitDone(pScrn->entityList[0])) { /* This is the second crtc */ pMga->SecondCrtc = TRUE; @@ -1275,7 +1280,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pScrn->AdjustFrame = MGAAdjustFrameCrtc2; pMgaEnt->pScrn_2 = pScrn; #ifdef XF86DRI - pMga->GetQuiescence = mgaGetQuiescence_shared; + pMga->GetQuiescence = MGAGetQuiescenceShared; #endif } else { pMga->SecondCrtc = FALSE; @@ -1283,11 +1288,11 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) if (xf86IsEntityShared(pScrn->entityList[0])) { pMgaEnt->pScrn_1 = pScrn; #ifdef XF86DRI - pMga->GetQuiescence = mgaGetQuiescence_shared; + pMga->GetQuiescence = MGAGetQuiescenceShared; #endif } else { #ifdef XF86DRI - pMga->GetQuiescence = mgaGetQuiescence; + pMga->GetQuiescence = MGAGetQuiescence; #endif } } @@ -1315,13 +1320,17 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) * We support both 24bpp and 32bpp layouts, so indicate that. */ - /* Prefer 24bpp fb unless the Overlay option is set */ + /* Prefer 24bpp fb unless the Overlay option is set, or DRI is + * supported. + */ flags24 = Support24bppFb | Support32bppFb | SupportConvert32to24; s = xf86TokenToOptName(MGAOptions, OPTION_OVERLAY); +#ifndef XF86DRI if (!(xf86FindOption(pScrn->confScreen->options, s) || xf86FindOption(pMga->device->options, s))) { flags24 |= PreferConvert32to24; } +#endif if (pMga->SecondCrtc) flags24 = Support32bppFb; @@ -1385,7 +1394,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) } /* Set the bits per RGB for 8bpp mode */ - if (pScrn->depth == 8) + if (pScrn->depth == 8) pScrn->rgbBits = 8; /* @@ -1444,60 +1453,23 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n", pScrn->chipset); - - if(xf86GetOptValInteger(MGAOptions, OPTION_XAALINES, - &(pMga->numXAALines))) { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Will Use %d lines for " - "offscreen memory if the DRI is enabled.\n", - pMga->numXAALines); - } else { - /* The default is to use 512 lines on a G400, 128 on a G200 */ - switch (pMga->Chipset) { - case PCI_CHIP_MGAG200: - case PCI_CHIP_MGAG200_PCI: - pMga->numXAALines = 128; - break; - default: - pMga->numXAALines = 512; - break; - } - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Offscreen memory usage " - "will be limited to %d lines if the DRI is enabled.\n", - pMga->numXAALines); - } - #ifdef XF86DRI - { - Bool temp; - - from = X_DEFAULT; - - pMga->agp_mode = 1; - if (xf86GetOptValBool(MGAOptions, OPTION_AGP_MODE_2X, - &temp)) { - pMga->agp_mode = 2; - from = X_CONFIG; - } - - if (xf86GetOptValBool(MGAOptions, OPTION_AGP_MODE_4X, - &temp)) { - pMga->agp_mode = 4; - from = X_CONFIG; - } - xf86DrvMsg(pScrn->scrnIndex, from, "Using AGP Mode %dx\n", - pMga->agp_mode); - - pMga->ReallyUseIrqZero = 0; - - if (xf86GetOptValBool(MGAOptions, OPTION_USEIRQZERO, - &temp)) { - pMga->ReallyUseIrqZero = 1; - from = X_CONFIG; - xf86DrvMsg(pScrn->scrnIndex, from, "Enabling use of IRQ " - "Zero (Dangerous)\n"); - } + from = X_DEFAULT; + pMga->agpMode = MGA_DEFAULT_AGP_MODE; + if (xf86GetOptValInteger(MGAOptions, + OPTION_AGP_MODE, &(pMga->agpMode))) { + if (pMga->agpMode < 1) { + pMga->agpMode = 1; + } + if (pMga->agpMode > MGA_MAX_AGP_MODE) { + pMga->agpMode = MGA_MAX_AGP_MODE; + } + from = X_CONFIG; } + + xf86DrvMsg(pScrn->scrnIndex, from, "Using AGP %dx mode\n", + pMga->agpMode); #endif from = X_DEFAULT; @@ -1552,38 +1524,38 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) if(!xf86GetOptValInteger( MGAOptions, OPTION_COLOR_KEY,&(pMga->colorKey))) pMga->colorKey = TRANSPARENCY_KEY; - pScrn->colorKey = pMga->colorKey; + pScrn->colorKey = pMga->colorKey; pScrn->overlayFlags = OVERLAY_8_32_PLANAR; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "PseudoColor overlay enabled\n"); } else { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Option \"Overlay\" is only supported in 32 bits per pixel on" "the first CRTC\n"); } } else { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "\"%s\" is not a valid value for Option \"Overlay\"\n", s); } } - + if(xf86GetOptValInteger(MGAOptions, OPTION_VIDEO_KEY, &(pMga->videoKey))) { xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n", pMga->videoKey); } else { - pMga->videoKey = (1 << pScrn->offset.red) | + pMga->videoKey = (1 << pScrn->offset.red) | (1 << pScrn->offset.green) | - (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue); + (((pScrn->mask.blue >> pScrn->offset.blue) - 1) << pScrn->offset.blue); } if (xf86ReturnOptValBool(MGAOptions, OPTION_SHADOW_FB, FALSE)) { pMga->ShadowFB = TRUE; pMga->NoAccel = TRUE; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using \"Shadow Framebuffer\" - acceleration disabled\n"); } if (xf86ReturnOptValBool(MGAOptions, OPTION_FBDEV, FALSE)) { pMga->FBDev = TRUE; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using framebuffer device\n"); } if (xf86ReturnOptValBool(MGAOptions, OPTION_OVERCLOCK_MEM, FALSE)) { @@ -1613,7 +1585,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga->NoAccel = TRUE; pMga->HWCursor = FALSE; pMga->Rotate = 1; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rotating screen clockwise - acceleration disabled\n"); } else if(!xf86NameCmp(s, "CCW")) { @@ -1621,12 +1593,12 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga->NoAccel = TRUE; pMga->HWCursor = FALSE; pMga->Rotate = -1; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rotating screen counter clockwise - acceleration disabled\n"); } else { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "\"%s\" is not a valid value for Option \"Rotate\"\n", s); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Valid options are \"CW\" or \"CCW\"\n"); } } @@ -1712,15 +1684,15 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) xf86DrvMsg(pScrn->scrnIndex, from, "MMIO registers at 0x%lX\n", (unsigned long)pMga->IOAddress); - + pMga->ILOADAddress = 0; if ( pMga->Chipset != PCI_CHIP_MGA2064 ) { if (pMga->PciInfo->memBase[2] != 0) { pMga->ILOADAddress = pMga->PciInfo->memBase[2] & 0xffffc000; - xf86DrvMsg(pScrn->scrnIndex, X_PROBED, + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Pseudo-DMA transfer window at 0x%lX\n", (unsigned long)pMga->ILOADAddress); - } + } } @@ -1762,7 +1734,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) MGAReadBios(pScrn); - xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, + xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "MGABios.RamdacType = 0x%x\n", pMga->Bios.RamdacType); /* HW bpp matches reported bpp */ @@ -1794,15 +1766,15 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) if(pMga->SecondCrtc == FALSE) { Bool UseHalf = FALSE; int adjust; - + xf86GetOptValBool(MGAOptions, OPTION_CRTC2HALF, &UseHalf); adjust = pScrn->videoRam / 2; if (UseHalf == TRUE || xf86GetOptValInteger(MGAOptions, OPTION_CRTC2RAM, &adjust)) { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Crtc2 will use %dK of VideoRam\n", adjust); - } else { + } else { adjust = min(adjust, 8192); xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Crtc2 will use %dK of VideoRam\n", @@ -1812,9 +1784,9 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pScrn->videoRam = pMgaEnt->mastervideoRam; pMgaEnt->slavevideoRam = adjust; pMgaEnt->masterFbAddress = pMga->FbAddress; - pMga->FbMapSize = + pMga->FbMapSize = pMgaEnt->masterFbMapSize = pScrn->videoRam * 1024; - pMgaEnt->slaveFbAddress = pMga->FbAddress + + pMgaEnt->slaveFbAddress = pMga->FbAddress + pMgaEnt->masterFbMapSize; pMgaEnt->slaveFbMapSize = pMgaEnt->slavevideoRam * 1024; pMga->realSrcOrg = pMga->SrcOrg = 0; @@ -1823,8 +1795,8 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga->FbAddress = pMgaEnt->slaveFbAddress; pMga->FbMapSize = pMgaEnt->slaveFbMapSize; pScrn->videoRam = pMgaEnt->slavevideoRam; - pMga->DstOrg = pMga->realSrcOrg = - pMgaEnt->slaveFbAddress - pMgaEnt->masterFbAddress; + pMga->DstOrg = pMga->realSrcOrg = + pMgaEnt->slaveFbAddress - pMgaEnt->masterFbAddress; pMga->SrcOrg = 0; /* This is not stored in hw format!! */ } pMgaEnt->refCount++; @@ -1844,7 +1816,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) } xf86DrvMsg(pScrn->scrnIndex, from, "VideoRAM: %d kByte\n", pScrn->videoRam); - + /* Set the bpp shift value */ pMga->BppShifts[0] = 0; pMga->BppShifts[1] = 1; @@ -1870,7 +1842,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga->i2cInit = NULL; } } -#if MGAuseI2C +#if MGAuseI2C /* - DDC can use I2C bus */ /* Load I2C if we have the code to use it */ if (pMga->i2cInit) { @@ -1968,7 +1940,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) clockRanges->ClockMulFactor = 1; clockRanges->ClockDivFactor = 1; - + /* Only set MemClk if appropriate for the ramdac */ if (pMga->Dac.SetMemClk) { if (pMga->MemClk == 0) { @@ -1987,15 +1959,15 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) * care of this, we don't worry about setting them here. */ { - int Pitches1[] = + int Pitches1[] = {640, 768, 800, 960, 1024, 1152, 1280, 1600, 1920, 2048, 0}; - int Pitches2[] = - {512, 640, 768, 800, 832, 960, 1024, 1152, 1280, 1600, 1664, + int Pitches2[] = + {512, 640, 768, 800, 832, 960, 1024, 1152, 1280, 1600, 1664, 1920, 2048, 0}; int *linePitches = NULL; int minPitch = 256; - int maxPitch = 2048; - + int maxPitch = 2048; + switch(pMga->Chipset) { case PCI_CHIP_MGA2064: if (!pMga->NoAccel) { @@ -2027,7 +1999,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) i = xf86ValidateModes(pScrn, pScrn->monitor->Modes, pScrn->display->modes, clockRanges, linePitches, minPitch, maxPitch, - pMga->Roundings[(pScrn->bitsPerPixel >> 3) - 1] * + pMga->Roundings[(pScrn->bitsPerPixel >> 3) - 1] * pScrn->bitsPerPixel, 128, 2048, pScrn->display->virtualX, pScrn->display->virtualY, @@ -2060,7 +2032,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) } #ifdef USEMGAHAL MGA_HAL( - swap_head + swap_head = xf86ReturnOptValBool(MGAOptions, OPTION_SWAPPED_HEAD, FALSE); if(pMga->SecondCrtc == FALSE) { @@ -2068,9 +2040,9 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga->pClientStruct = (LPCLIENTDATA) xalloc (sizeof(CLIENTDATA)); pMga->pClientStruct->pMga = (MGAPtr) pMga; - MGAMapMem(pScrn); + MGAMapMem(pScrn); MGAOpenLibrary(pMga->pBoard,pMga->pClientStruct,sizeof(CLIENTDATA)); - MGAUnmapMem(pScrn); + MGAUnmapMem(pScrn); pMga->pMgaHwInfo = (LPMGAHWINFO) xalloc (sizeof(MGAHWINFO)); MGAGetHardwareInfo(pMga->pBoard,pMga->pMgaHwInfo); @@ -2079,18 +2051,18 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMgaEnt->pClientStruct = pMga->pClientStruct; pMgaEnt->pBoard = pMga->pBoard; pMgaEnt->pMgaHwInfo = pMga->pMgaHwInfo; - } + } if (!swap_head) { mgaModeInfo.flOutput = MGAMODEINFO_ANALOG1; } else { - mgaModeInfo.flOutput = MGAMODEINFO_ANALOG2; + mgaModeInfo.flOutput = MGAMODEINFO_ANALOG2; } mgaModeInfo.ulDispWidth = pScrn->virtualX; mgaModeInfo.ulDispHeight = pScrn->virtualY; mgaModeInfo.ulDeskWidth = pScrn->virtualX; mgaModeInfo.ulDeskHeight = pScrn->virtualY; - mgaModeInfo.ulBpp = pScrn->bitsPerPixel; + mgaModeInfo.ulBpp = pScrn->bitsPerPixel; mgaModeInfo.ulZoom = 1; } else { /* Second CRTC && entity is shared */ if (digital == TRUE) { @@ -2112,7 +2084,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) mgaModeInfo.ulDispHeight = pScrn->virtualY; mgaModeInfo.ulDeskWidth = pScrn->virtualX; mgaModeInfo.ulDeskHeight = pScrn->virtualY; - mgaModeInfo.ulBpp = pScrn->bitsPerPixel; + mgaModeInfo.ulBpp = pScrn->bitsPerPixel; mgaModeInfo.ulZoom = 1; pMga->pBoard = pMgaEnt->pBoard; pMga->pClientStruct = pMgaEnt->pClientStruct; @@ -2134,15 +2106,15 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) (pMga->PciInfo->subsysCard == PCI_CARD_PROD_G100_SD)) { pMga->HasSDRAM = TRUE; xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Has SDRAM\n"); - } - /* - * Can we trust HALlib to set the memory configuration + } + /* + * Can we trust HALlib to set the memory configuration * registers correctly? */ - else if ((pMga->softbooted || pMga->Primary /*|| pMga->HALLoaded*/ ) && - (pMga->Chipset != PCI_CHIP_MGA2064) && + else if ((pMga->softbooted || pMga->Primary /*|| pMga->HALLoaded*/ ) && + (pMga->Chipset != PCI_CHIP_MGA2064) && (pMga->Chipset != PCI_CHIP_MGA2164) && - (pMga->Chipset != PCI_CHIP_MGA2164_AGP)) { + (pMga->Chipset != PCI_CHIP_MGA2164_AGP)) { CARD32 option_reg = pciReadLong(pMga->PciTag, PCI_OPTION_REG); if(!(option_reg & (1 << 14))) { pMga->HasSDRAM = TRUE; @@ -2182,10 +2154,10 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) */ pMga->YDstOrg = 0; - if (((pMga->Chipset == PCI_CHIP_MGA2064) || + if (((pMga->Chipset == PCI_CHIP_MGA2064) || (pMga->Chipset == PCI_CHIP_MGA2164) || (pMga->Chipset == PCI_CHIP_MGA2164_AGP)) && - (pScrn->virtualX * pScrn->virtualY * bytesPerPixel > 4*1024*1024)) + (pScrn->virtualX * pScrn->virtualY * bytesPerPixel > 4*1024*1024)) { int offset, offset_modulo, ydstorg_modulo; @@ -2226,12 +2198,12 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga->FbUsableSize = pMgaEnt->masterFbMapSize; /* Allocate HW cursor buffer at the end of video ram */ if( pMga->HWCursor && pMga->Dac.CursorOffscreenMemSize ) { - if( pScrn->virtualY * pScrn->displayWidth * + if( pScrn->virtualY * pScrn->displayWidth * pScrn->bitsPerPixel / 8 <= pMga->FbUsableSize - pMga->Dac.CursorOffscreenMemSize ) { pMga->FbUsableSize -= pMga->Dac.CursorOffscreenMemSize; pMga->FbCursorOffset = - pMgaEnt->masterFbMapSize - + pMgaEnt->masterFbMapSize - pMga->Dac.CursorOffscreenMemSize; } else { pMga->HWCursor = FALSE; @@ -2248,7 +2220,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) pMga->FbUsableSize = pMga->FbMapSize - pMga->YDstOrg * bytesPerPixel; /* Allocate HW cursor buffer at the end of video ram */ if( pMga->HWCursor && pMga->Dac.CursorOffscreenMemSize ) { - if( pScrn->virtualY * pScrn->displayWidth * + if( pScrn->virtualY * pScrn->displayWidth * pScrn->bitsPerPixel / 8 <= pMga->FbUsableSize - pMga->Dac.CursorOffscreenMemSize ) { pMga->FbUsableSize -= pMga->Dac.CursorOffscreenMemSize; @@ -2333,7 +2305,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) if(pMgaEnt->refCount == 2) { /* Both boards have done there initialization */ MGACloseLibrary(pMga->pBoard); - + if (pMga->pBoard) xfree(pMga->pBoard); if (pMga->pClientStruct) @@ -2346,7 +2318,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags) } } else { MGACloseLibrary(pMga->pBoard); - + if (pMga->pBoard) xfree(pMga->pBoard); if (pMga->pClientStruct) @@ -2377,7 +2349,7 @@ MGAMapMem(ScrnInfoPtr pScrn) /* * Map IO registers to virtual address space - */ + */ /* * For Alpha, we need to map SPARSE memory, since we need * byte/short access. This is taken care of automatically by the @@ -2411,7 +2383,7 @@ MGAMapMem(ScrnInfoPtr pScrn) if (pMga->ILOADAddress) { pMga->ILOADBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO | VIDMEM_MMIO_32BIT | - VIDMEM_READSIDEEFFECT, + VIDMEM_READSIDEEFFECT, pMga->PciTag, pMga->ILOADAddress, 0x800000); } else pMga->ILOADBase = NULL; @@ -2441,7 +2413,7 @@ MGAMapMemFBDev(ScrnInfoPtr pScrn) /* Map the ILOAD transfer window if there is one. We only make DWORD access on DWORD boundaries to this window */ if(pMga->ILOADAddress) - pMga->ILOADBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO, + pMga->ILOADBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO, pMga->PciTag, pMga->ILOADAddress, 0x800000); else pMga->ILOADBase = NULL; #endif @@ -2463,7 +2435,7 @@ MGAUnmapMem(ScrnInfoPtr pScrn) /* * Unmap IO registers to virtual address space - */ + */ xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pMga->IOBase, 0x4000); pMga->IOBase = NULL; @@ -2529,7 +2501,7 @@ static void FillModeInfoStruct(ScrnInfoPtr pScrn, DisplayModePtr mode) pMga->pMgaModeInfo->ulDeskWidth = pScrn->virtualX; pMga->pMgaModeInfo->ulDeskHeight = pScrn->virtualY; pMga->pMgaModeInfo->ulFBPitch = 0; - pMga->pMgaModeInfo->ulBpp = pScrn->bitsPerPixel; + pMga->pMgaModeInfo->ulBpp = pScrn->bitsPerPixel; pMga->pMgaModeInfo->ulZoom = 1; pMga->pMgaModeInfo->flSignalMode = 0x10; @@ -2597,7 +2569,7 @@ MGAModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) Bool digital = FALSE; Bool tv = FALSE; ULONG status; - Bool swap_head + Bool swap_head = xf86ReturnOptValBool(MGAOptions, OPTION_SWAPPED_HEAD, FALSE); /* Verify if user wants digital screen output */ @@ -2714,7 +2686,7 @@ MGAModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) } pMga->CurrentLayout.mode = mode; - + #ifdef XF86DRI if (pMga->directRenderingEnabled) DRIUnlock(screenInfo.screens[pScrn->scrnIndex]); @@ -2726,7 +2698,7 @@ MGAModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) /* * Restore the initial (text) mode. */ -static void +static void MGARestore(ScrnInfoPtr pScrn) { vgaHWPtr hwp = VGAHWPTR(pScrn); @@ -2797,8 +2769,9 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) int width, height, displayWidth; MGAEntPtr pMgaEnt = NULL; int f; + MessageType driFrom = X_DEFAULT; - /* + /* * First get the ScrnInfoRec */ pScrn = xf86Screens[pScreen->myNum]; @@ -2806,7 +2779,7 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) hwp = VGAHWPTR(pScrn); pMga = MGAPTR(pScrn); MGAdac = &pMga->Dac; - + /* Map the MGA memory and MMIO areas */ if (pMga->FBDev) { if (!MGAMapMemFBDev(pScrn)) @@ -2816,8 +2789,8 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) return FALSE; } - if ((pMga->Chipset == PCI_CHIP_MGAG100) - || (pMga->Chipset == PCI_CHIP_MGAG100_PCI)) + if ((pMga->Chipset == PCI_CHIP_MGAG100) + || (pMga->Chipset == PCI_CHIP_MGAG100_PCI)) MGAG100BlackMagic(pMga); if (xf86IsEntityShared(pScrn->entityList[0])) { @@ -2871,7 +2844,7 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) #ifdef USEMGAHAL MGA_HAL( /* There is a problem in the HALlib: set soft reset bit */ - if (!pMga->Primary && !pMga->FBDev && + if (!pMga->Primary && !pMga->FBDev && (pMga->PciInfo->subsysCard == PCI_CARD_MILL_G200_SG) ) { OUTREG(MGAREG_Reset, 1); usleep(200); @@ -2992,15 +2965,42 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) * InitGLXVisuals call back. * The DRI does not work when textured video is enabled at this time. */ - - if (!pMga->NoAccel && pMga->TexturedVideo != TRUE && - pMga->SecondCrtc == FALSE) - pMga->directRenderingEnabled = MGADRIScreenInit(pScreen); - else + if (!xf86ReturnOptValBool(MGAOptions, OPTION_DRI, TRUE)) { + driFrom = X_CONFIG; + } else if ( pMga->NoAccel ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "Acceleration disabled, not initializing the DRI\n" ); + pMga->directRenderingEnabled = FALSE; + driFrom = X_CONFIG; + } + else if ( pMga->TexturedVideo == TRUE ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "Textured video enabled, not initializing the DRI\n" ); + pMga->directRenderingEnabled = FALSE; + driFrom = X_CONFIG; + } + else if ( pMga->SecondCrtc == TRUE ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "Not initializing the DRI on the second head\n" ); pMga->directRenderingEnabled = FALSE; + } + else if ( (pMga->FbMapSize / + (width * (pScrn->bitsPerPixel >> 3))) <= height * 3 ) { + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "Static buffer allocation failed, not initializing the DRI\n" ); + xf86DrvMsg( pScrn->scrnIndex, X_ERROR, + "Need at least %d kB video memory at this resolution, bit depth\n", + (3 * displayWidth * height * + (pScrn->bitsPerPixel >> 3)) / 1024 ); + pMga->directRenderingEnabled = FALSE; + driFrom = X_PROBED; + } + else { + pMga->directRenderingEnabled = MGADRIScreenInit(pScreen); + } #endif - - + + if (pMga->Overlay8Plus24) { ret = cfb8_32ScreenInit(pScreen, FBStart, width, height, @@ -3048,15 +3048,15 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) xf86SetBackingStore(pScreen); xf86SetSilkenMouse(pScreen); - /* Initialize software cursor. + /* Initialize software cursor. Must precede creation of the default colormap */ miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); - /* Initialize HW cursor layer. + /* Initialize HW cursor layer. Must follow software cursor initialization*/ - if (pMga->HWCursor) { + if (pMga->HWCursor) { if(!MGAHWCursorInit(pScreen)) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Hardware cursor initialization failed\n"); } @@ -3064,13 +3064,13 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (!miCreateDefColormap(pScreen)) return FALSE; - /* Initialize colormap layer. + /* Initialize colormap layer. Must follow initialization of the default colormap */ if (!pMga->SecondCrtc) f = CMAP_PALETTED_TRUECOLOR | CMAP_RELOAD_ON_MODE_SWITCH; else f = CMAP_RELOAD_ON_MODE_SWITCH; - if(!xf86HandleColormaps(pScreen, 256, 8, + if(!xf86HandleColormaps(pScreen, 256, 8, (pMga->FBDev ? fbdevHWLoadPalette : MGAdac->LoadPalette), NULL, f)) return FALSE; @@ -3087,7 +3087,7 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) pMga->PointerMoved = pScrn->PointerMoved; pScrn->PointerMoved = MGAPointerMoved; } - + switch(pScrn->bitsPerPixel) { case 8: refreshArea = MGARefreshArea8; break; case 16: refreshArea = MGARefreshArea16; break; @@ -3100,7 +3100,7 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) } xf86DPMSInit(pScreen, MGADisplayPowerManagementSet, 0); - + pScrn->memPhysBase = pMga->FbAddress; pScrn->fbOffset = pMga->YDstOrg * (pScrn->bitsPerPixel / 8); @@ -3112,26 +3112,22 @@ MGAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) MGAInitVideo(pScreen); #ifdef XF86DRI - /* Initialize the Warp engine */ if (pMga->directRenderingEnabled) { - pMga->directRenderingEnabled = mgaConfigureWarp(pScrn); - } - if (pMga->directRenderingEnabled) { - /* Now that mi, cfb, drm and others have done their thing, + /* Now that mi, cfb, drm and others have done their thing, * complete the DRI setup. */ pMga->directRenderingEnabled = MGADRIFinishScreenInit(pScreen); } if (pMga->directRenderingEnabled) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering enabled\n"); + xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering enabled\n"); } else { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering disabled\n"); + xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering disabled\n"); } if (xf86IsEntityShared(pScrn->entityList[0]) && pMga->SecondCrtc == FALSE) pMgaEnt->directRenderingEnabled = pMga->directRenderingEnabled; - pMga->have_quiescense = 1; + pMga->haveQuiescense = 1; #endif - + /* Wrap the current CloseScreen function */ pMga->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = MGACloseScreen; @@ -3164,7 +3160,7 @@ MGASwitchMode(int scrnIndex, DisplayModePtr mode, int flags) * displayed location in the video memory. */ /* Usually mandatory */ -void +void MGAAdjustFrame(int scrnIndex, int x, int y, int flags) { ScrnInfoPtr pScrn; @@ -3191,11 +3187,11 @@ MGAAdjustFrame(int scrnIndex, int x, int y, int flags) /* find start of retrace */ while (INREG8(0x1FDA) & 0x08); - while (!(INREG8(0x1FDA) & 0x08)); + while (!(INREG8(0x1FDA) & 0x08)); /* wait until we're past the start (fixseg.c in the DDK) */ count = INREG(MGAREG_VCOUNT) + 2; while(INREG(MGAREG_VCOUNT) < count); - + OUTREG16(MGAREG_CRTC_INDEX, (Base & 0x00FF00) | 0x0C); OUTREG16(MGAREG_CRTC_INDEX, ((Base & 0x0000FF) << 8) | 0x0D); OUTREG8(MGAREG_CRTCEXT_INDEX, 0x00); @@ -3225,7 +3221,7 @@ MGAAdjustFrameCrtc2(int scrnIndex, int x, int y, int flags) * 3-93 c2startadd0 * 3-96 c2vcount */ - + Base = (y * pLayout->displayWidth + x) * pLayout->bitsPerPixel >> 3; Base += pMga->DstOrg; Base &= 0x01ffffc0; @@ -3245,7 +3241,7 @@ MGAEnterVT(int scrnIndex, int flags) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; MGAPtr pMga; -#ifdef XF86DRI +#ifdef XF86DRI ScreenPtr pScreen; #endif @@ -3257,7 +3253,7 @@ MGAEnterVT(int scrnIndex, int flags) DRIUnlock(pScreen); } #endif - + if (!MGAModeInit(pScrn, pScrn->currentMode)) return FALSE; MGAAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); @@ -3274,12 +3270,12 @@ static Bool MGAEnterVTFBDev(int scrnIndex, int flags) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; -#ifdef XF86DRI +#ifdef XF86DRI ScreenPtr pScreen; - MGAPtr pMGA; + MGAPtr pMga; - pMGA = MGAPTR(pScrn); - if (pMGA->directRenderingEnabled) { + pMga = MGAPTR(pScrn); + if (pMga->directRenderingEnabled) { pScreen = screenInfo.screens[scrnIndex]; DRIUnlock(pScreen); } @@ -3305,7 +3301,7 @@ MGALeaveVT(int scrnIndex, int flags) vgaHWPtr hwp = VGAHWPTR(pScrn); #ifdef XF86DRI ScreenPtr pScreen; - MGAPtr pMGA; + MGAPtr pMga; #endif MGARestore(pScrn); @@ -3314,13 +3310,13 @@ MGALeaveVT(int scrnIndex, int flags) if (xf86IsPc98()) outb(0xfac, 0x00); #ifdef XF86DRI - pMGA = MGAPTR(pScrn); - if (pMGA->directRenderingEnabled) { + pMga = MGAPTR(pScrn); + if (pMga->directRenderingEnabled) { pScreen = screenInfo.screens[scrnIndex]; DRILock(pScreen, 0); } #endif - + } @@ -3339,7 +3335,7 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen) vgaHWPtr hwp = VGAHWPTR(pScrn); MGAPtr pMga = MGAPTR(pScrn); MGAEntPtr pMgaEnt = NULL; - + if (pScrn->vtSema) { if (pMga->FBDev) { fbdevHWRestore(pScrn); @@ -3351,7 +3347,7 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen) vgaHWUnmapMem(pScrn); } } -#ifdef XF86DRI +#ifdef XF86DRI if (pMga->directRenderingEnabled) { MGADRICloseScreen(pScreen); pMga->directRenderingEnabled=FALSE; @@ -3371,7 +3367,7 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen) if(pMgaEnt->refCount == 0) { /* Both boards have closed there screen */ MGACloseLibrary(pMga->pBoard); - + if (pMga->pBoard) xfree(pMga->pBoard); if (pMga->pClientStruct) @@ -3383,7 +3379,7 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen) } } else { MGACloseLibrary(pMga->pBoard); - + if (pMga->pBoard) xfree(pMga->pBoard); if (pMga->pClientStruct) @@ -3392,7 +3388,7 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen) xfree(pMga->pMgaModeInfo); if (pMga->pMgaHwInfo) xfree(pMga->pMgaHwInfo); - } + } ); /* MGA_HAL */ #endif @@ -3455,8 +3451,8 @@ MGAValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) lace = 1 + ((mode->Flags & V_INTERLACE) != 0); if ((mode->CrtcHDisplay <= 2048) && - (mode->CrtcHSyncStart <= 4096) && - (mode->CrtcHSyncEnd <= 4096) && + (mode->CrtcHSyncStart <= 4096) && + (mode->CrtcHSyncEnd <= 4096) && (mode->CrtcHTotal <= 4096) && (mode->CrtcVDisplay <= 2048 * lace) && (mode->CrtcVSyncStart <= 4096 * lace) && @@ -3492,24 +3488,24 @@ MGASaveScreenCrtc2(ScreenPtr pScreen, int mode) MGAPtr pMga = NULL; Bool on; CARD32 tmp; - + on = xf86IsUnblank(mode); - + if (on) SetTimeSinceLastInputEvent(); if (pScreen != NULL) pScrn = xf86Screens[pScreen->myNum]; - + if (pScrn != NULL) pMga = MGAPTR(pScrn); - + if(pMga != NULL && pScrn->vtSema) { tmp = INREG(MGAREG_C2CTL); tmp &= ~0x00000008; if (!on) tmp |= 0x0000008; OUTREG(MGAREG_C2CTL, tmp); } - + return TRUE; } @@ -3576,7 +3572,7 @@ MGABlockHandler ( ScrnInfoPtr pScrn = xf86Screens[i]; MGAPtr pMga = MGAPTR(pScrn); - if(pMga->PaletteLoadCallback) + if(pMga->PaletteLoadCallback) (*pMga->PaletteLoadCallback)(pScrn); pScreen->BlockHandler = pMga->BlockHandler; @@ -3588,7 +3584,7 @@ MGABlockHandler ( (*pMga->VideoTimerCallback)(pScrn, currentTime.milliseconds); } - if(pMga->RenderCallback) + if(pMga->RenderCallback) (*pMga->RenderCallback)(pScrn); } @@ -3679,7 +3675,7 @@ dbg_outreg32(ScrnInfoPtr pScrn,int addr,int val) MGAPtr pMga; CARD32 ret; - if (((addr & 0xff00) == 0x1c00) + if (((addr & 0xff00) == 0x1c00) && (addr != 0x1c04) /* && (addr != 0x1c1c) */ && (addr != 0x1c20) diff --git a/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c index b41d5061e..f88e72f4c 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/sis/sis_dri.c @@ -76,16 +76,16 @@ SISInitVisualConfigs(ScreenPtr pScreen) case 32: numConfigs = (useZ16)?8:16; - if (!(pConfigs = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), + if (!(pConfigs = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } - if (!(pSISConfigs = (SISConfigPrivPtr)xnfcalloc(sizeof(SISConfigPrivRec), + if (!(pSISConfigs = (SISConfigPrivPtr)xcalloc(sizeof(SISConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } - if (!(pSISConfigPtrs = (SISConfigPrivPtr*)xnfcalloc(sizeof(SISConfigPrivPtr), + if (!(pSISConfigPtrs = (SISConfigPrivPtr*)xcalloc(sizeof(SISConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pSISConfigs); @@ -194,9 +194,9 @@ Bool SISDRIScreenInit(ScreenPtr pScreen) { int major, minor, patch; DRIQueryVersion(&major, &minor, &patch); - if (major != 3 || minor != 1 || patch < 0) { + if (major != 4 || minor < 0) { xf86DrvMsg(pScreen->myNum, X_ERROR, - "[drm] SISDRIScreenInit failed (DRI version = %d.%d.%d, expected 3.1.x). Disabling DRI.\n", + "[drm] SISDRIScreenInit failed (DRI version = %d.%d.%d, expected 4.0.x). Disabling DRI.\n", major, minor, patch); return FALSE; } @@ -246,7 +246,7 @@ Bool SISDRIScreenInit(ScreenPtr pScreen) pDRIInfo->SAREASize = SAREA_MAX; #endif - if (!(pSISDRI = (SISDRIPtr)xnfcalloc(sizeof(SISDRIRec),1))) { + if (!(pSISDRI = (SISDRIPtr)xcalloc(sizeof(SISDRIRec),1))) { DRIDestroyInfoRec(pSIS->pDRIInfo); pSIS->pDRIInfo=0; return FALSE; @@ -262,6 +262,9 @@ Bool SISDRIScreenInit(ScreenPtr pScreen) pDRIInfo->MoveBuffers = SISDRIMoveBuffers; pDRIInfo->bufferRequests = DRI_ALL_WINDOWS; + pDRIInfo->createDummyCtx = TRUE; + pDRIInfo->createDummyCtxPriv = FALSE; + if (!DRIScreenInit(pScreen, pDRIInfo, &pSIS->drmSubFD)) { xfree(pDRIInfo->devPrivate); pDRIInfo->devPrivate=0; diff --git a/xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_dri.c index f866f1a2d..d596ad9df 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_dri.c @@ -80,19 +80,19 @@ FFBDRIInitVisualConfigs(ScreenPtr pScreen) FFBConfigPrivPtr *pFfbConfigPtrs; pConfigs = (__GLXvisualConfig *) - xnfcalloc(sizeof(__GLXvisualConfig), 1); + xcalloc(sizeof(__GLXvisualConfig), 1); if (!pConfigs) return FALSE; pFfbConfigs = (FFBConfigPrivPtr) - xnfcalloc(sizeof(FFBConfigPrivRec), 1); + xcalloc(sizeof(FFBConfigPrivRec), 1); if (!pFfbConfigs) { xfree(pConfigs); return FALSE; } pFfbConfigPtrs = (FFBConfigPrivPtr *) - xnfcalloc(sizeof(FFBConfigPrivPtr), 1); + xcalloc(sizeof(FFBConfigPrivPtr), 1); if (!pFfbConfigPtrs) { xfree(pConfigs); xfree(pFfbConfigs); @@ -254,7 +254,7 @@ FFBDRIScreenInit(ScreenPtr pScreen) pDRIInfo->maxDrawableTableEntry = 15; pDRIInfo->SAREASize = (SAREA_MAX + (0x2000 - 1)) & ~(0x2000 - 1); - pFfbDRI = (FFBDRIPtr) xnfcalloc(sizeof(FFBDRIRec), 1); + pFfbDRI = (FFBDRIPtr) xcalloc(sizeof(FFBDRIRec), 1); if (pFfbDRI == NULL) { DRIDestroyInfoRec(pFfb->pDRIInfo); return FALSE; @@ -273,6 +273,9 @@ FFBDRIScreenInit(ScreenPtr pScreen) /* Our InitBuffers depends heavily on this setting. */ pDRIInfo->bufferRequests = DRI_3D_WINDOWS_ONLY; + pDRIInfo->createDummyCtx = TRUE; + pDRIInfo->createDummyCtxPriv = FALSE; + if (!DRIScreenInit(pScreen, pDRIInfo, &(pFfb->drmSubFD))) { DRIDestroyInfoRec(pFfb->pDRIInfo); xfree(pFfbDRI); diff --git a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c index 171be47da..4b0cb6b44 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c @@ -16,20 +16,20 @@ static char TDFXKernelDriverName[] = "tdfx"; static char TDFXClientDriverName[] = "tdfx"; -static Bool TDFXCreateContext(ScreenPtr pScreen, VisualPtr visual, +static Bool TDFXCreateContext(ScreenPtr pScreen, VisualPtr visual, drmContext hwContext, void *pVisualConfigPriv, DRIContextType contextStore); static void TDFXDestroyContext(ScreenPtr pScreen, drmContext hwContext, DRIContextType contextStore); -static void TDFXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType, - DRIContextType readContextType, +static void TDFXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType, + DRIContextType readContextType, void *readContextStore, - DRIContextType writeContextType, + DRIContextType writeContextType, void *writeContextStore); static Bool TDFXDRIOpenFullScreen(ScreenPtr pScreen); static Bool TDFXDRICloseFullScreen(ScreenPtr pScreen); static void TDFXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index); -static void TDFXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, +static void TDFXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, RegionPtr prgnSrc, CARD32 index); static void TDFXDRITransitionTo2d(ScreenPtr pScreen); static void TDFXDRITransitionTo3d(ScreenPtr pScreen); @@ -50,22 +50,22 @@ TDFXInitVisualConfigs(ScreenPtr pScreen) case 16: numConfigs = 16; - if (!(pConfigs = (__GLXvisualConfig*)xnfcalloc(sizeof(__GLXvisualConfig), + if (!(pConfigs = (__GLXvisualConfig*)xcalloc(sizeof(__GLXvisualConfig), numConfigs))) { return FALSE; } - if (!(pTDFXConfigs = (TDFXConfigPrivPtr)xnfcalloc(sizeof(TDFXConfigPrivRec), + if (!(pTDFXConfigs = (TDFXConfigPrivPtr)xcalloc(sizeof(TDFXConfigPrivRec), numConfigs))) { xfree(pConfigs); return FALSE; } - if (!(pTDFXConfigPtrs = (TDFXConfigPrivPtr*)xnfcalloc(sizeof(TDFXConfigPrivPtr), + if (!(pTDFXConfigPtrs = (TDFXConfigPrivPtr*)xcalloc(sizeof(TDFXConfigPrivPtr), numConfigs))) { xfree(pConfigs); xfree(pTDFXConfigs); return FALSE; } - for (i=0; i<numConfigs; i++) + for (i=0; i<numConfigs; i++) pTDFXConfigPtrs[i] = &pTDFXConfigs[i]; i=0; @@ -104,7 +104,7 @@ TDFXInitVisualConfigs(ScreenPtr pScreen) if (depth) { if (pTDFX->cpp>2) pConfigs[i].depthSize = 24; - else + else pConfigs[i].depthSize = 16; } else { pConfigs[i].depthSize = 0; @@ -141,24 +141,24 @@ TDFXInitVisualConfigs(ScreenPtr pScreen) case 32: numConfigs = 8; - pConfigs = (__GLXvisualConfig*) xnfcalloc(sizeof(__GLXvisualConfig), numConfigs); + pConfigs = (__GLXvisualConfig*) xcalloc(sizeof(__GLXvisualConfig), numConfigs); if (!pConfigs) return FALSE; - pTDFXConfigs = (TDFXConfigPrivPtr) xnfcalloc(sizeof(TDFXConfigPrivRec), numConfigs); + pTDFXConfigs = (TDFXConfigPrivPtr) xcalloc(sizeof(TDFXConfigPrivRec), numConfigs); if (!pTDFXConfigs) { xfree(pConfigs); return FALSE; } - pTDFXConfigPtrs = (TDFXConfigPrivPtr *) xnfcalloc(sizeof(TDFXConfigPrivPtr), numConfigs); + pTDFXConfigPtrs = (TDFXConfigPrivPtr *) xcalloc(sizeof(TDFXConfigPrivPtr), numConfigs); if (!pTDFXConfigPtrs) { xfree(pConfigs); xfree(pTDFXConfigs); return FALSE; } - for (i = 0; i < numConfigs; i++) + for (i = 0; i < numConfigs; i++) pTDFXConfigPtrs[i] = &pTDFXConfigs[i]; i=0; @@ -199,7 +199,7 @@ TDFXInitVisualConfigs(ScreenPtr pScreen) if (depth) { if (pTDFX->cpp > 2) pConfigs[i].depthSize = 24; - else + else pConfigs[i].depthSize = 16; } else { pConfigs[i].depthSize = 0; @@ -249,7 +249,7 @@ TDFXDoWakeupHandler(int screenNum, pointer wakeupData, unsigned long result, TDFXNeedSync(pScrn); } -static void +static void TDFXDoBlockHandler(int screenNum, pointer blockData, pointer pTimeout, pointer pReadmask) { @@ -300,9 +300,9 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) { int major, minor, patch; DRIQueryVersion(&major, &minor, &patch); - if (major != 3 || minor != 1 || patch < 0) { + if (major != 4 || minor < 0) { xf86DrvMsg(pScreen->myNum, X_ERROR, - "TDFXDRIScreenInit failed (DRI version = %d.%d.%d, expected 3.1.x). Disabling DRI.\n", + "TDFXDRIScreenInit failed (DRI version = %d.%d.%d, expected 4.0.x). Disabling DRI.\n", major, minor, patch); return FALSE; } @@ -343,10 +343,10 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) pDRIInfo->maxDrawableTableEntry = TDFX_MAX_DRAWABLES; #ifdef NOT_DONE - /* FIXME need to extend DRI protocol to pass this size back to client + /* FIXME need to extend DRI protocol to pass this size back to client * for SAREA mapping that includes a device private record */ - pDRIInfo->SAREASize = + pDRIInfo->SAREASize = ((sizeof(XF86DRISAREARec) + 0xfff) & 0x1000); /* round to page */ /* + shared memory device private rec */ #else @@ -360,7 +360,7 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) pDRIInfo->SAREASize = SAREA_MAX; #endif - if (!(pTDFXDRI = (TDFXDRIPtr)xnfcalloc(sizeof(TDFXDRIRec),1))) { + if (!(pTDFXDRI = (TDFXDRIPtr)xcalloc(sizeof(TDFXDRIRec),1))) { xf86DrvMsg(pScreen->myNum, X_ERROR, "DRI memory allocation failed, disabling DRI.\n"); DRIDestroyInfoRec(pTDFX->pDRIInfo); pTDFX->pDRIInfo=0; @@ -381,6 +381,9 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) pDRIInfo->TransitionTo3d = TDFXDRITransitionTo3d; pDRIInfo->bufferRequests = DRI_ALL_WINDOWS; + pDRIInfo->createDummyCtx = FALSE; + pDRIInfo->createDummyCtxPriv = FALSE; + if (!DRIScreenInit(pScreen, pDRIInfo, &pTDFX->drmSubFD)) { xfree(pDRIInfo->devPrivate); pDRIInfo->devPrivate=0; @@ -396,8 +399,7 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) drmVersionPtr version = drmGetVersion(pTDFX->drmSubFD); if (version) { if (version->version_major != 1 || - version->version_minor != 0 || - version->version_patchlevel < 0) { + version->version_minor < 0) { /* incompatible drm version */ xf86DrvMsg(pScreen->myNum, X_ERROR, "TDFXDRIScreenInit failed (DRM version = %d.%d.%d, expected 1.0.x). Disabling DRI.\n", @@ -413,7 +415,7 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) } pTDFXDRI->regsSize=TDFXIOMAPSIZE; - if (drmAddMap(pTDFX->drmSubFD, (drmHandle)pTDFX->MMIOAddr[0], + if (drmAddMap(pTDFX->drmSubFD, (drmHandle)pTDFX->MMIOAddr[0], pTDFXDRI->regsSize, DRM_REGISTERS, 0, &pTDFXDRI->regs)<0) { TDFXDRICloseScreen(pScreen); xf86DrvMsg(pScreen->myNum, X_ERROR, "drmAddMap failed, disabling DRI.\n"); @@ -453,7 +455,7 @@ TDFXDRICloseScreen(ScreenPtr pScreen) } static Bool -TDFXCreateContext(ScreenPtr pScreen, VisualPtr visual, +TDFXCreateContext(ScreenPtr pScreen, VisualPtr visual, drmContext hwContext, void *pVisualConfigPriv, DRIContextType contextStore) { @@ -461,7 +463,7 @@ TDFXCreateContext(ScreenPtr pScreen, VisualPtr visual, } static void -TDFXDestroyContext(ScreenPtr pScreen, drmContext hwContext, +TDFXDestroyContext(ScreenPtr pScreen, drmContext hwContext, DRIContextType contextStore) { } @@ -489,11 +491,12 @@ TDFXDRIFinishScreenInit(ScreenPtr pScreen) pTDFXDRI->fbOffset=pTDFX->fbOffset; pTDFXDRI->backOffset=pTDFX->backOffset; pTDFXDRI->depthOffset=pTDFX->depthOffset; + pTDFXDRI->sarea_priv_offset = sizeof(XF86DRISAREARec); return DRIFinishScreenInit(pScreen); } static void -TDFXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType, +TDFXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType, DRIContextType oldContextType, void *oldContext, DRIContextType newContextType, void *newContext) { @@ -515,10 +518,10 @@ TDFXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index) TDFXSetupForSolidFill(pScrn, 0, GXcopy, -1); while (nbox--) { TDFXSelectBuffer(pTDFX, TDFX_BACK); - TDFXSubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1, + TDFXSubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1, pbox->x2-pbox->x1, pbox->y2-pbox->y1); TDFXSelectBuffer(pTDFX, TDFX_DEPTH); - TDFXSubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1, + TDFXSubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1, pbox->x2-pbox->x1, pbox->y2-pbox->y1); pbox++; } @@ -528,7 +531,7 @@ TDFXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index) } static void -TDFXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, +TDFXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, RegionPtr prgnSrc, CARD32 index) { ScreenPtr pScreen = pParent->drawable.pScreen; @@ -571,11 +574,11 @@ TDFXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg, static Bool TDFXDRIOpenFullScreen(ScreenPtr pScreen) { +#if 0 ScrnInfoPtr pScrn; TDFXPtr pTDFX; xf86DrvMsg(pScreen->myNum, X_INFO, "OpenFullScreen\n"); -#if 0 pScrn = xf86Screens[pScreen->myNum]; pTDFX=TDFXPTR(pScrn); if (pTDFX->numChips>1) { @@ -588,10 +591,10 @@ TDFXDRIOpenFullScreen(ScreenPtr pScreen) static Bool TDFXDRICloseFullScreen(ScreenPtr pScreen) { +#if 0 ScrnInfoPtr pScrn; xf86DrvMsg(pScreen->myNum, X_INFO, "CloseFullScreen\n"); -#if 0 pScrn = xf86Screens[pScreen->myNum]; TDFXDisableSLI(pScrn); #endif diff --git a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c index bc9349c8e..3cac32eb1 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c @@ -164,7 +164,6 @@ static PciChipsets TDFXPciChipsets[] = { { -1, -1, RES_UNDEFINED } }; -/* !!! Do we want an option for PIO address space? !!! */ /* !!! Do we want an option for alternate clocking? !!! */ typedef enum { @@ -173,7 +172,8 @@ typedef enum { OPTION_USE_PIO, OPTION_SHOWCACHE, OPTION_VIDEO_KEY, - OPTION_NO_SLI + OPTION_NO_SLI, + OPTION_DRI } TDFXOpts; static OptionInfoRec TDFXOptions[] = { @@ -183,6 +183,7 @@ static OptionInfoRec TDFXOptions[] = { { OPTION_SHOWCACHE, "ShowCache", OPTV_BOOLEAN, {0}, FALSE}, { OPTION_VIDEO_KEY, "VideoKey", OPTV_INTEGER, {0}, FALSE}, { OPTION_NO_SLI, "NoSLI", OPTV_BOOLEAN, {0}, FALSE}, + { OPTION_DRI, "DRI", OPTV_BOOLEAN, {0}, FALSE}, { -1, NULL, OPTV_NONE, {0}, FALSE} }; @@ -492,7 +493,10 @@ TDFXCountRam(ScrnInfoPtr pScrn) { /* set memory interface delay values and enable refresh */ /* these apply to all RAM vendors */ dramInit1 = 0x0; - dramInit1 |= 2<<SST_SGRAM_OFLOP_DEL_ADJ_SHIFT; + if (pTDFX->ChipType==PCI_CHIP_BANSHEE) + dramInit1 |= 7<<SST_SGRAM_OFLOP_DEL_ADJ_SHIFT; + else + dramInit1 |= 2<<SST_SGRAM_OFLOP_DEL_ADJ_SHIFT; dramInit1 |= SST_SGRAM_CLK_NODELAY; dramInit1 |= SST_DRAM_REFRESH_EN; dramInit1 |= (0x18 << SST_DRAM_REFRESH_VALUE_SHIFT) & SST_DRAM_REFRESH_VALUE; @@ -594,28 +598,31 @@ static void TDFXInitChips(ScrnInfoPtr pScrn) { TDFXPtr pTDFX; - int i, cfgbits, initbits; + int i, v, cfgbits, initbits; int mem0base, mem1base, mem0size, mem0bits, mem1size, mem1bits; pTDFX=TDFXPTR(pScrn); cfgbits=pciReadLong(pTDFX->PciTag[0], CFG_PCI_DECODE); mem0base=pciReadLong(pTDFX->PciTag[0], CFG_MEM0BASE); mem1base=pciReadLong(pTDFX->PciTag[0], CFG_MEM1BASE); + initbits=pciReadLong(pTDFX->PciTag[0], CFG_INIT_ENABLE); mem0size=32*1024*1024; /* Registers are always 32MB */ mem1size=pScrn->videoRam*1024*2; /* Linear mapping is 2x memory */ mem0bits=TDFXSizeToCfg(mem0size); mem1bits=TDFXSizeToCfg(mem1size)<<4; cfgbits=(cfgbits&~(0xFF))|mem0bits|mem1bits; for (i=0; i<pTDFX->numChips; i++) { - initbits=pciReadLong(pTDFX->PciTag[i], CFG_INIT_ENABLE); initbits|=BIT(10); pciWriteLong(pTDFX->PciTag[i], CFG_INIT_ENABLE, initbits); + v=pciReadWord(pTDFX->PciTag[i], CFG_PCI_COMMAND); + if (!i) + pciWriteWord(pTDFX->PciTag[i], CFG_PCI_COMMAND, v|0x3); + else + pciWriteWord(pTDFX->PciTag[i], CFG_PCI_COMMAND, v|0x2); pTDFX->MMIOAddr[i]=mem0base+i*mem0size; - pciWriteLong(pTDFX->PciTag[i], CFG_MEM0BASE, 0xFFFFFFFF); pciWriteLong(pTDFX->PciTag[i], CFG_MEM0BASE, pTDFX->MMIOAddr[i]); pTDFX->MMIOAddr[i]&=0xFFFFFF00; pTDFX->LinearAddr[i]=mem1base+i*mem1size; - pciWriteLong(pTDFX->PciTag[i], CFG_MEM1BASE, 0xFFFFFFFF); pciWriteLong(pTDFX->PciTag[i], CFG_MEM1BASE, pTDFX->LinearAddr[i]); pTDFX->LinearAddr[i]&=0xFFFFFF00; pciWriteLong(pTDFX->PciTag[i], CFG_PCI_DECODE, cfgbits); @@ -672,6 +679,7 @@ TDFXPreInit(ScrnInfoPtr pScrn, int flags) if (xf86LoadSubModule(pScrn, "int10")) { xf86Int10InfoPtr pInt; +#if 0 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Softbooting the board (through the int10 interface).\n"); pInt = xf86InitInt10(pTDFX->pEnt->index); @@ -686,6 +694,7 @@ TDFXPreInit(ScrnInfoPtr pScrn, int flags) "Softbooting the board succeeded.\n"); xf86FreeInt10(pInt); } +#endif } match=pTDFX->PciInfo=xf86GetPciInfoForEntity(pTDFX->pEnt->index); @@ -747,9 +756,17 @@ TDFXPreInit(ScrnInfoPtr pScrn, int flags) return FALSE; } - if (!xf86SetDefaultVisual (pScrn, -1)) { + if (!xf86SetDefaultVisual(pScrn, -1)) { return FALSE; - } + } else { + /* We don't currently support DirectColor at > 8bpp */ + if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual" + " (%s) is not supported at depth %d\n", + xf86GetVisualName(pScrn->defaultVisual), pScrn->depth); + return FALSE; + } + } /* We use a programamble clock */ pScrn->progClock = TRUE; @@ -939,17 +956,23 @@ TDFXPreInit(ScrnInfoPtr pScrn, int flags) } xf86LoaderReqSymbols("fbScreenInit", "fbPictureInit", NULL); - pTDFX->NoAccel=xf86ReturnOptValBool(TDFXOptions, OPTION_NOACCEL, FALSE); - if (!pTDFX->NoAccel) { + if (!xf86ReturnOptValBool(TDFXOptions, OPTION_NOACCEL, FALSE)) { if (!xf86LoadSubModule(pScrn, "xaa")) { TDFXFreeRec(pScrn); return FALSE; } } - if (xf86ReturnOptValBool(TDFXOptions, OPTION_SHOWCACHE, FALSE)) { - pTDFX->ShowCache = TRUE; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ShowCache enabled\n"); + if (!xf86GetOptValBool(TDFXOptions, OPTION_SHOWCACHE, &(pTDFX->ShowCache))) { + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ShowCache %s\n", pTDFX->ShowCache ? "Enabled" : "Disabled"); + } else { + pTDFX->ShowCache = FALSE; + } + + if (xf86GetOptValInteger(TDFXOptions, OPTION_VIDEO_KEY, &(pTDFX->videoKey))) { + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n", pTDFX->videoKey); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key default 0x%x\n", pTDFX->videoKey = 0x1E); } if (xf86GetOptValInteger(TDFXOptions, OPTION_VIDEO_KEY, &(pTDFX->videoKey))) { @@ -1106,6 +1129,7 @@ DoSave(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, TDFXRegPtr tdfxReg, Bool saveFonts) { TDFXPtr pTDFX; vgaHWPtr hwp; + int i, dummy, count; TDFXTRACE("TDFXDoSave start\n"); pTDFX = TDFXPTR(pScrn); @@ -1136,6 +1160,14 @@ DoSave(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, TDFXRegPtr tdfxReg, Bool saveFonts) tdfxReg->clip1max=TDFXReadLongMMIO(pTDFX, SST_2D_CLIP1MAX); tdfxReg->srcbaseaddr=TDFXReadLongMMIO(pTDFX, SST_2D_SRCBASEADDR); tdfxReg->dstbaseaddr=TDFXReadLongMMIO(pTDFX, SST_2D_DSTBASEADDR); + for (i=0; i<512; i++) { + count=0; + do { + TDFXWriteLongMMIO(pTDFX, DACADDR, i); + dummy=TDFXReadLongMMIO(pTDFX, DACADDR); + } while (count++<100 && dummy!=i); + tdfxReg->dactable[i]=TDFXReadLongMMIO(pTDFX, DACDATA); + } } static void @@ -1155,6 +1187,7 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, TDFXRegPtr tdfxReg, Bool restoreFonts) { TDFXPtr pTDFX; vgaHWPtr hwp; + int i, dummy, count; TDFXTRACE("TDFXDoRestore start\n"); pTDFX = TDFXPTR(pScrn); @@ -1185,8 +1218,19 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, TDFXRegPtr tdfxReg, pTDFX->writeLong(pTDFX, VIDPROCCFG, tdfxReg->vidcfg); TDFXWriteLongMMIO(pTDFX, SST_2D_SRCBASEADDR, tdfxReg->srcbaseaddr); TDFXWriteLongMMIO(pTDFX, SST_2D_DSTBASEADDR, tdfxReg->dstbaseaddr); - vgaHWProtect(pScrn, FALSE); + for (i=0; i<512; i++) { + count=0; + do { + TDFXWriteLongMMIO(pTDFX, DACADDR, i); + dummy=TDFXReadLongMMIO(pTDFX, DACADDR); + } while (count++<100 && dummy!=i); + count=0; + do { + TDFXWriteLongMMIO(pTDFX, DACDATA, tdfxReg->dactable[i]); + dummy=TDFXReadLongMMIO(pTDFX, DACDATA); + } while (count++<100 && dummy!=tdfxReg->dactable[i]); + } pTDFX->sync(pScrn); } @@ -1429,6 +1473,7 @@ TDFXModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) int hd, hbs, hss, hse, hbe, ht, hskew; Bool dbl; + hd = hbs = hss = hse = hbe = ht = hskew = 0; hwp = VGAHWPTR(pScrn); pTDFX = TDFXPTR(pScrn); @@ -1489,35 +1534,35 @@ TDFXModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) static void TDFXLoadPalette16(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, - short visualClass) { + VisualPtr pVisual) { TDFXPtr pTDFX; int i, j, index, v, repeat, max; TDFXTRACE("TDFXLoadPalette16 start\n"); pTDFX = TDFXPTR(pScrn); + for (i=0; i<numColors; i++) { index=indices[i]; v=(colors[index/2].red<<16)|(colors[index].green<<8)|colors[index/2].blue; - if (i<numColors-1) max=indices[i+1]<<2; - else max=256; - for (j=index<<2; j<max; j++) { + max=min((index+1)<<2, 256); + for (j = index<<2; j < max; j++) + { repeat=100; do { - pTDFX->writeLong(pTDFX, DACADDR, j); - } while (--repeat && pTDFX->readLong(pTDFX, DACADDR)!=j); + TDFXWriteLongMMIO(pTDFX, DACADDR, j); + } while (--repeat && TDFXReadLongMMIO(pTDFX, DACADDR)!=j); if (!repeat) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to set dac index, " - "bypassing CLUT\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to set dac index, bypassing CLUT\n"); pTDFX->ModeReg.vidcfg |= SST_DESKTOP_CLUT_BYPASS; return; } + repeat=100; do { - pTDFX->writeLong(pTDFX, DACDATA, v); - } while (--repeat && pTDFX->readLong(pTDFX, DACDATA)!=v); + TDFXWriteLongMMIO(pTDFX, DACDATA, v); + } while (--repeat && TDFXReadLongMMIO(pTDFX, DACDATA)!=v); if (!repeat) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to set dac value, " - "bypassing CLUT\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to set dac value, bypassing CLUT\n"); pTDFX->ModeReg.vidcfg |= SST_DESKTOP_CLUT_BYPASS; return; } @@ -1527,7 +1572,7 @@ TDFXLoadPalette16(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, static void TDFXLoadPalette24(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, - short visualClass) { + VisualPtr pVisual) { TDFXPtr pTDFX; int i, index, v, repeat; @@ -1538,8 +1583,8 @@ TDFXLoadPalette24(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, v=(colors[index].red<<16)|(colors[index].green<<8)|colors[index].blue; repeat=100; do { - pTDFX->writeLong(pTDFX, DACADDR, index); - } while (--repeat && pTDFX->readLong(pTDFX, DACADDR)!=index); + TDFXWriteLongMMIO(pTDFX, DACADDR, index); + } while (--repeat && TDFXReadLongMMIO(pTDFX, DACADDR)!=index); if (!repeat) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to set dac index, " "bypassing CLUT\n"); @@ -1548,8 +1593,8 @@ TDFXLoadPalette24(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, } repeat=100; do { - pTDFX->writeLong(pTDFX, DACDATA, v); - } while (--repeat && pTDFX->readLong(pTDFX, DACDATA)!=v); + TDFXWriteLongMMIO(pTDFX, DACDATA, v); + } while (--repeat && TDFXReadLongMMIO(pTDFX, DACDATA)!=v); if (!repeat) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to set dac value, " "bypassing CLUT\n"); @@ -1625,7 +1670,7 @@ calcBufferSize(int xres, int yres, Bool tiled, int cpp) static void allocateMemory(ScrnInfoPtr pScrn) { TDFXPtr pTDFX; - int memRemaining, fifoSize, screenSizeInTiles; + int memRemaining, fifoSize, screenSizeInTiles, cursorSize; pTDFX = TDFXPTR(pScrn); @@ -1646,7 +1691,7 @@ static void allocateMemory(ScrnInfoPtr pScrn) { /* it to be on an *odd* page boundary. */ pTDFX->depthOffset = (memRemaining - screenSizeInTiles) &~ 0xFFF; if ((pTDFX->depthOffset & (0x1 << 12)) == 0) { -#if 0 +#if 1 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Changing depth offset from 0x%08x to 0x%08x\n", pTDFX->depthOffset, @@ -1658,7 +1703,7 @@ static void allocateMemory(ScrnInfoPtr pScrn) { /* to be on an *even* page boundary. */ pTDFX->backOffset = (pTDFX->depthOffset - screenSizeInTiles) &~ 0xFFF; if (pTDFX->backOffset & (0x1 << 12)) { -#if 0 +#if 1 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Changing back offset from 0x%08x to 0x%08x\n", pTDFX->backOffset, @@ -1670,8 +1715,9 @@ static void allocateMemory(ScrnInfoPtr pScrn) { /* CMDFIFO_PAGES pages, but no more than */ /* 255. We give 4096 bytes to the cursor */ fifoSize = ((255 <= CMDFIFO_PAGES) ? 255 : CMDFIFO_PAGES) << 12; + cursorSize = 4096; pTDFX->cursorOffset = 0; - pTDFX->fifoOffset = 4096; + pTDFX->fifoOffset = pTDFX->cursorOffset + cursorSize; pTDFX->fifoSize = fifoSize; /* Now, place the front buffer, forcing */ /* it to be on a page boundary too, just */ @@ -1684,21 +1730,21 @@ static void allocateMemory(ScrnInfoPtr pScrn) { if (pTDFX->texSize < 0) { pTDFX->backOffset = -1; pTDFX->depthOffset = -1; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "No Texture Memory available." - " Disabling direct rendering.\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "No Texture Memory available, disabling DRI\n"); } else { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Textures Memory %0.02f MB\n", (float)pTDFX->texSize/1024.0/1024.0); } -#if 0 + +#if 1 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Cursor Offset: [0x%08X,0x%08X)\n", pTDFX->cursorOffset, - pTDFX->cursorOffset+1024); + pTDFX->cursorOffset + cursorSize); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Fifo Offset: [0x%08X, 0x%08X)\n", pTDFX->fifoOffset, - pTDFX->fifoOffset+fifoSize); + pTDFX->fifoOffset + pTDFX->fifoSize); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Texture Offset: [0x%08X, 0x%08X)\n", pTDFX->texOffset, @@ -1711,11 +1757,11 @@ static void allocateMemory(ScrnInfoPtr pScrn) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "BackOffset: [0x%08X, 0x%08X)\n", pTDFX->backOffset, - pTDFX->backOffset+screenSizeInTiles); + pTDFX->backOffset + screenSizeInTiles); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "DepthOffset: [0x%08X, 0x%08X)\n", pTDFX->depthOffset, - pTDFX->depthOffset+screenSizeInTiles); + pTDFX->depthOffset + screenSizeInTiles); #endif /* 0/1 */ } @@ -1726,6 +1772,7 @@ TDFXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { TDFXPtr pTDFX; VisualPtr visual; BoxRec MemBox; + MessageType driFrom = X_DEFAULT; TDFXTRACE("TDFXScreenInit start\n"); pScrn = xf86Screens[pScreen->myNum]; @@ -1746,6 +1793,7 @@ TDFXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { allocateMemory(pScrn); +#if 0 if (pTDFX->numChips>1) { if (xf86ReturnOptValBool(TDFXOptions, OPTION_NO_SLI, FALSE)) { TDFXSetupSLI(pScrn, FALSE, 0); @@ -1753,13 +1801,14 @@ TDFXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { TDFXSetupSLI(pScrn, TRUE, 0); } } +#endif TDFXSetLFBConfig(pTDFX); /* We initialize in the state that our FIFO is up to date */ pTDFX->syncDone=TRUE; if (!TDFXInitFifo(pScreen)) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to initialize fifo\n"); + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to initialize private\n"); return FALSE; } @@ -1790,6 +1839,8 @@ TDFXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { TDFXSave(pScrn); if (!TDFXModeInit(pScrn, pScrn->currentMode)) return FALSE; + TDFXSetLFBConfig(pTDFX); + miClearVisualTypes(); if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth), @@ -1798,19 +1849,21 @@ TDFXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { miSetPixmapDepths (); + pTDFX->NoAccel=xf86ReturnOptValBool(TDFXOptions, OPTION_NOACCEL, FALSE); #ifdef XF86DRI /* * Setup DRI after visuals have been established, but before fbScreenInit * is called. fbScreenInit will eventually call into the drivers * InitGLXVisuals call back. */ - if (!pTDFX->NoAccel) { - if ( !((pTDFX->backOffset == -1) && (pTDFX->depthOffset == -1))) { + if (!xf86ReturnOptValBool(TDFXOptions, OPTION_DRI, TRUE) || pTDFX->NoAccel) { + pTDFX->directRenderingEnabled = FALSE; + driFrom = X_CONFIG; + } else if ((pTDFX->backOffset == -1) || (pTDFX->depthOffset == -1)) { + pTDFX->directRenderingEnabled = FALSE; + driFrom = X_PROBED; + } else { pTDFX->directRenderingEnabled = TDFXDRIScreenInit(pScreen); - } - /* Force the initialization of the context */ - if (pTDFX->directRenderingEnabled) - TDFXLostContext(pScreen); } #endif @@ -1890,21 +1943,20 @@ TDFXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { xf86DPMSInit(pScreen, TDFXDisplayPowerManagementSet, 0); #ifdef XF86DRI - if (!pTDFX->NoAccel) { - if (pTDFX->directRenderingEnabled) { + if (pTDFX->directRenderingEnabled) { /* Now that mi, fb, drm and others have done their thing, * complete the DRI setup. */ pTDFX->directRenderingEnabled = TDFXDRIFinishScreenInit(pScreen); - } } if (pTDFX->directRenderingEnabled) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering enabled\n"); + xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering enabled\n"); } else { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering disabled\n"); + xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering disabled\n"); } #endif + #ifdef XvExtension /* Initialize Xv support */ TDFXInitVideo (pScreen); @@ -1941,6 +1993,10 @@ TDFXAdjustFrame(int scrnIndex, int x, int y, int flags) { TDFXTRACE("TDFXAdjustFrame start\n"); pScrn = xf86Screens[scrnIndex]; pTDFX = TDFXPTR(pScrn); + + if (pTDFX->ShowCache && y && pScrn->vtSema) + y += pScrn->virtualY - 1; + tdfxReg = &pTDFX->ModeReg; if(pTDFX->ShowCache && y && pScrn->vtSema) y += pScrn->virtualY - 1; @@ -1952,19 +2008,20 @@ TDFXAdjustFrame(int scrnIndex, int x, int y, int flags) { static Bool TDFXEnterVT(int scrnIndex, int flags) { ScrnInfoPtr pScrn; -#ifdef XF86DRI ScreenPtr pScreen; +#ifdef XF86DRI TDFXPtr pTDFX; #endif TDFXTRACE("TDFXEnterVT start\n"); pScrn = xf86Screens[scrnIndex]; + pScreen = screenInfo.screens[scrnIndex]; + TDFXInitFifo(pScreen); #ifdef XF86DRI pTDFX = TDFXPTR(pScrn); if (pTDFX->directRenderingEnabled) { pScreen = screenInfo.screens[scrnIndex]; DRIUnlock(pScreen); - TDFXLostContext(pScreen); } #endif if (!TDFXModeInit(pScrn, pScrn->currentMode)) return FALSE; @@ -1987,8 +2044,10 @@ TDFXLeaveVT(int scrnIndex, int flags) { TDFXRestore(pScrn); vgaHWLock(hwp); pScreen = screenInfo.screens[scrnIndex]; -#ifdef XF86DRI pTDFX = TDFXPTR(pScrn); + pTDFX->sync(pScrn); + TDFXShutdownFifo(pScreen); +#ifdef XF86DRI if (pTDFX->directRenderingEnabled) { DRILock(pScreen, 0); TDFXSwapContextFifo(pScreen); @@ -2041,7 +2100,6 @@ TDFXCloseScreen(int scrnIndex, ScreenPtr pScreen) pTDFX->adaptor = NULL; } - pScrn->vtSema=FALSE; pScreen->BlockHandler = pTDFX->BlockHandler; diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drm_bufs.h b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drm_bufs.h index b82d1a263..16af7bd54 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drm_bufs.h +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drm_bufs.h @@ -946,18 +946,34 @@ int DRM(mapbufs)( struct inode *inode, struct file *filp, goto done; } +#if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); +#else + down_write( ¤t->mm->mmap_sem ); +#endif virtual = do_mmap( filp, 0, map->size, PROT_READ | PROT_WRITE, MAP_SHARED, (unsigned long)map->offset ); +#if LINUX_VERSION_CODE <= 0x020402 up( ¤t->mm->mmap_sem ); +#else + up_write( ¤t->mm->mmap_sem ); +#endif } else { +#if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); +#else + down_write( ¤t->mm->mmap_sem ); +#endif virtual = do_mmap( filp, 0, dma->byte_count, PROT_READ | PROT_WRITE, MAP_SHARED, 0 ); +#if LINUX_VERSION_CODE <= 0x020402 up( ¤t->mm->mmap_sem ); +#else + up_write( ¤t->mm->mmap_sem ); +#endif } if ( virtual > -1024UL ) { /* Real error */ diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/radeon_drv.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/radeon_drv.c index 59497acae..d76326676 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/radeon_drv.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/radeon_drv.c @@ -40,8 +40,8 @@ #define DRIVER_DATE "20010405" #define DRIVER_MAJOR 1 -#define DRIVER_MINOR 0 -#define DRIVER_PATCHLEVEL 2 +#define DRIVER_MINOR 1 +#define DRIVER_PATCHLEVEL 1 #define DRIVER_IOCTLS \ [DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { radeon_cp_buffers, 1, 0 }, \ diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c index 404840cdd..bb719edb6 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c @@ -35,11 +35,9 @@ # include "xf86.h" # include "xf86_OSproc.h" # include "xf86_ansic.h" -# include "xf86Priv.h" # define _DRM_MALLOC xalloc # define _DRM_FREE xfree # ifndef XFree86LOADER -# include <sys/stat.h> # include <sys/mman.h> # endif #else @@ -53,6 +51,7 @@ # include <signal.h> # include <sys/types.h> # include <sys/stat.h> +# define stat_t struct stat # include <sys/ioctl.h> # include <sys/mman.h> # include <sys/time.h> @@ -136,11 +135,7 @@ static char *drmStrdup(const char *s) static unsigned long drmGetKeyFromFd(int fd) { -#ifdef XFree86LOADER - struct xf86stat st; -#else - struct stat st; -#endif + stat_t st; st.st_rdev = 0; fstat(fd, &st); @@ -169,11 +164,7 @@ static drmHashEntry *drmGetEntry(int fd) static int drmOpenDevice(long dev, int minor) { -#ifdef XFree86LOADER - struct xf86stat st; -#else - struct stat st; -#endif + stat_t st; char buf[64]; int fd; mode_t dirmode = DRM_DEV_DIRMODE; @@ -220,7 +211,7 @@ static int drmOpenDevice(long dev, int minor) return -errno; } -int drmOpenMinor(int minor, int create) +static int drmOpenMinor(int minor, int create) { int fd; char buf[64]; diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmI810.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmI810.c index d5a7e2263..bb2805b29 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmI810.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmI810.c @@ -4,11 +4,9 @@ # include "xf86.h" # include "xf86_OSproc.h" # include "xf86_ansic.h" -# include "xf86Priv.h" # define _DRM_MALLOC xalloc # define _DRM_FREE xfree # ifndef XFree86LOADER -# include <sys/stat.h> # include <sys/mman.h> # endif #else @@ -21,7 +19,6 @@ # include <errno.h> # include <signal.h> # include <sys/types.h> -# include <sys/stat.h> # include <sys/ioctl.h> # include <sys/mman.h> # include <sys/time.h> @@ -70,8 +67,8 @@ Bool drmI810InitDma(int driSubFD, drmI810Init *info) memset(&init, 0, sizeof(drm_i810_init_t)); init.func = I810_INIT_DMA; - init.ring_map_idx = info->ring_map_idx; - init.buffer_map_idx = info->buffer_map_idx; + init.mmio_offset = info->mmio_offset; + init.buffers_offset = info->buffers_offset; init.ring_start = info->start; init.ring_end = info->end; init.ring_size = info->size; diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmMga.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmMga.c index d566b0868..1b2df36d1 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmMga.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmMga.c @@ -1,14 +1,41 @@ +/* xf86drmMga.c -- User-level interface to MGA DRM device + * Created: Sun Apr 9 18:13:54 2000 by gareth@valinux.com + * + * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * 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 MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS 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. + * + * Author: + * Gareth Hughes <gareth@valinux.com> + * + */ /* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmMga.c,v 1.3 2000/08/24 22:20:17 tsi Exp $ */ #ifdef XFree86Server # include "xf86.h" # include "xf86_OSproc.h" # include "xf86_ansic.h" -# include "xf86Priv.h" # define _DRM_MALLOC xalloc # define _DRM_FREE xfree # ifndef XFree86LOADER -# include <sys/stat.h> # include <sys/mman.h> # endif #else @@ -21,7 +48,6 @@ # include <errno.h> # include <signal.h> # include <sys/types.h> -# include <sys/stat.h> # include <sys/ioctl.h> # include <sys/mman.h> # include <sys/time.h> @@ -49,73 +75,237 @@ extern int xf86RemoveSIGIOHandler(int fd); #include "xf86drmMga.h" #include "drm.h" -Bool drmMgaCleanupDma(int driSubFD) +#define MGA_IDLE_RETRY 2048 + + +int drmMGAInitDMA( int fd, drmMGAInit *info ) { drm_mga_init_t init; - memset(&init, 0, sizeof(drm_mga_init_t)); + + memset( &init, 0, sizeof(drm_mga_init_t) ); + + init.func = MGA_INIT_DMA; + + init.sarea_priv_offset = info->sarea_priv_offset; + init.sgram = info->sgram; + init.chipset = info->chipset; + init.maccess = info->maccess; + + init.fb_cpp = info->fb_cpp; + init.front_offset = info->front_offset; + init.front_pitch = info->front_pitch; + init.back_offset = info->back_offset; + init.back_pitch = info->back_pitch; + + init.depth_cpp = info->depth_cpp; + init.depth_offset = info->depth_offset; + init.depth_pitch = info->depth_pitch; + + init.texture_offset[0] = info->texture_offset[0]; + init.texture_size[0] = info->texture_size[0]; + init.texture_offset[1] = info->texture_offset[1]; + init.texture_size[1] = info->texture_size[1]; + + init.fb_offset = info->fb_offset; + init.mmio_offset = info->mmio_offset; + init.status_offset = info->status_offset; + init.warp_offset = info->warp_offset; + init.primary_offset = info->primary_offset; + init.buffers_offset = info->buffers_offset; + + if ( ioctl( fd, DRM_IOCTL_MGA_INIT, &init ) ) { + return -errno; + } else { + return 0; + } +} + +int drmMGACleanupDMA( int fd ) +{ + drm_mga_init_t init; + + memset( &init, 0, sizeof(drm_mga_init_t) ); + init.func = MGA_CLEANUP_DMA; - if(ioctl(driSubFD, DRM_IOCTL_MGA_INIT, &init)) { - return FALSE; + + if ( ioctl( fd, DRM_IOCTL_MGA_INIT, &init ) ) { + return -errno; + } else { + return 0; } - - return TRUE; } -Bool drmMgaLockUpdate(int driSubFD, drmLockFlags flags) +int drmMGAFlushDMA( int fd, drmLockFlags flags ) { drm_lock_t lock; - - memset(&lock, 0, sizeof(drm_lock_t)); - - if (flags & DRM_LOCK_QUIESCENT) lock.flags |= _DRM_LOCK_QUIESCENT; - if (flags & DRM_LOCK_FLUSH) lock.flags |= _DRM_LOCK_FLUSH; - if (flags & DRM_LOCK_FLUSH_ALL) lock.flags |= _DRM_LOCK_FLUSH_ALL; - - if(ioctl(driSubFD, DRM_IOCTL_MGA_FLUSH, &lock)) { - return FALSE; + int ret, i = 0; + + memset( &lock, 0, sizeof(drm_lock_t) ); + + if ( flags & DRM_LOCK_QUIESCENT ) lock.flags |= _DRM_LOCK_QUIESCENT; + if ( flags & DRM_LOCK_FLUSH ) lock.flags |= _DRM_LOCK_FLUSH; + if ( flags & DRM_LOCK_FLUSH_ALL ) lock.flags |= _DRM_LOCK_FLUSH_ALL; + + do { + ret = ioctl( fd, DRM_IOCTL_MGA_FLUSH, &lock ); + } while ( ret && errno == EBUSY && i++ < MGA_IDLE_RETRY ); + + if ( ret == 0 ) + return 0; + if ( errno != EBUSY ) + return -errno; + + if ( lock.flags & _DRM_LOCK_QUIESCENT ) { + /* Only keep trying if we need quiescence. + */ + lock.flags &= ~(_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL); + + do { + ret = ioctl( fd, DRM_IOCTL_MGA_FLUSH, &lock ); + } while ( ret && errno == EBUSY && i++ < MGA_IDLE_RETRY ); + } + + if ( ret == 0 ) { + return 0; + } else { + return -errno; + } +} + +int drmMGAEngineReset( int fd ) +{ + if ( ioctl( fd, DRM_IOCTL_MGA_RESET, NULL ) ) { + return -errno; + } else { + return 0; + } +} + +int drmMGAFullScreen( int fd, int enable ) +{ + return -EINVAL; +} + +int drmMGASwapBuffers( int fd ) +{ + int ret, i = 0; + + do { + ret = ioctl( fd, DRM_IOCTL_MGA_SWAP, NULL ); + } while ( ret && errno == EBUSY && i++ < MGA_IDLE_RETRY ); + + if ( ret == 0 ) { + return 0; + } else { + return -errno; + } +} + +int drmMGAClear( int fd, unsigned int flags, + unsigned int clear_color, unsigned int clear_depth, + unsigned int color_mask, unsigned int depth_mask ) +{ + drm_mga_clear_t clear; + int ret, i = 0; + + clear.flags = flags; + clear.clear_color = clear_color; + clear.clear_depth = clear_depth; + clear.color_mask = color_mask; + clear.depth_mask = depth_mask; + + do { + ret = ioctl( fd, DRM_IOCTL_MGA_CLEAR, &clear ); + } while ( ret && errno == EBUSY && i++ < MGA_IDLE_RETRY ); + + if ( ret == 0 ) { + return 0; + } else { + return -errno; + } +} + +int drmMGAFlushVertexBuffer( int fd, int index, int used, int discard ) +{ + drm_mga_vertex_t vertex; + + vertex.idx = index; + vertex.used = used; + vertex.discard = discard; + + if ( ioctl( fd, DRM_IOCTL_MGA_VERTEX, &vertex ) ) { + return -errno; + } else { + return 0; } - - return TRUE; } -Bool drmMgaInitDma(int driSubFD, drmMgaInit *info) +int drmMGAFlushIndices( int fd, int index, int start, int end, int discard ) { - drm_mga_init_t init; - int i; - - memset(&init, 0, sizeof(drm_mga_init_t)); - init.func = MGA_INIT_DMA; - init.reserved_map_agpstart = info->reserved_map_agpstart; - init.reserved_map_idx = info->reserved_map_idx; - init.buffer_map_idx = info->buffer_map_idx; - init.sarea_priv_offset = info->sarea_priv_offset; - init.primary_size = info->primary_size; - init.warp_ucode_size = info->warp_ucode_size; - init.frontOffset = info->frontOffset; - init.backOffset = info->backOffset; - init.depthOffset = info->depthOffset; - init.textureOffset = info->textureOffset; - init.textureSize = info->textureSize; - init.agpTextureSize = info->agpTextureSize; - init.agpTextureOffset = info->agpTextureOffset; - init.cpp = info->cpp; - init.stride = info->stride; - init.sgram = info->sgram; - init.chipset = info->chipset; - - for(i = 0; i < MGA_MAX_WARP_PIPES; i++) { - init.WarpIndex[i].installed = info->WarpIndex[i].installed; - init.WarpIndex[i].phys_addr = info->WarpIndex[i].phys_addr; - init.WarpIndex[i].size = info->WarpIndex[i].size; - } - - init.mAccess = info->mAccess; - - - - if(ioctl(driSubFD, DRM_IOCTL_MGA_INIT, &init)) { - return FALSE; - } - return TRUE; + drm_mga_indices_t indices; + + indices.idx = index; + indices.start = start; + indices.end = end; + indices.discard = discard; + + if ( ioctl( fd, DRM_IOCTL_MGA_INDICES, &indices ) ) { + return -errno; + } else { + return 0; + } } +int drmMGATextureLoad( int fd, int index, + unsigned int dstorg, unsigned int length ) +{ + drm_mga_iload_t iload; + int ret, i = 0; + + iload.idx = index; + iload.dstorg = dstorg; + iload.length = length; + + do { + ret = ioctl( fd, DRM_IOCTL_MGA_ILOAD, &iload ); + } while ( ret && errno == EBUSY && i++ < MGA_IDLE_RETRY ); + + if ( ret == 0 ) { + return 0; + } else { + return -errno; + } +} + +int drmMGAAgpBlit( int fd, unsigned int planemask, + unsigned int src_offset, int src_pitch, + unsigned int dst_offset, int dst_pitch, + int delta_sx, int delta_sy, + int delta_dx, int delta_dy, + int height, int ydir ) +{ + drm_mga_blit_t blit; + int ret, i = 0; + + blit.planemask = planemask; + blit.srcorg = src_offset; + blit.dstorg = dst_offset; + blit.src_pitch = src_pitch; + blit.dst_pitch = dst_pitch; + blit.delta_sx = delta_sx; + blit.delta_sy = delta_sy; + blit.delta_dx = delta_dx; + blit.delta_dx = delta_dx; + blit.height = height; + blit.ydir = ydir; + + do { + ret = ioctl( fd, DRM_IOCTL_MGA_BLIT, &blit ); + } while ( ret && errno == EBUSY && i++ < MGA_IDLE_RETRY ); + + if ( ret == 0 ) { + return 0; + } else { + return -errno; + } +} diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmR128.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmR128.c index 82559225e..901fb9d3a 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmR128.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmR128.c @@ -32,11 +32,9 @@ # include "xf86.h" # include "xf86_OSproc.h" # include "xf86_ansic.h" -# include "xf86Priv.h" # define _DRM_MALLOC xalloc # define _DRM_FREE xfree # ifndef XFree86LOADER -# include <sys/stat.h> # include <sys/mman.h> # endif #else @@ -49,7 +47,6 @@ # include <errno.h> # include <signal.h> # include <sys/types.h> -# include <sys/stat.h> # include <sys/ioctl.h> # include <sys/mman.h> # include <sys/time.h> @@ -154,8 +151,11 @@ int drmR128StopCCE( int fd ) ret = ioctl( fd, DRM_IOCTL_R128_CCE_STOP, &stop ); - if ( ret && errno != EBUSY ) + if ( ret == 0 ) { + return 0; + } else if ( errno != EBUSY ) { return -errno; + } stop.flush = 0; @@ -163,8 +163,11 @@ int drmR128StopCCE( int fd ) ret = ioctl( fd, DRM_IOCTL_R128_CCE_STOP, &stop ); } while ( ret && errno == EBUSY && i++ < R128_IDLE_RETRY ); - if ( ret && errno != EBUSY ) + if ( ret == 0 ) { + return 0; + } else if ( errno != EBUSY ) { return -errno; + } stop.idle = 0; @@ -235,19 +238,16 @@ int drmR128SwapBuffers( int fd ) } int drmR128Clear( int fd, unsigned int flags, - int x, int y, int w, int h, - unsigned int clear_color, - unsigned int clear_depth ) + unsigned int clear_color, unsigned int clear_depth, + unsigned int color_mask, unsigned int depth_mask ) { drm_r128_clear_t clear; clear.flags = flags; - clear.x = x; - clear.y = y; - clear.w = w; - clear.h = h; clear.clear_color = clear_color; clear.clear_depth = clear_depth; + clear.color_mask = color_mask; + clear.depth_mask = depth_mask; if ( ioctl( fd, DRM_IOCTL_R128_CLEAR, &clear ) < 0 ) { return -errno; diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmRadeon.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmRadeon.c index 41d7cdf27..079d69950 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmRadeon.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmRadeon.c @@ -27,17 +27,15 @@ * Kevin E. Martin <martin@valinux.com> * */ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmRadeon.c,v 1.1 2001/01/08 01:07:37 martin Exp $ */ +/* $XFree86$ */ #ifdef XFree86Server # include "xf86.h" # include "xf86_OSproc.h" # include "xf86_ansic.h" -# include "xf86Priv.h" # define _DRM_MALLOC xalloc # define _DRM_FREE xfree # ifndef XFree86LOADER -# include <sys/stat.h> # include <sys/mman.h> # endif #else @@ -50,7 +48,6 @@ # include <errno.h> # include <signal.h> # include <sys/types.h> -# include <sys/stat.h> # include <sys/ioctl.h> # include <sys/mman.h> # include <sys/time.h> @@ -154,8 +151,11 @@ int drmRadeonStopCP( int fd ) ret = ioctl( fd, DRM_IOCTL_RADEON_CP_STOP, &stop ); - if ( ret && errno != EBUSY ) + if ( ret == 0 ) { + return 0; + } else if ( errno != EBUSY ) { return -errno; + } stop.flush = 0; @@ -163,8 +163,11 @@ int drmRadeonStopCP( int fd ) ret = ioctl( fd, DRM_IOCTL_RADEON_CP_STOP, &stop ); } while ( ret && errno == EBUSY && i++ < RADEON_IDLE_RETRY ); - if ( ret && errno != EBUSY ) + if ( ret == 0 ) { + return 0; + } else if ( errno != EBUSY ) { return -errno; + } stop.idle = 0; @@ -235,29 +238,33 @@ int drmRadeonSwapBuffers( int fd ) } int drmRadeonClear( int fd, unsigned int flags, - int x, int y, int w, int h, - unsigned int clear_color, - unsigned int clear_depth ) + unsigned int clear_color, unsigned int clear_depth, + unsigned int color_mask, unsigned int depth_mask, + void *b, int nbox ) { drm_radeon_clear_t clear; + drm_radeon_clear_rect_t depth_boxes[RADEON_NR_SAREA_CLIPRECTS]; + drm_clip_rect_t *boxes = (drm_clip_rect_t *)b; + int i; clear.flags = flags; - clear.x = x; - clear.y = y; - clear.w = w; - clear.h = h; clear.clear_color = clear_color; clear.clear_depth = clear_depth; + clear.color_mask = color_mask; + clear.depth_mask = depth_mask; + clear.depth_boxes = depth_boxes; /* We can remove this when we do real depth clears, instead of * rendering a rectangle into the depth buffer. This prevents * floating point calculations being done in the kernel. */ - clear.rect.f[CLEAR_X1] = (float)x; - clear.rect.f[CLEAR_Y1] = (float)y; - clear.rect.f[CLEAR_X2] = (float)x + w; - clear.rect.f[CLEAR_Y2] = (float)y + h; - clear.rect.f[CLEAR_DEPTH] = (float)clear_depth; + for ( i = 0 ; i < nbox ; i++ ) { + depth_boxes[i].f[CLEAR_X1] = (float)boxes[i].x1; + depth_boxes[i].f[CLEAR_Y1] = (float)boxes[i].y1; + depth_boxes[i].f[CLEAR_X2] = (float)boxes[i].x2; + depth_boxes[i].f[CLEAR_Y2] = (float)boxes[i].y2; + depth_boxes[i].f[CLEAR_DEPTH] = (float)clear_depth; + } if ( ioctl( fd, DRM_IOCTL_RADEON_CLEAR, &clear ) < 0 ) { return -errno; @@ -301,25 +308,32 @@ int drmRadeonFlushIndices( int fd, int prim, int index, } } -int drmRadeonTextureBlit( int fd, int index, - int offset, int pitch, int format, - int x, int y, int width, int height ) +int drmRadeonLoadTexture( int fd, int offset, int pitch, int format, + int width, int height, drmRadeonTexImage *image ) { - drm_radeon_blit_t blit; - - blit.idx = index; - blit.offset = offset; - blit.pitch = pitch; - blit.format = format; - blit.x = x; - blit.y = y; - blit.width = width; - blit.height = height; - - if ( ioctl( fd, DRM_IOCTL_RADEON_BLIT, &blit ) < 0 ) { - return -errno; - } else { + drm_radeon_texture_t tex; + drm_radeon_tex_image_t tmp; + int ret; + + tex.offset = offset; + tex.pitch = pitch; + tex.format = format; + tex.width = width; + tex.height = height; + tex.image = &tmp; + + /* This gets updated by the kernel when a multipass blit is needed. + */ + memcpy( &tmp, image, sizeof(drm_radeon_tex_image_t) ); + + do { + ret = ioctl( fd, DRM_IOCTL_RADEON_TEXTURE, &tex ); + } while ( ret && errno == EAGAIN ); + + if ( ret == 0 ) { return 0; + } else { + return -errno; } } diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmSiS.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmSiS.c index 4d101c1a1..fcea93ec0 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmSiS.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drmSiS.c @@ -4,11 +4,9 @@ # include "xf86.h" # include "xf86_OSproc.h" # include "xf86_ansic.h" -# include "xf86Priv.h" # define _DRM_MALLOC xalloc # define _DRM_FREE xfree # ifndef XFree86LOADER -# include <sys/stat.h> # include <sys/mman.h> # endif #else @@ -21,7 +19,6 @@ # include <errno.h> # include <signal.h> # include <sys/types.h> -# include <sys/stat.h> # include <sys/ioctl.h> # include <sys/mman.h> # include <sys/time.h> diff --git a/xc/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h b/xc/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h index 7d3b9a804..e48b672f4 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h +++ b/xc/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h @@ -318,6 +318,8 @@ extern void xf86longjmp(xf86jmp_buf env, int val); #include <sys/ipc.h> #include <sys/shm.h> #endif +#include <sys/stat.h> +#define stat_t struct stat #endif /* XFree86LOADER || NEED_XF86_PROTOTYPES */ /* diff --git a/xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h b/xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h index 09dffe9ad..615cc3f4c 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h +++ b/xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h @@ -64,7 +64,7 @@ typedef unsigned int xf86uid_t; typedef unsigned int xf86gid_t; struct xf86stat { - xf86dev_t st_rdev; /* This is incomplete */ + xf86dev_t st_rdev; /* This is incomplete, and makes assumptions */ }; /* sysv IPC */ @@ -499,6 +499,7 @@ typedef int xf86jmp_buf[20]; #define gid_t xf86gid_t #undef jmp_buf #define jmp_buf xf86jmp_buf +#define stat_t struct xf86stat /* * There should be no need to #undef any of these. If they are already |