[Xquartz-changes] xserver: Branch 'server-1.12-apple' - 74 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Wed Sep 28 12:17:01 PDT 2011


Rebased ref, commits from common ancestor:
commit 01125c7acc98d57d130f5f3bf84e0bdbd4be44e0
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Feb 12 19:48:52 2010 -0800

    fb: Revert fb changes that broke XQuartz
    
    http://bugs.freedesktop.org/show_bug.cgi?id=26124
    
    Revert "Fix source pictures getting random transforms after 2d6a8f668342a5190cdf43b5."
    Revert "fb: Adjust transform or composite coordinates for pixman operations"
    
    http://bugs.freedesktop.org/26124
    
    This reverts commit a72c65e9176c51de95db2fdbf4c5d946a4911695.
    This reverts commit a6bd5d2e482a5aa84acb3d4932e2a166d8670ef1.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/fb/fb.h b/fb/fb.h
index eaa21ad..e65a1c0 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -2049,11 +2049,8 @@ fbFillRegionSolid (DrawablePtr	pDrawable,
 		   FbBits	xor);
 
 extern _X_EXPORT pixman_image_t *
-image_from_pict (PicturePtr	pict,
-		 Bool		has_clip,
-		 int		*xoff,
-		 int		*yoff);
-
+image_from_pict (PicturePtr pict,
+		 Bool       has_clip);
 extern _X_EXPORT void free_pixman_pict (PicturePtr, pixman_image_t *);
 
 #endif /* _FB_H_ */
diff --git a/fb/fbpict.c b/fb/fbpict.c
index d1fd0cb..d2986c8 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -50,24 +50,19 @@ fbComposite (CARD8      op,
 	     CARD16     height)
 {
     pixman_image_t *src, *mask, *dest;
-    int src_xoff, src_yoff;
-    int msk_xoff, msk_yoff;
-    int dst_xoff, dst_yoff;
     
     miCompositeSourceValidate (pSrc);
     if (pMask)
 	miCompositeSourceValidate (pMask);
     
-    src = image_from_pict (pSrc, FALSE, &src_xoff, &src_yoff);
-    mask = image_from_pict (pMask, FALSE, &msk_xoff, &msk_yoff);
-    dest = image_from_pict (pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict (pSrc, TRUE);
+    mask = image_from_pict (pMask, TRUE);
+    dest = image_from_pict (pDst, TRUE);
 
     if (src && dest && !(pMask && !mask))
     {
 	pixman_image_composite (op, src, mask, dest,
-				xSrc + src_xoff, ySrc + src_yoff,
-				xMask + msk_xoff, yMask + msk_yoff,
-				xDst + dst_xoff, yDst + dst_yoff,
+				xSrc, ySrc, xMask, yMask, xDst, yDst,
 				width, height);
     }
 
@@ -146,22 +141,22 @@ create_conical_gradient_image (PictGradient *gradient)
 
 static pixman_image_t *
 create_bits_picture (PicturePtr pict,
-		     Bool       has_clip,
-		     int	*xoff,
-		     int	*yoff)
+		     Bool       has_clip)
 {
-    PixmapPtr pixmap;
     FbBits *bits;
     FbStride stride;
-    int bpp;
+    int bpp, xoff, yoff;
     pixman_image_t *image;
     
-    fbGetDrawablePixmap (pict->pDrawable, pixmap, *xoff, *yoff);
-    fbGetPixmapBitsData(pixmap, bits, stride, bpp);
+    fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff);
+
+    bits = (FbBits*)((CARD8*)bits +
+		     (pict->pDrawable->y + yoff) * stride * sizeof(FbBits) +
+		     (pict->pDrawable->x + xoff) * (bpp / 8));
 
     image = pixman_image_create_bits (
 	(pixman_format_code_t)pict->format,
-	pixmap->drawable.width, pixmap->drawable.height,
+	pict->pDrawable->width, pict->pDrawable->height,
 	(uint32_t *)bits, stride * sizeof (FbStride));
     
     
@@ -187,55 +182,33 @@ create_bits_picture (PicturePtr pict,
 	if (pict->clientClipType != CT_NONE)
 	    pixman_image_set_has_client_clip (image, TRUE);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, *xoff, *yoff);
+	pixman_region_translate (pict->pCompositeClip, - pict->pDrawable->x, - pict->pDrawable->y);
 
 	pixman_image_set_clip_region (image, pict->pCompositeClip);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, -*xoff, -*yoff);
+	pixman_region_translate (pict->pCompositeClip, pict->pDrawable->x, pict->pDrawable->y);
     }
     
     /* Indexed table */
     if (pict->pFormat->index.devPrivate)
 	pixman_image_set_indexed (image, pict->pFormat->index.devPrivate);
 
-    /* Add in drawable origin to position within the image */
-    *xoff += pict->pDrawable->x;
-    *yoff += pict->pDrawable->y;
-
     return image;
 }
 
 static pixman_image_t *
-image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map);
+image_from_pict_internal (PicturePtr pict, Bool has_clip, Bool is_alpha_map);
 
 static void
-set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map)
+set_image_properties (pixman_image_t *image, PicturePtr pict, Bool is_alpha_map)
 {
     pixman_repeat_t repeat;
     pixman_filter_t filter;
     
     if (pict->transform)
     {
-	/* For source images, adjust the transform to account
-	 * for the drawable offset within the pixman image,
-	 * then set the offset to 0 as it will be used
-	 * to compute positions within the transformed image.
-	 */
-	if (!has_clip) {
-	    struct pixman_transform	adjusted;
-
-	    adjusted = *pict->transform;
-	    pixman_transform_translate(&adjusted,
-				       NULL,
-				       pixman_int_to_fixed(*xoff),
-				       pixman_int_to_fixed(*yoff));
-	    pixman_image_set_transform (image, &adjusted);
-	    *xoff = 0;
-	    *yoff = 0;
-	} else
-	    pixman_image_set_transform (image, pict->transform);
+	pixman_image_set_transform (
+	    image, (pixman_transform_t *)pict->transform);
     }
     
     switch (pict->repeatType)
@@ -265,8 +238,7 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
      */
     if (pict->alphaMap && !is_alpha_map)
     {
-	int alpha_xoff, alpha_yoff;
-	pixman_image_t *alpha_map = image_from_pict_internal (pict->alphaMap, FALSE, &alpha_xoff, &alpha_yoff, TRUE);
+	pixman_image_t *alpha_map = image_from_pict_internal (pict->alphaMap, TRUE, TRUE);
 	
 	pixman_image_set_alpha_map (
 	    image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
@@ -299,7 +271,8 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
 }
 
 static pixman_image_t *
-image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map)
+image_from_pict_internal (PicturePtr pict,
+		 Bool has_clip, Bool is_alpha_map)
 {
     pixman_image_t *image = NULL;
 
@@ -308,7 +281,7 @@ image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
 
     if (pict->pDrawable)
     {
-	image = create_bits_picture (pict, has_clip, xoff, yoff);
+	image = create_bits_picture (pict, has_clip);
     }
     else if (pict->pSourcePict)
     {
@@ -329,19 +302,18 @@ image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
 	    else if (sp->type == SourcePictTypeConical)
 		image = create_conical_gradient_image (gradient);
 	}
-	*xoff = *yoff = 0;
     }
     
     if (image)
-	set_image_properties (image, pict, has_clip, xoff, yoff, is_alpha_map);
+	set_image_properties (image, pict, is_alpha_map);
     
     return image;
 }
 
 pixman_image_t *
-image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+image_from_pict (PicturePtr pict, Bool has_clip)
 {
-    return image_from_pict_internal (pict, has_clip, xoff, yoff, FALSE);
+    return image_from_pict_internal (pict, has_clip, FALSE);
 }
 
 void
diff --git a/fb/fbtrap.c b/fb/fbtrap.c
index 0b5a638..fbe2647 100644
--- a/fb/fbtrap.c
+++ b/fb/fbtrap.c
@@ -39,12 +39,11 @@ fbAddTraps (PicturePtr	pPicture,
 	    xTrap	*traps)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict (pPicture, FALSE, &dst_xoff, &dst_yoff)))
+    if (!(image = image_from_pict (pPicture, FALSE)))
 	return;
     
-    pixman_add_traps (image, x_off + dst_xoff, y_off + dst_yoff,
+    pixman_add_traps (image, x_off, y_off,
 		      ntrap, (pixman_trap_t *)traps);
 
     free_pixman_pict (pPicture, image);
@@ -57,14 +56,13 @@ fbRasterizeTrapezoid (PicturePtr    pPicture,
 		      int	    y_off)
 {
     pixman_image_t *image;
-    int	dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict (pPicture, FALSE, &dst_xoff, &dst_yoff)))
+    if (!(image = image_from_pict (pPicture, FALSE)))
 	return;
 
     pixman_rasterize_trapezoid (image, (pixman_trapezoid_t *)trap,
-				x_off + dst_xoff,
-				y_off + dst_yoff);
+				x_off,
+				y_off);
 
     free_pixman_pict (pPicture, image);
 }
@@ -77,13 +75,12 @@ fbAddTriangles (PicturePtr  pPicture,
 		xTriangle *tris)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict (pPicture, FALSE, &dst_xoff, &dst_yoff)))
+    if (!(image = image_from_pict (pPicture, FALSE)))
 	return;
     
     pixman_add_triangles (image,
-			  dst_xoff + x_off, dst_yoff + y_off,
+			  x_off, y_off,
 			  ntri, (pixman_triangle_t *)tris);
 
     free_pixman_pict (pPicture, image);
@@ -110,13 +107,11 @@ fbShapes (CompositeShapesFunc	composite,
 	  const uint8_t *	shapes)
 {
     pixman_image_t *src, *dst;
-    int src_xoff, src_yoff;
-    int dst_xoff, dst_yoff;
 
     miCompositeSourceValidate (pSrc);
 
-    src = image_from_pict (pSrc, FALSE, &src_xoff, &src_yoff);
-    dst = image_from_pict (pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict (pSrc, FALSE);
+    dst = image_from_pict (pDst, TRUE);
 
     if (src && dst)
     {
@@ -136,10 +131,10 @@ fbShapes (CompositeShapesFunc	composite,
 	    for (i = 0; i < nshapes; ++i)
 	    {
 		composite (op, src, dst, format,
-			   xSrc + src_xoff,
-			   ySrc + src_yoff,
-			   dst_xoff,
-			   dst_yoff,
+			   xSrc,
+			   ySrc,
+			   0,
+			   0,
 			   1, shapes + i * shape_size);
 	    }
 	}
@@ -162,10 +157,10 @@ fbShapes (CompositeShapesFunc	composite,
 	    }
 	    
 	    composite (op, src, dst, format,
-		       xSrc + src_xoff,
-		       ySrc + src_yoff,
-		       dst_xoff,
-		       dst_yoff,
+		       xSrc,
+		       ySrc,
+		       0,
+		       0,
 		       nshapes, shapes);
 	}
 
commit d85fbd444364086e02f3d16ac1f295837a435b6c
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 30 13:08:25 2010 -0700

    Workaround the GC clipping problem in miPaintWindow and add some debugging output.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 0f1ebe5..dcbfe1c 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -521,6 +521,7 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
+#include "../fb/fb.h"
 #endif 
 
 void
@@ -548,24 +549,37 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     Bool	solid = TRUE;
     DrawablePtr	drawable = &pWin->drawable;
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("START %d BS %d (pR = %ld)\n", what, pWin->backgroundState, ParentRelative);
+    ErrorF("      Rgn: %d %d %d %d\n", prgn->extents.x1, prgn->extents.y1,
+	                               prgn->extents.x2 - prgn->extents.x1,
+	                               prgn->extents.y2 - prgn->extents.y1);
+    ErrorF("      Win: %d %d (%d %d) %d %d\n", pWin->origin.x, pWin->origin.y,
+	                                       pWin->winSize.extents.x1, pWin->winSize.extents.y1,
+	                                       pWin->winSize.extents.x2 - pWin->winSize.extents.x1,
+					       pWin->winSize.extents.y2 - pWin->winSize.extents.y1);
+    ErrorF("     Draw: %d %d %d %d\n", pWin->drawable.x, pWin->drawable.y,
+				       pWin->drawable.width, pWin->drawable.height);
+#endif
+
 #ifdef ROOTLESS
     if(!drawable || drawable->type == UNDRAWABLE_WINDOW)
 	return;
-
-    if(IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-    
-        if(pWin->backgroundState == ParentRelative) {
-            if((what == PW_BACKGROUND) || 
-               (what == PW_BORDER && !pWin->borderIsPixel))
-                RootlessSetPixmapOfAncestors(pWin);
-        }
-    }
 #endif
     
     if (what == PW_BACKGROUND)
     {
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+
+	    if(pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	while (pWin->backgroundState == ParentRelative)
 	    pWin = pWin->parent;
 
@@ -591,6 +605,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     {
 	PixmapPtr   pixmap;
 
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+	    
+	    if(!pWin->borderIsPixel &&
+		pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	tile_x_off = drawable->x;
 	tile_y_off = drawable->y;
 	
@@ -599,6 +625,12 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 	    return;
 	pixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) drawable);
 	drawable = &pixmap->drawable;
+
+#ifdef XQUARTZ_CLIP_DEBUG
+	ErrorF("     Draw: %d %d %d %d\n",
+	       drawable->x, drawable->y, drawable->width, drawable->height);    
+#endif
+	
 #ifdef COMPOSITE
 	draw_x_off = pixmap->screen_x;
 	draw_y_off = pixmap->screen_y;
@@ -661,6 +693,57 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     ChangeGC (NullClient, pGC, gcmask, gcval);
     ValidateGC (drawable, pGC);
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);
+#endif
+    
+#ifdef XQUARTZ
+    /* Looks like our clipping isn't set right for some reason:
+     * http://xquartz.macosforge.org/trac/ticket/290
+     */
+    if(what == PW_BORDER) {
+
+#if 0
+	if(solid) {
+#if 1
+	    fbFillRegionSolid(&pWin->drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       pWin->drawable.bitsPerPixel));
+#else
+	    fbFillRegionSolid(drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       drawable->bitsPerPixel));
+#endif
+	    return;
+	}
+#endif
+    
+	pGC->pCompositeClip->extents.x1 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y1 += prgn->extents.y1;
+	pGC->pCompositeClip->extents.x2 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y2 += prgn->extents.y1;
+	
+	if(pGC->pCompositeClip->extents.x2 > drawable->pScreen->width)
+	    pGC->pCompositeClip->extents.x2 = drawable->pScreen->width;
+	if(pGC->pCompositeClip->extents.y2 > drawable->pScreen->height)
+	    pGC->pCompositeClip->extents.y2 = drawable->pScreen->height;
+    }
+#endif
+
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);    
+#endif
+
     numRects = RegionNumRects(prgn);
     pbox = RegionRects(prgn);
     for (i= numRects; --i >= 0; pbox++, prect++)
commit fdf5182a730e86bd230a231db7a261b4fa7600f3
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Oct 30 14:55:06 2010 -0700

    configure.ac: Add -fno-strict-aliasing to CFLAGS
    
    This should address https://bugs.freedesktop.org/show_bug.cgi?id=31238
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/configure.ac b/configure.ac
index 811435d..1f3476b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,12 @@ XORG_PROG_RAWCPP
 # easier overrides at build time.
 XSERVER_CFLAGS='$(CWARNFLAGS)'
 
+dnl Explicitly add -fno-strict-aliasing since this option should disappear
+dnl from util-macros CWARNFLAGS
+if  test "x$GCC" = xyes ; then
+    XSERVER_CFLAGS="$XSERVER_CFLAGS -fno-strict-aliasing"
+fi
+
 dnl Check for dtrace program (needed to build Xserver dtrace probes)
 dnl Also checks for <sys/sdt.h>, since some Linux distros have an 
 dnl ISDN trace program named dtrace
commit 54e37193ede635741f92774b85728c4c7707ce2a
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Sep 24 00:01:11 2011 -0700

    Bump ABI_VIDEODRV_VERSION to 12
    
    The ABI changed in the previous series of changes, so bump the ABI version for
    the next release.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 3038c04..d274c9d 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -82,7 +82,7 @@ typedef enum {
  * mask is 0xFFFF0000.
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
-#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(11, 0)
+#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(12, 0)
 #define ABI_XINPUT_VERSION	SET_ABI_VERSION(13, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(6, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
commit aebda5478781407dff233dfa2cbc9771f328d480
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Sep 14 13:45:18 2011 -0500

    xorg-server.pc.in: Remove libpciaccess and pixman-1 from Requires
    
    Every module building against xorg-server does not *Require* pixman nor
    libpciaccess.  If such modules need pixman or pciaccess, they should be
    depending on them directly rather than inheriting a dependency from
    xorg-server.  To do this, they should use PKG_CHECK_MODULES in configure.ac
    to check for pixman-1 or pciaccess and include the apporpriate _LIBS variable
    to the appropriate _LDFLAGS variable in Makefile.am
    
    This also moves pixman-1 to Requires.private, so CPPFLAGS is set right to
    to satisfy include dependencies but avoid linking needlessly.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>

diff --git a/configure.ac b/configure.ac
index deccd78..811435d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -783,11 +783,6 @@ VIDMODEPROTO="xf86vidmodeproto >= 2.2.99.1"
 WINDOWSWMPROTO="windowswmproto"
 APPLEWMPROTO="applewmproto >= 1.4"
 
-dnl Core modules for most extensions, et al.
-SDK_REQUIRED_MODULES="[xproto >= 7.0.22] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 1.9.99.902] [kbproto >= 1.0.3] fontsproto"
-# Make SDK_REQUIRED_MODULES available for inclusion in xorg-server.pc
-AC_SUBST(SDK_REQUIRED_MODULES)
-
 dnl List of libraries that require a specific version
 LIBAPPLEWM="applewm >= 1.4"
 LIBDMX="dmx >= 1.0.99.1"
@@ -809,6 +804,11 @@ dnl specific modules against it
 PKG_CHECK_MODULES(PIXMAN, $LIBPIXMAN)
 REQUIRED_LIBS="$REQUIRED_LIBS $LIBPIXMAN $LIBXFONT xau"
 
+dnl Core modules for most extensions, et al.
+SDK_REQUIRED_MODULES="[xproto >= 7.0.22] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 1.9.99.902] [kbproto >= 1.0.3] fontsproto $LIBPIXMAN"
+# Make SDK_REQUIRED_MODULES available for inclusion in xorg-server.pc
+AC_SUBST(SDK_REQUIRED_MODULES)
+
 REQUIRED_MODULES="[fixesproto >= 5.0] [damageproto >= 1.1] [xcmiscproto >= 1.2.0] [xtrans >= 1.2.2] [bigreqsproto >= 1.1.0] $SDK_REQUIRED_MODULES"
 
 if test "x$CONFIG_UDEV" = xyes &&
@@ -1559,6 +1559,7 @@ if test "x$XORG" = xyes; then
 	if test "x$PCI" = xyes; then
 
 	PKG_CHECK_MODULES([PCIACCESS], $LIBPCIACCESS)
+	SDK_REQUIRED_MODULES="$SDK_REQUIRED_MODULES $LIBPCIACCESS"
 	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $GLX_SYS_LIBS"
 	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
 
diff --git a/xorg-server.pc.in b/xorg-server.pc.in
index fb238b5..a98eca8 100644
--- a/xorg-server.pc.in
+++ b/xorg-server.pc.in
@@ -15,7 +15,6 @@ abi_extension=@abi_extension@
 Name: xorg-server
 Description: Modular X.Org X Server
 Version: @PACKAGE_VERSION@
-Requires: pixman-1 pciaccess
 Requires.private: @SDK_REQUIRED_MODULES@
 Cflags: -I${sdkdir} @symbol_visibility@
 Libs: -L${libdir}
commit 601b46ceeb454deed050aa761af91275456999e9
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Sep 14 10:37:38 2011 -0500

    darwin: configure: Force some irrelevant options to off on darwin
    
    This removes the need to pass the following to configure on darwin:
    --disable-pciaccess -disable-int10-module --disable-vbe --disable-vgahw --disable-libdrm
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/configure.ac b/configure.ac
index e72dffc..deccd78 100644
--- a/configure.ac
+++ b/configure.ac
@@ -718,6 +718,11 @@ case $host_os in
 		XV=no
 		;;
 	darwin*)
+		PCI=no
+		INT10MODULE=no
+		VGAHW=no
+		VBE=no
+		DRM=no
 		DRI2=no
 
 		if test x$XQUARTZ = xauto; then
commit 8d2ab25e06dcea3200456fedd8d11cbeb4468779
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Sep 14 15:42:19 2011 -0500

    xfree86: Link modules with -module
    
    This makes a difference on darwin (and apparently nowhere else)
    
    https://www.gnu.org/s/libtool/manual/libtool.html#Modules-for-libltdl
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>

diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am
index 1a162ab..b6eb54f 100644
--- a/hw/xfree86/dixmods/Makefile.am
+++ b/hw/xfree86/dixmods/Makefile.am
@@ -30,21 +30,21 @@ INCLUDES = @XORG_INCS@ \
            -I$(top_srcdir)/miext/shadow \
            -I$(top_srcdir)/glx
 
-libdbe_la_LDFLAGS = -avoid-version
+libdbe_la_LDFLAGS = -module -avoid-version
 libdbe_la_LIBADD = $(top_builddir)/dbe/libdbe.la
 libdbe_la_SOURCES = dbemodule.c
 
-libfb_la_LDFLAGS = -avoid-version
+libfb_la_LDFLAGS = -module -avoid-version
 libfb_la_LIBADD = $(top_builddir)/fb/libfb.la
 libfb_la_SOURCES = $(top_builddir)/fb/fbcmap_mi.c fbmodule.c
 libfb_la_CFLAGS = $(AM_CFLAGS)
 
-libwfb_la_LDFLAGS = -avoid-version
+libwfb_la_LDFLAGS = -module -avoid-version
 libwfb_la_LIBADD = $(top_builddir)/fb/libwfb.la
 libwfb_la_SOURCES = $(top_builddir)/fb/fbcmap_mi.c fbmodule.c
 libwfb_la_CFLAGS = $(AM_CFLAGS) -DFB_ACCESS_WRAPPER
 
-libglx_la_LDFLAGS = -avoid-version
+libglx_la_LDFLAGS = -module -avoid-version
 if AIGLX_DRI_LOADER
 GLXDRI_LIBRARY = $(top_builddir)/glx/libglxdri.la
 endif
@@ -53,11 +53,11 @@ libglx_la_LIBADD = \
 	$(GLXDRI_LIBRARY)
 libglx_la_SOURCES = glxmodule.c
 
-librecord_la_LDFLAGS = -avoid-version
+librecord_la_LDFLAGS = -module -avoid-version
 librecord_la_LIBADD = $(top_builddir)/record/librecord.la
 librecord_la_SOURCES = recordmod.c
 
-libshadow_la_LDFLAGS = -avoid-version
+libshadow_la_LDFLAGS = -module -avoid-version
 libshadow_la_LIBADD = $(top_builddir)/miext/shadow/libshadow.la
 libshadow_la_SOURCES = shmodule.c
 
diff --git a/hw/xfree86/dixmods/extmod/Makefile.am b/hw/xfree86/dixmods/extmod/Makefile.am
index cce19f7..87c28a4 100644
--- a/hw/xfree86/dixmods/extmod/Makefile.am
+++ b/hw/xfree86/dixmods/extmod/Makefile.am
@@ -21,7 +21,7 @@ INCLUDES = @XORG_INCS@ \
            -I$(top_srcdir)/hw/xfree86/loader \
            -I$(top_srcdir)/miext/shadow
 
-libextmod_la_LDFLAGS = -avoid-version
+libextmod_la_LDFLAGS = -module -avoid-version
 libextmod_la_SOURCES = modinit.c \
                        modinit.h \
                        $(DGA_SRCS) \
diff --git a/hw/xfree86/exa/Makefile.am b/hw/xfree86/exa/Makefile.am
index 39f7a90..3ced531 100644
--- a/hw/xfree86/exa/Makefile.am
+++ b/hw/xfree86/exa/Makefile.am
@@ -2,7 +2,7 @@ SUBDIRS = man
 
 module_LTLIBRARIES = libexa.la
 
-libexa_la_LDFLAGS = -avoid-version
+libexa_la_LDFLAGS = -module -avoid-version
 
 INCLUDES = \
 	$(XORG_INCS) \
diff --git a/hw/xfree86/fbdevhw/Makefile.am b/hw/xfree86/fbdevhw/Makefile.am
index 2a03890..4472acd 100644
--- a/hw/xfree86/fbdevhw/Makefile.am
+++ b/hw/xfree86/fbdevhw/Makefile.am
@@ -2,7 +2,7 @@ SUBDIRS = man
 
 module_LTLIBRARIES = libfbdevhw.la
 
-libfbdevhw_la_LDFLAGS = -avoid-version
+libfbdevhw_la_LDFLAGS = -module -avoid-version
 
 if FBDEVHW
 libfbdevhw_la_SOURCES = fbdevhw.c
diff --git a/hw/xfree86/shadowfb/Makefile.am b/hw/xfree86/shadowfb/Makefile.am
index 02d2dd4..39c6610 100644
--- a/hw/xfree86/shadowfb/Makefile.am
+++ b/hw/xfree86/shadowfb/Makefile.am
@@ -1,5 +1,5 @@
 module_LTLIBRARIES = libshadowfb.la
-libshadowfb_la_LDFLAGS = -avoid-version
+libshadowfb_la_LDFLAGS = -module -avoid-version
 libshadowfb_la_SOURCES = sfbmodule.c shadow.c
 
 sdk_HEADERS = shadowfb.h
diff --git a/hw/xfree86/vbe/Makefile.am b/hw/xfree86/vbe/Makefile.am
index 85c6fd8..4b794e6 100644
--- a/hw/xfree86/vbe/Makefile.am
+++ b/hw/xfree86/vbe/Makefile.am
@@ -1,5 +1,5 @@
 module_LTLIBRARIES = libvbe.la
-libvbe_la_LDFLAGS = -avoid-version
+libvbe_la_LDFLAGS = -module -avoid-version
 libvbe_la_SOURCES = vbe.c vbeModes.c vbe_module.c
 
 sdk_HEADERS = vbe.h vbeModes.h
diff --git a/hw/xfree86/xaa/Makefile.am b/hw/xfree86/xaa/Makefile.am
index 5bfb4e9..7ebe0b9 100644
--- a/hw/xfree86/xaa/Makefile.am
+++ b/hw/xfree86/xaa/Makefile.am
@@ -8,7 +8,7 @@ MSB_FIXED = mf-xaaBitmap.c mf-xaaStipple.c mf-xaaTEGlyph.c
 MSB_3_FIXED = mf3-xaaBitmap.c mf3-xaaStipple.c
 POLYSEG = s-xaaLine.c s-xaaDashLine.c
 
-libxaa_la_LDFLAGS = -avoid-version
+libxaa_la_LDFLAGS = -module -avoid-version
 if COMPOSITE
 libxaa_la_LIBADD = $(top_builddir)/miext/cw/libcw.la
 endif
commit 00c1b7cf5178e3076345df709e11f0d6159e33c2
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Sep 14 12:14:56 2011 -0500

    xfree86: fbdevhw: Remove unused include of pciaccess.h
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/hw/xfree86/fbdevhw/fbdevhw.h b/hw/xfree86/fbdevhw/fbdevhw.h
index bc46b9c..34870c2 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.h
+++ b/hw/xfree86/fbdevhw/fbdevhw.h
@@ -5,8 +5,6 @@
 #include "xf86str.h"
 #include "colormapst.h"
 
-#include <pciaccess.h>
-
 #define FBDEVHW_PACKED_PIXELS		0	/* Packed Pixels	*/
 #define FBDEVHW_PLANES			1	/* Non interleaved planes */
 #define FBDEVHW_INTERLEAVED_PLANES	2	/* Interleaved planes	*/
commit 7d32bde6f32559ea61d736977f008b64d4cc2b40
Author: Tiago Vignatti <tiago.vignatti at nokia.com>
Date:   Tue Jun 1 13:05:47 2010 +0300

    configure: wrap PCI code with macro and set it at build time
    
    --disable-pciaccess, used together with --disable-module-int10, can be used to
    disable all pci code inside the server.
    
    Note that XSERVER_LIBPCIACCESS was previously used only in the driver side and
    now it defines also whether the library is used inside the server. Also,
    XORG_BUS_PCI automake variable is introduced to track PCI code needs.
    
    Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Built-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/configure.ac b/configure.ac
index 0c0d4c5..e72dffc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -637,6 +637,7 @@ AC_ARG_ENABLE(int10-module,     AS_HELP_STRING([--enable-int10-module], [Build X
 AC_ARG_ENABLE(windowswm,      AS_HELP_STRING([--enable-windowswm], [Build XWin with WindowsWM extension (default: no)]), [WINDOWSWM=$enableval], [WINDOWSWM=no])
 AC_ARG_ENABLE(libdrm,         AS_HELP_STRING([--enable-libdrm], [Build Xorg with libdrm support (default: enabled)]), [DRM=$enableval],[DRM=yes])
 AC_ARG_ENABLE(clientids,      AS_HELP_STRING([--disable-clientids], [Build Xorg with client ID tracking (default: enabled)]), [CLIENTIDS=$enableval], [CLIENTIDS=yes])
+AC_ARG_ENABLE(pciaccess, AS_HELP_STRING([--enable-pciaccess], [Build Xorg with pciaccess library (default: enabled)]), [PCI=$enableval], [PCI=yes])
 
 dnl DDXes.
 AC_ARG_ENABLE(xorg,    	      AS_HELP_STRING([--enable-xorg], [Build Xorg server (default: auto)]), [XORG=$enableval], [XORG=auto])
@@ -1549,6 +1550,9 @@ if test "x$XORG" = xyes; then
 	xorg_bus_bsdpci=no
 	xorg_bus_sparc=no
 
+	AC_MSG_CHECKING([whether to build Xorg PCI functions])
+	if test "x$PCI" = xyes; then
+
 	PKG_CHECK_MODULES([PCIACCESS], $LIBPCIACCESS)
 	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $GLX_SYS_LIBS"
 	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
@@ -1568,6 +1572,10 @@ if test "x$XORG" = xyes; then
         xorg_bus_sparc="yes"
         ;;
 	esac
+	fi
+	AC_MSG_RESULT([$PCI])
+
+	AM_CONDITIONAL([XORG_BUS_PCI], [test "x$PCI" = xyes])
 	AM_CONDITIONAL([XORG_BUS_LINUXPCI], [test "x$xorg_bus_linuxpci" = xyes])
 	AM_CONDITIONAL([XORG_BUS_BSDPCI], [test "x$xorg_bus_bsdpci" = xyes])
 	AM_CONDITIONAL([XORG_BUS_SPARC], [test "x$xorg_bus_sparc" = xyes])
diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 23ddb5c..a273721 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -1,5 +1,10 @@
 noinst_LTLIBRARIES = libcommon.la
 
+if XORG_BUS_PCI
+PCI_SOURCES = xf86pciBus.c xf86VGAarbiter.c xf86VGAarbiter.h \
+              xf86VGAarbiterPriv.h
+endif
+
 if XORG_BUS_SPARC
 SBUS_SOURCES = xf86sbusBus.c
 endif
@@ -19,7 +24,7 @@ endif
 
 RANDRSOURCES = xf86RandR.c
 
-BUSSOURCES = xf86pciBus.c xf86fbBus.c xf86noBus.c $(SBUS_SOURCES)
+BUSSOURCES = xf86fbBus.c xf86noBus.c $(PCI_SOURCES) $(SBUS_SOURCES)
 
 MODEDEFSOURCES = $(srcdir)/vesamodes $(srcdir)/extramodes
 
@@ -33,7 +38,7 @@ AM_LDFLAGS = -r
 libcommon_la_SOURCES = xf86Configure.c xf86ShowOpts.c xf86Bus.c xf86Config.c \
                       xf86Cursor.c $(DGASOURCES) xf86DPMS.c \
                       xf86Events.c xf86Globals.c xf86AutoConfig.c \
-                      xf86Option.c xf86Init.c xf86VGAarbiter.c \
+                      xf86Option.c xf86Init.c \
                       xf86VidMode.c xf86fbman.c xf86cmap.c \
                       xf86Helper.c xf86PM.c xf86Xinput.c xisb.c \
                       xf86Mode.c xorgHelper.c \
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index da9287b..3185baf 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -92,6 +92,7 @@ extern _X_EXPORT Bool VTSwitchEnabled;	/* kbd driver */
 #ifndef _NO_XF86_PROTOTYPES
 
 /* PCI related */
+#ifdef XSERVER_LIBPCIACCESS
 #include <pciaccess.h>
 extern _X_EXPORT Bool pciSlotClaimed;
 
@@ -118,6 +119,15 @@ extern _X_EXPORT ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn,
 extern _X_EXPORT Bool xf86ConfigActivePciEntity(ScrnInfoPtr pScrn,
         int entityIndex,PciChipsets *p_chip, void *dummy, EntityProc init,
         EntityProc enter, EntityProc leave, pointer private);
+#else
+#define xf86VGAarbiterInit() do {} while (0)
+#define xf86VGAarbiterFini() do {} while (0)
+#define xf86VGAarbiterLock(x) do {} while (0)
+#define xf86VGAarbiterUnlock(x) do {} while (0)
+#define xf86VGAarbiterScrnInit(x) do {} while (0)
+#define xf86VGAarbiterDeviceDecodes() do {} while (0)
+#define xf86VGAarbiterWrapFunctions() do {} while (0)
+#endif
 
 /* xf86Bus.c */
 
diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 5c6e721..7fc6518 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -255,9 +255,9 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
 	    matches[i++] = xnfstrdup(sbusDriver);
     }
 #endif
-
+#ifdef XSERVER_LIBPCIACCESS
     i = xf86PciMatchDriver(matches, nmatches);
-
+#endif
     /* Fallback to platform default hardware */
     if (i < (nmatches - 1)) {
 #if defined(__i386__) || defined(__amd64__) || defined(__hurd__)
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 8749a29..c665a20 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -47,8 +47,9 @@
 
 #define XF86_OS_PRIVS
 #include "xf86_OSproc.h"
+#ifdef XSERVER_LIBPCIACCESS
 #include "xf86VGAarbiter.h"
-
+#endif
 /* Entity data */
 EntityPtr *xf86Entities = NULL;	/* Bus slots claimed by drivers */
 int xf86NumEntities = 0;
@@ -75,7 +76,7 @@ Bool
 xf86CallDriverProbe( DriverPtr drv, Bool detect_only )
 {
     Bool     foundScreen = FALSE;
-
+#ifdef XSERVER_LIBPCIACCESS
     if (drv->PciProbe != NULL) {
         if (xf86DoConfigure && xf86DoConfigurePass1) {
             assert(detect_only);
@@ -86,7 +87,7 @@ xf86CallDriverProbe( DriverPtr drv, Bool detect_only )
             foundScreen = xf86PciProbeDev(drv);
         }
     }
-
+#endif
     if (!foundScreen && (drv->Probe != NULL)) {
         xf86Msg( X_WARNING, "Falling back to old probe method for %s\n",
                              drv->driverName);
@@ -195,7 +196,9 @@ xf86BusConfig(void)
 void
 xf86BusProbe(void)
 {
+#ifdef XSERVER_LIBPCIACCESS
     xf86PciProbe();
+#endif
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
     xf86SbusProbe();
 #endif
@@ -504,9 +507,14 @@ xf86PostProbe(void)
 {
     int i;
 
-    if (fbSlotClaimed && (pciSlotClaimed
+    if (fbSlotClaimed && (
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
-	    || sbusSlotClaimed
+	    sbusSlotClaimed ||
+#endif
+#ifdef XSERVER_LIBPCIACCESS
+	    pciSlotClaimed
+#else
+        TRUE
 #endif
 	    ))
 	    FatalError("Cannot run in framebuffer mode. Please specify busIDs "
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index e6c4d8f..8a1177c 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -2409,7 +2409,7 @@ xf86HandleConfigFile(Bool autoconfig)
     }
 
     xf86ProcessOptions(-1, xf86ConfigLayout.options, LayoutOptions);
-
+#ifdef XSERVER_LIBPCIACCESS
     if ((scanptr = xf86GetOptValString(LayoutOptions, LAYOUT_ISOLATEDEVICE))) {
        ; /* IsolateDevice specified; overrides SingleCard */
     } else {
@@ -2424,7 +2424,7 @@ xf86HandleConfigFile(Bool autoconfig)
        } else
            xf86PciIsolateDevice(scanptr);
     }
-
+#endif
     /* Now process everything else */
     if (!configServerFlags(xf86configptr->conf_flags,xf86ConfigLayout.options)){
              ErrorF ("Problem when converting the config data structures\n");
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index ab07515..99b8b48 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -87,9 +87,11 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int
     /* Check for duplicates */
     for (i = 0;  i < nDevToConfig;  i++) {
         switch (bus) {
+#ifdef XSERVER_LIBPCIACCESS
             case BUS_PCI:
                 ret = xf86PciConfigure(busData, DevToConfig[i].pVideo);
-                break;
+	            break;
+#endif
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
             case BUS_SBUS:
                 ret = xf86SbusConfigure(busData, DevToConfig[i].sVideo);
@@ -118,10 +120,12 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int
     for (j = 0;  (DevToConfig[i].GDev.driver[j] = tolower(driver[j]));  j++);
 
     switch (bus) {
+#ifdef XSERVER_LIBPCIACCESS
         case BUS_PCI:
             xf86PciConfigureNewDev(busData, DevToConfig[i].pVideo,
                                    &DevToConfig[i].GDev, &chipset);
 	        break;
+#endif
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
         case BUS_SBUS:
             xf86SbusConfigureNewDev(busData, DevToConfig[i].sVideo,
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index cd025dc..613c7cf 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -42,8 +42,9 @@
 #include <X11/extensions/dpmsconst.h>
 #include "dpmsproc.h"
 #endif
+#ifdef XSERVER_LIBPCIACCESS
 #include "xf86VGAarbiter.h"
-
+#endif
 
 #ifdef DPMSExtension
 static DevPrivateKeyRec DPMSKeyRec;
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 350918d..74e0bc2 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -78,7 +78,9 @@
 #include "picturestr.h"
 
 #include "xf86Bus.h"
+#ifdef XSERVER_LIBPCIACCESS
 #include "xf86VGAarbiter.h"
+#endif
 #include "globals.h"
 #include "xserver-properties.h"
 
@@ -88,7 +90,6 @@
 #endif
 #include <hotplug.h>
 
-
 #ifdef XF86PM
 void (*xf86OSPMClose)(void) = NULL;
 #endif
@@ -1355,6 +1356,7 @@ ddxProcessArgument(int argc, char **argv, int i)
     xf86DoShowOptions = TRUE;
     return 1;
   }
+#ifdef XSERVER_LIBPCIACCESS
   if (!strcmp(argv[i], "-isolateDevice"))
   {
     CHECK_FOR_REQUIRED_ARGUMENT();
@@ -1364,6 +1366,7 @@ ddxProcessArgument(int argc, char **argv, int i)
     xf86PciIsolateDevice(argv[i]);
     return 2;
   }
+#endif
   /* Notice cmdline xkbdir, but pass to dix as well */
   if (!strcmp(argv[i], "-xkbdir"))
   {
@@ -1432,7 +1435,9 @@ ddxUseMsg(void)
 #endif
   ErrorF("-allowMouseOpenFail    start server even if the mouse can't be initialized\n");
   ErrorF("-ignoreABI             make module ABI mismatches non-fatal\n");
+#ifdef XSERVER_LIBPCIACCESS
   ErrorF("-isolateDevice bus_id  restrict device resets to bus_id (PCI only)\n");
+#endif
   ErrorF("-version               show the server version\n");
   ErrorF("-showDefaultModulePath show the server default module path\n");
   ErrorF("-showDefaultLibPath    show the server default library path\n");
diff --git a/hw/xfree86/common/xf86fbBus.c b/hw/xfree86/common/xf86fbBus.c
index 059e378..4592980 100644
--- a/hw/xfree86/common/xf86fbBus.c
+++ b/hw/xfree86/common/xf86fbBus.c
@@ -54,8 +54,10 @@ xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active)
     EntityPtr p;
     int num;
 
+#ifdef XSERVER_LIBPCIACCESS
     if (pciSlotClaimed)
 	return -1;
+#endif
 #if defined(__sparc__) || defined (__sparc64__)
     if (sbusSlotClaimed)
 	return -1;
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 43e9d1d..e2ca558 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -41,9 +41,6 @@
 #include "colormapst.h"
 #include "xf86Module.h"
 #include "xf86Opt.h"
-#include "xf86Pci.h"
-
-#include <pciaccess.h>
 
 /**
  * Integer type that is of the size of the addressable memory (machine size).
@@ -309,6 +306,8 @@ typedef struct {
 struct _SymTabRec;
 struct _PciChipsets;
 
+struct pci_device;
+
 typedef struct _DriverRec {
     int			driverVersion;
     char *		driverName;
@@ -350,8 +349,6 @@ typedef enum {
     BUS_last    /* Keep last */
 } BusType;
 
-struct pci_device;
-
 typedef struct {
     int		fbNum;
 } SbusBusId;
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index 23c48eb..e244a2d 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <stdio.h>
 
+#include <X11/Xarch.h>
 #include "xf86.h"
 #include "xf86DDC.h"
 #include "xf86Crtc.h"
diff --git a/hw/xfree86/os-support/bus/Makefile.am b/hw/xfree86/os-support/bus/Makefile.am
index 16c1021..e09d4d2 100644
--- a/hw/xfree86/os-support/bus/Makefile.am
+++ b/hw/xfree86/os-support/bus/Makefile.am
@@ -1,7 +1,10 @@
 noinst_LTLIBRARIES = libbus.la
 sdk_HEADERS = xf86Pci.h
 
-PCI_SOURCES = Pci.c Pci.h
+PCI_SOURCES =
+if XORG_BUS_PCI
+PCI_SOURCES += Pci.c Pci.h
+endif
 
 if XORG_BUS_BSDPCI
 PCI_SOURCES += bsd_pci.c
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 18bb735..19795d5 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -118,14 +118,16 @@ cat > sdksyms.c << EOF
 #include "xf86.h"
 #include "xf86Module.h"
 #include "xf86Opt.h"
-#include "xf86PciInfo.h"
+#ifdef XSERVER_LIBPCIACCESS
+ #include "xf86PciInfo.h"
+ #include "xf86VGAarbiter.h"
+#endif
 #include "xf86Priv.h"
 #include "xf86Privstr.h"
 #include "xf86cmap.h"
 #include "xf86fbman.h"
 #include "xf86str.h"
 #include "xf86Xinput.h"
-#include "xf86VGAarbiter.h"
 #include "xisb.h"
 #if XV
 # include "xf86xv.h"
@@ -170,7 +172,9 @@ cat > sdksyms.c << EOF
 
 
 /* hw/xfree86/os-support/bus/Makefile.am */
-#include "xf86Pci.h"
+#ifdef XSERVER_LIBPCIACCESS
+# include "xf86Pci.h"
+#endif
 #if defined(__sparc__) || defined(__sparc)
 # include "xf86Sbus.h"
 #endif
diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
index 33bf908..6b9230f 100644
--- a/include/xorg-config.h.in
+++ b/include/xorg-config.h.in
@@ -127,4 +127,7 @@
 /* Build with libdrm support */
 #undef WITH_LIBDRM
 
+/* Use libpciaccess */
+#undef XSERVER_LIBPCIACCESS
+
 #endif /* _XORG_CONFIG_H_ */
commit 4736ea0c10a4e4ec5fbb6ad662fad28b839cce1e
Author: Tiago Vignatti <tiago.vignatti at nokia.com>
Date:   Mon May 31 19:27:07 2010 +0300

    configure: make PCI configuration more sane
    
    No semantical changes. Just moved code around, grouping PCI related stuff in a
    single chunk.
    
    Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Built-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/configure.ac b/configure.ac
index 7efc4c6..0c0d4c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1245,7 +1245,6 @@ if test "x$XDMAUTH" = xyes; then
 fi
 
 AC_DEFINE_DIR(COMPILEDDEFAULTFONTPATH, FONTPATH, [Default font path])
-AC_DEFINE_DIR(PCI_TXT_IDS_PATH, PCI_TXT_IDS_DIR, [Default PCI text file ID path])
 AC_DEFINE_DIR(SERVER_MISC_CONFIG_PATH, SERVERCONFIG, [Server miscellaneous config path])
 AC_DEFINE_DIR(BASE_FONT_PATH, FONTROOTDIR, [Default base font path])
 dridriverdir=`$PKG_CONFIG --variable=dridriverdir dri`
@@ -1496,9 +1495,6 @@ if test "x$XORG" = xauto; then
 fi
 AC_MSG_RESULT([$XORG])
 
-xorg_bus_bsdpci=no
-xorg_bus_sparc=no
-
 if test "x$XORG" = xyes; then
 	XORG_DDXINCS='-I$(top_srcdir)/hw/xfree86 -I$(top_srcdir)/hw/xfree86/include -I$(top_srcdir)/hw/xfree86/common'
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
@@ -1546,10 +1542,39 @@ if test "x$XORG" = xyes; then
 	AC_SUBST([symbol_visibility])
 	dnl ===================================================================
 
+	dnl ===================================================================
+	dnl ================= beginning of PCI configuration ==================
+	dnl ===================================================================
+	xorg_bus_linuxpci=no
+	xorg_bus_bsdpci=no
+	xorg_bus_sparc=no
+
 	PKG_CHECK_MODULES([PCIACCESS], $LIBPCIACCESS)
 	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $GLX_SYS_LIBS"
 	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
 
+	AC_DEFINE(XSERVER_LIBPCIACCESS, 1, [Use libpciaccess for all pci manipulation])
+	AC_DEFINE_DIR(PCI_TXT_IDS_PATH, PCI_TXT_IDS_DIR, [Default PCI text file ID path])
+    case $host_os in
+      linux*)
+		xorg_bus_linuxpci="yes"
+		;;
+	  gnu* | freebsd* | kfreebsd*-gnu | netbsd* | openbsd* | solaris* | dragonfly*)
+		xorg_bus_bsdpci="yes"
+		;;
+	esac
+    case $host_cpu in
+      sparc*)
+        xorg_bus_sparc="yes"
+        ;;
+	esac
+	AM_CONDITIONAL([XORG_BUS_LINUXPCI], [test "x$xorg_bus_linuxpci" = xyes])
+	AM_CONDITIONAL([XORG_BUS_BSDPCI], [test "x$xorg_bus_bsdpci" = xyes])
+	AM_CONDITIONAL([XORG_BUS_SPARC], [test "x$xorg_bus_sparc" = xyes])
+	dnl ===================================================================
+	dnl ==================== end of PCI configuration =====================
+	dnl ===================================================================
+
 	case $host_os in
 	  linux*)
 		if test "x$LNXAPM" = xyes; then
@@ -1570,11 +1595,9 @@ if test "x$XORG" = xyes; then
 		;;
 	  freebsd* | kfreebsd*-gnu | dragonfly*)
 		XORG_OS_SUBDIR="bsd"
-		xorg_bus_bsdpci="yes"
 		;;
 	  netbsd*)
 		XORG_OS_SUBDIR="bsd"
-		xorg_bus_bsdpci="yes"
 		;;
 	  openbsd*)
 		if test "x$ac_cv_BSD_APM" = xyes \
@@ -1582,14 +1605,10 @@ if test "x$XORG" = xyes; then
 			XORG_CFLAGS="$XORG_CFLAGS -DXF86PM"
 		fi
 		XORG_OS_SUBDIR="bsd"
-		xorg_bus_bsdpci="yes"
 		;;
 	  solaris*)
 		XORG_OS_SUBDIR="solaris"
 		XORG_CFLAGS="$XORG_CFLAGS -DXF86PM"
-		# Use the same stubs as BSD for old functions, since we now
-		# use libpciaccess for PCI
-		xorg_bus_bsdpci="yes"
 		AC_CHECK_HEADERS([sys/kd.h])
 		AC_CHECK_HEADERS([sys/vt.h], [solaris_vt=yes], [solaris_vt=no])
 		# Check for minimum supported release
@@ -1634,9 +1653,6 @@ if test "x$XORG" = xyes; then
 		;;
 	  gnu*)
 		XORG_OS_SUBDIR="hurd"
-		# Use the same stubs as BSD for old functions, since we now
-		# use libpciaccess for PCI
-		xorg_bus_bsdpci="yes"
 		;;
 	  *)
 		XORG_OS_SUBDIR="stub"
@@ -1649,9 +1665,6 @@ if test "x$XORG" = xyes; then
 	esac
 
 	case $host_cpu in
-	  sparc*)
-		xorg_bus_sparc="yes"
-		;;
 	  i*86)
 		;;
 	esac
@@ -1708,7 +1721,6 @@ if test "x$XORG" = xyes; then
 	AC_DEFINE_DIR(DEFAULT_LIBRARY_PATH, libdir, [Default library install path])
 	AC_DEFINE_DIR(DEFAULT_LOGPREFIX, LOGPREFIX, [Default log location])
 	AC_DEFINE_UNQUOTED(__VENDORDWEBSUPPORT__, ["$VENDOR_WEB"], [Vendor web address for support])
-	AC_DEFINE(XSERVER_LIBPCIACCESS, 1, [Use libpciaccess for all pci manipulation])
 	if test "x$VGAHW" = xyes; then
 		AC_DEFINE(WITH_VGAHW, 1, [Building vgahw module])
 	fi
@@ -1738,8 +1750,6 @@ if test "x$XORG" = xyes; then
 	AC_SUBST([abi_extension])
 fi
 AM_CONDITIONAL([XORG], [test "x$XORG" = xyes])
-AM_CONDITIONAL([XORG_BUS_BSDPCI], [test "x$xorg_bus_bsdpci" = xyes])
-AM_CONDITIONAL([XORG_BUS_SPARC], [test "x$xorg_bus_sparc" = xyes])
 AM_CONDITIONAL([LINUX_ALPHA], [test "x$linux_alpha" = xyes])
 AM_CONDITIONAL([LNXACPI], [test "x$linux_acpi" = xyes])
 AM_CONDITIONAL([SOLARIS_ASM_INLINE], [test "x$solaris_asm_inline" = xyes])
commit 73c3a253b4d6c2a9fa4bee5d3574916f4768bc59
Author: Tiago Vignatti <tiago.vignatti at nokia.com>
Date:   Mon May 31 18:50:50 2010 +0300

    configure: change PCI function checking by a meaningful version of the library
    
    Version 0.10.7 of libpciaccess contains all functions being checked by
    autoconf, so use it instead.
    
    People that don't want VGA arbiter active can go to the library and enable the
    stubs there.
    
    Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Built-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/configure.ac b/configure.ac
index d22bd4e..7efc4c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -792,7 +792,7 @@ LIBXEXT="xext >= 1.0.99.4"
 LIBXFONT="xfont >= 1.4.2"
 LIBXI="xi >= 1.2.99.1"
 LIBXTST="xtst >= 1.0.99.2"
-LIBPCIACCESS="pciaccess >= 0.8.0"
+LIBPCIACCESS="pciaccess >= 0.10.7"
 LIBUDEV="libudev >= 143"
 LIBSELINUX="libselinux >= 2.0.86"
 LIBDBUS="dbus-1 >= 1.0"
@@ -1547,16 +1547,6 @@ if test "x$XORG" = xyes; then
 	dnl ===================================================================
 
 	PKG_CHECK_MODULES([PCIACCESS], $LIBPCIACCESS)
-	SAVE_LIBS=$LIBS
-	SAVE_CFLAGS=$CFLAGS
-	CFLAGS=$PCIACCESS_CFLAGS
-	LIBS=$PCIACCESS_LIBS
-	AC_CHECK_FUNCS([pci_system_init_dev_mem])
-	AC_CHECK_FUNCS([pci_device_enable])
-	AC_CHECK_FUNCS([pci_device_is_boot_vga])
-	AC_CHECK_FUNCS([pci_device_vgaarb_init])
-	LIBS=$SAVE_LIBS
-	CFLAGS=$SAVE_CFLAGS
 	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $GLX_SYS_LIBS"
 	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
 
diff --git a/hw/xfree86/common/xf86VGAarbiter.c b/hw/xfree86/common/xf86VGAarbiter.c
index 215e845..819ad6e 100644
--- a/hw/xfree86/common/xf86VGAarbiter.c
+++ b/hw/xfree86/common/xf86VGAarbiter.c
@@ -31,8 +31,6 @@
 #include "xorg-config.h"
 
 #include "xf86VGAarbiter.h"
-
-#ifdef HAVE_PCI_DEVICE_VGAARB_INIT
 #include "xf86VGAarbiterPriv.h"
 #include "xf86Bus.h"
 #include "xf86Priv.h"
@@ -1112,16 +1110,3 @@ VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, xRenderColor *color, int nRe
     VGAPut();
     PICTURE_EPILOGUE (CompositeRects, VGAarbiterCompositeRects);
 }
-#else
-/* dummy functions */
-void xf86VGAarbiterInit(void) {}
-void xf86VGAarbiterFini(void) {}
-
-void xf86VGAarbiterLock(ScrnInfoPtr pScrn) {}
-void xf86VGAarbiterUnlock(ScrnInfoPtr pScrn) {}
-Bool xf86VGAarbiterAllowDRI(ScreenPtr pScreen) { return TRUE; }
-void xf86VGAarbiterScrnInit(ScrnInfoPtr pScrn) {}
-void xf86VGAarbiterDeviceDecodes(ScrnInfoPtr pScrn, int rsrc) {}
-Bool xf86VGAarbiterWrapFunctions(void) { return FALSE; }
-
-#endif
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 2acf486..eb5323c 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -121,12 +121,10 @@ xf86PciProbe(void)
 	    xf86PciVideoInfo[num - 1] = info;
 
 	    pci_device_probe(info);
-#ifdef HAVE_PCI_DEVICE_IS_BOOT_VGA
 	    if (pci_device_is_boot_vga(info)) {
                 primaryBus.type = BUS_PCI;
                 primaryBus.id.pci = info;
             }
-#endif
 	    info->user_data = 0;
 	}
     }
diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index 7b4cea7..d54656f 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -175,10 +175,8 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 	checkDevMem(TRUE);
 	pVidMem->linearSupported = useDevMem;
 
-#if HAVE_PCI_SYSTEM_INIT_DEV_MEM
 	if (useDevMem)
 		pci_system_init_dev_mem(devMemFd);
-#endif
 
 #ifdef HAS_MTRR_SUPPORT
 	if (useDevMem) {
diff --git a/hw/xfree86/os-support/linux/int10/linux.c b/hw/xfree86/os-support/linux/int10/linux.c
index 2965b37..564447f 100644
--- a/hw/xfree86/os-support/linux/int10/linux.c
+++ b/hw/xfree86/os-support/linux/int10/linux.c
@@ -261,10 +261,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
 	    struct pci_device *rom_device =
 		xf86GetPciInfoForEntity(pInt->entityIndex);
 
-#if HAVE_PCI_DEVICE_ENABLE
 	    pci_device_enable(rom_device);
-#endif
-
 	    err = pci_device_read_rom(rom_device, (unsigned char *)(V_BIOS));
 	    if (err) {
 		xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (%s)\n",
diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
index 0d1ea91..33bf908 100644
--- a/include/xorg-config.h.in
+++ b/include/xorg-config.h.in
@@ -118,18 +118,6 @@
 /* Have execinfo.h */
 #undef HAVE_EXECINFO_H
 
-/* Have pci_system_init_dev_mem() */
-#undef HAVE_PCI_SYSTEM_INIT_DEV_MEM
-
-/* Define to 1 if you have the `pci_device_is_boot_vga' function. */
-#undef HAVE_PCI_DEVICE_IS_BOOT_VGA
-
-/* Have pci_enable_device */
-#undef HAVE_PCI_DEVICE_ENABLE
-
-/* Define to 1 if you have the `pci_device_vgaarb_init' function. */
-#undef HAVE_PCI_DEVICE_VGAARB_INIT
-
 /* Path to text files containing PCI IDs */
 #undef PCI_TXT_IDS_PATH
 
commit 1af6365c988f2d9b58c432e8755845e1ecccb3b8
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Tue Sep 13 15:32:16 2011 -0500

    xfree86: Work around issue where ar may be told to make an archive with no contents
    
    Automake:
    
     "Be careful when selecting library components conditionally. Because building
     an empty library is not portable, you should ensure that any library
     always contains at least one object."
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>

diff --git a/hw/xfree86/os-support/bus/Makefile.am b/hw/xfree86/os-support/bus/Makefile.am
index b1ca8f9..16c1021 100644
--- a/hw/xfree86/os-support/bus/Makefile.am
+++ b/hw/xfree86/os-support/bus/Makefile.am
@@ -12,7 +12,7 @@ PLATFORM_SOURCES = Sbus.c
 sdk_HEADERS += xf86Sbus.h
 endif
 
-libbus_la_SOURCES = $(PCI_SOURCES) $(PLATFORM_SOURCES)
+libbus_la_SOURCES = $(PCI_SOURCES) $(PLATFORM_SOURCES) nobus.c
 
 INCLUDES = $(XORG_INCS)
 
diff --git a/hw/xfree86/os-support/bus/nobus.c b/hw/xfree86/os-support/bus/nobus.c
new file mode 100644
index 0000000..ad23f52
--- /dev/null
+++ b/hw/xfree86/os-support/bus/nobus.c
@@ -0,0 +1 @@
+static void __noop_to_appease_ar__() { return; }
commit 8f2ff479785f2fd17e12f56d1fd36924a7d211db
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Tue Sep 13 15:38:45 2011 -0500

    xfree86: Add stubs for os-support to help adding new architecture support
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>

diff --git a/configure.ac b/configure.ac
index 7232098..d22bd4e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1649,8 +1649,8 @@ if test "x$XORG" = xyes; then
 		xorg_bus_bsdpci="yes"
 		;;
 	  *)
-		XORG_OS_SUBDIR="unknown"
-		AC_MSG_ERROR([m4_text_wrap(m4_join([ ],
+		XORG_OS_SUBDIR="stub"
+		AC_MSG_NOTICE([m4_text_wrap(m4_join([ ],
 		[Your OS is unknown. Xorg currently only supports Linux,],
 		[Free/Open/Net/DragonFlyBSD, Solaris/OpenSolaris, & GNU Hurd.],
 		[If you are interested in porting Xorg to your platform,],
@@ -2151,6 +2151,7 @@ hw/xfree86/os-support/hurd/Makefile
 hw/xfree86/os-support/misc/Makefile
 hw/xfree86/os-support/linux/Makefile
 hw/xfree86/os-support/solaris/Makefile
+hw/xfree86/os-support/stub/Makefile
 hw/xfree86/parser/Makefile
 hw/xfree86/ramdac/Makefile
 hw/xfree86/shadowfb/Makefile
diff --git a/hw/xfree86/os-support/Makefile.am b/hw/xfree86/os-support/Makefile.am
index 094563d..a0140a1 100644
--- a/hw/xfree86/os-support/Makefile.am
+++ b/hw/xfree86/os-support/Makefile.am
@@ -1,5 +1,5 @@
 SUBDIRS = bus @XORG_OS_SUBDIR@ misc $(DRI_SUBDIRS)
-DIST_SUBDIRS = bsd bus misc linux solaris hurd
+DIST_SUBDIRS = bsd bus misc linux solaris stub hurd
 
 sdk_HEADERS = xf86_OSproc.h xf86_OSlib.h
 
diff --git a/hw/xfree86/os-support/stub/Makefile.am b/hw/xfree86/os-support/stub/Makefile.am
new file mode 100644
index 0000000..a1156ef
--- /dev/null
+++ b/hw/xfree86/os-support/stub/Makefile.am
@@ -0,0 +1,19 @@
+noinst_LTLIBRARIES = libstub.la
+
+AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS)
+
+INCLUDES = $(XORG_INCS)
+
+libstub_la_SOURCES = \
+	$(srcdir)/../shared/VTsw_noop.c \
+	$(srcdir)/../shared/agp_noop.c \
+	$(srcdir)/../shared/ioperm_noop.c \
+	$(srcdir)/../shared/kmod_noop.c \
+	$(srcdir)/../shared/pm_noop.c \
+	$(srcdir)/../shared/vidmem.c \
+	$(srcdir)/../shared/posix_tty.c \
+	$(srcdir)/../shared/sigio.c \
+	stub_bell.c \
+	stub_bios.c \
+	stub_init.c \
+	stub_video.c
diff --git a/hw/xfree86/os-support/stub/stub_bell.c b/hw/xfree86/os-support/stub/stub_bell.c
new file mode 100644
index 0000000..4862592
--- /dev/null
+++ b/hw/xfree86/os-support/stub/stub_bell.c
@@ -0,0 +1,10 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86_OSlib.h"
+
+void
+xf86OSRingBell(int loudness, int pitch, int duration)
+{
+}
diff --git a/hw/xfree86/os-support/stub/stub_bios.c b/hw/xfree86/os-support/stub/stub_bios.c
new file mode 100644
index 0000000..8628316
--- /dev/null
+++ b/hw/xfree86/os-support/stub/stub_bios.c
@@ -0,0 +1,12 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86_OSlib.h"
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+		int Len)
+{
+	return -1;
+}
diff --git a/hw/xfree86/os-support/stub/stub_init.c b/hw/xfree86/os-support/stub/stub_init.c
new file mode 100644
index 0000000..36fd2b8
--- /dev/null
+++ b/hw/xfree86/os-support/stub/stub_init.c
@@ -0,0 +1,26 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86_OSlib.h"
+
+void
+xf86OpenConsole()
+{
+}
+
+void
+xf86CloseConsole()
+{
+}
+
+int
+xf86ProcessArgument(int argc, char *argv[], int i)
+{
+	return 0;
+}
+
+void
+xf86UseMsg()
+{
+}
diff --git a/hw/xfree86/os-support/stub/stub_video.c b/hw/xfree86/os-support/stub/stub_video.c
new file mode 100644
index 0000000..3274968
--- /dev/null
+++ b/hw/xfree86/os-support/stub/stub_video.c
@@ -0,0 +1,13 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+	pVidMem->initialised = TRUE;
+	return;
+}
commit 1f9a1566cd71bb3240a4c542cf01e0679b6add3c
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 10 19:26:13 2011 -0400

    incomplete: Remove xf86{Un,}MapVidMem
    
    And man does a lot of support code just fall away when you do that.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c
index bb3a5cb..860bbd4 100644
--- a/hw/xfree86/os-support/bsd/alpha_video.c
+++ b/hw/xfree86/os-support/bsd/alpha_video.c
@@ -67,32 +67,6 @@ static unsigned long hae_mask;
 static unsigned long bus_base;
 static unsigned long sparse_size;
 
-static unsigned long
-memory_base(void)
-{
-    static unsigned long base = 0;
-
-    if (base == 0) {
-	size_t len = sizeof(base);
-	int error;
-#ifdef __OpenBSD__
-       int mib[3];
-
-       mib[0] = CTL_MACHDEP;
-       mib[1] = CPU_CHIPSET;
-       mib[2] = CPU_CHIPSET_MEM;
-
-       if ((error = sysctl(mib, 3, &base, &len, NULL, 0)) < 0)
-#else
-	if ((error = sysctlbyname("hw.chipset.memory", &base, &len,
-				  0, 0)) < 0)
-#endif
-	    FatalError("xf86MapVidMem: can't find memory\n");
-    }
-
-    return base;
-}
-
 static int
 has_bwx(void)
 {
@@ -156,30 +130,9 @@ dense_base(void)
 	return abw[0].abw_abst.abst_sys_start;
 }
 
-static unsigned long
-memory_base(void)
-{
-	if (abw_count < 0)
-		init_abw();
-	
-	if (abw_count > 1) {
-		xf86Msg(X_INFO, "memory base = %#lx\n", 
-			abw[1].abw_abst.abst_sys_start); /* XXXX */
-		return abw[1].abw_abst.abst_sys_start;
-	} else if (abw_count == 1) {
-		/* assume memory_base == dense_base */
-		xf86Msg(X_INFO, "memory base = %#lx\n",
-			abw[0].abw_abst.abst_sys_start); /* XXXX */
-		return abw[0].abw_abst.abst_sys_start;
-	} else {
-		xf86Msg(X_INFO, "no memory base\n"); /* XXXX */
-		return 0;
-	}
-}
 #endif /* __NetBSD__ */
 
 #define BUS_BASE	dense_base()
-#define BUS_BASE_BWX	memory_base()
 
 /***************************************************************************/
 /* Video Memory Mapping section                                            */
@@ -199,11 +152,6 @@ static int  devMemFd = -1;
 #endif
 #define DEV_MEM "/dev/mem"
 
-static pointer mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, pointer, unsigned long);
-static pointer mapVidMemSparse(int, unsigned long, unsigned long, int);
-static void unmapVidMemSparse(int, pointer, unsigned long);
-
 /*
  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
  * "warn" is TRUE.
@@ -286,12 +234,8 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
 	if (has_bwx()) {
 	    xf86Msg(X_PROBED,"Machine type has 8/16 bit access\n");
-	    pVidMem->mapMem = mapVidMem;
-	    pVidMem->unmapMem = unmapVidMem;
 	} else {
 	    xf86Msg(X_PROBED,"Machine needs sparse mapping\n");
-	    pVidMem->mapMem = mapVidMemSparse;
-	    pVidMem->unmapMem = unmapVidMemSparse;
 #ifndef __NetBSD__
 	    if (axpSystem == -1)
                 axpSystem = bsdGetAXP(); 
@@ -303,59 +247,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 	pVidMem->initialised = TRUE;
 }
 
-static pointer
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-	pointer base;
-
-	checkDevMem(FALSE);
-	Base = Base & ((1L<<32) - 1);
-
-	if (useDevMem)
-	{
-	    if (devMemFd < 0) 
-	    {
-		FatalError("xf86MapVidMem: failed to open %s (%s)\n",
-			   DEV_MEM, strerror(errno));
-	    }
-	    base = mmap((caddr_t)0, Size,
-			(flags & VIDMEM_READONLY) ?
-			 PROT_READ : (PROT_READ | PROT_WRITE),
-			 MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX);
-	    if (base == MAP_FAILED)
-	    {
-		FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n",
-			   "xf86MapVidMem", DEV_MEM, Size, Base, 
-			   strerror(errno));
-	    }
-	    return base;
-	}
-		
-	/* else, mmap /dev/vga */
-	if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
-	{
-		FatalError("%s: Address 0x%lx outside allowable range\n",
-			   "xf86MapVidMem", Base);
-	}
-	base = mmap(0, Size,
-		    (flags & VIDMEM_READONLY) ?
-		     PROT_READ : (PROT_READ | PROT_WRITE),
-		    MAP_FLAGS, xf86Info.screenFd,
-		    (unsigned long)Base + BUS_BASE);
-	if (base == MAP_FAILED)
-	{
-	    FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
-		       strerror(errno));
-	}
-	return base;
-}
-
-static void
-unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-	munmap((caddr_t)Base, Size);
-}
-
 /*
  * Read BIOS via mmap()ing DEV_MEM
  */
@@ -502,48 +393,6 @@ sethae(u_int64_t hae)
 }
 #endif /* __NetBSD__ */
 
-static pointer
-mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    static Bool was_here = FALSE;
-
-    if (!was_here) {
-      was_here = TRUE;
-
-      checkDevMem(FALSE);
-
-      xf86WriteMmio8 = writeSparse8;
-      xf86WriteMmio16 = writeSparse16;
-      xf86WriteMmio32 = writeSparse32;
-      xf86WriteMmioNB8 = writeSparseNB8;
-      xf86WriteMmioNB16 = writeSparseNB16;
-      xf86WriteMmioNB32 = writeSparseNB32;
-      xf86ReadMmio8 = readSparse8;
-      xf86ReadMmio16 = readSparse16;
-      xf86ReadMmio32 = readSparse32;
-	
-      memBase = mmap((caddr_t)0, 0x100000000,
-		     PROT_READ | PROT_WRITE,
-		     MAP_SHARED, devMemFd,
-		     (off_t) BUS_BASE);
-      memSBase = mmap((caddr_t)0, 0x100000000,
-		      PROT_READ | PROT_WRITE,
-		      MAP_SHARED, devMemFd,
-		      (off_t) BUS_BASE_BWX);
-      
-      if (memSBase == MAP_FAILED || memBase == MAP_FAILED)	{
-	FatalError("xf86MapVidMem: Could not mmap framebuffer (%s)\n",
-		   strerror(errno));
-      }
-    }
-    return (pointer)((unsigned long)memBase + Base);
-}
-
-static void
-unmapVidMemSparse(int ScreenNum, pointer Base, unsigned long Size)
-{
-}
-
 static int
 readSparse8(pointer Base, register unsigned long Offset)
 {
diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c
index 482d53f..4d43ba2 100644
--- a/hw/xfree86/os-support/bsd/arm_video.c
+++ b/hw/xfree86/os-support/bsd/arm_video.c
@@ -115,9 +115,6 @@ static int  devMemFd = -1;
 
 #define DEV_MEM "/dev/mem"
 
-static pointer mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, pointer, unsigned long);
-
 /*
  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
  * "warn" is TRUE.
@@ -171,64 +168,9 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
 	checkDevMem(TRUE);
 	pVidMem->linearSupported = useDevMem;
-	pVidMem->mapMem = armMapVidMem;
-	pVidMem->unmapVidMem = armUnmapVidMem;
-
 	pVidMem->initialised = TRUE;
 }
 
-static pointer
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-	pointer base;
-
-	checkDevMem(FALSE);
-
-	if (useDevMem)
-	{
-	    if (devMemFd < 0) 
-	    {
-		FatalError("xf86MapVidMem: failed to open %s (%s)\n",
-			   DEV_MEM, strerror(errno));
-	    }
-	    base = mmap((caddr_t)0, Size,
-			(flags & VIDMEM_READONLY) ?
-			 PROT_READ : (PROT_READ | PROT_WRITE),
-			MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX);
-	    if (base == MAP_FAILED)
-	    {
-		FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n",
-			   "xf86MapVidMem", DEV_MEM, Size, Base, 
-			   strerror(errno));
-	    }
-	    return base;
-	}
-		
-	/* else, mmap /dev/vga */
-	if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
-	{
-		FatalError("%s: Address 0x%x outside allowable range\n",
-			   "xf86MapVidMem", Base);
-	}
-	base = mmap(0, Size,
-		    (flags & VIDMEM_READONLY) ?
-		     PROT_READ : (PROT_READ | PROT_WRITE),
-		    MAP_FLAGS, xf86Info.screenFd,
-		    (unsigned long)Base - 0xA0000);
-	if (base == MAP_FAILED)
-	{
-	    FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
-		       strerror(errno));
-	}
-	return base;
-}
-
-static void
-unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-	munmap((caddr_t)Base, Size);
-}
-
 /*
  * Read BIOS via mmap()ing DEV_MEM
  */
@@ -403,50 +345,6 @@ xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size)
     }
 }
 
-static pointer
-armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-	struct memAccess *memInfoP;
-	
-	if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
-	{
-	    /*
-	     ** xf86 passes in a physical address offset from the start
-	     ** of physical memory, but xf86MapInfoMap expects an 
-	     ** offset from the start of the specified region - it gets 
-	     ** the physical address of the region from the display driver.
-	     */
-	    switch(Region)
-	    {
-	        case LINEAR_REGION:
-		    if (vgaPhysLinearBase)
-		    {
-			Base -= vgaPhysLinearBase;
-		    }
-		    break;
-		case VGA_REGION:
-		    Base -= 0xA0000;
-		    break;
-	    }
-	    
-	    base = xf86MapInfoMap(memInfoP, Base, Size);
-	    return base;
-	}
-	return mapVidMem(ScreenNum, Base, Size, flags);
-}
-
-static void
-armUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-        struct memAccess *memInfoP;
-	
-	if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
-	{
-	    xf86MapInfoUnmap(memInfoP, Base, Size);
-	}
-	unmapVidMem(ScreenNum, Base, Size);
-}
-
 #ifdef USE_DEV_IO
 static int IoFd = -1;
 
diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index 7aef079..7b4cea7 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -44,17 +44,6 @@
 #define X_MTRR_ID "XFree86"
 #endif
 
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-#include <machine/mtrr.h>
-#include <machine/sysarch.h>
-#include <sys/queue.h>
-#ifdef __x86_64__
-#define i386_set_mtrr x86_64_set_mtrr
-#define i386_get_mtrr x86_64_get_mtrr
-#define i386_iopl x86_64_iopl
-#endif
-#endif
-
 #include "xf86_OSlib.h"
 #include "xf86OSpriv.h"
 
@@ -90,20 +79,6 @@ static int  devMemFd = -1;
 #endif
 #define DEV_MEM "/dev/mem"
 
-static pointer mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, pointer, unsigned long);
-
-#ifdef HAS_MTRR_SUPPORT
-static pointer setWC(int, unsigned long, unsigned long, Bool, MessageType);
-static void undoWC(int, pointer);
-static Bool cleanMTRR(void);
-#endif
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-static pointer NetBSDsetWC(int, unsigned long, unsigned long, Bool,
-			   MessageType);
-static void NetBSDundoWC(int, pointer);
-#endif
-
 /*
  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
  * "warn" is TRUE.
@@ -199,8 +174,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
 	checkDevMem(TRUE);
 	pVidMem->linearSupported = useDevMem;
-	pVidMem->mapMem = mapVidMem;
-	pVidMem->unmapMem = unmapVidMem;
 
 #if HAVE_PCI_SYSTEM_INIT_DEV_MEM
 	if (useDevMem)
@@ -210,71 +183,12 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 #ifdef HAS_MTRR_SUPPORT
 	if (useDevMem) {
 		if (cleanMTRR()) {
-			pVidMem->setWC = setWC;
-			pVidMem->undoWC = undoWC;
 		}
 	}
 #endif
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-	pVidMem->setWC = NetBSDsetWC;
-	pVidMem->undoWC = NetBSDundoWC;
-#endif
 	pVidMem->initialised = TRUE;
 }
 
-static pointer
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-	pointer base;
-
-	checkDevMem(FALSE);
-
-	if (useDevMem)
-	{
-	    if (devMemFd < 0) 
-	    {
-		FatalError("xf86MapVidMem: failed to open %s (%s)",
-			   DEV_MEM, strerror(errno));
-	    }
-	    base = mmap((caddr_t)0, Size,
-			(flags & VIDMEM_READONLY) ?
-			 PROT_READ : (PROT_READ | PROT_WRITE),
-			MAP_FLAGS, devMemFd, (off_t)Base);
-	    if (base == MAP_FAILED)
-	    {
-		FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)",
-			   "xf86MapVidMem", DEV_MEM, Size, Base, 
-			   strerror(errno));
-	    }
-	    return base;
-	}
-		
-	/* else, mmap /dev/vga */
-	if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
-	{
-		FatalError("%s: Address 0x%lx outside allowable range",
-			   "xf86MapVidMem", Base);
-	}
-	base = mmap(0, Size,
-		    (flags & VIDMEM_READONLY) ?
-		     PROT_READ : (PROT_READ | PROT_WRITE),
-		    MAP_FLAGS, xf86Info.screenFd,
-		    (unsigned long)Base - 0xA0000
-	    );
-	if (base == MAP_FAILED)
-	{
-	    FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)",
-		       strerror(errno));
-	}
-	return base;
-}
-
-static void
-unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-	munmap((caddr_t)Base, Size);
-}
-
 /*
  * Read BIOS via mmap()ing DEV_MEM
  */
@@ -580,329 +494,4 @@ cleanMTRR()
 	return TRUE;
 }
 
-typedef struct x_RangeRec {
-	struct mem_range_desc	mrd;
-	Bool			wasWC;
-	struct x_RangeRec *	next;
-} RangeRec, *RangePtr;
-
-static void
-freeRangeList(RangePtr range)
-{
-	RangePtr rp;
-
-	while (range) {
-		rp = range;
-		range = rp->next;
-		free(rp);
-	}
-}
-
-static RangePtr
-dupRangeList(RangePtr list)
-{
-	RangePtr new = NULL, rp, p;
-
-	rp = list;
-	while (rp) {
-		p = xnfalloc(sizeof(RangeRec));
-		*p = *rp;
-		p->next = new;
-		new = p;
-		rp = rp->next;
-	}
-	return new;
-}
-
-static RangePtr
-sortRangeList(RangePtr list)
-{
-	RangePtr rp1, rp2, copy, sorted = NULL, minp, prev, minprev;
-	unsigned long minBase;
-
-	/* Sort by base address */
-	rp1 = copy = dupRangeList(list);
-	while (rp1) {
-		minBase = rp1->mrd.mr_base;
-		minp = rp1;
-		minprev = NULL;
-		prev = rp1;
-		rp2 = rp1->next;
-		while (rp2) {
-			if (rp2->mrd.mr_base < minBase) {
-				minBase = rp2->mrd.mr_base;
-				minp = rp2;
-				minprev = prev;
-			}
-			prev = rp2;
-			rp2 = rp2->next;
-		}
-		if (minprev) {
-			minprev->next = minp->next;
-			rp1 = copy;
-		} else {
-			rp1 = minp->next;
-		}
-		minp->next = sorted;
-		sorted = minp;
-	}
-	return sorted;
-}
-
-/*
- * findRanges returns a list of ranges that overlap the specified range.
- */
-
-static void
-findRanges(unsigned long base, unsigned long size, RangePtr *ucp, RangePtr *wcp)
-{
-	struct mem_range_desc *mrd;
-	int nmr, i;
-	RangePtr rp, *p;
-	
-	if (!(mrd = getAllRanges(&nmr)))
-		return;
-
-	for (i = 0; i < nmr; i++) {
-		if ((mrd[i].mr_flags & MDF_ACTIVE) &&
-		    mrd[i].mr_base < base + size &&
-		    mrd[i].mr_base + mrd[i].mr_len > base) {
-			if (mrd[i].mr_flags & MDF_WRITECOMBINE)
-				p = wcp;
-			else if (mrd[i].mr_flags & MDF_UNCACHEABLE)
-				p = ucp;
-			else
-				continue;
-			rp = xnfalloc(sizeof(RangeRec));
-			rp->mrd = mrd[i];
-			rp->next = *p;
-			*p = rp;
-		}
-	}
-	free(mrd);
-}
-
-/*
- * This checks if the existing overlapping ranges fully cover the requested
- * range.  Is this overkill?
- */
-
-static Bool
-fullCoverage(unsigned long base, unsigned long size, RangePtr overlap)
-{
-	RangePtr rp1, sorted = NULL;
-	unsigned long end;
-
-	sorted = sortRangeList(overlap);
-	/* Look for gaps */
-	rp1 = sorted;
-	end = base + size;
-	while (rp1) {
-		if (rp1->mrd.mr_base > base) {
-			freeRangeList(sorted);
-			return FALSE;
-		} else {
-			base = rp1->mrd.mr_base + rp1->mrd.mr_len;
-		}
-		if (base >= end) {
-			freeRangeList(sorted);
-			return TRUE;
-		}
-		rp1 = rp1->next;
-	}
-	freeRangeList(sorted);
-	return FALSE;
-}
-
-static pointer
-addWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
-{
-	RangePtr uc = NULL, wc = NULL, retlist = NULL;
-	struct mem_range_desc mrd;
-	struct mem_range_op mro;
-
-	findRanges(base, size, &uc, &wc);
-
-	/* See of the full range is already WC */
-	if (!uc && fullCoverage(base, size, wc)) {
-		xf86DrvMsg(screenNum, from, 
-		   "Write-combining range (0x%lx,0x%lx) was already set\n",
-		    base, size);
-		return NULL;
-	}
-
-	/* Otherwise, try to add the new range */
-	mrd.mr_base = base;
-	mrd.mr_len = size;
-	strcpy(mrd.mr_owner, X_MTRR_ID);
-	mrd.mr_flags = MDF_WRITECOMBINE;
-	mro.mo_desc = &mrd;
-	mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-	if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
-		xf86DrvMsg(screenNum, X_WARNING,
-			   "Failed to set write-combining range "
-			   "(0x%lx,0x%lx)\n", base, size);
-		return NULL;
-	} else {
-		xf86DrvMsg(screenNum, from,
-			   "Write-combining range (0x%lx,0x%lx)\n", base, size);
-		retlist = xnfalloc(sizeof(RangeRec));
-		retlist->mrd = mrd;
-		retlist->wasWC = FALSE;
-		retlist->next = NULL;
-		return retlist;
-	}
-}
-
-static pointer
-delWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
-{
-	RangePtr uc = NULL, wc = NULL, retlist = NULL;
-	struct mem_range_desc mrd;
-	struct mem_range_op mro;
-
-	findRanges(base, size, &uc, &wc);
-
-	/*
-	 * See of the full range is already not WC, or if there is full
-	 * coverage from UC ranges.
-	 */
-	if (!wc || fullCoverage(base, size, uc)) {
-		xf86DrvMsg(screenNum, from, 
-		   "Write-combining range (0x%lx,0x%lx) was already clear\n",
-		    base, size);
-		return NULL;
-	}
-
-	/* Otherwise, try to add the new range */
-	mrd.mr_base = base;
-	mrd.mr_len = size;
-	strcpy(mrd.mr_owner, X_MTRR_ID);
-	mrd.mr_flags = MDF_UNCACHEABLE;
-	mro.mo_desc = &mrd;
-	mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-	if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
-		xf86DrvMsg(screenNum, X_WARNING,
-			   "Failed to remove write-combining range "
-			   "(0x%lx,0x%lx)\n", base, size);
-		/* XXX Should then remove all of the overlapping WC ranges */
-		return NULL;
-	} else {
-		xf86DrvMsg(screenNum, from,
-			   "Removed Write-combining range (0x%lx,0x%lx)\n",
-			   base, size);
-		retlist = xnfalloc(sizeof(RangeRec));
-		retlist->mrd = mrd;
-		retlist->wasWC = TRUE;
-		retlist->next = NULL;
-		return retlist;
-	}
-}
-
-static pointer
-setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
-	MessageType from)
-{
-	if (enable)
-		return addWC(screenNum, base, size, from);
-	else
-		return delWC(screenNum, base, size, from);
-}
-
-static void
-undoWC(int screenNum, pointer list)
-{
-	RangePtr rp;
-	struct mem_range_op mro;
-	Bool failed;
-
-	rp = list;
-	while (rp) {
-#ifdef DEBUG
-		ErrorF("Undo for (0x%lx,0x%lx), %d\n",
-			(unsigned long)rp->mrd.mr_base,
-			(unsigned long)rp->mrd.mr_len, rp->wasWC);
-#endif
-		failed = FALSE;
-		if (rp->wasWC) {
-			mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-			rp->mrd.mr_flags = MDF_WRITECOMBINE;
-			strcpy(rp->mrd.mr_owner, "unknown");
-		} else {
-			mro.mo_arg[0] = MEMRANGE_SET_REMOVE;
-		}
-		mro.mo_desc = &rp->mrd;
-
-		if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
-			if (!rp->wasWC) {
-				mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-				rp->mrd.mr_flags = MDF_UNCACHEABLE;
-				strcpy(rp->mrd.mr_owner, "unknown");
-				if (ioctl(devMemFd, MEMRANGE_SET, &mro))
-					failed = TRUE;
-			} else
-				failed = TRUE;
-		}
-		if (failed) {
-			xf86DrvMsg(screenNum, X_WARNING,
-				"Failed to restore MTRR range (0x%lx,0x%lx)\n",
-				(unsigned long)rp->mrd.mr_base,
-				(unsigned long)rp->mrd.mr_len);
-		}
-		rp = rp->next;
-	}
-}
-
 #endif /* HAS_MTRR_SUPPORT */
-
-
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-static pointer
-NetBSDsetWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
-	    MessageType from)
-{
-	struct mtrr *mtrrp;
-	int n;
-
-	xf86DrvMsg(screenNum, X_WARNING,
-		   "%s MTRR %lx - %lx\n", enable ? "set" : "remove",
-		   base, (base + size));
-
-	mtrrp = xnfalloc(sizeof (struct mtrr));
-	mtrrp->base = base;
-	mtrrp->len = size;
-	mtrrp->type = MTRR_TYPE_WC;
-
-	/*
-	 * MTRR_PRIVATE will make this MTRR get reset automatically
-	 * if this process exits, so we have no need for an explicit
-	 * cleanup operation when starting a new server.
-	 */
-
-	if (enable)
-		mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
-	else
-		mtrrp->flags = 0;
-	n = 1;
-
-	if (i386_set_mtrr(mtrrp, &n) < 0) {
-		free(mtrrp);
-		return NULL;
-	}
-	return mtrrp;
-}
-
-static void
-NetBSDundoWC(int screenNum, pointer list)
-{
-	struct mtrr *mtrrp = (struct mtrr *)list;
-	int n;
-
-	if (mtrrp == NULL)
-		return;
-	n = 1;
-	mtrrp->flags &= ~MTRR_VALID;
-	i386_set_mtrr(mtrrp, &n);
-	free(mtrrp);
-}
-#endif
diff --git a/hw/xfree86/os-support/bsd/ppc_video.c b/hw/xfree86/os-support/bsd/ppc_video.c
index 7e3fcdb..3000187 100644
--- a/hw/xfree86/os-support/bsd/ppc_video.c
+++ b/hw/xfree86/os-support/bsd/ppc_video.c
@@ -51,9 +51,6 @@
 #define DEV_MEM "/dev/xf86"
 #endif
 
-static pointer ppcMapVidMem(int, unsigned long, unsigned long, int flags);
-static void ppcUnmapVidMem(int, pointer, unsigned long);
-
 Bool xf86EnableIO(void);
 void xf86DisableIO(void);
 
@@ -61,42 +58,12 @@ void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
 	pVidMem->linearSupported = TRUE;
-	pVidMem->mapMem = ppcMapVidMem;
-	pVidMem->unmapMem = ppcUnmapVidMem;
 	pVidMem->initialised = TRUE;
 	xf86EnableIO();
 }
 
-
 volatile unsigned char *ioBase = MAP_FAILED;
 
-static pointer
-ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-	int fd = xf86Info.screenFd;
-	pointer base;
-#ifdef DEBUG
-	xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", 
-		    Base, Size, fd);
-#endif
-
-	base = mmap(0, Size,
-		    (flags & VIDMEM_READONLY) ?
-		     PROT_READ : (PROT_READ | PROT_WRITE),
-		    MAP_SHARED, fd, Base);
-	if (base == MAP_FAILED)
-		FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
-			   "xf86MapVidMem", Size, Base, strerror(errno));
-
-	return base;
-}
-
-static void
-ppcUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-	munmap(Base, Size);
-}
-
 int
 xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
 	     int Len)
diff --git a/hw/xfree86/os-support/bsd/sparc64_video.c b/hw/xfree86/os-support/bsd/sparc64_video.c
index c838792..e61ad13 100644
--- a/hw/xfree86/os-support/bsd/sparc64_video.c
+++ b/hw/xfree86/os-support/bsd/sparc64_video.c
@@ -42,50 +42,16 @@
 /* Video Memory Mapping section                                            */
 /***************************************************************************/
 
-static pointer sparc64MapVidMem(int, unsigned long, unsigned long, int);
-static void sparc64UnmapVidMem(int, pointer, unsigned long);
-
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
 	pVidMem->linearSupported = TRUE;
-	pVidMem->mapMem = sparc64MapVidMem;
-	pVidMem->unmapMem = sparc64UnmapVidMem;
 	pVidMem->initialised = TRUE;
 }
 
-static pointer
-sparc64MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, 
-		 int flags)
-{
-	int fd = xf86Info.screenFd;
-	pointer base;
-
-#ifdef DEBUG
-	xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", 
-		    Base, Size, fd);
-#endif
-
-	base = mmap(0, Size,
-		    (flags & VIDMEM_READONLY) ?
-		     PROT_READ : (PROT_READ | PROT_WRITE),
-		    MAP_SHARED, fd, Base);
-	if (base == MAP_FAILED)
-		FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
-			   "xf86MapVidMem", Size, Base, strerror(errno));
-	return base;
-}
-
-static void
-sparc64UnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-	munmap(Base, Size);
-}
-
 int
 xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
 	     int Len)
 {
-
 	return 0;
 }
diff --git a/hw/xfree86/os-support/hurd/hurd_video.c b/hw/xfree86/os-support/hurd/hurd_video.c
index 39f353b..db280b5 100644
--- a/hw/xfree86/os-support/hurd/hurd_video.c
+++ b/hw/xfree86/os-support/hurd/hurd_video.c
@@ -39,75 +39,6 @@
 #include "xf86OSpriv.h"
 
 /**************************************************************************
- * Video Memory Mapping section                                            
- ***************************************************************************/
-static pointer
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
-{
-    mach_port_t device,mem_dev;
-    memory_object_t mem_obj;
-    kern_return_t err;
-    vm_address_t addr=(vm_address_t)0;
-
-    err = get_privileged_ports (NULL, &device);
-    if( err )
-    {
-	errno = err;
-	FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n",strerror(errno));
-    }
-    err = device_open(device,D_READ|D_WRITE,"mem",&mem_dev);
-    mach_port_deallocate (mach_task_self(), device);
-    if( err )
-    {
-	errno = err;
-	FatalError("xf86MapVidMem() can't device_open. (%s)\n",strerror(errno));
-    }
-
-    err = device_map(mem_dev,VM_PROT_READ|VM_PROT_WRITE, Base , Size ,&mem_obj,0);
-    if( err )
-    {
-	errno = err;
-	FatalError("xf86MapVidMem() can't device_map. (%s)\n",strerror(errno));
-    }
-    err = vm_map(mach_task_self(),
-		 &addr,
-		 Size,
-		 0,     /* mask */
-		 TRUE,  /* anywhere */
-		 mem_obj,
-		 (vm_offset_t)Base,
-		 FALSE, /* copy on write */
-		 VM_PROT_READ|VM_PROT_WRITE,
-		 VM_PROT_READ|VM_PROT_WRITE,
-		 VM_INHERIT_SHARE);
-    mach_port_deallocate(mach_task_self(),mem_obj);
-    if( err )
-    {
-	errno = err;
-	FatalError("xf86MapVidMem() can't vm_map.(mem_obj) (%s)\n",strerror(errno));
-    }
-    mach_port_deallocate(mach_task_self(),mem_dev);
-    if( err )
-    {
-	errno = err;
-	FatalError("xf86MapVidMem() can't mach_port_deallocate.(mem_dev) (%s)\n",strerror(errno));
-    }
-    return (pointer)addr;
-}
-
-static void
-unmapVidMem(int ScreenNum,pointer Base,unsigned long Size)
-{
-    kern_return_t err = vm_deallocate(mach_task_self(), (int)Base, Size);
-    if( err )
-    {
-	errno = err;
-	ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n",strerror(errno));
-    }
-    return;
-}
-
-/**************************************************************************
  * I/O Permissions section                                                 
  ***************************************************************************/
 
@@ -149,7 +80,5 @@ void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
 	pVidMem->linearSupported = TRUE;
-	pVidMem->mapMem = mapVidMem;
-	pVidMem->unmapMem = unmapVidMem;
 	pVidMem->initialised = TRUE;
 }
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index 3d45511..18116bd 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -42,10 +42,6 @@
 #include "shared/xf86Axp.h"
 #endif
 
-#ifdef HAS_MTRR_SUPPORT
-#include <asm/mtrr.h>
-#endif
-
 #ifndef MAP_FAILED
 #define MAP_FAILED ((void *)-1)
 #endif
@@ -83,16 +79,12 @@ extern int iopl(int __level);
 /* Video Memory Mapping section                                            */
 /***************************************************************************/
 
-static pointer mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, pointer, unsigned long);
 #if defined (__alpha__) 
 extern void sethae(unsigned long hae);
 extern unsigned long _bus_base __P ((void)) __attribute__ ((const));
 extern unsigned long _bus_base_sparse __P ((void)) __attribute__ ((const));
 
-static pointer mapVidMemSparse(int, unsigned long, unsigned long, int);
 extern axpDevice lnxGetAXP(void);
-static void unmapVidMemSparse(int, pointer, unsigned long);
 static axpDevice axpSystem = -1;
 static Bool needSparse;
 static unsigned long hae_thresh;
@@ -100,269 +92,6 @@ static unsigned long hae_mask;
 static unsigned long bus_base;
 #endif
 
-#ifdef HAS_MTRR_SUPPORT
-
-#define SPLIT_WC_REGIONS 1
-
-static pointer setWC(int, unsigned long, unsigned long, Bool, MessageType);
-static void undoWC(int, pointer);
-
-/* The file desc for /proc/mtrr. Once opened, left opened, and the mtrr
-   driver will clean up when we exit. */
-#define MTRR_FD_UNOPENED (-1)	/* We have yet to open /proc/mtrr */
-#define MTRR_FD_PROBLEM (-2)	/* We tried to open /proc/mtrr, but had
-				   a problem. */
-static int mtrr_fd = MTRR_FD_UNOPENED;
-
-/* Open /proc/mtrr. FALSE on failure. Will always fail on Linux 2.0, 
-   and will fail on Linux 2.2 with MTRR support configured out,
-   so verbosity should be chosen appropriately. */
-static Bool
-mtrr_open(int verbosity)
-{
-	/* Only report absence of /proc/mtrr once. */
-	static Bool warned = FALSE;
-
-	if (mtrr_fd == MTRR_FD_UNOPENED) { 
-		mtrr_fd = open("/proc/mtrr", O_WRONLY);
-
-		if (mtrr_fd < 0)
-			mtrr_fd = MTRR_FD_PROBLEM;
-	}
-
-	if (mtrr_fd == MTRR_FD_PROBLEM) {
-		/* To make sure we only ever warn once, need to check
-		   verbosity outside xf86MsgVerb */
-		if (!warned && verbosity <= xf86GetVerbosity()) {
-			xf86MsgVerb(X_WARNING, verbosity,
-				  "System lacks support for changing MTRRs\n");
-			warned = TRUE;
-		}
-
-		return FALSE;
-	}
-	else
-		return TRUE;
-}
-
-/*
- * We maintain a list of WC regions for each physical mapping so they can
- * be undone when unmapping.
- */
-
-struct mtrr_wc_region {
-	struct mtrr_sentry	sentry;
-	Bool			added;		/* added WC or removed it */
-	struct mtrr_wc_region *	next;
-};
-
-
-static struct mtrr_wc_region *
-mtrr_cull_wc_region(int screenNum, unsigned long base, unsigned long size,
-		      MessageType from)
-{
-	/* Some BIOS writers thought that setting wc over the mmio
-	   region of a graphics devices was a good idea. Try to fix
-	   it. */
-
-	struct mtrr_gentry gent;
-	struct mtrr_wc_region *wcreturn = NULL, *wcr;
-	int count, ret=0;
-
-	/* Linux 2.0 users should not get a warning without -verbose */
-	if (!mtrr_open(2))
-		return NULL;
-
-	for (gent.regnum = 0; 
-	     ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0;
-	     gent.regnum++) {
-		if (gent.type != MTRR_TYPE_WRCOMB
-		    || gent.base + gent.size <= base
-		    || base + size <= gent.base)
-			continue;
-
-		/* Found an overlapping region. Delete it. */
-		
-		wcr = malloc(sizeof(*wcr));
-		if (!wcr)
-			return NULL;
-		wcr->sentry.base = gent.base;
-		wcr->sentry.size = gent.size;
-		wcr->sentry.type = MTRR_TYPE_WRCOMB;
-		wcr->added = FALSE;
-		
-		count = 3;
-		while (count-- && 
-		       (ret = ioctl(mtrr_fd, MTRRIOC_KILL_ENTRY, &(wcr->sentry))) < 0);
-		
-		if (ret >= 0) {
-			xf86DrvMsg(screenNum, from,
-				   "Removed MMIO write-combining range "
-				   "(0x%lx,0x%lx)\n",
-				   (unsigned long) gent.base, (unsigned long) gent.size);
-			wcr->next = wcreturn;
-			wcreturn = wcr;
-			gent.regnum--;
-		} else {
-			free(wcr);
-			xf86DrvMsgVerb(screenNum, X_WARNING, 0,
-				   "Failed to remove MMIO "
-				   "write-combining range (0x%lx,0x%lx)\n",
-				       gent.base, (unsigned long) gent.size);
-		}
-	}
-	return wcreturn;
-}
-
-
-static struct mtrr_wc_region *
-mtrr_remove_offending(int screenNum, unsigned long base, unsigned long size,
-		      MessageType from)
-{
-    struct mtrr_gentry gent;
-    struct mtrr_wc_region *wcreturn = NULL, **wcr;
-
-    if (!mtrr_open(2))
-	return NULL;
-
-    wcr = &wcreturn;
-    for (gent.regnum = 0; 
-	 ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++ ) {
-	if (gent.type == MTRR_TYPE_WRCOMB
-	    && ((gent.base >= base && gent.base + gent.size < base + size) || 
-		(gent.base >  base && gent.base + gent.size <= base + size))) {
-	    *wcr = mtrr_cull_wc_region(screenNum, gent.base, gent.size, from);
-	    if (*wcr) gent.regnum--;
-	    while(*wcr) {
-		wcr = &((*wcr)->next);
-	    }
-	}
-    }
-    return wcreturn;
-}
-
-
-static struct mtrr_wc_region *
-mtrr_add_wc_region(int screenNum, unsigned long base, unsigned long size,
-		   MessageType from)
-{
-        struct mtrr_wc_region **wcr, *wcreturn, *curwcr;
-
-       /*
-        * There can be only one....
-        */
-
-	wcreturn = mtrr_remove_offending(screenNum, base, size, from);
-	wcr = &wcreturn;
-	while (*wcr) {
-	    wcr = &((*wcr)->next);
-	} 
-
-	/* Linux 2.0 should not warn, unless the user explicitly asks for
-	   WC. */
-
-	if (!mtrr_open(from == X_CONFIG ? 0 : 2))
-		return wcreturn;
-
-	*wcr = curwcr = malloc(sizeof(**wcr));
-	if (!curwcr)
-	    return wcreturn;
-
-	curwcr->sentry.base = base;
-	curwcr->sentry.size = size;
-	curwcr->sentry.type = MTRR_TYPE_WRCOMB;
-	curwcr->added = TRUE;
-	curwcr->next = NULL;
-
-#if SPLIT_WC_REGIONS
-	/*
-	 * Splits up the write-combining region if it is not aligned on a
- 	 * size boundary.
-	 */
-
-	{
-	    unsigned long lbase, d_size = 1;
-	    unsigned long n_size = size;
-	    unsigned long n_base = base;
-
-	    for (lbase = n_base, d_size = 1; !(lbase & 1);
-		 lbase = lbase >> 1, d_size <<= 1);
-	    while (d_size > n_size)
-		d_size = d_size >> 1;
-	    DebugF("WC_BASE: 0x%lx WC_END: 0x%lx\n",base,base+d_size-1);
-	    n_base += d_size;
-	    n_size -= d_size;
-	    if (n_size) {
-		xf86DrvMsgVerb(screenNum,X_INFO,3,"Splitting WC range: "
-			       "base: 0x%lx, size: 0x%lx\n",base,size);
-		curwcr->next = mtrr_add_wc_region(screenNum, n_base, n_size,from);
-	    }
-	    curwcr->sentry.size = d_size;
-	} 
-	
-	/*****************************************************************/
-#endif /* SPLIT_WC_REGIONS */
-
-	if (ioctl(mtrr_fd, MTRRIOC_ADD_ENTRY, &curwcr->sentry) >= 0) {
-		/* Avoid printing on every VT switch */
-		if (xf86ServerIsInitialising()) {
-			xf86DrvMsg(screenNum, from,
-				   "Write-combining range (0x%lx,0x%lx)\n",
-				   base, size);
-		}
-		return wcreturn;
-	}
-	else {
-	        *wcr = curwcr->next;
-		free(curwcr);
-		
-		/* Don't complain about the VGA region: MTRR fixed
-		   regions aren't currently supported, but might be in
-		   the future. */
-		if ((unsigned long)base >= 0x100000) {
-			xf86DrvMsgVerb(screenNum, X_WARNING, 0,
-				"Failed to set up write-combining range "
-				"(0x%lx,0x%lx)\n", base, size);
-		}
-		return wcreturn;
-	}
-}
-
-static void
-mtrr_undo_wc_region(int screenNum, struct mtrr_wc_region *wcr)
-{
-	struct mtrr_wc_region *p, *prev;
-
-	if (mtrr_fd >= 0) {
-		p = wcr;
-		while (p) {
-			if (p->added)
-				ioctl(mtrr_fd, MTRRIOC_DEL_ENTRY, &p->sentry);
-			prev = p;
-			p = p->next;
-			free(prev);
-		}
-	}
-}
-
-static pointer
-setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
-      MessageType from)
-{
-	if (enable)
-		return mtrr_add_wc_region(screenNum, base, size, from);
-	else
-		return mtrr_cull_wc_region(screenNum, base, size, from);
-}
-
-static void
-undoWC(int screenNum, pointer regioninfo)
-{
-	mtrr_undo_wc_region(screenNum, regioninfo);
-}
-
-#endif /* HAS_MTRR_SUPPORT */
-
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
@@ -378,105 +107,14 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 	}
 	if (needSparse) {
 	  xf86Msg(X_INFO,"Machine needs sparse mapping\n");
-	  pVidMem->mapMem = mapVidMemSparse;
-	  pVidMem->unmapMem = unmapVidMemSparse;
 	} else {
 	  xf86Msg(X_INFO,"Machine type has 8/16 bit access\n");
-	  pVidMem->mapMem = mapVidMem;
-	  pVidMem->unmapMem = unmapVidMem;
 	}	
-#else
-	pVidMem->mapMem = mapVidMem;
-	pVidMem->unmapMem = unmapVidMem;
 #endif /* __alpha__ */
 
-
-#ifdef HAS_MTRR_SUPPORT
-	pVidMem->setWC = setWC;
-	pVidMem->undoWC = undoWC;
-#endif
 	pVidMem->initialised = TRUE;
 }
 
-#ifdef __sparc__
-/* Basically, you simply cannot do this on Sparc.  You have to do something portable
- * like use /dev/fb* or mmap() on /proc/bus/pci/X/Y nodes. -DaveM
- */
-static pointer mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-	return NULL;
-}
-#else
-static pointer
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    pointer base;
-    int fd;
-    int mapflags = MAP_SHARED; 
-    int prot;
-    memType realBase, alignOff;
-
-    realBase = Base & ~(getpagesize() - 1);
-    alignOff = Base - realBase;
-    DebugF("base: %lx, realBase: %lx, alignOff: %lx \n",
-	   Base,realBase,alignOff);
-
-#if defined(__ia64__) || defined(__arm__) || defined(__s390__)
-#ifndef MAP_WRITECOMBINED
-#define MAP_WRITECOMBINED 0x00010000
-#endif
-#ifndef MAP_NONCACHED
-#define MAP_NONCACHED 0x00020000
-#endif
-    if(flags & VIDMEM_FRAMEBUFFER) 
-        mapflags |= MAP_WRITECOMBINED; 
-    else
-        mapflags |= MAP_NONCACHED; 
-#endif
-
-#if 0
-    /* this will disappear when people upgrade their kernels */
-    fd = open(DEV_MEM,
-	      ((flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR) | O_SYNC);
-#else
-    fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
-#endif
-    if (fd < 0)
-    {
-	FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n",
-		   strerror(errno));
-    }
-
-    if (flags & VIDMEM_READONLY)
-	prot = PROT_READ;
-    else
-	prot = PROT_READ | PROT_WRITE;
-
-    /* This requires linux-0.99.pl10 or above */
-    base = mmap((caddr_t)0, Size + alignOff, prot, mapflags, fd,
- 		(off_t)realBase  + BUS_BASE);
-    close(fd);
-    if (base == MAP_FAILED) {
-        FatalError("xf86MapVidMem: Could not mmap framebuffer"
-		   " (0x%08lx,0x%lx) (%s)\n", Base, Size,
-		   strerror(errno));
-    }
-    DebugF("base: %lx aligned base: %lx\n",base, (char *)base + alignOff);
-    return (char *)base + alignOff;
-}
-#endif /* !(__sparc__) */
-    
-static void
-unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-    memType alignOff = (memType)Base 
-	- ((memType)Base & ~(getpagesize() - 1));
-
-    DebugF("alignment offset: %lx\n",alignOff);
-    munmap((caddr_t)((memType)Base - alignOff), (Size + alignOff));
-}
-
-
 /***************************************************************************/
 /* I/O Permissions section                                                 */
 /***************************************************************************/
@@ -599,115 +237,6 @@ writeSparse32(int Value, pointer Base, register unsigned long Offset);
 
 static unsigned long msb_set = 0;
 
-static pointer
-mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    int fd, prot;
-    unsigned long ret, rets = 0;
-
-    static Bool was_here = FALSE;
-
-    if (!was_here) {
-      was_here = TRUE;
-
-      xf86WriteMmio8 = writeSparse8;
-      xf86WriteMmio16 = writeSparse16;
-      xf86WriteMmio32 = writeSparse32;
-      xf86WriteMmioNB8 = writeSparseNB8;
-      xf86WriteMmioNB16 = writeSparseNB16;
-      xf86WriteMmioNB32 = writeSparseNB32;
-      xf86ReadMmio8 = readSparse8;
-      xf86ReadMmio16 = readSparse16;
-      xf86ReadMmio32 = readSparse32;
-    }
-	
-    fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
-    if (fd < 0) {
-        FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n",
-		   strerror(errno));
-    }
-
-#if 0
-    xf86Msg(X_INFO,"mapVidMemSparse: try Base 0x%lx size 0x%lx flags 0x%x\n",
-	    Base, Size, flags);
-#endif
-
-    if (flags & VIDMEM_READONLY)
-	prot = PROT_READ;
-    else
-	prot = PROT_READ | PROT_WRITE;
-
-    /* This requirers linux-0.99.pl10 or above */
-
-    /*
-     * Always do DENSE mmap, since read32/write32 currently require it.
-     */
-    ret = (unsigned long)mmap((caddr_t)(DENSE_BASE + Base), Size,
-		   prot, MAP_SHARED, fd,
-		   (off_t) (bus_base + Base));
-
-    /*
-     * Do SPARSE mmap only when MMIO and not MMIO_32BIT, or FRAMEBUFFER
-     * and SPARSE (which should require the use of read/write macros).
-     *
-     * By not SPARSE mmapping an 8MB framebuffer, we can save approx. 256K
-     * bytes worth of pagetable (32 pages).
-     */
-    if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) ||
-	((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE)))
-    {
-        rets = (unsigned long)mmap((caddr_t)(SPARSE_BASE + (Base << 5)),
-				   Size << 5, prot, MAP_SHARED, fd,
-				   (off_t) _bus_base_sparse() + (Base << 5));
-    }
-
-    close(fd);
-      
-    if (ret == (unsigned long)MAP_FAILED) {
-        FatalError("xf86MapVidMemSparse: Could not (dense) mmap fb (%s)\n",
-		   strerror(errno));
-    }
-
-    if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) ||
-	((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE)))
-    {
-        if (rets == (unsigned long)MAP_FAILED ||
-	    rets != (SPARSE_BASE + (Base << 5)))
-	{
-	    FatalError("mapVidMemSparse: Could not (sparse) mmap fb (%s)\n",
-		       strerror(errno));
-	}
-    }
-
-#if 1
-    if (rets)
-        xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx"
-		" to DENSE at 0x%lx and SPARSE at 0x%lx\n",
-		Base, Size, ret, rets);
-    else
-        xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx"
-		" to DENSE only at 0x%lx\n",
-		Base, Size, ret);
-
-#endif
-    return (pointer) ret;
-}
-
-static void
-unmapVidMemSparse(int ScreenNum, pointer Base, unsigned long Size)
-{
-    unsigned long Offset = (unsigned long)Base - DENSE_BASE;
-#if 1
-    xf86Msg(X_INFO,"unmapVidMemSparse: unmapping Base 0x%lx Size 0x%lx\n",
-	    Base, Size);
-#endif
-    /* Unmap DENSE always. */
-    munmap((caddr_t)Base, Size);
-
-    /* Unmap SPARSE always, and ignore error in case we did not map it. */
-    munmap((caddr_t)(SPARSE_BASE + (Offset << 5)), Size << 5);
-}
-
 static int
 readSparse8(pointer Base, register unsigned long Offset)
 {
diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index 54f6c64..146ce8b 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -25,7 +25,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
@@ -43,133 +42,7 @@
  * This file contains the common part of the video memory mapping functions
  */
 
-/*
- * Get a piece of the ScrnInfoRec.  At the moment, this is only used to hold
- * the MTRR option information, but it is likely to be expanded if we do
- * auto unmapping of memory at VT switch.
- *
- */
-
-typedef struct {
-	unsigned long 	size;
-	pointer		virtBase;
-	pointer 	mtrrInfo;
-} MappingRec, *MappingPtr;
-	
-typedef struct {
-	int		numMappings;
-	MappingPtr *	mappings;
-	Bool		mtrrEnabled;
-	MessageType	mtrrFrom;
-	Bool		mtrrOptChecked;
-	ScrnInfoPtr	pScrn;
-} VidMapRec, *VidMapPtr;
-
-static int vidMapIndex = -1;
-
-#define VIDMAPPTR(p) ((VidMapPtr)((p)->privates[vidMapIndex].ptr))
-
 static VidMemInfo vidMemInfo = {FALSE, };
-static VidMapRec  vidMapRec  = {0, NULL, TRUE, X_DEFAULT, FALSE, NULL};
-
-static VidMapPtr
-getVidMapRec(int scrnIndex)
-{
-	VidMapPtr vp;
-	ScrnInfoPtr pScrn;
-
-	if ((scrnIndex < 0) ||
-	    !(pScrn = xf86Screens[scrnIndex]))
-		return &vidMapRec;
-
-	if (vidMapIndex < 0)
-		vidMapIndex = xf86AllocateScrnInfoPrivateIndex();
-
-	if (VIDMAPPTR(pScrn) != NULL)
-		return VIDMAPPTR(pScrn);
-
-	vp = pScrn->privates[vidMapIndex].ptr = xnfcalloc(sizeof(VidMapRec), 1);
-	vp->mtrrEnabled = TRUE;	/* default to enabled */
-	vp->mtrrFrom = X_DEFAULT;
-	vp->mtrrOptChecked = FALSE;
-	vp->pScrn = pScrn;
-	return vp;
-}
-
-static MappingPtr
-newMapping(VidMapPtr vp)
-{
-	vp->mappings = xnfrealloc(vp->mappings, sizeof(MappingPtr) *
-				  (vp->numMappings + 1));
-	vp->mappings[vp->numMappings] = xnfcalloc(sizeof(MappingRec), 1);
-	return vp->mappings[vp->numMappings++];
-}
-
-static MappingPtr
-findMapping(VidMapPtr vp, pointer vbase, unsigned long size)
-{
-	int i;
-
-	for (i = 0; i < vp->numMappings; i++) {
-		if (vp->mappings[i]->virtBase == vbase &&
-		    vp->mappings[i]->size == size)
-			return vp->mappings[i];
-	}
-	return NULL;
-}
-
-static void
-removeMapping(VidMapPtr vp, MappingPtr mp)
-{
-	int i, found = 0;
-
-	for (i = 0; i < vp->numMappings; i++) {
-		if (vp->mappings[i] == mp) {
-			found = 1;
-			free(vp->mappings[i]);
-		} else if (found) {
-			vp->mappings[i - 1] = vp->mappings[i];
-		}
-	}
-	vp->numMappings--;
-	vp->mappings[vp->numMappings] = NULL;
-}
-
-enum { OPTION_MTRR };
-static const OptionInfoRec opts[] =
-{
-	{ OPTION_MTRR, "mtrr", OPTV_BOOLEAN, {0}, FALSE },
-	{ -1, NULL, OPTV_NONE, {0}, FALSE }
-};
-
-static void
-checkMtrrOption(VidMapPtr vp)
-{
-	if (!vp->mtrrOptChecked && vp->pScrn && vp->pScrn->options != NULL) {
-		OptionInfoPtr options;
-
-		options = xnfalloc(sizeof(opts));
-		(void)memcpy(options, opts, sizeof(opts));
-		xf86ProcessOptions(vp->pScrn->scrnIndex, vp->pScrn->options,
-					options);
-		if (xf86GetOptValBool(options, OPTION_MTRR, &vp->mtrrEnabled))
-			vp->mtrrFrom = X_CONFIG;
-		free(options);
-		vp->mtrrOptChecked = TRUE;
-	}
-}
-
-void
-xf86MakeNewMapping(int ScreenNum, int Flags, unsigned long Base, unsigned long Size, pointer Vbase)
-{
-	VidMapPtr vp;
-	MappingPtr mp;
-
-	vp = getVidMapRec(ScreenNum);
-	mp = newMapping(vp);
-	mp->size = Size;
-	mp->virtBase = Vbase;
-}
 
 void
 xf86InitVidMem(void)
@@ -180,111 +53,9 @@ xf86InitVidMem(void)
 	}
 }
 
-pointer
-xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
-{
-	pointer vbase = NULL;
-	VidMapPtr vp;
-	MappingPtr mp;
-
-	if (((Flags & VIDMEM_FRAMEBUFFER) &&
-	     (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))))
-	    FatalError("Mapping memory with more than one type\n");
-	    
-	xf86InitVidMem();
-	if (!vidMemInfo.initialised || !vidMemInfo.mapMem)
-		return NULL;
-
-	vbase = vidMemInfo.mapMem(ScreenNum, Base, Size, Flags);
-
-	if (!vbase || vbase == (pointer)-1)
-		return NULL;
-
-	vp = getVidMapRec(ScreenNum);
-	mp = newMapping(vp);
-	mp->size = Size;
-	mp->virtBase = vbase;
-
-	/*
-	 * Check the "mtrr" option even when MTRR isn't supported to avoid
-	 * warnings about unrecognised options.
-	 */
-	checkMtrrOption(vp);
-
-	if (vp->mtrrEnabled && vidMemInfo.setWC) {
-		if (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))
-			mp->mtrrInfo =
-				vidMemInfo.setWC(ScreenNum, Base, Size, FALSE,
-						 vp->mtrrFrom);
-		else if (Flags & VIDMEM_FRAMEBUFFER)
-			mp->mtrrInfo =
-				vidMemInfo.setWC(ScreenNum, Base, Size, TRUE,
-						 vp->mtrrFrom);
-	}
-	return vbase;
-}
-
-void
-xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-	VidMapPtr vp;
-	MappingPtr mp;
-
-	if (!vidMemInfo.initialised || !vidMemInfo.unmapMem) {
-		xf86DrvMsg(ScreenNum, X_WARNING,
-		  "xf86UnMapVidMem() called before xf86MapVidMem()\n");
-		return;
-	}
-
-	vp = getVidMapRec(ScreenNum);
-	mp = findMapping(vp, Base, Size);
-	if (!mp) {
-		xf86DrvMsg(ScreenNum, X_WARNING,
-		  "xf86UnMapVidMem: cannot find region for [%p,0x%lx]\n",
-		  Base, Size);
-		return;
-	}
-	if (vp->mtrrEnabled && vidMemInfo.undoWC && mp)
-		vidMemInfo.undoWC(ScreenNum, mp->mtrrInfo);
-
-	vidMemInfo.unmapMem(ScreenNum, Base, Size);
-	removeMapping(vp, mp);
-}
-
-Bool
-xf86CheckMTRR(int ScreenNum)
-{
-	VidMapPtr vp = getVidMapRec(ScreenNum);
-
-	/*
-	 * Check the "mtrr" option even when MTRR isn't supported to avoid
-	 * warnings about unrecognised options.
-	 */
-	checkMtrrOption(vp);
-
-	if (vp->mtrrEnabled && vidMemInfo.setWC)
-		return TRUE;
-		
-	return FALSE;
-}
-
 Bool
 xf86LinearVidMem(void)
 {
 	xf86InitVidMem();
 	return vidMemInfo.linearSupported;
 }
-
-void
-xf86MapReadSideEffects(int ScreenNum, int Flags, pointer base,
-			unsigned long Size)
-{
-	if (!(Flags & VIDMEM_READSIDEEFFECT))
-		return;
-
-	if (!vidMemInfo.initialised || !vidMemInfo.readSideEffects)
-		return;
-
-	vidMemInfo.readSideEffects(ScreenNum, base, Size);
-}
-
diff --git a/hw/xfree86/os-support/xf86OSpriv.h b/hw/xfree86/os-support/xf86OSpriv.h
index 754128d..cb85602 100644
--- a/hw/xfree86/os-support/xf86OSpriv.h
+++ b/hw/xfree86/os-support/xf86OSpriv.h
@@ -32,22 +32,8 @@
 #ifndef _XF86OSPRIV_H
 #define _XF86OSPRIV_H
 
-typedef pointer (*MapMemProcPtr)(int, unsigned long, unsigned long, int);
-typedef void (*UnmapMemProcPtr)(int, pointer, unsigned long);
-typedef pointer (*SetWCProcPtr)(int, unsigned long, unsigned long, Bool,
-				MessageType);
-typedef void (*ProtectMemProcPtr)(int, pointer, unsigned long, Bool); 
-typedef void (*UndoWCProcPtr)(int, pointer);
-typedef void (*ReadSideEffectsProcPtr)(int, pointer, unsigned long);
-
 typedef struct {
 	Bool			initialised;
-	MapMemProcPtr		mapMem;
-	UnmapMemProcPtr		unmapMem;
-	ProtectMemProcPtr	protectMem;
-	SetWCProcPtr		setWC;
-	UndoWCProcPtr		undoWC;
-	ReadSideEffectsProcPtr	readSideEffects;
 	Bool			linearSupported;
 } VidMemInfo, *VidMemInfoPtr;
 
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 6a29fbd..e844d10 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -75,24 +75,6 @@
  */ 
 
 /*
- * Flags for xf86MapVidMem().  Multiple flags can be or'd together.  The
- * flags may be used as hints.  For example it would be permissible to
- * enable write combining for memory marked only for framebuffer use.
- */
-
-#define VIDMEM_FRAMEBUFFER	0x01	/* memory for framebuffer use */
-#define VIDMEM_MMIO		0x02	/* memory for I/O use */
-#define VIDMEM_MMIO_32BIT	0x04	/* memory accesses >= 32bit */
-#define VIDMEM_READSIDEEFFECT	0x08	/* reads can have side-effects */
-#define VIDMEM_SPARSE		0x10	/* sparse mapping required
-					 * assumed when VIDMEM_MMIO is
-					 * set. May be used with
-					 * VIDMEM_FRAMEBUFFER) */
-#define VIDMEM_READONLY		0x20	/* read-only mapping
-					 * used when reading BIOS images
-					 * through xf86MapVidMem() */
-
-/*
  * OS-independent modem state flags for xf86SetSerialModemState() and
  * xf86GetSerialModemState().
  */
@@ -132,10 +114,6 @@ _XFUNCPROTOBEGIN
 
 /* public functions */
 extern _X_EXPORT Bool xf86LinearVidMem(void);
-extern _X_EXPORT Bool xf86CheckMTRR(int);
-extern _X_EXPORT pointer xf86MapVidMem(int, int, unsigned long, unsigned long);
-extern _X_EXPORT void xf86UnMapVidMem(int, pointer, unsigned long);
-extern _X_EXPORT void xf86MapReadSideEffects(int, int, pointer, unsigned long);
 extern _X_EXPORT int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *, int);
 extern _X_EXPORT Bool xf86EnableIO(void);
 extern _X_EXPORT void xf86DisableIO(void);
@@ -209,7 +187,6 @@ extern _X_EXPORT int xf86ProcessArgument(int, char **, int);
 extern _X_EXPORT void xf86UseMsg(void);
 extern _X_EXPORT PMClose xf86OSPMOpen(void);
 
-extern _X_EXPORT void xf86MakeNewMapping(int, int, unsigned long, unsigned long, pointer);
 extern _X_EXPORT void xf86InitVidMem(void);
 
 #endif /* XF86_OS_PRIVS */
commit 60de203cc2dc48ba27e8b1005b730f378cc63421
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 10 19:00:02 2011 -0400

    int10: Port internal users off xf86MapVidMem
    
    This API is apparently semi-deprecated even by XFree86 standards, and
    there are only four drivers left using it.  Let's start chopping it off.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index 20a07fc..22ebd47 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -103,8 +103,8 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     MapVRam(pInt);
 #ifdef _PC
     if (!sysMem)
-	sysMem = xf86MapVidMem(screen, VIDMEM_MMIO, V_BIOS,
-			       BIOS_SIZE + SYS_BIOS - V_BIOS);
+	pci_device_map_legacy(pInt->dev, V_BIOS, BIOS_SIZE + SYS_BIOS - V_BIOS,
+			      1, &sysMem);
     INTPriv(pInt)->sysMem = sysMem;
 
     if (xf86ReadBIOS(0, 0, base, LOW_PAGE_SIZE) < 0) {
diff --git a/hw/xfree86/int10/helper_exec.c b/hw/xfree86/int10/helper_exec.c
index f74da47..78e7810 100644
--- a/hw/xfree86/int10/helper_exec.c
+++ b/hw/xfree86/int10/helper_exec.c
@@ -680,10 +680,12 @@ static void
 SetResetBIOSVars(xf86Int10InfoPtr pInt, Bool set)
 {
     int pagesize = getpagesize();
-    unsigned char* base = xf86MapVidMem(pInt->scrnIndex,
-					VIDMEM_MMIO, 0, pagesize);
+    unsigned char* base;
     int i;
 
+    if (pci_device_map_legacy(pInt->dev, 0, pagesize, 1, (void **)&base))
+	return; /* eek */
+
     if (set) {
 	for (i = BIOS_SCRATCH_OFF; i < BIOS_SCRATCH_END; i++)
 	    MEM_WW(pInt, i, *(base + i));
@@ -692,7 +694,7 @@ SetResetBIOSVars(xf86Int10InfoPtr pInt, Bool set)
 	    *(base + i) = MEM_RW(pInt, i);
     }
     
-    xf86UnMapVidMem(pInt->scrnIndex,base,pagesize);
+    pci_device_unmap_legacy(pInt->dev, base, pagesize);
 }
 
 void
@@ -706,7 +708,9 @@ xf86Int10SaveRestoreBIOSVars(xf86Int10InfoPtr pInt, Bool save)
 	|| (!save && !pInt->BIOSScratch))
 	return;
     
-    base = xf86MapVidMem(pInt->scrnIndex, VIDMEM_MMIO, 0, pagesize);
+    if (pci_device_map_legacy(pInt->dev, 0, pagesize, 1, (void **)&base))
+	return; /* eek */
+
     base += BIOS_SCRATCH_OFF;
     if (save) {
 	if ((pInt->BIOSScratch
@@ -722,7 +726,7 @@ xf86Int10SaveRestoreBIOSVars(xf86Int10InfoPtr pInt, Bool save)
 	}
     }
     
-    xf86UnMapVidMem(pInt->scrnIndex,base - BIOS_SCRATCH_OFF ,pagesize);
+    pci_device_unmap_legacy(pInt->dev, base, pagesize);
 }
 #endif
 
commit 52e8757779482d4c965ca14a60bcc83ba30248fa
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 10 17:34:23 2011 -0400

    pci: Remove xf86MapDomainMemory
    
    This is slightly draconian, but that API is just awful.  In all but
    one case in the callers it's used to get a map of some legacy VGA
    memory, and it would be cleaner for the caller to just call
    pci_device_map_legacy.
    
    The sole exception is in the vesa driver, which uses it to avoid having
    to look up which device the BAR belongs to.  That's similarly trivial to
    fix.
    
    Having done that, Linux's PCI layer is now very small indeed.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index d51860d..7232098 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1496,7 +1496,6 @@ if test "x$XORG" = xauto; then
 fi
 AC_MSG_RESULT([$XORG])
 
-xorg_bus_linuxpci=no
 xorg_bus_bsdpci=no
 xorg_bus_sparc=no
 
@@ -1567,7 +1566,6 @@ if test "x$XORG" = xyes; then
 			XORG_CFLAGS="$XORG_CFLAGS -DXF86PM"
 		fi
 		XORG_OS_SUBDIR="linux"
-		xorg_bus_linuxpci="yes"
 		linux_acpi="no"
 		case $host_cpu in
 		  alpha*)
@@ -1750,7 +1748,6 @@ if test "x$XORG" = xyes; then
 	AC_SUBST([abi_extension])
 fi
 AM_CONDITIONAL([XORG], [test "x$XORG" = xyes])
-AM_CONDITIONAL([XORG_BUS_LINUXPCI], [test "x$xorg_bus_linuxpci" = xyes])
 AM_CONDITIONAL([XORG_BUS_BSDPCI], [test "x$xorg_bus_bsdpci" = xyes])
 AM_CONDITIONAL([XORG_BUS_SPARC], [test "x$xorg_bus_sparc" = xyes])
 AM_CONDITIONAL([LINUX_ALPHA], [test "x$linux_alpha" = xyes])
diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index 040d999..20a07fc 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -238,9 +238,7 @@ MapVRam(xf86Int10InfoPtr pInt)
     int pagesize = getpagesize();
     int size = ((VRAM_SIZE + pagesize - 1) / pagesize) * pagesize;
 
-    INTPriv(pInt)->vRam = xf86MapDomainMemory(pInt->scrnIndex, VIDMEM_MMIO,
-					      pInt->dev, V_RAM, size);
-
+    pci_device_map_legacy(pInt->dev, V_RAM, size, 1, &(INTPriv(pInt)->vRam));
     pInt->io = pci_legacy_open_io(pInt->dev, 0, 64 * 1024);
 }
 
@@ -251,8 +249,7 @@ UnmapVRam(xf86Int10InfoPtr pInt)
     int pagesize = getpagesize();
     int size = ((VRAM_SIZE + pagesize - 1)/pagesize) * pagesize;
 
-    xf86UnMapVidMem(screen, INTPriv(pInt)->vRam, size);
-
+    pci_device_unmap_legacy(pInt->dev, INTPriv(pInt)->vRam, size);
     pci_device_close_io(pInt->dev, pInt->io);
     pInt->io = NULL;
 }
diff --git a/hw/xfree86/os-support/bus/Makefile.am b/hw/xfree86/os-support/bus/Makefile.am
index 643cb25..b1ca8f9 100644
--- a/hw/xfree86/os-support/bus/Makefile.am
+++ b/hw/xfree86/os-support/bus/Makefile.am
@@ -3,10 +3,6 @@ sdk_HEADERS = xf86Pci.h
 
 PCI_SOURCES = Pci.c Pci.h
 
-if XORG_BUS_LINUXPCI
-PCI_SOURCES += linuxPci.c
-endif
-
 if XORG_BUS_BSDPCI
 PCI_SOURCES += bsd_pci.c
 endif
diff --git a/hw/xfree86/os-support/bus/bsd_pci.c b/hw/xfree86/os-support/bus/bsd_pci.c
index f51d5c0..7a5dbbb 100644
--- a/hw/xfree86/os-support/bus/bsd_pci.c
+++ b/hw/xfree86/os-support/bus/bsd_pci.c
@@ -48,13 +48,6 @@
 
 #include "pciaccess.h"
 
-pointer
-xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
-		    ADDRESS Base, unsigned long Size)
-{
-    return xf86MapVidMem(ScreenNum, Flags, Base, Size);
-}
-
 void
 osPciInit(void)
 {
diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
deleted file mode 100644
index 8f314b5..0000000
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright 1998 by Concurrent Computer Corporation
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of Concurrent Computer
- * Corporation not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission.  Concurrent Computer Corporation makes no representations
- * about the suitability of this software for any purpose.  It is
- * provided "as is" without express or implied warranty.
- *
- * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
- * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
- * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
- * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Copyright 1998 by Metro Link Incorporated
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of Metro Link
- * Incorporated not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission.  Metro Link Incorporated makes no representations
- * about the suitability of this software for any purpose.  It is
- * provided "as is" without express or implied warranty.
- *
- * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
- * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
- * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
- * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <stdio.h>
-#include "xf86_OSlib.h"
-#include "Pci.h"
-
-/**
- * \bug
- * The generation of the procfs file name for the domain != 0 case may not be 
- * correct.
- */
-static int
-linuxPciOpenFile(struct pci_device *dev, Bool write)
-{
-    static struct pci_device *last_dev = NULL;
-    static int	fd = -1,is_write = 0;
-    char		file[64];
-
-    if (dev == NULL) {
-	return -1;
-    }
-
-    if (fd == -1 || (write && (!is_write)) || (last_dev != dev)) {
-	if (fd != -1) {
-	    close(fd);
-	    fd = -1;
-	}
-
-	sprintf(file,"/sys/bus/pci/devices/%04u:%02x:%02x.%01x/config",
-		dev->domain, dev->bus, dev->dev, dev->func);
-
-	if (write) {
-	    fd = open(file,O_RDWR);
-	    if (fd != -1) is_write = TRUE;
-	} else {
-	    switch (is_write) {
-	    case TRUE:
-		fd = open(file,O_RDWR);
-		if (fd > -1)
-		    break;
-	    default:
-		fd = open(file,O_RDONLY);
-		is_write = FALSE;
-	    }
-	}
-
-	last_dev = dev;
-    }
-
-    return fd;
-}
-
-/*
- * Compiling the following simply requires the presence of <linux/pci.c>.
- * Actually running this is another matter altogether...
- *
- * This scheme requires that the kernel allow mmap()'ing of a host bridge's I/O
- * and memory spaces through its /proc/bus/pci/BUS/DFN entry.  Which one is
- * determined by a prior ioctl().
- *
- * For the sparc64 port, this means 2.4.12 or later.  For ppc, this
- * functionality is almost, but not quite there yet.  Alpha and other kernel
- * ports to multi-domain architectures still need to implement this.
- *
- * TO DO:  Address the deleterious reaction some host bridges have to master
- *         aborts.  This is already done for secondary PCI buses, but not yet
- *         for accesses to primary buses (except for the SPARC port, where
- *         master aborts are avoided during PCI scans).
- */
-
-#include <linux/pci.h>
-
-#ifndef PCIIOC_BASE		/* Ioctls for /proc/bus/pci/X/Y nodes. */
-#define PCIIOC_BASE		('P' << 24 | 'C' << 16 | 'I' << 8)
-
-/* Get controller for PCI device. */
-#define PCIIOC_CONTROLLER	(PCIIOC_BASE | 0x00)
-/* Set mmap state to I/O space. */
-#define PCIIOC_MMAP_IS_IO	(PCIIOC_BASE | 0x01)
-/* Set mmap state to MEM space. */
-#define PCIIOC_MMAP_IS_MEM	(PCIIOC_BASE | 0x02)
-/* Enable/disable write-combining. */
-#define PCIIOC_WRITE_COMBINE	(PCIIOC_BASE | 0x03)
-
-#endif
-
-static pointer
-linuxMapPci(int ScreenNum, int Flags, struct pci_device *dev,
-	    ADDRESS Base, unsigned long Size, int mmap_ioctl)
-{
-    /* Align to page boundary */
-    const ADDRESS realBase = Base & ~(getpagesize() - 1);
-    const ADDRESS Offset = Base - realBase;
-
-    do {
-	unsigned char *result;
-	int fd, mmapflags, prot;
-
-	xf86InitVidMem();
-
-	/* If dev is NULL, linuxPciOpenFile will return -1, and this routine
-	 * will fail gracefully.
-	 */
-        prot = ((Flags & VIDMEM_READONLY) == 0);
-        if (((fd = linuxPciOpenFile(dev, prot)) < 0) ||
-	    (ioctl(fd, mmap_ioctl, 0) < 0))
-	    break;
-
-/* Note:  IA-64 doesn't compile this and doesn't need to */
-#ifdef __ia64__
-
-# ifndef  MAP_WRITECOMBINED
-#  define MAP_WRITECOMBINED 0x00010000
-# endif
-# ifndef  MAP_NONCACHED
-#  define MAP_NONCACHED     0x00020000
-# endif
-
-	if (Flags & VIDMEM_FRAMEBUFFER)
-	    mmapflags = MAP_SHARED | MAP_WRITECOMBINED;
-	else
-	    mmapflags = MAP_SHARED | MAP_NONCACHED;
-
-#else /* !__ia64__ */
-
-	mmapflags = (Flags & VIDMEM_FRAMEBUFFER) / VIDMEM_FRAMEBUFFER;
-
-	if (ioctl(fd, PCIIOC_WRITE_COMBINE, mmapflags) < 0)
-	    break;
-
-	mmapflags = MAP_SHARED;
-
-#endif /* ?__ia64__ */
-
-
-	if (Flags & VIDMEM_READONLY)
-	    prot = PROT_READ;
-	else
-	    prot = PROT_READ | PROT_WRITE;
-
-	result = mmap(NULL, Size + Offset, prot, mmapflags, fd, realBase);
-
-	if (!result || ((pointer)result == MAP_FAILED))
-	    return NULL;
-
-	xf86MakeNewMapping(ScreenNum, Flags, realBase, Size + Offset, result);
-
-	return result + Offset;
-    } while (0);
-
-    if (mmap_ioctl == PCIIOC_MMAP_IS_MEM)
-	return xf86MapVidMem(ScreenNum, Flags, Base, Size);
-
-    return NULL;
-}
-
-static int
-linuxOpenLegacy(struct pci_device *dev, char *name)
-{
-    static const char PREFIX[] = "/sys/class/pci_bus/%04x:%02x/%s";
-    char path[sizeof(PREFIX) + 10];
-    int fd = -1;
-
-    while (dev != NULL) {
-	snprintf(path, sizeof(path) - 1, PREFIX, dev->domain, dev->bus, name);
-	fd = open(path, O_RDWR);
-	if (fd >= 0) {
-	    return fd;
-	}
-
-	dev = pci_device_get_parent_bridge(dev);
-    }
-
-    return fd;
-}
-
-/*
- * xf86MapDomainMemory - memory map PCI domain memory
- *
- * This routine maps the memory region in the domain specified by Tag and
- * returns a pointer to it.  The pointer is saved for future use if it's in
- * the legacy ISA memory space (memory in a domain between 0 and 1MB).
- */
-pointer
-xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
-		    ADDRESS Base, unsigned long Size)
-{
-    int fd = -1;
-    pointer addr;
-
-    /*
-     * We use /proc/bus/pci on non-legacy addresses or if the Linux sysfs
-     * legacy_mem interface is unavailable.
-     */
-    if ((Base > 1024*1024) || ((fd = linuxOpenLegacy(dev, "legacy_mem")) < 0))
-	return linuxMapPci(ScreenNum, Flags, dev, Base, Size,
-			   PCIIOC_MMAP_IS_MEM);
-    else
-	addr = mmap(NULL, Size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, Base);
-
-    if (fd >= 0)
-	close(fd);
-    if (addr == NULL || addr == MAP_FAILED) {
-	perror("mmap failure");
-	FatalError("xf86MapDomainMem():  mmap() failure\n");
-    }
-    return addr;
-}
diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h
index 6c9a0a1..74ead20 100644
--- a/hw/xfree86/os-support/bus/xf86Pci.h
+++ b/hw/xfree86/os-support/bus/xf86Pci.h
@@ -254,8 +254,6 @@ typedef enum {
 extern _X_EXPORT Bool xf86scanpci(void);
 
 /* Domain access functions.  Some of these probably shouldn't be public */
-extern _X_EXPORT pointer xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
-    ADDRESS Base, unsigned long Size);
 extern _X_EXPORT struct pci_io_handle *xf86MapLegacyIO(struct pci_device *dev);
 extern _X_EXPORT void xf86UnmapLegacyIO(struct pci_device *, struct pci_io_handle *);
 
diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c
index 072c599..2ce6352 100644
--- a/hw/xfree86/vgahw/vgaHW.c
+++ b/hw/xfree86/vgahw/vgaHW.c
@@ -1741,7 +1741,6 @@ Bool
 vgaHWMapMem(ScrnInfoPtr scrp)
 {
     vgaHWPtr hwp = VGAHWPTR(scrp);
-    int scr_index = scrp->scrnIndex;
     
     if (hwp->Base)
 	return TRUE;
@@ -1759,8 +1758,7 @@ vgaHWMapMem(ScrnInfoPtr scrp)
      * for now.
      */
     DebugF("Mapping VGAMem\n");
-    hwp->Base = xf86MapDomainMemory(scr_index, VIDMEM_MMIO_32BIT, hwp->dev,
-				    hwp->MapPhys, hwp->MapSize);
+    pci_device_map_legacy(hwp->dev, hwp->MapPhys, hwp->MapSize, 1, &hwp->Base);
     return hwp->Base != NULL;
 }
 
@@ -1769,13 +1767,12 @@ void
 vgaHWUnmapMem(ScrnInfoPtr scrp)
 {
     vgaHWPtr hwp = VGAHWPTR(scrp);
-    int scr_index = scrp->scrnIndex;
 
     if (hwp->Base == NULL)
 	return;
     
     DebugF("Unmapping VGAMem\n");
-    xf86UnMapVidMem(scr_index, hwp->Base, hwp->MapSize);
+    pci_device_unmap_legacy(hwp->dev, hwp->Base, hwp->MapSize);
     hwp->Base = NULL;
 }
 
commit bc8ed7e1a950ce68b45ab177b05f5306bc9f9f2d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 10 18:04:10 2011 -0400

    int10: Use pciaccess rom fetch for !PC machines
    
    ... instead of rolling our own, badly.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index beb90b5..040d999 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -62,62 +62,6 @@ static void UnmapVRam(xf86Int10InfoPtr pInt);
 
 static void *sysMem = NULL;
 
-/**
- * Read legacy VGA video BIOS associated with specified domain.
- * 
- * Attempts to read up to 128KiB of legacy VGA video BIOS.
- * 
- * \return
- * The number of bytes read on success or -1 on failure.
- *
- * \bug
- * PCI ROMs can contain multiple BIOS images (e.g., OpenFirmware, x86 VGA,
- * etc.).  How do we know that \c pci_device_read_rom will return the
- * legacy VGA BIOS image?
- */
-#ifndef _PC
-static int
-read_legacy_video_BIOS(struct pci_device *dev, unsigned char *Buf)
-{
-    const ADDRESS Base = 0xC0000;
-    const int Len = 0x10000 * 2;
-    const int pagemask = getpagesize() - 1;
-    const ADDRESS offset = Base & ~pagemask;
-    const unsigned long size = ((Base + Len + pagemask) & ~pagemask) - offset;
-    unsigned char *ptr, *src;
-    int len;
-
-
-    /* Try to use the civilized PCI interface first.
-     */
-    if (pci_device_read_rom(dev, Buf) == 0) {
-	return dev->rom_size;
-    }
-
-    ptr = xf86MapDomainMemory(-1, VIDMEM_READONLY, dev, offset, size);
-
-    if (!ptr)
-	return -1;
-
-    /* Using memcpy() here can hang the system */
-    src = ptr + (Base - offset);
-    for (len = 0; len < (Len / 2); len++) {
-	Buf[len] = src[len];
-    }
-
-    if ((Buf[0] == 0x55) && (Buf[1] == 0xAA) && (Buf[2] > 0x80)) {
-	for ( /* empty */ ; len < Len; len++) {
-	    Buf[len] = src[len];
-	}
-    }
-
-    xf86UnMapVidMem(-1, ptr, size);
-
-    return Len;
-}
-#endif /* _PC */
-
-
 xf86Int10InfoPtr
 xf86ExtendedInitInt10(int entityIndex, int Flags)
 {
@@ -232,7 +176,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
      */
     vbiosMem = (char *)base + V_BIOS;
     memset(vbiosMem, 0, 2 * V_BIOS_SIZE);
-    if (read_legacy_video_BIOS(pInt->dev, vbiosMem) < V_BIOS_SIZE) {
+    if (pci_device_read_rom(pInt->dev, vbiosMem) < V_BIOS_SIZE) {
 	xf86DrvMsg(screen, X_WARNING,
 		   "Unable to retrieve all of segment 0x0C0000.\n");
     }
commit 93c571e40b3a49678c1b29eb04d2452589c0f59f
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 10 16:41:08 2011 -0400

    pci: Deprecate the PCITAG type
    
    It is kept around to help drivers through the API transition and will be
    removed at some point in the future.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/int10/helper_exec.c b/hw/xfree86/int10/helper_exec.c
index 8b52e88..f74da47 100644
--- a/hw/xfree86/int10/helper_exec.c
+++ b/hw/xfree86/int10/helper_exec.c
@@ -475,7 +475,7 @@ static struct pci_device*
 pci_device_for_cfg_address (CARD32 addr)
 {
 	struct pci_device *dev = NULL;
-	PCITAG tag = PCI_TAG(addr);
+	CARD32 tag = PCI_TAG(addr);
 	struct pci_slot_match slot_match = {
 		.domain = PCI_DOM_FROM_TAG(tag),
 		.bus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(tag)),
diff --git a/hw/xfree86/os-support/bus/Pci.c b/hw/xfree86/os-support/bus/Pci.c
index f1dbfc2..0362a00 100644
--- a/hw/xfree86/os-support/bus/Pci.c
+++ b/hw/xfree86/os-support/bus/Pci.c
@@ -126,12 +126,6 @@
 
 #include "Pci.h"
 
-PCITAG
-pciTag(int busnum, int devnum, int funcnum)
-{
-	return(PCI_MAKE_TAG(busnum,devnum,funcnum));
-}
-
 Bool
 xf86scanpci(void)
 {
diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h
index 3a17c30..6c9a0a1 100644
--- a/hw/xfree86/os-support/bus/xf86Pci.h
+++ b/hw/xfree86/os-support/bus/xf86Pci.h
@@ -236,7 +236,7 @@
 /* Primitive Types */
 typedef unsigned long ADDRESS;		/* Memory/PCI address */
 typedef unsigned long IOADDRESS _X_DEPRECATED;	/* Must be large enough for a pointer */
-typedef unsigned long PCITAG;
+typedef CARD32 PCITAG _X_DEPRECATED;
 
 typedef enum {
     PCI_MEM,
@@ -251,7 +251,6 @@ typedef enum {
 
 
 /* Public PCI access functions */
-extern _X_EXPORT PCITAG pciTag(int busnum, int devnum, int funcnum);
 extern _X_EXPORT Bool xf86scanpci(void);
 
 /* Domain access functions.  Some of these probably shouldn't be public */
commit c0f46922ed41ff77661f60d292d33e194723d8a1
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Jan 7 17:20:15 2011 -0500

    xfree86: Remove unused bios_devmem.c
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/Makefile.am b/hw/xfree86/os-support/Makefile.am
index 348b7ff..094563d 100644
--- a/hw/xfree86/os-support/Makefile.am
+++ b/hw/xfree86/os-support/Makefile.am
@@ -16,6 +16,3 @@ libxorgos_la_LIBADD = @XORG_OS_SUBDIR@/lib at XORG_OS_SUBDIR@.la \
 
 AM_CFLAGS = $(DIX_CFLAGS) 
 
-# FIXME: These don't seem to be used anywhere
-EXTRA_DIST += \
-	shared/bios_devmem.c
diff --git a/hw/xfree86/os-support/shared/bios_devmem.c b/hw/xfree86/os-support/shared/bios_devmem.c
deleted file mode 100644
index b9dfb7d..0000000
--- a/hw/xfree86/os-support/shared/bios_devmem.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 1993 by David Wexelblat <dwex at goblin.org>
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of David Wexelblat not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  David Wexelblat makes no representations
- * about the suitability of this software for any purpose.  It is provided
- * "as is" without express or implied warranty.
- *
- * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-#include <string.h>
-
-/*
- * Read BIOS via /dev/mem.
- */
-
-#ifndef DEV_MEM
-# define DEV_MEM "/dev/mem"
-#endif
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-		int Len)
-{
- 	int fd;
-
-#ifdef __ia64__
-	if ((fd = open(DEV_MEM, O_RDONLY | O_SYNC)) < 0)
-#else
- 	if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
-#endif
-	{
-		xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
-			DEV_MEM, strerror(errno));
-		return -1;
-	}
-
-	if (lseek(fd, (Base+Offset), SEEK_SET) < 0)
-	{
-		xf86Msg(X_WARNING, "xf86ReadBIOS: %s seek failed (%s)\n",
-			DEV_MEM, strerror(errno));
-		close(fd);
-		return -1;
-	}
-	if (read(fd, Buf, Len) != Len)
-	{
-		xf86Msg(X_WARNING, "xf86ReadBIOS: %s read failed (%s)\n",
-			DEV_MEM, strerror(errno));
-		close(fd);
-		return -1;
-	}
-	close(fd);
-	return Len;
-}
commit 9e30a3bbc54cabd764a6e70858ffe7e5f2265832
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Jan 7 16:57:15 2011 -0500

    linux: Remove ia64 domain I/O support code
    
    pciaccess handles this now.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index b0d2643..d51860d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1570,14 +1570,10 @@ if test "x$XORG" = xyes; then
 		xorg_bus_linuxpci="yes"
 		linux_acpi="no"
 		case $host_cpu in
-		  ia64*)
-			linux_ia64=yes
-			linux_acpi="yes"
-			;;
 		  alpha*)
 		  	linux_alpha=yes
 			;;
-		  i*86|amd64*|x86_64*)
+		  i*86|amd64*|x86_64*|ia64*)
 			linux_acpi="yes"
 			;;
 		  *)
@@ -1757,7 +1753,6 @@ AM_CONDITIONAL([XORG], [test "x$XORG" = xyes])
 AM_CONDITIONAL([XORG_BUS_LINUXPCI], [test "x$xorg_bus_linuxpci" = xyes])
 AM_CONDITIONAL([XORG_BUS_BSDPCI], [test "x$xorg_bus_bsdpci" = xyes])
 AM_CONDITIONAL([XORG_BUS_SPARC], [test "x$xorg_bus_sparc" = xyes])
-AM_CONDITIONAL([LINUX_IA64], [test "x$linux_ia64" = xyes])
 AM_CONDITIONAL([LINUX_ALPHA], [test "x$linux_alpha" = xyes])
 AM_CONDITIONAL([LNXACPI], [test "x$linux_acpi" = xyes])
 AM_CONDITIONAL([SOLARIS_ASM_INLINE], [test "x$solaris_asm_inline" = xyes])
diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index 7a82627..36748df 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -1,9 +1,5 @@
 noinst_LTLIBRARIES = liblinux.la
 
-if LINUX_IA64
-PLATFORM_PCI_SUPPORT = $(srcdir)/../shared/ia64Pci.c
-PLATFORM_INCLUDES = -I$(srcdir)/../shared
-endif
 if LINUX_ALPHA
 noinst_LTLIBRARIES += liblinuxev56.la
 PLATFORM_PCI_SUPPORT = \
diff --git a/hw/xfree86/os-support/shared/ia64Pci.c b/hw/xfree86/os-support/shared/ia64Pci.c
deleted file mode 100644
index c93c74c..0000000
--- a/hw/xfree86/os-support/shared/ia64Pci.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (C) 2002-2003 The XFree86 Project, 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 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 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 THE
- * XFREE86 PROJECT 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.
- *
- * Except as contained in this notice, the name of the XFree86 Project shall
- * not be used in advertising or otherwise to promote the sale, use or other
- * dealings in this Software without prior written authorization from the
- * XFree86 Project.
- */
-
-/*
- * This file contains the glue needed to support various IA-64 chipsets.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <signal.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <linux/pci.h>
-
-#include "compiler.h"
-#include "Pci.h"
-
-/*
- * We use special in/out routines here since Altix platforms require the
- * use of the sysfs legacy_io interface.  The legacy_io file maps to the I/O
- * space of a given PCI domain; reads and writes are used to do port I/O.
- * The file descriptor for the file is stored in the upper bits of the
- * value passed in by the caller, and is created and populated by
- * xf86MapLegacyIO.
- *
- * If the legacy_io interface doesn't exist, we fall back to the glibc in/out
- * routines, which are prefixed by an underscore (e.g. _outb).
- */
-static int ia64_port_to_fd(unsigned long port)
-{
-    return (port >> 24) & 0xffffffff;
-}
-
-void outb(unsigned long port, unsigned char val)
-{
-    int fd = ia64_port_to_fd(port);
-
-    if (!fd) {
-	_outb(val, port & 0xffff);
-	goto out;
-    }
-    if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
-	ErrorF("I/O lseek failed\n");
-	goto out;
-    }
-    if (write(fd, &val, 1) != 1) {
-	ErrorF("I/O write failed\n");
-	goto out;
-    }
- out:
-    return;
-}
-
-void outw(unsigned long port, unsigned short val)
-{
-    int fd = ia64_port_to_fd(port);
-
-    if (!fd) {
-	_outw(val, port & 0xffff);
-	goto out;
-    }
-    if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
-	ErrorF("I/O lseek failed\n");
-	goto out;
-    }
-    if (write(fd, &val, 2) != 2) {
-	ErrorF("I/O write failed\n");
-	goto out;
-    }
- out:
-    return;
-}
-
-void outl(unsigned long port, unsigned int val)
-{
-    int fd = ia64_port_to_fd(port);
-
-    if (!fd) {
-	_outl(val, port & 0xffff);
-	goto out;
-    }
-    if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
-	ErrorF("I/O lseek failed\n");
-	goto out;
-    }
-    if (write(fd, &val, 4) != 4) {
-	ErrorF("I/O write failed\n");
-	goto out;
-    }
- out:
-    return;
-}
-
-unsigned int inb(unsigned long port)
-{
-    int fd = ia64_port_to_fd(port);
-    unsigned char val;
-
-    if (!fd)
-	return _inb(port & 0xffff);
-
-    if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
-	ErrorF("I/O lseek failed\n");
-	val = -1;
-	goto out;
-    }
-    if (read(fd, &val, 1) != 1) {
-	ErrorF("I/O read failed\n");
-	val = -1;
-	goto out;
-    }
- out:
-    return val;
-}
-
-unsigned int inw(unsigned long port)
-{
-    int fd = ia64_port_to_fd(port);
-    unsigned short val;
-
-    if (!fd)
-	return _inw(port & 0xffff);
-
-    if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
-	ErrorF("I/O lseek failed\n");
-	val = -1;
-	goto out;
-    }
-    if (read(fd, &val, 2) != 2) {
-	ErrorF("I/O read failed\n");
-	val = -1;
-	goto out;
-    }
- out:
-    return val;
-}
-
-unsigned int inl(unsigned long port)
-{
-    int fd = ia64_port_to_fd(port);
-    unsigned int val;
-
-    if (!fd)
-	return _inl(port & 0xffff);
-
-    if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
-	ErrorF("I/O lseek failed\n");
-	val = -1;
-	goto out;
-    }
-    if (read(fd, &val, 4) != 4) {
-	ErrorF("I/O read failed\n");
-	val = -1;
-	goto out;
-    }
- out:
-    return val;
-}
-
commit 16cb1dbe3dd3420b5b39aefe801621f75922ede4
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Oct 16 16:09:56 2009 -0400

    linux: Remove pre-2.6 PCI interface support
    
    If you haven't ported 2.6 to your architecture in the intervening seven
    years, you can keep running older servers.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
index 2778bba..8f314b5 100644
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ b/hw/xfree86/os-support/bus/linuxPci.c
@@ -63,47 +63,19 @@ linuxPciOpenFile(struct pci_device *dev, Bool write)
     static struct pci_device *last_dev = NULL;
     static int	fd = -1,is_write = 0;
     char		file[64];
-    struct stat	ignored;
-    static int is26 = -1;
 
     if (dev == NULL) {
 	return -1;
     }
 
-    if (is26 == -1) {
-	is26 = (stat("/sys/bus/pci", &ignored) < 0) ? 0 : 1;
-    }
-	
     if (fd == -1 || (write && (!is_write)) || (last_dev != dev)) {
 	if (fd != -1) {
 	    close(fd);
 	    fd = -1;
 	}
 
-	if (is26) {
-	    sprintf(file,"/sys/bus/pci/devices/%04u:%02x:%02x.%01x/config",
-		    dev->domain, dev->bus, dev->dev, dev->func);
-	} else {
-	    if (dev->domain == 0) {
-		sprintf(file,"/proc/bus/pci/%02x", dev->bus);
-		if (stat(file, &ignored) < 0) {
-		    sprintf(file, "/proc/bus/pci/0000:%02x/%02x.%1x",
-			    dev->bus, dev->dev, dev->func);
-		} else {
-		    sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
-			    dev->bus, dev->dev, dev->func);
-		}
-	    } else {
-		sprintf(file,"/proc/bus/pci/%02x%02x", dev->domain, dev->bus);
-		if (stat(file, &ignored) < 0) {
-		    sprintf(file, "/proc/bus/pci/%04x:%04x/%02x.%1x",
-			    dev->domain, dev->bus, dev->dev, dev->func);
-		} else {
-		    sprintf(file, "/proc/bus/pci/%02x%02x/%02x.%1x",
-			    dev->domain, dev->bus, dev->dev, dev->func);
-		}
-	    }
-	}
+	sprintf(file,"/sys/bus/pci/devices/%04u:%02x:%02x.%01x/config",
+		dev->domain, dev->bus, dev->dev, dev->func);
 
 	if (write) {
 	    fd = open(file,O_RDWR);
commit 7eba03aadbc31058fbd1c3736c75af1b34e2a14f
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Oct 16 14:05:54 2009 -0400

    bus: remove some dead struct fields
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index 89db4cc..54f6c64 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -51,11 +51,9 @@
  */
 
 typedef struct {
-	unsigned long 	physBase;
 	unsigned long 	size;
 	pointer		virtBase;
 	pointer 	mtrrInfo;
-	int		flags;
 } MappingRec, *MappingPtr;
 	
 typedef struct {
@@ -169,10 +167,8 @@ xf86MakeNewMapping(int ScreenNum, int Flags, unsigned long Base, unsigned long S
 
 	vp = getVidMapRec(ScreenNum);
 	mp = newMapping(vp);
-	mp->physBase = Base;
 	mp->size = Size;
 	mp->virtBase = Vbase;
-	mp->flags = Flags;
 }
 
 void
@@ -206,10 +202,8 @@ xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
 
 	vp = getVidMapRec(ScreenNum);
 	mp = newMapping(vp);
-	mp->physBase = Base;
 	mp->size = Size;
 	mp->virtBase = vbase;
-	mp->flags = Flags;
 
 	/*
 	 * Check the "mtrr" option even when MTRR isn't supported to avoid
commit e1b98233369e60e9c9d44dc121a1e598cd541474
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 20 11:42:11 2010 -0400

    linux: Use pci_device_get_parent_bridge instead of open-coding it
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
index 28bba01..2778bba 100644
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ b/hw/xfree86/os-support/bus/linuxPci.c
@@ -160,45 +160,6 @@ linuxPciOpenFile(struct pci_device *dev, Bool write)
 
 #endif
 
-/* This probably shouldn't be Linux-specific */
-static struct pci_device *
-get_parent_bridge(struct pci_device *dev)
-{
-    struct pci_id_match bridge_match = {
-	PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
-	(PCI_CLASS_BRIDGE << 16) | (PCI_SUBCLASS_BRIDGE_PCI << 8),
-	0
-    };
-    struct pci_device *bridge;
-    struct pci_device_iterator *iter;
-
-    if (dev == NULL) {
-	return NULL;
-    }
-
-    iter = pci_id_match_iterator_create(& bridge_match);
-    if (iter == NULL) {
-	return NULL;
-    }
-
-    while ((bridge = pci_device_next(iter)) != NULL) {
-	if (bridge->domain == dev->domain) {
-	    const struct pci_bridge_info *info = 
-		pci_device_get_bridge_info(bridge);
-
-	    if (info != NULL) {
-		if (info->secondary_bus == dev->bus) {
-		    break;
-		}
-	    }
-	}
-    }
-
-    pci_iterator_destroy(iter);
-
-    return bridge;
-}
-
 static pointer
 linuxMapPci(int ScreenNum, int Flags, struct pci_device *dev,
 	    ADDRESS Base, unsigned long Size, int mmap_ioctl)
@@ -283,7 +244,7 @@ linuxOpenLegacy(struct pci_device *dev, char *name)
 	    return fd;
 	}
 
-	dev = get_parent_bridge(dev);
+	dev = pci_device_get_parent_bridge(dev);
     }
 
     return fd;
commit 4243c78b00b2d2881b20c7c0f0d8be8af850f325
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 16 13:33:04 2011 -0400

    pci: Port xf86MapLegacyIO to pciaccess
    
    Per-domain I/O is now something drivers must manually request, and must
    keep track of within their own state rather than in the ScrnInfoRec.
    It's not really possible to split that into two steps without an
    additional intermediate ABI break, so don't even try.  Drivers that want
    source compatibility should ifdef on the presence of xf86UnmapLegacyIO.
    
    As a fringe benefit, domain-aware I/O is now OS-independent, relying
    only on support in pciaccess.  Simplify OS PCI setup to reflect this.
    
    The IOADDRESS type is kept around to help drivers through the API
    transition and will be removed at some point in the future.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 3b08968..8749a29 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -308,7 +308,6 @@ xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex)
     pScrn->entityInstanceList = xnfrealloc(pScrn->entityInstanceList,
 				    pScrn->numEntities * sizeof(int));
     pScrn->entityInstanceList[pScrn->numEntities - 1] = 0;
-    pScrn->domainIOBase = xf86Entities[entityIndex]->domainIO;
 }
 
 void
diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h
index e161c7f..0b2ebdb 100644
--- a/hw/xfree86/common/xf86Bus.h
+++ b/hw/xfree86/common/xf86Bus.h
@@ -58,7 +58,6 @@ typedef struct {
     DevUnion *                  entityPrivates;
     int                         numInstances;
     GDevPtr *                   devices;   
-    IOADDRESS                   domainIO;
 } EntityRec, *EntityPtr;
 
 #define ACCEL_IS_SHARABLE 0x100
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 447b192..2acf486 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -235,11 +235,6 @@ xf86ClaimPciSlot(struct pci_device * d, DriverPtr drvp,
             xf86AddDevToEntity(num, dev);
 	pciSlotClaimed = TRUE;
 
-	if (active) {
-	    /* Map in this domain's I/O space */
-	   p->domainIO = xf86MapLegacyIO(d);
-	}
-	
  	return num;
     } else
  	return -1;
@@ -1357,3 +1352,15 @@ xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
     if (*chipset < 0)
         *chipset = (pVideo->vendor_id << 16) | pVideo->device_id;
 }
+
+struct pci_io_handle *
+xf86MapLegacyIO(struct pci_device *dev)
+{
+    return pci_legacy_open_io(dev, 0, 64 * 1024);
+}
+
+void
+xf86UnmapLegacyIO(struct pci_device *dev, struct pci_io_handle *handle)
+{
+    pci_device_close_io(dev, handle);
+}
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 0493dc5..43e9d1d 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -742,7 +742,6 @@ typedef struct _ScrnInfoRec {
     unsigned long	biosBase;		/* Base address of video BIOS */
     unsigned long	memPhysBase;		/* Physical address of FB */
     unsigned long 	fbOffset;		/* Offset of FB in the above */
-    IOADDRESS    	domainIOBase;		/* Domain I/O base address */
     int			memClk;			/* memory clock */
     int			textClockFreq;		/* clock of text mode */
     Bool		flipPixels;		/* swap default black/white */
diff --git a/hw/xfree86/os-support/bus/Pci.c b/hw/xfree86/os-support/bus/Pci.c
index fe4850e..f1dbfc2 100644
--- a/hw/xfree86/os-support/bus/Pci.c
+++ b/hw/xfree86/os-support/bus/Pci.c
@@ -140,7 +140,7 @@ xf86scanpci(void)
     success = (pci_system_init() == 0);
 
     /* choose correct platform/OS specific PCI init routine */
-	ARCH_PCI_INIT();
+    osPciInit();
 
     return success;
 }
diff --git a/hw/xfree86/os-support/bus/Pci.h b/hw/xfree86/os-support/bus/Pci.h
index 3493013..88560ec 100644
--- a/hw/xfree86/os-support/bus/Pci.h
+++ b/hw/xfree86/os-support/bus/Pci.h
@@ -137,20 +137,14 @@
 #define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu)
 #define PCI_TAG_NO_DOMAIN(tag) ((tag) & 0x00ffff00u)
 
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+#if defined(linux)
+#define osPciInit(x) do {} while (0)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
 	defined(__OpenBSD__) || defined(__NetBSD__) || \
 	defined(__DragonFly__) || defined(__sun) || defined(__GNU__)
-#define ARCH_PCI_INIT bsdPciInit
-#endif
-
-#if defined(linux)
-#define ARCH_PCI_INIT linuxPciInit
-#endif /* defined(linux) */
-
-#ifndef ARCH_PCI_INIT
+extern void osPciInit(void);
+#else
 #error No PCI support available for this architecture/OS combination
 #endif
 
-extern void ARCH_PCI_INIT(void);
-
 #endif /* _PCI_H */
diff --git a/hw/xfree86/os-support/bus/bsd_pci.c b/hw/xfree86/os-support/bus/bsd_pci.c
index 17b52db..f51d5c0 100644
--- a/hw/xfree86/os-support/bus/bsd_pci.c
+++ b/hw/xfree86/os-support/bus/bsd_pci.c
@@ -55,15 +55,8 @@ xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
     return xf86MapVidMem(ScreenNum, Flags, Base, Size);
 }
 
-IOADDRESS
-xf86MapLegacyIO(struct pci_device *dev)
-{
-    (void)dev;
-    return 0;
-}
-
 void
-bsdPciInit(void)
+osPciInit(void)
 {
     xf86InitVidMem();
 }
diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
index fcfdbcb..28bba01 100644
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ b/hw/xfree86/os-support/bus/linuxPci.c
@@ -52,21 +52,6 @@
 #include "xf86_OSlib.h"
 #include "Pci.h"
 
-static const struct pci_id_match match_host_bridge = {
-    PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
-    (PCI_CLASS_BRIDGE << 16) | (PCI_SUBCLASS_BRIDGE_HOST << 8),
-    0x0000ffff00, 0
-};
-
-#define MAX_DOMAINS 257
-static pointer DomainMmappedIO[MAX_DOMAINS];
-
-void
-linuxPciInit(void)
-{
-    memset(DomainMmappedIO, 0, sizeof(DomainMmappedIO));
-}
-
 /**
  * \bug
  * The generation of the procfs file name for the domain != 0 case may not be 
@@ -153,15 +138,6 @@ linuxPciOpenFile(struct pci_device *dev, Bool write)
  * functionality is almost, but not quite there yet.  Alpha and other kernel
  * ports to multi-domain architectures still need to implement this.
  *
- * This scheme is also predicated on the use of an IOADDRESS compatible type to
- * designate I/O addresses.  Although IOADDRESS is defined as an unsigned
- * integral type, it is actually the virtual address of, i.e. a pointer to, the
- * I/O port to access.  And so, the inX/outX macros in "compiler.h" need to be
- * #define'd appropriately (as is done on SPARC's).
- *
- * Another requirement to port this scheme to another multi-domain architecture
- * is to add the appropriate entries in the pciControllerSizes array below.
- *
  * TO DO:  Address the deleterious reaction some host bridges have to master
  *         aborts.  This is already done for secondary PCI buses, but not yet
  *         for accesses to primary buses (except for the SPARC port, where
@@ -223,67 +199,6 @@ get_parent_bridge(struct pci_device *dev)
     return bridge;
 }
 
-/*
- * This is ugly, but until I can extract this information from the kernel,
- * it'll have to do.  The default I/O space size is 64K, and 4G for memory.
- * Anything else needs to go in this table.  (PowerPC folk take note.)
- *
- * Note that Linux/SPARC userland is 32-bit, so 4G overflows to zero here.
- *
- * Please keep this table in ascending vendor/device order.
- */
-static const struct pciSizes {
-    unsigned short vendor, device;
-    unsigned long io_size, mem_size;
-} pciControllerSizes[] = {
-    {
-	PCI_VENDOR_SUN, PCI_CHIP_PSYCHO,
-	1U << 16, 1U << 31
-    },
-    {
-	PCI_VENDOR_SUN, PCI_CHIP_SCHIZO,
-	1U << 24, 1U << 31	/* ??? */
-    },
-    {
-	PCI_VENDOR_SUN, PCI_CHIP_SABRE,
-	1U << 24, (unsigned long)(1ULL << 32)
-    },
-    {
-	PCI_VENDOR_SUN, PCI_CHIP_HUMMINGBIRD,
-	1U << 24, (unsigned long)(1ULL << 32)
-    }
-};
-#define NUM_SIZES (sizeof(pciControllerSizes) / sizeof(pciControllerSizes[0]))
-
-static const struct pciSizes *
-linuxGetSizesStruct(const struct pci_device *dev)
-{
-    static const struct pciSizes default_size = {
-	0, 0, 1U << 16, (unsigned long)(1ULL << 32)
-    };
-    int          i;
-
-    /* Look up vendor/device */
-    if (dev != NULL) {
-	for (i = 0;  i < NUM_SIZES;  i++) {
-	    if ((dev->vendor_id == pciControllerSizes[i].vendor)
-		&& (dev->device_id == pciControllerSizes[i].device)) {
-		return & pciControllerSizes[i];
-	    }
-	}
-    }
-
-    /* Default to 64KB I/O and 4GB memory. */
-    return & default_size;
-}
-
-static __inline__ unsigned long
-linuxGetIOSize(const struct pci_device *dev)
-{
-    const struct pciSizes * const sizes = linuxGetSizesStruct(dev);
-    return sizes->io_size;
-}
-
 static pointer
 linuxMapPci(int ScreenNum, int Flags, struct pci_device *dev,
 	    ADDRESS Base, unsigned long Size, int mmap_ioctl)
@@ -406,45 +321,3 @@ xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
     }
     return addr;
 }
-
-/**
- * Map I/O space in this domain
- *
- * Each domain has a legacy ISA I/O space.  This routine will try to
- * map it using the Linux sysfs legacy_io interface.  If that fails,
- * it'll fall back to using /proc/bus/pci.
- *
- * If the legacy_io interface \b does exist, the file descriptor (\c fd below)
- * will be saved in the \c DomainMmappedIO array in the upper bits of the
- * pointer.  Callers will do I/O with small port numbers (<64k values), so
- * the platform I/O code can extract the port number and the \c fd, \c lseek
- * to the port number in the legacy_io file, and issue the read or write.
- *
- * This has no means of returning failure, so all errors are fatal
- */
-IOADDRESS
-xf86MapLegacyIO(struct pci_device *dev)
-{
-    const int domain = dev->domain;
-    struct pci_device *bridge = get_parent_bridge(dev);
-    int fd;
-
-    if (domain >= MAX_DOMAINS)
-	FatalError("xf86MapLegacyIO():  domain out of range\n");
-
-    if (DomainMmappedIO[domain] == NULL) {
-	/* Permanently map all of I/O space */
-	fd = linuxOpenLegacy(bridge, "legacy_io");
-	if (fd < 0) {
-	    DomainMmappedIO[domain] = linuxMapPci(-1, VIDMEM_MMIO, bridge,
-						  0, linuxGetIOSize(bridge),
-						  PCIIOC_MMAP_IS_IO);
-	}
-	else { /* legacy_io file exists, encode fd */
-	    DomainMmappedIO[domain] = (pointer)(intptr_t)(fd << 24);
-	}
-    }
-
-    return (IOADDRESS)DomainMmappedIO[domain];
-}
-
diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h
index ce1336b..3a17c30 100644
--- a/hw/xfree86/os-support/bus/xf86Pci.h
+++ b/hw/xfree86/os-support/bus/xf86Pci.h
@@ -235,7 +235,7 @@
 
 /* Primitive Types */
 typedef unsigned long ADDRESS;		/* Memory/PCI address */
-typedef unsigned long IOADDRESS;	/* Must be large enough for a pointer */
+typedef unsigned long IOADDRESS _X_DEPRECATED;	/* Must be large enough for a pointer */
 typedef unsigned long PCITAG;
 
 typedef enum {
@@ -257,6 +257,7 @@ extern _X_EXPORT Bool xf86scanpci(void);
 /* Domain access functions.  Some of these probably shouldn't be public */
 extern _X_EXPORT pointer xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
     ADDRESS Base, unsigned long Size);
-extern _X_EXPORT IOADDRESS xf86MapLegacyIO(struct pci_device *dev);
+extern _X_EXPORT struct pci_io_handle *xf86MapLegacyIO(struct pci_device *dev);
+extern _X_EXPORT void xf86UnmapLegacyIO(struct pci_device *, struct pci_io_handle *);
 
 #endif /* _XF86PCI_H */
commit 8074591f5612dd47612414ed3873a87948aab7fd
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Sep 20 18:12:29 2011 -0400

    vgahw: Port to pciaccess IO space routines
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c
index 9e934f6..072c599 100644
--- a/hw/xfree86/vgahw/vgaHW.c
+++ b/hw/xfree86/vgahw/vgaHW.c
@@ -163,67 +163,67 @@ static CARD8 defaultDAC[768] =
 static void
 stdWriteCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value)
 {
-    outb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_INDEX_OFFSET, index);
-    outb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_DATA_OFFSET, value);
+    pci_io_write8(hwp->io, hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index);
+    pci_io_write8(hwp->io, hwp->IOBase + VGA_CRTC_DATA_OFFSET, value);
 }
 
 static CARD8
 stdReadCrtc(vgaHWPtr hwp, CARD8 index)
 {
-    outb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_INDEX_OFFSET, index);
-    return inb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_DATA_OFFSET);
+    pci_io_write8(hwp->io, hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index);
+    return pci_io_read8(hwp->io, hwp->IOBase + VGA_CRTC_DATA_OFFSET);
 }
 
 static void
 stdWriteGr(vgaHWPtr hwp, CARD8 index, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_GRAPH_INDEX, index);
-    outb(hwp->PIOOffset + VGA_GRAPH_DATA, value);
+    pci_io_write8(hwp->io, VGA_GRAPH_INDEX, index);
+    pci_io_write8(hwp->io, VGA_GRAPH_DATA, value);
 }
 
 static CARD8
 stdReadGr(vgaHWPtr hwp, CARD8 index)
 {
-    outb(hwp->PIOOffset + VGA_GRAPH_INDEX, index);
-    return inb(hwp->PIOOffset + VGA_GRAPH_DATA);
+    pci_io_write8(hwp->io, VGA_GRAPH_INDEX, index);
+    return pci_io_read8(hwp->io, VGA_GRAPH_DATA);
 }
 
 static void
 stdWriteSeq(vgaHWPtr hwp, CARD8 index, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_SEQ_INDEX, index);
-    outb(hwp->PIOOffset + VGA_SEQ_DATA, value);
+    pci_io_write8(hwp->io, VGA_SEQ_INDEX, index);
+    pci_io_write8(hwp->io, VGA_SEQ_DATA, value);
 }
 
 static CARD8
 stdReadSeq(vgaHWPtr hwp, CARD8 index)
 {
-    outb(hwp->PIOOffset + VGA_SEQ_INDEX, index);
-    return inb(hwp->PIOOffset + VGA_SEQ_DATA);
+    pci_io_write8(hwp->io, VGA_SEQ_INDEX, index);
+    return pci_io_read8(hwp->io, VGA_SEQ_DATA);
 }
 
 static CARD8
 stdReadST00(vgaHWPtr hwp)
 {
-    return inb(hwp->PIOOffset + VGA_IN_STAT_0);
+    return pci_io_read8(hwp->io, VGA_IN_STAT_0);
 }
 
 static CARD8
 stdReadST01(vgaHWPtr hwp)
 {
-    return inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
+    return pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET);
 }
 
 static CARD8
 stdReadFCR(vgaHWPtr hwp)
 {
-    return inb(hwp->PIOOffset + VGA_FEATURE_R);
+    return pci_io_read8(hwp->io, VGA_FEATURE_R);
 }
 
 static void
 stdWriteFCR(vgaHWPtr hwp, CARD8 value)
 {
-    outb(hwp->IOBase + hwp->PIOOffset + VGA_FEATURE_W_OFFSET,value);
+    pci_io_write8(hwp->io, hwp->IOBase + VGA_FEATURE_W_OFFSET,value);
 }
 
 static void
@@ -234,9 +234,9 @@ stdWriteAttr(vgaHWPtr hwp, CARD8 index, CARD8 value)
     else
 	index |= 0x20;
 
-    (void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
-    outb(hwp->PIOOffset + VGA_ATTR_INDEX, index);
-    outb(hwp->PIOOffset + VGA_ATTR_DATA_W, value);
+    (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET);
+    pci_io_write8(hwp->io, VGA_ATTR_INDEX, index);
+    pci_io_write8(hwp->io, VGA_ATTR_DATA_W, value);
 }
 
 static CARD8
@@ -247,85 +247,85 @@ stdReadAttr(vgaHWPtr hwp, CARD8 index)
     else
 	index |= 0x20;
 
-    (void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
-    outb(hwp->PIOOffset + VGA_ATTR_INDEX, index);
-    return inb(hwp->PIOOffset + VGA_ATTR_DATA_R);
+    (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET);
+    pci_io_write8(hwp->io, VGA_ATTR_INDEX, index);
+    return pci_io_read8(hwp->io, VGA_ATTR_DATA_R);
 }
 
 static void
 stdWriteMiscOut(vgaHWPtr hwp, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_MISC_OUT_W, value);
+    pci_io_write8(hwp->io, VGA_MISC_OUT_W, value);
 }
 
 static CARD8
 stdReadMiscOut(vgaHWPtr hwp)
 {
-    return inb(hwp->PIOOffset + VGA_MISC_OUT_R);
+    return pci_io_read8(hwp->io, VGA_MISC_OUT_R);
 }
 
 static void
 stdEnablePalette(vgaHWPtr hwp)
 {
-    (void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
-    outb(hwp->PIOOffset + VGA_ATTR_INDEX, 0x00);
+    (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET);
+    pci_io_write8(hwp->io, VGA_ATTR_INDEX, 0x00);
     hwp->paletteEnabled = TRUE;
 }
 
 static void
 stdDisablePalette(vgaHWPtr hwp)
 {
-    (void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
-    outb(hwp->PIOOffset + VGA_ATTR_INDEX, 0x20);
+    (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET);
+    pci_io_write8(hwp->io, VGA_ATTR_INDEX, 0x20);
     hwp->paletteEnabled = FALSE;
 }
 
 static void
 stdWriteDacMask(vgaHWPtr hwp, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_DAC_MASK, value);
+    pci_io_write8(hwp->io, VGA_DAC_MASK, value);
 }
 
 static CARD8
 stdReadDacMask(vgaHWPtr hwp)
 {
-    return inb(hwp->PIOOffset + VGA_DAC_MASK);
+    return pci_io_read8(hwp->io, VGA_DAC_MASK);
 }
 
 static void
 stdWriteDacReadAddr(vgaHWPtr hwp, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_DAC_READ_ADDR, value);
+    pci_io_write8(hwp->io, VGA_DAC_READ_ADDR, value);
 }
 
 static void
 stdWriteDacWriteAddr(vgaHWPtr hwp, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_DAC_WRITE_ADDR, value);
+    pci_io_write8(hwp->io, VGA_DAC_WRITE_ADDR, value);
 }
 
 static void
 stdWriteDacData(vgaHWPtr hwp, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_DAC_DATA, value);
+    pci_io_write8(hwp->io, VGA_DAC_DATA, value);
 }
 
 static CARD8
 stdReadDacData(vgaHWPtr hwp)
 {
-    return inb(hwp->PIOOffset + VGA_DAC_DATA);
+    return pci_io_read8(hwp->io, VGA_DAC_DATA);
 }
 
 static CARD8
 stdReadEnable(vgaHWPtr hwp)
 {
-    return inb(hwp->PIOOffset + VGA_ENABLE);
+    return pci_io_read8(hwp->io, VGA_ENABLE);
 }
 
 static void
 stdWriteEnable(vgaHWPtr hwp, CARD8 value)
 {
-    outb(hwp->PIOOffset + VGA_ENABLE, value);
+    pci_io_write8(hwp->io, VGA_ENABLE, value);
 }
 
 void
@@ -353,9 +353,10 @@ vgaHWSetStdFuncs(vgaHWPtr hwp)
     hwp->writeDacReadAddr	= stdWriteDacReadAddr;
     hwp->writeDacData		= stdWriteDacData;
     hwp->readDacData		= stdReadDacData;
-    hwp->PIOOffset		= 0;
     hwp->readEnable		= stdReadEnable;
     hwp->writeEnable		= stdWriteEnable;
+
+    hwp->io = pci_legacy_open_io(hwp->dev, 0, 64 * 1024);
 }
 
 /*
@@ -1719,7 +1720,9 @@ vgaHWFreeHWRec(ScrnInfoPtr scrp)
 	vgaHWPtr hwp = VGAHWPTR(scrp);
 
 	if (!hwp)
-	    return;
+            return;
+
+        pci_device_close_io(hwp->dev, hwp->io);
 
 	free(hwp->FontInfo1);
 	free(hwp->FontInfo2);
@@ -1789,8 +1792,7 @@ vgaHWGetIOBase(vgaHWPtr hwp)
     hwp->IOBase = (hwp->readMiscOut(hwp) & 0x01) ?
 				VGA_IOBASE_COLOR : VGA_IOBASE_MONO;
     xf86DrvMsgVerb(hwp->pScrn->scrnIndex, X_INFO, 3,
-	"vgaHWGetIOBase: hwp->IOBase is 0x%04x, hwp->PIOOffset is 0x%04lx\n",
-	hwp->IOBase, hwp->PIOOffset);
+	"vgaHWGetIOBase: hwp->IOBase is 0x%04x\n", hwp->IOBase);
 }
 
 
@@ -1995,11 +1997,12 @@ SaveScreenProcPtr vgaHWSaveScreenWeak(void)
 void
 xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc)(ScrnInfoPtr, int),
 	      void (*ProtectRegs)(ScrnInfoPtr, Bool),
-	      void (*BlankScreen)(ScrnInfoPtr, Bool), IOADDRESS vertsyncreg,
+	      void (*BlankScreen)(ScrnInfoPtr, Bool), unsigned long vertsyncreg,
 	      int maskval, int knownclkindex, int knownclkvalue)
 {
     register int status = vertsyncreg;
     unsigned long i, cnt, rcnt, sync;
+    vgaHWPtr hwp = VGAHWPTR(pScrn);
 
     /* First save registers that get written on */
     (*ClockFunc)(pScrn, CLK_REG_SAVE);
@@ -2026,22 +2029,22 @@ xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc)(ScrnInfoPtr, int),
 	cnt  = 0;
 	sync = 200000;
 
-	while ((inb(status) & maskval) == 0x00)
+	while ((pci_io_read8(hwp->io, status) & maskval) == 0x00)
 	    if (sync-- == 0) goto finish;
 	/* Something appears to be happening, so reset sync count */
 	sync = 200000;
-	while ((inb(status) & maskval) == maskval)
+	while ((pci_io_read8(hwp->io, status) & maskval) == maskval)
 	    if (sync-- == 0) goto finish;
 	/* Something appears to be happening, so reset sync count */
 	sync = 200000;
-	while ((inb(status) & maskval) == 0x00)
+	while ((pci_io_read8(hwp->io, status) & maskval) == 0x00)
 	    if (sync-- == 0) goto finish;
 
 	for (rcnt = 0; rcnt < 5; rcnt++)
 	{
-	    while (!(inb(status) & maskval))
+	    while (!(pci_io_read8(hwp->io, status) & maskval))
 		cnt++;
-	    while ((inb(status) & maskval))
+	    while ((pci_io_read8(hwp->io, status) & maskval))
 		cnt++;
 	}
 
diff --git a/hw/xfree86/vgahw/vgaHW.h b/hw/xfree86/vgahw/vgaHW.h
index 12cfac0..e943aa3 100644
--- a/hw/xfree86/vgahw/vgaHW.h
+++ b/hw/xfree86/vgahw/vgaHW.h
@@ -151,17 +151,13 @@ typedef struct _vgaHWRec {
     vgaHWWriteProcPtr		writeDacData;
     vgaHWReadProcPtr		readDacData;
     pointer                     ddc;
-    IOADDRESS			PIOOffset;	/* offset + vgareg
-						   = pioreg */
+    struct pci_io_handle        *io;
     vgaHWReadProcPtr		readEnable;
     vgaHWWriteProcPtr		writeEnable;
     struct pci_device          *dev;
 } vgaHWRec;
 
 /* Some macros that VGA drivers can use in their ChipProbe() function */
-#define VGAHW_GET_IOBASE()	((inb(VGA_MISC_OUT_R) & 0x01) ?		      \
-					 VGA_IOBASE_COLOR : VGA_IOBASE_MONO)
-
 #define OVERSCAN 0x11		/* Index of OverScan register */
 
 /* Flags that define how overscan correction should take place */
@@ -174,15 +170,11 @@ typedef struct _vgaHWRec {
 #define BITS_PER_GUN 6
 #define COLORMAP_SIZE 256
 
-#if defined(__powerpc__) || defined(__arm__) || defined(__s390__) || defined(__nds32__)
-#define DACDelay(hw) /* No legacy VGA support */
-#else
-#define DACDelay(hw)							      \
-	do {								      \
-	    (void)inb((hw)->PIOOffset + (hw)->IOBase + VGA_IN_STAT_1_OFFSET); \
-	    (void)inb((hw)->PIOOffset + (hw)->IOBase + VGA_IN_STAT_1_OFFSET); \
+#define DACDelay(hw)							 \
+	do {								 \
+	    pci_io_read8((hw)->io, (hw)->IOBase + VGA_IN_STAT_1_OFFSET); \
+	    pci_io_read8((hw)->io, (hw)->IOBase + VGA_IN_STAT_1_OFFSET); \
 	} while (0)
-#endif
 
 /* Function Prototypes */
 
@@ -235,7 +227,7 @@ extern _X_EXPORT void xf86GetClocks(ScrnInfoPtr pScrn, int num,
 		   Bool (*ClockFunc)(ScrnInfoPtr, int),
 		   void (*ProtectRegs)(ScrnInfoPtr, Bool),
 		   void (*BlankScreen)(ScrnInfoPtr, Bool),
-		   IOADDRESS vertsyncreg, int maskval,
+		   unsigned long vertsyncreg, int maskval,
 		   int knownclkindex, int knownclkvalue);
 
 #endif /* _VGAHW_H */
commit 17b9ec191de0f1f9070f9fafc9138484b14c78da
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 22 13:45:57 2011 -0400

    vgahw: Don't default to standard (port space) access routines
    
    In fact, don't default to anything; drivers must explicitly say which
    kind they want, and they are strongly encouraged to do MMIO if possible.
    This is an ABI change in that drivers that don't will crash, but drivers
    that are explicit will work with both old and new servers.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c
index 911bf07..9e934f6 100644
--- a/hw/xfree86/vgahw/vgaHW.c
+++ b/hw/xfree86/vgahw/vgaHW.c
@@ -1706,9 +1706,6 @@ vgaHWGetHWRec(ScrnInfoPtr scrp)
     hwp->MapSize = 0;
     hwp->pScrn = scrp;
 
-    /* Initialise the function pointers with the standard VGA versions */
-    vgaHWSetStdFuncs(hwp);
-
     hwp->dev = xf86GetPciInfoForEntity(scrp->entityList[0]);
 
     return TRUE;
commit 208e1fadaf4d8a21107c89c120bd64ff8911a308
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 22 13:44:53 2011 -0400

    vgahw: Remove IO domain setup
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c
index 2ecea1c..911bf07 100644
--- a/hw/xfree86/vgahw/vgaHW.c
+++ b/hw/xfree86/vgahw/vgaHW.c
@@ -1709,7 +1709,6 @@ vgaHWGetHWRec(ScrnInfoPtr scrp)
     /* Initialise the function pointers with the standard VGA versions */
     vgaHWSetStdFuncs(hwp);
 
-    hwp->PIOOffset = scrp->domainIOBase;
     hwp->dev = xf86GetPciInfoForEntity(scrp->entityList[0]);
 
     return TRUE;
commit e4d054419682b07cd68f34d7abeb12672097eb30
Author: Adam Jackson <ajax at redhat.com>
Date:   Sat Sep 18 08:24:19 2010 -0400

    int10: Port to pciaccess' legacy IO API
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index 9940854..beb90b5 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -297,7 +297,7 @@ MapVRam(xf86Int10InfoPtr pInt)
     INTPriv(pInt)->vRam = xf86MapDomainMemory(pInt->scrnIndex, VIDMEM_MMIO,
 					      pInt->dev, V_RAM, size);
 
-    pInt->ioBase = xf86Screens[pInt->scrnIndex]->domainIOBase;
+    pInt->io = pci_legacy_open_io(pInt->dev, 0, 64 * 1024);
 }
 
 static void
@@ -308,6 +308,9 @@ UnmapVRam(xf86Int10InfoPtr pInt)
     int size = ((VRAM_SIZE + pagesize - 1)/pagesize) * pagesize;
 
     xf86UnMapVidMem(screen, INTPriv(pInt)->vRam, size);
+
+    pci_device_close_io(pInt->dev, pInt->io);
+    pInt->io = NULL;
 }
 
 Bool
diff --git a/hw/xfree86/int10/helper_exec.c b/hw/xfree86/int10/helper_exec.c
index 44d8a7f..8b52e88 100644
--- a/hw/xfree86/int10/helper_exec.c
+++ b/hw/xfree86/int10/helper_exec.c
@@ -331,7 +331,7 @@ x_inb(CARD16 port)
 	}
 #endif /* __NOT_YET__ */
     } else if (!pciCfg1inb(port, &val)) {
-	val = inb(Int10Current->ioBase + port);
+	val = pci_io_read8(Int10Current->io, port);
 	if (PRINT_PORT && DEBUG_IO_TRACE())
 	    ErrorF(" inb(%#x) = %2.2x\n", port, val);
     }
@@ -353,7 +353,7 @@ x_inw(CARD16 port)
 	X_GETTIMEOFDAY(&tv);
 	val = (CARD16)(tv.tv_usec / 3);
     } else if (!pciCfg1inw(port, &val)) {
-	val = inw(Int10Current->ioBase + port);
+	val = pci_io_read16(Int10Current->io, port);
 	if (PRINT_PORT && DEBUG_IO_TRACE())
 	    ErrorF(" inw(%#x) = %4.4x\n", port, val);
     }
@@ -387,7 +387,7 @@ x_outb(CARD16 port, CARD8 val)
     } else if (!pciCfg1outb(port, val)) {
 	if (PRINT_PORT && DEBUG_IO_TRACE())
 	    ErrorF(" outb(%#x, %2.2x)\n", port, val);
-	outb(Int10Current->ioBase + port, val);
+	pci_io_write8(Int10Current->io, port, val);
     }
 }
 
@@ -398,7 +398,7 @@ x_outw(CARD16 port, CARD16 val)
     if (!pciCfg1outw(port, val)) {
 	if (PRINT_PORT && DEBUG_IO_TRACE())
 	    ErrorF(" outw(%#x, %4.4x)\n", port, val);
-	outw(Int10Current->ioBase + port, val);
+	pci_io_write16(Int10Current->io, port, val);
     }
 }
 
@@ -408,7 +408,7 @@ x_inl(CARD16 port)
     CARD32 val;
 
     if (!pciCfg1in(port, &val)) {
-	val = inl(Int10Current->ioBase + port);
+	val = pci_io_read32(Int10Current->io, port);
 	if (PRINT_PORT && DEBUG_IO_TRACE())
 	    ErrorF(" inl(%#x) = %8.8" PRIx32 "\n", port, val);
     }
@@ -421,7 +421,7 @@ x_outl(CARD16 port, CARD32 val)
     if (!pciCfg1out(port, val)) {
 	if (PRINT_PORT && DEBUG_IO_TRACE())
 	    ErrorF(" outl(%#x, %8.8" PRIx32 ")\n", port, val);
-	outl(Int10Current->ioBase + port, val);
+	pci_io_write32(Int10Current->io, port, val);
     }
 }
 
@@ -650,29 +650,29 @@ bios_checksum(const CARD8 *start, int size)
 void
 LockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga)
 {
-    vga->save_msr    = inb(pInt->ioBase + 0x03CC);
-    vga->save_vse    = inb(pInt->ioBase + 0x03C3);
+    vga->save_msr    = pci_io_read8(pInt->io, 0x03CC);
+    vga->save_vse    = pci_io_read8(pInt->io, 0x03C3);
 #ifndef __ia64__
-    vga->save_46e8   = inb(pInt->ioBase + 0x46E8);
+    vga->save_46e8   = pci_io_read8(pInt->io, 0x46E8);
 #endif
-    vga->save_pos102 = inb(pInt->ioBase + 0x0102);
-    outb(pInt->ioBase + 0x03C2, ~(CARD8)0x03 & vga->save_msr);
-    outb(pInt->ioBase + 0x03C3, ~(CARD8)0x01 & vga->save_vse);
+    vga->save_pos102 = pci_io_read8(pInt->io, 0x0102);
+    pci_io_write8(pInt->io, 0x03C2, ~(CARD8)0x03 & vga->save_msr);
+    pci_io_write8(pInt->io, 0x03C3, ~(CARD8)0x01 & vga->save_vse);
 #ifndef __ia64__
-    outb(pInt->ioBase + 0x46E8, ~(CARD8)0x08 & vga->save_46e8);
+    pci_io_write8(pInt->io, 0x46E8, ~(CARD8)0x08 & vga->save_46e8);
 #endif
-    outb(pInt->ioBase + 0x0102, ~(CARD8)0x01 & vga->save_pos102);
+    pci_io_write8(pInt->io, 0x0102, ~(CARD8)0x01 & vga->save_pos102);
 }
 
 void
 UnlockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga)
 {
-    outb(pInt->ioBase + 0x0102, vga->save_pos102);
+    pci_io_write8(pInt->io, 0x0102, vga->save_pos102);
 #ifndef __ia64__
-    outb(pInt->ioBase + 0x46E8, vga->save_46e8);
+    pci_io_write8(pInt->io, 0x46E8, vga->save_46e8);
 #endif
-    outb(pInt->ioBase + 0x03C3, vga->save_vse);
-    outb(pInt->ioBase + 0x03C2, vga->save_msr);
+    pci_io_write8(pInt->io, 0x03C3, vga->save_vse);
+    pci_io_write8(pInt->io, 0x03C2, vga->save_msr);
 }
 
 #if defined (_PC)
diff --git a/hw/xfree86/int10/xf86int10.c b/hw/xfree86/int10/xf86int10.c
index 51eb91f..dd00e54 100644
--- a/hw/xfree86/int10/xf86int10.c
+++ b/hw/xfree86/int10/xf86int10.c
@@ -84,7 +84,7 @@ int42_handler(xf86Int10InfoPtr pInt)
 	/* Leave:  Nothing                                    */
 	/* Implemented (except for clearing the screen)       */
 	{                                         /* Localise */
-	    IOADDRESS ioport;
+	    unsigned int ioport;
 	    int i;
 	    CARD16 int1d, regvals, tmp;
 	    CARD8 mode, cgamode, cgacolour;
@@ -172,18 +172,15 @@ int42_handler(xf86Int10InfoPtr pInt)
 	    /* Rows */
 	    MEM_WB(pInt, 0x0484, (25 - 1));
 
-	    /* Remap I/O port number into its domain */
-	    ioport += pInt->ioBase;
-
-	    /* Programme the mode */
-	    outb(ioport + 4, cgamode & 0x37);   /* Turn off screen */
+	    /* Program the mode */
+	    pci_io_write8(pInt->io, ioport + 4, cgamode & 0x37);   /* Turn off screen */
 	    for (i = 0; i < 0x10; i++) {
 		tmp = MEM_RB(pInt, regvals + i);
-		outb(ioport, i);
-		outb(ioport + 1, tmp);
+		pci_io_write8(pInt->io, ioport, i);
+		pci_io_write8(pInt->io, ioport + 1, tmp);
 	    }
-	    outb(ioport + 5, cgacolour);        /* Select colour mode */
-	    outb(ioport + 4, cgamode);          /* Turn on screen */
+	    pci_io_write8(pInt->io, ioport + 5, cgacolour);        /* Select colour mode */
+	    pci_io_write8(pInt->io, ioport + 4, cgamode);          /* Turn on screen */
 	}
 	break;
 
@@ -194,15 +191,15 @@ int42_handler(xf86Int10InfoPtr pInt)
 	/* Leave:  Nothing                                    */
 	/* Implemented                                        */
 	{                                         /* Localise */
-	    IOADDRESS ioport = MEM_RW(pInt, 0x0463) + pInt->ioBase;
+	    unsigned int ioport = MEM_RW(pInt, 0x0463);
 
 	    MEM_WB(pInt, 0x0460, X86_CL);
 	    MEM_WB(pInt, 0x0461, X86_CH);
 
-	    outb(ioport, 0x0A);
-	    outb(ioport + 1, X86_CH);
-	    outb(ioport, 0x0B);
-	    outb(ioport + 1, X86_CL);
+	    pci_io_write8(pInt->io, ioport, 0x0A);
+	    pci_io_write8(pInt->io, ioport + 1, X86_CH);
+	    pci_io_write8(pInt->io, ioport, 0x0B);
+	    pci_io_write8(pInt->io, ioport + 1, X86_CL);
 	}
 	break;
 
@@ -214,7 +211,7 @@ int42_handler(xf86Int10InfoPtr pInt)
 	/* Leave:  Nothing                                    */
 	/* Implemented                                        */
 	{                                         /* Localise */
-	    IOADDRESS ioport;
+	    unsigned int ioport;
 	    CARD16 offset;
 
 	    MEM_WB(pInt, (X86_BH << 1) + 0x0450, X86_DL);
@@ -226,11 +223,11 @@ int42_handler(xf86Int10InfoPtr pInt)
 	    offset = (X86_DH * MEM_RW(pInt, 0x044A)) + X86_DL;
 	    offset += MEM_RW(pInt, 0x044E) << 1;
 
-	    ioport = MEM_RW(pInt, 0x0463) + pInt->ioBase;
-	    outb(ioport, 0x0E);
-	    outb(ioport + 1, offset >> 8);
-	    outb(ioport, 0x0F);
-	    outb(ioport + 1, offset & 0xFF);
+	    ioport = MEM_RW(pInt, 0x0463);
+	    pci_io_write8(pInt->io, ioport, 0x0E);
+	    pci_io_write8(pInt->io, ioport + 1, offset >> 8);
+	    pci_io_write8(pInt->io, ioport, 0x0F);
+	    pci_io_write8(pInt->io, ioport + 1, offset & 0xFF);
 	}
 	break;
 
@@ -276,7 +273,7 @@ int42_handler(xf86Int10InfoPtr pInt)
 	/* Leave:  Nothing                                    */
 	/* Implemented                                        */
 	{                                         /* Localise */
-	    IOADDRESS ioport = MEM_RW(pInt, 0x0463) + pInt->ioBase;
+	    unsigned int ioport = MEM_RW(pInt, 0x0463);
 	    CARD16 start;
 	    CARD8 x, y;
 
@@ -287,10 +284,10 @@ int42_handler(xf86Int10InfoPtr pInt)
 	    start <<= 1;
 
 	    /* Update start address */
-	    outb(ioport, 0x0C);
-	    outb(ioport + 1, start >> 8);
-	    outb(ioport, 0x0D);
-	    outb(ioport + 1, start & 0xFF);
+	    pci_io_write8(pInt->io, ioport, 0x0C);
+	    pci_io_write8(pInt->io, ioport + 1, start >> 8);
+	    pci_io_write8(pInt->io, ioport, 0x0D);
+	    pci_io_write8(pInt->io, ioport + 1, start & 0xFF);
 
 	    /* Switch cursor position */
 	    y = MEM_RB(pInt, (X86_AL << 1) + 0x0450);
@@ -298,10 +295,10 @@ int42_handler(xf86Int10InfoPtr pInt)
 	    start += (y * MEM_RW(pInt, 0x044A)) + x;
 
 	    /* Update cursor position */
-	    outb(ioport, 0x0E);
-	    outb(ioport + 1, start >> 8);
-	    outb(ioport, 0x0F);
-	    outb(ioport + 1, start & 0xFF);
+	    pci_io_write8(pInt->io, ioport, 0x0E);
+	    pci_io_write8(pInt->io, ioport + 1, start >> 8);
+	    pci_io_write8(pInt->io, ioport, 0x0F);
+	    pci_io_write8(pInt->io, ioport + 1, start & 0xFF);
 	}
 	break;
 
@@ -426,7 +423,7 @@ int42_handler(xf86Int10InfoPtr pInt)
 	/* Leave:  Nothing                                    */
 	/* Implemented                                        */
 	{                                         /* Localise */
-	    IOADDRESS ioport = MEM_RW(pInt, 0x0463) + 5 + pInt->ioBase;
+	    unsigned int ioport = MEM_RW(pInt, 0x0463) + 5;
 	    CARD8 cgacolour = MEM_RB(pInt, 0x0466);
 
 	    if (X86_BH) {
@@ -438,7 +435,7 @@ int42_handler(xf86Int10InfoPtr pInt)
 	    }
 
 	    MEM_WB(pInt, 0x0466, cgacolour);
-	    outb(ioport, cgacolour);
+	    pci_io_write8(pInt->io, ioport, cgacolour);
 	}
 	break;
 
diff --git a/hw/xfree86/int10/xf86int10.h b/hw/xfree86/int10/xf86int10.h
index ba9ee52..5bf326e 100644
--- a/hw/xfree86/int10/xf86int10.h
+++ b/hw/xfree86/int10/xf86int10.h
@@ -41,7 +41,7 @@ typedef struct {
     int flags;
     int stackseg;
     struct pci_device *dev;
-    IOADDRESS ioBase;
+    struct pci_io_handle *io;
 } xf86Int10InfoRec, *xf86Int10InfoPtr;
 
 typedef struct _int10Mem {
commit 3c1ea74e77b0caf513bfc9624a5ca2607d5d0b10
Author: Adam Jackson <ajax at redhat.com>
Date:   Sat Sep 18 08:05:11 2010 -0400

    xfree86: Move xf86GetClocks to vgahw
    
    This is really a vga-specific hack anyway.  The only modern driver that
    uses it is trident, but it's already loaded vgahw by the time it would
    call xf86GetClocks.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 1b6c998..da9287b 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -239,12 +239,6 @@ extern _X_EXPORT void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from);
 extern _X_EXPORT void xf86PrintChipsets(const char *drvname, const char *drvmsg,
 		       SymTabPtr chips);
 extern _X_EXPORT int xf86MatchDevice(const char *drivername, GDevPtr **driversectlist);
-extern _X_EXPORT void xf86GetClocks(ScrnInfoPtr pScrn, int num,
-		   Bool (*ClockFunc)(ScrnInfoPtr, int),
-		   void (*ProtectRegs)(ScrnInfoPtr, Bool),
-		   void (*BlankScreen)(ScrnInfoPtr, Bool),
-		   IOADDRESS vertsyncreg, int maskval,
-		   int knownclkindex, int knownclkvalue);
 extern _X_EXPORT const char *xf86GetVisualName(int visual);
 extern _X_EXPORT int xf86GetVerbosity(void);
 extern _X_EXPORT Pix24Flags xf86GetPix24(void);
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index a8aa316..cf57752 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1353,96 +1353,6 @@ xf86MatchDevice(const char *drivername, GDevPtr **sectlist)
     return i;
 }
 
-/*
- * xf86GetClocks -- get the dot-clocks via a BIG BAD hack ...
- */
-void
-xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc)(ScrnInfoPtr, int),
-	      void (*ProtectRegs)(ScrnInfoPtr, Bool),
-	      void (*BlankScreen)(ScrnInfoPtr, Bool), IOADDRESS vertsyncreg,
-	      int maskval, int knownclkindex, int knownclkvalue)
-{
-    register int status = vertsyncreg;
-    unsigned long i, cnt, rcnt, sync;
-
-    /* First save registers that get written on */
-    (*ClockFunc)(pScrn, CLK_REG_SAVE);
-
-    if (num > MAXCLOCKS)
-	num = MAXCLOCKS;
-
-    for (i = 0; i < num; i++)
-    {
-	if (ProtectRegs)
-	    (*ProtectRegs)(pScrn, TRUE);
-	if (!(*ClockFunc)(pScrn, i))
-	{
-	    pScrn->clock[i] = -1;
-	    continue;
-	}
-	if (ProtectRegs)
-	    (*ProtectRegs)(pScrn, FALSE);
-	if (BlankScreen)
-	    (*BlankScreen)(pScrn, FALSE);
-
-    	usleep(50000);     /* let VCO stabilise */
-
-    	cnt  = 0;
-    	sync = 200000;
-
-	while ((inb(status) & maskval) == 0x00)
-	    if (sync-- == 0) goto finish;
-	/* Something appears to be happening, so reset sync count */
-	sync = 200000;
-	while ((inb(status) & maskval) == maskval)
-	    if (sync-- == 0) goto finish;
-	/* Something appears to be happening, so reset sync count */
-	sync = 200000;
-	while ((inb(status) & maskval) == 0x00)
-	    if (sync-- == 0) goto finish;
-
-	for (rcnt = 0; rcnt < 5; rcnt++)
-	{
-	    while (!(inb(status) & maskval))
-		cnt++;
-	    while ((inb(status) & maskval))
-		cnt++;
-	}
-
-finish:
-	pScrn->clock[i] = cnt ? cnt : -1;
-	if (BlankScreen)
-            (*BlankScreen)(pScrn, TRUE);
-    }
-
-    for (i = 0; i < num; i++)
-    {
-	if (i != knownclkindex)
-	{
-	    if (pScrn->clock[i] == -1)
-	    {
-		pScrn->clock[i] = 0;
-	    }
-	    else
-	    {
-		pScrn->clock[i] = (int)(0.5 +
-                    (((float)knownclkvalue) * pScrn->clock[knownclkindex]) /
-	            (pScrn->clock[i]));
-		/* Round to nearest 10KHz */
-		pScrn->clock[i] += 5;
-		pScrn->clock[i] /= 10;
-		pScrn->clock[i] *= 10;
-	    }
-	}
-    }
-
-    pScrn->clock[knownclkindex] = knownclkvalue;
-    pScrn->numClocks = num;
-
-    /* Restore registers that were written on */
-    (*ClockFunc)(pScrn, CLK_REG_RESTORE);
-}
-
 const char *
 xf86GetVisualName(int visual)
 {
diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c
index ee045d1..2ecea1c 100644
--- a/hw/xfree86/vgahw/vgaHW.c
+++ b/hw/xfree86/vgahw/vgaHW.c
@@ -1992,3 +1992,93 @@ SaveScreenProcPtr vgaHWSaveScreenWeak(void)
 {
     return vgaHWSaveScreen;
 }
+
+/*
+ * xf86GetClocks -- get the dot-clocks via a BIG BAD hack ...
+ */
+void
+xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc)(ScrnInfoPtr, int),
+	      void (*ProtectRegs)(ScrnInfoPtr, Bool),
+	      void (*BlankScreen)(ScrnInfoPtr, Bool), IOADDRESS vertsyncreg,
+	      int maskval, int knownclkindex, int knownclkvalue)
+{
+    register int status = vertsyncreg;
+    unsigned long i, cnt, rcnt, sync;
+
+    /* First save registers that get written on */
+    (*ClockFunc)(pScrn, CLK_REG_SAVE);
+
+    if (num > MAXCLOCKS)
+	num = MAXCLOCKS;
+
+    for (i = 0; i < num; i++)
+    {
+	if (ProtectRegs)
+	    (*ProtectRegs)(pScrn, TRUE);
+	if (!(*ClockFunc)(pScrn, i))
+	{
+	    pScrn->clock[i] = -1;
+	    continue;
+	}
+	if (ProtectRegs)
+	    (*ProtectRegs)(pScrn, FALSE);
+	if (BlankScreen)
+	    (*BlankScreen)(pScrn, FALSE);
+
+	usleep(50000);     /* let VCO stabilise */
+
+	cnt  = 0;
+	sync = 200000;
+
+	while ((inb(status) & maskval) == 0x00)
+	    if (sync-- == 0) goto finish;
+	/* Something appears to be happening, so reset sync count */
+	sync = 200000;
+	while ((inb(status) & maskval) == maskval)
+	    if (sync-- == 0) goto finish;
+	/* Something appears to be happening, so reset sync count */
+	sync = 200000;
+	while ((inb(status) & maskval) == 0x00)
+	    if (sync-- == 0) goto finish;
+
+	for (rcnt = 0; rcnt < 5; rcnt++)
+	{
+	    while (!(inb(status) & maskval))
+		cnt++;
+	    while ((inb(status) & maskval))
+		cnt++;
+	}
+
+finish:
+	pScrn->clock[i] = cnt ? cnt : -1;
+	if (BlankScreen)
+            (*BlankScreen)(pScrn, TRUE);
+    }
+
+    for (i = 0; i < num; i++)
+    {
+	if (i != knownclkindex)
+	{
+	    if (pScrn->clock[i] == -1)
+	    {
+		pScrn->clock[i] = 0;
+	    }
+	    else
+	    {
+		pScrn->clock[i] = (int)(0.5 +
+                    (((float)knownclkvalue) * pScrn->clock[knownclkindex]) /
+	            (pScrn->clock[i]));
+		/* Round to nearest 10KHz */
+		pScrn->clock[i] += 5;
+		pScrn->clock[i] /= 10;
+		pScrn->clock[i] *= 10;
+	    }
+	}
+    }
+
+    pScrn->clock[knownclkindex] = knownclkvalue;
+    pScrn->numClocks = num;
+
+    /* Restore registers that were written on */
+    (*ClockFunc)(pScrn, CLK_REG_RESTORE);
+}
diff --git a/hw/xfree86/vgahw/vgaHW.h b/hw/xfree86/vgahw/vgaHW.h
index b31c007..12cfac0 100644
--- a/hw/xfree86/vgahw/vgaHW.h
+++ b/hw/xfree86/vgahw/vgaHW.h
@@ -231,5 +231,11 @@ extern _X_EXPORT Bool vgaHWAllocDefaultRegs(vgaRegPtr regp);
 
 extern _X_EXPORT DDC1SetSpeedProc vgaHWddc1SetSpeedWeak(void);
 extern _X_EXPORT SaveScreenProcPtr vgaHWSaveScreenWeak(void);
+extern _X_EXPORT void xf86GetClocks(ScrnInfoPtr pScrn, int num,
+		   Bool (*ClockFunc)(ScrnInfoPtr, int),
+		   void (*ProtectRegs)(ScrnInfoPtr, Bool),
+		   void (*BlankScreen)(ScrnInfoPtr, Bool),
+		   IOADDRESS vertsyncreg, int maskval,
+		   int knownclkindex, int knownclkvalue);
 
 #endif /* _VGAHW_H */
commit 239e6df38dee80e531b18bcfabc1d94ac9d9dd63
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Tue Sep 20 20:39:06 2011 -0700

    XQuartz: Use set_front_process rather than X11ApplicationSetFrontProcess since we're already in the AppKit thread
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 7fd7dab..12ff53c 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -356,7 +356,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
                          */
                         _appFlags._active = YES;
 
-                        X11ApplicationSetFrontProcess();
+                        [self set_front_process:nil];
 
                         /* Get the Spaces preference for SwitchOnActivate */
                         (void)CFPreferencesAppSynchronize(CFSTR("com.apple.dock"));
commit 11d310bb9e27208ea1b7b2b68f939a15aa557ca7
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Thu Sep 22 18:55:19 2011 -0700

    Address regressions from e8ff555b95ba and d206d52f657c to work with other compilers
    
    1) The error attribute appeared in gcc-4.3
    2) The return type of __builtin_constant_p is int
    3) Sun Studio 12.0 and later builtin support for __builtin_constant_p
    
    Found by Tinderbox.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/include/misc.h b/include/misc.h
index 1fea73e..0867746 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -261,14 +261,16 @@ version_compare(uint16_t a_major, uint16_t a_minor,
 #define SwapRestL(stuff) \
     SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
 
-#ifdef __GNUC__
+#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
 void __attribute__((error("wrong sized variable passed to swap"))) wrong_size(void);
 #else
 static inline void wrong_size(void)
 {
 }
+#endif
 
-static inline void __builtin_constant_p(int x)
+#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C < 0x590)))
+static inline int __builtin_constant_p(int x)
 {
 	return 0;
 }
commit afb1fe695d197187a301c19863a128a65389b15c
Merge: 7fb4bef... c7163fd...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Sep 26 20:24:15 2011 -0700

    Merge remote-tracking branch 'whot/next'

commit c7163fdd302f706a3d67f0fdf93eeb3396bb3332
Author: vdb at picaros.org <vdb at picaros.org>
Date:   Wed Aug 31 07:23:01 2011 +0200

    xfree86: .BI style: monitor section in xorg.conf man page
    
    The xorg.conf manual uses the following convention in most of its
    sections:
    
    bold = text to be copied literally to the config file,
    italic = a symbolic name to be substituted by a true value.
    
    Some configuration keywords seem to have been changed into generic
    options.  Prepending Option to the manual entry swapped the
    bold-italic logic.  This patch restores the convention in the monitor
    section and consists of
    
    -.BI "Option " "\*qPreferredMode\*q  " \*qstring\*q
    +.BI "Option \*qPreferredMode\*q \*q" name \*q
    
    modifications.
    
    Plus a few minor changes (Modes → Mode) and a typo fix.
    
    Signed-off-by: Servaas Vandenberghe
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index df877b9..8615343 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -1449,7 +1449,7 @@ driver plus the identifier of a monitor section, one associates a monitor
 section with an output by adding an option to the Device section in the
 following format:
 
-.B Option \*qMonitor-outputname\*q \*qmonitorsection\*q
+.BI "Option \*qMonitor-" outputname "\*q \*q" monitorsection \*q
 
 (for example,
 .B Option \*qMonitor-VGA\*q \*qVGA monitor\*q
@@ -1465,7 +1465,7 @@ modes available.
 When modes are specified explicitly in the
 .B Monitor
 section (with the
-.BR Modes ,
+.BR Mode ,
 .BR ModeLine ,
 or
 .B UseModes
@@ -1614,7 +1614,7 @@ mentioned above doubles this value.
 This entry is a more compact version of the
 .B Mode
 entry, and it also can be used to specify video modes for the monitor.
-is a single line format for specifying video modes.
+This is a single line format for specifying video modes.
 In most cases this isn't necessary because the built\-in set of VESA
 standard modes will be sufficient.
 .PP
@@ -1669,61 +1669,61 @@ The
 and
 .B VScan
 options mentioned above in the
-.B Modes
+.B Mode
 entry description can also be used here.
 .RE
 .TP 7
-.BI "Option " "\*qDPMS\*q  " \*qbool\*q
+.BI "Option \*qDPMS\*q \*q" bool \*q
 This option controls whether the server should enable the DPMS extension
 for power management for this screen.  The default is to enable the
 extension.
 .TP 7
-.BI "Option " "\*qSyncOnGreen\*q  " \*qbool\*q
+.BI "Option \*qSyncOnGreen\*q \*q" bool \*q
 This option controls whether the video card should drive the sync signal
 on the green color pin.  Not all cards support this option, and most
 monitors do not require it.  The default is off.
 .TP 7
-.BI "Option " "\*qPrimary\*q  " \*qbool\*q
+.BI "Option \*qPrimary\*q \*q" bool \*q
 This optional entry specifies that the monitor should be treated as the primary
 monitor. (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qPreferredMode\*q  " \*qstring\*q
+.BI "Option \*qPreferredMode\*q \*q" name \*q
 This optional entry specifies a mode to be marked as the preferred initial mode
 of the monitor.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qPosition\*q  " "\*qx y\*q"
+.BI "Option \*qPosition\*q \*q" x " " y \*q
 This optional entry specifies the position of the monitor within the X
 screen.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qLeftOf\*q  " \*qoutput\*q
+.BI "Option \*qLeftOf\*q \*q" output \*q
 This optional entry specifies that the monitor should be positioned to the
 left of the output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qRightOf\*q  " \*qoutput\*q
+.BI "Option \*qRightOf\*q \*q" output \*q
 This optional entry specifies that the monitor should be positioned to the
 right of the output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qAbove\*q  " \*qoutput\*q
+.BI "Option \*qAbove\*q \*q" output \*q
 This optional entry specifies that the monitor should be positioned above the
 output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qBelow\*q  " \*qoutput\*q
+.BI "Option \*qBelow\*q \*q" output \*q
 This optional entry specifies that the monitor should be positioned below the
 output (not monitor) of the given name.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qEnable\*q  " \*qbool\*q
+.BI "Option \*qEnable\*q \*q" bool \*q
 This optional entry specifies whether the monitor should be turned on
 at startup.  By default, the server will attempt to enable all connected
 monitors.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qDefaultModes\*q  " \*qbool\*q
+.BI "Option \*qDefaultModes\*q \*q" bool \*q
 This optional entry specifies whether the server should add supported default
 modes to the list of modes offered on this monitor. By default, the server
 will add default modes; you should only disable this if you can guarantee
@@ -1731,21 +1731,21 @@ that EDID will be available at all times, or if you have added custom modelines
 which the server can use.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qMinClock\*q  " \*qfrequency\*q
+.BI "Option \*qMinClock\*q \*q" frequency \*q
 This optional entry specifies the minimum dot clock, in kHz, that is supported
 by the monitor.
 .TP 7
-.BI "Option " "\*qMaxClock\*q  " \*qfrequency\*q
+.BI "Option \*qMaxClock\*q \*q" frequency \*q
 This optional entry specifies the maximum dot clock, in kHz, that is supported
 by the monitor.
 .TP 7
-.BI "Option " "\*qIgnore\*q  " \*qbool\*q
+.BI "Option \*qIgnore\*q \*q" bool \*q
 This optional entry specifies that the monitor should be ignored entirely,
 and not reported through RandR.  This is useful if the hardware reports the
 presence of outputs that don't exist.
 (RandR 1.2-supporting drivers only)
 .TP 7
-.BI "Option " "\*qRotate\*q  " \*qrotation\*q
+.BI "Option \*qRotate\*q \*q" rotation \*q
 This optional entry specifies the initial rotation of the given monitor.
 Valid values for rotation are \*qnormal\*q, \*qleft\*q, \*qright\*q, and
 \*qinverted\*q.
commit 4b4caecb7d2c8e0b7e4fedc95fba2a728bbc25e6
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Sep 6 09:33:43 2011 +1000

    xfree86: expose Option "TransformationMatrix"
    
    Recent changes to the server change the default absolute input device
    behaviour on zaphods to span the whole desktop too. Since these setups
    usually use an xorg.conf, allow the transformation matrix to be specified in
    the config as well.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 526b92d..9fbcba9 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -266,6 +266,34 @@ ApplyAccelerationSettings(DeviceIntPtr dev){
     }
 }
 
+static void
+ApplyTransformationMatrix(DeviceIntPtr dev)
+{
+    InputInfoPtr pInfo = (InputInfoPtr)dev->public.devicePrivate;
+    char *str;
+    int rc;
+    float matrix[9] = {0};
+
+    if (!dev->valuator)
+        return;
+
+    str = xf86SetStrOption(pInfo->options, "TransformationMatrix", NULL);
+    if (!str)
+        return;
+
+    rc = sscanf(str, "%f %f %f %f %f %f %f %f %f", &matrix[0], &matrix[1], &matrix[2],
+                &matrix[3], &matrix[4], &matrix[5], &matrix[6], &matrix[7], &matrix[8]);
+    if (rc != 9) {
+        xf86Msg(X_ERROR, "%s: invalid format for transformation matrix. Ignoring configuration.\n",
+                pInfo->name);
+        return;
+    }
+
+    XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_TRANSFORM),
+                           XIGetKnownProperty(XATOM_FLOAT), 32,
+                           PropModeReplace, 9, matrix, FALSE);
+}
+
 /***********************************************************************
  *
  * xf86ProcessCommonOptions --
@@ -755,6 +783,7 @@ xf86DeleteInput(InputInfoPtr pInp, int flags)
 static int
 xf86InputDevicePostInit(DeviceIntPtr dev) {
     ApplyAccelerationSettings(dev);
+    ApplyTransformationMatrix(dev);
     return Success;
 }
 
diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index 6774dbc..df877b9 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -948,6 +948,17 @@ is equivalent to
 
 This option controls the startup behavior only, a device
 may be reattached or set floating at runtime.
+.TP 7
+.BI "Option \*qTransformationMatrix\*q \*q" a " " b " " c " " d " " e " " f " " g " " h " " i \*q
+Specifies the 3x3 transformation matrix for absolute input devices. The
+input device will be bound to the area given in the matrix.  In most
+configurations, "a" and "e" specify the width and height of the area the
+device is bound to, and "c" and "f" specify the x and y offset of the area.
+The value range is 0 to 1, where 1 represents the width or height of all
+root windows together, 0.5 represents half the area, etc. The values
+represent a 3x3 matrix, with the first, second and third group of three
+values representing the first, second and third row of the matrix,
+respectively.  The identity matrix is "1 0 0 0 1 0 0 0 1".
 .SS POINTER ACCELERATION
 For pointing devices, the following options control how the pointer
 is accelerated or decelerated with respect to physical device motion. Most of
commit cf51424a34fb2b567a867338ab44f83b5c43251c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Sep 6 09:39:01 2011 +1000

    xfree86: use subheader for Pointer Acceleration parts in xorg.conf(5)
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index f406f82..6774dbc 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -948,7 +948,7 @@ is equivalent to
 
 This option controls the startup behavior only, a device
 may be reattached or set floating at runtime.
-.PP
+.SS POINTER ACCELERATION
 For pointing devices, the following options control how the pointer
 is accelerated or decelerated with respect to physical device motion. Most of
 these can be adjusted at runtime, see the xinput(1) man page for details. Only
commit 9125952b407090b040bffb3d752288293137cf77
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Sep 5 15:43:14 2011 +1000

    xfree86: fix comment typo
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 114cdd9..526b92d 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -746,7 +746,7 @@ xf86DeleteInput(InputInfoPtr pInp, int flags)
 }
 
 /*
- * Apply backend-specific initialization. Invoked after ActiveteDevice(),
+ * Apply backend-specific initialization. Invoked after ActivateDevice(),
  * i.e. after the driver successfully completed DEVICE_INIT and the device
  * is advertised.
  * @param dev the device
commit 2d2dce558d24eeea0eb011ec9ebaa6c5c2273c39
Author: Sam Spilsbury <sam.spilsbury at canonical.com>
Date:   Wed Sep 14 09:58:34 2011 +0800

    Remove the SendEvent bit (0x80) before doing range checks on event type.
    
    Some extension libraries may set this bit before converting the event to
    wire protocol and as such range checking the event will cause an invalid
    BadValue error to result. As the documentation suggests the the bit
    should be "forced on", remove it before doing range checks and continue
    to force it on in the server.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/events.c b/dix/events.c
index 7fe0fba..fbe4fc9 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5251,6 +5251,8 @@ CloseDownEvents(void)
     InputEventList = NULL;
 }
 
+#define SEND_EVENT_BIT 0x80
+
 /**
  * Server-side protocol handling for SendEvent request.
  *
@@ -5268,6 +5270,16 @@ ProcSendEvent(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xSendEventReq);
 
+    /* libXext and other extension libraries may set the bit indicating
+     * that this event came from a SendEvent request so remove it
+     * since otherwise the event type may fail the range checks
+     * and cause an invalid BadValue error to be returned.
+     *
+     * This is safe to do since we later add the SendEvent bit (0x80)
+     * back in once we send the event to the client */
+
+    stuff->event.u.u.type &= ~(SEND_EVENT_BIT);
+
     /* The client's event type must be a core event type or one defined by an
 	extension. */
 
@@ -5325,7 +5337,7 @@ ProcSendEvent(ClientPtr client)
 	client->errorValue = stuff->propagate;
 	return BadValue;
     }
-    stuff->event.u.u.type |= 0x80;
+    stuff->event.u.u.type |= SEND_EVENT_BIT;
     if (stuff->propagate)
     {
 	for (;pWin; pWin = pWin->parent)
commit f52d5cd374563544dafe29587411f345e31bbdf8
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed Aug 31 00:46:52 2011 +0200

    Xi: Fix passive XI2 ungrabs on XIAll[Master]Devices
    
    The corresponding DeviceIntPtr wasn't being gotten properly,
    resulting in BadDevice from dixLookupDevice().
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index ae43433..5cdd8ac 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -261,9 +261,16 @@ ProcXIPassiveUngrabDevice(ClientPtr client)
     REQUEST(xXIPassiveUngrabDeviceReq);
     REQUEST_AT_LEAST_SIZE(xXIPassiveUngrabDeviceReq);
 
-    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
-    if (rc != Success)
-	return rc;
+    if (stuff->deviceid == XIAllDevices)
+        dev = inputInfo.all_devices;
+    else if (stuff->deviceid == XIAllMasterDevices)
+        dev = inputInfo.all_master_devices;
+    else
+    {
+        rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
+        if (rc != Success)
+	    return rc;
+    }
 
     if (stuff->grab_type != XIGrabtypeButton &&
         stuff->grab_type != XIGrabtypeKeycode &&
commit 24823f1ab0f16e0815ef44340894537dc4babf6a
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Aug 3 16:01:28 2011 +1000

    xfree86: switch options from pointer to XF86OptionPtr
    
    In all cases, the pointer was simply type-cast anyway. Let's get some
    compile-time type safety going, how about that.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
    
    Squashed in:
    xfree86: Move definition of xf86OptionPtr into separate header file
    
    The pile of spaghettis that is the xfree86 include dependencies make it
    rather hard to have a single typedef somewhere that's not interfering with
    everything else or drags in a whole bunch of other includes.
    
    Move the xf86OptionRec and GenericListRec declarations into a separate
    header.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index c031d4b..23ddb5c 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -51,7 +51,7 @@ sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \
               xf86PciInfo.h xf86Priv.h xf86Privstr.h \
               xf86cmap.h xf86fbman.h xf86str.h xf86Xinput.h xisb.h \
               $(XVSDKINCS) $(XF86VMODE_SDK) xorgVersion.h \
-              xf86sbusBus.h xf86VGAarbiter.h
+              xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h
 
 DISTCLEANFILES = xf86Build.h
 CLEANFILES = $(BUILT_SOURCES)
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 54332e3..ae152b9 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -332,7 +332,7 @@ extern _X_EXPORT DisplayModePtr xf86ModesAdd(DisplayModePtr modes, DisplayModePt
 
 /* xf86Option.c */
 
-extern _X_EXPORT void xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts);
+extern _X_EXPORT void xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts);
 
 
 /* xf86RandR.c */
diff --git a/hw/xfree86/common/xf86Opt.h b/hw/xfree86/common/xf86Opt.h
index 9453f2a..88392dc 100644
--- a/hw/xfree86/common/xf86Opt.h
+++ b/hw/xfree86/common/xf86Opt.h
@@ -30,6 +30,7 @@
 
 #ifndef _XF86_OPT_H_
 #define _XF86_OPT_H_
+#include "xf86Optionstr.h"
 
 typedef struct {
     double freq;
@@ -69,34 +70,34 @@ typedef struct {
     Bool                found;
 } OptionInfoRec, *OptionInfoPtr;
 
-extern _X_EXPORT int xf86SetIntOption(pointer optlist, const char *name, int deflt);
-extern _X_EXPORT double xf86SetRealOption(pointer optlist, const char *name, double deflt);
-extern _X_EXPORT char *xf86SetStrOption(pointer optlist, const char *name, char *deflt);
-extern _X_EXPORT int xf86SetBoolOption(pointer list, const char *name, int deflt );
-extern _X_EXPORT double xf86SetPercentOption(pointer list, const char *name, double deflt );
-extern _X_EXPORT int xf86CheckIntOption(pointer optlist, const char *name, int deflt);
-extern _X_EXPORT double xf86CheckRealOption(pointer optlist, const char *name, double deflt);
-extern _X_EXPORT char *xf86CheckStrOption(pointer optlist, const char *name, char *deflt);
-extern _X_EXPORT int xf86CheckBoolOption(pointer list, const char *name, int deflt );
-extern _X_EXPORT double xf86CheckPercentOption(pointer list, const char *name, double deflt );
-extern _X_EXPORT pointer xf86AddNewOption(pointer head, const char *name, const char *val );
-extern _X_EXPORT pointer xf86NewOption(char *name, char *value );
-extern _X_EXPORT pointer xf86NextOption(pointer list );
-extern _X_EXPORT pointer xf86OptionListCreate(const char **options, int count, int used);
-extern _X_EXPORT pointer xf86OptionListMerge(pointer head, pointer tail);
-extern _X_EXPORT pointer xf86OptionListDuplicate(pointer list);
-extern _X_EXPORT void xf86OptionListFree(pointer opt);
-extern _X_EXPORT char *xf86OptionName(pointer opt);
-extern _X_EXPORT char *xf86OptionValue(pointer opt);
-extern _X_EXPORT void xf86OptionListReport(pointer parm);
-extern _X_EXPORT pointer xf86FindOption(pointer options, const char *name);
-extern _X_EXPORT char *xf86FindOptionValue(pointer options, const char *name);
-extern _X_EXPORT void xf86MarkOptionUsed(pointer option);
-extern _X_EXPORT void xf86MarkOptionUsedByName(pointer options, const char *name);
-extern _X_EXPORT Bool xf86CheckIfOptionUsed(pointer option);
-extern _X_EXPORT Bool xf86CheckIfOptionUsedByName(pointer options, const char *name);
-extern _X_EXPORT void xf86ShowUnusedOptions(int scrnIndex, pointer options);
-extern _X_EXPORT void xf86ProcessOptions(int scrnIndex, pointer options, OptionInfoPtr optinfo);
+extern _X_EXPORT int xf86SetIntOption(XF86OptionPtr optlist, const char *name, int deflt);
+extern _X_EXPORT double xf86SetRealOption(XF86OptionPtr optlist, const char *name, double deflt);
+extern _X_EXPORT char *xf86SetStrOption(XF86OptionPtr optlist, const char *name, char *deflt);
+extern _X_EXPORT int xf86SetBoolOption(XF86OptionPtr list, const char *name, int deflt );
+extern _X_EXPORT double xf86SetPercentOption(XF86OptionPtr list, const char *name, double deflt );
+extern _X_EXPORT int xf86CheckIntOption(XF86OptionPtr optlist, const char *name, int deflt);
+extern _X_EXPORT double xf86CheckRealOption(XF86OptionPtr optlist, const char *name, double deflt);
+extern _X_EXPORT char *xf86CheckStrOption(XF86OptionPtr optlist, const char *name, char *deflt);
+extern _X_EXPORT int xf86CheckBoolOption(XF86OptionPtr list, const char *name, int deflt );
+extern _X_EXPORT double xf86CheckPercentOption(XF86OptionPtr list, const char *name, double deflt );
+extern _X_EXPORT XF86OptionPtr xf86AddNewOption(XF86OptionPtr head, const char *name, const char *val );
+extern _X_EXPORT XF86OptionPtr xf86NewOption(char *name, char *value );
+extern _X_EXPORT XF86OptionPtr xf86NextOption(XF86OptionPtr list );
+extern _X_EXPORT XF86OptionPtr xf86OptionListCreate(const char **options, int count, int used);
+extern _X_EXPORT XF86OptionPtr xf86OptionListMerge(XF86OptionPtr head, XF86OptionPtr tail);
+extern _X_EXPORT XF86OptionPtr xf86OptionListDuplicate(XF86OptionPtr list);
+extern _X_EXPORT void xf86OptionListFree(XF86OptionPtr opt);
+extern _X_EXPORT char *xf86OptionName(XF86OptionPtr opt);
+extern _X_EXPORT char *xf86OptionValue(XF86OptionPtr opt);
+extern _X_EXPORT void xf86OptionListReport(XF86OptionPtr parm);
+extern _X_EXPORT XF86OptionPtr xf86FindOption(XF86OptionPtr options, const char *name);
+extern _X_EXPORT char *xf86FindOptionValue(XF86OptionPtr options, const char *name);
+extern _X_EXPORT void xf86MarkOptionUsed(XF86OptionPtr option);
+extern _X_EXPORT void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name);
+extern _X_EXPORT Bool xf86CheckIfOptionUsed(XF86OptionPtr option);
+extern _X_EXPORT Bool xf86CheckIfOptionUsedByName(XF86OptionPtr options, const char *name);
+extern _X_EXPORT void xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr options);
+extern _X_EXPORT void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, OptionInfoPtr optinfo);
 extern _X_EXPORT OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table, int token);
 extern _X_EXPORT const char *xf86TokenToOptName(const OptionInfoRec *table, int token);
 extern _X_EXPORT Bool xf86IsOptionSet(const OptionInfoRec *table, int token);
@@ -110,9 +111,9 @@ extern _X_EXPORT Bool xf86GetOptValBool(const OptionInfoRec *table, int token, B
 extern _X_EXPORT Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def);
 extern _X_EXPORT int xf86NameCmp(const char *s1, const char *s2);
 extern _X_EXPORT char *xf86NormalizeName(const char *s);
-extern _X_EXPORT pointer xf86ReplaceIntOption(pointer optlist,  const char *name, const int val);
-extern _X_EXPORT pointer xf86ReplaceRealOption(pointer optlist,  const char *name, const double val);
-extern _X_EXPORT pointer xf86ReplaceBoolOption(pointer optlist, const char *name, const Bool val);
-extern _X_EXPORT pointer xf86ReplacePercentOption(pointer optlist, const char *name, const double val);
-extern _X_EXPORT pointer xf86ReplaceStrOption(pointer optlist,  const char *name, const char* val);
+extern _X_EXPORT XF86OptionPtr xf86ReplaceIntOption(XF86OptionPtr optlist,  const char *name, const int val);
+extern _X_EXPORT XF86OptionPtr xf86ReplaceRealOption(XF86OptionPtr optlist,  const char *name, const double val);
+extern _X_EXPORT XF86OptionPtr xf86ReplaceBoolOption(XF86OptionPtr optlist, const char *name, const Bool val);
+extern _X_EXPORT XF86OptionPtr xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, const double val);
+extern _X_EXPORT XF86OptionPtr xf86ReplaceStrOption(XF86OptionPtr optlist,  const char *name, const char* val);
 #endif
diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c
index a3a836f..73b6573 100644
--- a/hw/xfree86/common/xf86Option.c
+++ b/hw/xfree86/common/xf86Option.c
@@ -40,11 +40,12 @@
 #include <X11/X.h>
 #include "os.h"
 #include "xf86.h"
+#include "xf86Opt.h"
 #include "xf86Xinput.h"
 #include "xf86Optrec.h"
 #include "xf86Parser.h"
 
-static Bool ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
+static Bool ParseOptionValue(int scrnIndex, XF86OptionPtr options, OptionInfoPtr p,
 			     Bool markUsed);
 
 /*
@@ -66,7 +67,7 @@ static Bool ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
  */
 
 void
-xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts)
+xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts)
 {
     XF86OptionPtr tmp;
     XF86OptionPtr extras = (XF86OptionPtr)extraOpts;
@@ -140,10 +141,10 @@ xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts)
  * Duplicate the option list passed in. The returned pointer will be a newly
  * allocated option list and must be freed by the caller.
  */
-pointer
-xf86OptionListDuplicate(pointer options)
+XF86OptionPtr
+xf86OptionListDuplicate(XF86OptionPtr options)
 {
-    pointer o = NULL;
+    XF86OptionPtr o = NULL;
 
     while (options)
     {
@@ -158,7 +159,7 @@ xf86OptionListDuplicate(pointer options)
 /* Created for new XInput stuff -- essentially extensions to the parser	*/
 
 static int
-LookupIntOption(pointer optlist, const char *name, int deflt, Bool markUsed)
+LookupIntOption(XF86OptionPtr optlist, const char *name, int deflt, Bool markUsed)
 {
     OptionInfoRec o;
 
@@ -171,7 +172,7 @@ LookupIntOption(pointer optlist, const char *name, int deflt, Bool markUsed)
 
 
 static double
-LookupRealOption(pointer optlist, const char *name, double deflt,
+LookupRealOption(XF86OptionPtr optlist, const char *name, double deflt,
 		 Bool markUsed)
 {
     OptionInfoRec o;
@@ -185,7 +186,7 @@ LookupRealOption(pointer optlist, const char *name, double deflt,
 
 
 static char *
-LookupStrOption(pointer optlist, const char *name, char *deflt, Bool markUsed)
+LookupStrOption(XF86OptionPtr optlist, const char *name, char *deflt, Bool markUsed)
 {
     OptionInfoRec o;
 
@@ -201,7 +202,7 @@ LookupStrOption(pointer optlist, const char *name, char *deflt, Bool markUsed)
 
 
 static int
-LookupBoolOption(pointer optlist, const char *name, int deflt, Bool markUsed)
+LookupBoolOption(XF86OptionPtr optlist, const char *name, int deflt, Bool markUsed)
 {
     OptionInfoRec o;
 
@@ -213,7 +214,7 @@ LookupBoolOption(pointer optlist, const char *name, int deflt, Bool markUsed)
 }
 
 static double
-LookupPercentOption(pointer optlist, const char *name, double deflt, Bool markUsed)
+LookupPercentOption(XF86OptionPtr optlist, const char *name, double deflt, Bool markUsed)
 {
     OptionInfoRec o;
 
@@ -227,34 +228,34 @@ LookupPercentOption(pointer optlist, const char *name, double deflt, Bool markUs
 /* These xf86Set* functions are intended for use by non-screen specific code */
 
 int
-xf86SetIntOption(pointer optlist, const char *name, int deflt)
+xf86SetIntOption(XF86OptionPtr optlist, const char *name, int deflt)
 {
     return LookupIntOption(optlist, name, deflt, TRUE);
 }
 
 
 double
-xf86SetRealOption(pointer optlist, const char *name, double deflt)
+xf86SetRealOption(XF86OptionPtr optlist, const char *name, double deflt)
 {
     return LookupRealOption(optlist, name, deflt, TRUE);
 }
 
 
 char *
-xf86SetStrOption(pointer optlist, const char *name, char *deflt)
+xf86SetStrOption(XF86OptionPtr optlist, const char *name, char *deflt)
 {
     return LookupStrOption(optlist, name, deflt, TRUE);
 }
 
 
 int
-xf86SetBoolOption(pointer optlist, const char *name, int deflt)
+xf86SetBoolOption(XF86OptionPtr optlist, const char *name, int deflt)
 {
     return LookupBoolOption(optlist, name, deflt, TRUE);
 }
 
 double
-xf86SetPercentOption(pointer optlist, const char *name, double deflt)
+xf86SetPercentOption(XF86OptionPtr optlist, const char *name, double deflt)
 {
     return LookupPercentOption(optlist, name, deflt, TRUE);
 }
@@ -264,35 +265,35 @@ xf86SetPercentOption(pointer optlist, const char *name, double deflt)
  * as used.
  */
 int
-xf86CheckIntOption(pointer optlist, const char *name, int deflt)
+xf86CheckIntOption(XF86OptionPtr optlist, const char *name, int deflt)
 {
     return LookupIntOption(optlist, name, deflt, FALSE);
 }
 
 
 double
-xf86CheckRealOption(pointer optlist, const char *name, double deflt)
+xf86CheckRealOption(XF86OptionPtr optlist, const char *name, double deflt)
 {
     return LookupRealOption(optlist, name, deflt, FALSE);
 }
 
 
 char *
-xf86CheckStrOption(pointer optlist, const char *name, char *deflt)
+xf86CheckStrOption(XF86OptionPtr optlist, const char *name, char *deflt)
 {
     return LookupStrOption(optlist, name, deflt, FALSE);
 }
 
 
 int
-xf86CheckBoolOption(pointer optlist, const char *name, int deflt)
+xf86CheckBoolOption(XF86OptionPtr optlist, const char *name, int deflt)
 {
     return LookupBoolOption(optlist, name, deflt, FALSE);
 }
 
 
 double
-xf86CheckPercentOption(pointer optlist, const char *name, double deflt)
+xf86CheckPercentOption(XF86OptionPtr optlist, const char *name, double deflt)
 {
     return LookupPercentOption(optlist, name, deflt, FALSE);
 }
@@ -300,44 +301,44 @@ xf86CheckPercentOption(pointer optlist, const char *name, double deflt)
  * addNewOption() has the required property of replacing the option value
  * if the option is already present.
  */
-pointer
-xf86ReplaceIntOption(pointer optlist, const char *name, const int val)
+XF86OptionPtr
+xf86ReplaceIntOption(XF86OptionPtr optlist, const char *name, const int val)
 {
     char tmp[16];
     sprintf(tmp,"%i",val);
     return xf86AddNewOption(optlist,name,tmp);
 }
 
-pointer
-xf86ReplaceRealOption(pointer optlist, const char *name, const double val)
+XF86OptionPtr
+xf86ReplaceRealOption(XF86OptionPtr optlist, const char *name, const double val)
 {
     char tmp[32];
     snprintf(tmp,32,"%f",val);
     return xf86AddNewOption(optlist,name,tmp);
 }
 
-pointer
-xf86ReplaceBoolOption(pointer optlist, const char *name, const Bool val)
+XF86OptionPtr
+xf86ReplaceBoolOption(XF86OptionPtr optlist, const char *name, const Bool val)
 {
     return xf86AddNewOption(optlist,name,val?"True":"False");
 }
 
-pointer
-xf86ReplacePercentOption(pointer optlist, const char *name, const double val)
+XF86OptionPtr
+xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, const double val)
 {
     char tmp[16];
     sprintf(tmp, "%lf%%", val);
     return xf86AddNewOption(optlist,name,tmp);
 }
 
-pointer
-xf86ReplaceStrOption(pointer optlist, const char *name, const char* val)
+XF86OptionPtr
+xf86ReplaceStrOption(XF86OptionPtr optlist, const char *name, const char* val)
 {
       return xf86AddNewOption(optlist,name,val);
 }
 
-pointer
-xf86AddNewOption(pointer head, const char *name, const char *val)
+XF86OptionPtr
+xf86AddNewOption(XF86OptionPtr head, const char *name, const char *val)
 {
     /* XXX These should actually be allocated in the parser library. */
     char *tmp = val ? strdup(val) : NULL;
@@ -347,51 +348,51 @@ xf86AddNewOption(pointer head, const char *name, const char *val)
 }
 
 
-pointer
+XF86OptionPtr
 xf86NewOption(char *name, char *value)
 {
     return xf86newOption(name, value);
 }
 
 
-pointer
-xf86NextOption(pointer list)
+XF86OptionPtr
+xf86NextOption(XF86OptionPtr list)
 {
     return xf86nextOption(list);
 }
 
-pointer
+XF86OptionPtr
 xf86OptionListCreate(const char **options, int count, int used)
 {
 	return xf86optionListCreate(options, count, used);
 }
 
-pointer
-xf86OptionListMerge(pointer head, pointer tail)
+XF86OptionPtr
+xf86OptionListMerge(XF86OptionPtr head, XF86OptionPtr tail)
 {
 	return xf86optionListMerge(head, tail);
 }
 
 void
-xf86OptionListFree(pointer opt)
+xf86OptionListFree(XF86OptionPtr opt)
 {
 	xf86optionListFree(opt);
 }
 
 char *
-xf86OptionName(pointer opt)
+xf86OptionName(XF86OptionPtr opt)
 {
 	return xf86optionName(opt);
 }
 
 char *
-xf86OptionValue(pointer opt)
+xf86OptionValue(XF86OptionPtr opt)
 {
 	return xf86optionValue(opt);
 }
 
 void
-xf86OptionListReport(pointer parm)
+xf86OptionListReport(XF86OptionPtr parm)
 {
     XF86OptionPtr opts = parm;
 
@@ -407,30 +408,30 @@ xf86OptionListReport(pointer parm)
 
 /* End of XInput-caused section	*/
 
-pointer
-xf86FindOption(pointer options, const char *name)
+XF86OptionPtr
+xf86FindOption(XF86OptionPtr options, const char *name)
 {
     return xf86findOption(options, name);
 }
 
 
 char *
-xf86FindOptionValue(pointer options, const char *name)
+xf86FindOptionValue(XF86OptionPtr options, const char *name)
 {
     return xf86findOptionValue(options, name);
 }
 
 
 void
-xf86MarkOptionUsed(pointer option)
+xf86MarkOptionUsed(XF86OptionPtr option)
 {
     if (option != NULL)
-	((XF86OptionPtr)option)->opt_used = TRUE;
+	option->opt_used = TRUE;
 }
 
 
 void
-xf86MarkOptionUsedByName(pointer options, const char *name)
+xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name)
 {
     XF86OptionPtr opt;
 
@@ -440,16 +441,16 @@ xf86MarkOptionUsedByName(pointer options, const char *name)
 }
 
 Bool
-xf86CheckIfOptionUsed(pointer option)
+xf86CheckIfOptionUsed(XF86OptionPtr option)
 {
     if (option != NULL)
-	return ((XF86OptionPtr)option)->opt_used;
+	return option->opt_used;
     else
 	return FALSE;
 }
 
 Bool
-xf86CheckIfOptionUsedByName(pointer options, const char *name)
+xf86CheckIfOptionUsedByName(XF86OptionPtr options, const char *name)
 {
     XF86OptionPtr opt;
 
@@ -461,10 +462,8 @@ xf86CheckIfOptionUsedByName(pointer options, const char *name)
 }
 
 void
-xf86ShowUnusedOptions(int scrnIndex, pointer options)
+xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr opt)
 {
-    XF86OptionPtr opt = options;
-
     while (opt) {
 	if (opt->opt_name && !opt->opt_used) {
 	    xf86DrvMsg(scrnIndex, X_WARNING, "Option \"%s\" is not used\n",
@@ -482,7 +481,7 @@ GetBoolValue(OptionInfoPtr p, const char *s)
 }
 
 static Bool
-ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
+ParseOptionValue(int scrnIndex, XF86OptionPtr options, OptionInfoPtr p,
 		 Bool markUsed)
 {
     char *s, *end;
@@ -695,7 +694,7 @@ ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
 
 
 void
-xf86ProcessOptions(int scrnIndex, pointer options, OptionInfoPtr optinfo)
+xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, OptionInfoPtr optinfo)
 {
     OptionInfoPtr p;
 
diff --git a/hw/xfree86/common/xf86Optionstr.h b/hw/xfree86/common/xf86Optionstr.h
new file mode 100644
index 0000000..8cc82d3
--- /dev/null
+++ b/hw/xfree86/common/xf86Optionstr.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * 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
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ */
+
+#ifndef XF86OPTIONSTR_H
+#define XF86OPTIONSTR_H
+
+/*
+ * all records that need to be linked lists should contain a GenericList as
+ * their first field.
+ */
+typedef struct generic_list_rec
+{
+	void *next;
+}
+GenericListRec, *GenericListPtr, *glp;
+
+/*
+ * All options are stored using this data type.
+ */
+typedef struct _XF86OptionRec
+{
+	GenericListRec list;
+	char *opt_name;
+	char *opt_val;
+	int opt_used;
+	char *opt_comment;
+}
+XF86OptionRec;
+
+typedef struct _XF86OptionRec *XF86OptionPtr;
+
+#endif
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index e25115c..114cdd9 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -276,7 +276,7 @@ ApplyAccelerationSettings(DeviceIntPtr dev){
  */
 void
 xf86ProcessCommonOptions(InputInfoPtr pInfo,
-                         pointer	list)
+                         XF86OptionPtr list)
 {
     if (xf86SetBoolOption(list, "Floating", 0) ||
         !xf86SetBoolOption(list, "AlwaysCore", 1) ||
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 1b0b16f..a4d9e58 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -103,7 +103,7 @@ typedef struct _InputInfoRec {
     char *		    type_name;
     InputDriverPtr	    drv;
     pointer		    module;
-    pointer		    options;
+    XF86OptionPtr	    options;
     InputAttributes         *attrs;
 } *InputInfoPtr;
 
@@ -144,7 +144,7 @@ extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int ke
 extern _X_EXPORT InputInfoPtr xf86FirstLocalDevice(void);
 extern _X_EXPORT int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min);
 extern _X_EXPORT void xf86XInputSetScreen(InputInfoPtr pInfo, int screen_number, int x, int y);
-extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo, pointer options);
+extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo, XF86OptionPtr options);
 extern _X_EXPORT void xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
 				int maxval, int resolution, int min_res,
 				int max_res, int mode);
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index 0290960..bc25c56 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -3175,7 +3175,7 @@ would not need to use these directly.
 
     <blockquote><para>
 	<programlisting>
-    pointer xf86FindOption(pointer options, const char *name);
+    XF86OptionPtr xf86FindOption(XF86OptionPtr options, const char *name);
 	</programlisting>
 	<blockquote><para>
       Takes a list of options and an option name, and returns a handle
@@ -3187,7 +3187,7 @@ would not need to use these directly.
 
     <blockquote><para>
 	<programlisting>
-    char *xf86FindOptionValue(pointer options, const char *name);
+    char *xf86FindOptionValue(XF86OptionPtr options, const char *name);
 	</programlisting>
 	<blockquote><para>
       Takes a list of options and an option name, and returns the value
@@ -3201,7 +3201,7 @@ would not need to use these directly.
 
     <blockquote><para>
 	<programlisting>
-    void xf86MarkOptionUsed(pointer option);
+    void xf86MarkOptionUsed(XF86OptionPtr option);
 	</programlisting>
 	<blockquote><para>
       Takes a handle for an option, and marks that option as used.
@@ -3211,7 +3211,7 @@ would not need to use these directly.
 
     <blockquote><para>
 	<programlisting>
-    void xf86MarkOptionUsedByName(pointer options, const char *name);
+    void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name);
 	</programlisting>
 	<blockquote><para>
       Takes a list of options and an option name and marks the first
@@ -3225,7 +3225,7 @@ Next, the higher level functions that most drivers would use.
     </para>
     <blockquote><para>
 	<programlisting>
-    void xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts);
+    void xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts);
 	</programlisting>
 	<blockquote><para>
       Collect the options from each of the config file sections used by
@@ -3245,7 +3245,7 @@ Next, the higher level functions that most drivers would use.
 
     <blockquote><para>
 	<programlisting>
-    void xf86ProcessOptions(int scrnIndex, pointer options,
+    void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options,
                             OptionInfoPtr optinfo);
 	</programlisting>
 	<blockquote><para>
@@ -3354,7 +3354,7 @@ Next, the higher level functions that most drivers would use.
 
     <blockquote><para>
 	<programlisting>
-    void xf86ShowUnusedOptions(int scrnIndex, pointer options);
+    void xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr options);
 	</programlisting>
 	<blockquote><para>
       Prints out warning messages for each option in the list of options
diff --git a/hw/xfree86/os-support/shared/posix_tty.c b/hw/xfree86/os-support/shared/posix_tty.c
index fb83860..cc12a31 100644
--- a/hw/xfree86/os-support/shared/posix_tty.c
+++ b/hw/xfree86/os-support/shared/posix_tty.c
@@ -112,7 +112,7 @@ GetBaud (int baudrate)
 }
 
 int
-xf86OpenSerial (pointer options)
+xf86OpenSerial (XF86OptionPtr options)
 {
 	struct termios t;
 	int fd, i;
@@ -185,7 +185,7 @@ xf86OpenSerial (pointer options)
 }
 
 int
-xf86SetSerial (int fd, pointer options)
+xf86SetSerial (int fd, XF86OptionPtr options)
 {
 	struct termios t;
 	int val;
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index f0cb768..6a29fbd 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -126,6 +126,7 @@
 
 #include <X11/Xfuncproto.h>
 #include "opaque.h"
+#include "xf86Optionstr.h"
 
 _XFUNCPROTOBEGIN
 
@@ -145,8 +146,8 @@ extern _X_EXPORT void xf86SetRGBOut(void);
 extern _X_EXPORT void xf86OSRingBell(int, int, int);
 extern _X_EXPORT void xf86SetReallySlowBcopy(void);
 extern _X_EXPORT void xf86SlowBcopy(unsigned char *, unsigned char *, int);
-extern _X_EXPORT int xf86OpenSerial(pointer options);
-extern _X_EXPORT int xf86SetSerial(int fd, pointer options);
+extern _X_EXPORT int xf86OpenSerial(XF86OptionPtr options);
+extern _X_EXPORT int xf86SetSerial(int fd, XF86OptionPtr options);
 extern _X_EXPORT int xf86SetSerialSpeed(int fd, int speed);
 extern _X_EXPORT int xf86ReadSerial(int fd, void *buf, int count);
 extern _X_EXPORT int xf86WriteSerial(int fd, const void *buf, int count);
diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am
index 1cd70e7..002cfbf 100644
--- a/hw/xfree86/parser/Makefile.am
+++ b/hw/xfree86/parser/Makefile.am
@@ -50,3 +50,5 @@ EXTRA_DIST = \
 sdk_HEADERS = \
 	xf86Parser.h \
 	xf86Optrec.h
+
+INCLUDES = -I$(srcdir)/../common
diff --git a/hw/xfree86/parser/xf86Optrec.h b/hw/xfree86/parser/xf86Optrec.h
index 5ccf728..61a8c5f 100644
--- a/hw/xfree86/parser/xf86Optrec.h
+++ b/hw/xfree86/parser/xf86Optrec.h
@@ -65,33 +65,10 @@
 #define _xf86Optrec_h_
 #include <stdio.h>
 #include <string.h>
+#include "xf86Optionstr.h"
 
 #include <X11/Xfuncproto.h>
 
-/* 
- * all records that need to be linked lists should contain a GenericList as
- * their first field.
- */
-typedef struct generic_list_rec
-{
-	void *next;
-}
-GenericListRec, *GenericListPtr, *glp;
-
-/*
- * All options are stored using this data type.
- */
-typedef struct
-{
-	GenericListRec list;
-	char *opt_name;
-	char *opt_val;
-	int opt_used;
-	char *opt_comment;
-}
-XF86OptionRec, *XF86OptionPtr;
-
-
 extern _X_EXPORT XF86OptionPtr xf86addNewOption(XF86OptionPtr head, char *name, char *val);
 extern _X_EXPORT XF86OptionPtr xf86optionListDup(XF86OptionPtr opt);
 extern _X_EXPORT void xf86optionListFree(XF86OptionPtr opt);
diff --git a/test/xfree86.c b/test/xfree86.c
index 2b591cf..7012e90 100644
--- a/test/xfree86.c
+++ b/test/xfree86.c
@@ -33,14 +33,15 @@
 static void
 xfree86_option_list_duplicate(void)
 {
-    pointer options;
-    pointer duplicate;
+    XF86OptionPtr options;
+    XF86OptionPtr duplicate;
     const char *o1 = "foo",
                *o2 = "bar",
                *v1 = "one",
                *v2 = "two";
     const char *o_null= "NULL";
     char *val1, *val2;
+    XF86OptionPtr a, b;
 
     duplicate = xf86OptionListDuplicate(NULL);
     assert(!duplicate);
@@ -67,9 +68,9 @@ xfree86_option_list_duplicate(void)
     assert(strcmp(val1, v2) == 0);
     assert(strcmp(val1, val2) == 0);
 
-    val1 = xf86FindOption(options, o_null);
-    val2 = xf86FindOption(duplicate, o_null);
-    assert(val1 && val2);
+    a = xf86FindOption(options, o_null);
+    b = xf86FindOption(duplicate, o_null);
+    assert(a && b);
 }
 
 int main(int argc, char** argv)
commit 05284a03f9002b03a66ae355b34790ec02b726f0
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Aug 4 14:45:46 2011 +1000

    input: make InputOption opaque, provide interface functions.
    
    InputOptions is not switched to use struct list for a future patch to unify
    it with the XF86OptionRec.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/config/config-backends.h b/config/config-backends.h
index 0d36d72..35ab8a0 100644
--- a/config/config-backends.h
+++ b/config/config-backends.h
@@ -27,10 +27,10 @@
 #include <dix-config.h>
 #endif
 #include "input.h"
+#include "list.h"
 
 void remove_devices(const char *backend, const char *config_info);
 BOOL device_is_duplicate(const char *config_info);
-InputOption* add_option(InputOption **options, const char *key, const char *value);
 
 #ifdef CONFIG_UDEV
 int config_udev_init(void);
diff --git a/config/config.c b/config/config.c
index af8f4f9..9c28785 100644
--- a/config/config.c
+++ b/config/config.c
@@ -122,25 +122,3 @@ device_is_duplicate(const char *config_info)
     return FALSE;
 }
 
-/**
- * Allocate a new option and append to the list.
- *
- * @return A pointer to the newly allocated InputOption struct.
- */
-InputOption*
-add_option(InputOption **options, const char *key, const char *value)
-{
-    if (!value || *value == '\0')
-        return NULL;
-
-    for (; *options; options = &(*options)->next)
-        ;
-    *options = calloc(sizeof(**options), 1);
-    if (!*options) /* Yeesh. */
-        return NULL;
-    (*options)->key = strdup(key);
-    (*options)->value = strdup(value);
-    (*options)->next = NULL;
-
-    return *options;
-}
diff --git a/config/dbus.c b/config/dbus.c
index 41eca99..f0fc568 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -68,8 +68,7 @@ static int
 add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
 {
     DBusMessageIter iter, reply_iter, subiter;
-    InputOption *tmpo = NULL, *options = NULL;
-    char *tmp = NULL;
+    InputOption *input_options = NULL;
     int ret, err;
     DeviceIntPtr dev = NULL;
 
@@ -80,7 +79,8 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
         MALFORMED_MESSAGE();
     }
 
-    if (!add_option(&options, "_source", "client/dbus")) {
+    input_options = input_option_new(input_options, "_source", "client/dbus");
+    if (!input_options) {
         ErrorF("[config/dbus] couldn't allocate first key/value pair\n");
         ret = BadAlloc;
         goto unwind;
@@ -88,36 +88,22 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
 
     /* signature should be [ss][ss]... */
     while (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) {
-        tmpo = calloc(sizeof(*tmpo), 1);
-        if (!tmpo) {
-            ErrorF("[config/dbus] couldn't allocate option\n");
-            ret = BadAlloc;
-            goto unwind;
-        }
-        tmpo->next = options;
-        options = tmpo;
-
+        char *key, *value;
         dbus_message_iter_recurse(&iter, &subiter);
 
         if (dbus_message_iter_get_arg_type(&subiter) != DBUS_TYPE_STRING)
             MALFORMED_MESSAGE();
 
-        dbus_message_iter_get_basic(&subiter, &tmp);
-        if (!tmp)
+        dbus_message_iter_get_basic(&subiter, &key);
+        if (!key)
             MALFORMED_MESSAGE();
         /* The _ prefix refers to internal settings, and may not be given by
          * the client. */
-        if (tmp[0] == '_') {
+        if (key[0] == '_') {
             ErrorF("[config/dbus] attempted subterfuge: option name %s given\n",
-                   tmp);
+                   key);
             MALFORMED_MESSAGE();
         }
-        options->key = strdup(tmp);
-        if (!options->key) {
-            ErrorF("[config/dbus] couldn't duplicate key!\n");
-            ret = BadAlloc;
-            goto unwind;
-        }
 
         if (!dbus_message_iter_has_next(&subiter))
             MALFORMED_MESSAGE();
@@ -125,20 +111,16 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
         if (dbus_message_iter_get_arg_type(&subiter) != DBUS_TYPE_STRING)
             MALFORMED_MESSAGE();
 
-        dbus_message_iter_get_basic(&subiter, &tmp);
-        if (!tmp)
+        dbus_message_iter_get_basic(&subiter, &value);
+        if (!value)
             MALFORMED_MESSAGE();
-        options->value = strdup(tmp);
-        if (!options->value) {
-            ErrorF("[config/dbus] couldn't duplicate option!\n");
-            ret = BadAlloc;
-            goto unwind;
-        }
+
+        input_options = input_option_new(input_options, key, value);
 
         dbus_message_iter_next(&iter);
     }
 
-    ret = NewInputDeviceRequest(options, NULL, &dev);
+    ret = NewInputDeviceRequest(input_options, NULL, &dev);
     if (ret != Success) {
         DebugF("[config/dbus] NewInputDeviceRequest failed\n");
         goto unwind;
@@ -172,13 +154,7 @@ unwind:
         dbus_message_iter_append_basic(&reply_iter, DBUS_TYPE_INT32, &err);
     }
 
-    while (options) {
-        tmpo = options;
-        options = options->next;
-        free(tmpo->key);
-        free(tmpo->value);
-        free(tmpo);
-    }
+    input_option_free_list(&input_options);
 
     return ret;
 }
diff --git a/config/hal.c b/config/hal.c
index 0b2d7d0..aa234eb 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -128,7 +128,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
 {
     char *path = NULL, *driver = NULL, *name = NULL, *config_info = NULL;
     char *hal_tags, *parent;
-    InputOption *options = NULL, *tmpo = NULL;
+    InputOption *input_options = NULL;
     InputAttributes attrs = {0};
     DeviceIntPtr dev = NULL;
     DBusError error;
@@ -205,18 +205,19 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         free(parent);
     }
 
-    if (!add_option(&options, "_source", "server/hal")) {
+    input_options = input_option_new(NULL, "_source", "server/hal");
+    if (!input_options) {
         LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n");
         goto unwind;
     }
 
     /* most drivers use device.. not path. evdev uses both however, but the
      * path version isn't documented apparently. support both for now. */
-    add_option(&options, "path", path);
-    add_option(&options, "device", path);
+    input_options = input_option_new(input_options, "path", path);
+    input_options = input_option_new(input_options, "device", path);
 
-    add_option(&options, "driver", driver);
-    add_option(&options, "name", name);
+    input_options = input_option_new(input_options, "driver", driver);
+    input_options = input_option_new(input_options, "name", name);
 
     if (asprintf (&config_info, "hal:%s", udi) == -1) {
         config_info = NULL;
@@ -290,7 +291,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                     } else
                     {
                         /* all others */
-                        add_option(&options, psi_key + sizeof(LIBHAL_PROP_KEY)-1, tmp_val);
+                        input_options = input_option_new(input_options, psi_key + sizeof(LIBHAL_PROP_KEY)-1, tmp_val);
                         free(tmp_val);
                     }
                 } else
@@ -358,20 +359,20 @@ device_added(LibHalContext *hal_ctx, const char *udi)
 
     /* Now add xkb options */
     if (xkb_opts.layout)
-        add_option(&options, "xkb_layout", xkb_opts.layout);
+        input_options = input_option_new(input_options, "xkb_layout", xkb_opts.layout);
     if (xkb_opts.rules)
-        add_option(&options, "xkb_rules", xkb_opts.rules);
+        input_options = input_option_new(input_options, "xkb_rules", xkb_opts.rules);
     if (xkb_opts.variant)
-        add_option(&options, "xkb_variant", xkb_opts.variant);
+        input_options = input_option_new(input_options, "xkb_variant", xkb_opts.variant);
     if (xkb_opts.model)
-        add_option(&options, "xkb_model", xkb_opts.model);
+        input_options = input_option_new(input_options, "xkb_model", xkb_opts.model);
     if (xkb_opts.options)
-        add_option(&options, "xkb_options", xkb_opts.options);
-    add_option(&options, "config_info", config_info);
+        input_options = input_option_new(input_options, "xkb_options", xkb_opts.options);
+    input_options = input_option_new(input_options, "config_info", config_info);
 
     /* this isn't an error, but how else do you output something that the user can see? */
     LogMessage(X_INFO, "config/hal: Adding input device %s\n", name);
-    if ((rc = NewInputDeviceRequest(options, &attrs, &dev)) != Success) {
+    if ((rc = NewInputDeviceRequest(input_options, &attrs, &dev)) != Success) {
         LogMessage(X_ERROR, "config/hal: NewInputDeviceRequest failed (%d)\n", rc);
         dev = NULL;
         goto unwind;
@@ -384,12 +385,7 @@ unwind:
     free(driver);
     free(name);
     free(config_info);
-    while ((tmpo = options)) {
-        options = tmpo->next;
-        free(tmpo->key);        /* NULL if dev != NULL */
-        free(tmpo->value);      /* NULL if dev != NULL */
-        free(tmpo);
-    }
+    input_option_free_list(&input_options);
 
     free(attrs.product);
     free(attrs.vendor);
diff --git a/config/udev.c b/config/udev.c
index 1f431c1..1ba0d50 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -60,7 +60,7 @@ device_added(struct udev_device *udev_device)
     const char *syspath;
     const char *tags_prop;
     const char *key, *value, *tmp;
-    InputOption *options = NULL, *tmpo;
+    InputOption *input_options;
     InputAttributes attrs = {};
     DeviceIntPtr dev = NULL;
     struct udev_list_entry *set, *entry;
@@ -93,8 +93,9 @@ device_added(struct udev_device *udev_device)
         return;
     }
 
-    if (!add_option(&options, "_source", "server/udev"))
-        goto unwind;
+    input_options = input_option_new(NULL, "_source", "server/udev");
+    if (!input_options)
+        return;
 
     parent = udev_device_get_parent(udev_device);
     if (parent) {
@@ -127,10 +128,9 @@ device_added(struct udev_device *udev_device)
         name = "(unnamed)";
     else
         attrs.product = strdup(name);
-    add_option(&options, "name", name);
-
-    add_option(&options, "path", path);
-    add_option(&options, "device", path);
+    input_options = input_option_new(input_options, "name", name);
+    input_options = input_option_new(input_options, "path", path);
+    input_options = input_option_new(input_options, "device", path);
     if (path)
         attrs.device = strdup(path);
 
@@ -160,15 +160,15 @@ device_added(struct udev_device *udev_device)
             LOG_PROPERTY(path, key, value);
             tmp = key + sizeof(UDEV_XKB_PROP_KEY) - 1;
             if (!strcasecmp(tmp, "rules"))
-                add_option(&options, "xkb_rules", value);
+                input_options = input_option_new(input_options, "xkb_rules", value);
             else if (!strcasecmp(tmp, "layout"))
-                add_option(&options, "xkb_layout", value);
+                input_options = input_option_new(input_options, "xkb_layout", value);
             else if (!strcasecmp(tmp, "variant"))
-                add_option(&options, "xkb_variant", value);
+                input_options = input_option_new(input_options, "xkb_variant", value);
             else if (!strcasecmp(tmp, "model"))
-                add_option(&options, "xkb_model", value);
+                input_options = input_option_new(input_options, "xkb_model", value);
             else if (!strcasecmp(tmp, "options"))
-                add_option(&options, "xkb_options", value);
+                input_options = input_option_new(input_options, "xkb_options", value);
         } else if (!strcmp(key, "ID_VENDOR")) {
             LOG_PROPERTY(path, key, value);
             attrs.vendor = strdup(value);
@@ -193,22 +193,17 @@ device_added(struct udev_device *udev_device)
         }
     }
 
-    add_option(&options, "config_info", config_info);
+    input_options = input_option_new(input_options, "config_info", config_info);
 
     LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n",
                name, path);
-    rc = NewInputDeviceRequest(options, &attrs, &dev);
+    rc = NewInputDeviceRequest(input_options, &attrs, &dev);
     if (rc != Success)
         goto unwind;
 
  unwind:
     free(config_info);
-    while ((tmpo = options)) {
-        options = tmpo->next;
-        free(tmpo->key);        /* NULL if dev != NULL */
-        free(tmpo->value);      /* NULL if dev != NULL */
-        free(tmpo);
-    }
+    input_option_free_list(&input_options);
 
     free(attrs.usb_id);
     free(attrs.pnp_id);
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 9632076..7aeb1e5 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -598,3 +598,144 @@ void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms)
     event->deviceid = dev->id;
     event->sourceid = dev->id;
 }
+
+/**
+ * Delete the element with the key from the list, freeing all memory
+ * associated with the element..
+ */
+static void
+input_option_free(InputOption *o)
+{
+    free(o->key);
+    free(o->value);
+    free(o);
+}
+
+/*
+ * Create a new InputOption with the key/value pair provided.
+ * If a list is provided, the new options is added to the list and the list
+ * is returned.
+ *
+ * If a new option is added to a list that already contains that option, the
+ * previous option is overwritten.
+ *
+ * @param list The list to add to.
+ * @param key Option key, will be copied.
+ * @param value Option value, will be copied.
+ *
+ * @return If list is not NULL, the list with the new option added. If list
+ * is NULL, a new option list with one element. On failure, NULL is
+ * returned.
+ */
+InputOption*
+input_option_new(InputOption* list, const char *key, const char *value)
+{
+    InputOption *opt = NULL;
+
+    if (!key)
+        return NULL;
+
+    if (list)
+    {
+        nt_list_for_each_entry(opt, list, next)
+        {
+            if (strcmp(input_option_get_key(opt), key) == 0)
+            {
+                input_option_set_value(opt, value);
+                return list;
+            }
+        }
+    }
+
+    opt = calloc(1, sizeof(InputOption));
+    if (!opt)
+        return NULL;
+
+    nt_list_init(opt, next);
+    input_option_set_key(opt, key);
+    input_option_set_value(opt, value);
+
+    if (list)
+    {
+        nt_list_append(opt, list, InputOption, next);
+        return list;
+    } else
+        return opt;
+}
+
+InputOption*
+input_option_free_element(InputOption *list, const char *key)
+{
+    InputOption *element;
+
+    nt_list_for_each_entry(element, list, next) {
+        if (strcmp(input_option_get_key(element), key) == 0) {
+            nt_list_del(element, list, InputOption, next);
+            input_option_free(element);
+            break;
+        }
+    }
+    return list;
+}
+
+/**
+ * Free the list pointed at by opt.
+ */
+void
+input_option_free_list(InputOption **opt)
+{
+    InputOption *element, *tmp;
+
+    nt_list_for_each_entry_safe(element, tmp, *opt, next) {
+        nt_list_del(element, *opt, InputOption, next);
+        input_option_free(element);
+    }
+    *opt = NULL;
+}
+
+
+/**
+ * Find the InputOption with the given option name.
+ *
+ * @return The InputOption or NULL if not present.
+ */
+InputOption*
+input_option_find(InputOption *list, const char *key)
+{
+    InputOption *element;
+
+    nt_list_for_each_entry(element, list, next) {
+        if (strcmp(input_option_get_key(element), key) == 0)
+            return element;
+    }
+
+    return NULL;
+}
+
+const char*
+input_option_get_key(const InputOption *opt)
+{
+    return opt->key;
+}
+
+const char*
+input_option_get_value(const InputOption *opt)
+{
+    return opt->value;
+}
+
+void
+input_option_set_key(InputOption *opt, const char *key)
+{
+    free(opt->key);
+    if (key)
+        opt->key = strdup(key);
+}
+
+void
+input_option_set_value(InputOption *opt, const char *value)
+{
+    free(opt->value);
+    if (value)
+        opt->value = strdup(value);
+}
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 83d5cae..e25115c 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -879,35 +879,35 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
     if (!pInfo)
         return BadAlloc;
 
-    for (option = options; option; option = option->next) {
-        if (strcasecmp(option->key, "driver") == 0) {
+    nt_list_for_each_entry(option, options, next) {
+        if (strcasecmp(input_option_get_key(option), "driver") == 0) {
             if (pInfo->driver) {
                 rval = BadRequest;
                 goto unwind;
             }
-            pInfo->driver = xstrdup(option->value);
+            pInfo->driver = xstrdup(input_option_get_value(option));
             if (!pInfo->driver) {
                 rval = BadAlloc;
                 goto unwind;
             }
         }
 
-        if (strcasecmp(option->key, "name") == 0 ||
-            strcasecmp(option->key, "identifier") == 0) {
+        if (strcasecmp(input_option_get_key(option), "name") == 0 ||
+            strcasecmp(input_option_get_key(option), "identifier") == 0) {
             if (pInfo->name) {
                 rval = BadRequest;
                 goto unwind;
             }
-            pInfo->name = xstrdup(option->value);
+            pInfo->name = xstrdup(input_option_get_value(option));
             if (!pInfo->name) {
                 rval = BadAlloc;
                 goto unwind;
             }
         }
 
-        if (strcmp(option->key, "_source") == 0 &&
-            (strcmp(option->value, "server/hal") == 0 ||
-             strcmp(option->value, "server/udev") == 0)) {
+        if (strcmp(input_option_get_key(option), "_source") == 0 &&
+            (strcmp(input_option_get_value(option), "server/hal") == 0 ||
+             strcmp(input_option_get_value(option), "server/udev") == 0)) {
             is_auto = 1;
             if (!xf86Info.autoAddDevices) {
                 rval = BadMatch;
@@ -916,13 +916,11 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
         }
     }
 
-    for (option = options; option; option = option->next) {
-        /* Steal option key/value strings from the provided list.
-         * We need those strings, the InputOption list doesn't. */
-        pInfo->options = xf86addNewOption(pInfo->options,
-                                               option->key, option->value);
-        option->key = NULL;
-        option->value = NULL;
+    nt_list_for_each_entry(option, options, next) {
+        /* Copy option key/value strings from the provided list */
+        pInfo->options = xf86AddNewOption(pInfo->options,
+                                          input_option_get_key(option),
+                                          input_option_get_value(option));
     }
 
     /* Apply InputClass settings */
diff --git a/include/input.h b/include/input.h
index 5377a0c..0258f4f 100644
--- a/include/input.h
+++ b/include/input.h
@@ -56,6 +56,7 @@ SOFTWARE.
 #include "window.h"     /* for WindowPtr */
 #include "xkbrules.h"
 #include "events.h"
+#include "list.h"
 
 #define DEVICE_INIT	0
 #define DEVICE_ON	1
@@ -202,11 +203,7 @@ typedef struct {
 extern _X_EXPORT KeybdCtrl	defaultKeyboardControl;
 extern _X_EXPORT PtrCtrl	defaultPointerControl;
 
-typedef struct _InputOption {
-    char                *key;
-    char                *value;
-    struct _InputOption *next;
-} InputOption;
+typedef struct _InputOption InputOption;
 
 typedef struct _InputAttributes {
     char                *product;
@@ -595,4 +592,14 @@ extern _X_EXPORT void valuator_mask_copy(ValuatorMask *dest,
                                          const ValuatorMask *src);
 extern _X_EXPORT int valuator_mask_get(const ValuatorMask *mask, int valnum);
 
+/* InputOption handling interface */
+extern _X_EXPORT InputOption* input_option_new(InputOption *list, const char *key, const char *value);
+extern _X_EXPORT void input_option_free_list(InputOption **opt);
+extern _X_EXPORT InputOption* input_option_free_element(InputOption *opt, const char *key);
+extern _X_EXPORT InputOption* input_option_find(InputOption *list, const char *key);
+extern _X_EXPORT const char* input_option_get_key(const InputOption *opt);
+extern _X_EXPORT const char* input_option_get_value(const InputOption *opt);
+extern _X_EXPORT void input_option_set_key(InputOption *opt, const char* key);
+extern _X_EXPORT void input_option_set_value(InputOption *opt, const char* value);
+
 #endif /* INPUT_H */
diff --git a/include/inputstr.h b/include/inputstr.h
index 838f9f0..480e956 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -602,4 +602,11 @@ static inline WindowPtr DeepestSpriteWin(SpritePtr sprite)
     return sprite->spriteTrace[sprite->spriteTraceGood - 1];
 }
 
+struct _InputOption {
+    char                *key;
+    char                *value;
+    struct _InputOption *next;
+};
+
+
 #endif /* INPUTSTRUCT_H */
diff --git a/test/input.c b/test/input.c
index 5d4cbf6..b8dad1c 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1308,6 +1308,95 @@ static void dix_get_master(void)
 }
 
 
+static void input_option_test(void)
+{
+    InputOption *list = NULL;
+    InputOption *opt;
+    const char *val;
+
+    printf("Testing input_option list interface\n");
+
+    list = input_option_new(list, "key", "value");
+    assert(list);
+    opt = input_option_find(list, "key");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "value") == 0);
+
+    list = input_option_new(list, "2", "v2");
+    opt = input_option_find(list, "key");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "value") == 0);
+
+    opt = input_option_find(list, "2");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "v2") == 0);
+
+    list = input_option_new(list, "3", "v3");
+
+    /* search, delete */
+    opt = input_option_find(list, "key");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "value") == 0);
+    list = input_option_free_element(list, "key");
+    opt = input_option_find(list, "key");
+    assert(opt == NULL);
+
+    opt = input_option_find(list, "2");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "v2") == 0);
+    list = input_option_free_element(list, "2");
+    opt = input_option_find(list, "2");
+    assert(opt == NULL);
+
+    opt = input_option_find(list, "3");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "v3") == 0);
+    list = input_option_free_element(list, "3");
+    opt = input_option_find(list, "3");
+    assert(opt == NULL);
+
+    /* list deletion */
+    list = input_option_new(list, "1", "v3");
+    list = input_option_new(list, "2", "v3");
+    list = input_option_new(list, "3", "v3");
+    input_option_free_list(&list);
+
+    assert(list == NULL);
+
+    list = input_option_new(list, "1", "v1");
+    list = input_option_new(list, "2", "v2");
+    list = input_option_new(list, "3", "v3");
+
+    /* value replacement */
+    opt = input_option_find(list, "2");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "v2") == 0);
+    input_option_set_value(opt, "foo");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "foo") == 0);
+    opt = input_option_find(list, "2");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "foo") == 0);
+
+    /* key replacement */
+    input_option_set_key(opt, "bar");
+    val = input_option_get_key(opt);
+    assert(strcmp(val, "bar") == 0);
+    opt = input_option_find(list, "bar");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "foo") == 0);
+
+    /* value replacement in input_option_new */
+    list = input_option_new(list, "bar", "foobar");
+    opt = input_option_find(list, "bar");
+    val = input_option_get_value(opt);
+    assert(strcmp(val, "foobar") == 0);
+
+    input_option_free_list(&list);
+    assert(list == NULL);
+}
+
+
 int main(int argc, char** argv)
 {
     dix_input_valuator_masks();
@@ -1324,6 +1413,7 @@ int main(int argc, char** argv)
     xi_unregister_handlers();
     dix_valuator_alloc();
     dix_get_master();
+    input_option_test();
 
     return 0;
 }
commit fcafe825751bef99f4c0b36250ca6f15f127502f
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 8 15:21:46 2011 +1000

    Add null-terminated list interface.
    
    This is a set of macros to provide a struct list-alike interface for classic
    linked lists such as the XF86OptionRec or the DeviceIntRec. The typical
    format for these is to have a "struct foo *next" pointer in each struct foo
    and walk through those. These macros provide a few basic functions to add to,
    remove from and iterate through these lists.
    
    While struct list is in some ways more flexible, switching legacy code to
    use struct list is not alway viable. These macros at least reduce the amount
    of open-coded lists.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/include/list.h b/include/list.h
index 5933b97..7825dce 100644
--- a/include/list.h
+++ b/include/list.h
@@ -278,4 +278,164 @@ list_is_empty(struct list *head)
 	 &pos->member != (head);					\
 	 pos = tmp, tmp = __container_of(pos->member.next, tmp, member))
 
+
+
+/* NULL-Terminated List Interface
+ *
+ * The interface below does _not_ use the struct list as described above.
+ * It is mainly for legacy structures that cannot easily be switched to
+ * struct list.
+ *
+ * This interface is for structs like
+ *      struct foo {
+ *          [...]
+ *          struct foo *next;
+ *           [...]
+ *      };
+ *
+ * The position and field name of "next" are arbitrary.
+ */
+
+/**
+ * Init the element as null-terminated list.
+ *
+ * Example:
+ * struct foo *list = malloc();
+ * nt_list_init(list, next);
+ *
+ * @param list The list element that will be the start of the list
+ * @param member Member name of the field pointing to next struct
+ */
+#define nt_list_init(_list, _member) \
+	(_list)->_member = NULL
+
+/**
+ * Returns the next element in the list or NULL on termination.
+ *
+ * Example:
+ * struct foo *element = list;
+ * while ((element = nt_list_next(element, next)) { }
+ *
+ * This macro is not safe for node deletion. Use list_for_each_entry_safe
+ * instead.
+ *
+ * @param list The list or current element.
+ * @param member Member name of the field pointing to next struct.
+ */
+#define nt_list_next(_list, _member) \
+	(_list)->_member
+
+/**
+ * Iterate through each element in the list.
+ *
+ * Example:
+ * struct foo *iterator;
+ * nt_list_for_each_entry(iterator, list, next) {
+ *      [modify iterator]
+ * }
+ *
+ * @param entry Assigned to the current list element
+ * @param list The list to iterate through.
+ * @param member Member name of the field pointing to next struct.
+ */
+#define nt_list_for_each_entry(_entry, _list, _member)			\
+	for (_entry = _list; _entry; _entry = (_entry)->_member)
+
+/**
+ * Iterate through each element in the list, keeping a backup pointer to the
+ * element. This macro allows for the deletion of a list element while
+ * looping through the list.
+ *
+ * See nt_list_for_each_entry for more details.
+ *
+ * @param entry Assigned to the current list element
+ * @param tmp The pointer to the next element
+ * @param list The list to iterate through.
+ * @param member Member name of the field pointing to next struct.
+ */
+#define nt_list_for_each_entry_safe(_entry, _tmp, _list, _member)	\
+	for (_entry = _list, _tmp = (_entry) ? (_entry)->_member : NULL;\
+		_entry;							\
+		_entry = _tmp, _tmp = (_tmp) ? (_tmp)->_member: NULL)
+
+
+/**
+ * Append the element to the end of the list. This macro may be used to
+ * merge two lists.
+ *
+ * Example:
+ * struct foo *elem = malloc(...);
+ * nt_list_init(elem, next)
+ * nt_list_append(elem, list, struct foo, next);
+ *
+ * Resulting list order:
+ * list_item_0 -> list_item_1 -> ... -> elem_item_0 -> elem_item_1 ...
+ *
+ * @param entry An entry (or list) to append to the list
+ * @param list The list to append to. This list must be a valid list, not
+ * NULL.
+ * @param type The list type
+ * @param member Member name of the field pointing to next struct
+ */
+#define nt_list_append(_entry, _list, _type, _member)		        \
+    do {								\
+	_type *__iterator = _list;					\
+	while (__iterator->_member) { __iterator = __iterator->_member;}\
+	__iterator->_member = _entry;					\
+    } while (0)
+
+/**
+ * Insert the element at the next position in the list. This macro may be
+ * used to insert a list into a list.
+ *
+ * struct foo *elem = malloc(...);
+ * nt_list_init(elem, next)
+ * nt_list_insert(elem, list, struct foo, next);
+ *
+ * Resulting list order:
+ * list_item_0 -> elem_item_0 -> elem_item_1 ... -> list_item_1 -> ...
+ *
+ * @param entry An entry (or list) to append to the list
+ * @param list The list to insert to. This list must be a valid list, not
+ * NULL.
+ * @param type The list type
+ * @param member Member name of the field pointing to next struct
+ */
+#define nt_list_insert(_entry, _list, _type, _member)			\
+    do {								\
+	nt_list_append((_list)->_member, _entry, _type, _member);	\
+	(_list)->_member = _entry;					\
+    } while (0)
+
+/**
+ * Delete the entry from the list by iterating through the list and
+ * removing any reference from the list to the entry.
+ *
+ * Example:
+ * struct foo *elem = <assign to right element>
+ * nt_list_del(elem, list, struct foo, next);
+ *
+ * @param entry The entry to delete from the list. entry is always
+ * re-initialized as a null-terminated list.
+ * @param list The list containing the entry, set to the new list without
+ * the removed entry.
+ * @param type The list type
+ * @param member Member name of the field pointing to the next entry
+ */
+#define nt_list_del(_entry, _list, _type, _member)		\
+	do {							\
+		_type *__e = _entry;				\
+		if (__e == NULL) break;				\
+		if ((_list) == __e) {				\
+		    _list = __e->_member;			\
+		} else {					\
+		    _type *__prev = _list;			\
+		    while (__prev->_member && __prev->_member != __e)	\
+			__prev = nt_list_next(__prev, _member);	\
+		    if (__prev->_member)			\
+			__prev->_member = __e->_member;		\
+		}						\
+		nt_list_init(__e, _member);			\
+	} while(0)
+
 #endif
diff --git a/test/list.c b/test/list.c
index b101c76..f7d7bff 100644
--- a/test/list.c
+++ b/test/list.c
@@ -29,6 +29,7 @@
 #include <list.h>
 #include <string.h>
 #include <assert.h>
+#include <stdlib.h>
 
 struct parent {
     int a;
@@ -161,6 +162,164 @@ test_list_for_each(void)
     }
 }
 
+struct foo {
+    char a;
+    struct foo *next;
+    char b;
+};
+
+static void
+test_nt_list_init(void)
+{
+    struct foo foo;
+
+    foo.a = 10;
+    foo.b = 20;
+    nt_list_init(&foo, next);
+
+    assert(foo.a == 10);
+    assert(foo.b == 20);
+    assert(foo.next == NULL);
+    assert(nt_list_next(&foo, next) == NULL);
+}
+
+static void
+test_nt_list_append(void)
+{
+    int i;
+    struct foo *foo = calloc(10, sizeof(struct foo));
+    struct foo *item;
+
+    for (item = foo, i = 1; i <= 10; i++, item++)
+    {
+	item->a = i;
+	item->b = i * 2;
+	nt_list_init(item, next);
+
+	if (item != foo)
+	    nt_list_append(item, foo, struct foo, next);
+    }
+
+    /* Test using nt_list_next */
+    for (item = foo, i = 1; i <= 10; i++, item = nt_list_next(item, next))
+    {
+	assert(item->a = i);
+	assert(item->b = i * 2);
+    }
+
+    /* Test using nt_list_for_each_entry */
+    i = 1;
+    nt_list_for_each_entry(item, foo, next) {
+	assert(item->a = i);
+	assert(item->b = i * 2);
+	i++;
+    }
+    assert(i == 11);
+}
+
+static void
+test_nt_list_insert(void)
+{
+    int i;
+    struct foo *foo = calloc(10, sizeof(struct foo));
+    struct foo *item;
+
+    foo->a = 10;
+    foo->b = 20;
+    nt_list_init(foo, next);
+
+    for (item = &foo[1], i = 9; i > 0; i--, item++)
+    {
+	item->a = i;
+	item->b = i * 2;
+	nt_list_init(item, next);
+	nt_list_insert(item, foo, struct foo, next);
+    }
+
+    /* Test using nt_list_next */
+    for (item = foo, i = 10; i > 0; i--, item = nt_list_next(item, next))
+    {
+	assert(item->a = i);
+	assert(item->b = i * 2);
+    }
+
+    /* Test using nt_list_for_each_entry */
+    i = 1;
+    nt_list_for_each_entry(item, foo, next) {
+	assert(item->a = i);
+	assert(item->b = i * 2);
+	i++;
+    }
+    assert(i == 11);
+}
+
+static void
+test_nt_list_delete(void)
+{
+    int i = 1;
+    struct foo *list = calloc(10, sizeof(struct foo));
+    struct foo *foo = list;
+    struct foo *item, *tmp;
+    struct foo *empty_list = foo;
+
+    nt_list_init(empty_list, next);
+    nt_list_del(empty_list, empty_list, struct foo, next);
+    assert(!empty_list);
+
+    for (item = foo, i = 1; i <= 10; i++, item++)
+    {
+	item->a = i;
+	item->b = i * 2;
+	nt_list_init(item, next);
+
+	if (item != foo)
+	    nt_list_append(item, foo, struct foo, next);
+    }
+
+    i = 0;
+    nt_list_for_each_entry(item, foo, next) {
+	i++;
+    }
+    assert(i == 10);
+
+    /* delete last item */
+    nt_list_del(&foo[9], foo, struct foo, next);
+    i = 0;
+    nt_list_for_each_entry(item, foo, next) {
+	assert(item->a != 10); /* element 10 is gone now */
+	i++;
+    }
+    assert(i == 9); /* 9 elements left */
+
+    /* delete second item */
+    nt_list_del(foo->next, foo, struct foo, next);
+    assert(foo->next->a == 3);
+
+    i = 0;
+    nt_list_for_each_entry(item, foo, next) {
+	assert(item->a != 10); /* element 10 is gone now */
+	assert(item->a != 2); /* element 2 is gone now */
+	i++;
+    }
+    assert(i == 8); /* 9 elements left */
+
+    item = foo;
+    /* delete first item */
+    nt_list_del(foo, foo, struct foo, next);
+    assert(item != foo);
+    assert(item->next == NULL);
+    assert(foo->a == 3);
+    assert(foo->next->a == 4);
+
+    nt_list_for_each_entry_safe(item, tmp, foo, next) {
+	nt_list_del(item, foo, struct foo, next);
+    }
+
+    assert(!foo);
+    assert(!item);
+
+    free(list);
+}
 
 int main(int argc, char** argv)
 {
@@ -169,5 +328,10 @@ int main(int argc, char** argv)
     test_list_del();
     test_list_for_each();
 
+    test_nt_list_init();
+    test_nt_list_append();
+    test_nt_list_insert();
+    test_nt_list_delete();
+
     return 0;
 }
commit 79ca7c0b5786a02a80a1c40ed475e928da7c82b3
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 12 15:55:48 2011 +1000

    xfree86: comment typo fix
    
    in synch → in sync
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index d22fdc8..83d5cae 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -1348,7 +1348,7 @@ xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
 }
 
 /*
- * Set the valuator values to be in synch with dix/event.c
+ * Set the valuator values to be in sync with dix/event.c
  * DefineInitialRootWindow().
  */
 void
commit 2bfb802839688ecf328119c4c6979390fc60348d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jul 29 16:33:54 2011 +1000

    dix: don't XWarpPointer through the last slave anymore (#38313)
    
    This line was introduced pre-1.6 to fix Bug 19297. The effect of warping
    through the VCP then was that if a device had custom valuator ranges, the
    warp position would be wrong. The better device for this effect is the the
    XTest device.
    
    This fixes a server crash where the lastSlave is a pointer device without
    valuators (Bug 38313#0).
    
    And while we're at it, make sure the Xinerama code-path does the same.
    
    X.Org Bug 38313 <http://bugs.freedesktop.org/show_bug.cgi?id=38313>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 27c3172..7fe0fba 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3377,16 +3377,21 @@ XineramaWarpPointer(ClientPtr client)
 {
     WindowPtr	dest = NULL;
     int		x, y, rc;
-    SpritePtr   pSprite = PickPointer(client)->spriteInfo->sprite;
+    DeviceIntPtr dev;
+    SpritePtr   pSprite;
 
     REQUEST(xWarpPointerReq);
 
-
     if (stuff->dstWid != None) {
 	rc = dixLookupWindow(&dest, stuff->dstWid, client, DixReadAccess);
 	if (rc != Success)
 	    return rc;
     }
+
+    /* Post through the XTest device */
+    dev = PickPointer(client);
+    dev = GetXTestDevice(dev);
+    pSprite = dev->spriteInfo->sprite;
     x = pSprite->hotPhys.x;
     y = pSprite->hotPhys.y;
 
@@ -3436,9 +3441,9 @@ XineramaWarpPointer(ClientPtr client)
     else if (y >= pSprite->physLimits.y2)
 	y = pSprite->physLimits.y2 - 1;
     if (pSprite->hotShape)
-	ConfineToShape(PickPointer(client), pSprite->hotShape, &x, &y);
+	ConfineToShape(dev, pSprite->hotShape, &x, &y);
 
-    XineramaSetCursorPosition(PickPointer(client), x, y, TRUE);
+    XineramaSetCursorPosition(dev, x, y, TRUE);
 
     return Success;
 }
@@ -3456,7 +3461,7 @@ ProcWarpPointer(ClientPtr client)
     WindowPtr	dest = NULL;
     int		x, y, rc;
     ScreenPtr	newScreen;
-    DeviceIntPtr dev, tmp;
+    DeviceIntPtr dev, tmp, xtest_dev = NULL;
     SpritePtr   pSprite;
 
     REQUEST(xWarpPointerReq);
@@ -3469,11 +3474,13 @@ ProcWarpPointer(ClientPtr client)
 	    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixWriteAccess);
 	    if (rc != Success)
 		return rc;
+            if (IsXTestDevice(tmp, dev))
+                xtest_dev = tmp;
 	}
     }
 
-    if (dev->lastSlave)
-        dev = dev->lastSlave;
+    /* Use the XTest device to actually move the pointer */
+    dev = xtest_dev;
     pSprite = dev->spriteInfo->sprite;
 
 #ifdef PANORAMIX
commit b29ce0726d55ec41cfbce0814e21b0217ef64efe
Author: Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
Date:   Tue Aug 9 11:00:34 2011 +0900

    Disable check of double-aligned in test/input.c on Renesas SH
    
    Renesas SH is not aligned at size of double.
    When structure has double value, It is aligned in 4byte (long).
    
    Signed-off-by: Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/test/input.c b/test/input.c
index c2b0eb0..5d4cbf6 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1223,7 +1223,7 @@ static void dix_valuator_alloc(void)
 
         assert(v);
         assert(v->numAxes == num_axes);
-#ifndef __i386__
+#if !defined(__i386__) && !defined(__sh__)
         /* must be double-aligned on 64 bit */
         assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
         assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
commit 3be379f5076566edaf92c27df5a4d447bcf5d015
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Aug 11 10:59:07 2011 +1000

    dix: use helper functions in EventIsDeliverable
    
    Proximity events don't have an XI2 type and caused error messages in the
    log when trying to get the event filter. Use this opportunity to
    clean up the code, instead of manually setting the fields that
    GetEventFilter requires use EventTo(XI2|XI|Core) instead.
    
    Co-Authored-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/events.c b/dix/events.c
index 0e22fdc..27c3172 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2503,44 +2503,45 @@ EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
     int filter = 0;
     int type;
     OtherInputMasks *inputMasks = wOtherInputMasks(win);
-    xEvent ev;
-
-    /* XXX: this makes me gag */
-    type = GetXI2Type(event);
-    ev.u.u.type = GenericEvent; /* GetEventFilter only cares about type and evtype*/
-    ((xGenericEvent*)&ev)->extension = IReqCode;
-    ((xGenericEvent*)&ev)->evtype = type;
-    filter = GetEventFilter(dev, &ev);
-    if (type && inputMasks &&
-        ((inputMasks->xi2mask[XIAllDevices][type/8] & filter) ||
-         ((inputMasks->xi2mask[XIAllMasterDevices][type/8] & filter) && IsMaster(dev)) ||
-         (inputMasks->xi2mask[dev->id][type/8] & filter)))
-        rc |= EVENT_XI2_MASK;
-
-    type = GetXIType(event);
-    ev.u.u.type = type;
-    filter = GetEventFilter(dev, &ev);
-
-    /* Check for XI mask */
-    if (type && inputMasks &&
-        (inputMasks->deliverableEvents[dev->id] & filter) &&
-        (inputMasks->inputEvents[dev->id] & filter))
-        rc |= EVENT_XI1_MASK;
-
-    /* Check for XI DontPropagate mask */
-    if (type && inputMasks &&
-        (inputMasks->dontPropagateMask[dev->id] & filter))
-        rc |= EVENT_DONT_PROPAGATE_MASK;
-
-    /* Check for core mask */
-    type = GetCoreType(event);
-    if (type && (win->deliverableEvents & filter) &&
-        ((wOtherEventMasks(win) | win->eventMask) & filter))
-        rc |= EVENT_CORE_MASK;
-
-    /* Check for core DontPropagate mask */
-    if (type && (filter & wDontPropagateMask(win)))
-        rc |= EVENT_DONT_PROPAGATE_MASK;
+
+    if ((type = GetXI2Type(event)) != 0)
+    {
+        filter = GetXI2EventFilterMask(type);
+
+        if (inputMasks &&
+            (GetXI2MaskByte(inputMasks->xi2mask,  dev, type) & filter))
+            rc |= EVENT_XI2_MASK;
+    }
+
+    if ((type = GetXIType(event)) != 0)
+    {
+        filter = GetEventFilterMask(dev, type);
+
+        /* Check for XI mask */
+        if (inputMasks &&
+            (inputMasks->deliverableEvents[dev->id] & filter) &&
+            (inputMasks->inputEvents[dev->id] & filter))
+            rc |= EVENT_XI1_MASK;
+
+        /* Check for XI DontPropagate mask */
+        if (inputMasks && (inputMasks->dontPropagateMask[dev->id] & filter))
+            rc |= EVENT_DONT_PROPAGATE_MASK;
+
+    }
+
+    if ((type = GetCoreType(event)) != 0)
+    {
+        filter = GetEventFilterMask(dev, type);
+
+        /* Check for core mask */
+        if ((win->deliverableEvents & filter) &&
+            ((wOtherEventMasks(win) | win->eventMask) & filter))
+            rc |= EVENT_CORE_MASK;
+
+        /* Check for core DontPropagate mask */
+        if (filter & wDontPropagateMask(win))
+            rc |= EVENT_DONT_PROPAGATE_MASK;
+    }
 
     return rc;
 }
commit 799879797505a5e891ccaec2bea73fd838c94b7a
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Aug 11 10:57:05 2011 +1000

    dix: abstract XI2 filter mask lookup
    
    Don't access the xi2mask bytes directly or calculate the offsets manually,
    use a few helper functions instead. XI2 masks are a bit weird in the event
    handling code since they slot onto the legacy code. For core/XI 1.x events,
    the event mask is a CARD32. That mask is used together with the event filter
    (also 32 bit) to determine if event delivery should be attempted.
    XI2 masks are of arbitrary size and their mask is simply the byte of the
    mask that contains the event mask. Likewise, the filter is a single byte
    matching that mask. Provide helper functions get these bytes and masks in
    the right order instead of accessing them manually.
    
    EventIsDeliverable should be part of this cleanup patch but it will be
    gutted with the next patch.
    
    Co-Authored-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/events.c b/dix/events.c
index 8e07532..0e22fdc 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -408,6 +408,24 @@ static const Mask default_filter[128] =
 	CantBeFiltered		       /* MappingNotify */
 };
 
+static inline Mask
+GetEventFilterMask(DeviceIntPtr dev, int evtype)
+{
+    return filters[dev ? dev->id : 0][evtype];
+}
+
+static inline Mask
+GetXI2EventFilterMask(int evtype)
+{
+    return (1 << (evtype % 8));
+}
+
+static inline int
+GetXI2EventFilterOffset(int evtype)
+{
+    return (evtype / 8);
+}
+
 /**
  * For the given event, return the matching event filter. This filter may then
  * be AND'ed with the selected event mask.
@@ -429,14 +447,28 @@ GetEventFilter(DeviceIntPtr dev, xEvent *event)
     int evtype = 0;
 
     if (event->u.u.type != GenericEvent)
-        return filters[dev ? dev->id : 0][event->u.u.type];
+        return GetEventFilterMask(dev, event->u.u.type);
     else if ((evtype = xi2_get_type(event)))
-        return (1 << (evtype % 8));
+        return GetXI2EventFilterMask(evtype);
     ErrorF("[dix] Unknown event type %d. No filter\n", event->u.u.type);
     return 0;
 }
 
 /**
+ * Return the single byte of the device's XI2 mask that contains the mask
+ * for the event_type.
+ */
+static int
+GetXI2MaskByte(unsigned char xi2mask[][XI2MASKSIZE], DeviceIntPtr dev, int event_type)
+{
+    int byte = GetXI2EventFilterOffset(event_type);
+    return xi2mask[dev->id][byte] |
+           xi2mask[XIAllDevices][byte] |
+           (IsMaster(dev) ? xi2mask[XIAllMasterDevices][byte] : 0);
+}
+
+
+/**
  * Return the windows complete XI2 mask for the given XI2 event type.
  */
 Mask
@@ -452,9 +484,7 @@ GetWindowXI2Mask(DeviceIntPtr dev, WindowPtr win, xEvent* ev)
     evtype = ((xGenericEvent*)ev)->evtype;
     filter = GetEventFilter(dev, ev);
 
-    return ((inputMasks->xi2mask[dev->id][evtype/8] & filter) ||
-            inputMasks->xi2mask[XIAllDevices][evtype/8] ||
-            (inputMasks->xi2mask[XIAllMasterDevices][evtype/8] && IsMaster(dev)));
+    return (GetXI2MaskByte(inputMasks->xi2mask, dev, evtype) & filter);
 }
 
 Mask
@@ -465,10 +495,7 @@ GetEventMask(DeviceIntPtr dev, xEvent *event, InputClients* other)
     /* XI2 filters are only ever 8 bit, so let's return a 8 bit mask */
     if ((evtype = xi2_get_type(event)))
     {
-        int byte = evtype / 8;
-        return (other->xi2mask[dev->id][byte] |
-                other->xi2mask[XIAllDevices][byte] |
-                (IsMaster(dev)? other->xi2mask[XIAllMasterDevices][byte] : 0));
+        return GetXI2MaskByte(other->xi2mask, dev, evtype);
     } else if (core_get_type(event) != 0)
         return other->mask[XIAllDevices];
     else
@@ -4061,9 +4088,7 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
             if (rc == Success)
             {
                 int evtype = xi2_get_type(xi2);
-                mask = grab->xi2mask[XIAllDevices][evtype/8] |
-                    grab->xi2mask[XIAllMasterDevices][evtype/8] |
-                    grab->xi2mask[thisDev->id][evtype/8];
+                mask = GetXI2MaskByte(grab->xi2mask, thisDev, evtype);
                 /* try XI2 event */
                 FixUpEventFromWindow(pSprite, xi2, grab->window, None, TRUE);
                 /* XXX: XACE */
@@ -4542,9 +4567,7 @@ DeviceEnterLeaveEvent(
     if (grab)
     {
         Mask mask;
-        mask = grab->xi2mask[XIAllDevices][type/8] |
-               grab->xi2mask[XIAllMasterDevices][type/8] |
-               grab->xi2mask[mouse->id][type/8];
+        mask = GetXI2MaskByte(grab->xi2mask, mouse, type);
         TryClientEvents(rClient(grab), mouse, (xEvent*)event, 1, mask,
                         filter, grab);
     } else {
commit 8c5a4d6fbecf79f2dc4f2d836d741203b2d5e856
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 1 14:12:41 2011 +1000

    dix: don't use the pointer as modifier device in UngrabKey.
    
    Modifier device is always the keyboard.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 8419064..8e07532 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5356,7 +5356,7 @@ ProcUngrabKey(ClientPtr client)
     tempGrab.window = pWin;
     tempGrab.modifiersDetail.exact = stuff->modifiers;
     tempGrab.modifiersDetail.pMask = NULL;
-    tempGrab.modifierDevice = GetPairedDevice(keybd);
+    tempGrab.modifierDevice = keybd;
     tempGrab.type = KeyPress;
     tempGrab.grabtype = GRABTYPE_CORE;
     tempGrab.detail.exact = stuff->key;
commit 3a077f246e9ac07a37c1b01c3d321e0f5ceb4153
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Aug 3 15:07:23 2011 +1000

    input: provide a single function to init DeviceEvents to 0
    
    getevents.c already had that function, but XKB was manually initializing it,
    causing bugs when the event structure was updated in one place but not the
    other.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index f7f4617..be2840c 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -154,17 +154,6 @@ key_autorepeats(DeviceIntPtr pDev, int key_code)
 }
 
 static void
-init_event(DeviceIntPtr dev, DeviceEvent* event, Time ms)
-{
-    memset(event, 0, sizeof(DeviceEvent));
-    event->header = ET_Internal;
-    event->length = sizeof(DeviceEvent);
-    event->time = ms;
-    event->deviceid = dev->id;
-    event->sourceid = dev->id;
-}
-
-static void
 init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail)
 {
     memset(event, 0, sizeof(RawDeviceEvent));
@@ -1006,7 +995,7 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     set_raw_valuators(raw, &mask, raw->valuators.data);
 
     event = &events->device_event;
-    init_event(pDev, event, ms);
+    init_device_event(event, pDev, ms);
     event->detail.key = key_code;
 
     if (type == KeyPress) {
@@ -1228,7 +1217,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     clipValuators(pDev, &mask);
 
     event = &events->device_event;
-    init_event(pDev, event, ms);
+    init_device_event(event, pDev, ms);
 
     if (type == MotionNotify) {
         event->type = ET_Motion;
@@ -1321,7 +1310,7 @@ GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type, const Val
     events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events);
 
     event = &events->device_event;
-    init_event(pDev, event, GetTimeInMillis());
+    init_device_event(event, pDev, GetTimeInMillis());
     event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut;
 
     clipValuators(pDev, &mask);
@@ -1357,7 +1346,7 @@ PostSyntheticMotion(DeviceIntPtr pDev,
 #endif
 
     memset(&ev, 0, sizeof(DeviceEvent));
-    init_event(pDev, &ev, time);
+    init_device_event(&ev, pDev, time);
     ev.root_x = x;
     ev.root_y = y;
     ev.type = ET_Motion;
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 49e1758..9632076 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -584,3 +584,17 @@ void verify_internal_event(const InternalEvent *ev)
         FatalError("Wrong event type %d. Aborting server\n", ev->any.header);
     }
 }
+
+/**
+ * Initializes the given event to zero (or default values), for the given
+ * device.
+ */
+void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms)
+{
+    memset(event, 0, sizeof(DeviceEvent));
+    event->header = ET_Internal;
+    event->length = sizeof(DeviceEvent);
+    event->time = ms;
+    event->deviceid = dev->id;
+    event->sourceid = dev->id;
+}
diff --git a/include/inpututils.h b/include/inpututils.h
index 92a7543..63e1a26 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -38,5 +38,6 @@ struct _ValuatorMask {
 };
 
 extern void verify_internal_event(const InternalEvent *ev);
+extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
 
 #endif
diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 12fe2a1..4115ff2 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -124,15 +124,11 @@ AccessXKeyboardEvent(DeviceIntPtr	keybd,
 				 Bool		isRepeat)
 {
     DeviceEvent event;
-    memset(&event, 0, sizeof(DeviceEvent));
-    event.header = ET_Internal;
+
+    init_device_event(&event, keybd, GetTimeInMillis());
     event.type = type;
     event.detail.key = keyCode;
-    event.time = GetTimeInMillis();
-    event.length = sizeof(DeviceEvent);
     event.key_repeat = isRepeat;
-    event.sourceid = keybd->id;
-    event.deviceid = keybd->id;
 
     if (xkbDebugFlags&0x8) {
 	DebugF("[xkb] AXKE: Key %d %s\n", keyCode,
commit 4b376ddeb4f3c9d9d279ffd2946d88edd5af4cfc
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 1 14:20:53 2011 +1000

    dix: fix compiler warnings ("foo" set but not used)
    
    devices.c: In function 'AttachDevice':
    devices.c:2409:18: warning: variable 'oldmaster' set but not used
    [-Wunused-but-set-variable]
    
    events.c: In function 'ConfineToShape':
    events.c:683:15: warning: variable 'pSprite' set but not used
    [-Wunused-but-set-variable]
    
    events.c: In function 'ProcGrabPointer':
    events.c:4759:15: warning: variable 'time' set but not used
    [-Wunused-but-set-variable]
    
    getevents.c: In function 'GetMotionHistory':
    getevents.c:425:9: warning: variable 'dflt' set but not used
    [-Wunused-but-set-variable]
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/devices.c b/dix/devices.c
index 334f5d3..ab8a648 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2406,7 +2406,6 @@ int
 AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master)
 {
     ScreenPtr screen;
-    DeviceIntPtr oldmaster;
     if (!dev || IsMaster(dev))
         return BadDevice;
 
@@ -2425,7 +2424,6 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master)
         free(dev->spriteInfo->sprite);
     }
 
-    oldmaster = GetMaster(dev, MASTER_ATTACHED);
     dev->master = master;
 
     /* If device is set to floating, we need to create a sprite for it,
diff --git a/dix/events.c b/dix/events.c
index 25ff899..8419064 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -680,9 +680,7 @@ ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py)
     BoxRec box;
     int x = *px, y = *py;
     int incx = 1, incy = 1;
-    SpritePtr pSprite;
 
-    pSprite = pDev->spriteInfo->sprite;
     if (RegionContainsPoint(shape, x, y, &box))
 	return;
     box = *RegionExtents(shape);
@@ -4765,7 +4763,6 @@ ProcGrabPointer(ClientPtr client)
     WindowPtr confineTo;
     CursorPtr oldCursor;
     REQUEST(xGrabPointerReq);
-    TimeStamp time;
     int rc;
 
     REQUEST_SIZE_MATCH(xGrabPointerReq);
@@ -4811,7 +4808,6 @@ ProcGrabPointer(ClientPtr client)
     if (oldCursor && rep.status == GrabSuccess)
         FreeCursor (oldCursor, (Cursor)0);
 
-    time = ClientTimeToServerTime(stuff->time);
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
     rep.length = 0;
diff --git a/dix/getevents.c b/dix/getevents.c
index a12462a..f7f4617 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -414,7 +414,6 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
     Time current;
     /* The size of a single motion event. */
     int size;
-    int dflt;
     AxisInfo from, *to; /* for scaling */
     INT32 *ocbuf, *icbuf; /* pointer to coordinates for copying */
     INT16 *corebuf;
@@ -502,13 +501,6 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
                     else if (j == 1 && (from.max_value < from.min_value))
                         from.max_value = pScreen->height;
 
-                    if (j == 0 && (to->max_value < to->min_value))
-                        dflt = pScreen->width;
-                    else if (j == 1 && (to->max_value < to->min_value))
-                        dflt = pScreen->height;
-                    else
-                        dflt = 0;
-
                     /* scale from stored range into current range */
                     coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, 0);
                     memcpy(ocbuf, &coord, sizeof(INT32));
commit 6fd2adc179141310e45a56ee90ef5b5f6115a1f6
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 1 14:27:54 2011 +1000

    mi: fix compiler warnings ("foo" set but not used)
    
    misprite.c: In function 'miSpriteSaveUnderCursor':
    misprite.c:940:12: warning: variable 'y' set but not used
    [-Wunused-but-set-variable]
    misprite.c:940:9: warning: variable 'x' set but not used
    [-Wunused-but-set-variable]
    
    mivaltree.c: In function 'miComputeClips':
    mivaltree.c:226:10: warning: variable 'resized' set but not used
    [-Wunused-but-set-variable]
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/mi/misprite.c b/mi/misprite.c
index 1cfcdf6..1025c5a 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -937,8 +937,6 @@ static void
 miSpriteSaveUnderCursor(DeviceIntPtr pDev, ScreenPtr pScreen)
 {
     miSpriteScreenPtr   pScreenPriv;
-    int			x, y;
-    CursorPtr		pCursor;
     miCursorInfoPtr     pCursorInfo;
 
     if (IsFloating(pDev))
@@ -949,10 +947,7 @@ miSpriteSaveUnderCursor(DeviceIntPtr pDev, ScreenPtr pScreen)
     pCursorInfo = MISPRITE(pDev);
 
     miSpriteComputeSaved (pDev, pScreen);
-    pCursor = pCursorInfo->pCursor;
 
-    x = pCursorInfo->x - (int)pCursor->bits->xhot;
-    y = pCursorInfo->y - (int)pCursor->bits->yhot;
     miSpriteDisableDamage(pScreen, pScreenPriv);
 
     miDCSaveUnderCursor(pDev,
diff --git a/mi/mivaltree.c b/mi/mivaltree.c
index 0e00c2f..e1d47c0 100644
--- a/mi/mivaltree.c
+++ b/mi/mivaltree.c
@@ -223,7 +223,6 @@ miComputeClips (
     RegionRec		childUnion;
     Bool		overlap;
     RegionPtr		borderVisible;
-    Bool		resized;
     /*
      * Figure out the new visibility of this window.
      * The extent of the universe should be the same as the extent of
@@ -378,7 +377,6 @@ miComputeClips (
     }
 
     borderVisible = pParent->valdata->before.borderVisible;
-    resized = pParent->valdata->before.resized;
     RegionNull(&pParent->valdata->after.borderExposed);
     RegionNull(&pParent->valdata->after.exposed);
 
commit 484cef5b29ef82402a15e155b3b8505b1e4a6830
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Aug 2 09:21:00 2011 +1000

    Xi: silence compiler warnings (set but not used)
    
    exevents.c: In function 'UpdateDeviceState':
    exevents.c:719:9: warning: variable 'bit' set but not used
    [-Wunused-but-set-variable]
    
    exevents.c: In function 'ProcessOtherEvent':
    exevents.c:889:22: warning: variable 'v' set but not used
    [-Wunused-but-set-variable]
    exevents.c:888:17: warning: variable 'k' set but not used
    [-Wunused-but-set-variable]
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 3e3c67b..38089a2 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -716,7 +716,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
 {
     int i;
     int key = 0,
-        bit = 0,
         last_valuator;
 
     KeyClassPtr k       = NULL;
@@ -750,7 +749,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
     b = device->button;
 
     key = event->detail.key;
-    bit = 1 << (key & 7);
 
     /* Update device axis */
     /* Check valuators first */
@@ -888,8 +886,6 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
     Bool deactivateDeviceGrab = FALSE;
     int key = 0, rootX, rootY;
     ButtonClassPtr b;
-    KeyClassPtr k;
-    ValuatorClassPtr v;
     int ret = 0;
     int state, i;
     DeviceIntPtr mouse = NULL, kbd = NULL;
@@ -953,9 +949,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
     if (ret == DONT_PROCESS)
         return;
 
-    v = device->valuator;
     b = device->button;
-    k = device->key;
 
     if (IsMaster(device) || IsFloating(device))
         CheckMotion(event, device);
commit 98fe735ea1d756711019c3d90ed6abd9c06abebf
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 1 13:52:13 2011 +1000

    dix: add KEYBOARD_OR_FLOAT and POINTER_OR_FLOAT to GetMaster()
    
    GetMaster() currently requires an attached slave device as parameter,
    resuling in many calls being IsFloating(dev) ? dev : GetMaster(...);
    
    Add two new parameters so GetMaster can be called unconditionally to get the
    right device.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/devices.c b/dix/devices.c
index 0ccf252..334f5d3 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2484,16 +2484,22 @@ GetPairedDevice(DeviceIntPtr dev)
 
 
 /**
- * Returns the right master for the type of event needed. If the event is a
- * keyboard event.
- * This function may be called with a master device as argument. If so, the
- * returned master is either the device itself or the paired master device.
- * If dev is a floating slave device, NULL is returned.
+ * Returns the requested master for this device.
+ * The return values are:
+ * - MASTER_ATTACHED: the master for this device or NULL for a floating
+ *   slave.
+ * - MASTER_KEYBOARD: the master keyboard for this device or NULL for a
+ *   floating slave
+ * - MASTER_POINTER: the master keyboard for this device or NULL for a
+ *   floating slave
+ * - POINTER_OR_FLOAT: the master pointer for this device or the device for
+ *   a floating slave
+ * - KEYBOARD_OR_FLOAT: the master keyboard for this device or the device for
+ *   a floating slave
  *
- * @type ::MASTER_KEYBOARD or ::MASTER_POINTER or ::MASTER_ATTACHED
- * @return The requested master device. In the case of MASTER_ATTACHED, this
- * is the directly attached master to this device, regardless of the type.
- * Otherwise, it is either the master keyboard or pointer for this device.
+ * @param which ::MASTER_KEYBOARD or ::MASTER_POINTER, ::MASTER_ATTACHED,
+ * ::POINTER_OR_FLOAT or ::KEYBOARD_OR_FLOAT.
+ * @return The requested master device
  */
 DeviceIntPtr
 GetMaster(DeviceIntPtr dev, int which)
@@ -2502,12 +2508,15 @@ GetMaster(DeviceIntPtr dev, int which)
 
     if (IsMaster(dev))
         master = dev;
-    else
+    else {
         master = dev->master;
+        if (!master && (which == POINTER_OR_FLOAT || which == KEYBOARD_OR_FLOAT))
+            return dev;
+    }
 
     if (master && which != MASTER_ATTACHED)
     {
-        if (which == MASTER_KEYBOARD)
+        if (which == MASTER_KEYBOARD || which == KEYBOARD_OR_FLOAT)
         {
             if (master->type != MASTER_KEYBOARD)
                 master = GetPairedDevice(master);
diff --git a/include/inputstr.h b/include/inputstr.h
index 00f72c2..838f9f0 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -472,7 +472,10 @@ typedef struct _SpriteInfoRec {
 #define MASTER_POINTER          1
 #define MASTER_KEYBOARD         2
 #define SLAVE                   3
-#define MASTER_ATTACHED         4  /* special type for GetMaster */
+/* special types for GetMaster */
+#define MASTER_ATTACHED         4       /* Master for this device */
+#define KEYBOARD_OR_FLOAT       5       /* Keyboard master for this device or this device if floating */
+#define POINTER_OR_FLOAT        6       /* Pointer master for this device or this device if floating */
 
 typedef struct _DeviceIntRec {
     DeviceRec	public;
diff --git a/test/input.c b/test/input.c
index 31597f9..c2b0eb0 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1292,6 +1292,19 @@ static void dix_get_master(void)
     assert(GetMaster(&floating, MASTER_POINTER) == NULL);
     assert(GetMaster(&floating, MASTER_KEYBOARD) == NULL);
     assert(GetMaster(&floating, MASTER_ATTACHED) == NULL);
+
+    assert(GetMaster(&vcp, POINTER_OR_FLOAT) == &vcp);
+    assert(GetMaster(&vck, POINTER_OR_FLOAT) == &vcp);
+    assert(GetMaster(&ptr, POINTER_OR_FLOAT) == &vcp);
+    assert(GetMaster(&kbd, POINTER_OR_FLOAT) == &vcp);
+
+    assert(GetMaster(&vcp, KEYBOARD_OR_FLOAT) == &vck);
+    assert(GetMaster(&vck, KEYBOARD_OR_FLOAT) == &vck);
+    assert(GetMaster(&ptr, KEYBOARD_OR_FLOAT) == &vck);
+    assert(GetMaster(&kbd, KEYBOARD_OR_FLOAT) == &vck);
+
+    assert(GetMaster(&floating, KEYBOARD_OR_FLOAT) == &floating);
+    assert(GetMaster(&floating, POINTER_OR_FLOAT) == &floating);
 }
 
 
commit dbbe5735d1451bb32f43bce90f0bcfeff46f9743
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Aug 2 08:54:00 2011 +1000

    test: add a test for GetMaster() behaviour
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/test/input.c b/test/input.c
index 837ce49..31597f9 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1234,6 +1234,67 @@ static void dix_valuator_alloc(void)
     free(v);
 }
 
+static void dix_get_master(void)
+{
+    DeviceIntRec vcp, vck;
+    DeviceIntRec ptr, kbd;
+    DeviceIntRec floating;
+    SpriteInfoRec vcp_sprite, vck_sprite;
+    SpriteInfoRec ptr_sprite, kbd_sprite;
+    SpriteInfoRec floating_sprite;
+
+    memset(&vcp, 0, sizeof(DeviceIntRec));
+    memset(&vck, 0, sizeof(DeviceIntRec));
+    memset(&ptr, 0, sizeof(DeviceIntRec));
+    memset(&kbd, 0, sizeof(DeviceIntRec));
+    memset(&floating, 0, sizeof(DeviceIntRec));
+
+    memset(&vcp_sprite, 0, sizeof(DeviceIntRec));
+    memset(&vck_sprite, 0, sizeof(DeviceIntRec));
+    memset(&ptr_sprite, 0, sizeof(DeviceIntRec));
+    memset(&kbd_sprite, 0, sizeof(DeviceIntRec));
+    memset(&floating_sprite, 0, sizeof(DeviceIntRec));
+
+    vcp.type = MASTER_POINTER;
+    vck.type = MASTER_KEYBOARD;
+    ptr.type = SLAVE;
+    kbd.type = SLAVE;
+    floating.type = SLAVE;
+
+    vcp.spriteInfo = &vcp_sprite;
+    vck.spriteInfo = &vck_sprite;
+    ptr.spriteInfo = &ptr_sprite;
+    kbd.spriteInfo = &kbd_sprite;
+    floating.spriteInfo = &floating_sprite;
+
+    vcp_sprite.paired = &vck;
+    vck_sprite.paired = &vcp;
+    ptr_sprite.paired = &vcp;
+    kbd_sprite.paired = &vck;
+    floating_sprite.paired = &floating;
+
+    vcp_sprite.spriteOwner = TRUE;
+    floating_sprite.spriteOwner = TRUE;
+
+    ptr.master = &vcp;
+    kbd.master = &vck;
+
+    assert(GetPairedDevice(&vcp) == &vck);
+    assert(GetPairedDevice(&vck) == &vcp);
+    assert(GetMaster(&ptr, MASTER_POINTER) == &vcp);
+    assert(GetMaster(&ptr, MASTER_KEYBOARD) == &vck);
+    assert(GetMaster(&kbd, MASTER_POINTER) == &vcp);
+    assert(GetMaster(&kbd, MASTER_KEYBOARD) == &vck);
+    assert(GetMaster(&ptr, MASTER_ATTACHED) == &vcp);
+    assert(GetMaster(&kbd, MASTER_ATTACHED) == &vck);
+
+    assert(GetPairedDevice(&floating) == &floating);
+    assert(GetMaster(&floating, MASTER_POINTER) == NULL);
+    assert(GetMaster(&floating, MASTER_KEYBOARD) == NULL);
+    assert(GetMaster(&floating, MASTER_ATTACHED) == NULL);
+}
+
+
 int main(int argc, char** argv)
 {
     dix_input_valuator_masks();
@@ -1249,6 +1310,7 @@ int main(int argc, char** argv)
     include_bit_test_macros();
     xi_unregister_handlers();
     dix_valuator_alloc();
+    dix_get_master();
 
     return 0;
 }
commit b3c76b0c53ac42b70d12849da18465e8467e474c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 1 11:54:17 2011 +1000

    mi: fix comment typo, whitespace in miPointerSetPosition
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/mi/mipointer.c b/mi/mipointer.c
index 7680ca1..670f63b 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -569,9 +569,9 @@ miPointerMoveNoEvent (DeviceIntPtr pDev, ScreenPtr pScreen,
  *
  * @param pDev The device to move
  * @param mode Movement mode (Absolute or Relative)
- * @param[in,out] x The x coordiante in screen coordinates (in regards to total
+ * @param[in,out] x The x coordinate in screen coordinates (in regards to total
  * desktop size)
- * @param[in,out] y The y coordiante in screen coordinates (in regards to total
+ * @param[in,out] y The y coordinate in screen coordinates (in regards to total
  * desktop size)
  */
 void
@@ -603,7 +603,7 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, int *x, int *y)
 		pScreen = newScreen;
 		(*pScreenPriv->screenFuncs->NewEventScreen) (pDev, pScreen,
 							     FALSE);
-	    	/* Smash the confine to the new screen */
+		/* Smash the confine to the new screen */
                 pPointer->limits.x2 = pScreen->width;
                 pPointer->limits.y2 = pScreen->height;
 	    }
@@ -622,8 +622,8 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, int *x, int *y)
     if (pScreen->ConstrainCursorHarder)
        pScreen->ConstrainCursorHarder(pDev, pScreen, mode, x, y);
 
-    if (pPointer->x == *x && pPointer->y == *y && 
-            pPointer->pScreen == pScreen) 
+    if (pPointer->x == *x && pPointer->y == *y &&
+            pPointer->pScreen == pScreen)
         return;
 
     miPointerMoveNoEvent(pDev, pScreen, *x, *y);
commit c9562bed0d5e26b7e3e55e26cf1ddc5086d61cc6
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 1 09:52:38 2011 +1000

    dix: rename mieqSwitchScreen argument fromDix → set_dequeue_screen, document
    
    fromDIX is neither exactly true nor particularly helpful in understanding
    what this parameter triggers. Rename to set_dequeue_screen, because that's
    exactly what happens.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/mi/mi.h b/mi/mi.h
index c186940..24d1af9 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -206,7 +206,7 @@ extern _X_EXPORT void mieqEnqueue(
 extern _X_EXPORT void mieqSwitchScreen(
     DeviceIntPtr /* pDev */,
     ScreenPtr /*pScreen*/,
-    Bool /*fromDIX*/
+    Bool /*set_dequeue_screen*/
 );
 
 extern _X_EXPORT void mieqProcessDeviceEvent(
diff --git a/mi/mieq.c b/mi/mieq.c
index fc3738a..b75bde9 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -209,14 +209,29 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
 #endif
 }
 
+/**
+ * Changes the screen reference events are being enqueued from.
+ * Input events are enqueued with a screen reference and dequeued and
+ * processed with a (potentially different) screen reference.
+ * This function is called whenever a new event has changed screen but is
+ * still logically on the previous screen as seen by the client.
+ * This usually happens whenever the visible cursor moves across screen
+ * boundaries during event generation, before the same event is processed
+ * and sent down the wire.
+ *
+ * @param pDev The device that triggered a screen change.
+ * @param pScreen The new screen events are being enqueued for.
+ * @param set_dequeue_screen If TRUE, pScreen is set as both enqueue screen
+ * and dequeue screen.
+ */
 void
-mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX)
+mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool set_dequeue_screen)
 {
 #ifdef XQUARTZ
     pthread_mutex_lock(&miEventQueueMutex);
 #endif
     EnqueueScreen(pDev) = pScreen;
-    if (fromDIX)
+    if (set_dequeue_screen)
         DequeueScreen(pDev) = pScreen;
 #ifdef XQUARTZ
     pthread_mutex_unlock(&miEventQueueMutex);
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 539096e..c4265f9 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -87,7 +87,7 @@ typedef struct _miPointerScreenFuncRec {
     void	(*NewEventScreen)(
 		    DeviceIntPtr /* pDev */,
                     ScreenPtr /* pScr */,
-		    Bool /* fromDIX */
+		    Bool /* set_dequeue_screen */
                     );
 } miPointerScreenFuncRec, *miPointerScreenFuncPtr;
 
commit 09496996accfdaf7bc01097a25db400912004d97
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jul 28 15:56:08 2011 +1000

    dix: ignore devices when adding passive core grabs to list (#39545)
    
    Passive core grabs are mostly device-independent. In an MPX scenario, they
    may change to reflect whichever master pair activated the grab last. For
    adding new grabs to the list, ignore the device for core grabs to return
    failures when trying to set the same grab combo twice on a window.
    
    X.Org Bug 39545 <http://bugs.freedesktop.org/show_bug.cgi?id=39545>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/grabs.c b/dix/grabs.c
index 85ca9ee..c28356d 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -479,7 +479,7 @@ AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab)
 
     for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next)
     {
-	if (GrabMatchesSecond(pGrab, grab, FALSE))
+	if (GrabMatchesSecond(pGrab, grab, (pGrab->grabtype == GRABTYPE_CORE)))
 	{
 	    if (CLIENT_BITS(pGrab->resource) != CLIENT_BITS(grab->resource))
 	    {
commit 80c37048539daa1d257d127d66502bde45c97c85
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jul 28 15:43:10 2011 +1000

    dix: avoid using the VCP as modifier device
    
    Core grabs may change device when they're activated to reflect the master
    they apply to. If the device is a keyboard, modifierDevice is erroneously
    set to the Virtual Core Pointer.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 8a4c6b9..25ff899 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3678,7 +3678,7 @@ CheckPassiveGrabsOnWindow(
             if (tempGrab.type < GenericEvent)
             {
                 grab->device = device;
-                grab->modifierDevice = GetPairedDevice(device);
+                grab->modifierDevice = GetMaster(device, MASTER_KEYBOARD);
             }
 
             for (other = inputInfo.devices; other; other = other->next)
commit 20a61845d3c93c337bf3331a6bac30cf66c2a293
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Aug 9 11:21:06 2011 +1000

    config: use add_option for '_source' too
    
    _source was being allocated manually, with all other options added to that
    list through add_option. Skip the manual part, allocate the first option
    _source with add_option too.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/config/dbus.c b/config/dbus.c
index 34e3caa..41eca99 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -80,15 +80,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
         MALFORMED_MESSAGE();
     }
 
-    options = calloc(sizeof(*options), 1);
-    if (!options) {
-        ErrorF("[config/dbus] couldn't allocate option\n");
-        return BadAlloc;
-    }
-
-    options->key = strdup("_source");
-    options->value = strdup("client/dbus");
-    if (!options->key || !options->value) {
+    if (!add_option(&options, "_source", "client/dbus")) {
         ErrorF("[config/dbus] couldn't allocate first key/value pair\n");
         ret = BadAlloc;
         goto unwind;
diff --git a/config/hal.c b/config/hal.c
index 297520a..0b2d7d0 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -205,15 +205,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         free(parent);
     }
 
-    options = calloc(sizeof(*options), 1);
-    if (!options){
-        LogMessage(X_ERROR, "config/hal: couldn't allocate space for input options!\n");
-        goto unwind;
-    }
-
-    options->key = strdup("_source");
-    options->value = strdup("server/hal");
-    if (!options->key || !options->value) {
+    if (!add_option(&options, "_source", "server/hal")) {
         LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n");
         goto unwind;
     }
diff --git a/config/udev.c b/config/udev.c
index b11c81d..1f431c1 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -93,13 +93,7 @@ device_added(struct udev_device *udev_device)
         return;
     }
 
-    options = calloc(sizeof(*options), 1);
-    if (!options)
-        return;
-
-    options->key = strdup("_source");
-    options->value = strdup("server/udev");
-    if (!options->key || !options->value)
+    if (!add_option(&options, "_source", "server/udev"))
         goto unwind;
 
     parent = udev_device_get_parent(udev_device);
commit d33652dad8838ab0a9175ca4613a3161ebc5676f
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Aug 9 11:20:31 2011 +1000

    config: return the new InputOption from add_option.
    
    Change add_option to return the new InputOption on success, or NULL
    failure. This way we can at least check for errors in callers.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/config/config-backends.h b/config/config-backends.h
index 0a2a22a..0d36d72 100644
--- a/config/config-backends.h
+++ b/config/config-backends.h
@@ -30,7 +30,7 @@
 
 void remove_devices(const char *backend, const char *config_info);
 BOOL device_is_duplicate(const char *config_info);
-void add_option(InputOption **options, const char *key, const char *value);
+InputOption* add_option(InputOption **options, const char *key, const char *value);
 
 #ifdef CONFIG_UDEV
 int config_udev_init(void);
diff --git a/config/config.c b/config/config.c
index d86f7c6..af8f4f9 100644
--- a/config/config.c
+++ b/config/config.c
@@ -122,18 +122,25 @@ device_is_duplicate(const char *config_info)
     return FALSE;
 }
 
-void
+/**
+ * Allocate a new option and append to the list.
+ *
+ * @return A pointer to the newly allocated InputOption struct.
+ */
+InputOption*
 add_option(InputOption **options, const char *key, const char *value)
 {
     if (!value || *value == '\0')
-        return;
+        return NULL;
 
     for (; *options; options = &(*options)->next)
         ;
     *options = calloc(sizeof(**options), 1);
     if (!*options) /* Yeesh. */
-        return;
+        return NULL;
     (*options)->key = strdup(key);
     (*options)->value = strdup(value);
     (*options)->next = NULL;
+
+    return *options;
 }
commit e684e816acb617b4dc66a68e2b0ba8f80399170a
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jul 20 16:21:28 2011 +1000

    config: fix a log message
    
    PRODUCT was taken from the parent, hence ppath.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/config/udev.c b/config/udev.c
index fc6ee5d..b11c81d 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -126,7 +126,7 @@ device_added(struct udev_device *udev_device)
                 == -1)
                 attrs.usb_id = NULL;
             else
-                LOG_PROPERTY(path, "PRODUCT", product);
+                LOG_PROPERTY(ppath, "PRODUCT", product);
         }
     }
     if (!name)
commit 1357cd725143c1a35e32f15df658de111b151692
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jul 8 16:13:45 2011 +1000

    Revert "Attempt to add the 'mouse' driver in more situations."
    
    This reverts commit 43d9edd31e31b33b9da4a50d8ab05004881c8d5a.
    
    This commit was introduced in the 1.2 cycle when hotplugging was less than
    ideal (i.e. it didn't exist). From the commit message:
    
        Always add a mouse driver instance configured to send core events, unless
        a core pointer already exists using either the mouse or void drivers.  This
        handles the laptop case where the config file only specifies, say,
        synaptics, which causes the touchpad to work but not the pointing stick.
        We don't double-instantiate the mouse driver to avoid the mouse moving twice
        as fast, and we skip this logic when the user asked for a void core pointer
        since that probably means they want to run with no pointer at all.
    
    To get this case above, a user would need to disable hotplugging _and_ have a
    xorg.conf that only references one device. This is possible, but not a use-case
    we should worry about too much now.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 8670e53..25755fd 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1134,7 +1134,6 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
     XF86ConfInputPtr confInput;
     XF86ConfInputRec defPtr, defKbd;
     MessageType from = X_DEFAULT;
-    int found = 0;
     const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse",
 				   "void", NULL };
 
@@ -1251,40 +1250,6 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	return FALSE;
     }
 
-    /*
-     * always synthesize a 'mouse' section configured to send core
-     * events, unless a 'void' section is found, in which case the user
-     * probably wants to run footless.
-     *
-     * If you're using an evdev keyboard and expect a default mouse
-     * section ... deal.
-     */
-    for (devs = servlayoutp->inputs; devs && *devs; devs++) {
-	const char **driver = mousedrivers;
-	while(*driver) {
-	    if (!strcmp((*devs)->driver, *driver)) {
-		found = 1;
-		break;
-	    }
-	    driver++;
-	}
-    }
-    if (!found && xf86Info.forceInputDevices) {
-	xf86Msg(X_INFO, "No default mouse found, adding one\n");
-	memset(&defPtr, 0, sizeof(defPtr));
-	defPtr.inp_identifier = strdup("<default pointer>");
-	defPtr.inp_driver = strdup("mouse");
-	confInput = &defPtr;
-	Pointer = xf86AllocateInput();
-	if (Pointer)
-	    foundPointer = configInput(Pointer, confInput, from);
-	if (foundPointer) {
-	    Pointer->options = xf86addNewOption(NULL,
-					       xnfstrdup("AlwaysCore"), "on");
-	    servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer);
-	}
-    }
-
     confInput = NULL;
 
     /* 1. Check for the -keyboard command line option. */
commit 159b03e13760920274b573a2bccdbf6a79f059e7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jul 18 21:19:23 2011 +0200

    config: add udev/systemd multi-seat support
    
    Add support for multi-seat-aware input device hotplugging. This
    implements the multi-seat scheme explained here:
    
    http://www.freedesktop.org/wiki/Software/systemd/multiseat
    
    This introduces a new X server switch "-seat" which allows configuration
    of the seat to enumerate hotplugging devices on. If specified the value
    of this parameter will also be exported as root window property
    Xorg_Seat.
    
    To properly support input hotplugging devices need to be tagged in udev
    according to the seat they are on. Untagged devices are assumed to be on
    the default seat "seat0". If no "-seat" parameter is passed only devices
    on "seat0" are used. This means that the new scheme is perfectly
    compatible with existing setups which have no tagged input devices.
    
    Note that the -seat switch takes a completely generic identifier, and
    that it has no effect on non-Linux systems. In fact, on other OSes a
    completely different identifier scheme for seats could be used but still
    be exposed with the Xorg_Seat and -seat.
    
    I tried to follow the coding style of the surrounding code blocks if
    there was any one could follow.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/config/udev.c b/config/udev.c
index e7383dc..fc6ee5d 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -35,6 +35,7 @@
 #include "hotplug.h"
 #include "config-backends.h"
 #include "os.h"
+#include "globals.h"
 
 #define UDEV_XKB_PROP_KEY "xkb"
 
@@ -65,6 +66,7 @@ device_added(struct udev_device *udev_device)
     struct udev_list_entry *set, *entry;
     struct udev_device *parent;
     int rc;
+    const char *dev_seat;
 
     path = udev_device_get_devnode(udev_device);
 
@@ -73,6 +75,16 @@ device_added(struct udev_device *udev_device)
     if (!path || !syspath)
         return;
 
+    dev_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
+    if (!dev_seat)
+        dev_seat = "seat0";
+
+    if (SeatId && strcmp(dev_seat, SeatId))
+        return;
+
+    if (!SeatId && strcmp(dev_seat, "seat0"))
+        return;
+
     if (!udev_device_get_property_value(udev_device, "ID_INPUT")) {
         LogMessageVerb(X_INFO, 10,
                        "config/udev: ignoring device %s without "
@@ -284,6 +296,9 @@ config_udev_init(void)
     udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", NULL);
     udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL); /* For Wacom serial devices */
 
+    if (SeatId && strcmp(SeatId, "seat0"))
+        udev_monitor_filter_add_match_tag(udev_monitor, SeatId);
+
     if (udev_monitor_enable_receiving(udev_monitor)) {
         ErrorF("config/udev: failed to bind the udev monitor\n");
         return 0;
@@ -296,6 +311,9 @@ config_udev_init(void)
     udev_enumerate_add_match_subsystem(enumerate, "input");
     udev_enumerate_add_match_subsystem(enumerate, "tty");
 
+    if (SeatId && strcmp(SeatId, "seat0"))
+        udev_enumerate_add_match_tag(enumerate, SeatId);
+
     udev_enumerate_scan_devices(enumerate);
     devices = udev_enumerate_get_list_entry(enumerate);
     udev_list_entry_foreach(device, devices) {
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 5ee68cd..89bc82a 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -80,6 +80,7 @@
 #include "xf86Bus.h"
 #include "xf86VGAarbiter.h"
 #include "globals.h"
+#include "xserver-properties.h"
 
 #ifdef DPMSExtension
 #include <X11/extensions/dpmsconst.h>
@@ -654,6 +655,24 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
       }
     }
 
+    if (SeatId) {
+        Atom SeatAtom;
+
+        SeatAtom = MakeAtom(SEAT_ATOM_NAME, sizeof(SEAT_ATOM_NAME) - 1, TRUE);
+
+        for (i = 0; i < xf86NumScreens; i++) {
+            int ret;
+
+            ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex,
+                                                 SeatAtom, XA_STRING, 8,
+                                                 strlen(SeatId)+1, SeatId );
+            if (ret != Success) {
+                xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING,
+                           "Failed to register seat property\n");
+            }
+        }
+    }
+
     /* If a screen uses depth 24, show what the pixmap format is */
     for (i = 0; i < xf86NumScreens; i++) {
 	if (xf86Screens[i]->depth == 24) {
diff --git a/include/globals.h b/include/globals.h
index 8b80a65..17bca82 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -21,7 +21,7 @@ extern _X_EXPORT int defaultColorVisualClass;
 
 extern _X_EXPORT int GrabInProgress;
 extern _X_EXPORT Bool noTestExtensions;
-
+extern _X_EXPORT char *SeatId;
 extern _X_EXPORT char *ConnectionInfo;
 
 #ifdef DPMSExtension
diff --git a/include/xserver-properties.h b/include/xserver-properties.h
index 2b1feab..bf50042 100644
--- a/include/xserver-properties.h
+++ b/include/xserver-properties.h
@@ -30,6 +30,9 @@
  * byte-ordering. */
 #define XATOM_FLOAT "FLOAT"
 
+/* STRING. Seat name of this display */
+#define SEAT_ATOM_NAME "Xorg_Seat"
+
 /* BOOL. 0 - device disabled, 1 - device enabled */
 #define XI_PROP_ENABLED      "Device Enabled"
 /* BOOL. If present, device is a virtual XTEST device */
diff --git a/man/Xserver.man b/man/Xserver.man
index f743912..1a36b09 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -220,6 +220,12 @@ sets screen-saver timeout time in minutes.
 .B \-su
 disables save under support on all screens.
 .TP 8
+.B \-seat \fIseat\fP
+seat to run on. Takes a string identifying a seat in a platform
+specific syntax. On platforms which support this feature this may be
+used to limit the server to expose only a specific subset of devices
+connected to the system.
+.TP 8
 .B \-t \fInumber\fP
 sets pointer acceleration threshold in pixels (i.e. after how many pixels
 pointer acceleration should take effect).
diff --git a/os/utils.c b/os/utils.c
index 36cb46f..e8ecb71 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -201,6 +201,8 @@ Bool PanoramiXExtensionDisabledHack = FALSE;
 
 int auditTrailLevel = 1;
 
+char *SeatId = NULL;
+
 #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
 #define HAS_SAVED_IDS_AND_SETEUID
 #endif
@@ -511,6 +513,7 @@ void UseMsg(void)
     ErrorF("-render [default|mono|gray|color] set render color alloc policy\n");
     ErrorF("-retro                 start with classic stipple and cursor\n");
     ErrorF("-s #                   screen-saver timeout (minutes)\n");
+    ErrorF("-seat string           seat to run on\n");
     ErrorF("-t #                   default pointer threshold (pixels/t)\n");
     ErrorF("-terminate             terminate at server reset\n");
     ErrorF("-to #                  connection time out\n");
@@ -802,6 +805,13 @@ ProcessCommandLine(int argc, char *argv[])
 	    else
 		UseMsg();
 	}
+	else if ( strcmp( argv[i], "-seat") == 0)
+	{
+	    if(++i < argc)
+		SeatId = argv[i];
+	    else
+		UseMsg();
+	}
 	else if ( strcmp( argv[i], "-t") == 0)
 	{
 	    if(++i < argc)
commit 95772598b57f6054fbf88683fa0a492c77605790
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jul 8 16:10:07 2011 +1000

    xfree86: use xf86AllocateInput for implicit devices too
    
    Slowly merging the vastly different code-paths.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 83eac8b..8670e53 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1089,7 +1089,7 @@ freeDevice(InputInfoPtr *list, InputInfoPtr pInfo)
 
 /**
  * Append pInfo to the null-terminated list, allocating space as necessary.
- * pInfo is copied into the last element.
+ * pInfo is used as the last element.
  */
 static InputInfoPtr*
 addDevice(InputInfoPtr *list, InputInfoPtr pInfo)
@@ -1103,8 +1103,7 @@ addDevice(InputInfoPtr *list, InputInfoPtr pInfo)
     list = xnfrealloc(list, (count + 1) * sizeof(InputInfoPtr));
     list[count] = NULL;
 
-    list[count - 1] = xnfalloc(sizeof(InputInfoRec));
-    *list[count - 1] = *pInfo;
+    list[count - 1] = pInfo;
     return list;
 }
 
@@ -1131,7 +1130,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
     const char *pointerMsg = NULL, *keyboardMsg = NULL;
     InputInfoPtr *devs, /* iterator */
             indp;
-    InputInfoRec Pointer = {}, Keyboard = {};
+    InputInfoPtr Pointer, Keyboard;
     XF86ConfInputPtr confInput;
     XF86ConfInputRec defPtr, defKbd;
     MessageType from = X_DEFAULT;
@@ -1235,18 +1234,20 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 
     /* Add the core pointer device to the layout, and set it to Core. */
     if (foundPointer && confInput) {
-	foundPointer = configInput(&Pointer, confInput, from);
-        if (foundPointer) {
-	    Pointer.options = xf86addNewOption(Pointer.options,
+	Pointer = xf86AllocateInput();
+	if (Pointer)
+	    foundPointer = configInput(Pointer, confInput, from);
+	if (foundPointer) {
+	    Pointer->options = xf86addNewOption(Pointer->options,
 					       xnfstrdup("CorePointer"), "on");
-	    Pointer.fd = -1;
-	    servlayoutp->inputs = addDevice(servlayoutp->inputs, &Pointer);
+	    servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer);
 	}
     }
 
     if (!foundPointer && xf86Info.forceInputDevices) {
 	/* This shouldn't happen. */
 	xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n");
+	xf86DeleteInput(Pointer, 0);
 	return FALSE;
     }
 
@@ -1274,12 +1275,13 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	defPtr.inp_identifier = strdup("<default pointer>");
 	defPtr.inp_driver = strdup("mouse");
 	confInput = &defPtr;
-	foundPointer = configInput(&Pointer, confInput, from);
-        if (foundPointer) {
-	    Pointer.options = xf86addNewOption(NULL,
+	Pointer = xf86AllocateInput();
+	if (Pointer)
+	    foundPointer = configInput(Pointer, confInput, from);
+	if (foundPointer) {
+	    Pointer->options = xf86addNewOption(NULL,
 					       xnfstrdup("AlwaysCore"), "on");
-	    Pointer.fd = -1;
-	    servlayoutp->inputs = addDevice(servlayoutp->inputs, &Pointer);
+	    servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer);
 	}
     }
 
@@ -1356,18 +1358,20 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 
     /* Add the core keyboard device to the layout, and set it to Core. */
     if (foundKeyboard && confInput) {
-	foundKeyboard = configInput(&Keyboard, confInput, from);
-        if (foundKeyboard) {
-	    Keyboard.options = xf86addNewOption(Keyboard.options,
+	Keyboard = xf86AllocateInput();
+	if (Keyboard)
+	    foundKeyboard = configInput(Keyboard, confInput, from);
+	if (foundKeyboard) {
+	    Keyboard->options = xf86addNewOption(Keyboard->options,
 						xnfstrdup("CoreKeyboard"), "on");
-	    Keyboard.fd = -1;
-	    servlayoutp->inputs = addDevice(servlayoutp->inputs, &Keyboard);
+	    servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard);
 	}
     }
 
     if (!foundKeyboard && xf86Info.forceInputDevices) {
 	/* This shouldn't happen. */
 	xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n");
+	xf86DeleteInput(Keyboard, 0);
 	return FALSE;
     }
 
commit fa8f4652819b692faaf2789cf32d7fa99fbb34aa
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jul 4 15:02:20 2011 +1000

    xfree86: factor out adding/removing a device from the input device array
    
    No functional changes, just readability improvements. This also gets rid of
    the count variable. Count was just used for resizing the null-terminated
    list. Since we're not in a time-critical path here at all we can afford to
    loop the list multiple times instead of keeping an extra variable around.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index c7d567d..83eac8b 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1068,6 +1068,46 @@ Bool xf86DRI2Enabled(void)
     return xf86Info.dri2;
 }
 
+/**
+ * Search for the pInfo in the null-terminated list given and remove (and
+ * free) it if present. All other devices are moved forward.
+ */
+static void
+freeDevice(InputInfoPtr *list, InputInfoPtr pInfo)
+{
+    InputInfoPtr *devs;
+
+    for (devs = list; devs && *devs; devs++) {
+	if (*devs == pInfo) {
+	    free(*devs);
+	    for (; devs && *devs; devs++)
+		devs[0] = devs[1];
+	    break;
+	}
+    }
+}
+
+/**
+ * Append pInfo to the null-terminated list, allocating space as necessary.
+ * pInfo is copied into the last element.
+ */
+static InputInfoPtr*
+addDevice(InputInfoPtr *list, InputInfoPtr pInfo)
+{
+    InputInfoPtr *devs;
+    int count = 1;
+
+    for (devs = list; devs && *devs; devs++)
+	count++;
+
+    list = xnfrealloc(list, (count + 1) * sizeof(InputInfoPtr));
+    list[count] = NULL;
+
+    list[count - 1] = xnfalloc(sizeof(InputInfoRec));
+    *list[count - 1] = *pInfo;
+    return list;
+}
+
 /*
  * Locate the core input devices.  These can be specified/located in
  * the following ways, in order of priority:
@@ -1094,7 +1134,6 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
     InputInfoRec Pointer = {}, Keyboard = {};
     XF86ConfInputPtr confInput;
     XF86ConfInputRec defPtr, defKbd;
-    int count = 0;
     MessageType from = X_DEFAULT;
     int found = 0;
     const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse",
@@ -1119,7 +1158,6 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 		coreKeyboard = indp;
 	    }
 	}
-	count++;
     }
 
     confInput = NULL;
@@ -1139,17 +1177,9 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	 * removed.
 	 */
 	if (corePointer) {
-	    for (devs = servlayoutp->inputs; devs && *devs; devs++) {
-		if (*devs == corePointer) {
-		    free(*devs);
-		    for (; devs && *devs; devs++)
-			devs[0] = devs[1];
-		    break;
-		}
-	    }
-	    count--;
+	    freeDevice(servlayoutp->inputs, corePointer);
+	    corePointer = NULL;
 	}
-	corePointer = NULL;
 	foundPointer = TRUE;
     }
 
@@ -1210,14 +1240,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	    Pointer.options = xf86addNewOption(Pointer.options,
 					       xnfstrdup("CorePointer"), "on");
 	    Pointer.fd = -1;
-	    count++;
-	    devs = xnfrealloc(servlayoutp->inputs,
-			      (count + 1) * sizeof(InputInfoPtr));
-            devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
-	    devs[count] = NULL;
-
-	    *devs[count - 1] = Pointer;
-	    servlayoutp->inputs = devs;
+	    servlayoutp->inputs = addDevice(servlayoutp->inputs, &Pointer);
 	}
     }
 
@@ -1256,14 +1279,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	    Pointer.options = xf86addNewOption(NULL,
 					       xnfstrdup("AlwaysCore"), "on");
 	    Pointer.fd = -1;
-	    count++;
-	    devs = xnfrealloc(servlayoutp->inputs,
-			      (count + 1) * sizeof(InputInfoPtr));
-            devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
-	    devs[count] = NULL;
-
-	    *devs[count - 1] = Pointer;
-	    servlayoutp->inputs = devs;
+	    servlayoutp->inputs = addDevice(servlayoutp->inputs, &Pointer);
 	}
     }
 
@@ -1284,17 +1300,9 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	 * removed.
 	 */
 	if (coreKeyboard) {
-	    for (devs = servlayoutp->inputs; devs && *devs; devs++) {
-		if (*devs == coreKeyboard) {
-		    free(*devs);
-		    for (; devs && *devs; devs++)
-			devs[0] = devs[1];
-		    break;
-		}
-	    }
-	    count--;
+	    freeDevice(servlayoutp->inputs, coreKeyboard);
+	    coreKeyboard = NULL;
 	}
-	coreKeyboard = NULL;
 	foundKeyboard = TRUE;
     }
 
@@ -1353,14 +1361,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	    Keyboard.options = xf86addNewOption(Keyboard.options,
 						xnfstrdup("CoreKeyboard"), "on");
 	    Keyboard.fd = -1;
-	    count++;
-	    devs = xnfrealloc(servlayoutp->inputs,
-			      (count + 1) * sizeof(InputInfoPtr));
-            devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
-	    devs[count] = NULL;
-
-	    *devs[count - 1] = Keyboard;
-	    servlayoutp->inputs = devs;
+	    servlayoutp->inputs = addDevice(servlayoutp->inputs, &Keyboard);
 	}
     }
 
commit 5b5477c05f691205064ca4d8034f8dd47ab975b7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jul 4 14:14:11 2011 +1000

    xfree86: update comment for InitInput
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 71926f8..5ee68cd 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -806,11 +806,10 @@ duplicateDevice(InputInfoPtr pInfo)
     return dup;
 }
 
-/*
- * InitInput --
- *      Initialize all supported input devices.
+/**
+ * Initialize all supported input devices present and referenced in the
+ * xorg.conf.
  */
-
 void
 InitInput(int argc, char **argv)
 {
commit 7354f607833c69626d8692bc5176b18ea1cf6263
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jul 4 14:26:13 2011 +1000

    xfree86: nest loops instead of 0x1 pointers.
    
    If we find the core device, move all other device pointers forward right
    then and there. The break will jump out of the top loop.
    
    They had a special on braces today, so I added some for readability (and
    fixed up tab vs space indentation.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 2dba088..c7d567d 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1139,15 +1139,14 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	 * removed.
 	 */
 	if (corePointer) {
-	    for (devs = servlayoutp->inputs; devs && *devs; devs++)
-		if (*devs == corePointer)
-                {
-                    free(*devs);
-                    *devs = (InputInfoPtr)0x1; /* ensure we dont skip next loop*/
+	    for (devs = servlayoutp->inputs; devs && *devs; devs++) {
+		if (*devs == corePointer) {
+		    free(*devs);
+		    for (; devs && *devs; devs++)
+			devs[0] = devs[1];
 		    break;
-                }
-	    for (; devs && *devs; devs++)
-		devs[0] = devs[1];
+		}
+	    }
 	    count--;
 	}
 	corePointer = NULL;
@@ -1285,15 +1284,14 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	 * removed.
 	 */
 	if (coreKeyboard) {
-	    for (devs = servlayoutp->inputs; devs && *devs; devs++)
-		if (*devs == coreKeyboard)
-                {
-                    free(*devs);
-                    *devs = (InputInfoPtr)0x1; /* ensure we dont skip next loop */
+	    for (devs = servlayoutp->inputs; devs && *devs; devs++) {
+		if (*devs == coreKeyboard) {
+		    free(*devs);
+		    for (; devs && *devs; devs++)
+			devs[0] = devs[1];
 		    break;
-                }
-	    for (; devs && *devs; devs++)
-		devs[0] = devs[1];
+		}
+	    }
 	    count--;
 	}
 	coreKeyboard = NULL;
commit 5669aa2d24dff9ab276e5f74a09f97ec77b90e75
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jul 4 14:05:30 2011 +1000

    xfree86: improve readability of synthesized device.
    
    No functional changes.
    
    The options we assign are the ones from the Pointer/Keyboard device so we
    might as well use those readable names instead of dev[count-1]->options.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 04d0180..2dba088 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1208,16 +1208,16 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
     if (foundPointer && confInput) {
 	foundPointer = configInput(&Pointer, confInput, from);
         if (foundPointer) {
+	    Pointer.options = xf86addNewOption(Pointer.options,
+					       xnfstrdup("CorePointer"), "on");
+	    Pointer.fd = -1;
 	    count++;
 	    devs = xnfrealloc(servlayoutp->inputs,
 			      (count + 1) * sizeof(InputInfoPtr));
             devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
-            Pointer.fd = -1;
-	    *devs[count - 1] = Pointer;
-	    devs[count - 1]->options =
-				xf86addNewOption(devs[count -1]->options,
-				    xnfstrdup("CorePointer"), "on");
 	    devs[count] = NULL;
+
+	    *devs[count - 1] = Pointer;
 	    servlayoutp->inputs = devs;
 	}
     }
@@ -1254,15 +1254,16 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	confInput = &defPtr;
 	foundPointer = configInput(&Pointer, confInput, from);
         if (foundPointer) {
+	    Pointer.options = xf86addNewOption(NULL,
+					       xnfstrdup("AlwaysCore"), "on");
+	    Pointer.fd = -1;
 	    count++;
 	    devs = xnfrealloc(servlayoutp->inputs,
 			      (count + 1) * sizeof(InputInfoPtr));
             devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
-            Pointer.fd = -1;
-	    *devs[count - 1] = Pointer;
-	    devs[count - 1]->options =
-				xf86addNewOption(NULL, xnfstrdup("AlwaysCore"), "on");
 	    devs[count] = NULL;
+
+	    *devs[count - 1] = Pointer;
 	    servlayoutp->inputs = devs;
 	}
     }
@@ -1351,16 +1352,16 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
     if (foundKeyboard && confInput) {
 	foundKeyboard = configInput(&Keyboard, confInput, from);
         if (foundKeyboard) {
+	    Keyboard.options = xf86addNewOption(Keyboard.options,
+						xnfstrdup("CoreKeyboard"), "on");
+	    Keyboard.fd = -1;
 	    count++;
 	    devs = xnfrealloc(servlayoutp->inputs,
 			      (count + 1) * sizeof(InputInfoPtr));
             devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
-            Keyboard.fd = -1;
-	    *devs[count - 1] = Keyboard;
-	    devs[count - 1]->options =
-				xf86addNewOption(devs[count - 1]->options,
-				    xnfstrdup("CoreKeyboard"), "on");
 	    devs[count] = NULL;
+
+	    *devs[count - 1] = Keyboard;
 	    servlayoutp->inputs = devs;
 	}
     }
commit 5aa826cdd1f2e768bedf23d399703a5d0b6302be
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jul 4 13:52:11 2011 +1000

    test: add a option duplication test
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/test/Makefile.am b/test/Makefile.am
index 7ef408c..689dd7f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,7 +1,7 @@
 if ENABLE_UNIT_TESTS
 if HAVE_LD_WRAP
 SUBDIRS= . xi2
-noinst_PROGRAMS = xkb input xtest list misc fixes
+noinst_PROGRAMS = xkb input xtest list misc fixes xfree86
 check_LTLIBRARIES = libxservertest.la
 
 TESTS=$(noinst_PROGRAMS)
@@ -23,6 +23,7 @@ xtest_LDADD=$(TEST_LDADD)
 list_LDADD=$(TEST_LDADD)
 misc_LDADD=$(TEST_LDADD)
 fixes_LDADD=$(TEST_LDADD)
+xfree86_LDADD=$(TEST_LDADD)
 
 nodist_libxservertest_la_SOURCES = $(top_builddir)/hw/xfree86/sdksyms.c
 libxservertest_la_LIBADD = \
diff --git a/test/xfree86.c b/test/xfree86.c
new file mode 100644
index 0000000..2b591cf
--- /dev/null
+++ b/test/xfree86.c
@@ -0,0 +1,80 @@
+/**
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  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
+ *  THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <assert.h>
+
+
+#include "xf86.h"
+
+static void
+xfree86_option_list_duplicate(void)
+{
+    pointer options;
+    pointer duplicate;
+    const char *o1 = "foo",
+               *o2 = "bar",
+               *v1 = "one",
+               *v2 = "two";
+    const char *o_null= "NULL";
+    char *val1, *val2;
+
+    duplicate = xf86OptionListDuplicate(NULL);
+    assert(!duplicate);
+
+    options = xf86AddNewOption(NULL, o1, v1);
+    assert(options);
+    options = xf86AddNewOption(options, o2, v2);
+    assert(options);
+    options = xf86AddNewOption(options, o_null, NULL);
+    assert(options);
+
+    duplicate = xf86OptionListDuplicate(options);
+    assert(duplicate);
+
+    val1 = xf86CheckStrOption(options, o1, "1");
+    val2 = xf86CheckStrOption(duplicate, o1, "2");
+
+    assert(strcmp(val1, v1) == 0);
+    assert(strcmp(val1, val2) == 0);
+
+    val1 = xf86CheckStrOption(options, o2, "1");
+    val2 = xf86CheckStrOption(duplicate, o2, "2");
+
+    assert(strcmp(val1, v2) == 0);
+    assert(strcmp(val1, val2) == 0);
+
+    val1 = xf86FindOption(options, o_null);
+    val2 = xf86FindOption(duplicate, o_null);
+    assert(val1 && val2);
+}
+
+int main(int argc, char** argv)
+{
+    xfree86_option_list_duplicate();
+
+    return 0;
+}
commit 4527e2b776cfcdac2b189b5439b9a3d0b6433077
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jul 4 13:46:24 2011 +1000

    xfree86: when implicitly choosing a core device, set the option to a value
    
    Devices are core pointers/keyboards by default now anyway, but let's set the
    option to some value instead of just NULL.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index ddd0b36..04d0180 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1216,7 +1216,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	    *devs[count - 1] = Pointer;
 	    devs[count - 1]->options =
 				xf86addNewOption(devs[count -1]->options,
-				    xnfstrdup("CorePointer"), NULL);
+				    xnfstrdup("CorePointer"), "on");
 	    devs[count] = NULL;
 	    servlayoutp->inputs = devs;
 	}
@@ -1261,7 +1261,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
             Pointer.fd = -1;
 	    *devs[count - 1] = Pointer;
 	    devs[count - 1]->options =
-				xf86addNewOption(NULL, xnfstrdup("AlwaysCore"), NULL);
+				xf86addNewOption(NULL, xnfstrdup("AlwaysCore"), "on");
 	    devs[count] = NULL;
 	    servlayoutp->inputs = devs;
 	}
@@ -1359,7 +1359,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	    *devs[count - 1] = Keyboard;
 	    devs[count - 1]->options =
 				xf86addNewOption(devs[count - 1]->options,
-				    xnfstrdup("CoreKeyboard"), NULL);
+				    xnfstrdup("CoreKeyboard"), "on");
 	    devs[count] = NULL;
 	    servlayoutp->inputs = devs;
 	}
commit 44d53728a6a533fc0a6e0a10269d1cc99e9dad32
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jul 4 13:44:44 2011 +1000

    xfree86: don't warn about duplicate core devices
    
    It doesn't matter. All devices are core pointer devices by default now
    anyway.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 58b30dd..ddd0b36 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1111,22 +1111,12 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	    xf86CheckBoolOption(indp->options, "CorePointer", FALSE)) {
 	    if (!corePointer) {
 		corePointer = indp;
-	    } else {
-		    xf86ReplaceBoolOption(indp->options, "CorePointer", FALSE);
-		xf86Msg(X_WARNING, "Duplicate core pointer devices.  "
-			"Removing core pointer attribute from \"%s\"\n",
-			indp->name);
 	    }
 	}
 	if (indp->options &&
 	    xf86CheckBoolOption(indp->options, "CoreKeyboard", FALSE)) {
 	    if (!coreKeyboard) {
 		coreKeyboard = indp;
-	    } else {
-		    xf86ReplaceBoolOption(indp->options, "CoreKeyboard", FALSE);
-		xf86Msg(X_WARNING, "Duplicate core keyboard devices.  "
-			"Removing core keyboard attribute from \"%s\"\n",
-			indp->name);
 	    }
 	}
 	count++;
commit 033f53c223dc12a91f00e10a69f87a4f2a7adb6b
Author: Daniel Kurtz <djkurtz at chromium.org>
Date:   Mon Aug 8 15:09:48 2011 +0800

    xf86Helper: use LogHdrMessageVerb in xf86VDrvMsgVerb
    
    LogHdrMessageVerb allows passing a parameterized header to insert in a log
    message between MessageType and the formatted message body string.
    
    Signed-off-by: Daniel Kurtz <djkurtz at chromium.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index f42d0f9..d6c2a7b 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1027,36 +1027,20 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
     }
 }
 
-/* Print driver messages in the standard format */
-
-#undef PREFIX_SIZE
-#define PREFIX_SIZE 14
-
+/* Print driver messages in the standard format of
+   (<type>) <screen name>(<screen index>): <message> */
 void
 xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
 		va_list args)
 {
-    char *tmpFormat;
-
     /* Prefix the scrnIndex name to the format string. */
     if (scrnIndex >= 0 && scrnIndex < xf86NumScreens &&
-	xf86Screens[scrnIndex]->name) {
-	tmpFormat = malloc(strlen(format) +
-			   strlen(xf86Screens[scrnIndex]->name) +
-			   PREFIX_SIZE + 1);
-	if (!tmpFormat)
-	    return;
-
-	snprintf(tmpFormat, PREFIX_SIZE + 1, "%s(%d): ",
-		 xf86Screens[scrnIndex]->name, scrnIndex);
-
-	strcat(tmpFormat, format);
-	LogVMessageVerb(type, verb, tmpFormat, args);
-	free(tmpFormat);
-    } else
+	xf86Screens[scrnIndex]->name)
+	LogHdrMessageVerb(type, verb, format, args, "%s(%d): ",
+	    xf86Screens[scrnIndex]->name, scrnIndex);
+    else
 	LogVMessageVerb(type, verb, format, args);
 }
-#undef PREFIX_SIZE
 
 /* Print driver messages, with verbose level specified directly */
 void
commit cd8ee3e5cb29b9cd6402d2fbc71463c6b04b6077
Author: Daniel Kurtz <djkurtz at chromium.org>
Date:   Mon Aug 8 15:09:47 2011 +0800

    xf86Helper: use LogHdrMessageVerb in xf86VIDrvMsgVerb
    
    LogHdrMessageVerb allows passing a parameterized header to insert in a log
    message between MessageType and the formatted message body string.
    
    Signed-off-by: Daniel Kurtz <djkurtz at chromium.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index f8e6c8b..f42d0f9 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1082,20 +1082,23 @@ xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...)
 }
 
 /* Print input driver messages in the standard format of
-   <driver>: <device name>: <message> */
+   (<type>) <driver>: <device name>: <message> */
 void
-xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *format,
-		 va_list args)
+xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb,
+		 const char *format, va_list args)
 {
-    char *msg;
+    const char *driverName = NULL;
+    const char *deviceName = NULL;
 
-    if (asprintf(&msg, "%s: %s: %s", dev->drv->driverName, dev->name, format)
-	== -1) {
-	LogVMessageVerb(type, verb, "%s", args);
-    } else {
-	LogVMessageVerb(type, verb, msg, args);
-	free(msg);
+    /* Prefix driver and device names to formatted message. */
+    if (dev) {
+	deviceName = dev->name;
+	if (dev->drv)
+	    driverName = dev->drv->driverName;
     }
+
+    LogHdrMessageVerb(type, verb, format, args, "%s: %s: ", driverName,
+	deviceName);
 }
 
 /* Print input driver message, with verbose level specified directly */
commit b31d104fc09a7241856ff8d226be11ec562beac3
Author: Daniel Kurtz <djkurtz at chromium.org>
Date:   Mon Aug 8 15:09:46 2011 +0800

    os/log: Add LogVHdrMessageVerb and friends
    
    LogVHdrMessageVerb allows a custom header to be inserted in a log message,
    between the Log system's MessageType string, and a formatted variable
    message body. The custom header can itself be a formatted variable string.
    
    These functions can be used, for example, by driver abstraction layers to
    format specific driver messages in a standard format, but do it in a way
    that is efficient, obeys the log-layers verbosity settings, and is safe
    to use in signal handlers (because they don't call malloc), even for
    types besides X_NONE.
    
    Signed-off-by: Daniel Kurtz <djkurtz at chromium.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/os.h b/include/os.h
index a553f57..5401ea4 100644
--- a/include/os.h
+++ b/include/os.h
@@ -525,6 +525,19 @@ extern _X_EXPORT void LogMessageVerb(MessageType type, int verb, const char *for
 			   ...) _X_ATTRIBUTE_PRINTF(3,4);
 extern _X_EXPORT void LogMessage(MessageType type, const char *format, ...)
 			_X_ATTRIBUTE_PRINTF(2,3);
+
+extern _X_EXPORT void LogVHdrMessageVerb(MessageType type, int verb,
+			    const char *msg_format, va_list msg_args,
+			    const char *hdr_format, va_list hdr_args)
+			_X_ATTRIBUTE_PRINTF(3,0) _X_ATTRIBUTE_PRINTF(5,0);
+extern _X_EXPORT void LogHdrMessageVerb(MessageType type, int verb,
+			    const char *msg_format, va_list msg_args,
+			    const char *hdr_format, ...)
+			_X_ATTRIBUTE_PRINTF(3,0) _X_ATTRIBUTE_PRINTF(5,6);
+extern _X_EXPORT void LogHdrMessage(MessageType type, const char *msg_format,
+			    va_list msg_args, const char *hdr_format, ...)
+			_X_ATTRIBUTE_PRINTF(2,0) _X_ATTRIBUTE_PRINTF(4,5);
+
 extern _X_EXPORT void FreeAuditTimer(void);
 extern _X_EXPORT void AuditF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2);
 extern _X_EXPORT void VAuditF(const char *f, va_list args) _X_ATTRIBUTE_PRINTF(1,0);
diff --git a/os/log.c b/os/log.c
index 4ff0180..2eddf06 100644
--- a/os/log.c
+++ b/os/log.c
@@ -411,6 +411,61 @@ LogMessage(MessageType type, const char *format, ...)
     va_end(ap);
 }
 
+
+void
+LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
+		   va_list msg_args, const char *hdr_format, va_list hdr_args)
+{
+    const char *type_str;
+    char tmpFormat[1024];
+    char *tmpFormat_end = &tmpFormat[sizeof(tmpFormat)];
+    char *p;
+    int left;
+
+    type_str = LogMessageTypeVerbString(type, verb);
+    if (!type_str)
+	return;
+
+    /* if type_str != "", copy it and ' ' to tmpFormat; set p after ' ' */
+    p = tmpFormat;
+    if (type_str[0] != '\0')
+	p += snprintf(tmpFormat, sizeof(tmpFormat), "%s ", type_str);
+
+    /* append as much of hdr as fits after type_str (if there was one) */
+    left = tmpFormat_end - p;
+    if (left > 1)
+	p += vsnprintf(p, left, hdr_format, hdr_args);
+
+    /* append as much of msg_format as will fit after hdr */
+    left = tmpFormat_end - p;
+    if (left > 1)
+	snprintf(p, left, "%s", msg_format);
+
+    LogVWrite(verb, tmpFormat, msg_args);
+}
+
+void
+LogHdrMessageVerb(MessageType type, int verb, const char *msg_format,
+		  va_list msg_args, const char *hdr_format, ...)
+{
+    va_list hdr_args;
+
+    va_start(hdr_args, hdr_format);
+    LogVHdrMessageVerb(type, verb, msg_format, msg_args, hdr_format, hdr_args);
+    va_end(hdr_args);
+}
+
+void
+LogHdrMessage(MessageType type, const char *msg_format, va_list msg_args,
+	      const char *hdr_format, ...)
+{
+    va_list hdr_args;
+
+    va_start(hdr_args, hdr_format);
+    LogVHdrMessageVerb(type, 1, msg_format, msg_args, hdr_format, hdr_args);
+    va_end(hdr_args);
+}
+
 void
 AbortServer(void) _X_NORETURN;
 
commit b82f934db661c59d7397ce180d08cf8f8f7118b1
Author: Daniel Kurtz <djkurtz at chromium.org>
Date:   Mon Aug 8 15:09:45 2011 +0800

    os/log: Pull LogMessageTypeVerbString out of LogVMessageVerb
    
    Also, optimize how the type and format strings are combined.
    
    Signed-off-by: Daniel Kurtz <djkurtz at chromium.org>
    Reviewed-by: Guillem Jover <guillem at hadrons.org>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/log.c b/os/log.c
index f519762..4ff0180 100644
--- a/os/log.c
+++ b/os/log.c
@@ -165,6 +165,9 @@ asm (".desc ___crashreporter_info__, 0x10");
 #ifndef X_NOT_IMPLEMENTED_STRING
 #define X_NOT_IMPLEMENTED_STRING	"(NI)"
 #endif
+#ifndef X_NONE_STRING
+#define X_NONE_STRING                   ""
+#endif
 
 /*
  * LogInit is called to start logging to a file.  It is also called (with
@@ -325,58 +328,65 @@ LogWrite(int verb, const char *f, ...)
     va_end(args);
 }
 
+/* Returns the Message Type string to prepend to a logging message, or NULL
+ * if the message will be dropped due to insufficient verbosity. */
+static const char *
+LogMessageTypeVerbString(MessageType type, int verb)
+{
+    if (type == X_ERROR)
+	verb = 0;
+
+    if (logVerbosity < verb && logFileVerbosity < verb)
+	return NULL;
+
+    switch (type) {
+    case X_PROBED:
+	return X_PROBE_STRING;
+    case X_CONFIG:
+	return X_CONFIG_STRING;
+    case X_DEFAULT:
+	return X_DEFAULT_STRING;
+    case X_CMDLINE:
+	return X_CMDLINE_STRING;
+    case X_NOTICE:
+	return X_NOTICE_STRING;
+    case X_ERROR:
+	return X_ERROR_STRING;
+    case X_WARNING:
+	return X_WARNING_STRING;
+    case X_INFO:
+	return X_INFO_STRING;
+    case X_NOT_IMPLEMENTED:
+	return X_NOT_IMPLEMENTED_STRING;
+    case X_UNKNOWN:
+	return X_UNKNOWN_STRING;
+    case X_NONE:
+	return X_NONE_STRING;
+    default:
+	return X_UNKNOWN_STRING;
+    }
+}
+
 void
 LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
 {
-    const char *s  = X_UNKNOWN_STRING;
-    char tmpBuf[1024];
-
-    /* Ignore verbosity for X_ERROR */
-    if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) {
-	switch (type) {
-	case X_PROBED:
-	    s = X_PROBE_STRING;
-	    break;
-	case X_CONFIG:
-	    s = X_CONFIG_STRING;
-	    break;
-	case X_DEFAULT:
-	    s = X_DEFAULT_STRING;
-	    break;
-	case X_CMDLINE:
-	    s = X_CMDLINE_STRING;
-	    break;
-	case X_NOTICE:
-	    s = X_NOTICE_STRING;
-	    break;
-	case X_ERROR:
-	    s = X_ERROR_STRING;
-	    if (verb > 0)
-		verb = 0;
-	    break;
-	case X_WARNING:
-	    s = X_WARNING_STRING;
-	    break;
-	case X_INFO:
-	    s = X_INFO_STRING;
-	    break;
-	case X_NOT_IMPLEMENTED:
-	    s = X_NOT_IMPLEMENTED_STRING;
-	    break;
-	case X_UNKNOWN:
-	    s = X_UNKNOWN_STRING;
-	    break;
-	case X_NONE:
-	    s = NULL;
-	    break;
-	}
-
-        /* if s is not NULL we need a space before format */
-        snprintf(tmpBuf, sizeof(tmpBuf), "%s%s%s", s ? s : "",
-                                                   s ? " " : "",
-                                                   format);
-        LogVWrite(verb, tmpBuf, args);
+    const char *type_str;
+    char tmpFormat[1024];
+    char *new_format;
+
+    type_str = LogMessageTypeVerbString(type, verb);
+    if (!type_str)
+	return;
+
+    /* if type_str is not "", prepend it and ' ', to format */
+    if (type_str[0] == '\0')
+        new_format = format;
+    else {
+        new_format = tmpFormat;
+        snprintf(tmpFormat, sizeof(tmpFormat), "%s %s", type_str, format);
     }
+
+    LogVWrite(verb, new_format, args);
 }
 
 /* Log message with verbosity level specified. */


More information about the Xquartz-changes mailing list