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

Jeremy Huddleston jeremyhu at freedesktop.org
Mon Oct 3 12:07:36 PDT 2011


Rebased ref, commits from common ancestor:
commit d2bee418b89a3566eb93837e834ac5f6fe04e897
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 769f6d18abf409f7924ef66124e7ca9a1af33ab9
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 1a6687f14b9c93573cb5a8a1118705a652ffb70f
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 8962ae0..a66dc5e 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 c8d7a381b7f0f432c98bb3bc10135fd5fbc0b4e0
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 330d87a..a9645e7 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(14, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(6, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
commit 641e1aec33246f762d57638909e3e568179843b6
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 2c900e7..8962ae0 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 >= 2.0.99.1] [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 >= 2.0.99.1] [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 &&
@@ -1567,6 +1567,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 64f8880924253c1601ae5207a23a19ffbda73db3
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/configure.ac b/configure.ac
index 32b0f1b..2c900e7 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 4b29b9aa7f5afe2edcc34eaea99ee94d23705cf7
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 0837044800cbd4425943f2d0c8553c0aa42b77c4
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 42636333be34959325912929d17aa745194c6bf8
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 f21d2f0..32b0f1b 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])
@@ -1557,6 +1558,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"
@@ -1573,6 +1577,9 @@ if test "x$XORG" = xyes; then
 		xorg_bus_sparc="yes"
 		;;
 	esac
+	fi
+	AC_MSG_RESULT([$PCI])
+
 	dnl ===================================================================
 	dnl ==================== end of PCI configuration =====================
 	dnl ===================================================================
@@ -1752,6 +1759,7 @@ if test "x$XORG" = xyes; then
 	AC_SUBST([abi_extension])
 fi
 AM_CONDITIONAL([XORG], [test "x$XORG" = xyes])
+AM_CONDITIONAL([XORG_BUS_PCI], [test "x$PCI" = 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/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 4a03428..669da0d 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 71724ccd7b8037a80eea0d8c5df5e50a0a5b6320
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 f46a2ab..f21d2f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1254,7 +1254,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`
@@ -1505,9 +1504,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'
@@ -1555,10 +1551,32 @@ if test "x$XORG" = xyes; then
 	AC_SUBST([symbol_visibility])
 	dnl ===================================================================
 
+	dnl ===================================================================
+	dnl ================= beginning of PCI configuration ==================
+	dnl ===================================================================
+	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
+	  gnu* | freebsd* | kfreebsd*-gnu | netbsd* | openbsd* | solaris* | dragonfly*)
+		xorg_bus_bsdpci="yes"
+		;;
+	esac
+	case $host_cpu in
+	  sparc*)
+		xorg_bus_sparc="yes"
+		;;
+	esac
+	dnl ===================================================================
+	dnl ==================== end of PCI configuration =====================
+	dnl ===================================================================
+
 	case $host_os in
 	  linux*)
 		if test "x$LNXAPM" = xyes; then
@@ -1579,11 +1597,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 \
@@ -1591,14 +1607,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
@@ -1643,9 +1655,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"
@@ -1658,9 +1667,6 @@ if test "x$XORG" = xyes; then
 	esac
 
 	case $host_cpu in
-	  sparc*)
-		xorg_bus_sparc="yes"
-		;;
 	  i*86)
 		;;
 	esac
@@ -1717,7 +1723,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
commit eaa9e084430e2758c09424a028de26e236e49505
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/configure.ac b/configure.ac
index 9de1f15..f46a2ab 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"
@@ -1556,16 +1556,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 835e981198e2ca03bf3c20389c9d8719bdcfe379
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 d554c28f1ccd4736b32600fe6bb790f52a9536d4
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 7f52fb1..9de1f15 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1658,8 +1658,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,],
@@ -2160,6 +2160,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 399aaf6e3771a0986cbc73077e52e2b6029ae269
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 82f974b3e71bcf37a7e820dc7851294919d366f0
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 67323342a27ffc97360daad49bdcce394a992814
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 0639a0a..7f52fb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1505,7 +1505,6 @@ if test "x$XORG" = xauto; then
 fi
 AC_MSG_RESULT([$XORG])
 
-xorg_bus_linuxpci=no
 xorg_bus_bsdpci=no
 xorg_bus_sparc=no
 
@@ -1576,7 +1575,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*)
@@ -1759,7 +1757,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 dd4b675ab93c77e190348a7c4d0a072ce9d5d541
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 e20897682abeb02c086e203b2634b2a587513031
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 50c5a816cc0e36c539337f48a7c0030c83771c8a
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 2ca4ac3ef219ebeae6124529fa691e219b3c8f6f
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/configure.ac b/configure.ac
index 7c5aaaf..0639a0a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1579,14 +1579,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"
 			;;
 		  *)
@@ -1766,7 +1762,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 b15e4ce481011ee8b9eb053915b3afddf562d32b
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 4ee60731055dd4d699a68b2be03633ca07e4a9ff
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 bbeb3ea9d7a5053f1f5d1c1050a866430738b66e
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 18336cdcde903fb911d5d8fa55fc87c89cfd6d40
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 b36a80f63c7fb0e00f75e0e3f12ff3481db2fafe
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 6284a17615ac2f534caeee68b07da383c03fed0b
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 1f0c655959f768c358eccd261da1211c8f993677
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 357b23b1eb34e8421f870905ab0bdc059bcacd65
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 7b0a5cff719a0fd6f9ae5873b429261543bc4498
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>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

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 fad04dd9701aa76249a0bab31676103debb84307
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Sep 27 18:04:06 2011 +0100

    udev: make use of udev_enumerate_add_match_tag() only when it is available
    
    udev_enumerate_add_match_tag() and udev_monitor_filter_add_match_tag()
    are mostly optimizations, hence simply skip these calls if they are not
    available in the installed version of libudev.
    
    This should fix the build on older versions of udev.
    
    [airlied: fixes tinderbox failures on RHEL6]
    
    Signed-off-by: Lennart Poettering <lennart at poettering.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Tested-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/config/udev.c b/config/udev.c
index 1ba0d50..e2b3726 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -285,8 +285,10 @@ 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 */
 
+#ifdef HAVE_UDEV_MONITOR_FILTER_ADD_MATCH_TAG
     if (SeatId && strcmp(SeatId, "seat0"))
         udev_monitor_filter_add_match_tag(udev_monitor, SeatId);
+#endif
 
     if (udev_monitor_enable_receiving(udev_monitor)) {
         ErrorF("config/udev: failed to bind the udev monitor\n");
@@ -300,8 +302,10 @@ config_udev_init(void)
     udev_enumerate_add_match_subsystem(enumerate, "input");
     udev_enumerate_add_match_subsystem(enumerate, "tty");
 
+#ifdef HAVE_UDEV_ENUMERATE_ADD_MATCH_TAG
     if (SeatId && strcmp(SeatId, "seat0"))
         udev_enumerate_add_match_tag(enumerate, SeatId);
+#endif
 
     udev_enumerate_scan_devices(enumerate);
     devices = udev_enumerate_get_list_entry(enumerate);
diff --git a/configure.ac b/configure.ac
index ecd5386..7c5aaaf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -822,6 +822,15 @@ if test "x$CONFIG_UDEV" = xyes; then
 		AC_MSG_ERROR([udev configuration API requested, but libudev is not installed])
 	fi
 	AC_DEFINE(CONFIG_UDEV, 1, [Use libudev for input hotplug])
+
+	SAVE_LIBS=$LIBS
+	SAVE_CFLAGS=$CFLAGS
+	CFLAGS=$UDEV_CFLAGS
+	LIBS=$UDEV_LIBS
+	AC_CHECK_FUNCS([udev_monitor_filter_add_match_tag])
+	AC_CHECK_FUNCS([udev_enumerate_add_match_tag])
+	LIBS=$SAVE_LIBS
+	CFLAGS=$SAVE_CFLAGS
 fi
 
 dnl HAVE_DBUS is true if we actually have the D-Bus library, whereas
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index aa7de60..7d6cb96 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -399,6 +399,12 @@
 /* Use libudev for input hotplug */
 #undef CONFIG_UDEV
 
+/* Use udev_monitor_filter_add_match_tag() */
+#undef HAVE_UDEV_MONITOR_FILTER_ADD_MATCH_TAG
+
+/* Use udev_enumerate_add_match_tag() */
+#undef HAVE_UDEV_ENUMERATE_ADD_MATCH_TAG
+
 /* Use D-Bus for input hotplug */
 #undef CONFIG_NEED_DBUS
 
commit 77743f877d573cdf70fcb5cb5897250f668ebf9b
Author: Jamey Sharp <jamey at minilop.net>
Date:   Mon Sep 26 22:38:44 2011 -0700

    kdrive: Fix build for opaque InputOption structure.
    
    Commit 05284a03f9002b03a66ae355b34790ec02b726f0 missed fixing up
    kdrive's use of the old non-opaque structure.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kinfo.c b/hw/kdrive/src/kinfo.c
index 7055fbf..0055b16 100644
--- a/hw/kdrive/src/kinfo.c
+++ b/hw/kdrive/src/kinfo.c
@@ -134,19 +134,9 @@ KdNewPointer (void)
 void
 KdFreePointer(KdPointerInfo *pi)
 {
-    InputOption *option, *prev = NULL;
-
     free(pi->name);
     free(pi->path);
-
-    for (option = pi->options; option; option = option->next) {
-        free(prev);
-        free(option->key);
-        free(option->value);
-        prev = option;
-    }
-
-    free(prev);
+    input_option_free_list(&pi->options);
     free(pi);
 }
 
commit 9a55b3661b4172f9a32cd6fefb254e06edb1a88a
Merge: cf11ca3... 84bb020...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Oct 3 11:49:23 2011 -0700

    Merge remote-tracking branch 'alanc/master'

commit cf11ca360c2ded5ca309faa9d039160947387bb8
Merge: 463dd87... 6eae9fa...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Oct 3 11:44:59 2011 -0700

    Merge remote-tracking branch 'jeremyhu/for-keith'

commit 463dd87062edaa974cb8c7163328a53197f237e1
Author: Pauli Nieminen <pauli.nieminen at linux.intel.com>
Date:   Thu Sep 22 18:38:53 2011 +0300

    xf86/modes: Fix shadow rotation crashing when screen pixmap changes
    
    Driver may change screen pixmaps after page flipping that would then
    make damage lose track of the root pixmap.
    
    Using root window for shadow damages fixes the problem because
    SetWindowPixmap is implemented in shadow code.
    
    Signed-off-by: Pauli Nieminen <pauli.nieminen at linux.intel.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 45aabf0..ff7000b 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -198,7 +198,7 @@ xf86RotatePrepare (ScreenPtr pScreen)
 	    if (!xf86_config->rotation_damage_registered)
 	    {
 		/* Hook damage to screen pixmap */
-		DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+		DamageRegister (&pScreen->root->drawable,
 				xf86_config->rotation_damage);
 		xf86_config->rotation_damage_registered = TRUE;
 		EnableLimitedSchedulingLatency();
@@ -305,7 +305,7 @@ xf86RotateDestroy (xf86CrtcPtr crtc)
 	/* Free damage structure */
 	if (xf86_config->rotation_damage_registered)
 	{
-	    DamageUnregister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+	    DamageUnregister (&pScreen->root->drawable,
 			      xf86_config->rotation_damage);
 	    xf86_config->rotation_damage_registered = FALSE;
 	    DisableLimitedSchedulingLatency();
commit f5d50b46ddeb039ab6564141f61261e94ee67637
Merge: 57cd32e... 524e544...
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Oct 3 11:36:28 2011 -0700

    Merge remote-tracking branch 'whot/next'

commit 57cd32e93425597317b4b7722859155419836e4c
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Thu Aug 25 15:41:55 2011 -0700

    xfree86/modes: Make cursor position transform a helper function
    
    When the driver can handle the crtc transform in hardware, it sets
    crtc->driverIsPerformingTransform, which turns off both the shadow
    layer and the cursor's position-transforming code.  However, some
    drivers actually do require the cursor position to still be
    transformed in these cases.  Move the cursor position transform into a
    helper function that can be called by such drivers.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 0d7a6a6..ffb2eff 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -948,6 +948,14 @@ xf86_hide_cursors (ScrnInfoPtr scrn);
 extern _X_EXPORT void
 xf86_cursors_fini (ScreenPtr screen);
 
+/**
+ * Transform the cursor's coordinates based on the crtc transform.  Normally
+ * this is done by the server, but if crtc->driverIsPerformingTransform is TRUE,
+ * then the server does not transform the cursor position automatically.
+ */
+extern _X_EXPORT void
+xf86CrtcTransformCursorPos (xf86CrtcPtr crtc, int *x, int *y);
+
 /*
  * For overlay video, compute the relevant CRTC and
  * clip video to that.
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index 02dea5c..4a03428 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -337,7 +337,36 @@ xf86_show_cursors (ScrnInfoPtr scrn)
 	    xf86_crtc_show_cursor (crtc);
     }
 }
-    
+
+void xf86CrtcTransformCursorPos (xf86CrtcPtr crtc, int *x, int *y)
+{
+    ScrnInfoPtr scrn = crtc->scrn;
+    ScreenPtr screen = scrn->pScreen;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+    xf86CursorScreenPtr ScreenPriv =
+	(xf86CursorScreenPtr)dixLookupPrivate(&screen->devPrivates,
+					      xf86CursorScreenKey);
+    struct pict_f_vector v;
+    int dx, dy;
+
+    v.v[0] = (*x + ScreenPriv->HotX) + 0.5;
+    v.v[1] = (*y + ScreenPriv->HotY) + 0.5;
+    v.v[2] = 1;
+    pixman_f_transform_point (&crtc->f_framebuffer_to_crtc, &v);
+    /* cursor will have 0.5 added to it already so floor is sufficent */
+    *x = floor (v.v[0]);
+    *y = floor (v.v[1]);
+    /*
+     * Transform position of cursor upper left corner
+     */
+    xf86_crtc_rotate_coord_back (crtc->rotation, cursor_info->MaxWidth,
+				 cursor_info->MaxHeight, ScreenPriv->HotX,
+				 ScreenPriv->HotY, &dx, &dy);
+    *x -= dx;
+    *y -= dy;
+}
+
 static void
 xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 {
@@ -346,36 +375,12 @@ xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
     xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
     DisplayModePtr	mode = &crtc->mode;
     Bool		in_range;
-    int			dx, dy;
 
     /*
      * Transform position of cursor on screen
      */
     if (crtc->transform_in_use && !crtc->driverIsPerformingTransform)
-    {
-	ScreenPtr	screen = scrn->pScreen;
-	xf86CursorScreenPtr ScreenPriv =
-	    (xf86CursorScreenPtr)dixLookupPrivate(&screen->devPrivates,
-						  xf86CursorScreenKey);
-	struct pict_f_vector   v;
-
-	v.v[0] = (x + ScreenPriv->HotX) + 0.5;
-	v.v[1] = (y + ScreenPriv->HotY) + 0.5;
-	v.v[2] = 1;
-	pixman_f_transform_point (&crtc->f_framebuffer_to_crtc, &v);
-	/* cursor will have 0.5 added to it already so floor is sufficent */
-	x = floor (v.v[0]);
-	y = floor (v.v[1]);
-	/*
-	 * Transform position of cursor upper left corner
-	 */
-	xf86_crtc_rotate_coord_back (crtc->rotation,
-				     cursor_info->MaxWidth,
-				     cursor_info->MaxHeight,
-				     ScreenPriv->HotX, ScreenPriv->HotY, &dx, &dy);
-	x -= dx;
-	y -= dy;
-   }
+	xf86CrtcTransformCursorPos(crtc, &x, &y);
     else
     {
 	x -= crtc->x;
commit 245cb8e94fd15990e1b7d6622added460f104dba
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Thu Aug 25 10:19:48 2011 -0700

    xfree86/modes: Let the driver handle the transform
    
    If a driver can use hardware to handle the crtc transform, then
    there's no need for the server's shadow layer to do it.  Add a crtc
    flag that lets the driver indicate that it is handling the transform.
    If it's set, consider the transformed size of the screen but don't
    actually enable the shadow layer.  Also stop adjusting the cursor
    image and position.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 68a968c..0d7a6a6 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2006 Keith Packard
+ * Copyright © 2011 Aaron Plattner
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -223,7 +224,7 @@ typedef struct _xf86CrtcFuncs {
 
 } xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
 
-#define XF86_CRTC_VERSION 3
+#define XF86_CRTC_VERSION 4
 
 struct _xf86Crtc {
     /**
@@ -361,6 +362,19 @@ struct _xf86Crtc {
      * Clear the shadow
      */
     Bool	    shadowClear;
+
+    /**
+     * Indicates that the driver is handling the transform, so the shadow
+     * surface should be disabled.  The driver writes this field before calling
+     * xf86CrtcRotate to indicate that it is handling the transform (including
+     * rotation and reflection).
+     *
+     * Setting this flag also causes the server to stop adjusting the cursor
+     * image and position.
+     *
+     * Added in ABI version 4
+     */
+    Bool	    driverIsPerformingTransform;
 };
 
 typedef struct _xf86OutputFuncs {
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index 23c48eb..02dea5c 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2007 Keith Packard
- * Copyright © 2010 Aaron Plattner
+ * Copyright © 2010-2011 Aaron Plattner
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -47,6 +47,18 @@
 #include "inputstr.h"
 
 /*
+ * Returns the rotation being performed by the server.  If the driver indicates
+ * that it's handling the screen transform, then this returns RR_Rotate_0.
+ */
+static Rotation
+xf86_crtc_cursor_rotation (xf86CrtcPtr crtc)
+{
+    if (crtc->driverIsPerformingTransform)
+	return RR_Rotate_0;
+    return crtc->rotation;
+}
+
+/*
  * Given a screen coordinate, rotate back to a cursor source coordinate
  */
 static void
@@ -214,6 +226,7 @@ xf86_crtc_convert_cursor_to_argb (xf86CrtcPtr crtc, unsigned char *src)
     int			xin, yin;
     int			flags = cursor_info->Flags;
     CARD32		bits;
+    const Rotation	rotation = xf86_crtc_cursor_rotation(crtc);
 
 #ifdef ARGB_CURSOR
     crtc->cursor_argb = FALSE;
@@ -222,7 +235,7 @@ xf86_crtc_convert_cursor_to_argb (xf86CrtcPtr crtc, unsigned char *src)
     for (y = 0; y < cursor_info->MaxHeight; y++)
 	for (x = 0; x < cursor_info->MaxWidth; x++) 
 	{
-	    xf86_crtc_rotate_coord (crtc->rotation,
+	    xf86_crtc_rotate_coord (rotation,
 				    cursor_info->MaxWidth,
 				    cursor_info->MaxHeight,
 				    x, y, &xin, &yin);
@@ -338,7 +351,7 @@ xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
     /*
      * Transform position of cursor on screen
      */
-    if (crtc->transform_in_use)
+    if (crtc->transform_in_use && !crtc->driverIsPerformingTransform)
     {
 	ScreenPtr	screen = scrn->pScreen;
 	xf86CursorScreenPtr ScreenPriv =
@@ -420,12 +433,13 @@ xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src)
     xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
     xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
     CARD8		*cursor_image;
+    const Rotation	rotation = xf86_crtc_cursor_rotation(crtc);
 
 #ifdef ARGB_CURSOR
     crtc->cursor_argb = FALSE;
 #endif
 
-    if (crtc->rotation == RR_Rotate_0)
+    if (rotation == RR_Rotate_0)
 	cursor_image = src;
     else
     {
@@ -439,7 +453,7 @@ xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src)
         for (y = 0; y < cursor_info->MaxHeight; y++)
 	    for (x = 0; x < cursor_info->MaxWidth; x++) 
 	    {
-		xf86_crtc_rotate_coord (crtc->rotation,
+		xf86_crtc_rotate_coord (rotation,
 					cursor_info->MaxWidth,
 					cursor_info->MaxHeight,
 					x, y, &xin, &yin);
@@ -532,12 +546,13 @@ xf86_crtc_load_cursor_argb (xf86CrtcPtr crtc, CursorPtr cursor)
     int			source_height = cursor->bits->height;
     int			image_width = cursor_info->MaxWidth;
     int			image_height = cursor_info->MaxHeight;
-    
+    const Rotation	rotation = xf86_crtc_cursor_rotation(crtc);
+
     for (y = 0; y < image_height; y++)
 	for (x = 0; x < image_width; x++)
 	{
-	    xf86_crtc_rotate_coord (crtc->rotation, image_width, image_height,
-				    x, y, &xin, &yin);
+	    xf86_crtc_rotate_coord (rotation, image_width, image_height, x, y,
+				    &xin, &yin);
 	    if (xin < source_width && yin < source_height)
 		bits = cursor_source[yin * source_width + xin];
 	    else
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 57c3499..45aabf0 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2006 Keith Packard
+ * Copyright © 2011 Aaron Plattner
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -84,7 +85,10 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crtc, RegionPtr region)
     int			n = RegionNumRects(region);
     BoxPtr		b = RegionRects(region);
     XID			include_inferiors = IncludeInferiors;
-    
+
+    if (crtc->driverIsPerformingTransform)
+	return;
+
     src = CreatePicture (None,
 			 &root->drawable,
 			 format,
@@ -290,7 +294,7 @@ xf86RotateDestroy (xf86CrtcPtr crtc)
     }
 
     for (c = 0; c < xf86_config->num_crtc; c++)
-	if (xf86_config->crtc[c]->transform_in_use)
+	if (xf86_config->crtc[c]->rotatedData)
 	    return;
 
     /*
@@ -414,52 +418,73 @@ xf86CrtcRotate (xf86CrtcPtr crtc)
     }
     else
     {
-	/*
-	 * these are the size of the shadow pixmap, which
-	 * matches the mode, not the pre-rotated copy in the
-	 * frame buffer
-	 */
-	int	    width = crtc->mode.HDisplay;
-	int	    height = crtc->mode.VDisplay;
-	void	    *shadowData = crtc->rotatedData;
-	PixmapPtr   shadow = crtc->rotatedPixmap;
-	int	    old_width = shadow ? shadow->drawable.width : 0;
-	int	    old_height = shadow ? shadow->drawable.height : 0;
-
-	/* Allocate memory for rotation */
-	if (old_width != width || old_height != height)
-	{
-	    if (shadow || shadowData)
+	if (crtc->driverIsPerformingTransform) {
+	    xf86RotateDestroy(crtc);
+	} else {
+	    /*
+	     * these are the size of the shadow pixmap, which
+	     * matches the mode, not the pre-rotated copy in the
+	     * frame buffer
+	     */
+	    int		width = crtc->mode.HDisplay;
+	    int		height = crtc->mode.VDisplay;
+	    void	*shadowData = crtc->rotatedData;
+	    PixmapPtr	shadow = crtc->rotatedPixmap;
+	    int		old_width = shadow ? shadow->drawable.width : 0;
+	    int		old_height = shadow ? shadow->drawable.height : 0;
+
+	    /* Allocate memory for rotation */
+	    if (old_width != width || old_height != height)
 	    {
-		crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
-		crtc->rotatedPixmap = NULL;
-		crtc->rotatedData = NULL;
+		if (shadow || shadowData)
+		{
+		    crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
+		    crtc->rotatedPixmap = NULL;
+		    crtc->rotatedData = NULL;
+		}
+		shadowData = crtc->funcs->shadow_allocate (crtc, width, height);
+		if (!shadowData)
+		    goto bail1;
+		crtc->rotatedData = shadowData;
+		/* shadow will be damaged in xf86RotatePrepare */
+	    }
+	    else
+	    {
+		/* mark shadowed area as damaged so it will be repainted */
+		damage = TRUE;
 	    }
-	    shadowData = crtc->funcs->shadow_allocate (crtc, width, height);
-	    if (!shadowData)
-		goto bail1;
-	    crtc->rotatedData = shadowData;
-	    /* shadow will be damaged in xf86RotatePrepare */
-	}
-	else
-	{
-	    /* mark shadowed area as damaged so it will be repainted */
-	    damage = TRUE;
-	}
 
-	if (!xf86_config->rotation_damage)
-	{
-	    /* Create damage structure */
-	    xf86_config->rotation_damage = DamageCreate (NULL, NULL,
-						DamageReportNone,
-						TRUE, pScreen, pScreen);
 	    if (!xf86_config->rotation_damage)
-		goto bail2;
-	    
-	    /* Wrap block handler */
-	    if (!xf86_config->BlockHandler) {
-		xf86_config->BlockHandler = pScreen->BlockHandler;
-		pScreen->BlockHandler = xf86RotateBlockHandler;
+	    {
+		/* Create damage structure */
+		xf86_config->rotation_damage = DamageCreate (NULL, NULL,
+						    DamageReportNone,
+						    TRUE, pScreen, pScreen);
+		if (!xf86_config->rotation_damage)
+		    goto bail2;
+
+		/* Wrap block handler */
+		if (!xf86_config->BlockHandler) {
+		    xf86_config->BlockHandler = pScreen->BlockHandler;
+		    pScreen->BlockHandler = xf86RotateBlockHandler;
+		}
+	    }
+
+	    if (0)
+	    {
+	bail2:
+		if (shadow || shadowData)
+		{
+		    crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
+		    crtc->rotatedPixmap = NULL;
+		    crtc->rotatedData = NULL;
+		}
+	bail1:
+		if (old_width && old_height)
+		    crtc->rotatedPixmap =
+			crtc->funcs->shadow_create (crtc, NULL, old_width,
+						    old_height);
+		return FALSE;
 	    }
 	}
 #ifdef RANDR_12_INTERFACE
@@ -482,24 +507,6 @@ xf86CrtcRotate (xf86CrtcPtr crtc)
 	    }
 	}
 #endif
-
-	if (0)
-	{
-    bail2:
-	    if (shadow || shadowData)
-	    {
-		crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
-		crtc->rotatedPixmap = NULL;
-		crtc->rotatedData = NULL;
-	    }
-    bail1:
-	    if (old_width && old_height)
-		crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
-								  NULL,
-								  old_width,
-								  old_height);
-	    return FALSE;
-	}
 	crtc->transform_in_use = TRUE;
     }
     crtc->crtc_to_framebuffer = crtc_to_fb;
commit e089737fb13868bd3a72b7ac4799d502d188f03e
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Oct 3 11:23:16 2011 -0700

    Add AC_LANG_SOURCE wrappers around configure.ac code fragments
    
    Current autoconf versions are very unhappy when code fragments are not
    wrapped in AC_LANG_SOURCE macros, generating errors like:
    
    configure.ac:723: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
    ../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
    ../../lib/autoconf/general.m4:2662: _AC_LINK_IFELSE is expanded from...
    ../../lib/autoconf/general.m4:2679: AC_LINK_IFELSE is expanded from...
    ../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
    ../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
    ../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
    configure.ac:723: the top level
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index b0d2643..60ebbcb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -723,7 +723,7 @@ case $host_os in
 			AC_CACHE_CHECK([whether to build Xquartz],xorg_cv_Carbon_framework,[
 		 		save_LDFLAGS=$LDFLAGS
 				LDFLAGS="$LDFLAGS -framework Carbon"
-				AC_LINK_IFELSE([char FSFindFolder(); int main() { FSFindFolder(); return 0;}],
+				AC_LINK_IFELSE([AC_LANG_SOURCE([char FSFindFolder(); int main() { FSFindFolder(); return 0;}])],
 				               [xorg_cv_Carbon_framework=yes],
 				               [xorg_cv_Carbon_framework=no])
 			        LDFLAGS=$save_LDFLAGS])
@@ -874,12 +874,12 @@ AC_DEFINE_UNQUOTED([USE_SIGIO_BY_DEFAULT], [$USE_SIGIO_BY_DEFAULT_VALUE],
 		   [Use SIGIO handlers for input device events by default])
 
 AC_MSG_CHECKING([for glibc...])
-AC_PREPROC_IFELSE([
+AC_PREPROC_IFELSE([AC_LANG_SOURCE([
 #include <features.h>
 #ifndef __GLIBC__
 #error
 #endif
-], glibc=yes, glibc=no)
+])], glibc=yes, glibc=no)
 AC_MSG_RESULT([$glibc])
 
 AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes],
@@ -903,7 +903,7 @@ if ! test "x$have_clock_gettime" = xno; then
         CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200112L"
     fi
 
-    AC_RUN_IFELSE([
+    AC_RUN_IFELSE([AC_LANG_SOURCE([
 #include <time.h>
 
 int main(int argc, char *argv[[]]) {
@@ -914,7 +914,7 @@ int main(int argc, char *argv[[]]) {
     else
         return 1;
 }
-    ], [MONOTONIC_CLOCK=yes], [MONOTONIC_CLOCK=no],
+    ])], [MONOTONIC_CLOCK=yes], [MONOTONIC_CLOCK=no],
        [MONOTONIC_CLOCK="cross compiling"])
 
     LIBS="$LIBS_SAVE"
commit 524e5445c0b6df5247d4aac5368470bb89ef4080
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Oct 1 08:43:52 2011 -0700

    Add #include "inpututils.h" to xkbAccessX.c for init_device_event
    
    Fixes Sun compiler warning:
    "xkbAccessX.c", line 128: warning: implicit function declaration: init_device_event
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 4115ff2..d246827 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -37,6 +37,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "inputstr.h"
 #include "eventstr.h"
+#include "inpututils.h"
 #include <xkbsrv.h>
 #if !defined(WIN32)
 #include <sys/time.h>
commit f32c827d513c44f07e1d0fbcc0c96cef18c9a4d9
Author: Max Schwarz <Max at x-quadraht.de>
Date:   Sun Sep 25 20:44:26 2011 +0200

    Input: Fix frac calculation on [Raw]DeviceEvent conversion
    
    (1UL << 32) evaluates to 0 (at least here), so do the
    fraction calculation in two steps as in libXi. Fractions on xXIRawEvent
    were not multiplied at all, which also gave 0 as result.
    
    Signed-off-by: Max Schwarz <Max at x-quadraht.de>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 9cc177e..f9aafa5 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -635,7 +635,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
             SetBit(ptr, i);
             axisval->integral = trunc(ev->valuators.data[i]);
             axisval->frac = (ev->valuators.data[i] - axisval->integral) *
-                            (1UL << 32);
+                            (1 << 16) * (1 << 16);
             axisval++;
         }
     }
@@ -679,10 +679,12 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
         {
             SetBit(ptr, i);
             axisval->integral = trunc(ev->valuators.data[i]);
-            axisval->frac = ev->valuators.data[i] - axisval->integral;
+            axisval->frac = (ev->valuators.data[i] - axisval->integral) *
+                            (1 << 16) * (1 << 16);
             axisval_raw->integral = trunc(ev->valuators.data_raw[i]);
-            axisval_raw->frac = ev->valuators.data_raw[i] -
-                                axisval_raw->integral;
+            axisval_raw->frac =
+                (ev->valuators.data_raw[i] - axisval_raw->integral) *
+                  (1 << 16) * (1 << 16);
             axisval++;
             axisval_raw++;
         }
commit 4c6bc0e76599dbe5ede2e1f48c9936a0e996b638
Merge: 057cc92... 3304bbf...
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Sep 30 09:24:56 2011 +1000

    Merge branch 'smooth-scrolling' into next

commit 3304bbff9b4ed63f1a47410a5320a136420ba2c6
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Feb 15 18:49:58 2011 +0000

    Input: Add smooth-scrolling support to GetPointerEvents
    
    For scroll wheel support, we used to send buttons 4/5 and 6/7 for
    horizontal/vertical positive/negative scroll events.  For touchpads, we
    really want more fine-grained scroll values.  GetPointerEvents now
    accepts both old-school scroll button presses, and new-style scroll axis
    events, while emitting both types of events to support both old and new
    clients.
    
    This works with the new XIScrollClass to mark axes as scrolling axes.
    Drivers mark any valuators that send scroll events with SetScrollValuator.
    (Currently missing: the XIDeviceChangeEvent being sent when a driver changes
    a scroll axis at run-time. This can be added later.)
    
    Note: the SCROLL_TYPE enums are intentionally different values to the XI2
    proto values to avoid copy/overlapping range bugs.
    
    Co-authored-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-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 a6455e6..74a78ec 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1091,6 +1091,55 @@ InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int
     if (mode & OutOfProximity)
         dev->proximity->in_proximity = FALSE;
 
+    return SetScrollValuator(dev, axnum, SCROLL_TYPE_NONE, 0, SCROLL_FLAG_NONE);
+}
+
+/**
+ * Set the given axis number as a scrolling valuator.
+ */
+Bool
+SetScrollValuator(DeviceIntPtr dev, int axnum, enum ScrollType type, double increment, int flags)
+{
+    AxisInfoPtr ax;
+    int *current_ax;
+
+    if (!dev || !dev->valuator || axnum >= dev->valuator->numAxes)
+        return FALSE;
+
+    switch (type)
+    {
+        case SCROLL_TYPE_VERTICAL:
+            current_ax = &dev->valuator->v_scroll_axis;
+            break;
+        case SCROLL_TYPE_HORIZONTAL:
+            current_ax = &dev->valuator->h_scroll_axis;
+            break;
+        case SCROLL_TYPE_NONE:
+            ax = &dev->valuator->axes[axnum];
+            ax->scroll.type = type;
+            return TRUE;
+        default:
+            return FALSE;
+    }
+
+    if (increment == 0.0)
+        return FALSE;
+
+    if (*current_ax != -1 && axnum != *current_ax)
+    {
+        ax = &dev->valuator->axes[*current_ax];
+        if (ax->scroll.type == type &&
+            (flags & SCROLL_FLAG_PREFERRED) && (ax->scroll.flags & SCROLL_FLAG_PREFERRED))
+            return FALSE;
+    }
+    *current_ax = axnum;
+
+    ax = &dev->valuator->axes[axnum];
+    ax->scroll.type = type;
+    ax->scroll.increment = increment;
+    ax->scroll.flags = flags;
+    /* FIXME: generate DeviceChanged Events */
+
     return TRUE;
 }
 
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 902eb91..9961d1b 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -229,7 +229,16 @@ SizeDeviceClasses(DeviceIntPtr dev)
     }
 
     if (dev->valuator)
-        len += sizeof(xXIValuatorInfo) * dev->valuator->numAxes;
+    {
+        int i;
+        len += (sizeof(xXIValuatorInfo)) * dev->valuator->numAxes;
+
+        for (i = 0; i < dev->valuator->numAxes; i++) {
+            if (dev->valuator->axes[i].scroll.type != SCROLL_TYPE_NONE)
+                len += sizeof(xXIScrollInfo);
+        }
+    }
+
 
     return len;
 }
@@ -369,6 +378,56 @@ SwapValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info)
     swaps(&info->sourceid);
 }
 
+int
+ListScrollInfo(DeviceIntPtr dev, xXIScrollInfo *info, int axisnumber)
+{
+    ValuatorClassPtr v = dev->valuator;
+    AxisInfoPtr axis = &v->axes[axisnumber];
+
+    if (axis->scroll.type == SCROLL_TYPE_NONE)
+        return 0;
+
+    info->type = XIScrollClass;
+    info->length = sizeof(xXIScrollInfo)/4;
+    info->number = axisnumber;
+    switch(axis->scroll.type)
+    {
+        case SCROLL_TYPE_VERTICAL:
+            info->scroll_type = XIScrollTypeVertical;
+            break;
+        case SCROLL_TYPE_HORIZONTAL:
+            info->scroll_type = XIScrollTypeHorizontal;
+            break;
+        default:
+            ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n", axis->scroll.type);
+            break;
+    }
+    info->increment.integral = (int)axis->scroll.increment;
+    info->increment.frac = (unsigned int)(axis->scroll.increment * (1UL << 16) * (1UL << 16));
+    info->sourceid = v->sourceid;
+
+    info->flags = 0;
+
+    if (axis->scroll.flags & SCROLL_FLAG_DONT_EMULATE)
+        info->flags |= XIScrollFlagNoEmulation;
+    if (axis->scroll.flags & SCROLL_FLAG_PREFERRED)
+        info->flags |= XIScrollFlagPreferred;
+
+    return info->length * 4;
+}
+
+static void
+SwapScrollInfo(DeviceIntPtr dev, xXIScrollInfo* info)
+{
+    swaps(&info->type);
+    swaps(&info->length);
+    swaps(&info->number);
+    swaps(&info->sourceid);
+    swaps(&info->scroll_type);
+    swapl(&info->increment.integral);
+    swapl(&info->increment.frac);
+}
+
 int GetDeviceUse(DeviceIntPtr dev, uint16_t *attachment)
 {
     DeviceIntPtr master = GetMaster(dev, MASTER_ATTACHED);
@@ -458,6 +517,15 @@ ListDeviceClasses(ClientPtr client, DeviceIntPtr dev,
         total_len += len;
     }
 
+    for (i = 0; dev->valuator && i < dev->valuator->numAxes; i++)
+    {
+        len = ListScrollInfo(dev, (xXIScrollInfo*)any, i);
+        if (len)
+            (*nclasses)++;
+        any += len;
+        total_len += len;
+    }
+
     return total_len;
 }
 
@@ -484,6 +552,9 @@ SwapDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info)
             case XIValuatorClass:
                 SwapValuatorInfo(dev, (xXIValuatorInfo*)any);
                 break;
+            case XIScrollClass:
+                SwapScrollInfo(dev, (xXIScrollInfo*)any);
+                break;
         }
 
         any += len * 4;
diff --git a/Xi/xiquerydevice.h b/Xi/xiquerydevice.h
index 02f0659..9db6aa2 100644
--- a/Xi/xiquerydevice.h
+++ b/Xi/xiquerydevice.h
@@ -44,4 +44,5 @@ int ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info, Bool reportState);
 int ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info);
 int ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info,
 		     int axisnumber, Bool reportState);
+int ListScrollInfo(DeviceIntPtr dev, xXIScrollInfo* info, int axisnumber);
 #endif /* QUERYDEV_H */
diff --git a/dix/devices.c b/dix/devices.c
index ab8a648..64557aa 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -260,6 +260,8 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
 					  offsetof(DeviceIntRec, devPrivates), PRIVATE_DEVICE);
     if (!dev)
 	return (DeviceIntPtr)NULL;
+
+    dev->last.scroll = NULL;
     dev->id = devid;
     dev->public.processInputProc = ProcessOtherEvent;
     dev->public.realInputProc = ProcessOtherEvent;
@@ -939,6 +941,7 @@ CloseDevice(DeviceIntPtr dev)
 
     free(dev->deviceGrab.sync.event);
     free(dev->config_info);     /* Allocated in xf86ActivateDevice. */
+    free(dev->last.scroll);
     dev->config_info = NULL;
     dixFreeObjectWithPrivates(dev, PRIVATE_DEVICE);
 }
@@ -1277,10 +1280,19 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
     if (!valc)
         return FALSE;
 
+    dev->last.scroll = valuator_mask_new(numAxes);
+    if (!dev->last.scroll)
+    {
+        free(valc);
+        return FALSE;
+    }
+
     valc->sourceid = dev->id;
     valc->motion = NULL;
     valc->first_motion = 0;
     valc->last_motion = 0;
+    valc->h_scroll_axis = -1;
+    valc->v_scroll_axis = -1;
 
     valc->numMotionEvents = numMotionEvents;
     valc->motionHintWindow = NullWindow;
diff --git a/dix/getevents.c b/dix/getevents.c
index 45243df..c429715 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -2,6 +2,7 @@
  * Copyright © 2006 Nokia Corporation
  * Copyright © 2006-2007 Daniel Stone
  * Copyright © 2008 Red Hat, Inc.
+ * Copyright © 2011 The Chromium Authors
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -603,8 +604,10 @@ GetMaximumEventsNum(void) {
     /* One raw event
      * One device event
      * One possible device changed event
+     * Lots of possible separate button scroll events (horiz + vert)
+     * Lots of possible separate raw button scroll events (horiz + vert)
      */
-    return 3;
+    return 100;
 }
 
 
@@ -1171,6 +1174,95 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
 }
 
 /**
+ * Generate events for each scroll axis that changed between before/after
+ * for the device.
+ *
+ * @param events The pointer to the event list to fill the events
+ * @param dev The device to generate the events for
+ * @param axis The axis number to generate events for
+ * @param mask State before this event in absolute coords
+ * @param[in,out] last Last scroll state posted in absolute coords (modified
+ * in-place)
+ * @param ms Current time in ms
+ * @param max_events Max number of events to be generated
+ * @return The number of events generated
+ */
+static int
+emulate_scroll_button_events(InternalEvent *events,
+                             DeviceIntPtr dev,
+                             int axis,
+                             const ValuatorMask *mask,
+                             ValuatorMask *last,
+                             CARD32 ms,
+                             int max_events)
+{
+    AxisInfoPtr ax;
+    double delta;
+    double incr;
+    int num_events = 0;
+    double total;
+    int b;
+
+    if (dev->valuator->axes[axis].scroll.type == SCROLL_TYPE_NONE)
+        return 0;
+
+    if (!valuator_mask_isset(mask, axis))
+        return 0;
+
+    ax = &dev->valuator->axes[axis];
+    incr = ax->scroll.increment;
+
+    if (!valuator_mask_isset(last, axis))
+        valuator_mask_set_double(last, axis, 0);
+
+    delta = valuator_mask_get_double(mask, axis) - valuator_mask_get_double(last, axis);
+    total = delta;
+    b = (ax->scroll.type == SCROLL_TYPE_VERTICAL) ? 5 : 7;
+
+    if ((incr > 0 && delta < 0) ||
+        (incr < 0 && delta > 0))
+        b--; /* we're scrolling up or left → button 4 or 6 */
+
+    while (fabs(delta) >= fabs(incr))
+    {
+        int nev_tmp;
+
+        if (delta > 0)
+            delta -= fabs(incr);
+        else if (delta < 0)
+            delta += fabs(incr);
+
+        /* fill_pointer_events() generates four events: one normal and one raw
+         * event for button press and button release.
+         * We may get a bigger scroll delta than we can generate events
+         * for. In that case, we keep decreasing delta, but skip events.
+         */
+        if (num_events + 4 < max_events)
+        {
+            nev_tmp = fill_pointer_events(events, dev, ButtonPress, b, ms,
+                                          POINTER_EMULATED, NULL);
+            events += nev_tmp;
+            num_events += nev_tmp;
+            nev_tmp = fill_pointer_events(events, dev, ButtonRelease, b, ms,
+                                          POINTER_EMULATED, NULL);
+            events += nev_tmp;
+            num_events += nev_tmp;
+        }
+    }
+
+    /* We emulated, update last.scroll */
+    if (total != delta)
+    {
+        total -= delta;
+        valuator_mask_set_double(last, axis,
+                                 valuator_mask_get_double(last, axis) + total);
+    }
+
+    return num_events;
+}
+
+
+/**
  * Generate a complete series of InternalEvents (filled into the EventList)
  * representing pointer motion, or button presses.  If the device is a slave
  * device, also potentially generate a DeviceClassesChangedEvent to update
@@ -1193,7 +1285,12 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
                  int buttons, int flags, const ValuatorMask *mask_in)
 {
     CARD32 ms = GetTimeInMillis();
-    int num_events = 0;
+    int num_events = 0, nev_tmp;
+    int h_scroll_axis = pDev->valuator->h_scroll_axis;
+    int v_scroll_axis = pDev->valuator->v_scroll_axis;
+    ValuatorMask mask;
+    ValuatorMask scroll;
+    int i;
 
     /* refuse events from disabled devices */
     if (!pDev->enabled)
@@ -1204,8 +1301,73 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
 
     events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT,
                               &num_events);
-    num_events += fill_pointer_events(events, pDev, type, buttons, ms, flags,
-                                      mask_in);
+
+    valuator_mask_copy(&mask, mask_in);
+
+    /* Turn a scroll button press into a smooth-scrolling event if
+     * necessary. This only needs to cater for the XIScrollFlagPreferred
+     * axis (if more than one scrolling axis is present) */
+    if (type == ButtonPress)
+    {
+        double val, adj;
+        int axis;
+
+        switch (buttons) {
+        case 4:
+            adj = 1.0;
+            axis = v_scroll_axis;
+            break;
+        case 5:
+            adj = -1.0;
+            axis = v_scroll_axis;
+            break;
+        case 6:
+            adj = 1.0;
+            axis = h_scroll_axis;
+            break;
+        case 7:
+            adj = -1.0;
+            axis = h_scroll_axis;
+            break;
+        default:
+            adj = 0.0;
+            axis = -1;
+            break;
+        }
+
+        if (adj != 0.0 && axis != -1)
+        {
+            adj *= pDev->valuator->axes[axis].scroll.increment;
+            val = valuator_mask_get_double(&mask, axis) + adj;
+            valuator_mask_set_double(&mask, axis, val);
+            type = MotionNotify;
+            buttons = 0;
+        }
+    }
+
+    /* First fill out the original event set, with smooth-scrolling axes. */
+    nev_tmp = fill_pointer_events(events, pDev, type, buttons, ms, flags,
+                                  &mask);
+    events += nev_tmp;
+    num_events += nev_tmp;
+
+    valuator_mask_zero(&scroll);
+
+    /* Now turn the smooth-scrolling axes back into emulated button presses
+     * for legacy clients, based on the integer delta between before and now */
+    for (i = 0; i < valuator_mask_size(&mask); i++) {
+        if (!valuator_mask_isset(&mask, i))
+            continue;
+
+        valuator_mask_set_double(&scroll, i, pDev->last.valuators[i]);
+
+        nev_tmp = emulate_scroll_button_events(events, pDev, i, &scroll,
+                                               pDev->last.scroll, ms,
+                                               GetMaximumEventsNum() - num_events);
+        events += nev_tmp;
+        num_events += nev_tmp;
+    }
+
     return num_events;
 }
 
diff --git a/include/exevents.h b/include/exevents.h
index 731f31e..4fe6c61 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -37,6 +37,22 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *              Interface available to drivers                 *
  ***************************************************************/
 
+/**
+ * Scroll flags for ::SetScrollValuator.
+ */
+enum ScrollFlags {
+    SCROLL_FLAG_NONE            = 0,
+    /**
+     * Do not emulate legacy button events for valuator events on this axis.
+     */
+    SCROLL_FLAG_DONT_EMULATE    = (1 << 1),
+    /**
+     * This axis is the preferred axis for valuator emulation for this axis'
+     * scroll type.
+     */
+    SCROLL_FLAG_PREFERRED       = (1 << 2)
+};
+
 extern _X_EXPORT int InitProximityClassDeviceStruct(
 	DeviceIntPtr           /* dev */);
 
@@ -51,6 +67,13 @@ extern _X_EXPORT Bool InitValuatorAxisStruct(
 	int                    /* max_res */,
 	int                    /* mode */);
 
+extern _X_EXPORT Bool SetScrollValuator(
+	DeviceIntPtr           /* dev */,
+	int                    /* axnum */,
+	enum ScrollType        /* type */,
+	double                 /* increment */,
+	int                    /* flags */);
+
 /* Input device properties */
 extern _X_EXPORT void XIDeleteAllDeviceProperties(
         DeviceIntPtr            /* device */
diff --git a/include/inputstr.h b/include/inputstr.h
index c25f5c6..9d4108e 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -75,6 +75,16 @@ extern _X_EXPORT int CountBits(const uint8_t *mask, int len);
 #define XI2MASKSIZE     ((XI2LASTEVENT + 7)/8) /* no of bits for masks */
 
 /**
+ * Scroll types for ::SetScrollValuator and the scroll type in the
+ * ::ScrollInfoPtr.
+ */
+enum ScrollType {
+    SCROLL_TYPE_NONE = 0,           /**< Not a scrolling valuator */
+    SCROLL_TYPE_VERTICAL = 8,
+    SCROLL_TYPE_HORIZONTAL = 9,
+};
+
+/**
  * This struct stores the core event mask for each client except the client
  * that created the window.
  *
@@ -252,6 +262,12 @@ typedef struct _KeyClassRec {
     struct _XkbSrvInfo *xkbInfo;
 } KeyClassRec, *KeyClassPtr;
 
+typedef struct _ScrollInfo {
+    enum ScrollType	type;
+    double		increment;
+    int			flags;
+} ScrollInfo, *ScrollInfoPtr;
+
 typedef struct _AxisInfo {
     int		resolution;
     int		min_resolution;
@@ -260,6 +276,7 @@ typedef struct _AxisInfo {
     int		max_value;
     Atom	label;
     CARD8	mode;
+    ScrollInfo  scroll;
 } AxisInfo, *AxisInfoPtr;
 
 typedef struct _ValuatorAccelerationRec {
@@ -283,6 +300,8 @@ typedef struct _ValuatorClassRec {
     unsigned short	  numAxes;
     double		  *axisVal; /* always absolute, but device-coord system */
     ValuatorAccelerationRec	accelScheme;
+    int                   h_scroll_axis; /* horiz smooth-scrolling axis */
+    int                   v_scroll_axis; /* vert smooth-scrolling axis */
 } ValuatorClassRec;
 
 typedef struct _ButtonClassRec {
@@ -524,6 +543,7 @@ typedef struct _DeviceIntRec {
         double          valuators[MAX_VALUATORS];
         int             numValuators;
         DeviceIntPtr    slave;
+        ValuatorMask    *scroll;
     } last;
 
     /* Input device property handling. */
diff --git a/test/input.c b/test/input.c
index 2501d59..afc4d4d 100644
--- a/test/input.c
+++ b/test/input.c
@@ -52,6 +52,7 @@ static void dix_init_valuators(void)
 {
     DeviceIntRec dev;
     ValuatorClassPtr val;
+    AxisInfoPtr axis;
     const int num_axes = 2;
     int i;
     Atom atoms[MAX_VALUATORS] = { 0 };
@@ -78,6 +79,62 @@ static void dix_init_valuators(void)
     }
 
     assert(dev.last.numValuators == num_axes);
+
+    /* invalid increment */
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_VERTICAL, 0.0, SCROLL_FLAG_NONE) == FALSE);
+    /* invalid type */
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_VERTICAL - 1, 1.0, SCROLL_FLAG_NONE) == FALSE);
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_HORIZONTAL + 1, 1.0, SCROLL_FLAG_NONE) == FALSE);
+    /* invalid axisnum */
+    assert(SetScrollValuator(&dev, 2, SCROLL_TYPE_HORIZONTAL, 1.0, SCROLL_FLAG_NONE) == FALSE);
+
+    /* valid */
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_VERTICAL, 3.0, SCROLL_FLAG_NONE) == TRUE);
+    axis = &dev.valuator->axes[0];
+    assert(axis->scroll.increment == 3.0);
+    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
+    assert(axis->scroll.flags == 0);
+
+    /* valid */
+    assert(SetScrollValuator(&dev, 1, SCROLL_TYPE_HORIZONTAL, 2.0, SCROLL_FLAG_NONE) == TRUE);
+    axis = &dev.valuator->axes[1];
+    assert(axis->scroll.increment == 2.0);
+    assert(axis->scroll.type == SCROLL_TYPE_HORIZONTAL);
+    assert(axis->scroll.flags == 0);
+
+    /* can add another non-preffered axis */
+    assert(SetScrollValuator(&dev, 1, SCROLL_TYPE_VERTICAL, 5.0, SCROLL_FLAG_NONE) == TRUE);
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_HORIZONTAL, 5.0, SCROLL_FLAG_NONE) == TRUE);
+
+    /* can overwrite with Preferred */
+    assert(SetScrollValuator(&dev, 1, SCROLL_TYPE_VERTICAL, 5.5, SCROLL_FLAG_PREFERRED) == TRUE);
+    axis = &dev.valuator->axes[1];
+    assert(axis->scroll.increment == 5.5);
+    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
+    assert(axis->scroll.flags == SCROLL_FLAG_PREFERRED);
+
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_HORIZONTAL, 8.8, SCROLL_FLAG_PREFERRED) == TRUE);
+    axis = &dev.valuator->axes[0];
+    assert(axis->scroll.increment == 8.8);
+    assert(axis->scroll.type == SCROLL_TYPE_HORIZONTAL);
+    assert(axis->scroll.flags == SCROLL_FLAG_PREFERRED);
+
+    /* can overwrite as none */
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_NONE, 5.0,
+                SCROLL_FLAG_NONE) == TRUE);
+    axis = &dev.valuator->axes[0];
+    assert(axis->scroll.type == SCROLL_TYPE_NONE);
+
+    /* can overwrite axis with new settings */
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_VERTICAL, 5.0, SCROLL_FLAG_NONE) == TRUE);
+    axis = &dev.valuator->axes[0];
+    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
+    assert(axis->scroll.increment == 5.0);
+    assert(axis->scroll.flags == SCROLL_FLAG_NONE);
+    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_VERTICAL, 3.0, SCROLL_FLAG_NONE) == TRUE);
+    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
+    assert(axis->scroll.increment == 3.0);
+    assert(axis->scroll.flags == SCROLL_FLAG_NONE);
 }
 
 /* just check the known success cases, and that error cases set the client's
diff --git a/test/xi2/protocol-common.c b/test/xi2/protocol-common.c
index 4234533..56d6bd2 100644
--- a/test/xi2/protocol-common.c
+++ b/test/xi2/protocol-common.c
@@ -29,6 +29,8 @@
 #include "extinit.h" /* for XInputExtensionInit */
 #include "exglobals.h"
 #include "xkbsrv.h" /* for XkbInitPrivates */
+#include "xserver-properties.h"
+#include <X11/extensions/XI2.h>
 
 #include "protocol-common.h"
 
@@ -63,6 +65,65 @@ static void fake_init_sprite(DeviceIntPtr dev)
     sprite->physLimits.y2 = screen.height;
 }
 
+/* This is essentially CorePointerProc with ScrollAxes added */
+static int
+TestPointerProc(DeviceIntPtr pDev, int what)
+{
+#define NBUTTONS 10
+#define NAXES 4
+    BYTE map[NBUTTONS + 1];
+    int i = 0;
+    Atom btn_labels[NBUTTONS] = {0};
+    Atom axes_labels[NAXES] = {0};
+
+    switch (what) {
+    case DEVICE_INIT:
+        for (i = 1; i <= NBUTTONS; i++)
+            map[i] = i;
+
+	btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+	btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+	btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+	btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+	btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+	btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+	btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+	/* don't know about the rest */
+
+	axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+	axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+	axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL);
+	axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HSCROLL);
+
+        if (!InitPointerDeviceStruct((DevicePtr)pDev, map, NBUTTONS, btn_labels,
+                                (PtrCtrlProcPtr)NoopDDA,
+                                GetMotionHistorySize(), NAXES, axes_labels))
+        {
+            ErrorF("Could not initialize device '%s'. Out of memory.\n",
+                   pDev->name);
+            return BadAlloc;
+        }
+        pDev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
+        pDev->last.valuators[0] = pDev->valuator->axisVal[0];
+        pDev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
+        pDev->last.valuators[1] = pDev->valuator->axisVal[1];
+
+        SetScrollValuator(pDev, 2, SCROLL_TYPE_VERTICAL, 2.4, SCROLL_FLAG_NONE);
+        SetScrollValuator(pDev, 3, SCROLL_TYPE_HORIZONTAL, 3.5, SCROLL_FLAG_PREFERRED);
+        break;
+
+    case DEVICE_CLOSE:
+        break;
+
+    default:
+        break;
+    }
+
+    return Success;
+
+#undef NBUTTONS
+#undef NAXES
+}
 /**
  * Create and init 2 master devices (VCP + VCK) and two slave devices, one
  * default mouse, one default keyboard.
@@ -84,7 +145,7 @@ struct devices init_devices(void)
     EnableDevice(devices.vck, FALSE);
 
     AllocDevicePair(&client, "", &devices.mouse, &devices.kbd,
-                    CorePointerProc, CoreKeyboardProc, FALSE);
+                    TestPointerProc, CoreKeyboardProc, FALSE);
     ActivateDevice(devices.mouse, FALSE);
     ActivateDevice(devices.kbd, FALSE);
     EnableDevice(devices.mouse, FALSE);
diff --git a/test/xi2/protocol-xiquerydevice.c b/test/xi2/protocol-xiquerydevice.c
index 47eb5b1..63d725f 100644
--- a/test/xi2/protocol-xiquerydevice.c
+++ b/test/xi2/protocol-xiquerydevice.c
@@ -127,7 +127,7 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
                 dev = devices.mouse;
                 assert(info->use == XISlavePointer);
                 assert(info->attachment == devices.vcp->id);
-                assert(info->num_classes == 3); /* 2 axes + button */
+                assert(info->num_classes == 7); /* 4 axes + button + 2 scroll*/
                 break;
             case 5:  /* keyboard */
                 dev = devices.kbd;
@@ -183,11 +183,48 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
                         }
                         break;
                     }
-                case 2: /* VCP and mouse have the same properties */
                 case 4:
                     {
                         assert(any->type == XIButtonClass ||
-                                any->type == XIValuatorClass);
+                               any->type == XIValuatorClass ||
+                               any->type == XIScrollClass);
+
+                        if (any->type == XIScrollClass)
+                        {
+                            xXIScrollInfo *si = (xXIScrollInfo*)any;
+
+                            if (client->swapped)
+                            {
+                                swaps(&si->number);
+                                swaps(&si->scroll_type);
+                                swapl(&si->increment.integral);
+                                swapl(&si->increment.frac);
+                            }
+                            assert(si->length == 6);
+                            assert(si->number == 2 || si->number == 3);
+                            if (si->number == 2) {
+                                assert(si->scroll_type == XIScrollTypeVertical);
+                                assert(!si->flags);
+                            }
+                            if (si->number == 3) {
+                                assert(si->scroll_type == XIScrollTypeHorizontal);
+                                assert(si->flags & XIScrollFlagPreferred);
+                                assert(!(si->flags & ~XIScrollFlagPreferred));
+                            }
+
+                            assert(si->increment.integral == si->number);
+                            /* FIXME: frac testing with float/FP issues? */
+                            assert(si->increment.frac > 0.3  * (1UL << 32));
+                            assert(si->increment.frac < 0.6  * (1UL << 32));
+                        }
+
+                    }
+                    /* fall through */
+                case 2: /* VCP and mouse have the same properties except for scroll */
+                    {
+                        if (info->deviceid == 2 ) /* VCP */
+                            assert(any->type == XIButtonClass ||
+                                   any->type == XIValuatorClass);
 
                         if (any->type == XIButtonClass)
                         {
@@ -217,8 +254,10 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
                             }
 
                             assert(vi->length == 11);
-                            assert(vi->number == 0 ||
-                                     vi->number == 1);
+                            assert(vi->number >= 0 && vi->number < 4);
+                            if (info->deviceid == 2) /* VCP */
+                                assert(vi->number < 2);
+
                             assert(vi->mode == XIModeRelative);
                             /* device was set up as relative, so standard
                              * values here. */
commit 057cc92ebfeebe81b7d01ff2c6aa2c066c8d1a64
Merge: afb1fe6... 52c9b59...
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Sep 29 14:18:35 2011 +1000

    Merge branch 'raw-events' into next
    
    Conflicts:
    	configure.ac
    	dix/events.c

diff --cc configure.ac
index b0d2643,da33c16..58ec3fb
--- a/configure.ac
+++ b/configure.ac
@@@ -778,7 -785,7 +778,7 @@@ 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"
 -SDK_REQUIRED_MODULES="[xproto >= 7.0.17] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 2.0.99.1] [kbproto >= 1.0.3] fontsproto"
++SDK_REQUIRED_MODULES="[xproto >= 7.0.22] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 2.0.99.1] [kbproto >= 1.0.3] fontsproto"
  # Make SDK_REQUIRED_MODULES available for inclusion in xorg-server.pc
  AC_SUBST(SDK_REQUIRED_MODULES)
  
diff --cc dix/events.c
index fbe4fc9,6b74b1a..4e21c2d
--- a/dix/events.c
+++ b/dix/events.c
@@@ -2275,28 -2297,42 +2322,41 @@@ DeliverRawEvent(RawDeviceEvent *ev, Dev
  
      if (grab)
          DeliverGrabbedEvent((InternalEvent*)ev, device, FALSE);
-     else { /* deliver to all root windows */
-         xEvent *xi;
-         int i;
-         int filter;
  
-         i = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
-         if (i != Success)
-         {
-             ErrorF("[Xi] %s: XI2 conversion failed in %s (%d)\n",
-                     __func__, device->name, i);
-             return;
-         }
+     filter = GetEventFilter(device, xi);
+ 
+     for (i = 0; i < screenInfo.numScreens; i++)
+     {
+         WindowPtr root;
+         InputClients *inputclients;
  
-         filter = GetEventFilter(device, xi);
+         root = screenInfo.screens[i]->root;
+         if (!GetClientsForDelivery(device, root, xi, filter, &inputclients))
+             continue;
  
-         for (i = 0; i < screenInfo.numScreens; i++)
-             DeliverEventsToWindow(device, screenInfo.screens[i]->root, xi, 1,
-                                   filter, NullGrab);
-         free(xi);
+         for (; inputclients; inputclients = inputclients->next)
+         {
+             ClientPtr c; /* unused */
+             Mask m;      /* unused */
+             InputClients ic = *inputclients;
+ 
+             /* Because we run through the list manually, copy the actual
+              * list, shorten the copy to only have one client and then pass
+              * that down to DeliverEventToInputClients. This way we avoid
+              * double events on XI 2.1 clients that have a grab on the
+              * device.
+              */
+             ic.next = NULL;
+ 
+             if (!FilterRawEvents(rClient(&ic), grab))
+                 DeliverEventToInputClients(device, &ic, root, xi, 1,
+                                            filter, NULL, &c, &m);
+         }
      }
+ 
+     free(xi);
  }
  
 -
  /* If the event goes to dontClient, don't send it and return 0.  if
     send works,  return 1 or if send didn't work, return 2.
     Only works for core events.
commit 52c9b59a9fed6abfeca775a7a04133cee18eac0b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon May 30 09:47:06 2011 +1000

    dix: use 'rc' for return code in DeliverRawEvent
    
    Reported-by: Walter Harms <wharms at bfs.de>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 2112a47..6b74b1a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2284,14 +2284,14 @@ DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
 {
     GrabPtr grab = device->deviceGrab.grab;
     xEvent *xi;
-    int i;
+    int i, rc;
     int filter;
 
-    i = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
-    if (i != Success)
+    rc = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
+    if (rc != Success)
     {
         ErrorF("[Xi] %s: XI2 conversion failed in %s (%d)\n",
-                __func__, device->name, i);
+                __func__, device->name, rc);
         return;
     }
 
commit b6b1f1b514bf14ddf6b265b8d4551f892ded0dd2
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed May 11 13:56:08 2011 +1000

    input: deliver raw events unconditionally for XI 2.1 clients.
    
    Deliver raw events regardless whether there is a grab on or not for clients
    supporting 2.1 or later.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 8a4c6b9..2112a47 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2243,35 +2243,96 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
     return nondeliveries;
 }
 
+/**
+ * Filter out raw events for XI 2.0 and XI 2.1 clients.
+ *
+ * If there is a grab on the device, 2.0 clients only get raw events if they
+ * have the grab. 2.1+ clients get raw events in all cases.
+ *
+ * @return TRUE if the event should be discarded, FALSE otherwise.
+ */
+static BOOL
+FilterRawEvents(const ClientPtr client, const GrabPtr grab)
+{
+    XIClientPtr client_xi_version;
+    int cmp;
+
+    /* device not grabbed -> don't filter */
+    if (!grab)
+        return FALSE;
+
+    client_xi_version = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
+
+    cmp = version_compare(client_xi_version->major_version,
+                          client_xi_version->minor_version, 2, 0);
+    /* XI 2.0: if device is grabbed, skip
+       XI 2.1: if device is grabbed by us, skip, we've already delivered */
+    return (cmp == 0) ? TRUE : SameClient(grab, client);
+}
+
+/**
+ * Deliver a raw event to the grab owner (if any) and to all root windows.
+ *
+ * Raw event delivery differs between XI 2.0 and XI 2.1.
+ * XI 2.0: events delivered to the grabbing client (if any) OR to all root
+ * windows
+ * XI 2.1: events delivered to all root windows, regardless of grabbing
+ * state.
+ */
 void
 DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
 {
     GrabPtr grab = device->deviceGrab.grab;
+    xEvent *xi;
+    int i;
+    int filter;
+
+    i = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
+    if (i != Success)
+    {
+        ErrorF("[Xi] %s: XI2 conversion failed in %s (%d)\n",
+                __func__, device->name, i);
+        return;
+    }
 
     if (grab)
         DeliverGrabbedEvent((InternalEvent*)ev, device, FALSE);
-    else { /* deliver to all root windows */
-        xEvent *xi;
-        int i;
-        int filter;
 
-        i = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
-        if (i != Success)
-        {
-            ErrorF("[Xi] %s: XI2 conversion failed in %s (%d)\n",
-                    __func__, device->name, i);
-            return;
-        }
+    filter = GetEventFilter(device, xi);
 
-        filter = GetEventFilter(device, xi);
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+        WindowPtr root;
+        InputClients *inputclients;
+
+        root = screenInfo.screens[i]->root;
+        if (!GetClientsForDelivery(device, root, xi, filter, &inputclients))
+            continue;
 
-        for (i = 0; i < screenInfo.numScreens; i++)
-            DeliverEventsToWindow(device, screenInfo.screens[i]->root, xi, 1,
-                                  filter, NullGrab);
-        free(xi);
+        for (; inputclients; inputclients = inputclients->next)
+        {
+            ClientPtr c; /* unused */
+            Mask m;      /* unused */
+            InputClients ic = *inputclients;
+
+            /* Because we run through the list manually, copy the actual
+             * list, shorten the copy to only have one client and then pass
+             * that down to DeliverEventToInputClients. This way we avoid
+             * double events on XI 2.1 clients that have a grab on the
+             * device.
+             */
+            ic.next = NULL;
+
+            if (!FilterRawEvents(rClient(&ic), grab))
+                DeliverEventToInputClients(device, &ic, root, xi, 1,
+                                           filter, NULL, &c, &m);
+        }
     }
+
+    free(xi);
 }
 
+
 /* If the event goes to dontClient, don't send it and return 0.  if
    send works,  return 1 or if send didn't work, return 2.
    Only works for core events.
commit 16244fba001826190445302f56784f5de9c59c01
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jun 2 13:50:13 2011 +1000

    Support (and require) XI 2.1
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/configure.ac b/configure.ac
index 22566c9..da33c16 100644
--- a/configure.ac
+++ b/configure.ac
@@ -785,7 +785,7 @@ WINDOWSWMPROTO="windowswmproto"
 APPLEWMPROTO="applewmproto >= 1.4"
 
 dnl Core modules for most extensions, et al.
-SDK_REQUIRED_MODULES="[xproto >= 7.0.17] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 1.9.99.902] [kbproto >= 1.0.3] fontsproto"
+SDK_REQUIRED_MODULES="[xproto >= 7.0.17] [randrproto >= 1.2.99.3] [renderproto >= 0.11] [xextproto >= 7.1.99] [inputproto >= 2.0.99.1] [kbproto >= 1.0.3] fontsproto"
 # Make SDK_REQUIRED_MODULES available for inclusion in xorg-server.pc
 AC_SUBST(SDK_REQUIRED_MODULES)
 
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 7b7a9f5..832bcf7 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -127,7 +127,7 @@
 
 /* X Input */
 #define SERVER_XI_MAJOR_VERSION			2
-#define SERVER_XI_MINOR_VERSION			0
+#define SERVER_XI_MINOR_VERSION			1
 
 /* XKB */
 #define SERVER_XKB_MAJOR_VERSION		1
commit 54e05d80a122bac57920fce1704c0f57492b849c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri May 27 14:21:39 2011 +1000

    dix: rename ProcessRawEvents to dix/events.c:DeliverRawEvent
    
    No functional changes, prep work for future changes.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 042ea69..3e3c67b 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -876,35 +876,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
     return DEFAULT;
 }
 
-static void
-ProcessRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
-{
-    GrabPtr grab = device->deviceGrab.grab;
-
-    if (grab)
-        DeliverGrabbedEvent((InternalEvent*)ev, device, FALSE);
-    else { /* deliver to all root windows */
-        xEvent *xi;
-        int i;
-        int filter;
-
-        i = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
-        if (i != Success)
-        {
-            ErrorF("[Xi] %s: XI2 conversion failed in %s (%d)\n",
-                    __func__, device->name, i);
-            return;
-        }
-
-        filter = GetEventFilter(device, xi);
-
-        for (i = 0; i < screenInfo.numScreens; i++)
-            DeliverEventsToWindow(device, screenInfo.screens[i]->root, xi, 1,
-                                  filter, NullGrab);
-        free(xi);
-    }
-}
-
 /**
  * Main device event processing function.
  * Called from when processing the events from the event queue.
@@ -932,7 +903,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
         ev->any.type == ET_RawButtonRelease ||
         ev->any.type == ET_RawMotion)
     {
-        ProcessRawEvent(&ev->raw_event, device);
+        DeliverRawEvent(&ev->raw_event, device);
         return;
     }
 
diff --git a/dix/events.c b/dix/events.c
index 9063c28..8a4c6b9 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2243,6 +2243,35 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
     return nondeliveries;
 }
 
+void
+DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
+{
+    GrabPtr grab = device->deviceGrab.grab;
+
+    if (grab)
+        DeliverGrabbedEvent((InternalEvent*)ev, device, FALSE);
+    else { /* deliver to all root windows */
+        xEvent *xi;
+        int i;
+        int filter;
+
+        i = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
+        if (i != Success)
+        {
+            ErrorF("[Xi] %s: XI2 conversion failed in %s (%d)\n",
+                    __func__, device->name, i);
+            return;
+        }
+
+        filter = GetEventFilter(device, xi);
+
+        for (i = 0; i < screenInfo.numScreens; i++)
+            DeliverEventsToWindow(device, screenInfo.screens[i]->root, xi, 1,
+                                  filter, NullGrab);
+        free(xi);
+    }
+}
+
 /* If the event goes to dontClient, don't send it and return 0.  if
    send works,  return 1 or if send didn't work, return 2.
    Only works for core events.
diff --git a/include/dix.h b/include/dix.h
index 9a111e8..b1bf9ed 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -387,6 +387,11 @@ extern _X_EXPORT int DeliverEventsToWindow(
     Mask /* filter */,
     GrabPtr /* grab */);
 
+extern _X_EXPORT void DeliverRawEvent(
+    RawDeviceEvent* /* ev */,
+    DeviceIntPtr /* dev */
+);
+
 extern int DeliverDeviceEvents(
     WindowPtr /* pWin */,
     InternalEvent* /* event */,
commit c48133f133c64d356a1208f185619bfdf7e9a5f2
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri May 27 14:19:45 2011 +1000

    Xi: use temporary variable for filter.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 3b0411d..042ea69 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -886,6 +886,7 @@ ProcessRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
     else { /* deliver to all root windows */
         xEvent *xi;
         int i;
+        int filter;
 
         i = EventToXI2((InternalEvent*)ev, (xEvent**)&xi);
         if (i != Success)
@@ -895,9 +896,11 @@ ProcessRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
             return;
         }
 
+        filter = GetEventFilter(device, xi);
+
         for (i = 0; i < screenInfo.numScreens; i++)
             DeliverEventsToWindow(device, screenInfo.screens[i]->root, xi, 1,
-                                  GetEventFilter(device, xi), NULL);
+                                  filter, NullGrab);
         free(xi);
     }
 }
commit ac0850e86f22191091a1eb07237cae9de49ee00d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri May 27 12:14:32 2011 +1000

    dix: split DeliverEventToWindowMask up a bit more.
    
    Move out the actual event delivery, it needs to be used from elsewhere.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 66fbe9a..9063c28 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2076,35 +2076,27 @@ out:
 }
 
 /**
- * Deliver events to clients registered on the window.
- *
- * @param client_return On successful delivery, set to the recipient.
- * @param mask_return On successful delivery, set to the recipient's event
- * mask for this event.
+ * Try delivery on each client in inputclients, provided the event mask
+ * accepts it and there is no interfering core grab..
  */
 static enum EventDeliveryState
-DeliverEventToWindowMask(DeviceIntPtr dev, WindowPtr win, xEvent *events,
-                         int count, Mask filter, GrabPtr grab,
-                         ClientPtr *client_return, Mask *mask_return)
+DeliverEventToInputClients(DeviceIntPtr dev, InputClients *inputclients,
+                           WindowPtr win, xEvent *events,
+                           int count, Mask filter, GrabPtr grab,
+                           ClientPtr *client_return, Mask *mask_return)
 {
     int attempt;
-    enum EventDeliveryState rc = EVENT_SKIP;
-    InputClients *other;
+    enum EventDeliveryState rc = EVENT_NOT_DELIVERED;
 
-    if (!GetClientsForDelivery(dev, win, events, filter, &other))
-        goto out;
-
-    rc = EVENT_NOT_DELIVERED;
-
-    for (; other; other = other->next)
+    for (; inputclients; inputclients = inputclients->next)
     {
         Mask mask;
-        ClientPtr client = rClient(other);
+        ClientPtr client = rClient(inputclients);
 
         if (IsInterferingGrab(client, dev, events))
             continue;
 
-        mask = GetEventMask(dev, events, other);
+        mask = GetEventMask(dev, events, inputclients);
 
         if (XaceHook(XACE_RECEIVE_ACCESS, client, win,
                     events, count))
@@ -2125,12 +2117,34 @@ DeliverEventToWindowMask(DeviceIntPtr dev, WindowPtr win, xEvent *events,
         }
     }
 
-out:
     return rc;
 }
 
 
 /**
+ * Deliver events to clients registered on the window.
+ *
+ * @param client_return On successful delivery, set to the recipient.
+ * @param mask_return On successful delivery, set to the recipient's event
+ * mask for this event.
+ */
+static enum EventDeliveryState
+DeliverEventToWindowMask(DeviceIntPtr dev, WindowPtr win, xEvent *events,
+                         int count, Mask filter, GrabPtr grab,
+                         ClientPtr *client_return, Mask *mask_return)
+{
+    InputClients *clients;
+
+    if (!GetClientsForDelivery(dev, win, events, filter, &clients))
+        return EVENT_SKIP;
+
+    return DeliverEventToInputClients(dev, clients, win, events, count, filter,
+                                      grab, client_return, mask_return);
+
+}
+
+
+/**
  * Deliver events to a window. At this point, we do not yet know if the event
  * actually needs to be delivered. May activate a grab if the event is a
  * button press.
commit 5ea2fb389fce235366e9fce83d20abdc8874f4e2
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri May 27 11:43:50 2011 +1000

    dix: rename DeliverEventsToClients to DeliverEventsToWindowMask
    
    To avoid confusion with a future patch and it better describes what this
    does anyway - delivering events to all clients that have the event mask on
    the window.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 20754f0..66fbe9a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2083,9 +2083,9 @@ out:
  * mask for this event.
  */
 static enum EventDeliveryState
-DeliverEventToClients(DeviceIntPtr dev, WindowPtr win, xEvent *events,
-                      int count, Mask filter, GrabPtr grab,
-                      ClientPtr *client_return, Mask *mask_return)
+DeliverEventToWindowMask(DeviceIntPtr dev, WindowPtr win, xEvent *events,
+                         int count, Mask filter, GrabPtr grab,
+                         ClientPtr *client_return, Mask *mask_return)
 {
     int attempt;
     enum EventDeliveryState rc = EVENT_SKIP;
@@ -2192,8 +2192,8 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
     {
         enum EventDeliveryState rc;
 
-        rc = DeliverEventToClients(pDev, pWin, pEvents, count, filter, grab,
-                                   &client, &deliveryMask);
+        rc = DeliverEventToWindowMask(pDev, pWin, pEvents, count, filter,
+                                      grab, &client, &deliveryMask);
 
         switch(rc)
         {
commit 016413dae947fe4e8e918f728c87354fa4928275
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri May 27 11:40:56 2011 +1000

    dix: split client list retrieval out of DeliverEventToClients
    
    No functional change, but "other" was renamed to "clients".
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 3c7bd50..20754f0 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2037,31 +2037,29 @@ DeliverToWindowOwner(DeviceIntPtr dev, WindowPtr win,
     return EVENT_NOT_DELIVERED;
 }
 
+
 /**
- * Deliver events to clients registered on the window.
+ * Get the list of clients that should be tried for event delivery on the
+ * given window.
  *
- * @param client_return On successful delivery, set to the recipient.
- * @param mask_return On successful delivery, set to the recipient's event
- * mask for this event.
+ * @return 1 if the client list should be traversed, zero if the event
+ * should be skipped.
  */
-static enum EventDeliveryState
-DeliverEventToClients(DeviceIntPtr dev, WindowPtr win, xEvent *events,
-                      int count, Mask filter, GrabPtr grab,
-                      ClientPtr *client_return, Mask *mask_return)
+static Bool
+GetClientsForDelivery(DeviceIntPtr dev, WindowPtr win,
+                      xEvent *events, Mask filter, InputClients **clients)
 {
-    int attempt;
-    enum EventDeliveryState rc = EVENT_SKIP;
-    InputClients *other;
+    int rc = 0;
 
     if (core_get_type(events) != 0)
-        other = (InputClients *)wOtherClients(win);
+        *clients = (InputClients *)wOtherClients(win);
     else if (xi2_get_type(events) != 0)
     {
         OtherInputMasks *inputMasks = wOtherInputMasks(win);
         /* Has any client selected for the event? */
         if (!GetWindowXI2Mask(dev, win, events))
             goto out;
-        other = inputMasks->inputClients;
+        *clients = inputMasks->inputClients;
     } else {
         OtherInputMasks *inputMasks = wOtherInputMasks(win);
         /* Has any client selected for the event? */
@@ -2069,9 +2067,33 @@ DeliverEventToClients(DeviceIntPtr dev, WindowPtr win, xEvent *events,
             !(inputMasks->inputEvents[dev->id] & filter))
             goto out;
 
-        other = inputMasks->inputClients;
+        *clients = inputMasks->inputClients;
     }
 
+    rc = 1;
+out:
+    return rc;
+}
+
+/**
+ * Deliver events to clients registered on the window.
+ *
+ * @param client_return On successful delivery, set to the recipient.
+ * @param mask_return On successful delivery, set to the recipient's event
+ * mask for this event.
+ */
+static enum EventDeliveryState
+DeliverEventToClients(DeviceIntPtr dev, WindowPtr win, xEvent *events,
+                      int count, Mask filter, GrabPtr grab,
+                      ClientPtr *client_return, Mask *mask_return)
+{
+    int attempt;
+    enum EventDeliveryState rc = EVENT_SKIP;
+    InputClients *other;
+
+    if (!GetClientsForDelivery(dev, win, events, filter, &other))
+        goto out;
+
     rc = EVENT_NOT_DELIVERED;
 
     for (; other; other = other->next)
commit 537c5f631d1f8d526e63355b7d88cb1fb2793492
Author: Cyril Brulebois <kibi at debian.org>
Date:   Sun Jun 5 03:21:18 2011 +0200

    xkb: Fix case checks for Latin 4.
    
    That one was missing _XkbKSLower:
      XK_kra: U+0138 LATIN SMALL LETTER KRA
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/xkb/xkbfmisc.c b/xkb/xkbfmisc.c
index e042671..d8202b4 100644
--- a/xkb/xkbfmisc.c
+++ b/xkb/xkbfmisc.c
@@ -92,7 +92,8 @@ unsigned	set,rtrn;
 		((ks>=XK_Amacron)&&(ks<=XK_Umacron))) {
 		rtrn|= _XkbKSUpper;
 	    }
-	    if (((ks>=XK_rcedilla)&&(ks<=XK_tslash))||
+	    if ((ks==XK_kra)||
+	        ((ks>=XK_rcedilla)&&(ks<=XK_tslash))||
 	        (ks==XK_eng)||
 		((ks>=XK_amacron)&&(ks<=XK_umacron))) {
 		rtrn|= _XkbKSLower;
commit 0b56a7f0ad01d3a86cdd7a14d5e567a00a3553f6
Author: Cyril Brulebois <kibi at debian.org>
Date:   Sun Jun 5 03:12:44 2011 +0200

    xkb: Fix case checks for Latin 2.
    
    Those ones were getting _XkbKSLower for no reasons:
      XK_ogonek: U+02DB OGONEK
      XK_doubleacute: U+02DD DOUBLE ACUTE ACCENT
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/xkb/xkbfmisc.c b/xkb/xkbfmisc.c
index c36cc7b..e042671 100644
--- a/xkb/xkbfmisc.c
+++ b/xkb/xkbfmisc.c
@@ -71,7 +71,7 @@ unsigned	set,rtrn;
 		((ks>=XK_Racute)&&(ks<=XK_Tcedilla))) {
 		rtrn|= _XkbKSUpper;
 	    }
-	    if (((ks>=XK_aogonek)&&(ks<=XK_zabovedot)&&(ks!=XK_caron))||
+	    if (((ks>=XK_aogonek)&&(ks<=XK_zabovedot)&&(ks!=XK_ogonek)&&(ks!=XK_caron)&&(ks!=XK_doubleacute))||
 		((ks>=XK_racute)&&(ks<=XK_tcedilla))) {
 		rtrn|= _XkbKSLower;
 	    }
commit 512a9750c197437889ff7f26a8d2bd242e030745
Author: Cyril Brulebois <kibi at debian.org>
Date:   Sun Jun 5 03:03:47 2011 +0200

    xkb: Fix case checks for Latin 1.
    
    That one was missing _XkbKSLower:
      XK_ssharp: U+00DF LATIN SMALL LETTER SHARP S
    
    That one was getting _XkbKSLower for no reasons:
      XK_division: U+00F7 DIVISION SIGN
    
    For reference, XK_multiply was already excluded from the _XkbKSUpper
    check, it's no big surprise XK_division has to be excluded from the
    _XkbKSLower check.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/xkb/xkbfmisc.c b/xkb/xkbfmisc.c
index 1ac9d82..c36cc7b 100644
--- a/xkb/xkbfmisc.c
+++ b/xkb/xkbfmisc.c
@@ -62,7 +62,7 @@ unsigned	set,rtrn;
 		rtrn|= _XkbKSUpper;
 	    }
 	    if (((ks>=XK_a)&&(ks<=XK_z))||
-		((ks>=XK_agrave)&&(ks<=XK_ydiaeresis))) {
+		((ks>=XK_ssharp)&&(ks<=XK_ydiaeresis)&&(ks!=XK_division))) {
 		rtrn|= _XkbKSLower;
 	    }
 	    break;
commit 635a1f50bc65512ec491fe71b9dfa8cf9118e2c2
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Sep 23 12:04:39 2011 +1000

    input: allow for max < min for relative axes on  InitValuatorAxisStruct
    
    Relative axes are initialized with 0, -1 but so far this never had any
    effect as all users of this function (for relative axes) just set it to the
    defaults anyway.
    
    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 8a3c256..a6455e6 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1073,7 +1073,7 @@ InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int
 {
     AxisInfoPtr ax;
 
-    if (!dev || !dev->valuator || minval > maxval)
+    if (!dev || !dev->valuator || (minval > maxval && mode == Absolute))
         return FALSE;
     if (axnum >= dev->valuator->numAxes)
         return FALSE;
commit 8d1a414cca51e7f8a93470c5aa2e998f5ca1bc9a
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Sep 23 12:03:48 2011 +1000

    input: switch InitValuatorAxisStruct to return Bool
    
    Return errors instead of silently ignoring them.
    
    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 4dd9b85..8a3c256 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1067,16 +1067,16 @@ InitProximityClassDeviceStruct(DeviceIntPtr dev)
  *
  * @see InitValuatorClassDeviceStruct
  */
-void
+Bool
 InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int maxval,
 		       int resolution, int min_res, int max_res, int mode)
 {
     AxisInfoPtr ax;
 
     if (!dev || !dev->valuator || minval > maxval)
-        return;
+        return FALSE;
     if (axnum >= dev->valuator->numAxes)
-        return;
+        return FALSE;
 
     ax = dev->valuator->axes + axnum;
 
@@ -1090,6 +1090,8 @@ InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int
 
     if (mode & OutOfProximity)
         dev->proximity->in_proximity = FALSE;
+
+    return TRUE;
 }
 
 static void
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 9fbcba9..49b2fb2 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -1363,15 +1363,15 @@ xf86XInputSetScreen(InputInfoPtr	pInfo,
 }
 
 
-void
+Bool
 xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int maxval,
 			   int resolution, int min_res, int max_res, int mode)
 {
     if (!dev || !dev->valuator)
-        return;
+        return FALSE;
 
-    InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, min_res,
-			   max_res, mode);
+    return InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, min_res,
+				  max_res, mode);
 }
 
 /*
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index a4d9e58..189f7ab 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -145,7 +145,7 @@ 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, XF86OptionPtr options);
-extern _X_EXPORT void xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
+extern _X_EXPORT Bool xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
 				int maxval, int resolution, int min_res,
 				int max_res, int mode);
 extern _X_EXPORT void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum);
diff --git a/include/exevents.h b/include/exevents.h
index 2b22698..731f31e 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -40,7 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 extern _X_EXPORT int InitProximityClassDeviceStruct(
 	DeviceIntPtr           /* dev */);
 
-extern _X_EXPORT void InitValuatorAxisStruct(
+extern _X_EXPORT Bool InitValuatorAxisStruct(
 	DeviceIntPtr           /* dev */,
 	int                    /* axnum */,
 	Atom                   /* label */,
commit 5ac1f885f5c106b970835de36e13a9a7ea413df4
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Feb 15 19:44:53 2011 +0000

    Input: Add POINTER_EMULATED flag to GetPointerEvents
    
    POINTER_EMULATED merely sets XIPointerEmulated in the generated
    DeviceEvent.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index 4eb1b3a..45243df 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -58,6 +58,7 @@
 #endif
 
 #include <X11/extensions/XI.h>
+#include <X11/extensions/XI2.h>
 #include <X11/extensions/XIproto.h>
 #include <pixman.h>
 #include "exglobals.h"
@@ -1159,6 +1160,11 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
     event->root_x_frac = screenx - trunc(screenx);
     event->root_y_frac = screeny - trunc(screeny);
 
+    if (flags & POINTER_EMULATED) {
+        raw->flags = XIPointerEmulated;
+        event->flags = XIPointerEmulated;
+    }
+
     set_valuators(pDev, event, &mask);
 
     return num_events;
diff --git a/include/input.h b/include/input.h
index 577f5d9..6ba1ab2 100644
--- a/include/input.h
+++ b/include/input.h
@@ -68,6 +68,7 @@ SOFTWARE.
 #define POINTER_ACCELERATE	(1 << 3)
 #define POINTER_SCREEN		(1 << 4)	/* Data in screen coordinates */
 #define POINTER_NORAW		(1 << 5)	/* Don't generate RawEvents */
+#define POINTER_EMULATED	(1 << 6)	/* Event was emulated from another event */
 
 /*int constants for pointer acceleration schemes*/
 #define PtrAccelNoOp            0
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index d7a9ee4..bfa23b5 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -41,6 +41,7 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
     int nvals = 0;
     int bits_set;
     int len;
+    uint32_t flagmask = 0;
 
     if (swap)
     {
@@ -62,7 +63,17 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
     assert(out->detail == in->detail.button);
     assert(out->deviceid == in->deviceid);
     assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask))));
-    assert(out->flags == 0); /* FIXME: we don't set the flags yet */
+
+    switch (in->type) {
+    case ET_RawMotion:
+    case ET_RawButtonPress:
+    case ET_RawButtonRelease:
+        flagmask = XIPointerEmulated;
+        break;
+    default:
+        flagmask = 0;
+    }
+    assert((out->flags & ~flagmask) == 0);
 
     ptr = (unsigned char*)&out[1];
     bits_set = 0;
@@ -304,6 +315,11 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
     assert(out->sourceid == in->sourceid);
 
     switch (in->type) {
+        case ET_ButtonPress:
+        case ET_Motion:
+        case ET_ButtonRelease:
+            flagmask = XIPointerEmulated;
+            break;
         case ET_KeyPress:
             flagmask = XIKeyRepeat;
             break;
commit 78d8d6dd7f31cb903d5c8baf64181795736f33ed
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Feb 15 14:23:25 2011 +0000

    Input: Add vertical and horizontal scroll axes
    
    To be used for smooth scrolling with future driver APIs, replacing
    Rel Vert Wheel and Rel Horiz Wheel axes, which have not been used in any
    open driver to date.
    
    Combined with double-granularity ValuatorMasks, these axes allow for
    fine-grained scroll data to be sent to clients.  Future commits allow
    drivers to post these scroll axes to
    QueuePointerEvents/GetPointerEvents, which take care of emulating legacy
    scroll button events.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index fa0d811..14f1491 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -52,11 +52,14 @@ static struct dev_properties
 } dev_properties[] = {
     {0, XI_PROP_ENABLED},
     {0, XI_PROP_XTEST_DEVICE},
+
     {0, XATOM_FLOAT},
+
     {0, ACCEL_PROP_PROFILE_NUMBER},
     {0, ACCEL_PROP_CONSTANT_DECELERATION},
     {0, ACCEL_PROP_ADAPTIVE_DECELERATION},
     {0, ACCEL_PROP_VELOCITY_SCALING},
+
     {0, AXIS_LABEL_PROP},
     {0, AXIS_LABEL_PROP_REL_X},
     {0, AXIS_LABEL_PROP_REL_Y},
@@ -68,6 +71,8 @@ static struct dev_properties
     {0, AXIS_LABEL_PROP_REL_DIAL},
     {0, AXIS_LABEL_PROP_REL_WHEEL},
     {0, AXIS_LABEL_PROP_REL_MISC},
+    {0, AXIS_LABEL_PROP_REL_VSCROLL},
+    {0, AXIS_LABEL_PROP_REL_HSCROLL},
     {0, AXIS_LABEL_PROP_ABS_X},
     {0, AXIS_LABEL_PROP_ABS_Y},
     {0, AXIS_LABEL_PROP_ABS_Z},
diff --git a/include/xserver-properties.h b/include/xserver-properties.h
index bf50042..18b54ba 100644
--- a/include/xserver-properties.h
+++ b/include/xserver-properties.h
@@ -77,6 +77,8 @@
 #define AXIS_LABEL_PROP_REL_DIAL        "Rel Dial"
 #define AXIS_LABEL_PROP_REL_WHEEL       "Rel Vert Wheel"
 #define AXIS_LABEL_PROP_REL_MISC        "Rel Misc"
+#define AXIS_LABEL_PROP_REL_VSCROLL     "Rel Vert Scroll"
+#define AXIS_LABEL_PROP_REL_HSCROLL     "Rel Horiz Scroll"
 
 /*
  * Absolute axes
commit d8e42decbad4abe13265f4c546a0c561905d018f
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Feb 15 18:54:14 2011 +0000

    Input: Split GetPointerEvents body into a helper function
    
    For smooth-scrolling support, we want GetPointerEvents to generate
    multiple events, so split the body of the function out into a helper
    function in order to call it multiple times.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index 7cb2968..4eb1b3a 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1043,40 +1043,25 @@ QueuePointerEvents(DeviceIntPtr device, int type,
 }
 
 /**
- * Generate a series of InternalEvents representing pointer motion, or
- * button presses.
+ * Helper function for GetPointerEvents, which only generates motion and
+ * raw motion events for the slave device: does not update the master device.
  *
- * The DDX is responsible for allocating the events in the first
- * place via InitEventList() and GetMaximumEventsNum(), and for freeing it.
- *
- * In the generated events rootX/Y will be in absolute screen coords and
- * the valuator information in the absolute or relative device coords.
- *
- * last.valuators[x] of the device is always in absolute device coords.
- * last.valuators[x] of the master device is in absolute screen coords.
- *
- * master->last.valuators[x] for x > 2 is undefined.
+ * Should not be called by anyone other than GetPointerEvents.
  *
  * @return the number of events written into events.
  */
-int
-GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons,
-                 int flags, const ValuatorMask *mask_in) {
+static int
+fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
+                    int buttons, CARD32 ms, int flags,
+                    const ValuatorMask *mask_in)
+{
     int num_events = 1, i;
-    CARD32 ms;
     DeviceEvent *event;
-    RawDeviceEvent    *raw;
+    RawDeviceEvent *raw;
     double screenx = 0.0, screeny = 0.0;
     ScreenPtr scr = miPointerGetScreen(pDev);
     ValuatorMask mask;
 
-    /* refuse events from disabled devices */
-    if (!pDev->enabled)
-        return 0;
-
-    if (!scr)
-        return 0;
-
     switch (type)
     {
         case MotionNotify:
@@ -1092,10 +1077,6 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
             return 0;
     }
 
-    ms = GetTimeInMillis(); /* before pointer update to help precision */
-
-    events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events);
-
     valuator_mask_copy(&mask, mask_in);
 
     if ((flags & POINTER_NORAW) == 0)
@@ -1184,6 +1165,45 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
 }
 
 /**
+ * Generate a complete series of InternalEvents (filled into the EventList)
+ * representing pointer motion, or button presses.  If the device is a slave
+ * device, also potentially generate a DeviceClassesChangedEvent to update
+ * the master device.
+ *
+ * events is not NULL-terminated; the return value is the number of events.
+ * The DDX is responsible for allocating the event structure in the first
+ * place via InitEventList() and GetMaximumEventsNum(), and for freeing it.
+ *
+ * In the generated events rootX/Y will be in absolute screen coords and
+ * the valuator information in the absolute or relative device coords.
+ *
+ * last.valuators[x] of the device is always in absolute device coords.
+ * last.valuators[x] of the master device is in absolute screen coords.
+ *
+ * master->last.valuators[x] for x > 2 is undefined.
+ */
+int
+GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
+                 int buttons, int flags, const ValuatorMask *mask_in)
+{
+    CARD32 ms = GetTimeInMillis();
+    int num_events = 0;
+
+    /* refuse events from disabled devices */
+    if (!pDev->enabled)
+        return 0;
+
+    if (!miPointerGetScreen(pDev))
+        return 0;
+
+    events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT,
+                              &num_events);
+    num_events += fill_pointer_events(events, pDev, type, buttons, ms, flags,
+                                      mask_in);
+    return num_events;
+}
+
+/**
  * Generate internal events representing this proximity event and enqueue
  * them on the event queue.
  *
commit bc8aad2376207b5ca9c74effae67fb8183222d2e
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Mar 3 19:48:15 2011 +0000

    Input: Set last valuators in GetPointerEvents only
    
    Previously, various pieces of code, including acceleration, used to drop
    the values into DeviceIntRec::last.valuators.  Remove all this and only
    do it in GetPointerEvents after all transformation, acceleration and
    clipping, so we're guaranteed to always have the correct values.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index db47315..7cb2968 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -701,7 +701,6 @@ moveAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
             continue;
         val = valuator_mask_get_double(mask, i);
         clipAxis(dev, i, &val);
-        dev->last.valuators[i] = val;
         valuator_mask_set_double(mask, i, val);
     }
 }
@@ -731,7 +730,6 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
         if (valuator_get_mode(dev, i) == Absolute &&
             ((i != 0 && i != 1) || clip_xy))
             clipAxis(dev, i, &val);
-        dev->last.valuators[i] = val;
         valuator_mask_set_double(mask, i, val);
     }
 }
@@ -821,10 +819,6 @@ positionSprite(DeviceIntPtr dev, int mode, ScreenPtr scr, ValuatorMask *mask,
         master->last.valuators[1] = *screeny;
     }
 
-    /* dropy x/y (device coordinates) back into valuators for next event */
-    dev->last.valuators[0] = x;
-    dev->last.valuators[1] = y;
-
     if (valuator_mask_isset(mask, 0))
         valuator_mask_set_double(mask, 0, x);
     if (valuator_mask_isset(mask, 1))
@@ -1068,7 +1062,7 @@ QueuePointerEvents(DeviceIntPtr device, int type,
 int
 GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons,
                  int flags, const ValuatorMask *mask_in) {
-    int num_events = 1;
+    int num_events = 1, i;
     CARD32 ms;
     DeviceEvent *event;
     RawDeviceEvent    *raw;
@@ -1153,6 +1147,12 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
 
     clipValuators(pDev, &mask);
 
+    for (i = 0; i < valuator_mask_size(&mask); i++)
+    {
+        if (valuator_mask_isset(&mask, i))
+            pDev->last.valuators[i] = valuator_mask_get_double(&mask, i);
+    }
+
     event = &events->device_event;
     init_device_event(event, pDev, ms);
 
commit 94c19a0a72403fc522e3d05eeb57f35e111a2562
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Mar 3 15:46:45 2011 +0000

    Input: Convert DeviceIntRec::last to use doubles
    
    Change the last real user of a split integer/fractional co-ordinate
    system, DeviceIntRec's last->{valuators,remainder} to just have one set
    of doubles.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xiwarppointer.c b/Xi/xiwarppointer.c
index 8fcb4d1..11ab241 100644
--- a/Xi/xiwarppointer.c
+++ b/Xi/xiwarppointer.c
@@ -190,8 +190,6 @@ ProcXIWarpPointer(ClientPtr client)
     /* if we don't update the device, we get a jump next time it moves */
     pDev->last.valuators[0] = x;
     pDev->last.valuators[1] = y;
-    pDev->last.remainder[0] = 0;
-    pDev->last.remainder[1] = 0;
     miPointerUpdateSprite(pDev);
 
     /* FIXME: XWarpPointer is supposed to generate an event. It doesn't do it
diff --git a/dix/getevents.c b/dix/getevents.c
index fac845e..db47315 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -291,15 +291,12 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
 {
     ScreenPtr scr = miPointerGetScreen(pDev);
     int i;
-    double val, ret;
     DeviceIntPtr lastSlave;
 
     /* master->last.valuators[0]/[1] is in screen coords and the actual
      * position of the pointer */
     pDev->last.valuators[0] = master->last.valuators[0];
     pDev->last.valuators[1] = master->last.valuators[1];
-    pDev->last.remainder[0] = master->last.remainder[0];
-    pDev->last.remainder[1] = master->last.remainder[1];
 
     if (!pDev->valuator)
         return;
@@ -307,19 +304,17 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
     /* scale back to device coordinates */
     if(pDev->valuator->numAxes > 0)
     {
-        val = pDev->last.valuators[0] + pDev->last.remainder[0];
-        ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 0,
-                                  scr->width);
-        pDev->last.valuators[0] = trunc(ret);
-        pDev->last.remainder[0] = ret - trunc(ret);
+        pDev->last.valuators[0] = rescaleValuatorAxis(pDev->last.valuators[0],
+                                                      NULL,
+                                                      pDev->valuator->axes + 0,
+                                                      scr->width);
     }
     if(pDev->valuator->numAxes > 1)
     {
-        val = pDev->last.valuators[1] + pDev->last.remainder[1];
-        ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 1,
-                                  scr->height);
-        pDev->last.valuators[1] = trunc(ret);
-        pDev->last.remainder[1] = ret - trunc(ret);
+        pDev->last.valuators[1] = rescaleValuatorAxis(pDev->last.valuators[1],
+                                                      NULL,
+                                                      pDev->valuator->axes + 1,
+                                                      scr->height);
     }
 
     /* calculate the other axis as well based on info from the old
@@ -331,15 +326,13 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
             if (i >= lastSlave->valuator->numAxes)
             {
                 pDev->last.valuators[i] = 0;
-                pDev->last.remainder[i] = 0;
             }
             else
             {
-                val = pDev->last.valuators[i] + pDev->last.remainder[i];
-                ret = rescaleValuatorAxis(val, lastSlave->valuator->axes + i,
+                double val = pDev->last.valuators[i];
+                val = rescaleValuatorAxis(val, lastSlave->valuator->axes + i,
                                           pDev->valuator->axes + i, 0);
-                pDev->last.valuators[i] = trunc(ret);
-                pDev->last.remainder[i] = ret - trunc(ret);
+                pDev->last.valuators[i] = val;
             }
         }
     }
@@ -523,7 +516,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
  */
 static void
 updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
-                    int *valuators)
+                    double *valuators)
 {
     char *buff = (char *) pDev->valuator->motion;
     ValuatorClassPtr v;
@@ -545,6 +538,7 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
 
         for (i = 0; i < v->numAxes; i++)
         {
+            int val;
             /* XI1 doesn't support mixed mode devices */
             if (valuator_get_mode(pDev, i) != valuator_get_mode(pDev, 0))
                 break;
@@ -557,7 +551,8 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
             buff += sizeof(INT32);
             memcpy(buff, &v->axes[i].max_value, sizeof(INT32));
             buff += sizeof(INT32);
-            memcpy(buff, &valuators[i], sizeof(INT32));
+            val = valuators[i];
+            memcpy(buff, &val, sizeof(INT32));
             buff += sizeof(INT32);
         }
     } else
@@ -573,12 +568,14 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
 
         for (i = 0; i < MAX_VALUATORS; i++)
         {
+            int val;
             if (valuator_mask_size(mask) <= i || !valuator_mask_isset(mask, i))
             {
                 buff += sizeof(INT32);
                 continue;
             }
-            memcpy(buff, &valuators[i], sizeof(INT32));
+            val = valuators[i];
+            memcpy(buff, &val, sizeof(INT32));
             buff += sizeof(INT32);
         }
     }
@@ -704,8 +701,7 @@ moveAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
             continue;
         val = valuator_mask_get_double(mask, i);
         clipAxis(dev, i, &val);
-        dev->last.valuators[i] = trunc(val);
-        dev->last.remainder[i] = val - trunc(val);
+        dev->last.valuators[i] = val;
         valuator_mask_set_double(mask, i, val);
     }
 }
@@ -725,7 +721,7 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
     /* calc other axes, clip, drop back into valuators */
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
-        double val = dev->last.valuators[i] + dev->last.remainder[i];
+        double val = dev->last.valuators[i];
 
         if (!valuator_mask_isset(mask, i))
             continue;
@@ -735,8 +731,7 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
         if (valuator_get_mode(dev, i) == Absolute &&
             ((i != 0 && i != 1) || clip_xy))
             clipAxis(dev, i, &val);
-        dev->last.valuators[i] = trunc(val);
-        dev->last.remainder[i] = val - trunc(val);
+        dev->last.valuators[i] = val;
         valuator_mask_set_double(mask, i, val);
     }
 }
@@ -786,11 +781,11 @@ positionSprite(DeviceIntPtr dev, int mode, ScreenPtr scr, ValuatorMask *mask,
     if (valuator_mask_isset(mask, 0))
         x = valuator_mask_get_double(mask, 0);
     else
-        x = dev->last.valuators[0] + dev->last.remainder[0];
+        x = dev->last.valuators[0];
     if (valuator_mask_isset(mask, 1))
         y = valuator_mask_get_double(mask, 1);
     else
-        y = dev->last.valuators[1] + dev->last.remainder[1];
+        y = dev->last.valuators[1];
 
     /* scale x&y to screen */
     *screenx = rescaleValuatorAxis(x, dev->valuator->axes + 0, NULL,
@@ -822,17 +817,13 @@ positionSprite(DeviceIntPtr dev, int mode, ScreenPtr scr, ValuatorMask *mask,
     /* Update the MD's co-ordinates, which are always in screen space. */
     if (!IsMaster(dev) || !IsFloating(dev)) {
         DeviceIntPtr master = GetMaster(dev, MASTER_POINTER);
-        master->last.valuators[0] = trunc(*screenx);
-        master->last.remainder[0] = *screenx - trunc(*screenx);
-        master->last.valuators[1] = trunc(*screeny);
-        master->last.remainder[1] = *screeny - trunc(*screeny);
+        master->last.valuators[0] = *screenx;
+        master->last.valuators[1] = *screeny;
     }
 
     /* dropy x/y (device coordinates) back into valuators for next event */
-    dev->last.valuators[0] = trunc(x);
-    dev->last.valuators[1] = trunc(y);
-    dev->last.remainder[0] = x - trunc(x);
-    dev->last.remainder[1] = y - trunc(y);
+    dev->last.valuators[0] = x;
+    dev->last.valuators[1] = y;
 
     if (valuator_mask_isset(mask, 0))
         valuator_mask_set_double(mask, 0, x);
@@ -1018,12 +1009,12 @@ transformAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
     if (valuator_mask_isset(mask, 0))
         ox = x = valuator_mask_get_double(mask, 0);
     else
-        ox = x = dev->last.valuators[0] + dev->last.remainder[0];
+        ox = x = dev->last.valuators[0];
 
     if (valuator_mask_isset(mask, 1))
         oy = y = valuator_mask_get_double(mask, 1);
     else
-        oy = y = dev->last.valuators[1] + dev->last.remainder[1];
+        oy = y = dev->last.valuators[1];
 
     transform(&dev->transform, &x, &y);
 
diff --git a/include/inputstr.h b/include/inputstr.h
index 480e956..c25f5c6 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -521,8 +521,7 @@ typedef struct _DeviceIntRec {
      * remainder supports acceleration
      */
     struct {
-        int             valuators[MAX_VALUATORS];
-        float           remainder[MAX_VALUATORS];
+        double          valuators[MAX_VALUATORS];
         int             numValuators;
         DeviceIntPtr    slave;
     } last;
commit 2d9beeb2174661d0a0732403ad4e49e9ff56718d
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Mar 3 15:36:55 2011 +0000

    Input: Make DeviceEvent use doubles internally
    
    Change the DeviceEvent InternalEvent to use doubles for its valuators,
    instead of data and data_frac.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 38089a2..4dd9b85 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -774,12 +774,9 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
 
     for (i = 0; i <= last_valuator && i < v->numAxes; i++)
     {
+        /* XXX: Relative/Absolute mode */
         if (BitIsOn(&event->valuators.mask, i))
-        {
-            /* XXX: Relative/Absolute mode */
             v->axisVal[i] = event->valuators.data[i];
-            v->axisVal[i] += (event->valuators.data_frac[i] * 1.0f / (1 << 16) / (1 << 16));
-        }
     }
 
     if (event->type == ET_KeyPress) {
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 54e9020..9cc177e 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -633,8 +633,9 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
         if (BitIsOn(ev->valuators.mask, i))
         {
             SetBit(ptr, i);
-            axisval->integral = ev->valuators.data[i];
-            axisval->frac = ev->valuators.data_frac[i];
+            axisval->integral = trunc(ev->valuators.data[i]);
+            axisval->frac = (ev->valuators.data[i] - axisval->integral) *
+                            (1UL << 32);
             axisval++;
         }
     }
diff --git a/dix/getevents.c b/dix/getevents.c
index d04f412..fac845e 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -196,9 +196,7 @@ set_valuators(DeviceIntPtr dev, DeviceEvent* event, ValuatorMask *mask)
             SetBit(event->valuators.mask, i);
             if (valuator_get_mode(dev, i) == Absolute)
                 SetBit(event->valuators.mode, i);
-            event->valuators.data[i] = valuator_mask_get(mask, i);
-            event->valuators.data_frac[i] =
-                dev->last.remainder[i] * (1 << 16) * (1 << 16);
+            event->valuators.data[i] = valuator_mask_get_double(mask, i);
         }
         else if (valuator_get_mode(dev, i) == Absolute)
             event->valuators.data[i] = dev->valuator->axisVal[i];
diff --git a/include/eventstr.h b/include/eventstr.h
index 0645585..2de077f 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -95,8 +95,7 @@ struct _DeviceEvent
     struct {
         uint8_t  mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
         uint8_t  mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/
-        int32_t  data[MAX_VALUATORS];         /**< Valuator data */
-        int32_t  data_frac[MAX_VALUATORS];    /**< Fractional part for data */
+        double   data[MAX_VALUATORS];         /**< Valuator data */
     } valuators;
     struct {
         uint32_t base;    /**< XKB base modifiers */
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 6df9af0..d7a9ee4 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -374,8 +374,8 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
             {
                 FP3232 vi, vo;
 
-                vi.integral = in->valuators.data[i];
-                vi.frac = in->valuators.data_frac[i];
+                vi.integral = trunc(in->valuators.data[i]);
+                vi.frac = (in->valuators.data[i] - vi.integral) * (1UL << 32);
 
                 vo = *values;
 
@@ -617,8 +617,7 @@ static void test_convert_XIDeviceEvent(void)
     {
         XISetMask(in.valuators.mask, i);
 
-        in.valuators.data[i] = i;
-        in.valuators.data_frac[i] = i + 20;
+        in.valuators.data[i] = i + (i * 0.0020);
         test_XIDeviceEvent(&in);
         XIClearMask(in.valuators.mask, i);
     }
commit 626f487b97c99b48bf1d8c8ef4367a686639c3e6
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Mar 3 15:06:45 2011 +0000

    Input: Make RawDeviceEvent use doubles internally
    
    Change RawDeviceEvent to use doubles for valuators internally, rather
    than data(_raw) and data(_raw)_frac.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index fa8ba9e..54e9020 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -649,7 +649,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
     int vallen, nvals;
     int i, len = sizeof(xXIRawEvent);
     char *ptr;
-    FP3232 *axisval;
+    FP3232 *axisval, *axisval_raw;
 
     nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask));
     len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once
@@ -671,16 +671,19 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
 
     ptr = (char*)&raw[1];
     axisval = (FP3232*)(ptr + raw->valuators_len * 4);
+    axisval_raw = axisval + nvals;
     for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++)
     {
         if (BitIsOn(ev->valuators.mask, i))
         {
             SetBit(ptr, i);
-            axisval->integral = ev->valuators.data[i];
-            axisval->frac = ev->valuators.data_frac[i];
-            (axisval + nvals)->integral = ev->valuators.data_raw[i];
-            (axisval + nvals)->frac = ev->valuators.data_raw_frac[i];
+            axisval->integral = trunc(ev->valuators.data[i]);
+            axisval->frac = ev->valuators.data[i] - axisval->integral;
+            axisval_raw->integral = trunc(ev->valuators.data_raw[i]);
+            axisval_raw->frac = ev->valuators.data_raw[i] -
+                                axisval_raw->integral;
             axisval++;
+            axisval_raw++;
         }
     }
 
diff --git a/dix/getevents.c b/dix/getevents.c
index ec79fcf..d04f412 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -167,20 +167,16 @@ init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail)
 }
 
 static void
-set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, int32_t* data,
-                  int32_t* data_frac)
+set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, double* data)
 {
     int i;
-    double val;
 
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
         if (valuator_mask_isset(mask, i))
         {
             SetBit(event->valuators.mask, i);
-            val = valuator_mask_get_double(mask, i);
-            data[i] = trunc(val);
-            data_frac[i] = (val - data[i]) * (1UL << 32);
+            data[i] = valuator_mask_get_double(mask, i);
         }
     }
 }
@@ -950,13 +946,11 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     valuator_mask_copy(&mask, mask_in);
 
     init_raw(pDev, raw, ms, type, key_code);
-    set_raw_valuators(raw, &mask, raw->valuators.data_raw,
-                      raw->valuators.data_raw_frac);
+    set_raw_valuators(raw, &mask, raw->valuators.data_raw);
 
     clipValuators(pDev, &mask);
 
-    set_raw_valuators(raw, &mask, raw->valuators.data,
-                      raw->valuators.data_frac);
+    set_raw_valuators(raw, &mask, raw->valuators.data);
 
     event = &events->device_event;
     init_device_event(event, pDev, ms);
@@ -1128,8 +1122,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
 	num_events++;
 
 	init_raw(pDev, raw, ms, type, buttons);
-	set_raw_valuators(raw, &mask, raw->valuators.data_raw,
-                          raw->valuators.data_raw_frac);
+        set_raw_valuators(raw, &mask, raw->valuators.data_raw);
     }
 
     if (flags & POINTER_ABSOLUTE)
@@ -1163,8 +1156,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     }
 
     if ((flags & POINTER_NORAW) == 0)
-        set_raw_valuators(raw, &mask, raw->valuators.data,
-                          raw->valuators.data_frac);
+        set_raw_valuators(raw, &mask, raw->valuators.data);
 
     positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative, scr,
                    &mask, &screenx, &screeny);
diff --git a/include/eventstr.h b/include/eventstr.h
index ecaeddc..0645585 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -199,10 +199,8 @@ struct _RawDeviceEvent
     } detail;
     struct {
         uint8_t  mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
-        int32_t  data[MAX_VALUATORS];         /**< Valuator data */
-        int32_t  data_frac[MAX_VALUATORS];    /**< Fractional part for data */
-        int32_t  data_raw[MAX_VALUATORS];     /**< Valuator data as posted */
-        int32_t  data_raw_frac[MAX_VALUATORS];/**< Fractional part for data_raw */
+        double   data[MAX_VALUATORS];         /**< Valuator data */
+        double   data_raw[MAX_VALUATORS];     /**< Valuator data as posted */
     } valuators;
     uint32_t flags;       /**< Flags to be copied into the generated event */
 };
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 80c47b0..6df9af0 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -93,8 +93,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
             value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4);
             value += nvals;
 
-            vi.integral = in->valuators.data[i];
-            vi.frac = in->valuators.data_frac[i];
+            vi.integral = trunc(in->valuators.data[i]);
+            vi.frac = in->valuators.data[i] - vi.integral;
 
             vo.integral = value->integral;
             vo.frac = value->frac;
@@ -109,8 +109,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
 
             raw_value = value + bits_set;
 
-            vi.integral = in->valuators.data_raw[i];
-            vi.frac = in->valuators.data_raw_frac[i];
+            vi.integral = trunc(in->valuators.data_raw[i]);
+            vi.frac = in->valuators.data_raw[i] - vi.integral;
 
             vo.integral = raw_value->integral;
             vo.frac = raw_value->frac;
@@ -248,10 +248,8 @@ static void test_convert_XIRawEvent(void)
     {
         XISetMask(in.valuators.mask, i);
 
-        in.valuators.data[i] = i;
-        in.valuators.data_raw[i] = i + 10;
-        in.valuators.data_frac[i] = i + 20;
-        in.valuators.data_raw_frac[i] = i + 30;
+        in.valuators.data[i] = i + (i * 0.0010);
+        in.valuators.data_raw[i] = (i + 10) + (i * 0.0030);
         test_XIRawEvent(&in);
         XIClearMask(in.valuators.mask, i);
     }
commit 3b7fb0f68dc0d40c968c2cfc9bb74b1d0fb48bc8
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 17:18:48 2011 +0000

    Input: Modify mask in-place in positionSprite
    
    Instead of taking pointers to x and y values to modify in
    positionSprite, just modify the mask (as well as dev->last) in place.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index a9409b4..ec79fcf 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -774,26 +774,34 @@ accelPointer(DeviceIntPtr dev, ValuatorMask* valuators, CARD32 ms)
  *
  * @param dev The device to be moved.
  * @param mode Movement mode (Absolute or Relative)
- * @param x Pointer to current x-axis value, may be modified.
- * @param y Pointer to current y-axis value, may be modified.
  * @param scr Screen the device's sprite is currently on.
+ * @param mask Mask of axis values for this event
  * @param screenx Screen x coordinate the sprite is on after the update.
  * @param screeny Screen y coordinate the sprite is on after the update.
  */
 static void
-positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
+positionSprite(DeviceIntPtr dev, int mode, ScreenPtr scr, ValuatorMask *mask,
                double *screenx, double *screeny)
 {
     int isx, isy; /* screen {x, y}, in int */
+    double x, y;
 
     if (!dev->valuator || dev->valuator->numAxes < 2)
         return;
 
+    if (valuator_mask_isset(mask, 0))
+        x = valuator_mask_get_double(mask, 0);
+    else
+        x = dev->last.valuators[0] + dev->last.remainder[0];
+    if (valuator_mask_isset(mask, 1))
+        y = valuator_mask_get_double(mask, 1);
+    else
+        y = dev->last.valuators[1] + dev->last.remainder[1];
+
     /* scale x&y to screen */
-    *screenx = rescaleValuatorAxis(*x, dev->valuator->axes + 0, NULL,
+    *screenx = rescaleValuatorAxis(x, dev->valuator->axes + 0, NULL,
                                    scr->width);
-
-    *screeny = rescaleValuatorAxis(*y, dev->valuator->axes + 1, NULL,
+    *screeny = rescaleValuatorAxis(y, dev->valuator->axes + 1, NULL,
                                    scr->height);
 
     /* miPointerSetPosition takes care of crossing screens for us, as well as
@@ -807,14 +815,14 @@ positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
     if (isx != trunc(*screenx))
     {
         *screenx -= trunc(*screenx) - isx;
-        *x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
-                                 scr->width);
+        x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
+                                scr->width);
     }
     if (isy != trunc(*screeny))
     {
         *screeny -= trunc(*screeny) - isy;
-        *y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
-                                 scr->height);
+        y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
+                                scr->height);
     }
 
     /* Update the MD's co-ordinates, which are always in screen space. */
@@ -827,10 +835,15 @@ positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
     }
 
     /* dropy x/y (device coordinates) back into valuators for next event */
-    dev->last.valuators[0] = trunc(*x);
-    dev->last.valuators[1] = trunc(*y);
-    dev->last.remainder[0] = *x - trunc(*x);
-    dev->last.remainder[1] = *y - trunc(*y);
+    dev->last.valuators[0] = trunc(x);
+    dev->last.valuators[1] = trunc(y);
+    dev->last.remainder[0] = x - trunc(x);
+    dev->last.remainder[1] = y - trunc(y);
+
+    if (valuator_mask_isset(mask, 0))
+        valuator_mask_set_double(mask, 0, x);
+    if (valuator_mask_isset(mask, 1))
+        valuator_mask_set_double(mask, 1, y);
 }
 
 /**
@@ -1076,8 +1089,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     CARD32 ms;
     DeviceEvent *event;
     RawDeviceEvent    *raw;
-    double x = 0.0, y = 0.0; /* device coords */
-    double screenx = 0.0, screeny = 0.0; /* screen coords */
+    double screenx = 0.0, screeny = 0.0;
     ScreenPtr scr = miPointerGetScreen(pDev);
     ValuatorMask mask;
 
@@ -1154,29 +1166,10 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         set_raw_valuators(raw, &mask, raw->valuators.data,
                           raw->valuators.data_frac);
 
-    if (valuator_mask_isset(&mask, 0))
-        x = valuator_mask_get_double(&mask, 0);
-    else
-        x = pDev->last.valuators[0] + pDev->last.remainder[0];
-    if (valuator_mask_isset(&mask, 1))
-        y = valuator_mask_get_double(&mask, 1);
-    else
-        y = pDev->last.valuators[1] + pDev->last.remainder[1];
-
-    positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
-                   &x, &y, scr, &screenx, &screeny);
-    if (valuator_mask_isset(&mask, 0))
-        valuator_mask_set_double(&mask, 0, x);
-    if (valuator_mask_isset(&mask, 1))
-        valuator_mask_set_double(&mask, 1, y);
+    positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative, scr,
+                   &mask, &screenx, &screeny);
     updateHistory(pDev, &mask, ms);
 
-    /* Update the valuators with the true value sent to the client*/
-    if (valuator_mask_isset(&mask, 0))
-        valuator_mask_set(&mask, 0, x);
-    if (valuator_mask_isset(&mask, 1))
-        valuator_mask_set(&mask, 1, y);
-
     clipValuators(pDev, &mask);
 
     event = &events->device_event;
commit 629a575261c08ca67324fea4c975636a1a95dc75
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 17:04:57 2011 +0000

    Input: Convert positionSprite and GetPointerEvents to double
    
    Use doubles internally in both of these functions, eliminating most of
    the remaining int co-ordinate usage.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index 94da143..a9409b4 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -776,91 +776,61 @@ accelPointer(DeviceIntPtr dev, ValuatorMask* valuators, CARD32 ms)
  * @param mode Movement mode (Absolute or Relative)
  * @param x Pointer to current x-axis value, may be modified.
  * @param y Pointer to current y-axis value, may be modified.
- * @param x_frac Fractional part of current x-axis value, may be modified.
- * @param y_frac Fractional part of current y-axis value, may be modified.
  * @param scr Screen the device's sprite is currently on.
  * @param screenx Screen x coordinate the sprite is on after the update.
  * @param screeny Screen y coordinate the sprite is on after the update.
- * @param screenx_frac Fractional part of screen x coordinate, as above.
- * @param screeny_frac Fractional part of screen y coordinate, as above.
  */
 static void
-positionSprite(DeviceIntPtr dev, int mode,
-               int *x, int *y, float x_frac, float y_frac,
-               ScreenPtr scr, int *screenx, int *screeny, float *screenx_frac, float *screeny_frac)
+positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
+               double *screenx, double *screeny)
 {
-    int old_screenx, old_screeny;
-    double val, ret;
+    int isx, isy; /* screen {x, y}, in int */
 
     if (!dev->valuator || dev->valuator->numAxes < 2)
         return;
 
     /* scale x&y to screen */
-    val = *x + x_frac;
-    ret = rescaleValuatorAxis(val, dev->valuator->axes + 0, NULL, scr->width);
-    *screenx = trunc(ret);
-    *screenx_frac = ret - trunc(ret);
-
-    val = *y + y_frac;
-    ret = rescaleValuatorAxis(val, dev->valuator->axes + 1, NULL, scr->height);
-    *screeny = trunc(ret);
-    *screeny_frac = ret - trunc(ret);
-
-    /* Hit the left screen edge? */
-    if (*screenx <= 0 && *screenx_frac < 0.0f)
+    *screenx = rescaleValuatorAxis(*x, dev->valuator->axes + 0, NULL,
+                                   scr->width);
+
+    *screeny = rescaleValuatorAxis(*y, dev->valuator->axes + 1, NULL,
+                                   scr->height);
+
+    /* miPointerSetPosition takes care of crossing screens for us, as well as
+     * clipping to the current screen.  In the event we actually change screen,
+     * we just drop the float component on the floor, then convert from
+     * screenx back into device co-ordinates. */
+    isx = trunc(*screenx);
+    isy = trunc(*screeny);
+    miPointerSetPosition(dev, mode, &isx, &isy);
+    scr = miPointerGetScreen(dev);
+    if (isx != trunc(*screenx))
     {
-        *screenx_frac = 0.0f;
-        x_frac = 0.0f;
+        *screenx -= trunc(*screenx) - isx;
+        *x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
+                                 scr->width);
     }
-    if (*screeny <= 0 && *screeny_frac < 0.0f)
+    if (isy != trunc(*screeny))
     {
-        *screeny_frac = 0.0f;
-        y_frac = 0.0f;
+        *screeny -= trunc(*screeny) - isy;
+        *y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
+                                 scr->height);
     }
 
-
-    old_screenx = *screenx;
-    old_screeny = *screeny;
-    /* This takes care of crossing screens for us, as well as clipping
-     * to the current screen. */
-    miPointerSetPosition(dev, mode, screenx, screeny);
-
-    if(!IsMaster(dev) && !IsFloating(dev)) {
+    /* Update the MD's co-ordinates, which are always in screen space. */
+    if (!IsMaster(dev) || !IsFloating(dev)) {
         DeviceIntPtr master = GetMaster(dev, MASTER_POINTER);
-        master->last.valuators[0] = *screenx;
-        master->last.valuators[1] = *screeny;
-        master->last.remainder[0] = *screenx_frac;
-        master->last.remainder[1] = *screeny_frac;
-    }
-
-    if (dev->valuator)
-    {
-        /* Crossed screen? Scale back to device coordiantes */
-        if(*screenx != old_screenx)
-        {
-            scr = miPointerGetScreen(dev);
-            val = *screenx + *screenx_frac;
-            ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 0,
-                                      scr->width);
-            *x = trunc(ret);
-            x_frac = ret - trunc(ret);
-        }
-        if(*screeny != old_screeny)
-        {
-            scr = miPointerGetScreen(dev);
-            val = *screeny + *screeny_frac;
-            ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 1,
-                                      scr->height);
-            *y = trunc(ret);
-            y_frac = ret - trunc(ret);
-        }
+        master->last.valuators[0] = trunc(*screenx);
+        master->last.remainder[0] = *screenx - trunc(*screenx);
+        master->last.valuators[1] = trunc(*screeny);
+        master->last.remainder[1] = *screeny - trunc(*screeny);
     }
 
     /* dropy x/y (device coordinates) back into valuators for next event */
-    dev->last.valuators[0] = *x;
-    dev->last.valuators[1] = *y;
-    dev->last.remainder[0] = x_frac;
-    dev->last.remainder[1] = y_frac;
+    dev->last.valuators[0] = trunc(*x);
+    dev->last.valuators[1] = trunc(*y);
+    dev->last.remainder[0] = *x - trunc(*x);
+    dev->last.remainder[1] = *y - trunc(*y);
 }
 
 /**
@@ -1106,9 +1076,8 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     CARD32 ms;
     DeviceEvent *event;
     RawDeviceEvent    *raw;
-    int x = 0, y = 0, /* device coords */
-        cx, cy; /* only screen coordinates */
-    float x_frac = 0.0, y_frac = 0.0, cx_frac, cy_frac;
+    double x = 0.0, y = 0.0; /* device coords */
+    double screenx = 0.0, screeny = 0.0; /* screen coords */
     ScreenPtr scr = miPointerGetScreen(pDev);
     ValuatorMask mask;
 
@@ -1155,7 +1124,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     {
         if (flags & POINTER_SCREEN) /* valuators are in screen coords */
         {
-            int scaled;
+            double scaled;
 
             if (valuator_mask_isset(&mask, 0))
             {
@@ -1185,27 +1154,21 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         set_raw_valuators(raw, &mask, raw->valuators.data,
                           raw->valuators.data_frac);
 
-    if (valuator_mask_isset(&mask, 0)) {
-        double tmp = valuator_mask_get_double(&mask, 0);
-        x = trunc(tmp);
-        x_frac = tmp - x;
-    }
-    else {
-        x = pDev->last.valuators[0];
-        x_frac = pDev->last.remainder[0];
-    }
-    if (valuator_mask_isset(&mask, 1)) {
-        double tmp = valuator_mask_get_double(&mask, 1);
-        y = trunc(tmp);
-        y_frac = tmp - y;
-    }
-    else {
-        y = pDev->last.valuators[1];
-        y_frac = pDev->last.remainder[1];
-    }
+    if (valuator_mask_isset(&mask, 0))
+        x = valuator_mask_get_double(&mask, 0);
+    else
+        x = pDev->last.valuators[0] + pDev->last.remainder[0];
+    if (valuator_mask_isset(&mask, 1))
+        y = valuator_mask_get_double(&mask, 1);
+    else
+        y = pDev->last.valuators[1] + pDev->last.remainder[1];
 
     positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
-                   &x, &y, x_frac, y_frac, scr, &cx, &cy, &cx_frac, &cy_frac);
+                   &x, &y, scr, &screenx, &screeny);
+    if (valuator_mask_isset(&mask, 0))
+        valuator_mask_set_double(&mask, 0, x);
+    if (valuator_mask_isset(&mask, 1))
+        valuator_mask_set_double(&mask, 1, y);
     updateHistory(pDev, &mask, ms);
 
     /* Update the valuators with the true value sent to the client*/
@@ -1235,10 +1198,11 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         event->detail.button = buttons;
     }
 
-    event->root_x = cx; /* root_x/y always in screen coords */
-    event->root_y = cy;
-    event->root_x_frac = cx_frac;
-    event->root_y_frac = cy_frac;
+    /* root_x and root_y must be in screen co-ordinates */
+    event->root_x = trunc(screenx);
+    event->root_y = trunc(screeny);
+    event->root_x_frac = screenx - trunc(screenx);
+    event->root_y_frac = screeny - trunc(screeny);
 
     set_valuators(pDev, event, &mask);
 
commit 51437995a5041a8c53c33b508b1607c78a5fa463
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 16:50:55 2011 +0000

    Input: Don't call positionSprite for non-pointer devices
    
    If the device doesn't have any valuators, or if it has less than two of
    them, don't bother calling positionSprite.  Users with one-dimensional
    pointing devices may be upset.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index 2c51388..94da143 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -792,28 +792,19 @@ positionSprite(DeviceIntPtr dev, int mode,
     int old_screenx, old_screeny;
     double val, ret;
 
-    /* scale x&y to screen */
-    if (dev->valuator && dev->valuator->numAxes > 0) {
-        val = *x + x_frac;
-        ret = rescaleValuatorAxis(val, dev->valuator->axes + 0, NULL,
-                                  scr->width);
-        *screenx = trunc(ret);
-        *screenx_frac = ret - trunc(ret);
-    } else {
-        *screenx = dev->last.valuators[0];
-        *screenx_frac = dev->last.remainder[0];
-    }
+    if (!dev->valuator || dev->valuator->numAxes < 2)
+        return;
 
-    if (dev->valuator && dev->valuator->numAxes > 1) {
-        val = *y + y_frac;
-        ret = rescaleValuatorAxis(val, dev->valuator->axes + 1, NULL,
-                                  scr->height);
-        *screeny = trunc(ret);
-        *screeny_frac = ret - trunc(ret);
-    } else {
-        *screeny = dev->last.valuators[1];
-        *screeny_frac = dev->last.remainder[1];
-    }
+    /* scale x&y to screen */
+    val = *x + x_frac;
+    ret = rescaleValuatorAxis(val, dev->valuator->axes + 0, NULL, scr->width);
+    *screenx = trunc(ret);
+    *screenx_frac = ret - trunc(ret);
+
+    val = *y + y_frac;
+    ret = rescaleValuatorAxis(val, dev->valuator->axes + 1, NULL, scr->height);
+    *screeny = trunc(ret);
+    *screeny_frac = ret - trunc(ret);
 
     /* Hit the left screen edge? */
     if (*screenx <= 0 && *screenx_frac < 0.0f)
commit 4c364a312daf2b743a0a60b9907f671804a1b1b6
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 16:49:53 2011 +0000

    Input: Convert rescaleValuatorAxis to double
    
    Instead of passing fractional pointers around everywhere, just pass
    doubles instead.  Much easier.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index dcd8263..2c51388 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -259,39 +259,29 @@ CreateClassesChangedEvent(InternalEvent* event,
 /**
  * Rescale the coord between the two axis ranges.
  */
-static int
-rescaleValuatorAxis(int coord, float remainder, float *remainder_return, AxisInfoPtr from, AxisInfoPtr to,
-                    int defmax)
+static double
+rescaleValuatorAxis(double coord, AxisInfoPtr from, AxisInfoPtr to,
+                    double defmax)
 {
-    int fmin = 0, tmin = 0, fmax = defmax, tmax = defmax, coord_return;
-    float value;
+    double fmin = 0.0, fmax = defmax;
+    double tmin = 0.0, tmax = defmax;
 
-    if(from && from->min_value < from->max_value) {
+    if (from && from->min_value < from->max_value) {
         fmin = from->min_value;
         fmax = from->max_value;
     }
-    if(to && to->min_value < to->max_value) {
+    if (to && to->min_value < to->max_value) {
         tmin = to->min_value;
         tmax = to->max_value;
     }
 
-    if(fmin == tmin && fmax == tmax) {
-        if (remainder_return)
-            *remainder_return = remainder;
+    if (fmin == tmin && fmax == tmax)
         return coord;
-    }
 
-    if(fmax == fmin) { /* avoid division by 0 */
-        if (remainder_return)
-            *remainder_return = 0.0;
-        return 0;
-    }
+    if (fmax == fmin) /* avoid division by 0 */
+        return 0.0;
 
-    value = (coord + remainder - fmin) * (tmax - tmin) / (fmax - fmin) + tmin;
-    coord_return = lroundf(value);
-    if (remainder_return)
-        *remainder_return = value - coord_return;
-    return coord_return;
+    return (coord - fmin) * (tmax - tmin) / (fmax - fmin) + tmin;
 }
 
 /**
@@ -307,6 +297,7 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
 {
     ScreenPtr scr = miPointerGetScreen(pDev);
     int i;
+    double val, ret;
     DeviceIntPtr lastSlave;
 
     /* master->last.valuators[0]/[1] is in screen coords and the actual
@@ -321,11 +312,21 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
 
     /* scale back to device coordinates */
     if(pDev->valuator->numAxes > 0)
-        pDev->last.valuators[0] = rescaleValuatorAxis(pDev->last.valuators[0], pDev->last.remainder[0],
-                        &pDev->last.remainder[0], NULL, pDev->valuator->axes + 0, scr->width);
+    {
+        val = pDev->last.valuators[0] + pDev->last.remainder[0];
+        ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 0,
+                                  scr->width);
+        pDev->last.valuators[0] = trunc(ret);
+        pDev->last.remainder[0] = ret - trunc(ret);
+    }
     if(pDev->valuator->numAxes > 1)
-        pDev->last.valuators[1] = rescaleValuatorAxis(pDev->last.valuators[1], pDev->last.remainder[1],
-                        &pDev->last.remainder[1], NULL, pDev->valuator->axes + 1, scr->height);
+    {
+        val = pDev->last.valuators[1] + pDev->last.remainder[1];
+        ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 1,
+                                  scr->height);
+        pDev->last.valuators[1] = trunc(ret);
+        pDev->last.remainder[1] = ret - trunc(ret);
+    }
 
     /* calculate the other axis as well based on info from the old
      * slave-device. If the old slave had less axes than this one,
@@ -340,12 +341,11 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
             }
             else
             {
-                pDev->last.valuators[i] =
-                    rescaleValuatorAxis(pDev->last.valuators[i],
-                            pDev->last.remainder[i],
-                            &pDev->last.remainder[i],
-                            lastSlave->valuator->axes + i,
-                            pDev->valuator->axes + i, 0);
+                val = pDev->last.valuators[i] + pDev->last.remainder[i];
+                ret = rescaleValuatorAxis(val, lastSlave->valuator->axes + i,
+                                          pDev->valuator->axes + i, 0);
+                pDev->last.valuators[i] = trunc(ret);
+                pDev->last.remainder[i] = ret - trunc(ret);
             }
         }
     }
@@ -456,7 +456,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
                 /* scale to screen coords */
                 to = &core_axis;
                 to->max_value = pScreen->width;
-                coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, pScreen->width);
+                coord = rescaleValuatorAxis(coord, &from, to, pScreen->width);
 
                 memcpy(corebuf, &coord, sizeof(INT16));
                 corebuf++;
@@ -467,7 +467,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
                 memcpy(&coord, icbuf++, sizeof(INT32));
 
                 to->max_value = pScreen->height;
-                coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, pScreen->height);
+                coord = rescaleValuatorAxis(coord, &from, to, pScreen->height);
                 memcpy(corebuf, &coord, sizeof(INT16));
 
             } else if (IsMaster(pDev))
@@ -495,7 +495,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
                         from.max_value = pScreen->height;
 
                     /* scale from stored range into current range */
-                    coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, 0);
+                    coord = rescaleValuatorAxis(coord, &from, to, 0);
                     memcpy(ocbuf, &coord, sizeof(INT32));
                     ocbuf++;
                 }
@@ -790,19 +790,26 @@ positionSprite(DeviceIntPtr dev, int mode,
                ScreenPtr scr, int *screenx, int *screeny, float *screenx_frac, float *screeny_frac)
 {
     int old_screenx, old_screeny;
+    double val, ret;
 
     /* scale x&y to screen */
     if (dev->valuator && dev->valuator->numAxes > 0) {
-        *screenx = rescaleValuatorAxis(*x, x_frac, screenx_frac,
-                dev->valuator->axes + 0, NULL, scr->width);
+        val = *x + x_frac;
+        ret = rescaleValuatorAxis(val, dev->valuator->axes + 0, NULL,
+                                  scr->width);
+        *screenx = trunc(ret);
+        *screenx_frac = ret - trunc(ret);
     } else {
         *screenx = dev->last.valuators[0];
         *screenx_frac = dev->last.remainder[0];
     }
 
     if (dev->valuator && dev->valuator->numAxes > 1) {
-        *screeny = rescaleValuatorAxis(*y, y_frac, screeny_frac,
-                dev->valuator->axes + 1, NULL, scr->height);
+        val = *y + y_frac;
+        ret = rescaleValuatorAxis(val, dev->valuator->axes + 1, NULL,
+                                  scr->height);
+        *screeny = trunc(ret);
+        *screeny_frac = ret - trunc(ret);
     } else {
         *screeny = dev->last.valuators[1];
         *screeny_frac = dev->last.remainder[1];
@@ -841,14 +848,20 @@ positionSprite(DeviceIntPtr dev, int mode,
         if(*screenx != old_screenx)
         {
             scr = miPointerGetScreen(dev);
-            *x = rescaleValuatorAxis(*screenx, *screenx_frac, &x_frac, NULL,
-                                    dev->valuator->axes + 0, scr->width);
+            val = *screenx + *screenx_frac;
+            ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 0,
+                                      scr->width);
+            *x = trunc(ret);
+            x_frac = ret - trunc(ret);
         }
         if(*screeny != old_screeny)
         {
             scr = miPointerGetScreen(dev);
-            *y = rescaleValuatorAxis(*screeny, *screeny_frac, &y_frac, NULL,
-                                     dev->valuator->axes + 1, scr->height);
+            val = *screeny + *screeny_frac;
+            ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 1,
+                                      scr->height);
+            *y = trunc(ret);
+            y_frac = ret - trunc(ret);
         }
     }
 
@@ -1155,19 +1168,17 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
 
             if (valuator_mask_isset(&mask, 0))
             {
-                scaled = rescaleValuatorAxis(valuator_mask_get(&mask, 0),
-                                             0.0, &x_frac, NULL,
-                                             pDev->valuator->axes + 0,
+                scaled = rescaleValuatorAxis(valuator_mask_get_double(&mask, 0),
+                                             NULL, pDev->valuator->axes + 0,
                                              scr->width);
-                valuator_mask_set(&mask, 0, scaled);
+                valuator_mask_set_double(&mask, 0, scaled);
             }
             if (valuator_mask_isset(&mask, 1))
             {
-                scaled = rescaleValuatorAxis(valuator_mask_get(&mask, 1),
-                                             0.0, &y_frac, NULL,
-                                             pDev->valuator->axes + 1,
+                scaled = rescaleValuatorAxis(valuator_mask_get_double(&mask, 1),
+                                             NULL, pDev->valuator->axes + 1,
                                              scr->height);
-                valuator_mask_set(&mask, 1, scaled);
+                valuator_mask_set_double(&mask, 1, scaled);
             }
         }
 
commit 5680fa41ea3373651f7017898a307e97cf29b0d3
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 16:30:30 2011 +0000

    Input: Remove x and y from moveAbsolute/moveRelative
    
    Both these functions modify the mask and
    pDev->last.{valuators,remainder} in-place now, so there's no need to
    pass in pointers to local x and y values.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index 483d65f..dcd8263 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -695,12 +695,10 @@ UpdateFromMaster(InternalEvent* events, DeviceIntPtr dev, int type, int *num_eve
  * Move the device's pointer to the position given in the valuators.
  *
  * @param dev The device whose pointer is to be moved.
- * @param x Returns the x position of the pointer after the move.
- * @param y Returns the y position of the pointer after the move.
  * @param mask Valuator data for this event.
  */
 static void
-moveAbsolute(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
+moveAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
 {
     int i;
 
@@ -716,21 +714,16 @@ moveAbsolute(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
         dev->last.remainder[i] = val - trunc(val);
         valuator_mask_set_double(mask, i, val);
     }
-
-    *x_out = dev->last.valuators[0];
-    *y_out = dev->last.valuators[1];
 }
 
 /**
  * Move the device's pointer by the values given in @valuators.
  *
  * @param dev The device whose pointer is to be moved.
- * @param x Returns the x position of the pointer after the move.
- * @param y Returns the y position of the pointer after the move.
  * @param mask Valuator data for this event.
  */
 static void
-moveRelative(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
+moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
 {
     int i;
     Bool clip_xy = IsMaster(dev) || !IsFloating(dev);
@@ -752,9 +745,6 @@ moveRelative(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
         dev->last.remainder[i] = val - trunc(val);
         valuator_mask_set_double(mask, i, val);
     }
-
-    *x_out = dev->last.valuators[0];
-    *y_out = dev->last.valuators[1];
 }
 
 /**
@@ -1182,26 +1172,34 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         }
 
         transformAbsolute(pDev, &mask);
-        moveAbsolute(pDev, &x, &y, &mask);
+        moveAbsolute(pDev, &mask);
     } else {
         if (flags & POINTER_ACCELERATE)
             accelPointer(pDev, &mask, ms);
-        moveRelative(pDev, &x, &y, &mask);
+        moveRelative(pDev, &mask);
     }
 
     if ((flags & POINTER_NORAW) == 0)
         set_raw_valuators(raw, &mask, raw->valuators.data,
                           raw->valuators.data_frac);
 
-    if (valuator_mask_isset(&mask, 0))
-    {
-        x_frac = valuator_mask_get_double(&mask, 0);
-        x_frac -= trunc(x_frac);
+    if (valuator_mask_isset(&mask, 0)) {
+        double tmp = valuator_mask_get_double(&mask, 0);
+        x = trunc(tmp);
+        x_frac = tmp - x;
     }
-    if (valuator_mask_isset(&mask, 1))
-    {
-        y_frac = valuator_mask_get_double(&mask, 1);
-        y_frac -= trunc(y_frac);
+    else {
+        x = pDev->last.valuators[0];
+        x_frac = pDev->last.remainder[0];
+    }
+    if (valuator_mask_isset(&mask, 1)) {
+        double tmp = valuator_mask_get_double(&mask, 1);
+        y = trunc(tmp);
+        y_frac = tmp - y;
+    }
+    else {
+        y = pDev->last.valuators[1];
+        y_frac = pDev->last.remainder[1];
     }
 
     positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
commit 0882b788da97c75e464eb352dac1d83c938a148e
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 16:27:31 2011 +0000

    Input: Convert acceleration code to using ValuatorMask
    
    Instead of passing a set of int* to the acceleration code, pass it a
    mask instead, which avoids an unfortunate loss of precision.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/getevents.c b/dix/getevents.c
index b8f4a8c..483d65f 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1184,13 +1184,8 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         transformAbsolute(pDev, &mask);
         moveAbsolute(pDev, &x, &y, &mask);
     } else {
-        if (flags & POINTER_ACCELERATE) {
+        if (flags & POINTER_ACCELERATE)
             accelPointer(pDev, &mask, ms);
-            /* The pointer acceleration code modifies the fractional part
-             * in-place, so we need to extract this information first */
-            x_frac = pDev->last.remainder[0];
-            y_frac = pDev->last.remainder[1];
-        }
         moveRelative(pDev, &x, &y, &mask);
     }
 
@@ -1198,6 +1193,17 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         set_raw_valuators(raw, &mask, raw->valuators.data,
                           raw->valuators.data_frac);
 
+    if (valuator_mask_isset(&mask, 0))
+    {
+        x_frac = valuator_mask_get_double(&mask, 0);
+        x_frac -= trunc(x_frac);
+    }
+    if (valuator_mask_isset(&mask, 1))
+    {
+        y_frac = valuator_mask_get_double(&mask, 1);
+        y_frac -= trunc(y_frac);
+    }
+
     positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
                    &x, &y, x_frac, y_frac, scr, &cx, &cy, &cx_frac, &cy_frac);
     updateHistory(pDev, &mask, ms);
diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 6271a6d..53a0d03 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -1115,11 +1115,10 @@ acceleratePointerPredictable(
     CARD32 evtime)
 {
     double dx = 0, dy = 0;
-    int tmpi;
     DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
     Bool soften = TRUE;
 
-    if (!velocitydata)
+    if (valuator_mask_num_valuators(val) == 0 || !velocitydata)
         return;
 
     if (velocitydata->statistics.profile_number == AccelProfileNone &&
@@ -1128,11 +1127,11 @@ acceleratePointerPredictable(
     }
 
     if (valuator_mask_isset(val, 0)) {
-        dx = valuator_mask_get(val, 0);
+        dx = valuator_mask_get_double(val, 0);
     }
 
     if (valuator_mask_isset(val, 1)) {
-        dy = valuator_mask_get(val, 1);
+        dy = valuator_mask_get_double(val, 1);
     }
 
     if (dx != 0.0 || dy != 0.0) {
@@ -1155,24 +1154,12 @@ acceleratePointerPredictable(
                     ApplySoftening(velocitydata, &dx, &dy);
                 ApplyConstantDeceleration(velocitydata, &dx, &dy);
 
-                /* Calculate the new delta (with accel) and drop it back
-                 * into the valuator masks */
-                if (dx != 0.0) {
-                    double tmp;
-                    tmp = mult * dx + dev->last.remainder[0];
-                    tmpi = trunc(tmp);
-                    valuator_mask_set(val, 0, tmpi);
-                    dev->last.remainder[0] = tmp - (double)tmpi;
-                }
-                if (dy != 0.0) {
-                    double tmp;
-                    tmp = mult * dy + dev->last.remainder[1];
-                    tmpi = trunc(tmp);
-                    valuator_mask_set(val, 1, tmpi);
-                    dev->last.remainder[1] = tmp - (double)tmpi;
-                }
-                DebugAccelF("pos (%i | %i) remainders x: %.3f y: %.3f delta x:%.3f y:%.3f\n",
-                            *px, *py, dev->last.remainder[0], dev->last.remainder[1], dx, dy);
+                if (dx != 0.0)
+                    valuator_mask_set_double(val, 0, mult * dx);
+                if (dy != 0.0)
+                    valuator_mask_set_double(val, 1, mult * dy);
+                DebugAccelF("pos (%i | %i) delta x:%.3f y:%.3f\n", mult * dx,
+                            mult * dy);
             }
         }
     }
@@ -1195,7 +1182,6 @@ acceleratePointerLightweight(
 {
     double mult = 0.0, tmpf;
     double dx = 0.0, dy = 0.0;
-    int tmpi;
 
     if (valuator_mask_isset(val, 0)) {
         dx = valuator_mask_get(val, 0);
@@ -1205,53 +1191,35 @@ acceleratePointerLightweight(
         dy = valuator_mask_get(val, 1);
     }
 
-    if (dx == 0.0 && dy == 0.0)
+    if (valuator_mask_num_valuators(val) == 0)
         return;
 
     if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
         /* modeled from xf86Events.c */
         if (dev->ptrfeed->ctrl.threshold) {
-            if ((abs(dx) + abs(dy)) >= dev->ptrfeed->ctrl.threshold) {
-                tmpf = ((double)dx *
-                        (double)(dev->ptrfeed->ctrl.num)) /
-                       (double)(dev->ptrfeed->ctrl.den) +
-                       dev->last.remainder[0];
+            if ((fabs(dx) + fabs(dy)) >= dev->ptrfeed->ctrl.threshold) {
                 if (dx != 0.0) {
-                    tmpi = (int) tmpf;
-                    valuator_mask_set(val, 0, tmpi);
-                    dev->last.remainder[0] = tmpf - (double)tmpi;
+                    tmpf = (dx * (double)(dev->ptrfeed->ctrl.num)) /
+                           (double)(dev->ptrfeed->ctrl.den);
+                    valuator_mask_set_double(val, 0, tmpf);
                 }
 
-                tmpf = ((double)dy *
-                        (double)(dev->ptrfeed->ctrl.num)) /
-                       (double)(dev->ptrfeed->ctrl.den) +
-                       dev->last.remainder[1];
                 if (dy != 0.0) {
-                    tmpi = (int) tmpf;
-                    valuator_mask_set(val, 1, tmpi);
-                    dev->last.remainder[1] = tmpf - (double)tmpi;
+                    tmpf = (dy * (double)(dev->ptrfeed->ctrl.num)) /
+                           (double)(dev->ptrfeed->ctrl.den);
+                    valuator_mask_set_double(val, 1, tmpf);
                 }
             }
         }
         else {
-	    mult = pow((double)dx * (double)dx + (double)dy * (double)dy,
+	    mult = pow(dx * dx + dy * dy,
                        ((double)(dev->ptrfeed->ctrl.num) /
                         (double)(dev->ptrfeed->ctrl.den) - 1.0) /
                        2.0) / 2.0;
-            if (dx != 0.0) {
-                tmpf = mult * (double)dx +
-                       dev->last.remainder[0];
-                tmpi = (int) tmpf;
-                valuator_mask_set(val, 0, tmpi);
-                dev->last.remainder[0] = tmpf - (double)tmpi;
-            }
-            if (dy != 0.0) {
-                tmpf = mult * (double)dy +
-                       dev->last.remainder[1];
-                tmpi = (int)tmpf;
-                valuator_mask_set(val, 1, tmpi);
-                dev->last.remainder[1] = tmpf - (double)tmpi;
-            }
+            if (dx != 0.0)
+                valuator_mask_set_double(val, 0, mult * dx);
+            if (dy != 0.0)
+                valuator_mask_set_double(val, 1, mult * dy);
         }
     }
 }
commit 2b8f1d07bd42c9d3db3dbacfe6a1335e47236a6c
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 15:37:53 2011 +0000

    Input: Widen pointer acceleration types to double
    
    This widens almost all of the float-using code in ptrveloc.[ch] to
    doubles, other than values coming from properties which are specified to
    be floats by the property API.
    
    Bumps input API to v14 as this changes the AccelScheme signature, as
    used by xf86-input-synaptics.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index c506791..6271a6d 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -63,9 +63,9 @@
 /* fwds */
 int
 SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
-static float
-SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity,
-                    float threshold, float acc);
+static double
+SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, double velocity,
+                    double threshold, double acc);
 static PointerAccelerationProfileFunc
 GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
 static BOOL
@@ -478,14 +478,10 @@ DoGetDirection(int dx, int dy){
         else
             dir = UNDEFINED; /* shouldn't happen */
     } else { /* compute angle and set appropriate flags */
-        float r;
+        double r;
         int i1, i2;
 
-#ifdef _ISOC99_SOURCE
-        r = atan2f(dy, dx);
-#else
         r = atan2(dy, dx);
-#endif
         /* find direction.
          *
          * Add 360° to avoid r become negative since C has no well-defined
@@ -524,8 +520,7 @@ static int
 GetDirection(int dx, int dy){
     static int cache[DIRECTION_CACHE_SIZE][DIRECTION_CACHE_SIZE];
     int dir;
-    if (abs(dx) <= DIRECTION_CACHE_RANGE &&
-	abs(dy) <= DIRECTION_CACHE_RANGE) {
+    if (abs(dx) <= DIRECTION_CACHE_RANGE && abs(dy) <= DIRECTION_CACHE_RANGE) {
 	/* cacheable */
 	dir = cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy];
 	if(dir == 0) {
@@ -553,7 +548,7 @@ GetDirection(int dx, int dy){
  * 0/0 and set it as the current one.
  */
 static inline void
-FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
+FeedTrackers(DeviceVelocityPtr vel, double dx, double dy, int cur_t)
 {
     int n;
     for(n = 0; n < vel->num_tracker; n++){
@@ -561,8 +556,8 @@ FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
 	vel->tracker[n].dy += dy;
     }
     n = (vel->cur_tracker + 1) % vel->num_tracker;
-    vel->tracker[n].dx = 0;
-    vel->tracker[n].dy = 0;
+    vel->tracker[n].dx = 0.0;
+    vel->tracker[n].dy = 0.0;
     vel->tracker[n].time = cur_t;
     vel->tracker[n].dir = GetDirection(dx, dy);
     DebugAccelF("(dix prtacc) motion [dx: %i dy: %i dir:%i diff: %i]\n",
@@ -576,9 +571,9 @@ FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
  * velocity scaling.
  * This assumes linear motion.
  */
-static float
+static double
 CalcTracker(const MotionTracker *tracker, int cur_t){
-    float dist = sqrt(tracker->dx * tracker->dx + tracker->dy * tracker->dy);
+    double dist = sqrt(tracker->dx * tracker->dx + tracker->dy * tracker->dy);
     int dtime = cur_t - tracker->time;
     if(dtime > 0)
 	return dist / dtime;
@@ -593,16 +588,16 @@ CalcTracker(const MotionTracker *tracker, int cur_t){
  *
  * @return The tracker's velocity or 0 if the above conditions are unmet
  */
-static float
+static double
 QueryTrackers(DeviceVelocityPtr vel, int cur_t){
     int offset, dir = UNDEFINED, used_offset = -1, age_ms;
     /* initial velocity: a low-offset, valid velocity */
-    float initial_velocity = 0, result = 0, velocity_diff;
-    float velocity_factor =  vel->corr_mul * vel->const_acceleration; /* premultiply */
+    double initial_velocity = 0, result = 0, velocity_diff;
+    double velocity_factor =  vel->corr_mul * vel->const_acceleration; /* premultiply */
     /* loop from current to older data */
     for(offset = 1; offset < vel->num_tracker; offset++){
 	MotionTracker *tracker = TRACKER(vel, offset);
-	float tracker_velocity;
+	double tracker_velocity;
 
 	age_ms = cur_t - tracker->time;
 
@@ -674,11 +669,11 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 BOOL
 ProcessVelocityData2D(
     DeviceVelocityPtr vel,
-    int dx,
-    int dy,
+    double dx,
+    double dy,
     int time)
 {
-    float velocity;
+    double velocity;
 
     vel->last_velocity = vel->velocity;
 
@@ -694,12 +689,12 @@ ProcessVelocityData2D(
  * this flattens significant ( > 1) mickeys a little bit for more steady
  * constant-velocity response
  */
-static inline float
-ApplySimpleSoftening(int prev_delta, int delta)
+static inline double
+ApplySimpleSoftening(double prev_delta, double delta)
 {
-    float result = delta;
+    double result = delta;
 
-    if (delta < -1 || delta > 1) {
+    if (delta < -1.0 || delta > 1.0) {
 	if (delta > prev_delta)
 	    result -= 0.5;
 	else if (delta < prev_delta)
@@ -718,8 +713,8 @@ ApplySimpleSoftening(int prev_delta, int delta)
 static void
 ApplySoftening(
         DeviceVelocityPtr vel,
-        float* fdx,
-        float* fdy)
+        double* fdx,
+        double* fdy)
 {
     if (vel->use_softening) {
         *fdx = ApplySimpleSoftening(vel->last_dx, *fdx);
@@ -728,7 +723,7 @@ ApplySoftening(
 }
 
 static void
-ApplyConstantDeceleration(DeviceVelocityPtr vel, float *fdx, float *fdy)
+ApplyConstantDeceleration(DeviceVelocityPtr vel, double *fdx, double *fdy)
 {
     *fdx *= vel->const_acceleration;
     *fdy *= vel->const_acceleration;
@@ -737,15 +732,15 @@ ApplyConstantDeceleration(DeviceVelocityPtr vel, float *fdx, float *fdy)
 /*
  * compute the acceleration for given velocity and enforce min_acceleartion
  */
-float
+double
 BasicComputeAcceleration(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc){
+    double velocity,
+    double threshold,
+    double acc){
 
-    float result;
+    double result;
     result = vel->Profile(dev, vel, velocity, threshold, acc);
 
     /* enforce min_acceleration */
@@ -759,13 +754,13 @@ BasicComputeAcceleration(
  * If the velocity has changed, an average is taken of 6 velocity factors:
  * current velocity, last velocity and 4 times the average between the two.
  */
-static float
+static double
 ComputeAcceleration(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float threshold,
-    float acc){
-    float result;
+    double threshold,
+    double acc){
+    double result;
 
     if(vel->velocity <= 0){
 	DebugAccelF("(dix ptracc) profile skipped\n");
@@ -808,13 +803,13 @@ ComputeAcceleration(
 /**
  * Polynomial function similar previous one, but with f(1) = 1
  */
-static float
+static double
 PolynomialAccelerationProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float ignored,
-    float acc)
+    double velocity,
+    double ignored,
+    double acc)
 {
    return pow(velocity, (acc - 1.0) * 0.5);
 }
@@ -824,13 +819,13 @@ PolynomialAccelerationProfile(
  * returns acceleration for velocity.
  * This profile selects the two functions like the old scheme did
  */
-static float
+static double
 ClassicProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc)
+    double velocity,
+    double threshold,
+    double acc)
 {
     if (threshold > 0) {
 	return SimpleSmoothProfile (dev,
@@ -856,15 +851,15 @@ ClassicProfile(
  * This has the expense of overall response dependency on min-acceleration.
  * In effect, min_acceleration mimics const_acceleration in this profile.
  */
-static float
+static double
 PowerProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc)
+    double velocity,
+    double threshold,
+    double acc)
 {
-    float vel_dist;
+    double vel_dist;
 
     acc = (acc-1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */
 
@@ -882,11 +877,11 @@ PowerProfile(
  *  - starts faster than a sinoid
  *  - smoothness C1 (Cinf if you dare to ignore endpoints)
  */
-static inline float
-CalcPenumbralGradient(float x){
+static inline double
+CalcPenumbralGradient(double x){
     x *= 2.0f;
     x -= 1.0f;
-    return 0.5f + (x * sqrt(1.0f - x*x) + asin(x))/M_PI;
+    return 0.5f + (x * sqrt(1.0 - x*x) + asin(x))/M_PI;
 }
 
 
@@ -894,13 +889,13 @@ CalcPenumbralGradient(float x){
  * acceleration function similar to classic accelerated/unaccelerated,
  * but with smooth transition in between (and towards zero for adaptive dec.).
  */
-static float
+static double
 SimpleSmoothProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc)
+    double velocity,
+    double threshold,
+    double acc)
 {
     if(velocity < 1.0f)
         return CalcPenumbralGradient(0.5 + velocity*0.5) * 2.0f - 1.0f;
@@ -920,15 +915,15 @@ SimpleSmoothProfile(
  * This profile uses the first half of the penumbral gradient as a start
  * and then scales linearly.
  */
-static float
+static double
 SmoothLinearProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc)
+    double velocity,
+    double threshold,
+    double acc)
 {
-    float res, nv;
+    double res, nv;
 
     if(acc > 1.0f)
         acc -= 1.0f; /*this is so acc = 1 is no acceleration */
@@ -955,15 +950,15 @@ SmoothLinearProfile(
  * From 0 to threshold, the response graduates smoothly from min_accel to
  * acceleration. Beyond threshold it is exactly the specified acceleration.
  */
-static float
+static double
 SmoothLimitedProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc)
+    double velocity,
+    double threshold,
+    double acc)
 {
-    float res;
+    double res;
 
     if(velocity >= threshold || threshold == 0.0f)
 	return acc;
@@ -976,24 +971,24 @@ SmoothLimitedProfile(
 }
 
 
-static float
+static double
 LinearProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc)
+    double velocity,
+    double threshold,
+    double acc)
 {
     return acc * velocity;
 }
 
-static float
+static double
 NoProfile(
     DeviceIntPtr dev,
     DeviceVelocityPtr vel,
-    float velocity,
-    float threshold,
-    float acc)
+    double velocity,
+    double threshold,
+    double acc)
 {
     return 1.0f;
 }
@@ -1119,7 +1114,8 @@ acceleratePointerPredictable(
     ValuatorMask* val,
     CARD32 evtime)
 {
-    int dx = 0, dy = 0, tmpi;
+    double dx = 0, dy = 0;
+    int tmpi;
     DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
     Bool soften = TRUE;
 
@@ -1139,47 +1135,44 @@ acceleratePointerPredictable(
         dy = valuator_mask_get(val, 1);
     }
 
-    if (dx || dy){
+    if (dx != 0.0 || dy != 0.0) {
         /* reset non-visible state? */
         if (ProcessVelocityData2D(velocitydata, dx , dy, evtime)) {
             soften = FALSE;
         }
 
         if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
-            float mult;
+            double mult;
 
             /* invoke acceleration profile to determine acceleration */
             mult = ComputeAcceleration (dev, velocitydata,
-                                        dev->ptrfeed->ctrl.threshold,
-                                        (float)dev->ptrfeed->ctrl.num /
-                                            (float)dev->ptrfeed->ctrl.den);
+					dev->ptrfeed->ctrl.threshold,
+					(double)dev->ptrfeed->ctrl.num /
+					(double)dev->ptrfeed->ctrl.den);
 
             if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) {
-                float fdx = dx,
-                      fdy = dy;
-
                 if (mult > 1.0f && soften)
-                    ApplySoftening(velocitydata, &fdx, &fdy);
-                ApplyConstantDeceleration(velocitydata, &fdx, &fdy);
+                    ApplySoftening(velocitydata, &dx, &dy);
+                ApplyConstantDeceleration(velocitydata, &dx, &dy);
 
                 /* Calculate the new delta (with accel) and drop it back
                  * into the valuator masks */
-                if (dx) {
-                    float tmp;
-                    tmp = mult * fdx + dev->last.remainder[0];
+                if (dx != 0.0) {
+                    double tmp;
+                    tmp = mult * dx + dev->last.remainder[0];
                     tmpi = trunc(tmp);
                     valuator_mask_set(val, 0, tmpi);
-                    dev->last.remainder[0] = tmp - (float)tmpi;
+                    dev->last.remainder[0] = tmp - (double)tmpi;
                 }
-                if (dy) {
-                    float tmp;
-                    tmp = mult * fdy + dev->last.remainder[1];
+                if (dy != 0.0) {
+                    double tmp;
+                    tmp = mult * dy + dev->last.remainder[1];
                     tmpi = trunc(tmp);
                     valuator_mask_set(val, 1, tmpi);
-                    dev->last.remainder[1] = tmp - (float)tmpi;
+                    dev->last.remainder[1] = tmp - (double)tmpi;
                 }
                 DebugAccelF("pos (%i | %i) remainders x: %.3f y: %.3f delta x:%.3f y:%.3f\n",
-                            *px, *py, dev->last.remainder[0], dev->last.remainder[1], fdx, fdy);
+                            *px, *py, dev->last.remainder[0], dev->last.remainder[1], dx, dy);
             }
         }
     }
@@ -1200,8 +1193,9 @@ acceleratePointerLightweight(
     ValuatorMask* val,
     CARD32 ignored)
 {
-    float mult = 0.0, tmpf;
-    int dx = 0, dy = 0, tmpi;
+    double mult = 0.0, tmpf;
+    double dx = 0.0, dy = 0.0;
+    int tmpi;
 
     if (valuator_mask_isset(val, 0)) {
         dx = valuator_mask_get(val, 0);
@@ -1211,52 +1205,52 @@ acceleratePointerLightweight(
         dy = valuator_mask_get(val, 1);
     }
 
-    if (!dx && !dy)
+    if (dx == 0.0 && dy == 0.0)
         return;
 
     if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
         /* modeled from xf86Events.c */
         if (dev->ptrfeed->ctrl.threshold) {
             if ((abs(dx) + abs(dy)) >= dev->ptrfeed->ctrl.threshold) {
-                tmpf = ((float)dx *
-                        (float)(dev->ptrfeed->ctrl.num)) /
-                       (float)(dev->ptrfeed->ctrl.den) +
+                tmpf = ((double)dx *
+                        (double)(dev->ptrfeed->ctrl.num)) /
+                       (double)(dev->ptrfeed->ctrl.den) +
                        dev->last.remainder[0];
-                if (dx) {
+                if (dx != 0.0) {
                     tmpi = (int) tmpf;
                     valuator_mask_set(val, 0, tmpi);
-                    dev->last.remainder[0] = tmpf - (float)tmpi;
+                    dev->last.remainder[0] = tmpf - (double)tmpi;
                 }
 
-                tmpf = ((float)dy *
-                        (float)(dev->ptrfeed->ctrl.num)) /
-                       (float)(dev->ptrfeed->ctrl.den) +
+                tmpf = ((double)dy *
+                        (double)(dev->ptrfeed->ctrl.num)) /
+                       (double)(dev->ptrfeed->ctrl.den) +
                        dev->last.remainder[1];
-                if (dy) {
+                if (dy != 0.0) {
                     tmpi = (int) tmpf;
                     valuator_mask_set(val, 1, tmpi);
-                    dev->last.remainder[1] = tmpf - (float)tmpi;
+                    dev->last.remainder[1] = tmpf - (double)tmpi;
                 }
             }
         }
         else {
-            mult = pow((float)dx * (float)dx + (float)dy * (float)dy,
-                       ((float)(dev->ptrfeed->ctrl.num) /
-                        (float)(dev->ptrfeed->ctrl.den) - 1.0) /
+	    mult = pow((double)dx * (double)dx + (double)dy * (double)dy,
+                       ((double)(dev->ptrfeed->ctrl.num) /
+                        (double)(dev->ptrfeed->ctrl.den) - 1.0) /
                        2.0) / 2.0;
-            if (dx) {
-                tmpf = mult * (float)dx +
+            if (dx != 0.0) {
+                tmpf = mult * (double)dx +
                        dev->last.remainder[0];
                 tmpi = (int) tmpf;
                 valuator_mask_set(val, 0, tmpi);
-                dev->last.remainder[0] = tmpf - (float)tmpi;
+                dev->last.remainder[0] = tmpf - (double)tmpi;
             }
-            if (dy) {
-                tmpf = mult * (float)dy +
+            if (dy != 0.0) {
+                tmpf = mult * (double)dy +
                        dev->last.remainder[1];
                 tmpi = (int)tmpf;
                 valuator_mask_set(val, 1, tmpi);
-                dev->last.remainder[1] = tmpf - (float)tmpi;
+                dev->last.remainder[1] = tmpf - (double)tmpi;
             }
         }
     }
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 3038c04..330d87a 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -83,7 +83,7 @@ typedef enum {
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
 #define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(11, 0)
-#define ABI_XINPUT_VERSION	SET_ABI_VERSION(13, 0)
+#define ABI_XINPUT_VERSION	SET_ABI_VERSION(14, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(6, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
 
diff --git a/include/ptrveloc.h b/include/ptrveloc.h
index 6ca309c..4f76b00 100644
--- a/include/ptrveloc.h
+++ b/include/ptrveloc.h
@@ -47,9 +47,9 @@ struct _DeviceVelocityRec;
  * profile
  * returns actual acceleration depending on velocity, acceleration control,...
  */
-typedef float (*PointerAccelerationProfileFunc)
+typedef double (*PointerAccelerationProfileFunc)
               (DeviceIntPtr dev, struct _DeviceVelocityRec* vel,
-               float velocity, float threshold, float accelCoeff);
+               double velocity, double threshold, double accelCoeff);
 
 /**
  * a motion history, with just enough information to
@@ -57,8 +57,8 @@ typedef float (*PointerAccelerationProfileFunc)
  * a more or less straight line
  */
 typedef struct _MotionTracker {
-    int dx, dy;     /* accumulated delta for each axis */
-    int time;         /* time of creation */
+    double dx, dy;  /* accumulated delta for each axis */
+    int time;       /* time of creation */
     int dir;        /* initial direction bitfield */
 } MotionTracker, *MotionTrackerPtr;
 
@@ -69,17 +69,17 @@ typedef struct _DeviceVelocityRec {
     MotionTrackerPtr tracker;
     int num_tracker;
     int cur_tracker;        /* current index */
-    float   velocity;       /* velocity as guessed by algorithm */
-    float   last_velocity;  /* previous velocity estimate */
-    int     last_dx;      /* last time-difference */
-    int     last_dy ;     /* phase of last/current estimate */
-    float   corr_mul;       /* config: multiply this into velocity */
-    float   const_acceleration;  /* config: (recipr.) const deceleration */
-    float   min_acceleration;    /* config: minimum acceleration */
+    double  velocity;       /* velocity as guessed by algorithm */
+    double  last_velocity;  /* previous velocity estimate */
+    double  last_dx;        /* last time-difference */
+    double  last_dy;        /* phase of last/current estimate */
+    double  corr_mul;       /* config: multiply this into velocity */
+    double  const_acceleration;  /* config: (recipr.) const deceleration */
+    double  min_acceleration;    /* config: minimum acceleration */
     short   reset_time;     /* config: reset non-visible state after # ms */
     short   use_softening;  /* config: use softening of mouse values */
-    float   max_rel_diff;   /* config: max. relative difference */
-    float   max_diff;       /* config: max. difference */
+    double  max_rel_diff;   /* config: max. relative difference */
+    double  max_diff;       /* config: max. difference */
     int     initial_range;  /* config: max. offset used as initial velocity */
     Bool    average_accel;  /* config: average acceleration over velocity */
     PointerAccelerationProfileFunc Profile;
@@ -107,11 +107,11 @@ extern _X_EXPORT void
 InitTrackers(DeviceVelocityPtr vel, int ntracker);
 
 extern _X_EXPORT BOOL
-ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time);
+ProcessVelocityData2D(DeviceVelocityPtr vel, double dx, double dy, int time);
 
-extern _X_EXPORT float
+extern _X_EXPORT double
 BasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel,
-    float velocity, float threshold, float acc);
+    double velocity, double threshold, double acc);
 
 extern _X_EXPORT void
 FreeVelocityData(DeviceVelocityPtr vel);
commit 8a4a4e1b8a33899653d68a21bb7ff0557a576338
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Jun 9 15:26:55 2011 +0100

    Input: Use trunc instead of lrintf in acceleration code
    
    For compatibility with all the rest of the input code.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index dfccf15..c506791 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -1167,19 +1167,14 @@ acceleratePointerPredictable(
                 if (dx) {
                     float tmp;
                     tmp = mult * fdx + dev->last.remainder[0];
-                    /* Since it may not be apparent: lrintf() does not offer
-                     * strong statements about rounding; however because we
-                     * process each axis conditionally, there's no danger
-                     * of a toggling remainder. Its lack of guarantees likely
-                     * makes it faster on the average target. */
-                    tmpi = lrintf(tmp);
+                    tmpi = trunc(tmp);
                     valuator_mask_set(val, 0, tmpi);
                     dev->last.remainder[0] = tmp - (float)tmpi;
                 }
                 if (dy) {
                     float tmp;
                     tmp = mult * fdy + dev->last.remainder[1];
-                    tmpi = lrintf(tmp);
+                    tmpi = trunc(tmp);
                     valuator_mask_set(val, 1, tmpi);
                     dev->last.remainder[1] = tmp - (float)tmpi;
                 }
commit e1df51421bc392d57f88c831fe0661871a8aa769
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 13:34:32 2011 +0000

    Input: Set fractional member in set_raw_valuators
    
    RawDeviceEvents have space for fractional valuator members, so might as
    well start using them.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index 76e8a32..b8f4a8c 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -167,16 +167,20 @@ init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail)
 }
 
 static void
-set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, int32_t* data)
+set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, int32_t* data,
+                  int32_t* data_frac)
 {
     int i;
+    double val;
 
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
         if (valuator_mask_isset(mask, i))
         {
             SetBit(event->valuators.mask, i);
-            data[i] = valuator_mask_get(mask, i);
+            val = valuator_mask_get_double(mask, i);
+            data[i] = trunc(val);
+            data_frac[i] = (val - data[i]) * (1UL << 32);
         }
     }
 }
@@ -969,11 +973,13 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     valuator_mask_copy(&mask, mask_in);
 
     init_raw(pDev, raw, ms, type, key_code);
-    set_raw_valuators(raw, &mask, raw->valuators.data_raw);
+    set_raw_valuators(raw, &mask, raw->valuators.data_raw,
+                      raw->valuators.data_raw_frac);
 
     clipValuators(pDev, &mask);
 
-    set_raw_valuators(raw, &mask, raw->valuators.data);
+    set_raw_valuators(raw, &mask, raw->valuators.data,
+                      raw->valuators.data_frac);
 
     event = &events->device_event;
     init_device_event(event, pDev, ms);
@@ -1147,7 +1153,8 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
 	num_events++;
 
 	init_raw(pDev, raw, ms, type, buttons);
-	set_raw_valuators(raw, &mask, raw->valuators.data_raw);
+	set_raw_valuators(raw, &mask, raw->valuators.data_raw,
+                          raw->valuators.data_raw_frac);
     }
 
     if (flags & POINTER_ABSOLUTE)
@@ -1188,7 +1195,8 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     }
 
     if ((flags & POINTER_NORAW) == 0)
-	set_raw_valuators(raw, &mask, raw->valuators.data);
+        set_raw_valuators(raw, &mask, raw->valuators.data,
+                          raw->valuators.data_frac);
 
     positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
                    &x, &y, x_frac, y_frac, scr, &cx, &cy, &cx_frac, &cy_frac);
commit cdf202250ef616f3b261db70da30e421ea59a630
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 14:50:29 2011 +0000

    Input: Convert transformAbsolute to work on doubles
    
    Change transformAbsolute to use doubles internally.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index 30044ba..76e8a32 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1026,32 +1026,37 @@ FreeEventList(InternalEvent *list, int num_events)
  * back into x/y.
  */
 static void
-transform(struct pixman_f_transform *m, int *x, int *y)
+transform(struct pixman_f_transform *m, double *x, double *y)
 {
     struct pixman_f_vector p = {.v = {*x, *y, 1}};
     pixman_f_transform_point(m, &p);
 
-    *x = lround(p.v[0]);
-    *y = lround(p.v[1]);
+    *x = p.v[0];
+    *y = p.v[1];
 }
 
 static void
 transformAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
 {
-    int x, y, ox, oy;
+    double x, y, ox, oy;
 
-    ox = x = valuator_mask_isset(mask, 0) ? valuator_mask_get(mask, 0) :
-                                            dev->last.valuators[0];
-    oy = y = valuator_mask_isset(mask, 1) ? valuator_mask_get(mask, 1) :
-                                            dev->last.valuators[1];
+    if (valuator_mask_isset(mask, 0))
+        ox = x = valuator_mask_get_double(mask, 0);
+    else
+        ox = x = dev->last.valuators[0] + dev->last.remainder[0];
+
+    if (valuator_mask_isset(mask, 1))
+        oy = y = valuator_mask_get_double(mask, 1);
+    else
+        oy = y = dev->last.valuators[1] + dev->last.remainder[1];
 
     transform(&dev->transform, &x, &y);
 
     if (valuator_mask_isset(mask, 0) || ox != x)
-        valuator_mask_set(mask, 0, x);
+        valuator_mask_set_double(mask, 0, x);
 
     if (valuator_mask_isset(mask, 1) || oy != y)
-        valuator_mask_set(mask, 1, y);
+        valuator_mask_set_double(mask, 1, y);
 }
 
 /**
commit 3463078f9697fad0ee11837d80e88889fc6a28a4
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 13:29:24 2011 +0000

    Input: Convert clipAxis, moveAbsolute and moveRelative to double
    
    Change all these three to use doubles internally, though the outputs of
    moveAbsolute and moveRelative are still truncated to int.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/getevents.c b/dix/getevents.c
index fd8b098..30044ba 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -617,7 +617,7 @@ GetMaximumEventsNum(void) {
  * InitValuatorAxisClassStruct.
  */
 static void
-clipAxis(DeviceIntPtr pDev, int axisNum, int *val)
+clipAxis(DeviceIntPtr pDev, int axisNum, double *val)
 {
     AxisInfoPtr axis;
 
@@ -647,9 +647,9 @@ clipValuators(DeviceIntPtr pDev, ValuatorMask *mask)
     for (i = 0; i < valuator_mask_size(mask); i++)
         if (valuator_mask_isset(mask, i))
         {
-            int val = valuator_mask_get(mask, i);
+            double val = valuator_mask_get_double(mask, i);
             clipAxis(pDev, i, &val);
-            valuator_mask_set(mask, i, val);
+            valuator_mask_set_double(mask, i, val);
         }
 }
 
@@ -699,17 +699,18 @@ static void
 moveAbsolute(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
 {
     int i;
-    int x, y;
 
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
-        if (valuator_mask_isset(mask, i))
-        {
-            int val = valuator_mask_get(mask, i);
-            clipAxis(dev, i, &val);
-            dev->last.valuators[i] = val;
-            valuator_mask_set(mask, i, val);
-        }
+        double val;
+
+        if (!valuator_mask_isset(mask, i))
+            continue;
+        val = valuator_mask_get_double(mask, i);
+        clipAxis(dev, i, &val);
+        dev->last.valuators[i] = trunc(val);
+        dev->last.remainder[i] = val - trunc(val);
+        valuator_mask_set_double(mask, i, val);
     }
 
     *x_out = dev->last.valuators[0];
@@ -733,18 +734,19 @@ moveRelative(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
     /* calc other axes, clip, drop back into valuators */
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
-        if (valuator_mask_isset(mask, i))
-        {
-            int val = dev->last.valuators[i];
-            val += valuator_mask_get(mask, i);
-            /* x & y need to go over the limits to cross screens if the SD
-             * isn't currently attached; otherwise, clip to screen bounds. */
-            if (valuator_get_mode(dev, i) == Absolute &&
-                ((i != 0 && i != 1) || clip_xy))
-                clipAxis(dev, i, &val);
-            dev->last.valuators[i] = val;
-            valuator_mask_set(mask, i, val);
-        }
+        double val = dev->last.valuators[i] + dev->last.remainder[i];
+
+        if (!valuator_mask_isset(mask, i))
+            continue;
+        val += valuator_mask_get_double(mask, i);
+        /* x & y need to go over the limits to cross screens if the SD
+         * isn't currently attached; otherwise, clip to screen bounds. */
+        if (valuator_get_mode(dev, i) == Absolute &&
+            ((i != 0 && i != 1) || clip_xy))
+            clipAxis(dev, i, &val);
+        dev->last.valuators[i] = trunc(val);
+        dev->last.remainder[i] = val - trunc(val);
+        valuator_mask_set_double(mask, i, val);
     }
 
     *x_out = dev->last.valuators[0];
commit 4e52cc0ef48145134cd58d357fb7289e6f8bb709
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 13:20:37 2011 +0000

    Input: Prepare moveRelative for conversion to double
    
    Shuffle some code around in moveRelative to make the conversion to
    double easier later.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index bcac6aa..fd8b098 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -719,48 +719,36 @@ moveAbsolute(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
 /**
  * Move the device's pointer by the values given in @valuators.
  *
- * @param dev The device which's pointer is to be moved.
+ * @param dev The device whose pointer is to be moved.
  * @param x Returns the x position of the pointer after the move.
  * @param y Returns the y position of the pointer after the move.
- * @param mask Bit mask of valid valuators.
- * @param valuators Valuator data for each axis between @first and
- *        @first+ at num.
+ * @param mask Valuator data for this event.
  */
 static void
-moveRelative(DeviceIntPtr dev, int *x, int *y, ValuatorMask *mask)
+moveRelative(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
 {
     int i;
-
-    *x = dev->last.valuators[0];
-    *y = dev->last.valuators[1];
-
-    if (valuator_mask_isset(mask, 0))
-        *x += valuator_mask_get(mask, 0);
-
-    if (valuator_mask_isset(mask, 1))
-        *y += valuator_mask_get(mask, 1);
-
-    /* if attached, clip both x and y to the defined limits (usually
-     * co-ord space limit). If it is attached, we need x/y to go over the
-     * limits to be able to change screens. */
-    if (dev->valuator && (IsMaster(dev) || !IsFloating(dev))) {
-        if (valuator_get_mode(dev, 0) == Absolute)
-            clipAxis(dev, 0, x);
-        if (valuator_get_mode(dev, 1) == Absolute)
-            clipAxis(dev, 1, y);
-    }
+    Bool clip_xy = IsMaster(dev) || !IsFloating(dev);
 
     /* calc other axes, clip, drop back into valuators */
-    for (i = 2; i < valuator_mask_size(mask); i++)
+    for (i = 0; i < valuator_mask_size(mask); i++)
     {
         if (valuator_mask_isset(mask, i))
         {
-            dev->last.valuators[i] += valuator_mask_get(mask, i);
-            if (valuator_get_mode(dev, i) == Absolute)
-                clipAxis(dev, i, &dev->last.valuators[i]);
-            valuator_mask_set(mask, i, dev->last.valuators[i]);
+            int val = dev->last.valuators[i];
+            val += valuator_mask_get(mask, i);
+            /* x & y need to go over the limits to cross screens if the SD
+             * isn't currently attached; otherwise, clip to screen bounds. */
+            if (valuator_get_mode(dev, i) == Absolute &&
+                ((i != 0 && i != 1) || clip_xy))
+                clipAxis(dev, i, &val);
+            dev->last.valuators[i] = val;
+            valuator_mask_set(mask, i, val);
         }
     }
+
+    *x_out = dev->last.valuators[0];
+    *y_out = dev->last.valuators[1];
 }
 
 /**
commit 80fdf9ca33a8f50f98a4b1a3279e66b040353b80
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 13:19:00 2011 +0000

    Input: Prepare moveAbsolute for conversion to double
    
    Shuffle some code around to make moving to double easier later.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index d9c5c0d..bcac6aa 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -690,40 +690,30 @@ UpdateFromMaster(InternalEvent* events, DeviceIntPtr dev, int type, int *num_eve
 /**
  * Move the device's pointer to the position given in the valuators.
  *
- * @param dev The device which's pointer is to be moved.
+ * @param dev The device whose pointer is to be moved.
  * @param x Returns the x position of the pointer after the move.
  * @param y Returns the y position of the pointer after the move.
- * @param mask Bit mask of valid valuators.
- * @param valuators Valuator data for each axis between @first and
- *        @first+ at num.
+ * @param mask Valuator data for this event.
  */
 static void
-moveAbsolute(DeviceIntPtr dev, int *x, int *y, ValuatorMask *mask)
+moveAbsolute(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
 {
     int i;
+    int x, y;
 
-    if (valuator_mask_isset(mask, 0))
-        *x = valuator_mask_get(mask, 0);
-    else
-        *x = dev->last.valuators[0];
-
-    if (valuator_mask_isset(mask, 1))
-        *y = valuator_mask_get(mask, 1);
-    else
-        *y = dev->last.valuators[1];
-
-    clipAxis(dev, 0, x);
-    clipAxis(dev, 1, y);
-
-    for (i = 2; i < valuator_mask_size(mask); i++)
+    for (i = 0; i < valuator_mask_size(mask); i++)
     {
         if (valuator_mask_isset(mask, i))
         {
-            dev->last.valuators[i] = valuator_mask_get(mask, i);
-            clipAxis(dev, i, &dev->last.valuators[i]);
-            valuator_mask_set(mask, i, dev->last.valuators[i]);
+            int val = valuator_mask_get(mask, i);
+            clipAxis(dev, i, &val);
+            dev->last.valuators[i] = val;
+            valuator_mask_set(mask, i, val);
         }
     }
+
+    *x_out = dev->last.valuators[0];
+    *y_out = dev->last.valuators[1];
 }
 
 /**
commit 6a6b4eb05c7822860e2362fa9b8441fc67055e27
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 2 17:22:59 2011 +0000

    Input: Store clipped absolute axes in the mask
    
    Change moveAbsolute to be more symmetric with moveRelative by storing a
    clipped axis value back in the mask, rather than just in
    dev->last.valuators.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index be2840c..d9c5c0d 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -721,6 +721,7 @@ moveAbsolute(DeviceIntPtr dev, int *x, int *y, ValuatorMask *mask)
         {
             dev->last.valuators[i] = valuator_mask_get(mask, i);
             clipAxis(dev, i, &dev->last.valuators[i]);
+            valuator_mask_set(mask, i, dev->last.valuators[i]);
         }
     }
 }
commit 7e919ef5bfa94d51a06eefb150ab947bdbfb6885
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Feb 23 17:28:18 2011 +0000

    Input: Add double-precision valuator_mask API
    
    Add API for valuator_mask that accepts and returns doubles, rather than
    ints.  No double API is provided for set_range at the moment.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 1c4af8e..0a3d3d8 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -497,10 +497,10 @@ valuator_mask_isset(const ValuatorMask *mask, int valuator)
 }
 
 /**
- * Set the valuator to the given data.
+ * Set the valuator to the given floating-point data.
  */
 void
-valuator_mask_set(ValuatorMask *mask, int valuator, int data)
+valuator_mask_set_double(ValuatorMask *mask, int valuator, double data)
 {
     mask->last_bit = max(valuator, mask->last_bit);
     SetBit(mask->mask, valuator);
@@ -508,13 +508,33 @@ valuator_mask_set(ValuatorMask *mask, int valuator, int data)
 }
 
 /**
- * Return the requested valuator value. If the mask bit is not set for the
- * given valuator, the returned value is undefined.
+ * Set the valuator to the given integer data.
+ */
+void
+valuator_mask_set(ValuatorMask *mask, int valuator, int data)
+{
+    valuator_mask_set_double(mask, valuator, data);
+}
+
+/**
+ * Return the requested valuator value as a double. If the mask bit is not
+ * set for the given valuator, the returned value is undefined.
+ */
+double
+valuator_mask_get_double(const ValuatorMask *mask, int valuator)
+{
+    return mask->valuators[valuator];
+}
+
+/**
+ * Return the requested valuator value as an integer, rounding towards zero.
+ * If the mask bit is not set for the given valuator, the returned value is
+ * undefined.
  */
 int
 valuator_mask_get(const ValuatorMask *mask, int valuator)
 {
-    return trunc(mask->valuators[valuator]);
+    return trunc(valuator_mask_get_double(mask, valuator));
 }
 
 /**
diff --git a/include/input.h b/include/input.h
index 0258f4f..577f5d9 100644
--- a/include/input.h
+++ b/include/input.h
@@ -583,6 +583,9 @@ extern _X_EXPORT void valuator_mask_set_range(ValuatorMask *mask,
 extern _X_EXPORT void valuator_mask_set(ValuatorMask *mask,
                                         int valuator,
                                         int data);
+extern _X_EXPORT void valuator_mask_set_double(ValuatorMask *mask,
+                                               int valuator,
+                                               double data);
 extern _X_EXPORT void valuator_mask_zero(ValuatorMask *mask);
 extern _X_EXPORT int valuator_mask_size(const ValuatorMask *mask);
 extern _X_EXPORT int valuator_mask_isset(const ValuatorMask *mask, int bit);
@@ -591,6 +594,8 @@ extern _X_EXPORT int valuator_mask_num_valuators(const ValuatorMask *mask);
 extern _X_EXPORT void valuator_mask_copy(ValuatorMask *dest,
                                          const ValuatorMask *src);
 extern _X_EXPORT int valuator_mask_get(const ValuatorMask *mask, int valnum);
+extern _X_EXPORT double valuator_mask_get_double(const ValuatorMask *mask,
+                                                 int valnum);
 
 /* InputOption handling interface */
 extern _X_EXPORT InputOption* input_option_new(InputOption *list, const char *key, const char *value);
diff --git a/test/input.c b/test/input.c
index b8dad1c..2501d59 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1089,12 +1089,16 @@ static void dix_input_valuator_masks(void)
 {
     ValuatorMask *mask = NULL, *copy;
     int nvaluators = MAX_VALUATORS;
-    int valuators[nvaluators];
+    double valuators[nvaluators];
+    int val_ranged[nvaluators];
     int i;
     int first_val, num_vals;
 
     for (i = 0; i < nvaluators; i++)
-        valuators[i] = i;
+    {
+        valuators[i] = i + 0.5;
+        val_ranged[i] = i;
+    }
 
     mask = valuator_mask_new(nvaluators);
     assert(mask != NULL);
@@ -1104,9 +1108,10 @@ static void dix_input_valuator_masks(void)
     for (i = 0; i < nvaluators; i++)
     {
         assert(!valuator_mask_isset(mask, i));
-        valuator_mask_set(mask, i, valuators[i]);
+        valuator_mask_set_double(mask, i, valuators[i]);
         assert(valuator_mask_isset(mask, i));
-        assert(valuator_mask_get(mask, i) == valuators[i]);
+        assert(valuator_mask_get(mask, i) == trunc(valuators[i]));
+        assert(valuator_mask_get_double(mask, i) == valuators[i]);
         assert(valuator_mask_size(mask) == i + 1);
         assert(valuator_mask_num_valuators(mask) == i + 1);
     }
@@ -1132,7 +1137,7 @@ static void dix_input_valuator_masks(void)
     first_val = 5;
     num_vals = 6;
 
-    valuator_mask_set_range(mask, first_val, num_vals, valuators);
+    valuator_mask_set_range(mask, first_val, num_vals, val_ranged);
     assert(valuator_mask_size(mask) == first_val + num_vals);
     assert(valuator_mask_num_valuators(mask) == num_vals);
     for (i = 0; i < nvaluators; i++)
@@ -1142,7 +1147,9 @@ static void dix_input_valuator_masks(void)
         else
         {
             assert(valuator_mask_isset(mask, i));
-            assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
+            assert(valuator_mask_get(mask, i) == val_ranged[i - first_val]);
+            assert(valuator_mask_get_double(mask, i) ==
+                    val_ranged[i - first_val]);
         }
     }
 
@@ -1156,6 +1163,8 @@ static void dix_input_valuator_masks(void)
     {
         assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
         assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
+        assert(valuator_mask_get_double(mask, i) ==
+                valuator_mask_get_double(copy, i));
     }
 
     valuator_mask_free(&mask);
commit 79d4deb76d5612b75ef26b4549b7ade3a656687d
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Feb 23 14:31:01 2011 +0000

    Input: Convert ValuatorMask to double-precision internally
    
    Switch the ValuatorMask struct to using doubles instead of ints for the
    actual values.  Preserve the old int API, and (attempt to) round towards
    zero for values we return.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 7aeb1e5..1c4af8e 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -514,7 +514,7 @@ valuator_mask_set(ValuatorMask *mask, int valuator, int data)
 int
 valuator_mask_get(const ValuatorMask *mask, int valuator)
 {
-    return mask->valuators[valuator];
+    return trunc(mask->valuators[valuator]);
 }
 
 /**
@@ -527,7 +527,7 @@ valuator_mask_unset(ValuatorMask *mask, int valuator)
         int i, lastbit = -1;
 
         ClearBit(mask->mask, valuator);
-        mask->valuators[valuator] = 0;
+        mask->valuators[valuator] = 0.0;
 
         for (i = 0; i <= mask->last_bit; i++)
             if (valuator_mask_isset(mask, i))
diff --git a/include/inpututils.h b/include/inpututils.h
index 63e1a26..47e242d 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -34,7 +34,7 @@
 struct _ValuatorMask {
     int8_t      last_bit; /* highest bit set in mask */
     uint8_t     mask[(MAX_VALUATORS + 7)/8];
-    int         valuators[MAX_VALUATORS]; /* valuator data */
+    double      valuators[MAX_VALUATORS]; /* valuator data */
 };
 
 extern void verify_internal_event(const InternalEvent *ev);
commit 60a766a96f9ec97adf6d0273f70ec23f313a11c6
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Jun 9 16:02:47 2011 +0100

    Input: Add flags to RawDeviceEvent
    
    Add a flags member which will be copied wholesale into the resultant
    xXIRawEvent.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 6ddcf9e..fa8ba9e 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -667,6 +667,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
     raw->detail         = ev->detail.button;
     raw->deviceid       = ev->deviceid;
     raw->valuators_len  = vallen;
+    raw->flags          = ev->flags;
 
     ptr = (char*)&raw[1];
     axisval = (FP3232*)(ptr + raw->valuators_len * 4);
diff --git a/include/eventstr.h b/include/eventstr.h
index 0885883..ecaeddc 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -204,6 +204,7 @@ struct _RawDeviceEvent
         int32_t  data_raw[MAX_VALUATORS];     /**< Valuator data as posted */
         int32_t  data_raw_frac[MAX_VALUATORS];/**< Fractional part for data_raw */
     } valuators;
+    uint32_t flags;       /**< Flags to be copied into the generated event */
 };
 
 #ifdef XQUARTZ
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 6ec94be..80c47b0 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -51,6 +51,7 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
         swapl(&out->time);
         swapl(&out->detail);
         swaps(&out->valuators_len);
+        swapl(&out->flags);
     }
 
 
commit 5d62c32981dbe9630bed32567b55008b536c81c5
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Mon Dec 27 13:24:35 2010 +0000

    Input: Add flags to DeviceEvent
    
    Add a flags member which will be copied wholesale into the resultant
    xXIDeviceEvent.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 024f2e8..6ddcf9e 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -605,6 +605,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
     xde->root_x         = FP1616(ev->root_x, ev->root_x_frac);
     xde->root_y         = FP1616(ev->root_y, ev->root_y_frac);
 
+    xde->flags          = ev->flags;
     if (ev->key_repeat)
         xde->flags      |= XIKeyRepeat;
 
diff --git a/include/eventstr.h b/include/eventstr.h
index 049688c..0885883 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -113,6 +113,7 @@ struct _DeviceEvent
     Window      root; /**< Root window of the event */
     int corestate;    /**< Core key/button state BEFORE the event */
     int key_repeat;   /**< Internally-generated key repeat event */
+    uint32_t flags;   /**< Flags to be copied into the generated event */
 };
 
 
commit 84bb0207f6db433a8d387d933393357da87ca23e
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Fri Sep 23 20:03:03 2011 -0400

    dix and os: gitignore dix.O and os.O
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/.gitignore b/dix/.gitignore
index c1b4f20..65f2f8c 100644
--- a/dix/.gitignore
+++ b/dix/.gitignore
@@ -1,2 +1,3 @@
 #		Add & Override for this directory and it's subdirectories
 Xserver-dtrace.h
+dix.O
diff --git a/os/.gitignore b/os/.gitignore
new file mode 100644
index 0000000..bba633b
--- /dev/null
+++ b/os/.gitignore
@@ -0,0 +1 @@
+os.O
commit 3d41939d0349569dcfd2aef9b846c739d0ba0060
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Sep 22 17:41:38 2011 -0700

    Unconditionally #include <stdint.h>
    
    The more recent inclusions of this file haven't been checking for
    HAVE_STDINT_H, so might as well make the older ones consistent.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 8e3c9cd..745135e 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -40,12 +40,7 @@ from The Open Group.
 #include <X11/extensions/xcmiscproto.h>
 #include "modinit.h"
 
-#if HAVE_STDINT_H
 #include <stdint.h>
-#elif !defined(UINT32_MAX)
-#define UINT32_MAX 0xffffffffU
-#endif
-
 
 static int
 ProcXCMiscGetVersion(ClientPtr client)
diff --git a/dbe/dbe.c b/dbe/dbe.c
index 86d8220..a468676 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -38,12 +38,7 @@
 #endif
 
 #include <string.h>
-#if HAVE_STDINT_H
 #include <stdint.h>
-#elif !defined(UINT32_MAX)
-#define UINT32_MAX 0xffffffffU
-#endif
-
 #include <X11/X.h>
 #include <X11/Xproto.h>
 #include "scrnintstr.h"
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 5facb11..aa7de60 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -178,9 +178,6 @@
 /* Define to 1 if you have the `shmctl64' function. */
 #undef HAVE_SHMCTL64
 
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
 /* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
 
diff --git a/render/render.c b/render/render.c
index cc13dbc..ff75409 100644
--- a/render/render.c
+++ b/render/render.c
@@ -52,11 +52,7 @@
 #include "panoramiXsrv.h"
 #endif
 
-#if HAVE_STDINT_H
 #include <stdint.h>
-#elif !defined(UINT32_MAX)
-#define UINT32_MAX 0xffffffffU
-#endif
 
 static int ProcRenderQueryVersion (ClientPtr pClient);
 static int ProcRenderQueryPictFormats (ClientPtr pClient);
commit 46d5ae5b551cc926331324073f2686b47e8aea07
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Fri Sep 23 09:38:25 2011 -0400

    dtrace: fix typo in title
    
    The word provider should be capitalized.
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/doc/dtrace/Xserver-DTrace.xml b/doc/dtrace/Xserver-DTrace.xml
index 2427202..fa8bc80 100644
--- a/doc/dtrace/Xserver-DTrace.xml
+++ b/doc/dtrace/Xserver-DTrace.xml
@@ -6,7 +6,7 @@
 
 <article id="Xserver-DTrace">
   <articleinfo>
-    <title>Xserver provider for DTrace</title>
+    <title>Xserver Provider for DTrace</title>
     <author>
       <firstname>Alan</firstname><surname>Coopersmith</surname>
       <affiliation>
commit 6cae6224994e3252b3b7c7608f983ce73e0206fc
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Fri Sep 23 09:38:24 2011 -0400

    dtrace: use docbook copyright markup for copyright holder
    
    No content change to copyright text.
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/doc/dtrace/Xserver-DTrace.xml b/doc/dtrace/Xserver-DTrace.xml
index cd8a812..2427202 100644
--- a/doc/dtrace/Xserver-DTrace.xml
+++ b/doc/dtrace/Xserver-DTrace.xml
@@ -15,11 +15,11 @@
       </affiliation>
     </author>
     <releaseinfo>X.Org Xserver version &xserver.version;</releaseinfo>
+    <copyright><year>2005</year><year>2006</year><year>2007</year><year>2010</year>
+      <holder>Oracle and/or its affiliates. All rights reserved.</holder>
+    </copyright>
     <legalnotice id="copyright">
       <para>
-Copyright (c) 2005, 2006, 2007, 2010, Oracle and/or its affiliates.
-All rights reserved.
-      </para><para>
 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
commit 58d3d46d6cc0d7a81db6bad61d158f3b9af8af71
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Sep 1 16:48:37 2011 -0700

    Assign ids to more tags in Xserver-Dtrace.xml
    
    Keeps xsltproc from adding random-number id tags to html output so that
    it's easier to see real changes vs. different random numbers.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Matt Dew <marcoz at osource.org>

diff --git a/doc/dtrace/Xserver-DTrace.xml b/doc/dtrace/Xserver-DTrace.xml
index 69cd30e..cd8a812 100644
--- a/doc/dtrace/Xserver-DTrace.xml
+++ b/doc/dtrace/Xserver-DTrace.xml
@@ -15,7 +15,7 @@
       </affiliation>
     </author>
     <releaseinfo>X.Org Xserver version &xserver.version;</releaseinfo>
-    <legalnotice>
+    <legalnotice id="copyright">
       <para>
 Copyright (c) 2005, 2006, 2007, 2010, Oracle and/or its affiliates.
 All rights reserved.
@@ -79,7 +79,7 @@ DEALINGS IN THE SOFTWARE.
       <parameter>arg2</parameter>, etc.  These tables should help you
       determine what the real data is for each of the probe arguments.
 
-    <table>
+    <table id="Probes_and_their_arguments">
       <title>Probes and their arguments</title>
       <tgroup cols='7'>
 	<colspec colname="probe" colwidth="2*"/>
@@ -195,7 +195,7 @@ DEALINGS IN THE SOFTWARE.
       To access data buffers referenced via <type>uintptr_t</type>'s, you will
       need to use <ulink url="http://wikis.sun.com/display/DTrace/Actions+and+Subroutines#ActionsandSubroutines-{{copyin}}"><function>copyin()</function></ulink>.
 
-    <table>
+    <table id="Probe_Arguments">
       <title>Probe Arguments</title>
       <tgroup cols='3'>
 	<colspec colname="arg" colwidth="2*"/>
@@ -313,7 +313,7 @@ DEALINGS IN THE SOFTWARE.
   <sect1 id="examples">
     <title>Examples</title>
 
-    <example>
+    <example id="Counting_requests_by_request_name">
       <title>Counting requests by request name</title>
 
       <para>
@@ -370,7 +370,7 @@ Xserver*:::request-start
       </para>
     </example>
 
-    <example>
+    <example id="Get_average_CPU_time_per_request">
       <title>Get average CPU time per request</title>
 
       <para>This script records the CPU time used between the probes at
@@ -419,7 +419,7 @@ Xserver*:::request-done
       </para>
     </example>
 
-    <example>
+    <example id="Monitoring_clients_that_connect_and_disconnect">
       <title>Monitoring clients that connect and disconnect</title>
 
       <para>
@@ -476,7 +476,7 @@ CPU     ID                    FUNCTION:NAME
       </para>
     </example>
 
-    <example>
+    <example id="Monitoring_clients_creating_Pixmaps">
       <title>Monitoring clients creating Pixmaps</title>
 
       <para>


More information about the Xquartz-changes mailing list