xserver: Branch 'master' - 132 commits

Keith Packard keithp at kemper.freedesktop.org
Wed Sep 17 15:56:54 PDT 2014


 COPYING                                          |   24 
 configure.ac                                     |   10 
 hw/xfree86/Makefile.am                           |    2 
 hw/xfree86/drivers/Makefile.am                   |    5 
 hw/xfree86/drivers/modesetting/Makefile.am       |   61 
 hw/xfree86/drivers/modesetting/driver.c          | 1113 +++++++++++++++
 hw/xfree86/drivers/modesetting/driver.h          |   81 +
 hw/xfree86/drivers/modesetting/drmmode_display.c | 1616 +++++++++++++++++++++++
 hw/xfree86/drivers/modesetting/drmmode_display.h |  136 +
 hw/xfree86/drivers/modesetting/modesetting.man   |   54 
 10 files changed, 3101 insertions(+), 1 deletion(-)

New commits:
commit eaee6572beefca240c42791f9a3a6e547bedd410
Merge: e3aa13b b84d25f
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Sep 17 15:49:24 2014 -0700

    Merge remote-tracking branch 'anholt/modesetting-import'

commit b84d25fd53e97105b99495af84abaacc4c901967
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:22:02 2014 -0700

    modesetting: Drop remaining old-xserver compatibility.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 35e73a3..adfb69c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -295,10 +295,8 @@ ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
 	    flag = (CARD32 *)data;
 	    (*flag) = 0;
 	    return TRUE;
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,15,99,902,0)
         case SUPPORTS_SERVER_FDS:
             return TRUE;
-#endif
 	default:
 	    return FALSE;
     }
@@ -494,7 +492,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
     ret = dispatch_dirty_region(scrn, pixmap, ms->damage, fb_id);
     if (ret == -EINVAL || ret == -ENOSYS) {
 	ms->dirty_enabled = FALSE;
-	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageUnregister(ms->damage);
 	DamageDestroy(ms->damage);
 	ms->damage = NULL;
 	xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
@@ -1082,7 +1080,7 @@ CloseScreen(ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
 
     if (ms->damage) {
-	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageUnregister(ms->damage);
 	DamageDestroy(ms->damage);
 	ms->damage = NULL;
     }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 88de97c..9723ccd 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -333,9 +333,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		crtc->x = x;
 		crtc->y = y;
 		crtc->rotation = rotation;
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,5,99,0,0)
 		crtc->transformPresent = FALSE;
-#endif
 	}
 
 	output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
@@ -360,10 +358,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		if (!xf86CrtcRotate(crtc)) {
 			goto done;
 		}
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,0,0,0)
 		crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
 				       crtc->gamma_blue, crtc->gamma_size);
-#endif
 		
 		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
@@ -521,8 +517,7 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 			drmModeRmFB(drmmode->fd, ppriv->fb_id);
 		}
 		if (drmmode_crtc->slave_damage) {
-			DamageUnregister(&crtc->randr_crtc->scanout_pixmap->drawable,
-					 drmmode_crtc->slave_damage);
+			DamageUnregister(drmmode_crtc->slave_damage);
 			drmmode_crtc->slave_damage = NULL;
 		}
 		return TRUE;
@@ -947,10 +942,8 @@ drmmode_output_get_property(xf86OutputPtr output, Atom property)
 static const xf86OutputFuncsRec drmmode_output_funcs = {
     .dpms = drmmode_output_dpms,
     .create_resources = drmmode_output_create_resources,
-#ifdef RANDR_12_INTERFACE
     .set_property = drmmode_output_set_property,
     .get_property = drmmode_output_get_property,
-#endif
     .detect = drmmode_output_detect,
     .mode_valid = drmmode_output_mode_valid,
 
@@ -1195,10 +1188,6 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 					   pitch, drmmode->shadow_fb);
 	}
 
-#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0)
-	scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr;
-#endif
-
 	for (i = 0; i < xf86_config->num_crtc; i++) {
 		xf86CrtcPtr crtc = xf86_config->crtc[i];
 
@@ -1395,11 +1384,9 @@ static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
           }
 
     /* Make the change through RandR */
-#ifdef RANDR_12_INTERFACE
         if (crtc->randr_crtc)
             RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
         else
-#endif
             crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
      }
 }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 1954abf..7bfe885 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -32,10 +32,6 @@
 #include "libudev.h"
 #endif
 
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
-#define DamageUnregister(d, dd) DamageUnregister(dd)
-#endif
-
 struct dumb_bo {
     uint32_t handle;
     uint32_t size;
@@ -62,9 +58,7 @@ typedef struct {
     Bool shadow_enable;
     void *shadow_fb;
 
-#ifdef HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
     DevPrivateKeyRec pixmapPrivateKeyRec;
-#endif
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
commit 7b0965a826612988dd721ddbd67cfbec392b67b5
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:37:46 2014 -0700

    modesetting: Drop use of compat-api.h
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index f6c6041..ca3279e 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -41,7 +41,6 @@ modesetting_drv_la_LIBADD = $(UDEV_LIBS) $(DRM_LIBS)
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
-	 compat-api.h \
 	 driver.c \
 	 driver.h \
 	 drmmode_display.c \
diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
deleted file mode 100644
index bd7decc..0000000
--- a/hw/xfree86/drivers/modesetting/compat-api.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Author: Dave Airlie <airlied at redhat.com>
- */
-
-/* this file provides API compat between server post 1.13 and pre it,
-   it should be reused inside as many drivers as possible */
-#ifndef COMPAT_API_H
-#define COMPAT_API_H
-
-#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
-#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
-#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
-#endif
-
-#ifndef XF86_HAS_SCRN_CONV
-#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
-#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
-#endif
-
-#ifndef XF86_SCRN_INTERFACE
-
-#define SCRN_ARG_TYPE int
-#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = xf86Screens[(arg1)]
-
-#define SCREEN_ARG_TYPE int
-#define SCREEN_PTR(arg1) ScreenPtr pScreen = screenInfo.screens[(arg1)]
-
-#define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv
-
-#define BLOCKHANDLER_ARGS_DECL int arg, void * blockData, void * pTimeout, void * pReadmask
-#define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask
-
-#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen
-#define CLOSE_SCREEN_ARGS scrnIndex, pScreen
-
-#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
-
-#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
-
-#define FREE_SCREEN_ARGS_DECL int arg, int flags
-
-#define VT_FUNC_ARGS_DECL int arg, int flags
-#define VT_FUNC_ARGS pScrn->scrnIndex, 0
-
-#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
-#else
-#define SCRN_ARG_TYPE ScrnInfoPtr
-#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = (arg1)
-
-#define SCREEN_ARG_TYPE ScreenPtr
-#define SCREEN_PTR(arg1) ScreenPtr pScreen = (arg1)
-
-#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
-
-#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, void * pTimeout, void * pReadmask
-#define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask
-
-#define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen
-#define CLOSE_SCREEN_ARGS pScreen
-
-#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
-#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
-
-#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
-
-#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
-#define VT_FUNC_ARGS pScrn
-
-#define XF86_ENABLEDISABLEFB_ARG(x) (x)
-
-#endif
-
-#endif
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b30c32c..35e73a3 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -59,20 +59,19 @@
 #include <pciaccess.h>
 #endif
 
-#include "compat-api.h"
 #include "driver.h"
 
-static void AdjustFrame(ADJUST_FRAME_ARGS_DECL);
-static Bool CloseScreen(CLOSE_SCREEN_ARGS_DECL);
-static Bool EnterVT(VT_FUNC_ARGS_DECL);
+static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y);
+static Bool CloseScreen(ScreenPtr pScreen);
+static Bool EnterVT(ScrnInfoPtr pScrn);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
-static ModeStatus ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose,
+static ModeStatus ValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool verbose,
 			    int flags);
-static void FreeScreen(FREE_SCREEN_ARGS_DECL);
-static void LeaveVT(VT_FUNC_ARGS_DECL);
-static Bool SwitchMode(SWITCH_MODE_ARGS_DECL);
-static Bool ScreenInit(SCREEN_INIT_ARGS_DECL);
+static void FreeScreen(ScrnInfoPtr pScrn);
+static void LeaveVT(ScrnInfoPtr pScrn);
+static Bool SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode);
+static Bool ScreenInit(ScreenPtr pScreen, int argc, char **argv);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
 
 static Bool Probe(DriverPtr drv, int flags);
@@ -537,13 +536,12 @@ static void dispatch_slave_dirty(ScreenPtr pScreen)
     }
 }
 
-static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
+static void msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
 {
-    SCREEN_PTR(arg);
     modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
     pScreen->BlockHandler = ms->BlockHandler;
-    pScreen->BlockHandler(BLOCKHANDLER_ARGS);
+    pScreen->BlockHandler(pScreen, pTimeout, pReadmask);
     pScreen->BlockHandler = msBlockHandler;
     if (pScreen->isGPU)
         dispatch_slave_dirty(pScreen);
@@ -910,7 +908,7 @@ SetMaster(ScrnInfoPtr pScrn)
 }
 
 static Bool
-ScreenInit(SCREEN_INIT_ARGS_DECL)
+ScreenInit(ScreenPtr pScreen, int argc, char **argv)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -1019,29 +1017,26 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-    return EnterVT(VT_FUNC_ARGS);
+    return EnterVT(pScrn);
 }
 
 static void
-AdjustFrame(ADJUST_FRAME_ARGS_DECL)
+AdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
-    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     drmmode_adjust_frame(pScrn, &ms->drmmode, x, y);
 }
 
 static void
-FreeScreen(FREE_SCREEN_ARGS_DECL)
+FreeScreen(ScrnInfoPtr pScrn)
 {
-    SCRN_INFO_PTR(arg);
     FreeRec(pScrn);
 }
 
 static void
-LeaveVT(VT_FUNC_ARGS_DECL)
+LeaveVT(ScrnInfoPtr pScrn)
 {
-    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
     xf86_hide_cursors(pScrn);
 
@@ -1060,9 +1055,8 @@ LeaveVT(VT_FUNC_ARGS_DECL)
  * This gets called when gaining control of the VT, and from ScreenInit().
  */
 static Bool
-EnterVT(VT_FUNC_ARGS_DECL)
+EnterVT(ScrnInfoPtr pScrn)
 {
-    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     pScrn->vtSema = TRUE;
@@ -1076,15 +1070,13 @@ EnterVT(VT_FUNC_ARGS_DECL)
 }
 
 static Bool
-SwitchMode(SWITCH_MODE_ARGS_DECL)
+SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
-    SCRN_INFO_PTR(arg);
-
     return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
 }
 
 static Bool
-CloseScreen(CLOSE_SCREEN_ARGS_DECL)
+CloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -1105,7 +1097,7 @@ CloseScreen(CLOSE_SCREEN_ARGS_DECL)
     drmmode_free_bos(pScrn, &ms->drmmode);
 
     if (pScrn->vtSema) {
-        LeaveVT(VT_FUNC_ARGS);
+        LeaveVT(pScrn);
     }
 
     pScreen->CreateScreenResources = ms->createScreenResources;
@@ -1113,11 +1105,11 @@ CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
-    return (*pScreen->CloseScreen) (CLOSE_SCREEN_ARGS);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static ModeStatus
-ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
+ValidMode(ScrnInfoPtr arg, DisplayModePtr mode, Bool verbose, int flags)
 {
     return MODE_OK;
 }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index d55157b..88de97c 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -46,7 +46,6 @@
 #include <cursorstr.h>
 
 #include <X11/extensions/dpmsconst.h>
-#include "compat-api.h"
 
 #include "driver.h"
 
commit 2feda3b6b58f46cef91ea41312aac9021a703777
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:06:23 2014 -0700

    modesetting: Connect the driver to the build.
    
    v2: Fix libdrm version check, and use XORG_VERSION_* instead of a
        static 1.0.0 version for the driver module.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index cba7d24..ae3327d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -863,6 +863,7 @@ fi
 PKG_CHECK_MODULES(UDEV, $LIBUDEV, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
 if test "x$CONFIG_UDEV" = xauto; then
 	CONFIG_UDEV="$HAVE_LIBUDEV"
+	AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if libudev is available.])
 fi
 AM_CONDITIONAL(CONFIG_UDEV, [test "x$CONFIG_UDEV" = xyes])
 if test "x$CONFIG_UDEV" = xyes; then
@@ -2039,6 +2040,12 @@ if test "x$XORG" = xyes; then
 	        XORG_SYS_LIBS="$XORG_SYS_LIBS $XORG_MODULES_LIBS"
 	fi
 
+	if test "x$DRM" = xyes; then
+		dnl 2.4.46 is required for cursor hotspot support.
+		PKG_CHECK_EXISTS(libdrm >= 2.4.46)
+		XORG_DRIVER_MODESETTING=yes
+	fi
+
 	AC_SUBST([XORG_LIBS])
 	AC_SUBST([XORG_SYS_LIBS])
 	AC_SUBST([XORG_INCS])
@@ -2109,6 +2116,7 @@ AM_CONDITIONAL([SOLARIS_VT], [test "x$solaris_vt" = xyes])
 AM_CONDITIONAL([DGA], [test "x$DGA" = xyes])
 AM_CONDITIONAL([XF86VIDMODE], [test "x$XF86VIDMODE" = xyes])
 AM_CONDITIONAL([XORG_BUS_PLATFORM], [test "x$CONFIG_UDEV_KMS" = xyes])
+AM_CONDITIONAL([XORG_DRIVER_MODESETTING], [test "x$XORG_DRIVER_MODESETTING" = xyes])
 
 dnl glamor
 AM_CONDITIONAL([GLAMOR], [test "x$GLAMOR" = xyes])
@@ -2554,6 +2562,8 @@ hw/xfree86/dixmods/Makefile
 hw/xfree86/doc/Makefile
 hw/xfree86/dri/Makefile
 hw/xfree86/dri2/Makefile
+hw/xfree86/drivers/Makefile
+hw/xfree86/drivers/modesetting/Makefile
 hw/xfree86/exa/Makefile
 hw/xfree86/exa/man/Makefile
 hw/xfree86/fbdevhw/Makefile
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index c5992c3..30f7c8f 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -38,7 +38,7 @@ SUBDIRS = common ddc x86emu $(INT10_SUBDIR) os-support parser \
 	  ramdac $(VGAHW_SUBDIR) loader modes $(DRI_SUBDIR) \
 	  $(DRI2_SUBDIR) . $(VBE_SUBDIR) i2c dixmods \
 	  fbdevhw shadowfb exa $(XF86UTILS_SUBDIR) doc man \
-	  $(GLAMOR_EGL_SUBDIR)
+	  $(GLAMOR_EGL_SUBDIR) drivers
 
 DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
                parser ramdac shadowfb vbe vgahw \
diff --git a/hw/xfree86/drivers/Makefile.am b/hw/xfree86/drivers/Makefile.am
new file mode 100644
index 0000000..04d787f
--- /dev/null
+++ b/hw/xfree86/drivers/Makefile.am
@@ -0,0 +1,5 @@
+SUBDIRS =
+
+if XORG_DRIVER_MODESETTING
+SUBDIRS += modesetting
+endif
diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 3cc4624..f6c6041 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -24,11 +24,20 @@
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
-AM_CFLAGS = $(XORG_CFLAGS) $(DRM_CFLAGS) $(UDEV_CFLAGS) $(CWARNFLAGS)
+AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) $(LIBDRM_CFLAGS) $(UDEV_CFLAGS) $(CWARNFLAGS)
+
+AM_CPPFLAGS = \
+	$(XORG_INCS) \
+	-I$(srcdir)/../../ddc \
+	-I$(srcdir)/../../i2c \
+	-I$(srcdir)/../../modes \
+	-I$(srcdir)/../../parser \
+	-I$(srcdir)/../../ramdac \
+	$(NULL)
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
 modesetting_drv_la_LDFLAGS = -module -avoid-version
-modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@
+modesetting_drv_la_LIBADD = $(UDEV_LIBS) $(DRM_LIBS)
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
@@ -37,3 +46,17 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 drmmode_display.c \
 	 drmmode_display.h
+
+drivermandir = $(DRIVER_MAN_DIR)
+driverman_PRE = modesetting.man
+driverman_DATA = $(driverman_PRE:man=@DRIVER_MAN_SUFFIX@)
+
+EXTRA_DIST = modesetting.man
+
+CLEANFILES = $(driverman_DATA)
+
+# String replacements in MAN_SUBSTS now come from xorg-macros.m4 via configure
+SUFFIXES = .$(DRIVER_MAN_SUFFIX) .man
+
+.man.$(DRIVER_MAN_SUFFIX):
+	$(AM_V_GEN)$(SED) $(MAN_SUBSTS) < $< > $@
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index eaa3a0f..b30c32c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -29,8 +29,8 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#ifdef HAVE_DIX_CONFIG_H
+#include "dix-config.h"
 #endif
 
 #include <unistd.h>
@@ -51,7 +51,7 @@
 #include "shadow.h"
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
-#include <xorg-server.h>
+#include <xorg-config.h>
 #ifdef XSERVER_PLATFORM_BUS
 #include "xf86platformBus.h"
 #endif
@@ -144,7 +144,9 @@ static XF86ModuleVersionInfo VersRec = {
     MODINFOSTRING1,
     MODINFOSTRING2,
     XORG_VERSION_CURRENT,
-    PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
+    XORG_VERSION_MAJOR,
+    XORG_VERSION_MINOR,
+    XORG_VERSION_PATCH,
     ABI_CLASS_VIDEODRV,
     ABI_VIDEODRV_VERSION,
     MOD_CLASS_VIDEODRV,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 31c39a2..d55157b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -25,8 +25,8 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#ifdef HAVE_DIX_CONFIG_H
+#include "dix-config.h"
 #endif
 
 #include <errno.h>
commit 6d6aa8ab6b6d62d65f1354b4cd9af0bf4f2e81d7
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:43:54 2014 -0700

    modesetting: Update for the platform device API change.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 5158c46..eaa3a0f 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -219,7 +219,7 @@ static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
 
 #if XF86_PDEV_SERVER_FD
     if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
-        fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1);
+        fd = xf86_platform_device_odev_attributes(platform_dev)->fd;
         if (fd == -1)
             return FALSE;
         return check_outputs(fd);
@@ -350,7 +350,7 @@ ms_platform_probe(DriverPtr driver,
               int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
-    const char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
+    const char *path = xf86_platform_device_odev_attributes(dev)->path;
     int scr_flags = 0;
 
     if (flags & PLATFORM_PROBE_GPU_SCREEN)
@@ -646,11 +646,11 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (pEnt->location.type == BUS_PLATFORM) {
 #ifdef XF86_PDEV_SERVER_FD
         if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
-            ms->fd = xf86_get_platform_device_int_attrib(pEnt->location.id.plat, ODEV_ATTRIB_FD, -1);
+            ms->fd = xf86_platform_device_odev_attributes(pEnt->location.id.plat)->fd;
         else
 #endif
         {
-            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+            char *path = xf86_platform_device_odev_attributes(pEnt->location.id.plat)->path;
             ms->fd = open_hw(path);
         }
     }
commit 9c080f44960d2338c7a59eee132a02d45186bfb0
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:41:46 2014 -0700

    modesetting: Drop use of "pointer" for "void *"
    
    The xserver doesn't have that typedef.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
index df783a8..bd7decc 100644
--- a/hw/xfree86/drivers/modesetting/compat-api.h
+++ b/hw/xfree86/drivers/modesetting/compat-api.h
@@ -48,7 +48,7 @@
 
 #define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv
 
-#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS_DECL int arg, void * blockData, void * pTimeout, void * pReadmask
 #define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask
 
 #define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen
@@ -73,7 +73,7 @@
 
 #define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
 
-#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, void * pTimeout, void * pReadmask
 #define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask
 
 #define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 44abdb3..5158c46 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -153,8 +153,8 @@ static XF86ModuleVersionInfo VersRec = {
 
 _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
 
-static pointer
-Setup(pointer module, pointer opts, int *errmaj, int *errmin)
+static void *
+Setup(void * module, void * opts, int *errmaj, int *errmin)
 {
     static Bool setupDone = 0;
 
@@ -168,7 +168,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * The return value must be non-NULL on success even though there
 	 * is no TearDownProc.
 	 */
-	return (pointer) 1;
+	return (void *) 1;
     } else {
 	if (errmaj)
 	    *errmaj = LDR_ONCEONLY;
commit a10ea01475c6d0795b1a00cfd8be9912f4b54235
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:24:31 2014 -0700

    modesetting: xserver already checks XEXTPROTO >= 7.2.99.901.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 6964e93..31c39a2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -45,13 +45,7 @@
 
 #include <cursorstr.h>
 
-/* DPMS */
-#ifdef HAVE_XEXTPROTO_71
 #include <X11/extensions/dpmsconst.h>
-#else
-#define DPMS_SERVER
-#include <X11/extensions/dpms.h>
-#endif
 #include "compat-api.h"
 
 #include "driver.h"
commit c7e8d4a6ee9542f56cd241cf7a960fb8223a6b22
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:21:24 2014 -0700

    modesetting: unifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
    
    The server will always have it.
    
    v2: Clean up some weird formatting from the unifdeffing.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index d99b027..44abdb3 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -501,7 +501,6 @@ static void dispatch_dirty(ScreenPtr pScreen)
     }
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static void dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(scrn);
@@ -535,7 +534,6 @@ static void dispatch_slave_dirty(ScreenPtr pScreen)
 	dispatch_dirty_crtc(scrn, crtc);
     }
 }
-#endif
 
 static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 {
@@ -545,12 +543,9 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
     pScreen->BlockHandler = ms->BlockHandler;
     pScreen->BlockHandler(BLOCKHANDLER_ARGS);
     pScreen->BlockHandler = msBlockHandler;
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     if (pScreen->isGPU)
         dispatch_slave_dirty(pScreen);
-    else
-#endif
-    if (ms->dirty_enabled)
+    else if (ms->dirty_enabled)
         dispatch_dirty(pScreen);
 }
 
@@ -686,7 +681,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     ms->drmmode.fd = ms->fd;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     pScrn->capabilities = 0;
 #ifdef DRM_CAP_PRIME
     ret = drmGetCap(ms->fd, DRM_CAP_PRIME, &value);
@@ -695,7 +689,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
             pScrn->capabilities |= RR_Capability_SinkOutput;
     }
 #endif
-#endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
     if (defaultdepth == 24 && defaultbpp == 24)
 	    bppflags = SupportConvert32to24 | Support24bppFb;
@@ -877,7 +870,6 @@ msShadowInit(ScreenPtr pScreen)
     return TRUE;
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static Bool
 msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 {
@@ -894,7 +886,6 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 
     return TRUE;
 }
-#endif
 
 static Bool
 SetMaster(ScrnInfoPtr pScrn)
@@ -950,12 +941,10 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     if (!miSetPixmapDepths())
 	return FALSE;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     if (!dixRegisterScreenSpecificPrivateKey(pScreen, &ms->drmmode.pixmapPrivateKeyRec,
         PRIVATE_PIXMAP, sizeof(msPixmapPrivRec))) { 
 	return FALSE;
     }
-#endif
 
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
@@ -1015,9 +1004,7 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     ms->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = msBlockHandler;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking;
-#endif
 
     if (!xf86CrtcScreenInit(pScreen))
 	return FALSE;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index c533324..6964e93 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -142,7 +142,6 @@ static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
 	return 0;
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, int size)
 {
   	struct dumb_bo *bo;
@@ -161,9 +160,7 @@ static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, in
 	bo->size = size;
 	return bo;
 }
-#endif
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 			drmmode_ptr drmmode, 
 			int fd_handle, int pitch, int size)
@@ -177,7 +174,6 @@ Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 	close(fd_handle);
 	return TRUE;
 }
-#endif
 
 static void
 drmmode_ConvertFromKMode(ScrnInfoPtr	scrn,
@@ -379,14 +375,11 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
 		fb_id = drmmode->fb_id;
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 		if (crtc->randr_crtc->scanout_pixmap) {
     			msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
 			fb_id = ppriv->fb_id;
 			x = y = 0;
-		} else 
-#endif
-		if (drmmode_crtc->rotate_fb_id) {
+		} else if (drmmode_crtc->rotate_fb_id) {
 			fb_id = drmmode_crtc->rotate_fb_id;
 			x = y = 0;
 		}
@@ -521,7 +514,6 @@ drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
 			    size, red, green, blue);
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static Bool
 drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 {
@@ -566,7 +558,6 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 	}
 	return TRUE;
 }
-#endif
 
 static void *drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
 {
@@ -590,9 +581,7 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
 
     .gamma_set = drmmode_crtc_gamma_set,
     .destroy = NULL, /* XXX */
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     .set_scanout_pixmap = drmmode_set_scanout_pixmap,
-#endif
     .shadow_allocate = drmmode_shadow_allocate,
     .shadow_create = drmmode_shadow_create,
 };
@@ -1032,10 +1021,8 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	/* need to do smart conversion here for compat with non-kms ATI driver */
 	if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
 		snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 	else if (pScrn->is_gpu)
 		snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id - 1);
-#endif
 	else
 		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
 
@@ -1549,7 +1536,6 @@ void *drmmode_map_front_bo(drmmode_ptr drmmode)
 	
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
 {
         int ret;
@@ -1563,7 +1549,6 @@ void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
 
         return ppriv->backing_bo->ptr;  
 }
-#endif
 
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 745c484..1954abf 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -32,11 +32,6 @@
 #include "libudev.h"
 #endif
 
-/* the perfect storm */
-#if XF86_CRTC_VERSION >= 5 && defined(HAVE_DRMPRIMEFDTOHANDLE) && HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
-#define MODESETTING_OUTPUT_SLAVE_SUPPORT 1
-#endif
-
 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
 #define DamageUnregister(d, dd) DamageUnregister(dd)
 #endif
@@ -103,7 +98,6 @@ typedef struct {
     int enc_clone_mask;
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 typedef struct _msPixmapPriv {
     uint32_t fb_id;
     struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */
@@ -119,7 +113,6 @@ void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
 Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 			drmmode_ptr drmmode,
 			int fd_handle, int pitch, int size);
-#endif
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
commit 0c07bfb38e61a8a6ad511dc8827e2dd20d68665d
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Aug 25 15:42:45 2014 -0700

    modesetting: Merge modesetting's COPYING into the xserver's.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/COPYING b/COPYING
index cc52a32..abf13c2 100644
--- a/COPYING
+++ b/COPYING
@@ -8,6 +8,7 @@ possible, and insert their name to this list.  Please sort by surname
 for people, and by the full name for other entities (e.g.  Juliusz
 Chroboczek sorts before Intel Corporation sorts before Daniel Stone).
 
+Copyright © 2011 Dave Airlie
 Copyright © 2000-2001 Juliusz Chroboczek
 Copyright © 1998 Egbert Eich
 Copyright © 2006-2007 Intel Corporation
@@ -145,6 +146,29 @@ used in advertising or otherwise to promote the sale, use or other dealings
 in this Software without prior written authorization from the X Consortium.
 
 
+Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+
+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, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
 Copyright © 1999-2000 SuSE, Inc.
 Copyright © 2007 Red Hat, Inc.
 
diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING
deleted file mode 100644
index 9508e25..0000000
--- a/hw/xfree86/drivers/modesetting/COPYING
+++ /dev/null
@@ -1,44 +0,0 @@
-Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-Copyright 2011 Dave Airlie
-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, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Copyright © 2007 Red Hat, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
commit 35dc7c75150733dbcef8a18b6796f49a7c48ebee
Merge: 3a51418 5f3485b
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Aug 25 15:52:58 2014 -0700

    Merge branch 'modesetting-import' into master
    
    This reintroduces a "hardware" driver to the xfree86 directory.
    Unlike the drivers that xorg used to include in the source tree, that
    needed independent release schedules to get hardware support out the
    door, the modesetting driver shouldn't change much as new hardware
    gets released.  A lot of what this driver needs to do is just keep up
    with server ABI changes.
    
    This import was done by taking xf86-video-modesetting-0.9.0, and
    running this script with 'git-filter-branch -f --tree-filter
    ~/bin/modesetting-filter':
    
    mkdir -p hw/xfree86/drivers/modesetting
    
    rm -f README autogen.sh configure.ac Makefile.am .gitignore
    rm -f man/Makefile.am
    
    mv man/modesetting.man hw/xfree86/drivers/modesetting/
    mv COPYING hw/xfree86/drivers/modesetting/
    mv src/* hw/xfree86/drivers/modesetting/

commit 5f3485b06e180674af640e7e9d7d56f67b61735b
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Thu Jun 26 10:37:19 2014 +0200

    bump to 0.9.0
commit 042bae0b49f6192ec3cb8bb51423c90c44638134
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed May 21 10:16:39 2014 -0400

    Use own thunk function instead of shadowUpdatePackedWeak
    
    I plan to remove the Weak functions from a future server.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 21274a9..d99b027 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -810,6 +810,12 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
     return ((uint8_t *)ms->drmmode.front_bo->ptr + row * stride + offset);
 }
 
+static void
+msUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf)
+{
+    shadowUpdatePacked(pScreen, pBuf);
+}
+
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
@@ -842,7 +848,7 @@ CreateScreenResources(ScreenPtr pScreen)
 	FatalError("Couldn't adjust screen pixmap\n");
 
     if (ms->drmmode.shadow_enable) {
-	if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(),
+	if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked,
 		       msShadowWindow, 0, 0))
 	    return FALSE;
     }
commit 219ce9e6c34bfc946005fb8e81ab4fb74ae1d25a
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri May 2 13:16:05 2014 +1000

    modesetting: fix build regression against older servers.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b5fcdaf..21274a9 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -217,7 +217,7 @@ static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
 {
     int fd;
 
-#if XSERVER_PLATFORM_BUS
+#if XF86_PDEV_SERVER_FD
     if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
         fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1);
         if (fd == -1)
commit 795af9ff017113788b4bb6d9dbeb5370c5b8165c
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri May 2 13:14:30 2014 +1000

    modesetting: fix use after free.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 28a4abb..c533324 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -778,11 +778,11 @@ drmmode_output_destroy(xf86OutputPtr output)
 		drmModeFreeProperty(drmmode_output->props[i].mode_prop);
 		free(drmmode_output->props[i].atoms);
 	}
+	free(drmmode_output->props);
 	for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) {
 		drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
-		free(drmmode_output->mode_encoders);
 	}
-	free(drmmode_output->props);
+	free(drmmode_output->mode_encoders);
 	drmModeFreeConnector(drmmode_output->mode_output);
 	free(drmmode_output);
 	output->driver_private = NULL;
commit f073b5e58262d5fcc0102d773091d11d175227ce
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Tue Mar 18 15:48:22 2014 +0100

    Add support for server managed fds
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 0f9190a..b5fcdaf 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -213,9 +213,20 @@ static int check_outputs(int fd)
     return ret;
 }
 
-static Bool probe_hw(const char *dev)
+static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
 {
-    int fd = open_hw(dev);
+    int fd;
+
+#if XSERVER_PLATFORM_BUS
+    if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
+        fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1);
+        if (fd == -1)
+            return FALSE;
+        return check_outputs(fd);
+    }
+#endif
+
+    fd = open_hw(dev);
     if (fd != -1) {
         int ret = check_outputs(fd);
         close(fd);
@@ -283,6 +294,10 @@ ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
 	    flag = (CARD32 *)data;
 	    (*flag) = 0;
 	    return TRUE;
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,15,99,902,0)
+        case SUPPORTS_SERVER_FDS:
+            return TRUE;
+#endif
 	default:
 	    return FALSE;
     }
@@ -341,7 +356,7 @@ ms_platform_probe(DriverPtr driver,
     if (flags & PLATFORM_PROBE_GPU_SCREEN)
             scr_flags = XF86_ALLOCATE_GPU_SCREEN;
 
-    if (probe_hw(path)) {
+    if (probe_hw(path, dev)) {
         scrn = xf86AllocateScreen(driver, scr_flags);
         xf86AddEntityToScreen(scrn, entity_num);
 
@@ -387,7 +402,7 @@ Probe(DriverPtr drv, int flags)
     for (i = 0; i < numDevSections; i++) {
 
 	dev = xf86FindOptionValue(devSections[i]->options,"kmsdev");
-	if (probe_hw(dev)) {
+	if (probe_hw(dev, NULL)) {
 	    int entity;
 	    entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
 	    scrn = xf86ConfigFbEntity(scrn, 0, entity,
@@ -558,6 +573,10 @@ FreeRec(ScrnInfoPtr pScrn)
         if (ms->pEnt->location.type == BUS_PCI)
             ret = drmClose(ms->fd);
         else
+#ifdef XF86_PDEV_SERVER_FD
+        if (!(ms->pEnt->location.type == BUS_PLATFORM &&
+              (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)))
+#endif
             ret = close(ms->fd);
         (void) ret;
     }
@@ -630,8 +649,15 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
 #if XSERVER_PLATFORM_BUS
     if (pEnt->location.type == BUS_PLATFORM) {
-        char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
-        ms->fd = open_hw(path);
+#ifdef XF86_PDEV_SERVER_FD
+        if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
+            ms->fd = xf86_get_platform_device_int_attrib(pEnt->location.id.plat, ODEV_ATTRIB_FD, -1);
+        else
+#endif
+        {
+            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+            ms->fd = open_hw(path);
+        }
     }
     else 
 #endif
@@ -865,21 +891,37 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 #endif
 
 static Bool
+SetMaster(ScrnInfoPtr pScrn)
+{
+    modesettingPtr ms = modesettingPTR(pScrn);
+    int ret;
+
+#ifdef XF86_PDEV_SERVER_FD
+    if (ms->pEnt->location.type == BUS_PLATFORM &&
+            (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
+        return TRUE;
+#endif
+
+    ret = drmSetMaster(ms->fd);
+    if (ret)
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "drmSetMaster failed: %s\n",
+                   strerror(errno));
+
+    return ret == 0;
+}
+
+static Bool
 ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
     VisualPtr visual;
-    int ret;
 
     pScrn->pScreen = pScreen;
 
-    ret = drmSetMaster(ms->fd);
-    if (ret) {
-        ErrorF("Unable to set master\n");
+    if (!SetMaster(pScrn))
         return FALSE;
-    }
-      
+
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
@@ -1010,6 +1052,12 @@ LeaveVT(VT_FUNC_ARGS_DECL)
 
     pScrn->vtSema = FALSE;
 
+#ifdef XF86_PDEV_SERVER_FD
+    if (ms->pEnt->location.type == BUS_PLATFORM &&
+            (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
+        return;
+#endif
+
     drmDropMaster(ms->fd);
 }
 
@@ -1024,10 +1072,7 @@ EnterVT(VT_FUNC_ARGS_DECL)
 
     pScrn->vtSema = TRUE;
 
-    if (drmSetMaster(ms->fd)) {
-        xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "drmSetMaster failed: %s\n",
-                   strerror(errno));
-    }
+    SetMaster(pScrn);
 
     if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
 	return FALSE;
commit 98f59a33dfc2d47a57c68420f226dc0c17992164
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Feb 28 12:04:30 2014 +1000

    modesetting: fix cursor rendering with hotspots.
    
    older kernels report EINVAL not ENOSYS, doh.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 5b796e0..28a4abb 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -500,7 +500,7 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
                CursorPtr cursor = xf86_config->cursor;
                int ret;
                ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot);
-               if (ret == -ENOSYS)
+               if (ret == -EINVAL)
                        use_set_cursor2 = FALSE;
                else
                        return;
commit 2029c028fcffbe1aa175ab75636ae954a211c82a
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Feb 25 09:06:55 2014 -0500

    modesetting: Don't (brokenly) double-track software cursor
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 4a74ece..0f9190a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -801,7 +801,7 @@ CreateScreenResources(ScreenPtr pScreen)
 
     drmmode_uevent_init(pScrn, &ms->drmmode);
 
-    if (!ms->SWCursor)
+    if (!ms->drmmode.sw_cursor)
         drmmode_map_cursor_bos(pScrn, &ms->drmmode);
     pixels = drmmode_map_front_bo(&ms->drmmode);
     if (!pixels)
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index e84d748..450b29c 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -59,7 +59,6 @@ typedef struct _modesettingRec
 #endif
 
     Bool noAccel;
-    Bool SWCursor;
     CloseScreenProcPtr CloseScreen;
 
     /* Broken-out options. */
commit fac2bcf1da09fba8bc8b22631e31f3c5b2737efd
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Jan 20 11:06:42 2014 +1000

    modesetting: try and use hotspot cursor support
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ccfd75f..5b796e0 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -43,6 +43,8 @@
 #include "xf86Crtc.h"
 #include "drmmode_display.h"
 
+#include <cursorstr.h>
+
 /* DPMS */
 #ifdef HAVE_XEXTPROTO_71
 #include <X11/extensions/dpmsconst.h>
@@ -491,6 +493,18 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	uint32_t handle = drmmode_crtc->cursor_bo->handle;
+       static Bool use_set_cursor2 = TRUE;
+
+       if (use_set_cursor2) {
+               xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+               CursorPtr cursor = xf86_config->cursor;
+               int ret;
+               ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot);
+               if (ret == -ENOSYS)
+                       use_set_cursor2 = FALSE;
+               else
+                       return;
+       }
 
 	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
 			 ms->cursor_width, ms->cursor_height);
commit 4aab7aa7c1a15af7211996fa30e17a645f120ff9
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Feb 21 12:48:42 2014 +1000

    modesetting: move closing fd to after we check outputs
    
    On something like cirrus, start X, then attempt to start a second
    X while the first is running, if fbdev is installed it'll fail
    hard.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b28622a..4a74ece 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -258,11 +258,11 @@ static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
 
     id = drmGetBusid(fd);
     devid = ms_DRICreatePCIBusID(pdev);
-    close(fd);
 
     if (id && devid && !strcmp(id, devid))
         ret = check_outputs(fd);
 
+    close(fd);
     free(id);
     free(devid);
     return ret;
commit 02fbae85e7aa17b213e1411fe558256998d367c4
Author: Alex Deucher <alexander.deucher at amd.com>
Date:   Wed Feb 12 13:06:51 2014 -0500

    modesetting: query cursor size from the kernel
    
    Use new drm caps.  This allows hw cursors to work
    correctly on gpus with non-64x64 cursors.
    
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b84624e..b28622a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -566,6 +566,14 @@ FreeRec(ScrnInfoPtr pScrn)
 
 }
 
+#ifndef DRM_CAP_CURSOR_WIDTH
+#define DRM_CAP_CURSOR_WIDTH 0x8
+#endif
+
+#ifndef DRM_CAP_CURSOR_HEIGHT
+#define DRM_CAP_CURSOR_HEIGHT 0x9
+#endif
+
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
@@ -706,6 +714,17 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	prefer_shadow = !!value;
     }
 
+    ms->cursor_width = 64;
+    ms->cursor_height = 64;
+    ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value);
+    if (!ret) {
+	ms->cursor_width = value;
+    }
+    ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_HEIGHT, &value);
+    if (!ret) {
+	ms->cursor_height = value;
+    }
+
     ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
@@ -933,7 +952,7 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
 
     /* Need to extend HWcursor support to handle mask interleave */
     if (!ms->drmmode.sw_cursor)
-	xf86_cursors_init(pScreen, 64, 64,
+	xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height,
 			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
 			  HARDWARE_CURSOR_ARGB);
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 79561c8..e84d748 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -76,6 +76,7 @@ typedef struct _modesettingRec
     DamagePtr damage;
     Bool dirty_enabled;
 
+    uint32_t cursor_width, cursor_height;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 25641ce..ccfd75f 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -52,6 +52,8 @@
 #endif
 #include "compat-api.h"
 
+#include "driver.h"
+
 static struct dumb_bo *dumb_bo_create(int fd,
 			  const unsigned width, const unsigned height,
 			  const unsigned bpp)
@@ -445,6 +447,7 @@ drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 static void
 drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	int i;
 	uint32_t *ptr;
@@ -453,10 +456,11 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 	/* cursor should be mapped already */
 	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
 
-	for (i = 0; i < 64 * 64; i++)
+	for (i = 0; i < ms->cursor_width * ms->cursor_height; i++)
 		ptr[i] = image[i];// cpu_to_le32(image[i]);
 
-	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
+			       ms->cursor_width, ms->cursor_height);
 	if (ret) {
 		xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 		xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
@@ -471,21 +475,25 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 static void
 drmmode_hide_cursor (xf86CrtcPtr crtc)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 64, 64);
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0,
+			 ms->cursor_width, ms->cursor_height);
 
 }
 
 static void
 drmmode_show_cursor (xf86CrtcPtr crtc)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	uint32_t handle = drmmode_crtc->cursor_bo->handle;
 
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
+			 ms->cursor_width, ms->cursor_height);
 }
 
 static void
@@ -1485,6 +1493,7 @@ void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode)
 /* create front and cursor BOs */
 Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
+	modesettingPtr ms = modesettingPTR(pScrn);
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	int width;
 	int height;
@@ -1500,7 +1509,8 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 		return FALSE;
 	pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
 
-	width = height = 64;
+	width = ms->cursor_width;
+	height = ms->cursor_height;
 	bpp = 32;
 	for (i = 0; i < xf86_config->num_crtc; i++) {
 		xf86CrtcPtr crtc = xf86_config->crtc[i];
commit ae24f5bf6b31c035af50e14727966055ed8767bd
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Tue Dec 3 17:01:28 2013 +0100

    bump to 0.8.1
commit 59e324abd7cbda5d301b7b67125cd6d96684f000
Author: Thierry Reding <thierry.reding at gmail.com>
Date:   Tue Nov 26 17:08:03 2013 +0100

    Properly identify DSI outputs
    
    Newer Linux kernels support DSI outputs. To be able to identify them
    properly, add DSI to the list of output names.
    
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Thierry Reding <treding at nvidia.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index a343778..25641ce 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -977,6 +977,7 @@ static const char * const output_names[] = { "None",
 					     "TV",
 					     "eDP",
 					     "Virtual",
+					     "DSI",
 };
 
 static void
commit 190289f6393191bb3c58067ce1df994809475077
Author: Thierry Reding <thierry.reding at gmail.com>
Date:   Tue Nov 26 17:08:02 2013 +0100

    Staticise and constify output names
    
    This array isn't used anywhere outside this file, so it can be made
    static. While at it, make the array const as well.
    
    Signed-off-by: Thierry Reding <treding at nvidia.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 773ec4c..a343778 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -961,22 +961,22 @@ static int subpixel_conv_table[7] = { 0, SubPixelUnknown,
 				      SubPixelVerticalBGR,
 				      SubPixelNone };
 
-const char *output_names[] = { "None",
-			       "VGA",
-			       "DVI",
-			       "DVI",
-			       "DVI",
-			       "Composite",
-			       "S-video",
-			       "LVDS",
-			       "CTV",
-			       "DIN",
-			       "DisplayPort",
-			       "HDMI",
-			       "HDMI",
-			       "TV",
-			       "eDP",
-			       "Virtual"
+static const char * const output_names[] = { "None",
+					     "VGA",
+					     "DVI",
+					     "DVI",
+					     "DVI",
+					     "Composite",
+					     "S-video",
+					     "LVDS",
+					     "CTV",
+					     "DIN",
+					     "DisplayPort",
+					     "HDMI",
+					     "HDMI",
+					     "TV",
+					     "eDP",
+					     "Virtual",
 };
 
 static void
commit a307ac27382dd0c377cd1a436cb25cb5aaa54416
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Nov 15 13:39:52 2013 +0900

    Handle new DamageUnregister API which has only one argument
    
    API change in 1.15
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index adf4b99..745c484 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -37,6 +37,10 @@
 #define MODESETTING_OUTPUT_SLAVE_SUPPORT 1
 #endif
 
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
+#define DamageUnregister(d, dd) DamageUnregister(dd)
+#endif
+
 struct dumb_bo {
     uint32_t handle;
     uint32_t size;
commit d6ffce4b0e2376e1f8f04ee70b323a6aea3e517e
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Nov 15 13:26:36 2013 +0900

    Clean up compiler warnings.
    
    Add const to any immutable string pointers.
    Rename 'range' to 'prop_range' to avoid redefined warning.
    Eliminate some unused return values.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index cc526f6..b84624e 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -183,7 +183,7 @@ Identify(int flags)
 		      Chipsets);
 }
 
-static int open_hw(char *dev)
+static int open_hw(const char *dev)
 {
     int fd;
     if (dev)
@@ -213,7 +213,7 @@ static int check_outputs(int fd)
     return ret;
 }
 
-static Bool probe_hw(char *dev)
+static Bool probe_hw(const char *dev)
 {
     int fd = open_hw(dev);
     if (fd != -1) {
@@ -237,7 +237,7 @@ ms_DRICreatePCIBusID(const struct pci_device *dev)
 }
 
 
-static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
+static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
 {
     int ret = FALSE, fd = open_hw(dev);
     char *id, *devid;
@@ -298,7 +298,7 @@ ms_pci_probe(DriverPtr driver,
     scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
 			       NULL, NULL, NULL, NULL, NULL);
     if (scrn) {
-	char *devpath;
+	const char *devpath;
 	GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0],
 						  scrn->entityInstanceList[0]);
 
@@ -335,7 +335,7 @@ ms_platform_probe(DriverPtr driver,
               int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
-    char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
+    const char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
     int scr_flags = 0;
 
     if (flags & PLATFORM_PROBE_GPU_SCREEN)
@@ -369,7 +369,7 @@ Probe(DriverPtr drv, int flags)
     int i, numDevSections;
     GDevPtr *devSections;
     Bool foundScreen = FALSE;
-    char *dev;
+    const char *dev;
     ScrnInfoPtr scrn = NULL;
 
     /* For now, just bail out for PROBE_DETECT. */
@@ -559,6 +559,7 @@ FreeRec(ScrnInfoPtr pScrn)
             ret = drmClose(ms->fd);
         else
             ret = close(ms->fd);
+        (void) ret;
     }
     free(ms->Options);
     free(ms);
@@ -572,7 +573,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    char *BusID = NULL, *devicename;
+    char *BusID = NULL;
+    const char *devicename;
     Bool prefer_shadow = TRUE;
     uint64_t value = 0;
     int ret;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4fb4d21..773ec4c 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -534,14 +534,13 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 	DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage);
 
 	if (ppriv->fb_id == 0) {
-		int r;
-		r = drmModeAddFB(drmmode->fd, ppix->drawable.width,
-				 ppix->drawable.height,
-				 ppix->drawable.depth,
-				 ppix->drawable.bitsPerPixel,
-				 ppix->devKind,
-				 ppriv->backing_bo->handle,
-				 &ppriv->fb_id);
+                drmModeAddFB(drmmode->fd, ppix->drawable.width,
+                             ppix->drawable.height,
+                             ppix->drawable.depth,
+                             ppix->drawable.bitsPerPixel,
+                             ppix->devKind,
+                             ppriv->backing_bo->handle,
+                             &ppriv->fb_id);
 	}
 	return TRUE;
 }
@@ -830,7 +829,7 @@ drmmode_output_create_resources(xf86OutputPtr output)
 	drmmode_prop = p->mode_prop;
 
 	if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
-	    INT32 range[2];
+	    INT32 prop_range[2];
 	    INT32 value = p->value;
 
 	    p->num_atoms = 1;
@@ -838,12 +837,12 @@ drmmode_output_create_resources(xf86OutputPtr output)
 	    if (!p->atoms)
 		continue;
 	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
-	    range[0] = drmmode_prop->values[0];
-	    range[1] = drmmode_prop->values[1];
+	    prop_range[0] = drmmode_prop->values[0];
+	    prop_range[1] = drmmode_prop->values[1];
 	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
 		    FALSE, TRUE,
 		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
-		    2, range);
+		    2, prop_range);
 	    if (err != 0) {
 		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
 			"RRConfigureOutputProperty error, %d\n", err);
commit 836daf4c7a276108a9f950e524828744aeda0a3c
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 31 11:24:48 2013 +1000

    modesetting: change output names for secondary GPUs
    
    if we are a secondary GPU modify the output name to avoid clashes.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ce90cea..4fb4d21 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1010,6 +1010,10 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	/* need to do smart conversion here for compat with non-kms ATI driver */
 	if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
 		snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+	else if (pScrn->is_gpu)
+		snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id - 1);
+#endif
 	else
 		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
 
commit 951d2f83fc65a136717fb8090510d053e3f3a6c0
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Jun 12 14:11:53 2013 +0200

    bump to 0.8.0
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>
commit 525ac7fb9a0d639253fc5d6556db3edb7239f932
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Jun 12 14:05:19 2013 +0200

    modesetting: probe only succeeds if connectors are detected
    
    This will prevent modesetting being used for outputless intel or nvidia cards.
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index c3d78be..cc526f6 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -201,12 +201,25 @@ static int open_hw(char *dev)
     return fd;
 }
 
+static int check_outputs(int fd)
+{
+    drmModeResPtr res = drmModeGetResources(fd);
+    int ret;
+
+    if (!res)
+        return FALSE;
+    ret = res->count_connectors > 0;
+    drmModeFreeResources(res);
+    return ret;
+}
+
 static Bool probe_hw(char *dev)
 {
     int fd = open_hw(dev);
     if (fd != -1) {
+        int ret = check_outputs(fd);
         close(fd);
-        return TRUE;
+        return ret;
     }
     return FALSE;
 }
@@ -226,7 +239,7 @@ ms_DRICreatePCIBusID(const struct pci_device *dev)
 
 static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
 {
-    int fd = open_hw(dev);
+    int ret = FALSE, fd = open_hw(dev);
     char *id, *devid;
     drmSetVersion sv;
 
@@ -247,13 +260,12 @@ static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
     devid = ms_DRICreatePCIBusID(pdev);
     close(fd);
 
-    if (!id || !devid)
-	return FALSE;
-
-    if (!strcmp(id, devid))
-	return TRUE;
+    if (id && devid && !strcmp(id, devid))
+        ret = check_outputs(fd);
 
-    return FALSE;
+    free(id);
+    free(devid);
+    return ret;
 }
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
commit d4791dd97b85ddac1295761bf6ab4f10c08346d7
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 11 10:29:25 2013 +1000

    modesetting: fix adjust frame crash
    
    When SDL called this it was totally broken, actually hook
    up to the underlying drmmode function.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64808
    
    Thanks to Peter Wu <lekensteyn at gmail.com> for harassing me.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 742aadd..c3d78be 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -956,16 +956,9 @@ static void
 AdjustFrame(ADJUST_FRAME_ARGS_DECL)
 {
     SCRN_INFO_PTR(arg);
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-    xf86OutputPtr output = config->output[config->compat_output];
-    xf86CrtcPtr crtc = output->crtc;
-
-    if (crtc && crtc->enabled) {
-	crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x,
-			      y);
-	crtc->x = output->initial_x + x;
-	crtc->y = output->initial_y + y;
-    }
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    drmmode_adjust_frame(pScrn, &ms->drmmode, x, y);
 }
 
 static void
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 2dc7576..ce90cea 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1267,7 +1267,7 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 	return TRUE;
 }
 
-void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags)
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y)
 {
 	xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
 	xf86OutputPtr  output = config->output[config->compat_output];
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 1d5522b..adf4b99 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -118,7 +118,7 @@ Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 #endif
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
-void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
 extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
 
commit c64fa9a2961f82719cc7734a4222f31297a2e593
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Apr 3 12:08:44 2013 +0200

    support 32 bpp pixmaps when 24 bpp fb is used.
    
    Fixes background corruption in ubuntu.
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 06d6d53..742aadd 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -650,7 +650,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 #endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
     if (defaultdepth == 24 && defaultbpp == 24)
-	    bppflags = Support24bppFb;
+	    bppflags = SupportConvert32to24 | Support24bppFb;
     else
 	    bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
     
commit 3a9a6c972e4bc88dc3dde9399df3b0cda759cd70
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Mar 27 10:33:46 2013 +0100

    bump version to 0.7.0
commit 862bc2836835b93f4b2cfd2de6ca344f65484a00
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Tue Mar 26 15:19:52 2013 +0100

    modesetting: return null for get_modes if output could not be retrieved
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index e8ebef1..2dc7576 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -709,6 +709,9 @@ drmmode_output_get_modes(xf86OutputPtr output)
 	drmModePropertyPtr props;
 	xf86MonPtr mon = NULL;
 
+	if (!koutput)
+		return NULL;
+
 	/* look for an EDID property */
 	for (i = 0; i < koutput->count_props; i++) {
 		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
commit 6b79a8791d35bbd1a13ebdec1c582f66c559c039
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Tue Mar 26 15:19:33 2013 +0100

    modesetting: clean up leaks
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 87ba272..06d6d53 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -206,7 +206,7 @@ static Bool probe_hw(char *dev)
     int fd = open_hw(dev);
     if (fd != -1) {
         close(fd);
-	return TRUE;
+        return TRUE;
     }
     return FALSE;
 }
@@ -530,15 +530,27 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 static void
 FreeRec(ScrnInfoPtr pScrn)
 {
+    modesettingPtr ms;
+
     if (!pScrn)
-	return;
+        return;
 
-    if (!pScrn->driverPrivate)
-	return;
+    ms = modesettingPTR(pScrn);
+    if (!ms)
+        return;
+    pScrn->driverPrivate = NULL;
 
-    free(pScrn->driverPrivate);
+    if (ms->fd > 0) {
+        int ret;
+
+        if (ms->pEnt->location.type == BUS_PCI)
+            ret = drmClose(ms->fd);
+        else
+            ret = close(ms->fd);
+    }
+    free(ms->Options);
+    free(ms);
 
-    pScrn->driverPrivate = NULL;
 }
 
 static Bool
@@ -596,8 +608,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
 #if XSERVER_PLATFORM_BUS
     if (pEnt->location.type == BUS_PLATFORM) {
-            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
-            ms->fd = open_hw(path);
+        char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+        ms->fd = open_hw(path);
     }
     else 
 #endif
commit 1754973206c09a901747e71d4abdf666293da59e
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Wed Feb 20 17:27:16 2013 -0800

    modesetting: match PCI class 3, any subclass
    
    If a device is not primary, the PCI device match fails because the
    xf86-video-modesetting driver looks specifically for a PCI class match of
    0x30000 with a mask of 0xffffff.  This fails to match, for example, a
    non-primary Intel VGA device, because it is reported as having a class of
    0x38000.
    
    Fix that by ignoring the low 16 bits of the class in the pci_id_match table.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Reviewed on IRC by Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 05b6176..87ba272 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -86,7 +86,7 @@ static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op,
 static const struct pci_id_match ms_device_match[] = {
     {
 	PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
-	0x00030000, 0x00ffffff, 0
+	0x00030000, 0x00ff0000, 0
     },
 
     { 0, 0, 0 },
commit beb1715e96b649a0903fa61f30dd1eb69411da2f
Author: Colin Walters <walters at verbum.org>
Date:   Wed Jan 4 22:37:06 2012 +0000

    autogen.sh: Implement GNOME Build API
    
    http://people.gnome.org/~walters/docs/build-api.txt
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
commit 75815dbb373d5a74d57cbec9d469f9f88a8ee3ef
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Dec 3 13:25:19 2012 +0000

    Add missing GTF modes
    
    A fixed-mode output device like a panel will often only inform of its
    preferred mode through its EDID. However, the driver will adjust user
    specified modes for display through use of a panel-fitter allowing
    greater flexibility in upscaling. This is often used by games to set a
    low resolution for performance and use the panel fitter to fill the
    screen.
    
    v2: Use the presence of the 'scaling mode' connector property as an
    indication that a panel fitter is attached to that pipe.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=55564

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 63cecc3..e8ebef1 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -626,6 +626,78 @@ drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
 	return MODE_OK;
 }
 
+static Bool
+has_panel_fitter(xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmModeConnectorPtr koutput = drmmode_output->mode_output;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+	int i;
+
+	/* Presume that if the output supports scaling, then we have a
+	 * panel fitter capable of adjust any mode to suit.
+	 */
+	for (i = 0; i < koutput->count_props; i++) {
+		drmModePropertyPtr props;
+		Bool found = FALSE;
+
+		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+		if (props) {
+			found = strcmp(props->name, "scaling mode") == 0;
+			drmModeFreeProperty(props);
+		}
+
+		if (found)
+			return TRUE;
+	}
+
+	return FALSE;
+}
+
+static DisplayModePtr
+drmmode_output_add_gtf_modes(xf86OutputPtr output,
+			     DisplayModePtr Modes)
+{
+	xf86MonPtr mon = output->MonInfo;
+	DisplayModePtr i, m, preferred = NULL;
+	int max_x = 0, max_y = 0;
+	float max_vrefresh = 0.0;
+
+	if (mon && GTF_SUPPORTED(mon->features.msc))
+		return Modes;
+
+	if (!has_panel_fitter(output))
+		return Modes;
+
+	for (m = Modes; m; m = m->next) {
+		if (m->type & M_T_PREFERRED)
+			preferred = m;
+		max_x = max(max_x, m->HDisplay);
+		max_y = max(max_y, m->VDisplay);
+		max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m));
+	}
+
+	max_vrefresh = max(max_vrefresh, 60.0);
+	max_vrefresh *= (1 + SYNC_TOLERANCE);
+
+	m = xf86GetDefaultModes();
+	xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0);
+
+	for (i = m; i; i = i->next) {
+		if (xf86ModeVRefresh(i) > max_vrefresh)
+			i->status = MODE_VSYNC;
+		if (preferred &&
+		    i->HDisplay >= preferred->HDisplay &&
+		    i->VDisplay >= preferred->VDisplay &&
+		    xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred))
+			i->status = MODE_VSYNC;
+	}
+
+	xf86PruneInvalidModes(output->scrn, &m, FALSE);
+
+	return xf86ModesAdd(Modes, m);
+}
+
 static DisplayModePtr
 drmmode_output_get_modes(xf86OutputPtr output)
 {
@@ -666,7 +738,8 @@ drmmode_output_get_modes(xf86OutputPtr output)
 		Modes = xf86ModesAdd(Modes, Mode);
 
 	}
-	return Modes;
+
+	return drmmode_output_add_gtf_modes(output, Modes);
 }
 
 static void
commit ac34281b8a487640c61f258ae45a6f17a4fb3cc0
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 7 12:24:20 2013 +1000

    modesetting: provide dummy hooks for shadow
    
    Since in some wierd cases the server can call these without checking they
    exist.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 42cd5ac..63cecc3 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -547,6 +547,17 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 }
 #endif
 
+static void *drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
+{
+	return NULL;
+}
+
+static PixmapPtr drmmode_shadow_create(xf86CrtcPtr crtc, void *data, int width,
+				       int height)
+{
+	return NULL;
+}
+
 static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .dpms = drmmode_crtc_dpms,
     .set_mode_major = drmmode_set_mode_major,
@@ -561,6 +572,8 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
 #ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     .set_scanout_pixmap = drmmode_set_scanout_pixmap,
 #endif
+    .shadow_allocate = drmmode_shadow_allocate,
+    .shadow_create = drmmode_shadow_create,
 };
 
 static void
commit 34a571c5b9781025897ba5e5c5e2a34ae5262266
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jan 9 13:04:00 2013 +1000

    modesetting: bump to 0.6.0
commit 8650ff14a52047173fa32f12f22ec6f4e38ff433
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jan 9 12:48:30 2013 +1000

    modesetting: fix crashes caused by udev race conditions
    
    So the kernel removes the device, and the driver processes the first
    udev event, and gets no output back from the kernel, so it check
    and don't fall over.
    
    This fixes a couple of crashes seen when hotplugging USB devices.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 8d760c2..42cd5ac 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -589,6 +589,8 @@ drmmode_output_detect(xf86OutputPtr output)
 	drmModeFreeConnector(drmmode_output->mode_output);
 
 	drmmode_output->mode_output = drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
+	if (!drmmode_output->mode_output)
+		return XF86OutputStatusDisconnected;
 
 	switch (drmmode_output->mode_output->connection) {
 	case DRM_MODE_CONNECTED:
@@ -683,6 +685,9 @@ drmmode_output_dpms(xf86OutputPtr output, int mode)
 	drmModeConnectorPtr koutput = drmmode_output->mode_output;
 	drmmode_ptr drmmode = drmmode_output->drmmode;
 
+	if (!koutput)
+		return;
+
 	drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
 				    drmmode_output->dpms_enum_id, mode);
 	return;
commit 0b198248ecfbcb7e7c61688145be4005366da23d
Author: Thierry Reding <thierry.reding at avionic-design.de>
Date:   Thu Nov 8 14:28:10 2012 +0100

    Remove call to miInitializeBackingStore()
    
    Recent versions of the X server no longer provide this function, which
    has been obsolete for over 2 years now.
    
    Signed-off-by: Thierry Reding <thierry.reding at avionic-design.de>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 200a6d8..05b6176 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -901,7 +901,6 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
 
     xf86SetBlackWhitePixels(pScreen);
 
-    miInitializeBackingStore(pScreen);
     xf86SetBackingStore(pScreen);
     xf86SetSilkenMouse(pScreen);
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
commit 739d6c067a9167226ce248aa82997bfc2cca7259
Author: Thierry Reding <thierry.reding at avionic-design.de>
Date:   Thu Nov 8 14:28:09 2012 +0100

    build: Put m4 macros in m4 subdirectory
    
    This silences a warning from libtoolize when running the autogen.sh
    script.
    
    Signed-off-by: Thierry Reding <thierry.reding at avionic-design.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit e47ad8a0aec7662970e7f81e6ee487330bf094c1
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Sep 17 11:48:14 2012 +1000

    modesetting: remove alloca usage again
    
    this slipped back in.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 38a1c09..200a6d8 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -428,10 +428,13 @@ static int dispatch_dirty_region(ScrnInfoPtr scrn,
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
 
     if (num_cliprects) {
-	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
+	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
 	    
+	if (!clip)
+	    return -ENOMEM;
+
 	/* XXX no need for copy? */
 	for (i = 0; i < num_cliprects; i++, rect++) {
 	    clip[i].x1 = rect->x1;
@@ -442,6 +445,7 @@ static int dispatch_dirty_region(ScrnInfoPtr scrn,
 
 	/* TODO query connector property to see if this is needed */
 	ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects);
+	free(clip);
 	DamageEmpty(damage);
 	if (ret) {
 	    if (ret == -EINVAL)
commit f8eb8c1cb4f453bdbe6a81815be8ecefba2084aa
Author: Alon Levy <alevy at redhat.com>
Date:   Tue Aug 28 11:46:47 2012 +1000

    modesetting: add virtual connector support
    
    [airlied: also make sure we don't crash in future.]
    
    Signed-off-by: Alon Levy <alevy at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 5e38265..8d760c2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -882,7 +882,8 @@ const char *output_names[] = { "None",
 			       "HDMI",
 			       "HDMI",
 			       "TV",
-			       "eDP"
+			       "eDP",
+			       "Virtual"
 };
 
 static void
@@ -913,7 +914,10 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	}
 
 	/* need to do smart conversion here for compat with non-kms ATI driver */
-	snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
+	if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
+		snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
+	else
+		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
 
 	output = xf86OutputCreate (pScrn, &drmmode_output_funcs, name);
 	if (!output) {
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 24f7960..1d5522b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -139,5 +139,7 @@ void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth
 #define DRM_CAP_DUMB_PREFER_SHADOW 4
 #endif
 
+#define MS_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
 
 #endif
commit 5eb697d88f0735e98fe9a97770ddda83202b1597
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Thu Sep 13 08:45:14 2012 +0200

    bump version to 0.5.0
commit e3d7d5d18e3281677890064679af459e1af108cf
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Jul 19 22:15:10 2012 +0000

    Implement ->driverFunc
    
    Copied from fbdev, makes it so we can run without iopl.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 371c171..38a1c09 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -79,6 +79,8 @@ static Bool Probe(DriverPtr drv, int flags);
 static Bool ms_pci_probe(DriverPtr driver,
 			 int entity_num, struct pci_device *device,
 			 intptr_t match_data);
+static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op,
+			   void *data);
 
 #ifdef XSERVER_LIBPCIACCESS
 static const struct pci_id_match ms_device_match[] = {
@@ -105,7 +107,7 @@ _X_EXPORT DriverRec modesetting = {
     AvailableOptions,
     NULL,
     0,
-    NULL,
+    ms_driver_func,
     ms_device_match,
     ms_pci_probe,
 #ifdef XSERVER_PLATFORM_BUS
@@ -259,6 +261,21 @@ AvailableOptions(int chipid, int busid)
     return Options;
 }
 
+static Bool
+ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
+{
+    xorgHWFlags *flag;
+    
+    switch (op) {
+	case GET_REQUIRED_HW_INTERFACES:
+	    flag = (CARD32 *)data;
+	    (*flag) = 0;
+	    return TRUE;
+	default:
+	    return FALSE;
+    }
+}
+
 #if XSERVER_LIBPCIACCESS
 static Bool
 ms_pci_probe(DriverPtr driver,
commit 02811f1a9cc35c5f82accb0459cb3910165e7e45
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 19 14:12:59 2012 +1000

    modesetting: add output slave support.
    
    This allows the driver to operate as an output slave.
    
    It adds scan out pixmap, and the capability
    checks to make sure they available.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 86be277..371c171 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -401,21 +401,20 @@ GetRec(ScrnInfoPtr pScrn)
     return TRUE;
 }
 
-static void dispatch_dirty(ScreenPtr pScreen)
+static int dispatch_dirty_region(ScrnInfoPtr scrn,
+				 PixmapPtr pixmap,
+				 DamagePtr damage,
+				 int fb_id)
 {
-    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(scrn);
-    RegionPtr dirty = DamageRegion(ms->damage);
+    RegionPtr dirty = DamageRegion(damage);
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
 
     if (num_cliprects) {
-	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
+	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
-	
-	if (!clip)
-		return;
-
+	    
 	/* XXX no need for copy? */
 	for (i = 0; i < num_cliprects; i++, rect++) {
 	    clip[i].x1 = rect->x1;
@@ -425,25 +424,71 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	}
 
 	/* TODO query connector property to see if this is needed */
-	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
-	free(clip);
+	ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects);
+	DamageEmpty(damage);
 	if (ret) {
-	    if (ret == -EINVAL || ret == -ENOSYS) {
-		ms->dirty_enabled = FALSE;
-		DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
-		DamageDestroy(ms->damage);
-		ms->damage = NULL;
-		xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
-		return;
-	    } else
-		ErrorF("%s: failed to send dirty (%i, %s)\n",
-		       __func__, ret, strerror(-ret));
+	    if (ret == -EINVAL)
+		return ret;
 	}
-	
-	DamageEmpty(ms->damage);
+    }
+    return 0;
+}
+
+static void dispatch_dirty(ScreenPtr pScreen)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    PixmapPtr pixmap = pScreen->GetScreenPixmap(pScreen);
+    int fb_id = ms->drmmode.fb_id;
+    int ret;
+
+    ret = dispatch_dirty_region(scrn, pixmap, ms->damage, fb_id);
+    if (ret == -EINVAL || ret == -ENOSYS) {
+	ms->dirty_enabled = FALSE;
+	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageDestroy(ms->damage);
+	ms->damage = NULL;
+	xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
+	return;
+    }
+}
+
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static void dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(scrn);
+    PixmapPtr pixmap = crtc->randr_crtc->scanout_pixmap;
+    msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, pixmap);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    DamagePtr damage = drmmode_crtc->slave_damage;
+    int fb_id = ppriv->fb_id;
+    int ret;
+
+    ret = dispatch_dirty_region(scrn, pixmap, damage, fb_id);
+    if (ret) {
+
     }
 }
 
+static void dispatch_slave_dirty(ScreenPtr pScreen)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++) {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (!crtc->randr_crtc)
+	    continue;
+	if (!crtc->randr_crtc->scanout_pixmap)
+	    continue;
+
+	dispatch_dirty_crtc(scrn, crtc);
+    }
+}
+#endif
+
 static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 {
     SCREEN_PTR(arg);
@@ -452,8 +497,13 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
     pScreen->BlockHandler = ms->BlockHandler;
     pScreen->BlockHandler(BLOCKHANDLER_ARGS);
     pScreen->BlockHandler = msBlockHandler;
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    if (pScreen->isGPU)
+        dispatch_slave_dirty(pScreen);
+    else
+#endif
     if (ms->dirty_enabled)
-	dispatch_dirty(pScreen);
+        dispatch_dirty(pScreen);
 }
 
 static void
@@ -555,6 +605,16 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     ms->drmmode.fd = ms->fd;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    pScrn->capabilities = 0;
+#ifdef DRM_CAP_PRIME
+    ret = drmGetCap(ms->fd, DRM_CAP_PRIME, &value);
+    if (ret == 0) {
+        if (value & DRM_PRIME_CAP_IMPORT)
+            pScrn->capabilities |= RR_Capability_SinkOutput;
+    }
+#endif
+#endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
     if (defaultdepth == 24 && defaultbpp == 24)
 	    bppflags = Support24bppFb;
@@ -719,6 +779,25 @@ msShadowInit(ScreenPtr pScreen)
     return TRUE;
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static Bool
+msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
+{
+    ScreenPtr screen = ppix->drawable.pScreen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    Bool ret;
+    int size = ppix->devKind * ppix->drawable.height;
+    int ihandle = (int)(long)fd_handle;
+
+    ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size);
+    if (ret == FALSE)
+	    return ret;
+
+    return TRUE;
+}
+#endif
+
 static Bool
 ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
@@ -757,6 +836,13 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     if (!miSetPixmapDepths())
 	return FALSE;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    if (!dixRegisterScreenSpecificPrivateKey(pScreen, &ms->drmmode.pixmapPrivateKeyRec,
+        PRIVATE_PIXMAP, sizeof(msPixmapPrivRec))) { 
+	return FALSE;
+    }
+#endif
+
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
 
@@ -816,6 +902,10 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     ms->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = msBlockHandler;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking;
+#endif
+
     if (!xf86CrtcScreenInit(pScreen))
 	return FALSE;
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 9ee553e..5e38265 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -138,6 +138,43 @@ static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
 	return 0;
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, int size)
+{
+  	struct dumb_bo *bo;
+	int ret;
+
+	bo = calloc(1, sizeof(*bo));
+	if (!bo)
+		return NULL;
+
+	ret = drmPrimeFDToHandle(fd, handle, &bo->handle);
+	if (ret) {
+		free(bo);
+		return NULL;
+	}
+	bo->pitch = pitch;
+	bo->size = size;
+	return bo;
+}
+#endif
+
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+Bool drmmode_SetSlaveBO(PixmapPtr ppix,
+			drmmode_ptr drmmode, 
+			int fd_handle, int pitch, int size)
+{
+    	msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix);
+
+	ppriv->backing_bo = dumb_get_bo_from_handle(drmmode->fd, fd_handle, pitch, size);
+	if (!ppriv->backing_bo)
+		return FALSE;
+
+	close(fd_handle);
+	return TRUE;
+}
+#endif
+
 static void
 drmmode_ConvertFromKMode(ScrnInfoPtr	scrn,
 		     drmModeModeInfo *kmode,
@@ -274,7 +311,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 	int output_count = 0;
 	Bool ret = TRUE;
 	int i;
-	int fb_id;
+	uint32_t fb_id;
 	drmModeModeInfo kmode;
 	int height;
 
@@ -338,6 +375,13 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
 		fb_id = drmmode->fb_id;
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+		if (crtc->randr_crtc->scanout_pixmap) {
+    			msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+			fb_id = ppriv->fb_id;
+			x = y = 0;
+		} else 
+#endif
 		if (drmmode_crtc->rotate_fb_id) {
 			fb_id = drmmode_crtc->rotate_fb_id;
 			x = y = 0;
@@ -455,6 +499,54 @@ drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
 			    size, red, green, blue);
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static Bool
+drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	msPixmapPrivPtr ppriv;
+	void *ptr;
+
+	if (!ppix) {
+		if (crtc->randr_crtc->scanout_pixmap) {
+    			ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+			drmModeRmFB(drmmode->fd, ppriv->fb_id);
+		}
+		if (drmmode_crtc->slave_damage) {
+			DamageUnregister(&crtc->randr_crtc->scanout_pixmap->drawable,
+					 drmmode_crtc->slave_damage);
+			drmmode_crtc->slave_damage = NULL;
+		}
+		return TRUE;
+	}
+
+	ppriv = msGetPixmapPriv(drmmode, ppix);
+	if (!drmmode_crtc->slave_damage) {
+		drmmode_crtc->slave_damage = DamageCreate(NULL, NULL,
+							  DamageReportNone,
+							  TRUE,
+							  crtc->randr_crtc->pScreen,
+							  NULL);
+	}
+	ptr = drmmode_map_slave_bo(drmmode, ppriv);
+	ppix->devPrivate.ptr = ptr;
+	DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage);
+
+	if (ppriv->fb_id == 0) {
+		int r;
+		r = drmModeAddFB(drmmode->fd, ppix->drawable.width,
+				 ppix->drawable.height,
+				 ppix->drawable.depth,
+				 ppix->drawable.bitsPerPixel,
+				 ppix->devKind,
+				 ppriv->backing_bo->handle,
+				 &ppriv->fb_id);
+	}
+	return TRUE;
+}
+#endif
+
 static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .dpms = drmmode_crtc_dpms,
     .set_mode_major = drmmode_set_mode_major,
@@ -466,6 +558,9 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
 
     .gamma_set = drmmode_crtc_gamma_set,
     .destroy = NULL, /* XXX */
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    .set_scanout_pixmap = drmmode_set_scanout_pixmap,
+#endif
 };
 
 static void
@@ -1065,6 +1160,10 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 	/* workout clones */
 	drmmode_clones_init(pScrn, drmmode);
 
+#if XF86_CRTC_VERSION >= 5
+	xf86ProviderSetup(pScrn, NULL, "modesetting");
+#endif
+
 	xf86InitialConfiguration(pScrn, TRUE);
 
 	return TRUE;
@@ -1324,6 +1423,22 @@ void *drmmode_map_front_bo(drmmode_ptr drmmode)
 	
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
+{
+        int ret;
+
+        if (ppriv->backing_bo->ptr)
+                return ppriv->backing_bo->ptr;
+
+        ret = dumb_bo_map(drmmode->fd, ppriv->backing_bo);
+        if (ret)
+                return NULL;
+
+        return ppriv->backing_bo->ptr;  
+}
+#endif
+
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index fa280bd..24f7960 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -32,6 +32,11 @@
 #include "libudev.h"
 #endif
 
+/* the perfect storm */
+#if XF86_CRTC_VERSION >= 5 && defined(HAVE_DRMPRIMEFDTOHANDLE) && HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
+#define MODESETTING_OUTPUT_SLAVE_SUPPORT 1
+#endif
+
 struct dumb_bo {
     uint32_t handle;
     uint32_t size;
@@ -58,6 +63,9 @@ typedef struct {
     Bool shadow_enable;
     void *shadow_fb;
 
+#ifdef HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
+    DevPrivateKeyRec pixmapPrivateKeyRec;
+#endif
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
@@ -67,6 +75,7 @@ typedef struct {
     struct dumb_bo *cursor_bo;
     unsigned rotate_fb_id;
     uint16_t lut_r[256], lut_g[256], lut_b[256];
+    DamagePtr slave_damage;
 } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
 
 typedef struct {
@@ -90,6 +99,23 @@ typedef struct {
     int enc_clone_mask;
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+typedef struct _msPixmapPriv {
+    uint32_t fb_id;
+    struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */
+} msPixmapPrivRec, *msPixmapPrivPtr;
+
+
+extern DevPrivateKeyRec msPixmapPrivateKeyRec;
+#define msPixmapPrivateKey (&msPixmapPrivateKeyRec)
+
+#define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec))
+
+void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
+Bool drmmode_SetSlaveBO(PixmapPtr ppix,
+			drmmode_ptr drmmode,
+			int fd_handle, int pitch, int size);
+#endif
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
@@ -105,6 +131,7 @@ Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp);
 
+
 #ifndef DRM_CAP_DUMB_PREFERRED_DEPTH
 #define DRM_CAP_DUMB_PREFERRED_DEPTH 3
 #endif
commit fa171c5a81b1c226b5da54f35e6726d9c8e13afb
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 14:43:21 2012 +0100

    modesetting: add platform bus support

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8c3f4a4..86be277 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -52,6 +52,9 @@
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
 #include <xorg-server.h>
+#ifdef XSERVER_PLATFORM_BUS
+#include "xf86platformBus.h"
+#endif
 #if XSERVER_LIBPCIACCESS
 #include <pciaccess.h>
 #endif
@@ -88,6 +91,12 @@ static const struct pci_id_match ms_device_match[] = {
 };
 #endif
 
+#ifdef XSERVER_PLATFORM_BUS
+static Bool ms_platform_probe(DriverPtr driver,
+                          int entity_num, int flags, struct xf86_platform_device *device,
+			  intptr_t match_data);
+#endif
+
 _X_EXPORT DriverRec modesetting = {
     1,
     "modesetting",
@@ -99,6 +108,9 @@ _X_EXPORT DriverRec modesetting = {
     NULL,
     ms_device_match,
     ms_pci_probe,
+#ifdef XSERVER_PLATFORM_BUS
+    ms_platform_probe,
+#endif
 };
 
 static SymTabRec Chipsets[] = {
@@ -288,6 +300,40 @@ ms_pci_probe(DriverPtr driver,
 }
 #endif
 
+#ifdef XSERVER_PLATFORM_BUS
+static Bool
+ms_platform_probe(DriverPtr driver,
+              int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data)
+{
+    ScrnInfoPtr scrn = NULL;
+    char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
+    int scr_flags = 0;
+
+    if (flags & PLATFORM_PROBE_GPU_SCREEN)
+            scr_flags = XF86_ALLOCATE_GPU_SCREEN;
+
+    if (probe_hw(path)) {
+        scrn = xf86AllocateScreen(driver, scr_flags);
+        xf86AddEntityToScreen(scrn, entity_num);
+
+        scrn->driverName = "modesetting";
+        scrn->name = "modesetting";
+        scrn->PreInit = PreInit;
+        scrn->ScreenInit = ScreenInit;
+        scrn->SwitchMode = SwitchMode;
+        scrn->AdjustFrame = AdjustFrame;
+        scrn->EnterVT = EnterVT;
+        scrn->LeaveVT = LeaveVT;
+        scrn->FreeScreen = FreeScreen;
+        scrn->ValidMode = ValidMode;
+        xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                   "using drv %s\n", path ? path : "default device");
+    }
+
+    return scrn != NULL;
+}
+#endif
+
 static Bool
 Probe(DriverPtr drv, int flags)
 {
@@ -431,7 +477,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    char *BusID, *devicename;
+    char *BusID = NULL, *devicename;
     Bool prefer_shadow = TRUE;
     uint64_t value = 0;
     int ret;
@@ -477,24 +523,32 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
 
-    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-    if (ms->PciInfo) {
-       BusID = malloc(64);
-       sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_PLATFORM_BUS
+    if (pEnt->location.type == BUS_PLATFORM) {
+            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+            ms->fd = open_hw(path);
+    }
+    else 
+#endif
+    if (pEnt->location.type == BUS_PCI) {
+        ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+        if (ms->PciInfo) {
+            BusID = malloc(64);
+            sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
-	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	        ms->PciInfo->dev, ms->PciInfo->func
+                    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+                    ms->PciInfo->dev, ms->PciInfo->func
 #else
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+                    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+                    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+                    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
 #endif
-	    );
-
-       ms->fd = drmOpen(NULL, BusID);
+                );
+        }
+        ms->fd = drmOpen(NULL, BusID);
     } else {
-       devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
-       ms->fd = open_hw(devicename);
+        devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
+        ms->fd = open_hw(devicename);
     }
     if (ms->fd < 0)
 	return FALSE;
commit 709dbc68cdea9d282ba318c1cbc76614e98f41c4
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 25 15:38:34 2012 +1000

    modesetting: fix warning about close being undefined.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 185bfe9..9ee553e 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <unistd.h>
 #include "xf86str.h"
 #include "X11/Xatom.h"
 #include "micmap.h"
commit 71b86ea8dd69f21d090edd4f61698ad11b952d5e
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 25 15:33:52 2012 +1000

    modesetting: drop useless xf86PciInfo include
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index ad817c4..8c3f4a4 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -38,7 +38,6 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 #include "mipointer.h"
 #include "micmap.h"
commit cf196efa05bbefdeb43f6e6bcc5f6d9080fea715
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Jun 22 15:24:43 2012 +0100

    modesetting 0.4.0: bump configure.ac
commit 30ab80ef5421fea9d9dd0779aa138892ff62bd6e
Author: Dave Airlie <airlied at gmail.com>
Date:   Fri Jun 22 15:26:28 2012 +0100

    modesetting: pci probing requires interface version 1.4
    
    Set the drm interface version to 1.4 so we get the bus id correctly.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index f0529f5..ad817c4 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -215,10 +215,21 @@ static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
 {
     int fd = open_hw(dev);
     char *id, *devid;
+    drmSetVersion sv;
 
     if (fd == -1)
 	return FALSE;
 
+    sv.drm_di_major = 1;
+    sv.drm_di_minor = 4;
+    sv.drm_dd_major = -1;
+    sv.drm_dd_minor = -1;
+    if (drmSetInterfaceVersion(fd, &sv)) {
+        close(fd);
+        return FALSE;
+    }
+
+
     id = drmGetBusid(fd);
     devid = ms_DRICreatePCIBusID(pdev);
     close(fd);
commit ec79187d9a23ba30eafc7ba225049559e6bcb78d
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 14:41:18 2012 +0100

    modesetting: workaround kernel bug reporting 0x0 as valid mins
    
    It reports these but then you can't create a 0 sized bo.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index c0cc06b..185bfe9 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1379,6 +1379,10 @@ void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth,
 	if (!mode_res)
 		return;
 
+	if (mode_res->min_width == 0)
+		mode_res->min_width = 1;
+	if (mode_res->min_height == 0)
+		mode_res->min_height = 1;
 	/*create a bo */
 	bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32);
 	if (!bo) {
commit e07c945ab992b1b1acdd9f5554e0688f744e4769
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Jun 1 12:34:42 2012 +0100

    modesetting: bump to latest X server compat api.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
index 1bb7724..df783a8 100644
--- a/hw/xfree86/drivers/modesetting/compat-api.h
+++ b/hw/xfree86/drivers/modesetting/compat-api.h
@@ -38,4 +38,57 @@
 #define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
 #endif
 
+#ifndef XF86_SCRN_INTERFACE
+
+#define SCRN_ARG_TYPE int
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = xf86Screens[(arg1)]
+
+#define SCREEN_ARG_TYPE int
+#define SCREEN_PTR(arg1) ScreenPtr pScreen = screenInfo.screens[(arg1)]
+
+#define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask
+
+#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen
+#define CLOSE_SCREEN_ARGS scrnIndex, pScreen
+
+#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
+
+#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
+
+#define FREE_SCREEN_ARGS_DECL int arg, int flags
+
+#define VT_FUNC_ARGS_DECL int arg, int flags
+#define VT_FUNC_ARGS pScrn->scrnIndex, 0
+
+#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
+#else
+#define SCRN_ARG_TYPE ScrnInfoPtr
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = (arg1)
+
+#define SCREEN_ARG_TYPE ScreenPtr
+#define SCREEN_PTR(arg1) ScreenPtr pScreen = (arg1)
+
+#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask
+
+#define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen
+#define CLOSE_SCREEN_ARGS pScreen
+
+#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
+#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
+
+#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
+
+#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
+#define VT_FUNC_ARGS pScrn
+
+#define XF86_ENABLEDISABLEFB_ARG(x) (x)
+
+#endif
+
 #endif
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 61e0615..f0529f5 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -60,18 +60,17 @@
 #include "compat-api.h"
 #include "driver.h"
 
-static void AdjustFrame(int scrnIndex, int x, int y, int flags);
-static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
-static Bool EnterVT(int scrnIndex, int flags);
+static void AdjustFrame(ADJUST_FRAME_ARGS_DECL);
+static Bool CloseScreen(CLOSE_SCREEN_ARGS_DECL);
+static Bool EnterVT(VT_FUNC_ARGS_DECL);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
-static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
+static ModeStatus ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose,
 			    int flags);
-static void FreeScreen(int scrnIndex, int flags);
-static void LeaveVT(int scrnIndex, int flags);
-static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
-static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
-		       char **argv);
+static void FreeScreen(FREE_SCREEN_ARGS_DECL);
+static void LeaveVT(VT_FUNC_ARGS_DECL);
+static Bool SwitchMode(SWITCH_MODE_ARGS_DECL);
+static Bool ScreenInit(SCREEN_INIT_ARGS_DECL);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
 
 static Bool Probe(DriverPtr drv, int flags);
@@ -389,14 +388,13 @@ static void dispatch_dirty(ScreenPtr pScreen)
     }
 }
 
-static void msBlockHandler(int i, pointer blockData, pointer pTimeout,
-			   pointer pReadmask)
+static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 {
-    ScreenPtr pScreen = screenInfo.screens[i];
+    SCREEN_PTR(arg);
     modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
     pScreen->BlockHandler = ms->BlockHandler;
-    pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
+    pScreen->BlockHandler(BLOCKHANDLER_ARGS);
     pScreen->BlockHandler = msBlockHandler;
     if (ms->dirty_enabled)
 	dispatch_dirty(pScreen);
@@ -658,7 +656,7 @@ msShadowInit(ScreenPtr pScreen)
 }
 
 static Bool
-ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
+ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -722,7 +720,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     fbPictureInit(pScreen, NULL, 0);
 
     if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
-	xf86DrvMsg(scrnIndex, X_ERROR,
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		   "shadow fb init failed\n");
 	return FALSE;
     }
@@ -765,13 +763,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-    return EnterVT(scrnIndex, 1);
+    return EnterVT(VT_FUNC_ARGS);
 }
 
 static void
-AdjustFrame(int scrnIndex, int x, int y, int flags)
+AdjustFrame(ADJUST_FRAME_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
     xf86OutputPtr output = config->output[config->compat_output];
     xf86CrtcPtr crtc = output->crtc;
@@ -785,15 +783,16 @@ AdjustFrame(int scrnIndex, int x, int y, int flags)
 }
 
 static void
-FreeScreen(int scrnIndex, int flags)
+FreeScreen(FREE_SCREEN_ARGS_DECL)
 {
-    FreeRec(xf86Screens[scrnIndex]);
+    SCRN_INFO_PTR(arg);
+    FreeRec(pScrn);
 }
 
 static void
-LeaveVT(int scrnIndex, int flags)
+LeaveVT(VT_FUNC_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
     xf86_hide_cursors(pScrn);
 
@@ -806,9 +805,9 @@ LeaveVT(int scrnIndex, int flags)
  * This gets called when gaining control of the VT, and from ScreenInit().
  */
 static Bool
-EnterVT(int scrnIndex, int flags)
+EnterVT(VT_FUNC_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     pScrn->vtSema = TRUE;
@@ -825,17 +824,17 @@ EnterVT(int scrnIndex, int flags)
 }
 
 static Bool
-SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+SwitchMode(SWITCH_MODE_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
 
     return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
 }
 
 static Bool
-CloseScreen(int scrnIndex, ScreenPtr pScreen)
+CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     if (ms->damage) {
@@ -854,7 +853,7 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     drmmode_free_bos(pScrn, &ms->drmmode);
 
     if (pScrn->vtSema) {
-	LeaveVT(scrnIndex, 0);
+        LeaveVT(VT_FUNC_ARGS);
     }
 
     pScreen->CreateScreenResources = ms->createScreenResources;
@@ -862,11 +861,11 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
-    return (*pScreen->CloseScreen) (scrnIndex, pScreen);
+    return (*pScreen->CloseScreen) (CLOSE_SCREEN_ARGS);
 }
 
 static ModeStatus
-ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
 {
     return MODE_OK;
 }
commit 1c01090f6485cb82c2511fb461e66ff15a097358
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 23 11:31:39 2012 +0100

    modesetting: fix make distcheck
    
    add missing compat header file.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 68a63fa..3cc4624 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -32,6 +32,7 @@ modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
+	 compat-api.h \
 	 driver.c \
 	 driver.h \
 	 drmmode_display.c \
commit ef47a1b3bfec33d4031af2e01bdd46d634be2f51
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 23 11:21:55 2012 +0100

    modesetting: convert to new scrn conversion APIs.
    
    Generated with util/modular/x-driver-screen-scrn-conv.sh
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index ce4cdec..61e0615 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -348,7 +348,7 @@ GetRec(ScrnInfoPtr pScrn)
 
 static void dispatch_dirty(ScreenPtr pScreen)
 {
-    ScrnInfoPtr scrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(scrn);
     RegionPtr dirty = DamageRegion(ms->damage);
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
@@ -393,7 +393,7 @@ static void msBlockHandler(int i, pointer blockData, pointer pTimeout,
 			   pointer pReadmask)
 {
     ScreenPtr pScreen = screenInfo.screens[i];
-    modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]);
+    modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
     pScreen->BlockHandler = ms->BlockHandler;
     pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
@@ -586,7 +586,7 @@ static void *
 msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
 	       CARD32 *size, void *closure)
 {
-    ScrnInfoPtr pScrn = xf86Screens[screen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(pScrn);
     int stride;
 
@@ -599,7 +599,7 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap;
     Bool ret;
@@ -660,7 +660,7 @@ msShadowInit(ScreenPtr pScreen)
 static Bool
 ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
     VisualPtr visual;
     int ret;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 22fc66a..c0cc06b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -938,7 +938,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	struct dumb_bo *old_front = NULL;
 	Bool	    ret;
-	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
+	ScreenPtr   screen = xf86ScrnToScreen(scrn);
 	uint32_t    old_fb_id;
 	int	    i, pitch, old_width, old_height, old_pitch;
 	int cpp = (scrn->bitsPerPixel + 7) / 8;
@@ -1229,7 +1229,7 @@ drmmode_handle_uevents(int fd, void *closure)
 	if (!dev)
 		return;
 
-	RRGetInfo(screenInfo.screens[scrn->scrnIndex], TRUE);
+	RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
 	udev_device_unref(dev);
 }
 #endif
commit 3e46d578d8c40c95343278db0a66c931e85247c7
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 23 11:21:39 2012 +0100

    modesetting: add compat header file
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
new file mode 100644
index 0000000..1bb7724
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/compat-api.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Dave Airlie <airlied at redhat.com>
+ */
+
+/* this file provides API compat between server post 1.13 and pre it,
+   it should be reused inside as many drivers as possible */
+#ifndef COMPAT_API_H
+#define COMPAT_API_H
+
+#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
+#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
+#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
+#endif
+
+#ifndef XF86_HAS_SCRN_CONV
+#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
+#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
+#endif
+
+#endif
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index e977150..ce4cdec 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -57,6 +57,7 @@
 #include <pciaccess.h>
 #endif
 
+#include "compat-api.h"
 #include "driver.h"
 
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 71f2e02..22fc66a 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -49,6 +49,7 @@
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 #endif
+#include "compat-api.h"
 
 static struct dumb_bo *dumb_bo_create(int fd,
 			  const unsigned width, const unsigned height,
commit e8da587845978ad66c3b3e2e085fd99c16b5d3c8
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 9 09:33:54 2012 +0100

    bump version to 0.3.0
commit 62543946490e7decae4f6549d83072f004e850d4
Author: Matt Turner <mattst88 at gmail.com>
Date:   Wed May 9 00:26:29 2012 -0400

    configure.ac: remove DRI and RENDER
    
    Driver doesn't support either of these.
    
    Signed-off-by: Matt Turner <mattst88 at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 7dc22b7911ac3d5c131075903e3fbf52c58eac15
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 9 09:32:05 2012 +0100

    modesetting: make sure the pci device corresponds to the drm device
    
    If we get asked to pci open a device with a kms path override,
    make sure they match, otherwise this driver can steal the primary
    device binding for a usb adaptor.
    
    The driver should fallback to the old probe entry point in this case.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 2c9878c..e977150 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -198,6 +198,39 @@ static Bool probe_hw(char *dev)
     return FALSE;
 }
 
+static char *
+ms_DRICreatePCIBusID(const struct pci_device *dev)
+{
+    char *busID;
+
+    if (asprintf(&busID, "pci:%04x:%02x:%02x.%d",
+                 dev->domain, dev->bus, dev->dev, dev->func) == -1)
+        return NULL;
+
+    return busID;
+}
+
+
+static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
+{
+    int fd = open_hw(dev);
+    char *id, *devid;
+
+    if (fd == -1)
+	return FALSE;
+
+    id = drmGetBusid(fd);
+    devid = ms_DRICreatePCIBusID(pdev);
+    close(fd);
+
+    if (!id || !devid)
+	return FALSE;
+
+    if (!strcmp(id, devid))
+	return TRUE;
+
+    return FALSE;
+}
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
 {
@@ -219,7 +252,7 @@ ms_pci_probe(DriverPtr driver,
 						  scrn->entityInstanceList[0]);
 
 	devpath = xf86FindOptionValue(devSection->options, "kmsdev");
-	if (probe_hw(devpath)) {
+	if (probe_hw_pci(devpath, dev)) {
 	    scrn->driverVersion = 1;
 	    scrn->driverName = "modesetting";
 	    scrn->name = "modeset";
commit d063f64b5c8c8c27fca41163c93dbca06a774d1c
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 1 17:12:29 2012 +0100

    modesetting: attempt to work out if we want 24 or 32bpp
    
    the cirrus driver presents certain challenges, and this is a
    workaround, until we can possibly agree some sane interface
    for exposing this information.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index fb4b410..2c9878c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -59,10 +59,6 @@
 
 #include "driver.h"
 
-#ifndef DRM_CAP_DUMB_PREFER_SHADOW
-#define DRM_CAP_DUMB_PREFER_SHADOW 4
-#endif
-
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
 static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
 static Bool EnterVT(int scrnIndex, int flags);
@@ -397,6 +393,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     Bool prefer_shadow = TRUE;
     uint64_t value = 0;
     int ret;
+    int bppflags;
+    int defaultdepth, defaultbpp;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -459,9 +457,16 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (ms->fd < 0)
 	return FALSE;
 
+    ms->drmmode.fd = ms->fd;
+
+    drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
+    if (defaultdepth == 24 && defaultbpp == 24)
+	    bppflags = Support24bppFb;
+    else
+	    bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
+    
     if (!xf86SetDepthBpp
-	(pScrn, 0, 0, 0,
-	 PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
+	(pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags))
 	return FALSE;
 
     switch (pScrn->depth) {
@@ -501,7 +506,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
-    ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
 	goto fail;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 7fa933a..71f2e02 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1355,3 +1355,50 @@ void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 		dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo);
 	}
 }
+
+/* ugly workaround to see if we can create 32bpp */
+void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, int *bpp)
+{
+	drmModeResPtr mode_res;
+	uint64_t value;
+	struct dumb_bo *bo;
+	uint32_t fb_id;
+	int ret;
+
+	/* 16 is fine */
+	ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_PREFERRED_DEPTH, &value);
+	if (!ret && (value == 16 || value == 8)) {
+		*depth = value;
+		*bpp = value;
+		return;
+	}
+
+	*depth = 24;
+	mode_res = drmModeGetResources(drmmode->fd);
+	if (!mode_res)
+		return;
+
+	/*create a bo */
+	bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32);
+	if (!bo) {
+		*bpp = 24;
+		goto out;
+	}
+
+	ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height,
+			    24, 32, bo->pitch, bo->handle, &fb_id);
+
+	if (ret) {
+		*bpp = 24;
+		dumb_bo_destroy(drmmode->fd, bo);
+		goto out;
+	}
+
+	drmModeRmFB(drmmode->fd, fb_id);
+	*bpp = 32;
+
+	dumb_bo_destroy(drmmode->fd, bo);
+out:	
+	drmModeFreeResources(mode_res);
+	return;
+}
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index e83167b..fa280bd 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -103,4 +103,14 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void *drmmode_map_front_bo(drmmode_ptr drmmode);
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp);
+
+#ifndef DRM_CAP_DUMB_PREFERRED_DEPTH
+#define DRM_CAP_DUMB_PREFERRED_DEPTH 3
+#endif
+#ifndef DRM_CAP_DUMB_PREFER_SHADOW
+#define DRM_CAP_DUMB_PREFER_SHADOW 4
+#endif
+
+
 #endif
commit 610f532e6a3d934c473d2d16dff95f582285b2eb
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 1 16:52:18 2012 +0100

    modesetting: move opening kernel device to before setting depth
    
    due to interaction between option handling and set depth, we need
    to what fbdev does to get the device path early.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 827438a..fb4b410 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -437,6 +437,28 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
 
+    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+    if (ms->PciInfo) {
+       BusID = malloc(64);
+       sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	        ms->PciInfo->dev, ms->PciInfo->func
+#else
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	    );
+
+       ms->fd = drmOpen(NULL, BusID);
+    } else {
+       devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
+       ms->fd = open_hw(devicename);
+    }
+    if (ms->fd < 0)
+	return FALSE;
+
     if (!xf86SetDepthBpp
 	(pScrn, 0, 0, 0,
 	 PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
@@ -462,28 +484,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
-    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-    if (ms->PciInfo) {
-       BusID = malloc(64);
-       sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	        ms->PciInfo->dev, ms->PciInfo->func
-#else
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-	    );
-
-       ms->fd = drmOpen(NULL, BusID);
-    } else {
-       devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
-       ms->fd = open_hw(devicename);
-    }
-    if (ms->fd < 0)
-	return FALSE;
-
     if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
 	return FALSE;
     if (!xf86SetDefaultVisual(pScrn, -1))
commit 00c663a3bc76d567ad7edd6d6ef3f7f725b5df3a
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Apr 17 11:50:40 2012 +0100

    modesetting: add set/drop master around VT switch

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 516bf61..827438a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -756,10 +756,12 @@ static void
 LeaveVT(int scrnIndex, int flags)
 {
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-
+    modesettingPtr ms = modesettingPTR(pScrn);
     xf86_hide_cursors(pScrn);
 
     pScrn->vtSema = FALSE;
+
+    drmDropMaster(ms->fd);
 }
 
 /*
@@ -773,6 +775,11 @@ EnterVT(int scrnIndex, int flags)
 
     pScrn->vtSema = TRUE;
 
+    if (drmSetMaster(ms->fd)) {
+        xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "drmSetMaster failed: %s\n",
+                   strerror(errno));
+    }
+
     if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
 	return FALSE;
 
@@ -815,8 +822,6 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     pScreen->CreateScreenResources = ms->createScreenResources;
     pScreen->BlockHandler = ms->BlockHandler;
 
-    drmDropMaster(ms->fd);
-
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
     return (*pScreen->CloseScreen) (scrnIndex, pScreen);
commit 001dec898098e11c569abc20a307b3c2af2e2184
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Apr 17 11:48:03 2012 +0100

    cursor: hide cursors on LeaveVT

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b776ca1..516bf61 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -757,6 +757,8 @@ LeaveVT(int scrnIndex, int flags)
 {
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
+    xf86_hide_cursors(pScrn);
+
     pScrn->vtSema = FALSE;
 }
 
commit d5d5b407436dfdbffcd56bbefecf17d11750dddf
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat Apr 14 19:21:47 2012 +0100

    dirty: check malloc return
    
    Suggested by keithp.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 95d6b90..b776ca1 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -327,7 +327,10 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
-	    
+	
+	if (!clip)
+		return;
+
 	/* XXX no need for copy? */
 	for (i = 0; i < num_cliprects; i++, rect++) {
 	    clip[i].x1 = rect->x1;
commit 6c1b5cb903f2ff9cb915273835c301d6ac255f45
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat Apr 14 15:01:16 2012 +0100

    drop use of alloca, just use malloc/free
    
    Reported-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 87431ff..95d6b90 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -324,7 +324,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
 
     if (num_cliprects) {
-	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
+	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
 	    
@@ -338,6 +338,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
 
 	/* TODO query connector property to see if this is needed */
 	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
+	free(clip);
 	if (ret) {
 	    if (ret == -EINVAL || ret == -ENOSYS) {
 		ms->dirty_enabled = FALSE;
commit 0e8ee1cf4f3377a2916c43527ae0dc6cb07a67ec
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Mar 23 14:54:05 2012 +0000

    modesetting: fix build against older Xext
commit 53204d5c8bd83c957fbdb7d3dc2891118ed7658b
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:25 2012 +0100

    make busID non mandatory
    
    Currently the driver only probes a device when it has a
    busID. The busID is optional so don't depend on it.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7fa2630..87431ff 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -273,32 +273,30 @@ Probe(DriverPtr drv, int flags)
     for (i = 0; i < numDevSections; i++) {
 
 	dev = xf86FindOptionValue(devSections[i]->options,"kmsdev");
-	if (devSections[i]->busID) {
-	    if (probe_hw(dev)) {
-		int entity;
-		entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
-		scrn = xf86ConfigFbEntity(scrn, 0, entity,
-					  NULL, NULL, NULL, NULL);
-	    }
+	if (probe_hw(dev)) {
+	    int entity;
+	    entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
+	    scrn = xf86ConfigFbEntity(scrn, 0, entity,
+				  NULL, NULL, NULL, NULL);
+	}
 
-	    if (scrn) {
-		foundScreen = TRUE;
-		scrn->driverVersion = 1;
-		scrn->driverName = "modesetting";
-		scrn->name = "modesetting";
-		scrn->Probe = Probe;
-		scrn->PreInit = PreInit;
-		scrn->ScreenInit = ScreenInit;
-		scrn->SwitchMode = SwitchMode;
-		scrn->AdjustFrame = AdjustFrame;
-		scrn->EnterVT = EnterVT;
-		scrn->LeaveVT = LeaveVT;
-		scrn->FreeScreen = FreeScreen;
-		scrn->ValidMode = ValidMode;
-
-		xf86DrvMsg(scrn->scrnIndex, X_INFO,
+	if (scrn) {
+	    foundScreen = TRUE;
+	    scrn->driverVersion = 1;
+	    scrn->driverName = "modesetting";
+	    scrn->name = "modesetting";
+	    scrn->Probe = Probe;
+	    scrn->PreInit = PreInit;
+	    scrn->ScreenInit = ScreenInit;
+	    scrn->SwitchMode = SwitchMode;
+	    scrn->AdjustFrame = AdjustFrame;
+	    scrn->EnterVT = EnterVT;
+	    scrn->LeaveVT = LeaveVT;
+	    scrn->FreeScreen = FreeScreen;
+	    scrn->ValidMode = ValidMode;
+
+	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
 			   "using %s\n", dev ? dev : "default device");
-	    }
 	}
     }
 
commit bb7e39c1f2112f5fb7e87baddb114ab164fbc749
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:27 2012 +0100

    do not bail out on non pci devices
    
    To make the driver work on nin PCI devices we shouldn't bail
    out in this case.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 45643a8..7fa2630 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -415,9 +415,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     pScrn->displayWidth = 640;	       /* default it */
 
-    if (ms->pEnt->location.type != BUS_PCI)
-	return FALSE;
-
     /* Allocate an entity private if necessary */
     if (xf86IsEntityShared(pScrn->entityList[0])) {
 	msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
commit 2b6848fcb3f85f9ce18a6de1dc6c3ac047101aa8
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:26 2012 +0100

    Fix non PCI device probing
    
    When no devicename is found in the option then the driver probes
    by PciInfo no matter if it's valid or not. Instead of doing this
    use PciInfo only when it's valid and fall back to the devicename
    otherwise. With devicename probing use open_hw() to fall back
    on the KMSDEVICE environment variable or to the default device.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index dc90e04..45643a8 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -418,8 +418,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (ms->pEnt->location.type != BUS_PCI)
 	return FALSE;
 
-    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-
     /* Allocate an entity private if necessary */
     if (xf86IsEntityShared(pScrn->entityList[0])) {
 	msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
@@ -465,8 +463,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
-    devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
-    if (!devicename) {
+    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+    if (ms->PciInfo) {
        BusID = malloc(64);
        sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
@@ -481,7 +479,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
        ms->fd = drmOpen(NULL, BusID);
     } else {
-       ms->fd = open(devicename, O_RDWR, 0);
+       devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
+       ms->fd = open_hw(devicename);
     }
     if (ms->fd < 0)
 	return FALSE;
commit 456a001e3f7a24f443cf0bad8400d5d600e2ad46
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:24 2012 +0100

    introduce open_hw() function
    
    probe_hw opens the hardware in the order we want it:
    first try devname, if this is NULL then try the KMSDEVICE
    environment variable and as a last fallback use "/dev/dri/card0".
    Instead of implementing the same code again when really opening
    the device move the code to a open_hw() function and let probe_hw
    use it.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 2004434..dc90e04 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -174,7 +174,7 @@ Identify(int flags)
 		      Chipsets);
 }
 
-static Bool probe_hw(char *dev)
+static int open_hw(char *dev)
 {
     int fd;
     if (dev)
@@ -186,13 +186,20 @@ static Bool probe_hw(char *dev)
 	    fd = open(dev,O_RDWR, 0);
 	}
     }
-    if (fd == -1) {
+    if (fd == -1)
 	xf86DrvMsg(-1, X_ERROR,"open %s: %s\n", dev, strerror(errno));
-	return FALSE;
-    }
-    close(fd);
-    return TRUE;
 
+    return fd;
+}
+
+static Bool probe_hw(char *dev)
+{
+    int fd = open_hw(dev);
+    if (fd != -1) {
+        close(fd);
+	return TRUE;
+    }
+    return FALSE;
 }
 
 static const OptionInfoRec *
commit aa6ceaaa843525b2243569de162ed0b17faa7510
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:23 2012 +0100

    fix if() brackets in Probe function
    
    in Probe() the indention shows what's meant but there are no
    brackets. Add them.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index d8bb7b5..2004434 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -274,7 +274,7 @@ Probe(DriverPtr drv, int flags)
 					  NULL, NULL, NULL, NULL);
 	    }
 
-	    if (scrn)
+	    if (scrn) {
 		foundScreen = TRUE;
 		scrn->driverVersion = 1;
 		scrn->driverName = "modesetting";
@@ -291,6 +291,7 @@ Probe(DriverPtr drv, int flags)
 
 		xf86DrvMsg(scrn->scrnIndex, X_INFO,
 			   "using %s\n", dev ? dev : "default device");
+	    }
 	}
     }
 
commit 1349a2b7ab04553c8fddb60534400dea5cbd3cca
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Feb 22 10:07:06 2012 +0000

    xf86-video-modesetting 0.2.0
commit e5648616d222966a95edd6c35807dcf5b91a0f96
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Feb 22 09:59:12 2012 +0000

    modesetting: fix warnings, remove dead code.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index c004721..7fa933a 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -466,12 +466,6 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .destroy = NULL, /* XXX */
 };
 
-int drmmode_get_crtc_id(xf86CrtcPtr crtc)
-{
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	return drmmode_crtc->hw_id;
-}
-
 static void
 drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num)
 {
@@ -877,7 +871,7 @@ out_free_encoders:
 	
 }
 
-uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
+static uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
 {
 	drmmode_output_private_ptr drmmode_output = output->driver_private, clone_drmout;
 	int i;
@@ -1074,15 +1068,6 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 	return TRUE;
 }
 
-void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct dumb_bo *bo)
-{
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-	xf86CrtcPtr crtc = xf86_config->crtc[id];
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-
-	drmmode_crtc->cursor_bo = bo;
-}
-
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags)
 {
 	xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
commit f7724167746d15c0ca32a7f5f95fb594addcddd1
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 16:13:34 2012 -0500

    config: layout and comment the top portion of configure.ac
    
    Reorder statements to be consistent with other modules so things
    are easier to find.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit a0bb835dc7db1ddd0472058a2a05a600ddea3930
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:19 2012 -0500

    config: replace deprecated AC_HELP_STRING with AS_HELP_STRING
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit d56293cae78323b8976859c4461f8809a76a0b03
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:17 2012 -0500

    make: add all warnings according to the platform
    
    The current code only adds -Wall and only for gcc.
    Automake reserves the use of CPPFLAGS for the user to override
    on the command line.
    This also breaks the option --enable-strict-compilation
    
    The variable CWARNFLAGS contains the complete set of warnings
    and is platform sensitive.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 40ebf0a..68a63fa 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -24,7 +24,7 @@
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
-AM_CFLAGS = @XORG_CFLAGS@ @DRM_CFLAGS@ @UDEV_CFLAGS@
+AM_CFLAGS = $(XORG_CFLAGS) $(DRM_CFLAGS) $(UDEV_CFLAGS) $(CWARNFLAGS)
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
 modesetting_drv_la_LDFLAGS = -module -avoid-version
commit fa201fe8299099f7192a4399c9df245efcee3f8a
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:16 2012 -0500

    make: remove empty variable assignment
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index efc4bc0..40ebf0a 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -17,7 +17,6 @@
 #  ADAM JACKSON 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.
-SUBDIRS = 
 
 # this is obnoxious:
 # -module lets us name the module exactly how we want
@@ -37,5 +36,3 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 drmmode_display.c \
 	 drmmode_display.h
-
-EXTRA_DIST =
commit e159fbd8805005bb7a33bf2076fd2cef00e987c6
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:15 2012 -0500

    Remove unneeded AM_PROG_CC_C_CO
    
    There are no objects in subdirs or compiled multiple times
    with different flags.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 70558492376e66b73063e51b128b5bbad14b84f4
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:28 2012 -0500

    Remove redundant AC_PROG_CC
    
    Already covered by XORG_DEFAULT_OPTIONS
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit d4bb99ce754073de090221d98000f609a3891380
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:27 2012 -0500

    Replace obsolete AM_CONFIG_HEADER with AC_CONFIG_HEADERS
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 5c2d152cad66c3f8ed6a4e82c3e6a45269bbb66d
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:26 2012 -0500

    Add missing targets for ChangeLog and INSTALL
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 8673f545cdb465b6e74f1d2fcabe29bc7fa0243d
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:25 2012 -0500

    Remove redundant EXTRA_DIST for the README file.
    
    Autotools know about it, it is always distributed.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 88b637e59a37af8ec6c4c0783504b8f1a49e5595
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:24 2012 -0500

    make: remove redundant AUTOMAKE_OPTIONS
    
    Already covered by AM_INIT_AUTOMAKE([foreign dist-bzip2])
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit a7ea959094e9a8d862637a0ea515f687aaf89d29
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:23 2012 -0500

    Fix typo in .gitignore
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 861e2b444ffb24921e07fdc25ab2679c9b6d2f4d
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:22 2012 -0500

    man: missing AM_V_GEN and hard-coded sed command name
    
    Let's use the common xorg makefile for all drivers.
    This ensures no new problems are introduced.
    Improvements are welcome and to be applied to all drivers.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 453bbe5b442a9c21d7c22437545e487e2993ceb7
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:21 2012 -0500

    Add contact information to the README file
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit dd1d7e3519ea2f148be83ef7ab0b228da95ff9c3
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:20 2012 -0500

    Fill the COPYING file with license text
    
    This reflects the copyright license text in the source code
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING
index 7f33cbf..9508e25 100644
--- a/hw/xfree86/drivers/modesetting/COPYING
+++ b/hw/xfree86/drivers/modesetting/COPYING
@@ -1,12 +1,44 @@
-This is a stub file.  This package has not yet had its complete licensing
-information compiled.  Please see the individual source files for details on
-your rights to use and modify this software.
+Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+Copyright 2011 Dave Airlie
+All Rights Reserved.
 
-Please submit updated COPYING files to the Xorg bugzilla:
+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, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
 
-https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
 
-All licensing questions regarding this software should be directed at the
-Xorg mailing list:
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-http://lists.freedesktop.org/mailman/listinfo/xorg
+Copyright © 2007 Red Hat, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
commit b0e12e250d4b3438fb3306155a7bbff3e2d7f9b7
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 11:08:40 2012 +0000

    modesetting: disable dirty updates for ENOSYS
    
    the kernel can also return ENOSYS for this to say its not used.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8703b0b..d8bb7b5 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -333,7 +333,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	/* TODO query connector property to see if this is needed */
 	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
 	if (ret) {
-	    if (ret == -EINVAL) {
+	    if (ret == -EINVAL || ret == -ENOSYS) {
 		ms->dirty_enabled = FALSE;
 		DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
 		DamageDestroy(ms->damage);
commit c5529d68c5b01cf0f36d8f2ce3694a7a0f3333da
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 11:05:59 2012 +0000

    modesetting: fix shadow resizing.
    
    if we hotplugged and output, the shadow got disabled by accident.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index caa9f44..c004721 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -984,8 +984,21 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	if (!new_pixels)
 		goto fail;
 
-	screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
-				   pitch, new_pixels);
+	if (!drmmode->shadow_enable)
+		screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+					   pitch, new_pixels);
+	else {
+		void *new_shadow;
+		uint32_t size = scrn->displayWidth * scrn->virtualY *
+			((scrn->bitsPerPixel + 7) >> 3);
+		new_shadow = calloc(1, size);
+		if (new_shadow == NULL)
+			goto fail;
+		free(drmmode->shadow_fb);
+		drmmode->shadow_fb = new_shadow;
+		screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+					   pitch, drmmode->shadow_fb);
+	}
 
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0)
 	scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr;
commit f3b9e52b29e8b8c4b12bc2ce290ab44e88750ad9
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 11:00:56 2012 +0000

    modesetting: move shadow stuff to other structure
    
    we need this for resize to work properly.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b66f0d7..8703b0b 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -492,9 +492,9 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	prefer_shadow = !!value;
     }
 
-    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
+    ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->shadow_enable ? "YES" : "NO");
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
@@ -527,7 +527,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
-    if (ms->shadow_enable) {
+    if (ms->drmmode.shadow_enable) {
 	if (!xf86LoadSubModule(pScrn, "shadow")) {
 	    return FALSE;
 	}
@@ -577,13 +577,13 @@ CreateScreenResources(ScreenPtr pScreen)
 
     rootPixmap = pScreen->GetScreenPixmap(pScreen);
 
-    if (ms->shadow_enable)
-	pixels = ms->shadow_fb;
+    if (ms->drmmode.shadow_enable)
+	pixels = ms->drmmode.shadow_fb;
     
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
 	FatalError("Couldn't adjust screen pixmap\n");
 
-    if (ms->shadow_enable) {
+    if (ms->drmmode.shadow_enable) {
 	if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(),
 		       msShadowWindow, 0, 0))
 	    return FALSE;
@@ -634,11 +634,11 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
 	return FALSE;
 
-    if (ms->shadow_enable) {
-	ms->shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY *
+    if (ms->drmmode.shadow_enable) {
+	ms->drmmode.shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY *
 			       ((pScrn->bitsPerPixel + 7) >> 3));
-	if (!ms->shadow_fb)
-	    ms->shadow_enable = FALSE;
+	if (!ms->drmmode.shadow_fb)
+	    ms->drmmode.shadow_enable = FALSE;
     }	
     
     miClearVisualTypes();
@@ -677,7 +677,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     fbPictureInit(pScreen, NULL, 0);
 
-    if (ms->shadow_enable && !msShadowInit(pScreen)) {
+    if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
 	xf86DrvMsg(scrnIndex, X_ERROR,
 		   "shadow fb init failed\n");
 	return FALSE;
@@ -791,10 +791,10 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 	ms->damage = NULL;
     }
 
-    if (ms->shadow_enable) {
+    if (ms->drmmode.shadow_enable) {
 	shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
-	free(ms->shadow_fb);
-	ms->shadow_fb = NULL;
+	free(ms->drmmode.shadow_fb);
+	ms->drmmode.shadow_fb = NULL;
     }
     drmmode_uevent_fini(pScrn, &ms->drmmode);
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 2e51089..79561c8 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -75,8 +75,7 @@ typedef struct _modesettingRec
 
     DamagePtr damage;
     Bool dirty_enabled;
-    Bool shadow_enable;
-    void *shadow_fb;
+
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 7ede159..e83167b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -54,6 +54,10 @@ typedef struct {
     drmEventContext event_context;
     struct dumb_bo *front_bo;
     Bool sw_cursor;
+
+    Bool shadow_enable;
+    void *shadow_fb;
+
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
commit eb44a004b7230321ce6837ef44610153b1d2017b
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 10:54:36 2012 +0000

    modesetting: fix stride if kernel modifies it.
    
    If the kernel aligns things use its values instead.
    
    fixes output on nouveau here.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 57ac521..caa9f44 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -946,7 +946,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
 	uint32_t    old_fb_id;
 	int	    i, pitch, old_width, old_height, old_pitch;
-	int cpp = (scrn->bitsPerPixel + 1) / 8;
+	int cpp = (scrn->bitsPerPixel + 7) / 8;
 	PixmapPtr ppix = screen->GetScreenPixmap(screen);
 	void *new_pixels;
 
@@ -1287,16 +1287,17 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	int width;
 	int height;
-	int bpp;
+	int bpp = pScrn->bitsPerPixel;
 	int i;
+	int cpp = (bpp + 7) / 8;
 
 	width = pScrn->virtualX;
 	height = pScrn->virtualY;
-	bpp = pScrn->bitsPerPixel;
+
 	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
 	if (!drmmode->front_bo)
 		return FALSE;
-
+	pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
 
 	width = height = 64;
 	bpp = 32;
commit 2150cbda8c75d348f39926bbc23d3e4ca9b42c88
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 10:54:21 2012 +0000

    shadowfb: dump shadowfb state at startup

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8af9a9f..b66f0d7 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -494,6 +494,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->shadow_enable ? "YES" : "NO");
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
commit 86080a5f7a589e55a485c42bab47c6c8ff6428c1
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 16 19:41:40 2012 +0000

    use a cap to decide if shadow is preferred or not.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7ce1ac1..8af9a9f 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -59,6 +59,10 @@
 
 #include "driver.h"
 
+#ifndef DRM_CAP_DUMB_PREFER_SHADOW
+#define DRM_CAP_DUMB_PREFER_SHADOW 4
+#endif
+
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
 static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
 static Bool EnterVT(int scrnIndex, int flags);
@@ -380,6 +384,9 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
     char *BusID, *devicename;
+    Bool prefer_shadow = TRUE;
+    uint64_t value = 0;
+    int ret;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -480,7 +487,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	ms->drmmode.sw_cursor = TRUE;
     }
 
-    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE);
+    ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value);
+    if (!ret) {
+	prefer_shadow = !!value;
+    }
+
+    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
commit fc5f39acd49d023a82ab05fffde1b423b697753c
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 16 19:41:30 2012 +0000

    cleanup dumb cap fetch

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ec39967..57ac521 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1028,15 +1028,13 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
 	int i, num_dvi = 0, num_hdmi = 0;
 	int ret;
+	uint64_t value = 0;
 
 	/* check for dumb capability */
-	{
-		uint64_t value = 0;
-		ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
-		if (ret > 0 || value != 1) {
-			xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n");
-			return FALSE;
-		}
+	ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
+	if (ret > 0 || value != 1) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n");
+		return FALSE;
 	}
 
 	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
commit d94b3eaba9a33d0d78ed2d9acbc33394f40fdc2e
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Nov 14 11:22:44 2011 +0000

    modesetting: add cursor fallback if kernel rejects cursor.
    
    If the kernel rejects a cursor, cause a fallback, this isn't 100% as
    we can lose the initial cursor, but it works fine once wm starts.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 69a5fe0..7ce1ac1 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -477,7 +477,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
 
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
-	ms->SWCursor = TRUE;
+	ms->drmmode.sw_cursor = TRUE;
     }
 
     ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE);
@@ -681,7 +681,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
     /* Need to extend HWcursor support to handle mask interleave */
-    if (!ms->SWCursor)
+    if (!ms->drmmode.sw_cursor)
 	xf86_cursors_init(pScreen, 64, 64,
 			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
 			  HARDWARE_CURSOR_ARGB);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index dcf3eb3..ec39967 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -402,12 +402,23 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	int i;
 	uint32_t *ptr;
-
+	uint32_t handle = drmmode_crtc->cursor_bo->handle;
+	int ret;
 	/* cursor should be mapped already */
 	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
 
 	for (i = 0; i < 64 * 64; i++)
 		ptr[i] = image[i];// cpu_to_le32(image[i]);
+
+	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	if (ret) {
+		xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+		xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+		
+		cursor_info->MaxWidth = cursor_info->MaxHeight = 0;
+		drmmode_crtc->drmmode->sw_cursor = TRUE;
+		/* fallback to swcursor */
+	}
 }
 
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 845207a..7ede159 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -53,6 +53,7 @@ typedef struct {
 #endif
     drmEventContext event_context;
     struct dumb_bo *front_bo;
+    Bool sw_cursor;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
commit 594b3c4d6f6f748e08baffc4bc1c3ffad9b0d9cf
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 16 19:31:33 2012 +0000

    fix some whitespace

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 03aa027..69a5fe0 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -471,9 +471,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (ms->fd < 0)
 	return FALSE;
 
-
-
-
     if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
 	return FALSE;
     if (!xf86SetDefaultVisual(pScrn, -1))
commit 2e297978c928c571cf0a80e8d38423089014f07e
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Oct 5 15:12:43 2011 +0100

    fixup device open
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7060d37..03aa027 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -379,7 +379,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    char *BusID;
+    char *BusID, *devicename;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -421,22 +421,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	}
     }
 
-    BusID = malloc(64);
-    sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	    ms->PciInfo->dev, ms->PciInfo->func
-#else
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-	);
-
-    ms->fd = drmOpen(NULL, BusID);
-    if (ms->fd < 0)
-	return FALSE;
-
     pScrn->monitor = pScrn->confScreen->monitor;
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
@@ -459,11 +443,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     }
     xf86PrintDepthBpp(pScrn);
 
-    if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
-	return FALSE;
-    if (!xf86SetDefaultVisual(pScrn, -1))
-	return FALSE;
-
     /* Process the options */
     xf86CollectOptions(pScrn, NULL);
     if (!(ms->Options = malloc(sizeof(Options))))
@@ -471,6 +450,35 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
+    devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
+    if (!devicename) {
+       BusID = malloc(64);
+       sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	        ms->PciInfo->dev, ms->PciInfo->func
+#else
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	    );
+
+       ms->fd = drmOpen(NULL, BusID);
+    } else {
+       ms->fd = open(devicename, O_RDWR, 0);
+    }
+    if (ms->fd < 0)
+	return FALSE;
+
+
+
+
+    if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
+	return FALSE;
+    if (!xf86SetDefaultVisual(pScrn, -1))
+	return FALSE;
+
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
 	ms->SWCursor = TRUE;
     }
commit f47f6b6a53d414f28374391964c2930427d28f46
Author: James Simmons <jsimmons at infradead.org>
Date:   Thu Nov 3 13:20:18 2011 +0000

    don't map cursors in sw cursor mode

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7df587e..7060d37 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -551,7 +551,8 @@ CreateScreenResources(ScreenPtr pScreen)
 
     drmmode_uevent_init(pScrn, &ms->drmmode);
 
-    drmmode_map_cursor_bos(pScrn, &ms->drmmode);
+    if (!ms->SWCursor)
+        drmmode_map_cursor_bos(pScrn, &ms->drmmode);
     pixels = drmmode_map_front_bo(&ms->drmmode);
     if (!pixels)
 	return FALSE;
commit d4eebe5217a89de196c1933e1fe4d37e22d59c6b
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Nov 3 13:18:46 2011 +0000

    configure: don't require xvmc.
    
    Not needed in here
commit 6f581e3fde7ddc943c04f274e01735beb358b7f9
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Oct 3 16:09:12 2011 +0100

    fix fb_id for dirty reporting

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index bde690c..7df587e 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -327,7 +327,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	}
 
 	/* TODO query connector property to see if this is needed */
-	ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects);
+	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
 	if (ret) {
 	    if (ret == -EINVAL) {
 		ms->dirty_enabled = FALSE;
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 494ca0c..2e51089 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -46,7 +46,6 @@ typedef struct
 typedef struct _modesettingRec
 {
     int fd;
-    unsigned int fb_id;
 
     EntPtr entityPrivate;
 
commit 79959b734702486971447a11b2e4181463fda3bf
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Oct 3 11:35:39 2011 +0100

    fix make distcheck

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 4337977..efc4bc0 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -35,6 +35,7 @@ modesetting_drv_ladir = @moduledir@/drivers
 modesetting_drv_la_SOURCES = \
 	 driver.c \
 	 driver.h \
-	 drmmode_display.c
+	 drmmode_display.c \
+	 drmmode_display.h
 
 EXTRA_DIST =
commit cb65ec6b58daf9a1afc40c8693fa0632f8cf0585
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 16:06:52 2011 +0100

    check drm support dumb buffer capability

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 375170f..dcf3eb3 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1016,6 +1016,17 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
 Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
 	int i, num_dvi = 0, num_hdmi = 0;
+	int ret;
+
+	/* check for dumb capability */
+	{
+		uint64_t value = 0;
+		ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
+		if (ret > 0 || value != 1) {
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n");
+			return FALSE;
+		}
+	}
 
 	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
 
commit 6ccd13a2d7d78db2d5bd3fafb00f78d2ceb11741
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 16:00:50 2011 +0100

    add initial man page

diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man
index e69de29..34baa9c 100644
--- a/hw/xfree86/drivers/modesetting/modesetting.man
+++ b/hw/xfree86/drivers/modesetting/modesetting.man
@@ -0,0 +1,54 @@
+.\" shorthand for double quote that works everywhere.
+.ds q \N'34'
+.TH MODESETTING __drivermansuffix__ __vendorversion__
+.SH NAME
+modesetting \- video driver for framebuffer device
+.SH SYNOPSIS
+.nf
+.B "Section \*qDevice\*q"
+.BI "  Identifier \*q"  devname \*q
+.B  "  Driver \*qmodesetting\*q"
+.BI "  BusID  \*qpci:" bus : dev : func \*q
+\ \ ...
+.B EndSection
+.fi
+.SH DESCRIPTION
+.B modesetting
+is an __xservername__ driver for KMS devices.  This is a non-accelerated
+driver, the following framebuffer depths are supported: 8, 15, 16, 24.
+All visual types are supported for depth 8, and TrueColor visual is
+supported for the other depths.  RandR 1.2 is supported.
+.SH SUPPORTED HARDWARE
+The 
+.B modesetting
+driver supports all hardware where a KMS driver is available.
+modesetting uses the Linux DRM KMS ioctls and dumb object create/map.
+.SH CONFIGURATION DETAILS
+Please refer to __xconfigfile__(__filemansuffix__) for general configuration
+details.  This section only covers configuration details specific to
+this driver.
+.PP
+For this driver it is not required to specify modes in the screen 
+section of the config file.  The
+.B modesetting
+driver can pick up the currently used video mode from the kernel
+driver and will use it if there are no video modes configured.
+.PP
+For PCI boards you might have to add a BusID line to the Device
+section.  See above for a sample line.
+.PP
+The following driver 
+.B Options
+are supported:
+.TP
+.BI "Option \*qkmsdev\*q \*q" string \*q
+The framebuffer device to use. Default: /dev/dri/card0.
+.TP
+.BI "Option \*qShadowFB\*q \*q" boolean \*q
+Enable or disable use of the shadow framebuffer layer.  Default: on.
+.TP
+.SH "SEE ALSO"
+__xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), Xserver(__appmansuffix__),
+X(__miscmansuffix__)
+.SH AUTHORS
+Authors include: Dave Airlie
commit 1f37991dec98073d5dfbf0c30213f838999bd9da
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 15:55:36 2011 +0100

    add shadowfb support, default to on.
    
    we should probably expose a bit from kernel to say if shadow is preferred
    or wasteful.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 1192878..bde690c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -49,6 +49,7 @@
 #include "xf86Crtc.h"
 #include "miscstruct.h"
 #include "dixstruct.h"
+#include "shadow.h"
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
 #include <xorg-server.h>
@@ -110,11 +111,13 @@ typedef enum
 {
     OPTION_SW_CURSOR,
     OPTION_DEVICE_PATH,
+    OPTION_SHADOW_FB,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE },
+    {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -472,6 +475,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	ms->SWCursor = TRUE;
     }
 
+    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE);
+
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
@@ -504,11 +509,31 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
+    if (ms->shadow_enable) {
+	if (!xf86LoadSubModule(pScrn, "shadow")) {
+	    return FALSE;
+	}
+    }
+
     return TRUE;
     fail:
     return FALSE;
 }
 
+static void *
+msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
+	       CARD32 *size, void *closure)
+{
+    ScrnInfoPtr pScrn = xf86Screens[screen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    int stride;
+
+    stride = (pScrn->displayWidth * pScrn->bitsPerPixel) / 8;
+    *size = stride;
+
+    return ((uint8_t *)ms->drmmode.front_bo->ptr + row * stride + offset);
+}
+
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
@@ -532,9 +557,19 @@ CreateScreenResources(ScreenPtr pScreen)
 	return FALSE;
 
     rootPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    if (ms->shadow_enable)
+	pixels = ms->shadow_fb;
+    
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
 	FatalError("Couldn't adjust screen pixmap\n");
 
+    if (ms->shadow_enable) {
+	if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(),
+		       msShadowWindow, 0, 0))
+	    return FALSE;
+    }
+
     ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
                               pScreen, rootPixmap);
 
@@ -551,6 +586,15 @@ CreateScreenResources(ScreenPtr pScreen)
 }
 
 static Bool
+msShadowInit(ScreenPtr pScreen)
+{
+    if (!shadowSetup(pScreen)) {
+	return FALSE;
+    }
+    return TRUE;
+}
+
+static Bool
 ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -571,6 +615,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
 	return FALSE;
 
+    if (ms->shadow_enable) {
+	ms->shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY *
+			       ((pScrn->bitsPerPixel + 7) >> 3));
+	if (!ms->shadow_fb)
+	    ms->shadow_enable = FALSE;
+    }	
+    
     miClearVisualTypes();
 
     if (!miSetVisualTypes(pScrn->depth,
@@ -607,6 +658,12 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     fbPictureInit(pScreen, NULL, 0);
 
+    if (ms->shadow_enable && !msShadowInit(pScreen)) {
+	xf86DrvMsg(scrnIndex, X_ERROR,
+		   "shadow fb init failed\n");
+	return FALSE;
+    }
+  
     ms->createScreenResources = pScreen->CreateScreenResources;
     pScreen->CreateScreenResources = CreateScreenResources;
 
@@ -715,6 +772,11 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 	ms->damage = NULL;
     }
 
+    if (ms->shadow_enable) {
+	shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
+	free(ms->shadow_fb);
+	ms->shadow_fb = NULL;
+    }
     drmmode_uevent_fini(pScrn, &ms->drmmode);
 
     drmmode_free_bos(pScrn, &ms->drmmode);
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index beb5f8d..494ca0c 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -76,6 +76,8 @@ typedef struct _modesettingRec
 
     DamagePtr damage;
     Bool dirty_enabled;
+    Bool shadow_enable;
+    void *shadow_fb;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
commit 0b5e574dff230c7879eb9655bb7252553bbace50
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 15:55:24 2011 +0100

    remove unused debug

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index d1348c9..1192878 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -558,7 +558,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     VisualPtr visual;
     int ret;
 
-    ErrorF("ms is %p\n", ms);
     pScrn->pScreen = pScreen;
 
     ret = drmSetMaster(ms->fd);
commit d686130c17126d86db55aae6b65b12d8bcf6a098
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 14:13:58 2011 +0100

    add -Wall, cleanup warnings

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b56db94..d1348c9 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -33,6 +33,7 @@
 #include "config.h"
 #endif
 
+#include <unistd.h>
 #include <fcntl.h>
 #include "xf86.h"
 #include "xf86_OSproc.h"
@@ -199,8 +200,6 @@ ms_pci_probe(DriverPtr driver,
 	     int entity_num, struct pci_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
-    EntityInfoPtr entity;
-    DevUnion *private;
 
     scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
 			       NULL, NULL, NULL, NULL, NULL);
@@ -239,14 +238,11 @@ ms_pci_probe(DriverPtr driver,
 static Bool
 Probe(DriverPtr drv, int flags)
 {
-    int i, numUsed, numDevSections, *usedChips;
-    EntPtr msEnt = NULL;
-    DevUnion *pPriv;
+    int i, numDevSections;
     GDevPtr *devSections;
     Bool foundScreen = FALSE;
-    int numDevs;
     char *dev;
-    ScrnInfoPtr scrn;
+    ScrnInfoPtr scrn = NULL;
 
     /* For now, just bail out for PROBE_DETECT. */
     if (flags & PROBE_DETECT)
@@ -268,7 +264,7 @@ Probe(DriverPtr drv, int flags)
 		int entity;
 		entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
 		scrn = xf86ConfigFbEntity(scrn, 0, entity,
-					   NULL, NULL, NULL, NULL);
+					  NULL, NULL, NULL, NULL);
 	    }
 
 	    if (scrn)
@@ -376,17 +372,11 @@ FreeRec(ScrnInfoPtr pScrn)
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
-    xf86CrtcConfigPtr xf86_config;
     modesettingPtr ms;
-    MessageType from = X_PROBED;
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
     char *BusID;
-    int i;
-    char *s;
-    int num_pipe;
-    int max_width, max_height;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -526,7 +516,6 @@ CreateScreenResources(ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap;
     Bool ret;
-    int flags;
     void *pixels;
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
@@ -567,9 +556,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
     VisualPtr visual;
-    unsigned long sys_mem;
-    int c;
-    MessageType from;
     int ret;
 
     ErrorF("ms is %p\n", ms);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4f25bbe..375170f 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -108,11 +108,13 @@ static int dumb_bo_map(int fd, struct dumb_bo *bo)
 	return 0;
 }
 
+#if 0
 static int dumb_bo_unmap(int fd, struct dumb_bo *bo)
 {
 	bo->map_count--;
 	return 0;
 }
+#endif
 
 static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
 {
@@ -260,7 +262,6 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		     Rotation rotation, int x, int y)
 {
 	ScrnInfoPtr pScrn = crtc->scrn;
-	//	RADEONInfoPtr info = RADEONPTR(pScrn);
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
@@ -273,11 +274,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 	int i;
 	int fb_id;
 	drmModeModeInfo kmode;
-	int pitch;
-	uint32_t tiling_flags = 0;
 	int height;
 
-	pitch = pScrn->displayWidth;
 	height = pScrn->virtualY;
 
 	if (drmmode->fb_id == 0) {
@@ -795,7 +793,6 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	drmModePropertyPtr props;
 	char name[32];
 	int i;
-	const char *s;
 
 	koutput = drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]);
 	if (!koutput)
@@ -938,10 +935,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
 	uint32_t    old_fb_id;
 	int	    i, pitch, old_width, old_height, old_pitch;
-	int screen_size;
 	int cpp = (scrn->bitsPerPixel + 1) / 8;
-	struct dumb_bo *front_bo;
-	uint32_t tiling_flags = 0;
 	PixmapPtr ppix = screen->GetScreenPixmap(screen);
 	void *new_pixels;
 
@@ -949,12 +943,12 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 		return TRUE;
 
 	xf86DrvMsg(scrn->scrnIndex, X_INFO,
-		   "Allocate new frame buffer %dx%d stride %d\n",
-		   width, height, pitch / cpp);
+		   "Allocate new frame buffer %dx%d stride\n",
+		   width, height);
 
 	old_width = scrn->virtualX;
 	old_height = scrn->virtualY;
-	old_pitch = scrn->displayWidth;
+	old_pitch = drmmode->front_bo->pitch;
 	old_fb_id = drmmode->fb_id;
 	old_front = drmmode->front_bo;
 
@@ -1009,7 +1003,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	drmmode->front_bo = old_front;
 	scrn->virtualX = old_width;
 	scrn->virtualY = old_height;
-	scrn->displayWidth = old_pitch;
+	scrn->displayWidth = old_pitch / cpp;
 	drmmode->fb_id = old_fb_id;
 
 	return FALSE;
@@ -1021,11 +1015,9 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
 
 Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
-	xf86CrtcConfigPtr xf86_config;
 	int i, num_dvi = 0, num_hdmi = 0;
 
 	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
-	xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 
 	drmmode->scrn = pScrn;
 	drmmode->cpp = cpp;
commit a4f6e661b5d6662c413c86eeefb4affddd65c562
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 14:05:43 2011 +0100

    fix server recycling

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index bc80e30..b56db94 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -570,31 +570,17 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     unsigned long sys_mem;
     int c;
     MessageType from;
+    int ret;
 
-    /* deal with server regeneration */
-    if (ms->fd < 0) {
-	char *BusID;
-
-	BusID = malloc(64);
-	sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-		((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-		ms->PciInfo->dev, ms->PciInfo->func
-#else
-		((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-		((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-		((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-	    );
-
-	ms->fd = drmOpen(NULL, BusID);
-
-	if (ms->fd < 0)
-	    return FALSE;
-    }
-
+    ErrorF("ms is %p\n", ms);
     pScrn->pScreen = pScreen;
 
+    ret = drmSetMaster(ms->fd);
+    if (ret) {
+        ErrorF("Unable to set master\n");
+        return FALSE;
+    }
+      
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
@@ -716,7 +702,9 @@ EnterVT(int scrnIndex, int flags)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
-    if (!xf86SetDesiredModes(pScrn))
+    pScrn->vtSema = TRUE;
+
+    if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
 	return FALSE;
 
     return TRUE;
@@ -752,8 +740,8 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 
     pScreen->CreateScreenResources = ms->createScreenResources;
     pScreen->BlockHandler = ms->BlockHandler;
-    drmClose(ms->fd);
-    ms->fd = -1;
+
+    drmDropMaster(ms->fd);
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index d94ce03..4f25bbe 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1329,6 +1329,12 @@ void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	int i;
+
+	if (drmmode->fb_id) {
+		drmModeRmFB(drmmode->fd, drmmode->fb_id);
+		drmmode->fb_id = 0;
+	}
+
 	dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
 	drmmode->front_bo = NULL;
 
commit 7847321138be62b929123b25929a69f0a57aca3f
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:38:26 2011 +0100

    port damage tracking code from st/xorg

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 0aaafd1..bc80e30 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -307,6 +307,58 @@ GetRec(ScrnInfoPtr pScrn)
     return TRUE;
 }
 
+static void dispatch_dirty(ScreenPtr pScreen)
+{
+    ScrnInfoPtr scrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(scrn);
+    RegionPtr dirty = DamageRegion(ms->damage);
+    unsigned num_cliprects = REGION_NUM_RECTS(dirty);
+
+    if (num_cliprects) {
+	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
+	BoxPtr rect = REGION_RECTS(dirty);
+	int i, ret;
+	    
+	/* XXX no need for copy? */
+	for (i = 0; i < num_cliprects; i++, rect++) {
+	    clip[i].x1 = rect->x1;
+	    clip[i].y1 = rect->y1;
+	    clip[i].x2 = rect->x2;
+	    clip[i].y2 = rect->y2;
+	}
+
+	/* TODO query connector property to see if this is needed */
+	ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects);
+	if (ret) {
+	    if (ret == -EINVAL) {
+		ms->dirty_enabled = FALSE;
+		DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+		DamageDestroy(ms->damage);
+		ms->damage = NULL;
+		xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
+		return;
+	    } else
+		ErrorF("%s: failed to send dirty (%i, %s)\n",
+		       __func__, ret, strerror(-ret));
+	}
+	
+	DamageEmpty(ms->damage);
+    }
+}
+
+static void msBlockHandler(int i, pointer blockData, pointer pTimeout,
+			   pointer pReadmask)
+{
+    ScreenPtr pScreen = screenInfo.screens[i];
+    modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]);
+
+    pScreen->BlockHandler = ms->BlockHandler;
+    pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
+    pScreen->BlockHandler = msBlockHandler;
+    if (ms->dirty_enabled)
+	dispatch_dirty(pScreen);
+}
+
 static void
 FreeRec(ScrnInfoPtr pScrn)
 {
@@ -494,6 +546,18 @@ CreateScreenResources(ScreenPtr pScreen)
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
 	FatalError("Couldn't adjust screen pixmap\n");
 
+    ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
+                              pScreen, rootPixmap);
+
+    if (ms->damage) {
+	DamageRegister(&rootPixmap->drawable, ms->damage);
+	ms->dirty_enabled = TRUE;
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n");
+    } else {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		   "Failed to create screen damage record\n");
+	return FALSE;
+    }
     return ret;
 }
 
@@ -596,6 +660,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     ms->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = CloseScreen;
 
+    ms->BlockHandler = pScreen->BlockHandler;
+    pScreen->BlockHandler = msBlockHandler;
+
     if (!xf86CrtcScreenInit(pScreen))
 	return FALSE;
 
@@ -669,6 +736,12 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
+    if (ms->damage) {
+	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageDestroy(ms->damage);
+	ms->damage = NULL;
+    }
+
     drmmode_uevent_fini(pScrn, &ms->drmmode);
 
     drmmode_free_bos(pScrn, &ms->drmmode);
@@ -678,7 +751,7 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     }
 
     pScreen->CreateScreenResources = ms->createScreenResources;
-
+    pScreen->BlockHandler = ms->BlockHandler;
     drmClose(ms->fd);
     ms->fd = -1;
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 255dede..beb5f8d 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <drm.h>
 #include <xf86drm.h>
+#include <damage.h>
 
 #include "drmmode_display.h"
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
@@ -68,10 +69,13 @@ typedef struct _modesettingRec
     unsigned int SaveGeneration;
 
     CreateScreenResourcesProcPtr createScreenResources;
-
+    ScreenBlockHandlerProcPtr BlockHandler;
     void *driver;
 
     drmmode_rec drmmode;
+
+    DamagePtr damage;
+    Bool dirty_enabled;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
commit 4d3aadb22fc03f259a9d1717b55ce16d7a32e2be
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:34:27 2011 +0100

    drop loading dri2

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index dee9cff..0aaafd1 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -462,10 +462,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
-#ifdef DRI2
-    xf86LoadSubModule(pScrn, "dri2");
-#endif
-
     return TRUE;
     fail:
     return FALSE;
commit 1b1382c9e1995dcfe5dfec1de17155fa627ac6e8
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:34:17 2011 +0100

    update authors/copyright

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 9bb1cb4..dee9cff 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1,5 +1,6 @@
 /*
  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2011 Dave Airlie
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -23,7 +24,8 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ * Original Author: Alan Hourihane <alanh at tungstengraphics.com>
+ * Rewrite: Dave Airlie <airlied at redhat.com> 
  *
  */
 
commit 263597dbb3a75d711b5ad2e1f51554e6b2601d9a
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:30:46 2011 +0100

    gut some more unneeded code

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index be781bc..9bb1cb4 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -638,24 +638,6 @@ static void
 LeaveVT(int scrnIndex, int flags)
 {
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-    int o;
-
-    for (o = 0; o < config->num_crtc; o++) {
-	xf86CrtcPtr crtc = config->crtc[o];
-
-	//	cursor_destroy(crtc);
-
-	if (crtc->rotatedPixmap || crtc->rotatedData) {
-	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
-					crtc->rotatedData);
-	    crtc->rotatedPixmap = NULL;
-	    crtc->rotatedData = NULL;
-	}
-    }
-
-    drmModeRmFB(ms->fd, ms->fb_id);
 
     pScrn->vtSema = FALSE;
 }
commit a72bdf170c8bc55eef3d2dbb8e316839552288a5
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:28:59 2011 +0100

    modesetting: rewrite probing based on fbdev.
    
    This isn't perfect, it should really do more with bus id matching
    and finding the write drm device using sysfs if it can. but it removes
    lots of hardcoding of pci ids.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 47ffb07..be781bc 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -31,6 +31,7 @@
 #include "config.h"
 #endif
 
+#include <fcntl.h>
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
@@ -68,18 +69,19 @@ static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
 		       char **argv);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
 
-#if XSERVER_LIBPCIACCESS
-static Bool
-pci_probe(DriverPtr driver,
-	  int entity_num, struct pci_device *device, intptr_t match_data);
-#else
 static Bool Probe(DriverPtr drv, int flags);
-#endif
+static Bool ms_pci_probe(DriverPtr driver,
+			 int entity_num, struct pci_device *device,
+			 intptr_t match_data);
 
-#if XSERVER_LIBPCIACCESS
-static const struct pci_id_match device_match[] = {
-    {0x8086, 0x0046, 0xffff, 0xffff, 0, 0, 0},
-    {0, 0, 0},
+#ifdef XSERVER_LIBPCIACCESS
+static const struct pci_id_match ms_device_match[] = {
+    {
+	PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
+	0x00030000, 0x00ffffff, 0
+    },
+
+    { 0, 0, 0 },
 };
 #endif
 
@@ -87,38 +89,29 @@ _X_EXPORT DriverRec modesetting = {
     1,
     "modesetting",
     Identify,
-#if XSERVER_LIBPCIACCESS
-    NULL,
-#else
     Probe,
-#endif
     AvailableOptions,
     NULL,
     0,
     NULL,
-#if XSERVER_LIBPCIACCESS
-    device_match,
-    pci_probe
-#endif
+    ms_device_match,
+    ms_pci_probe,
 };
 
 static SymTabRec Chipsets[] = {
-    {0x0046, "Intel Graphics Device"},
+    {0, "kms" },
     {-1, NULL}
 };
 
-static PciChipsets PciDevices[] = {
-    {0x2592, 0x0046, RES_SHARED_VGA},
-    {-1, -1, RES_UNDEFINED}
-};
-
 typedef enum
 {
     OPTION_SW_CURSOR,
+    OPTION_DEVICE_PATH,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE },
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -171,6 +164,27 @@ Identify(int flags)
 		      Chipsets);
 }
 
+static Bool probe_hw(char *dev)
+{
+    int fd;
+    if (dev)
+	fd = open(dev, O_RDWR, 0);
+    else {
+	dev = getenv("KMSDEVICE");
+	if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) {
+	    dev = "/dev/dri/card0";
+	    fd = open(dev,O_RDWR, 0);
+	}
+    }
+    if (fd == -1) {
+	xf86DrvMsg(-1, X_ERROR,"open %s: %s\n", dev, strerror(errno));
+	return FALSE;
+    }
+    close(fd);
+    return TRUE;
+
+}
+
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
 {
@@ -179,25 +193,26 @@ AvailableOptions(int chipid, int busid)
 
 #if XSERVER_LIBPCIACCESS
 static Bool
-pci_probe(DriverPtr driver,
-	  int entity_num, struct pci_device *device, intptr_t match_data)
+ms_pci_probe(DriverPtr driver,
+	     int entity_num, struct pci_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
     EntityInfoPtr entity;
     DevUnion *private;
 
-    scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
+    scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
 			       NULL, NULL, NULL, NULL, NULL);
-    if (scrn != NULL) {
-	scrn->driverVersion = 1;
-	scrn->driverName = "modesetting";
-	scrn->name = "modesetting";
-	scrn->Probe = NULL;
-
-	entity = xf86GetEntityInfo(entity_num);
-
-	switch (device->device_id) {
-	case 0x0046:
+    if (scrn) {
+	char *devpath;
+	GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0],
+						  scrn->entityInstanceList[0]);
+
+	devpath = xf86FindOptionValue(devSection->options, "kmsdev");
+	if (probe_hw(devpath)) {
+	    scrn->driverVersion = 1;
+	    scrn->driverName = "modesetting";
+	    scrn->name = "modeset";
+	    scrn->Probe = NULL;
 	    scrn->PreInit = PreInit;
 	    scrn->ScreenInit = ScreenInit;
 	    scrn->SwitchMode = SwitchMode;
@@ -206,12 +221,19 @@ pci_probe(DriverPtr driver,
 	    scrn->LeaveVT = LeaveVT;
 	    scrn->FreeScreen = FreeScreen;
 	    scrn->ValidMode = ValidMode;
-	    break;
-	}
+
+	    xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
+		       "claimed PCI slot %d@%d:%d:%d\n", 
+		       dev->bus, dev->domain, dev->dev, dev->func);
+	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
+		       "using %s\n", devpath ? devpath : "default device");
+	} else
+	    scrn = NULL;
     }
     return scrn != NULL;
 }
-#else
+#endif
+
 static Bool
 Probe(DriverPtr drv, int flags)
 {
@@ -220,9 +242,13 @@ Probe(DriverPtr drv, int flags)
     DevUnion *pPriv;
     GDevPtr *devSections;
     Bool foundScreen = FALSE;
-    pciVideoPtr *VideoInfo;
-    pciVideoPtr *ppPci;
     int numDevs;
+    char *dev;
+    ScrnInfoPtr scrn;
+
+    /* For now, just bail out for PROBE_DETECT. */
+    if (flags & PROBE_DETECT)
+	return FALSE;
 
     /*
      * Find the config file Device sections that match this
@@ -232,110 +258,41 @@ Probe(DriverPtr drv, int flags)
 	return FALSE;
     }
 
-    /*
-     * This probing is just checking the PCI data the server already
-     * collected.
-     */
-    if (!(VideoInfo = xf86GetPciVideoInfo()))
-	return FALSE;
+    for (i = 0; i < numDevSections; i++) {
 
-#if 0
-    numUsed = 0;
-    for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
-	for (numDevs = 0; numDevs < numDevSections; numDevs++) {
-	    if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
-		if (xf86ComparePciBusString
-		    (devSections[numDevs]->busID, (*ppPci)->bus,
-		     (*ppPci)->device, (*ppPci)->func)) {
-		    /* Claim slot */
-		    if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
-					 (*ppPci)->func)) {
-			usedChips[numUsed++] =
-			    xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
-					     (*ppPci)->func, drv,
-					     (*ppPci)->chipType, NULL, TRUE);
-			ErrorF("CLAIMED %d %d %d\n", (*ppPci)->bus,
-			       (*ppPci)->device, (*ppPci)->func);
-		    }
-		}
+	dev = xf86FindOptionValue(devSections[i]->options,"kmsdev");
+	if (devSections[i]->busID) {
+	    if (probe_hw(dev)) {
+		int entity;
+		entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
+		scrn = xf86ConfigFbEntity(scrn, 0, entity,
+					   NULL, NULL, NULL, NULL);
 	    }
-	}
-    }
-#else
-    /* Look for Intel i8xx devices. */
-    numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
-				    Chipsets, PciDevices,
-				    devSections, numDevSections,
-				    drv, &usedChips);
-#endif
 
-    if (flags & PROBE_DETECT) {
-	if (numUsed > 0)
-	    foundScreen = TRUE;
-    } else {
-	for (i = 0; i < numUsed; i++) {
-	    ScrnInfoPtr pScrn = NULL;
-
-	    /* Allocate new ScrnInfoRec and claim the slot */
-	    if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
-					     PciDevices, NULL, NULL, NULL,
-					     NULL, NULL))) {
-		EntityInfoPtr pEnt;
-
-		pEnt = xf86GetEntityInfo(usedChips[i]);
-
-		pScrn->driverVersion = 1;
-		pScrn->driverName = "modesetting";
-		pScrn->name = "modesetting";
-		pScrn->Probe = Probe;
+	    if (scrn)
 		foundScreen = TRUE;
-		{
-		    /* Allocate an entity private if necessary */
-		    if (modesettingEntityIndex < 0)
-			modesettingEntityIndex =
-			    xf86AllocateEntityPrivateIndex();
-
-		    pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
-						 modesettingEntityIndex);
-		    if (!pPriv->ptr) {
-			pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
-			msEnt = pPriv->ptr;
-			msEnt->lastInstance = -1;
-		    } else {
-			msEnt = pPriv->ptr;
-		    }
-
-		    /*
-		     * Set the entity instance for this instance of the driver.
-		     * For dual head per card, instance 0 is the "master"
-		     * instance, driving the primary head, and instance 1 is
-		     * the "slave".
-		     */
-		    msEnt->lastInstance++;
-		    xf86SetEntityInstanceForScreen(pScrn,
-						   pScrn->entityList[0],
-						   msEnt->lastInstance);
-		    pScrn->PreInit = PreInit;
-		    pScrn->ScreenInit = ScreenInit;
-		    pScrn->SwitchMode = SwitchMode;
-		    pScrn->AdjustFrame = AdjustFrame;
-		    pScrn->EnterVT = EnterVT;
-		    pScrn->LeaveVT = LeaveVT;
-		    pScrn->FreeScreen = FreeScreen;
-		    pScrn->ValidMode = ValidMode;
-		    break;
-		}
-	    } else
-		ErrorF("FAILED PSCRN\n");
+		scrn->driverVersion = 1;
+		scrn->driverName = "modesetting";
+		scrn->name = "modesetting";
+		scrn->Probe = Probe;
+		scrn->PreInit = PreInit;
+		scrn->ScreenInit = ScreenInit;
+		scrn->SwitchMode = SwitchMode;
+		scrn->AdjustFrame = AdjustFrame;
+		scrn->EnterVT = EnterVT;
+		scrn->LeaveVT = LeaveVT;
+		scrn->FreeScreen = FreeScreen;
+		scrn->ValidMode = ValidMode;
+
+		xf86DrvMsg(scrn->scrnIndex, X_INFO,
+			   "using %s\n", dev ? dev : "default device");
 	}
     }
 
-    free(usedChips);
     free(devSections);
 
     return foundScreen;
 }
-#endif
 
 static Bool
 GetRec(ScrnInfoPtr pScrn)
commit a77fae850511c4d73af2af2b88804586f950f28d
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 11:52:51 2011 +0100

    cleanup some the drmmode_display header file

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 2d72505..845207a 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -33,49 +33,33 @@
 #endif
 
 struct dumb_bo {
-  uint32_t handle;
-  uint32_t size;
-  void *ptr;
-  int map_count;
-  uint32_t pitch;
+    uint32_t handle;
+    uint32_t size;
+    void *ptr;
+    int map_count;
+    uint32_t pitch;
 };
 
 typedef struct {
-  int fd;
-  unsigned fb_id;
-  drmModeResPtr mode_res;
-  drmModeFBPtr mode_fb;
-  int cpp;
-  ScrnInfoPtr scrn;
+    int fd;
+    unsigned fb_id;
+    drmModeResPtr mode_res;
+    drmModeFBPtr mode_fb;
+    int cpp;
+    ScrnInfoPtr scrn;
 #ifdef HAVE_UDEV
-  struct udev_monitor *uevent_monitor;
-  InputHandlerProc uevent_handler;
+    struct udev_monitor *uevent_monitor;
+    InputHandlerProc uevent_handler;
 #endif
-  drmEventContext event_context;
-  struct dumb_bo *front_bo;
+    drmEventContext event_context;
+    struct dumb_bo *front_bo;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
-  drmmode_ptr drmmode;
-  unsigned old_fb_id;
-  int flip_count;
-  void *event_data;
-  unsigned int fe_frame;
-  unsigned int fe_tv_sec;
-  unsigned int fe_tv_usec;
-} drmmode_flipdata_rec, *drmmode_flipdata_ptr;
-
-typedef struct {
-  drmmode_flipdata_ptr flipdata;
-  Bool dispatch_me;
-} drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr;
-
-typedef struct {
     drmmode_ptr drmmode;
     drmModeCrtcPtr mode_crtc;
     int hw_id;
     struct dumb_bo *cursor_bo;
-  //    struct radeon_bo *rotate_bo;
     unsigned rotate_fb_id;
     uint16_t lut_r[256], lut_g[256], lut_b[256];
 } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
@@ -103,21 +87,13 @@ typedef struct {
 
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
-//extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr);
-//extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
 extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
-extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
 
 extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode);
 extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
 
-extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling);
-extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
-extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
-
-//Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id);
 Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void *drmmode_map_front_bo(drmmode_ptr drmmode);
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
commit 2a4618905445ce13fd272a4634ef5103dc804231
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 11:49:26 2011 +0100

    modesetting: restart driver effort from other codebases
    
    This starts a randr 1.2 compatible driver with cursors.
    
    TODO:
    libkms
    dirty handling
    server recycling.

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 23e78b7..4337977 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -25,19 +25,16 @@ SUBDIRS =
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
-AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \
-	-I at GALLIUM_DIR@/src/gallium/include \
-	-I at GALLIUM_DIR@/src/gallium/auxiliary
+AM_CFLAGS = @XORG_CFLAGS@ @DRM_CFLAGS@ @UDEV_CFLAGS@
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
-modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm
+modesetting_drv_la_LDFLAGS = -module -avoid-version
+modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
 	 driver.c \
 	 driver.h \
-	 output.c \
-	 crtc.c \
-	 dri2.c
+	 drmmode_display.c
 
 EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
deleted file mode 100644
index d4f449b..0000000
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <unistd.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <math.h>
-#include <stdint.h>
-
-#include <xf86.h>
-#include <xf86i2c.h>
-#include <xf86Crtc.h>
-#include "driver.h"
-#include "xf86Modes.h"
-
-#define DPMS_SERVER
-#include <X11/extensions/dpms.h>
-
-struct crtc_private
-{
-    drmModeCrtcPtr drm_crtc;
-
-    /* hwcursor */
-    drmBO cursor_bo;
-};
-
-static void
-crtc_dpms(xf86CrtcPtr crtc, int mode)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-
-    switch (mode) {
-    case DPMSModeOn:
-    case DPMSModeStandby:
-    case DPMSModeSuspend:
-	break;
-    case DPMSModeOff:
-	break;
-    }
-}
-
-static Bool
-crtc_lock(xf86CrtcPtr crtc)
-{
-    return FALSE;
-}
-
-static void
-crtc_unlock(xf86CrtcPtr crtc)
-{
-}
-
-static void
-crtc_prepare(xf86CrtcPtr crtc)
-{
-}
-
-static void
-crtc_commit(xf86CrtcPtr crtc)
-{
-}
-
-static Bool
-crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
-		DisplayModePtr adjusted_mode)
-{
-    return TRUE;
-}
-
-static void
-crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
-	      DisplayModePtr adjusted_mode, int x, int y)
-{
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    xf86OutputPtr output = config->output[config->compat_output];
-    drmModeConnectorPtr drm_connector = output->driver_private;
-    struct crtc_private *crtcp = crtc->driver_private;
-    drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
-    struct drm_mode_modeinfo drm_mode;
-
-    drm_mode.clock = mode->Clock;
-    drm_mode.hdisplay = mode->HDisplay;
-    drm_mode.hsync_start = mode->HSyncStart;
-    drm_mode.hsync_end = mode->HSyncEnd;
-    drm_mode.htotal = mode->HTotal;
-    drm_mode.vdisplay = mode->VDisplay;
-    drm_mode.vsync_start = mode->VSyncStart;
-    drm_mode.vsync_end = mode->VSyncEnd;
-    drm_mode.vtotal = mode->VTotal;
-    drm_mode.flags = mode->Flags;
-    drm_mode.hskew = mode->HSkew;
-    drm_mode.vscan = mode->VScan;
-    drm_mode.vrefresh = mode->VRefresh;
-    if (!mode->name)
-	xf86SetModeDefaultName(mode);
-    strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
-
-    drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
-		   &drm_connector->connector_id, 1, &drm_mode);
-}
-
-void
-crtc_load_lut(xf86CrtcPtr crtc)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-}
-
-static void
-crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
-	       int size)
-{
-}
-
-static void *
-crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-
-    return NULL;
-}
-
-static PixmapPtr
-crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-
-    return NULL;
-}
-
-static void
-crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-}
-
-static void
-crtc_destroy(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (crtcp->cursor_bo.handle)
-	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
-
-    drmModeFreeCrtc(crtcp->drm_crtc);
-    xfree(crtcp);
-}
-
-static void
-crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
-{
-    unsigned char *ptr;
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (!crtcp->cursor_bo.handle)
-	drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
-		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE
-		    | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		    DRM_BO_FLAG_MEM_VRAM,
-		    DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
-
-    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE,
-	     DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
-
-    if (ptr)
-	memcpy(ptr, image, 64 * 64 * 4);
-
-    drmBOUnmap(ms->fd, &crtcp->cursor_bo);
-}
-
-static void
-crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y);
-}
-
-static void
-crtc_show_cursor(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (crtcp->cursor_bo.handle)
-	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id,
-			 crtcp->cursor_bo.handle, 64, 64);
-}
-
-static void
-crtc_hide_cursor(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
-}
-
-static const xf86CrtcFuncsRec crtc_funcs = {
-    .dpms = crtc_dpms,
-    .save = NULL,
-    .restore = NULL,
-    .lock = crtc_lock,
-    .unlock = crtc_unlock,
-    .mode_fixup = crtc_mode_fixup,
-    .prepare = crtc_prepare,
-    .mode_set = crtc_mode_set,
-    .commit = crtc_commit,
-    .gamma_set = crtc_gamma_set,
-    .shadow_create = crtc_shadow_create,
-    .shadow_allocate = crtc_shadow_allocate,
-    .shadow_destroy = crtc_shadow_destroy,
-    .set_cursor_position = crtc_set_cursor_position,
-    .show_cursor = crtc_show_cursor,
-    .hide_cursor = crtc_hide_cursor,
-    .load_cursor_image = NULL,	       /* lets convert to argb only */
-    .set_cursor_colors = NULL,	       /* using argb only */
-    .load_cursor_argb = crtc_load_cursor_argb,
-    .destroy = crtc_destroy,
-};
-
-void
-cursor_destroy(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (crtcp->cursor_bo.handle) {
-	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
-	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
-    }
-}
-
-void
-crtc_init(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    xf86CrtcPtr crtc;
-    drmModeResPtr res;
-    drmModeCrtcPtr drm_crtc = NULL;
-    struct crtc_private *crtcp;
-    int c, k, p;
-
-    res = drmModeGetResources(ms->fd);
-    if (res == 0) {
-	ErrorF("Failed drmModeGetResources %d\n", errno);
-	return;
-    }
-
-    for (c = 0; c < res->count_crtcs; c++) {
-	drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
-	if (!drm_crtc)
-	    continue;
-
-	crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
-	if (crtc == NULL)
-	    goto out;
-
-	crtcp = xcalloc(1, sizeof(struct crtc_private));
-	if (!crtcp) {
-	    xf86CrtcDestroy(crtc);
-	    goto out;
-	}
-
-	crtcp->drm_crtc = drm_crtc;
-
-	crtc->driver_private = crtcp;
-
-    }
-
-  out:
-    drmModeFreeResources(res);
-}
diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
deleted file mode 100644
index 7fd9fca..0000000
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include "driver.h"
-
-#include "dri2.h"
-
-extern unsigned int
-driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags);
-
-void
-driLock(ScreenPtr pScreen)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    if (!ms->lock_held)
-	DRM_LOCK(ms->fd, ms->lock, ms->context, 0);
-
-    ms->lock_held = 1;
-}
-
-void
-driUnlock(ScreenPtr pScreen)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    if (ms->lock_held)
-	DRM_UNLOCK(ms->fd, ms->lock, ms->context);
-
-    ms->lock_held = 0;
-}
-
-static void
-driBeginClipNotify(ScreenPtr pScreen)
-{
-    driLock(pScreen);
-}
-
-static void
-driEndClipNotify(ScreenPtr pScreen)
-{
-    driUnlock(pScreen);
-}
-
-struct __DRILock
-{
-    unsigned int block_header;
-    drm_hw_lock_t lock;
-    unsigned int next_id;
-};
-
-#define DRI2_SAREA_BLOCK_HEADER(type, size) (((type) << 16) | (size))
-#define DRI2_SAREA_BLOCK_LOCK		0x0001
-
-void
-driScreenInit(ScreenPtr pScreen)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    DRI2InfoRec dri2info;
-    const char *driverName;
-    unsigned int sarea_handle;
-    struct __DRILock *DRILock;
-    void *p;
-
-    dri2info.version = 1;
-    dri2info.fd = ms->fd;
-    dri2info.driverSareaSize = sizeof(struct __DRILock);
-    dri2info.driverName = "i915";      /* FIXME */
-    dri2info.getPixmapHandle = driGetPixmapHandle;
-    dri2info.beginClipNotify = driBeginClipNotify;
-    dri2info.endClipNotify = driEndClipNotify;
-
-    p = DRI2ScreenInit(pScreen, &dri2info);
-    if (!p)
-	return;
-
-    DRILock = p;
-    DRILock->block_header =
-	DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_LOCK, sizeof *DRILock);
-    ms->lock = &DRILock->lock;
-    ms->context = 1;
-    DRILock->next_id = 2;
-    driLock(pScreen);
-
-    DRI2Connect(pScreen, &ms->fd, &driverName, &sarea_handle);
-}
-
-void
-driCloseScreen(ScreenPtr pScreen)
-{
-    driUnlock(pScreen);
-    DRI2CloseScreen(pScreen);
-}
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 6b70d4b..47ffb07 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -34,10 +34,8 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86RAC.h"
 #include "xf86PciInfo.h"
 #include "xf86Pci.h"
-#include "xf86Resources.h"
 #include "mipointer.h"
 #include "micmap.h"
 #include <X11/extensions/randr.h>
@@ -59,8 +57,6 @@
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
 static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
 static Bool EnterVT(int scrnIndex, int flags);
-static Bool SaveHWState(ScrnInfoPtr pScrn);
-static Bool RestoreHWState(ScrnInfoPtr pScrn);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
 static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
@@ -82,7 +78,7 @@ static Bool Probe(DriverPtr drv, int flags);
 
 #if XSERVER_LIBPCIACCESS
 static const struct pci_id_match device_match[] = {
-    {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
+    {0x8086, 0x0046, 0xffff, 0xffff, 0, 0, 0},
     {0, 0, 0},
 };
 #endif
@@ -107,12 +103,12 @@ _X_EXPORT DriverRec modesetting = {
 };
 
 static SymTabRec Chipsets[] = {
-    {0x2592, "Intel Graphics Device"},
+    {0x0046, "Intel Graphics Device"},
     {-1, NULL}
 };
 
 static PciChipsets PciDevices[] = {
-    {0x2592, 0x2592, RES_SHARED_VGA},
+    {0x2592, 0x0046, RES_SHARED_VGA},
     {-1, -1, RES_UNDEFINED}
 };
 
@@ -126,24 +122,6 @@ static const OptionInfoRec Options[] = {
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
-static const char *fbSymbols[] = {
-    "fbPictureInit",
-    "fbScreenInit",
-    NULL
-};
-
-static const char *ddcSymbols[] = {
-    "xf86PrintEDID",
-    "xf86SetDDCproperties",
-    NULL
-};
-
-static const char *i2cSymbols[] = {
-    "xf86CreateI2CBusRec",
-    "xf86I2CBusInit",
-    NULL
-};
-
 int modesettingEntityIndex = -1;
 
 static MODULESETUPPROTO(Setup);
@@ -175,12 +153,6 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	xf86AddDriver(&modesetting, module, HaveDriverFuncs);
 
 	/*
-	 * Tell the loader about symbols from other modules that this module
-	 * might refer to.
-	 */
-	LoaderRefSymLists(fbSymbols, ddcSymbols, NULL);
-
-	/*
 	 * The return value must be non-NULL on success even though there
 	 * is no TearDownProc.
 	 */
@@ -225,7 +197,7 @@ pci_probe(DriverPtr driver,
 	entity = xf86GetEntityInfo(entity_num);
 
 	switch (device->device_id) {
-	case 0x2592:
+	case 0x0046:
 	    scrn->PreInit = PreInit;
 	    scrn->ScreenInit = ScreenInit;
 	    scrn->SwitchMode = SwitchMode;
@@ -358,8 +330,8 @@ Probe(DriverPtr drv, int flags)
 	}
     }
 
-    xfree(usedChips);
-    xfree(devSections);
+    free(usedChips);
+    free(devSections);
 
     return foundScreen;
 }
@@ -385,76 +357,11 @@ FreeRec(ScrnInfoPtr pScrn)
     if (!pScrn->driverPrivate)
 	return;
 
-    xfree(pScrn->driverPrivate);
+    free(pScrn->driverPrivate);
 
     pScrn->driverPrivate = NULL;
 }
 
-static void
-ProbeDDC(ScrnInfoPtr pScrn, int index)
-{
-    ConfiguredMonitor = NULL;
-}
-
-static Bool
-CreateFrontBuffer(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    ScreenPtr pScreen = pScrn->pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    Bool fbAccessDisabled;
-    int flags;
-
-    pScreen->ModifyPixmapHeader(rootPixmap,
-				pScrn->virtualX, pScrn->virtualY,
-				pScrn->depth, pScrn->bitsPerPixel,
-				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-				NULL);
-    drmModeAddFB(ms->fd,
-		 pScrn->virtualX,
-		 pScrn->virtualY,
-		 pScrn->depth,
-		 pScrn->bitsPerPixel,
-		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
-
-    pScrn->frameX0 = 0;
-    pScrn->frameY0 = 0;
-    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
-
-    return TRUE;
-}
-
-static Bool
-crtc_resize(ScrnInfoPtr pScrn, int width, int height)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    ScreenPtr pScreen = pScrn->pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    Bool fbAccessDisabled;
-    CARD8 *fbstart;
-
-    if (width == pScrn->virtualX && height == pScrn->virtualY)
-	return TRUE;
-
-    ErrorF("RESIZING TO %dx%d\n", width, height);
-
-    pScrn->virtualX = width;
-    pScrn->virtualY = height;
-
-    /* HW dependent - FIXME */
-    pScrn->displayWidth = pScrn->virtualX;
-
-    drmModeRmFB(ms->fd, ms->fb_id);
-
-    /* now create new frontbuffer */
-    return CreateFrontBuffer(pScrn);
-}
-
-static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
-    crtc_resize
-};
-
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
@@ -476,8 +383,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
 
     if (flags & PROBE_DETECT) {
-	ProbeDDC(pScrn, pEnt->index);
-	return TRUE;
+	return FALSE;
     }
 
     /* Allocate driverPrivate */
@@ -503,10 +409,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     } else
 	ms->entityPrivate = NULL;
 
-    if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
-	return FALSE;
-    }
-
     if (xf86IsEntityShared(pScrn->entityList[0])) {
 	if (xf86IsPrimInitDone(pScrn->entityList[0])) {
 	    /* do something */
@@ -515,7 +417,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	}
     }
 
-    BusID = xalloc(64);
+    BusID = malloc(64);
     sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
 	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
@@ -528,11 +430,9 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	);
 
     ms->fd = drmOpen(NULL, BusID);
-
     if (ms->fd < 0)
 	return FALSE;
 
-    pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
     pScrn->monitor = pScrn->confScreen->monitor;
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
@@ -562,36 +462,21 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     /* Process the options */
     xf86CollectOptions(pScrn, NULL);
-    if (!(ms->Options = xalloc(sizeof(Options))))
+    if (!(ms->Options = malloc(sizeof(Options))))
 	return FALSE;
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
-    /* Allocate an xf86CrtcConfig */
-    xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
-    xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-    max_width = 8192;
-    max_height = 8192;
-    xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
-
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
 	ms->SWCursor = TRUE;
     }
 
-    SaveHWState(pScrn);
-
-    crtc_init(pScrn);
-    output_init(pScrn);
-
-    if (!xf86InitialConfiguration(pScrn, TRUE)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
-	RestoreHWState(pScrn);
-	return FALSE;
+    ms->drmmode.fd = ms->fd;
+    if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
+	goto fail;
     }
 
-    RestoreHWState(pScrn);
-
     /*
      * If the driver can do gamma correction, it should call xf86SetGamma() here.
      */
@@ -618,29 +503,13 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
-    xf86LoaderReqSymLists(fbSymbols, NULL);
-
 #ifdef DRI2
     xf86LoadSubModule(pScrn, "dri2");
 #endif
 
     return TRUE;
-}
-
-static Bool
-SaveHWState(ScrnInfoPtr pScrn)
-{
-    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-    return TRUE;
-}
-
-static Bool
-RestoreHWState(ScrnInfoPtr pScrn)
-{
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-    return TRUE;
+    fail:
+    return FALSE;
 }
 
 static Bool
@@ -651,25 +520,24 @@ CreateScreenResources(ScreenPtr pScreen)
     PixmapPtr rootPixmap;
     Bool ret;
     int flags;
-
+    void *pixels;
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
 
-    rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
+      return FALSE;
 
-    if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL))
-	FatalError("Couldn't adjust screen pixmap\n");
+    drmmode_uevent_init(pScrn, &ms->drmmode);
 
-    drmModeAddFB(ms->fd,
-		 pScrn->virtualX,
-		 pScrn->virtualY,
-		 pScrn->depth,
-		 pScrn->bitsPerPixel,
-		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
+    drmmode_map_cursor_bos(pScrn, &ms->drmmode);
+    pixels = drmmode_map_front_bo(&ms->drmmode);
+    if (!pixels)
+	return FALSE;
 
-    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+    rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
+	FatalError("Couldn't adjust screen pixmap\n");
 
     return ret;
 }
@@ -688,7 +556,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (ms->fd < 0) {
 	char *BusID;
 
-	BusID = xalloc(64);
+	BusID = malloc(64);
 	sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
 		((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
@@ -710,6 +578,8 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
+    if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
+	return FALSE;
 
     miClearVisualTypes();
 
@@ -782,10 +652,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-#ifdef DRI2
-    driScreenInit(pScreen);
-#endif
-
     return EnterVT(scrnIndex, 1);
 }
 
@@ -822,7 +688,7 @@ LeaveVT(int scrnIndex, int flags)
     for (o = 0; o < config->num_crtc; o++) {
 	xf86CrtcPtr crtc = config->crtc[o];
 
-	cursor_destroy(crtc);
+	//	cursor_destroy(crtc);
 
 	if (crtc->rotatedPixmap || crtc->rotatedData) {
 	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
@@ -834,16 +700,6 @@ LeaveVT(int scrnIndex, int flags)
 
     drmModeRmFB(ms->fd, ms->fb_id);
 
-    RestoreHWState(pScrn);
-
-#if 0
-    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
-    drmMMLock(ms->fd, DRM_BO_MEM_TT, 1, 0);
-#endif
-#ifdef DRI2
-    driLock(pScrn->pScreen);
-#endif
-
     pScrn->vtSema = FALSE;
 }
 
@@ -856,29 +712,6 @@ EnterVT(int scrnIndex, int flags)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
-#if 0
-    if (pScrn->vtSema) {
-	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
-    }
-#endif
-
-#ifdef DRI2
-    driUnlock(pScrn->pScreen);
-#endif
-
-    /*
-     * Only save state once per server generation since that's what most
-     * drivers do.  Could change this to save state at each VT enter.
-     */
-    if (ms->SaveGeneration != serverGeneration) {
-	ms->SaveGeneration = serverGeneration;
-	SaveHWState(pScrn);
-    }
-
-    if (!flags)			       /* signals startup as we'll do this in CreateScreenResources */
-	CreateFrontBuffer(pScrn);
-
     if (!xf86SetDesiredModes(pScrn))
 	return FALSE;
 
@@ -899,16 +732,13 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
+    drmmode_uevent_fini(pScrn, &ms->drmmode);
+
+    drmmode_free_bos(pScrn, &ms->drmmode);
+
     if (pScrn->vtSema) {
 	LeaveVT(scrnIndex, 0);
-#if 0
-	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
-#endif
     }
-#ifdef DRI2
-    driCloseScreen(pScreen);
-#endif
 
     pScreen->CreateScreenResources = ms->createScreenResources;
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index a673f8f..255dede 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -30,9 +30,8 @@
 #include <errno.h>
 #include <drm.h>
 #include <xf86drm.h>
-#include <xf86drmMode.h>
-#include <xf86mm.h>
 
+#include "drmmode_display.h"
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
 
 typedef struct
@@ -72,10 +71,7 @@ typedef struct _modesettingRec
 
     void *driver;
 
-    /* dri2 */
-    drm_context_t context;
-    drm_hw_lock_t *lock;
-    int lock_held;
+    drmmode_rec drmmode;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
new file mode 100644
index 0000000..d94ce03
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -0,0 +1,1340 @@
+/*
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors:
+ *    Dave Airlie <airlied at redhat.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include "xf86str.h"
+#include "X11/Xatom.h"
+#include "micmap.h"
+#include "xf86cmap.h"
+#include "xf86DDC.h"
+
+#include <xf86drm.h>
+#include "xf86Crtc.h"
+#include "drmmode_display.h"
+
+/* DPMS */
+#ifdef HAVE_XEXTPROTO_71
+#include <X11/extensions/dpmsconst.h>
+#else
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+#endif
+
+static struct dumb_bo *dumb_bo_create(int fd,
+			  const unsigned width, const unsigned height,
+			  const unsigned bpp)
+{
+	struct drm_mode_create_dumb arg;
+	struct dumb_bo *bo;
+	int ret;
+
+	bo = calloc(1, sizeof(*bo));
+	if (!bo)
+		return NULL;
+
+	memset(&arg, 0, sizeof(arg));
+	arg.width = width;
+	arg.height = height;
+	arg.bpp = bpp;
+	
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
+	if (ret)
+		goto err_free;
+
+	bo->handle = arg.handle;
+	bo->size = arg.size;
+	bo->pitch = arg.pitch;
+
+	return bo;
+ err_free:
+	free(bo);
+	return NULL;
+}
+
+static int dumb_bo_map(int fd, struct dumb_bo *bo)
+{
+	struct drm_mode_map_dumb arg;
+	int ret;
+	void *map;
+
+	if (bo->ptr) {
+		bo->map_count++;
+		return 0;
+	}
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = bo->handle;
+
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
+	if (ret)
+		return ret;
+
+	map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
+		   fd, arg.offset);
+	if (map == MAP_FAILED)
+		return -errno;
+
+	bo->ptr = map;
+	return 0;
+}
+
+static int dumb_bo_unmap(int fd, struct dumb_bo *bo)
+{
+	bo->map_count--;
+	return 0;
+}
+
+static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
+{
+	struct drm_mode_destroy_dumb arg;
+	int ret;
+	
+	if (bo->ptr) {
+		munmap(bo->ptr, bo->size);
+		bo->ptr = NULL;
+	}
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = bo->handle;
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
+	if (ret)
+		return -errno;
+
+	free(bo);
+	return 0;
+}
+
+static void
+drmmode_ConvertFromKMode(ScrnInfoPtr	scrn,
+		     drmModeModeInfo *kmode,
+		     DisplayModePtr	mode)
+{
+	memset(mode, 0, sizeof(DisplayModeRec));
+	mode->status = MODE_OK;
+
+	mode->Clock = kmode->clock;
+
+	mode->HDisplay = kmode->hdisplay;
+	mode->HSyncStart = kmode->hsync_start;
+	mode->HSyncEnd = kmode->hsync_end;
+	mode->HTotal = kmode->htotal;
+	mode->HSkew = kmode->hskew;
+
+	mode->VDisplay = kmode->vdisplay;
+	mode->VSyncStart = kmode->vsync_start;
+	mode->VSyncEnd = kmode->vsync_end;
+	mode->VTotal = kmode->vtotal;
+	mode->VScan = kmode->vscan;
+
+	mode->Flags = kmode->flags; //& FLAG_BITS;
+	mode->name = strdup(kmode->name);
+
+	if (kmode->type & DRM_MODE_TYPE_DRIVER)
+		mode->type = M_T_DRIVER;
+	if (kmode->type & DRM_MODE_TYPE_PREFERRED)
+		mode->type |= M_T_PREFERRED;
+	xf86SetModeCrtc (mode, scrn->adjustFlags);
+}
+
+static void
+drmmode_ConvertToKMode(ScrnInfoPtr	scrn,
+		     drmModeModeInfo *kmode,
+		     DisplayModePtr	mode)
+{
+	memset(kmode, 0, sizeof(*kmode));
+
+	kmode->clock = mode->Clock;
+	kmode->hdisplay = mode->HDisplay;
+	kmode->hsync_start = mode->HSyncStart;
+	kmode->hsync_end = mode->HSyncEnd;
+	kmode->htotal = mode->HTotal;
+	kmode->hskew = mode->HSkew;
+
+	kmode->vdisplay = mode->VDisplay;
+	kmode->vsync_start = mode->VSyncStart;
+	kmode->vsync_end = mode->VSyncEnd;
+	kmode->vtotal = mode->VTotal;
+	kmode->vscan = mode->VScan;
+
+	kmode->flags = mode->Flags; //& FLAG_BITS;
+	if (mode->name)
+		strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN);
+	kmode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
+
+}
+
+static void
+drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode)
+{
+#if 0
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+//	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+//	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	/* bonghits in the randr 1.2 - uses dpms to disable crtc - bad buzz */
+	if (mode == DPMSModeOff) {
+//		drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+//			       0, 0, 0, NULL, 0, NULL);
+	}
+#endif
+}
+
+#if 0
+static PixmapPtr
+create_pixmap_for_fbcon(drmmode_ptr drmmode,
+			ScrnInfoPtr pScrn, int crtc_id)
+{
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	drmmode_crtc_private_ptr drmmode_crtc;
+	ScreenPtr pScreen = pScrn->pScreen;
+	PixmapPtr pixmap;
+	struct radeon_bo *bo;
+	drmModeFBPtr fbcon;
+	struct drm_gem_flink flink;
+
+	drmmode_crtc = xf86_config->crtc[crtc_id]->driver_private;
+
+	fbcon = drmModeGetFB(drmmode->fd, drmmode_crtc->mode_crtc->buffer_id);
+	if (fbcon == NULL)
+		return NULL;
+
+	flink.handle = fbcon->handle;
+	if (ioctl(drmmode->fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Couldn't flink fbcon handle\n");
+		return NULL;
+	}
+
+	bo = radeon_bo_open(drmmode->bufmgr, flink.name, 0, 0, 0, 0);
+	if (bo == NULL) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Couldn't allocate bo for fbcon handle\n");
+		return NULL;
+	}
+
+	pixmap = drmmode_create_bo_pixmap(pScreen, fbcon->width, fbcon->height,
+					  fbcon->depth, fbcon->bpp,
+					  fbcon->pitch, bo);
+	if (!pixmap) 
+		return NULL;
+
+	radeon_bo_unref(bo);
+	drmModeFreeFB(fbcon);
+	return pixmap;
+}
+
+#endif
+
+static Bool
+drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
+		     Rotation rotation, int x, int y)
+{
+	ScrnInfoPtr pScrn = crtc->scrn;
+	//	RADEONInfoPtr info = RADEONPTR(pScrn);
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	int saved_x, saved_y;
+	Rotation saved_rotation;
+	DisplayModeRec saved_mode;
+	uint32_t *output_ids;
+	int output_count = 0;
+	Bool ret = TRUE;
+	int i;
+	int fb_id;
+	drmModeModeInfo kmode;
+	int pitch;
+	uint32_t tiling_flags = 0;
+	int height;
+
+	pitch = pScrn->displayWidth;
+	height = pScrn->virtualY;
+
+	if (drmmode->fb_id == 0) {
+		ret = drmModeAddFB(drmmode->fd,
+				   pScrn->virtualX, height,
+                                   pScrn->depth, pScrn->bitsPerPixel,
+				   drmmode->front_bo->pitch,
+				   drmmode->front_bo->handle,
+                                   &drmmode->fb_id);
+                if (ret < 0) {
+                        ErrorF("failed to add fb %d\n", ret);
+                        return FALSE;
+                }
+        }
+
+	saved_mode = crtc->mode;
+	saved_x = crtc->x;
+	saved_y = crtc->y;
+	saved_rotation = crtc->rotation;
+
+	if (mode) {
+		crtc->mode = *mode;
+		crtc->x = x;
+		crtc->y = y;
+		crtc->rotation = rotation;
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,5,99,0,0)
+		crtc->transformPresent = FALSE;
+#endif
+	}
+
+	output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
+	if (!output_ids) {
+		ret = FALSE;
+		goto done;
+	}
+
+	if (mode) {
+		for (i = 0; i < xf86_config->num_output; i++) {
+			xf86OutputPtr output = xf86_config->output[i];
+			drmmode_output_private_ptr drmmode_output;
+
+			if (output->crtc != crtc)
+				continue;
+
+			drmmode_output = output->driver_private;
+			output_ids[output_count] = drmmode_output->mode_output->connector_id;
+			output_count++;
+		}
+
+		if (!xf86CrtcRotate(crtc)) {
+			goto done;
+		}
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,0,0,0)
+		crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
+				       crtc->gamma_blue, crtc->gamma_size);
+#endif
+		
+		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
+
+		fb_id = drmmode->fb_id;
+		if (drmmode_crtc->rotate_fb_id) {
+			fb_id = drmmode_crtc->rotate_fb_id;
+			x = y = 0;
+		}
+		ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+				     fb_id, x, y, output_ids, output_count, &kmode);
+		if (ret)
+			xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
+				   "failed to set mode: %s", strerror(-ret));
+		else
+			ret = TRUE;
+
+		if (crtc->scrn->pScreen)
+			xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
+		/* go through all the outputs and force DPMS them back on? */
+		for (i = 0; i < xf86_config->num_output; i++) {
+			xf86OutputPtr output = xf86_config->output[i];
+
+			if (output->crtc != crtc)
+				continue;
+
+			output->funcs->dpms(output, DPMSModeOn);
+		}
+	}
+
+#if 0
+	if (pScrn->pScreen &&
+		!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
+		xf86_reload_cursors(pScrn->pScreen);
+#endif
+done:
+	if (!ret) {
+		crtc->x = saved_x;
+		crtc->y = saved_y;
+		crtc->rotation = saved_rotation;
+		crtc->mode = saved_mode;
+	}
+#if defined(XF86_CRTC_VERSION) && XF86_CRTC_VERSION >= 3
+	else
+		crtc->active = TRUE;
+#endif
+
+	return ret;
+}
+
+static void
+drmmode_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
+{
+
+}
+
+static void
+drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y);
+}
+
+static void
+drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	int i;
+	uint32_t *ptr;
+
+	/* cursor should be mapped already */
+	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
+
+	for (i = 0; i < 64 * 64; i++)
+		ptr[i] = image[i];// cpu_to_le32(image[i]);
+}
+
+
+static void
+drmmode_hide_cursor (xf86CrtcPtr crtc)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 64, 64);
+
+}
+
+static void
+drmmode_show_cursor (xf86CrtcPtr crtc)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	uint32_t handle = drmmode_crtc->cursor_bo->handle;
+
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+}
+
+static void
+drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
+                      uint16_t *blue, int size)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+			    size, red, green, blue);
+}
+
+static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
+    .dpms = drmmode_crtc_dpms,
+    .set_mode_major = drmmode_set_mode_major,
+    .set_cursor_colors = drmmode_set_cursor_colors,
+    .set_cursor_position = drmmode_set_cursor_position,
+    .show_cursor = drmmode_show_cursor,
+    .hide_cursor = drmmode_hide_cursor,
+    .load_cursor_argb = drmmode_load_cursor_argb,
+
+    .gamma_set = drmmode_crtc_gamma_set,
+    .destroy = NULL, /* XXX */
+};
+
+int drmmode_get_crtc_id(xf86CrtcPtr crtc)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	return drmmode_crtc->hw_id;
+}
+
+static void
+drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num)
+{
+	xf86CrtcPtr crtc;
+	drmmode_crtc_private_ptr drmmode_crtc;
+
+	crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs);
+	if (crtc == NULL)
+		return;
+
+	drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1);
+	drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd, drmmode->mode_res->crtcs[num]);
+	drmmode_crtc->drmmode = drmmode;
+	crtc->driver_private = drmmode_crtc;
+}
+
+static xf86OutputStatus
+drmmode_output_detect(xf86OutputPtr output)
+{
+	/* go to the hw and retrieve a new output struct */
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+	xf86OutputStatus status;
+	drmModeFreeConnector(drmmode_output->mode_output);
+
+	drmmode_output->mode_output = drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
+
+	switch (drmmode_output->mode_output->connection) {
+	case DRM_MODE_CONNECTED:
+		status = XF86OutputStatusConnected;
+		break;
+	case DRM_MODE_DISCONNECTED:
+		status = XF86OutputStatusDisconnected;
+		break;
+	default:
+	case DRM_MODE_UNKNOWNCONNECTION:
+		status = XF86OutputStatusUnknown;
+		break;
+	}
+	return status;
+}
+
+static Bool
+drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
+{
+	return MODE_OK;
+}
+
+static DisplayModePtr
+drmmode_output_get_modes(xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmModeConnectorPtr koutput = drmmode_output->mode_output;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+	int i;
+	DisplayModePtr Modes = NULL, Mode;
+	drmModePropertyPtr props;
+	xf86MonPtr mon = NULL;
+
+	/* look for an EDID property */
+	for (i = 0; i < koutput->count_props; i++) {
+		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+		if (props && (props->flags & DRM_MODE_PROP_BLOB)) {
+			if (!strcmp(props->name, "EDID")) {
+				if (drmmode_output->edid_blob)
+					drmModeFreePropertyBlob(drmmode_output->edid_blob);
+				drmmode_output->edid_blob = drmModeGetPropertyBlob(drmmode->fd, koutput->prop_values[i]);
+			}
+			drmModeFreeProperty(props);
+		}
+	}
+
+	if (drmmode_output->edid_blob) {
+		mon = xf86InterpretEDID(output->scrn->scrnIndex,
+					drmmode_output->edid_blob->data);
+		if (mon && drmmode_output->edid_blob->length > 128)
+			mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
+	}
+	xf86OutputSetEDID(output, mon);
+
+	/* modes should already be available */
+	for (i = 0; i < koutput->count_modes; i++) {
+		Mode = xnfalloc(sizeof(DisplayModeRec));
+
+		drmmode_ConvertFromKMode(output->scrn, &koutput->modes[i], Mode);
+		Modes = xf86ModesAdd(Modes, Mode);
+
+	}
+	return Modes;
+}
+
+static void
+drmmode_output_destroy(xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	int i;
+
+	if (drmmode_output->edid_blob)
+		drmModeFreePropertyBlob(drmmode_output->edid_blob);
+	for (i = 0; i < drmmode_output->num_props; i++) {
+		drmModeFreeProperty(drmmode_output->props[i].mode_prop);
+		free(drmmode_output->props[i].atoms);
+	}
+	for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) {
+		drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
+		free(drmmode_output->mode_encoders);
+	}
+	free(drmmode_output->props);
+	drmModeFreeConnector(drmmode_output->mode_output);
+	free(drmmode_output);
+	output->driver_private = NULL;
+}
+
+static void
+drmmode_output_dpms(xf86OutputPtr output, int mode)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmModeConnectorPtr koutput = drmmode_output->mode_output;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+
+	drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
+				    drmmode_output->dpms_enum_id, mode);
+	return;
+}
+
+
+static Bool
+drmmode_property_ignore(drmModePropertyPtr prop)
+{
+    if (!prop)
+	return TRUE;
+    /* ignore blob prop */
+    if (prop->flags & DRM_MODE_PROP_BLOB)
+	return TRUE;
+    /* ignore standard property */
+    if (!strcmp(prop->name, "EDID") ||
+	    !strcmp(prop->name, "DPMS"))
+	return TRUE;
+
+    return FALSE;
+}
+
+static void
+drmmode_output_create_resources(xf86OutputPtr output)
+{
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmModeConnectorPtr mode_output = drmmode_output->mode_output;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
+    drmModePropertyPtr drmmode_prop;
+    int i, j, err;
+
+    drmmode_output->props = calloc(mode_output->count_props, sizeof(drmmode_prop_rec));
+    if (!drmmode_output->props)
+	return;
+    
+    drmmode_output->num_props = 0;
+    for (i = 0, j = 0; i < mode_output->count_props; i++) {
+	drmmode_prop = drmModeGetProperty(drmmode->fd, mode_output->props[i]);
+	if (drmmode_property_ignore(drmmode_prop)) {
+	    drmModeFreeProperty(drmmode_prop);
+	    continue;
+	}
+	drmmode_output->props[j].mode_prop = drmmode_prop;
+	drmmode_output->props[j].value = mode_output->prop_values[i];
+	drmmode_output->num_props++;
+	j++;
+    }
+
+    for (i = 0; i < drmmode_output->num_props; i++) {
+	drmmode_prop_ptr p = &drmmode_output->props[i];
+	drmmode_prop = p->mode_prop;
+
+	if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
+	    INT32 range[2];
+	    INT32 value = p->value;
+
+	    p->num_atoms = 1;
+	    p->atoms = calloc(p->num_atoms, sizeof(Atom));
+	    if (!p->atoms)
+		continue;
+	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
+	    range[0] = drmmode_prop->values[0];
+	    range[1] = drmmode_prop->values[1];
+	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
+		    FALSE, TRUE,
+		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
+		    2, range);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRConfigureOutputProperty error, %d\n", err);
+	    }
+	    err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
+		    XA_INTEGER, 32, PropModeReplace, 1, &value, FALSE, TRUE);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRChangeOutputProperty error, %d\n", err);
+	    }
+	} else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) {
+	    p->num_atoms = drmmode_prop->count_enums + 1;
+	    p->atoms = calloc(p->num_atoms, sizeof(Atom));
+	    if (!p->atoms)
+		continue;
+	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
+	    for (j = 1; j <= drmmode_prop->count_enums; j++) {
+		struct drm_mode_property_enum *e = &drmmode_prop->enums[j-1];
+		p->atoms[j] = MakeAtom(e->name, strlen(e->name), TRUE);
+	    }
+	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
+		    FALSE, FALSE,
+		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
+		    p->num_atoms - 1, (INT32 *)&p->atoms[1]);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRConfigureOutputProperty error, %d\n", err);
+	    }
+	    for (j = 0; j < drmmode_prop->count_enums; j++)
+		if (drmmode_prop->enums[j].value == p->value)
+		    break;
+	    /* there's always a matching value */
+	    err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
+		    XA_ATOM, 32, PropModeReplace, 1, &p->atoms[j+1], FALSE, TRUE);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRChangeOutputProperty error, %d\n", err);
+	    }
+	}
+    }
+}
+
+static Bool
+drmmode_output_set_property(xf86OutputPtr output, Atom property,
+		RRPropertyValuePtr value)
+{
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
+    int i;
+
+    for (i = 0; i < drmmode_output->num_props; i++) {
+	drmmode_prop_ptr p = &drmmode_output->props[i];
+
+	if (p->atoms[0] != property)
+	    continue;
+
+	if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) {
+	    uint32_t val;
+
+	    if (value->type != XA_INTEGER || value->format != 32 ||
+		    value->size != 1)
+		return FALSE;
+	    val = *(uint32_t *)value->data;
+
+	    drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id,
+		    p->mode_prop->prop_id, (uint64_t)val);
+	    return TRUE;
+	} else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) {
+	    Atom	atom;
+	    const char	*name;
+	    int		j;
+
+	    if (value->type != XA_ATOM || value->format != 32 || value->size != 1)
+		return FALSE;
+	    memcpy(&atom, value->data, 4);
+	    name = NameForAtom(atom);
+
+	    /* search for matching name string, then set its value down */
+	    for (j = 0; j < p->mode_prop->count_enums; j++) {
+		if (!strcmp(p->mode_prop->enums[j].name, name)) {
+		    drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id,
+			    p->mode_prop->prop_id, p->mode_prop->enums[j].value);
+		    return TRUE;
+		}
+	    }
+	}
+    }
+
+    return TRUE;
+}
+
+static Bool
+drmmode_output_get_property(xf86OutputPtr output, Atom property)
+{
+    return TRUE;
+}
+
+static const xf86OutputFuncsRec drmmode_output_funcs = {
+    .dpms = drmmode_output_dpms,
+    .create_resources = drmmode_output_create_resources,
+#ifdef RANDR_12_INTERFACE
+    .set_property = drmmode_output_set_property,
+    .get_property = drmmode_output_get_property,
+#endif
+    .detect = drmmode_output_detect,
+    .mode_valid = drmmode_output_mode_valid,
+
+    .get_modes = drmmode_output_get_modes,
+    .destroy = drmmode_output_destroy
+};
+
+static int subpixel_conv_table[7] = { 0, SubPixelUnknown,
+				      SubPixelHorizontalRGB,
+				      SubPixelHorizontalBGR,
+				      SubPixelVerticalRGB,
+				      SubPixelVerticalBGR,
+				      SubPixelNone };
+
+const char *output_names[] = { "None",
+			       "VGA",
+			       "DVI",
+			       "DVI",
+			       "DVI",
+			       "Composite",
+			       "S-video",
+			       "LVDS",
+			       "CTV",
+			       "DIN",
+			       "DisplayPort",
+			       "HDMI",
+			       "HDMI",
+			       "TV",
+			       "eDP"
+};
+
+static void
+drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dvi, int *num_hdmi)
+{
+	xf86OutputPtr output;
+	drmModeConnectorPtr koutput;
+	drmModeEncoderPtr *kencoders = NULL;
+	drmmode_output_private_ptr drmmode_output;
+	drmModePropertyPtr props;
+	char name[32];
+	int i;
+	const char *s;
+
+	koutput = drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]);
+	if (!koutput)
+		return;
+
+	kencoders = calloc(sizeof(drmModeEncoderPtr), koutput->count_encoders);
+	if (!kencoders) {
+		goto out_free_encoders;
+	}
+
+	for (i = 0; i < koutput->count_encoders; i++) {
+		kencoders[i] = drmModeGetEncoder(drmmode->fd, koutput->encoders[i]);
+		if (!kencoders[i]) {
+			goto out_free_encoders;
+		}
+	}
+
+	/* need to do smart conversion here for compat with non-kms ATI driver */
+	snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
+
+	output = xf86OutputCreate (pScrn, &drmmode_output_funcs, name);
+	if (!output) {
+		goto out_free_encoders;
+	}
+
+	drmmode_output = calloc(sizeof(drmmode_output_private_rec), 1);
+	if (!drmmode_output) {
+		xf86OutputDestroy(output);
+		goto out_free_encoders;
+	}
+
+	drmmode_output->output_id = drmmode->mode_res->connectors[num];
+	drmmode_output->mode_output = koutput;
+	drmmode_output->mode_encoders = kencoders;
+	drmmode_output->drmmode = drmmode;
+	output->mm_width = koutput->mmWidth;
+	output->mm_height = koutput->mmHeight;
+
+	output->subpixel_order = subpixel_conv_table[koutput->subpixel];
+	output->interlaceAllowed = TRUE;
+	output->doubleScanAllowed = TRUE;
+	output->driver_private = drmmode_output;
+	
+	output->possible_crtcs = 0x7f;
+	for (i = 0; i < koutput->count_encoders; i++) {
+		output->possible_crtcs &= kencoders[i]->possible_crtcs;
+	}
+	/* work out the possible clones later */
+	output->possible_clones = 0;
+
+	for (i = 0; i < koutput->count_props; i++) {
+		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+		if (props && (props->flags & DRM_MODE_PROP_ENUM)) {
+			if (!strcmp(props->name, "DPMS")) {
+				drmmode_output->dpms_enum_id = koutput->props[i];
+				drmModeFreeProperty(props);
+				break;
+			}
+			drmModeFreeProperty(props);
+		}
+	}
+
+	return;
+out_free_encoders:
+	if (kencoders){
+		for (i = 0; i < koutput->count_encoders; i++)
+			drmModeFreeEncoder(kencoders[i]);
+		free(kencoders);
+	}
+	drmModeFreeConnector(koutput);
+	
+}
+
+uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private, clone_drmout;
+	int i;
+	xf86OutputPtr clone_output;
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+	int index_mask = 0;
+
+	if (drmmode_output->enc_clone_mask == 0)
+		return index_mask;
+
+	for (i = 0; i < xf86_config->num_output; i++) {
+		clone_output = xf86_config->output[i];
+		clone_drmout = clone_output->driver_private;
+		if (output == clone_output)
+			continue;
+		
+		if (clone_drmout->enc_mask == 0)
+			continue;
+		if (drmmode_output->enc_clone_mask == clone_drmout->enc_mask)
+			index_mask |= (1 << i);
+	}
+	return index_mask;
+}
+
+
+static void
+drmmode_clones_init(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+{
+	int i, j;
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+	for (i = 0; i < xf86_config->num_output; i++) {
+		xf86OutputPtr output = xf86_config->output[i];
+		drmmode_output_private_ptr drmmode_output;
+
+		drmmode_output = output->driver_private;
+		drmmode_output->enc_clone_mask = 0xff;
+		/* and all the possible encoder clones for this output together */
+		for (j = 0; j < drmmode_output->mode_output->count_encoders; j++)
+		{
+			int k;
+			for (k = 0; k < drmmode->mode_res->count_encoders; k++) {
+				if (drmmode->mode_res->encoders[k] == drmmode_output->mode_encoders[j]->encoder_id)
+					drmmode_output->enc_mask |= (1 << k);
+			}
+
+			drmmode_output->enc_clone_mask &= drmmode_output->mode_encoders[j]->possible_clones;
+		}
+	}
+
+	for (i = 0; i < xf86_config->num_output; i++) {
+		xf86OutputPtr output = xf86_config->output[i];
+		output->possible_clones = find_clones(scrn, output);
+	}
+}
+
+static Bool
+drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
+{
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+	drmmode_crtc_private_ptr
+		    drmmode_crtc = xf86_config->crtc[0]->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	struct dumb_bo *old_front = NULL;
+	Bool	    ret;
+	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
+	uint32_t    old_fb_id;
+	int	    i, pitch, old_width, old_height, old_pitch;
+	int screen_size;
+	int cpp = (scrn->bitsPerPixel + 1) / 8;
+	struct dumb_bo *front_bo;
+	uint32_t tiling_flags = 0;
+	PixmapPtr ppix = screen->GetScreenPixmap(screen);
+	void *new_pixels;
+
+	if (scrn->virtualX == width && scrn->virtualY == height)
+		return TRUE;
+
+	xf86DrvMsg(scrn->scrnIndex, X_INFO,
+		   "Allocate new frame buffer %dx%d stride %d\n",
+		   width, height, pitch / cpp);
+
+	old_width = scrn->virtualX;
+	old_height = scrn->virtualY;
+	old_pitch = scrn->displayWidth;
+	old_fb_id = drmmode->fb_id;
+	old_front = drmmode->front_bo;
+
+	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel);
+	if (!drmmode->front_bo)
+		goto fail;
+
+	pitch = drmmode->front_bo->pitch;
+
+	scrn->virtualX = width;
+	scrn->virtualY = height;
+	scrn->displayWidth = pitch / cpp;
+
+	ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
+			   scrn->bitsPerPixel, pitch,
+			   drmmode->front_bo->handle,
+			   &drmmode->fb_id);
+	if (ret)
+		goto fail;
+	
+	new_pixels  = drmmode_map_front_bo(drmmode);
+	if (!new_pixels)
+		goto fail;
+
+	screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+				   pitch, new_pixels);
+
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0)
+	scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr;
+#endif
+
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+
+		if (!crtc->enabled)
+			continue;
+
+		drmmode_set_mode_major(crtc, &crtc->mode,
+				       crtc->rotation, crtc->x, crtc->y);
+	}
+
+	if (old_fb_id) {
+		drmModeRmFB(drmmode->fd, old_fb_id);
+		dumb_bo_destroy(drmmode->fd, old_front);
+	}
+
+	return TRUE;
+
+ fail:
+	if (drmmode->front_bo)
+		dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
+	drmmode->front_bo = old_front;
+	scrn->virtualX = old_width;
+	scrn->virtualY = old_height;
+	scrn->displayWidth = old_pitch;
+	drmmode->fb_id = old_fb_id;
+
+	return FALSE;
+}
+
+static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
+	drmmode_xf86crtc_resize
+};
+
+Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
+{
+	xf86CrtcConfigPtr xf86_config;
+	int i, num_dvi = 0, num_hdmi = 0;
+
+	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
+	xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+	drmmode->scrn = pScrn;
+	drmmode->cpp = cpp;
+	drmmode->mode_res = drmModeGetResources(drmmode->fd);
+	if (!drmmode->mode_res)
+		return FALSE;
+
+	xf86CrtcSetSizeRange(pScrn, 320, 200, drmmode->mode_res->max_width, drmmode->mode_res->max_height);
+	for (i = 0; i < drmmode->mode_res->count_crtcs; i++)
+		if (!xf86IsEntityShared(pScrn->entityList[0]) || pScrn->confScreen->device->screen == i)
+			drmmode_crtc_init(pScrn, drmmode, i);
+
+	for (i = 0; i < drmmode->mode_res->count_connectors; i++)
+		drmmode_output_init(pScrn, drmmode, i, &num_dvi, &num_hdmi);
+
+	/* workout clones */
+	drmmode_clones_init(pScrn, drmmode);
+
+	xf86InitialConfiguration(pScrn, TRUE);
+
+	return TRUE;
+}
+
+void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct dumb_bo *bo)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+	xf86CrtcPtr crtc = xf86_config->crtc[id];
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+	drmmode_crtc->cursor_bo = bo;
+}
+
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags)
+{
+	xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
+	xf86OutputPtr  output = config->output[config->compat_output];
+	xf86CrtcPtr	crtc = output->crtc;
+
+	if (crtc && crtc->enabled) {
+		drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
+				       x, y);
+	}
+}
+
+Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int c;
+
+	for (c = 0; c < config->num_crtc; c++) {
+		xf86CrtcPtr	crtc = config->crtc[c];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		xf86OutputPtr	output = NULL;
+		int		o;
+
+		/* Skip disabled CRTCs */
+		if (!crtc->enabled) {
+			drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+				       0, 0, 0, NULL, 0, NULL);
+			continue;
+		}
+
+		if (config->output[config->compat_output]->crtc == crtc)
+			output = config->output[config->compat_output];
+		else
+		{
+			for (o = 0; o < config->num_output; o++)
+				if (config->output[o]->crtc == crtc)
+				{
+					output = config->output[o];
+					break;
+				}
+		}
+		/* paranoia */
+		if (!output)
+			continue;
+
+		/* Mark that we'll need to re-set the mode for sure */
+		memset(&crtc->mode, 0, sizeof(crtc->mode));
+		if (!crtc->desiredMode.CrtcHDisplay)
+		{
+			DisplayModePtr  mode = xf86OutputFindClosestMode (output, pScrn->currentMode);
+
+			if (!mode)
+				return FALSE;
+			crtc->desiredMode = *mode;
+			crtc->desiredRotation = RR_Rotate_0;
+			crtc->desiredX = 0;
+			crtc->desiredY = 0;
+		}
+
+		if (!crtc->funcs->set_mode_major(crtc, &crtc->desiredMode, crtc->desiredRotation,
+						 crtc->desiredX, crtc->desiredY))
+			return FALSE;
+	}
+	return TRUE;
+}
+
+static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
+                                 int *indices, LOCO *colors, VisualPtr pVisual)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    uint16_t       lut_r[256], lut_g[256], lut_b[256];
+    int index, j, i;
+    int c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++) {
+        xf86CrtcPtr crtc = xf86_config->crtc[c];
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+        for (i = 0 ; i < 256; i++) {
+            lut_r[i] = drmmode_crtc->lut_r[i] << 6;
+            lut_g[i] = drmmode_crtc->lut_g[i] << 6;
+            lut_b[i] = drmmode_crtc->lut_b[i] << 6;
+        }
+
+        switch(pScrn->depth) {
+        case 15:
+            for (i = 0; i < numColors; i++) {
+                index = indices[i];
+                for (j = 0; j < 8; j++) {
+                    lut_r[index * 8 + j] = colors[index].red << 6;
+                    lut_g[index * 8 + j] = colors[index].green << 6;
+                    lut_b[index * 8 + j] = colors[index].blue << 6;
+                }
+            }
+         break;
+         case 16:
+             for (i = 0; i < numColors; i++) {
+                 index = indices[i];
+
+                  if (i <= 31) {
+                      for (j = 0; j < 8; j++) {
+                          lut_r[index * 8 + j] = colors[index].red << 6;
+                          lut_b[index * 8 + j] = colors[index].blue << 6;
+                      }
+                  }
+
+                  for (j = 0; j < 4; j++) {
+                      lut_g[index * 4 + j] = colors[index].green << 6;
+                  }
+              }
+	  break;
+          default:
+              for (i = 0; i < numColors; i++) {
+                  index = indices[i];
+                  lut_r[index] = colors[index].red << 6;
+                  lut_g[index] = colors[index].green << 6;
+                  lut_b[index] = colors[index].blue << 6;
+              }
+              break;
+          }
+
+    /* Make the change through RandR */
+#ifdef RANDR_12_INTERFACE
+        if (crtc->randr_crtc)
+            RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
+        else
+#endif
+            crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
+     }
+}
+
+Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn)
+{
+    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0,
+                  "Initializing kms color map\n");
+    if (!miCreateDefColormap(pScreen))
+        return FALSE;
+    /* all radeons support 10 bit CLUTs */
+    if (!xf86HandleColormaps(pScreen, 256, 10,
+                             drmmode_load_palette, NULL,
+                             CMAP_PALETTED_TRUECOLOR
+#if 0 /* This option messes up text mode! (eich at suse.de) */
+                             | CMAP_LOAD_EVEN_IF_OFFSCREEN
+#endif
+                             | CMAP_RELOAD_ON_MODE_SWITCH))
+         return FALSE;
+    return TRUE;
+}
+
+#ifdef HAVE_UDEV
+static void
+drmmode_handle_uevents(int fd, void *closure)
+{
+	drmmode_ptr drmmode = closure;
+	ScrnInfoPtr scrn = drmmode->scrn;
+	struct udev_device *dev;
+	dev = udev_monitor_receive_device(drmmode->uevent_monitor);
+	if (!dev)
+		return;
+
+	RRGetInfo(screenInfo.screens[scrn->scrnIndex], TRUE);
+	udev_device_unref(dev);
+}
+#endif
+
+void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+{
+#ifdef HAVE_UDEV
+	struct udev *u;
+	struct udev_monitor *mon;
+
+	u = udev_new();
+	if (!u)
+		return;
+	mon = udev_monitor_new_from_netlink(u, "udev");
+	if (!mon) {
+		udev_unref(u);
+		return;
+	}
+
+	if (udev_monitor_filter_add_match_subsystem_devtype(mon,
+							    "drm",
+							    "drm_minor") < 0 ||
+	    udev_monitor_enable_receiving(mon) < 0) {
+		udev_monitor_unref(mon);
+		udev_unref(u);
+		return;
+	}
+
+	drmmode->uevent_handler =
+		xf86AddGeneralHandler(udev_monitor_get_fd(mon),
+				      drmmode_handle_uevents,
+				      drmmode);
+
+	drmmode->uevent_monitor = mon;
+#endif
+}
+
+void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+{
+#ifdef HAVE_UDEV
+	if (drmmode->uevent_handler) {
+		struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor);
+		xf86RemoveGeneralHandler(drmmode->uevent_handler);
+
+		udev_monitor_unref(drmmode->uevent_monitor);
+		udev_unref(u);
+	}
+#endif
+}
+
+/* create front and cursor BOs */
+Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int width;
+	int height;
+	int bpp;
+	int i;
+
+	width = pScrn->virtualX;
+	height = pScrn->virtualY;
+	bpp = pScrn->bitsPerPixel;
+	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
+	if (!drmmode->front_bo)
+		return FALSE;
+
+
+	width = height = 64;
+	bpp = 32;
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		drmmode_crtc->cursor_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
+	}
+	return TRUE;
+}
+
+void *drmmode_map_front_bo(drmmode_ptr drmmode)
+{
+	int ret;
+
+	if (drmmode->front_bo->ptr)
+		return drmmode->front_bo->ptr;
+
+	ret = dumb_bo_map(drmmode->fd, drmmode->front_bo);
+	if (ret)
+		return NULL;
+
+	return drmmode->front_bo->ptr;
+	
+}
+
+Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int i, ret;
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		ret = dumb_bo_map(drmmode->fd, drmmode_crtc->cursor_bo);
+		if (ret)
+			return FALSE;
+	}
+	return TRUE;
+}
+
+void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int i;
+	dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
+	drmmode->front_bo = NULL;
+
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo);
+	}
+}
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
new file mode 100644
index 0000000..2d72505
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors:
+ *     Dave Airlie <airlied at redhat.com>
+ *
+ */
+#ifndef DRMMODE_DISPLAY_H
+#define DRMMODE_DISPLAY_H
+
+#include "xf86drmMode.h"
+#ifdef HAVE_UDEV
+#include "libudev.h"
+#endif
+
+struct dumb_bo {
+  uint32_t handle;
+  uint32_t size;
+  void *ptr;
+  int map_count;
+  uint32_t pitch;
+};
+
+typedef struct {
+  int fd;
+  unsigned fb_id;
+  drmModeResPtr mode_res;
+  drmModeFBPtr mode_fb;
+  int cpp;
+  ScrnInfoPtr scrn;
+#ifdef HAVE_UDEV
+  struct udev_monitor *uevent_monitor;
+  InputHandlerProc uevent_handler;
+#endif
+  drmEventContext event_context;
+  struct dumb_bo *front_bo;
+} drmmode_rec, *drmmode_ptr;
+
+typedef struct {
+  drmmode_ptr drmmode;
+  unsigned old_fb_id;
+  int flip_count;
+  void *event_data;
+  unsigned int fe_frame;
+  unsigned int fe_tv_sec;
+  unsigned int fe_tv_usec;
+} drmmode_flipdata_rec, *drmmode_flipdata_ptr;
+
+typedef struct {
+  drmmode_flipdata_ptr flipdata;
+  Bool dispatch_me;
+} drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr;
+
+typedef struct {
+    drmmode_ptr drmmode;
+    drmModeCrtcPtr mode_crtc;
+    int hw_id;
+    struct dumb_bo *cursor_bo;
+  //    struct radeon_bo *rotate_bo;
+    unsigned rotate_fb_id;
+    uint16_t lut_r[256], lut_g[256], lut_b[256];
+} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
+
+typedef struct {
+    drmModePropertyPtr mode_prop;
+    uint64_t value;
+    int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */
+    Atom *atoms;
+} drmmode_prop_rec, *drmmode_prop_ptr;
+
+
+typedef struct {
+    drmmode_ptr drmmode;
+    int output_id;
+    drmModeConnectorPtr mode_output;
+    drmModeEncoderPtr *mode_encoders;
+    drmModePropertyBlobPtr edid_blob;
+    int dpms_enum_id;
+    int num_props;
+    drmmode_prop_ptr props;
+    int enc_mask;
+    int enc_clone_mask;
+} drmmode_output_private_rec, *drmmode_output_private_ptr;
+
+
+extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
+//extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr);
+//extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo);
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
+extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
+
+extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode);
+extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
+
+extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling);
+extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
+extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
+
+//Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id);
+Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+void *drmmode_map_front_bo(drmmode_ptr drmmode);
+Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+#endif
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
deleted file mode 100644
index 1f95a2f..0000000
--- a/hw/xfree86/drivers/modesetting/output.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <xf86.h>
-#include <xf86i2c.h>
-#include <xf86Crtc.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#define DPMS_SERVER
-#include <X11/extensions/dpms.h>
-
-#include "X11/Xatom.h"
-
-#include "driver.h"
-
-static char *connector_enum_list[] = {
-    "Unknown",
-    "VGA",
-    "DVI-I",
-    "DVI-D",
-    "DVI-A",
-    "Composite",
-    "SVIDEO",
-    "LVDS",
-    "Component",
-    "9-pin DIN",
-    "DisplayPort",
-    "HDMI Type A",
-    "HDMI Type B",
-};
-
-static void
-dpms(xf86OutputPtr output, int mode)
-{
-}
-
-static void
-save(xf86OutputPtr output)
-{
-}
-
-static void
-restore(xf86OutputPtr output)
-{
-}
-
-static int
-mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
-{
-    return MODE_OK;
-}
-
-static Bool
-mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
-	   DisplayModePtr adjusted_mode)
-{
-    return TRUE;
-}
-
-static void
-prepare(xf86OutputPtr output)
-{
-    dpms(output, DPMSModeOff);
-}
-
-static void
-mode_set(xf86OutputPtr output, DisplayModePtr mode,
-	 DisplayModePtr adjusted_mode)
-{
-}
-
-static void
-commit(xf86OutputPtr output)
-{
-    dpms(output, DPMSModeOn);
-
-    if (output->scrn->pScreen != NULL)
-	xf86_reload_cursors(output->scrn->pScreen);
-}
-
-static xf86OutputStatus
-detect(xf86OutputPtr output)
-{
-    drmModeConnectorPtr drm_connector = output->driver_private;
-
-    switch (drm_connector->connection) {
-    case DRM_MODE_CONNECTED:
-	return XF86OutputStatusConnected;
-    case DRM_MODE_DISCONNECTED:
-	return XF86OutputStatusDisconnected;
-    default:
-	return XF86OutputStatusUnknown;
-    }
-}
-
-static DisplayModePtr
-get_modes(xf86OutputPtr output)
-{
-    drmModeConnectorPtr drm_connector = output->driver_private;
-    struct drm_mode_modeinfo *drm_mode = NULL;
-    DisplayModePtr modes = NULL, mode = NULL;
-    int i;
-
-    for (i = 0; i < drm_connector->count_modes; i++) {
-	drm_mode = &drm_connector->modes[i];
-	if (drm_mode) {
-	    mode = xcalloc(1, sizeof(DisplayModeRec));
-	    if (!mode)
-		continue;
-	    mode->type = 0;
-	    mode->Clock = drm_mode->clock;
-	    mode->HDisplay = drm_mode->hdisplay;
-	    mode->HSyncStart = drm_mode->hsync_start;
-	    mode->HSyncEnd = drm_mode->hsync_end;
-	    mode->HTotal = drm_mode->htotal;
-	    mode->VDisplay = drm_mode->vdisplay;
-	    mode->VSyncStart = drm_mode->vsync_start;
-	    mode->VSyncEnd = drm_mode->vsync_end;
-	    mode->VTotal = drm_mode->vtotal;
-	    mode->Flags = drm_mode->flags;
-	    mode->HSkew = drm_mode->hskew;
-	    mode->VScan = drm_mode->vscan;
-	    mode->VRefresh = xf86ModeVRefresh(mode);
-	    mode->Private = (void *)drm_mode;
-	    xf86SetModeDefaultName(mode);
-	    modes = xf86ModesAdd(modes, mode);
-	    xf86PrintModeline(0, mode);
-	}
-    }
-
-    return modes;
-}
-
-static void
-destroy(xf86OutputPtr output)
-{
-    drmModeFreeConnector(output->driver_private);
-}
-
-static void
-create_resources(xf86OutputPtr output)
-{
-#ifdef RANDR_12_INTERFACE
-#endif /* RANDR_12_INTERFACE */
-}
-
-#ifdef RANDR_12_INTERFACE
-static Bool
-set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
-{
-    return TRUE;
-}
-#endif /* RANDR_12_INTERFACE */
-
-#ifdef RANDR_13_INTERFACE
-static Bool
-get_property(xf86OutputPtr output, Atom property)
-{
-    return TRUE;
-}
-#endif /* RANDR_13_INTERFACE */
-
-#ifdef RANDR_GET_CRTC_INTERFACE
-static xf86CrtcPtr
-get_crtc(xf86OutputPtr output)
-{
-    return NULL;
-}
-#endif
-
-static const xf86OutputFuncsRec output_funcs = {
-    .create_resources = create_resources,
-    .dpms = dpms,
-    .save = save,
-    .restore = restore,
-    .mode_valid = mode_valid,
-    .mode_fixup = mode_fixup,
-    .prepare = prepare,
-    .mode_set = mode_set,
-    .commit = commit,
-    .detect = detect,
-    .get_modes = get_modes,
-#ifdef RANDR_12_INTERFACE
-    .set_property = set_property,
-#endif
-#ifdef RANDR_13_INTERFACE
-    .get_property = get_property,
-#endif
-    .destroy = destroy,
-#ifdef RANDR_GET_CRTC_INTERFACE
-    .get_crtc = get_crtc,
-#endif
-};
-
-void
-output_init(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    xf86OutputPtr output;
-    drmModeResPtr res;
-    drmModeConnectorPtr drm_connector = NULL;
-    drmModeEncoderPtr drm_encoder = NULL;
-    drmModeCrtcPtr crtc;
-    char *name;
-    int c, v, p;
-
-    res = drmModeGetResources(ms->fd);
-    if (res == 0) {
-	DRV_ERROR("Failed drmModeGetResources\n");
-	return;
-    }
-
-    for (c = 0; c < res->count_connectors; c++) {
-	drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
-	if (!drm_connector)
-	    goto out;
-
-	for (p = 0; p < drm_connector->count_props; p++) {
-	    drmModePropertyPtr prop;
-
-	    prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
-
-	    name = NULL;
-	    if (prop) {
-		ErrorF("VALUES %d\n", prop->count_values);
-
-		for (v = 0; v < prop->count_values; v++)
-		    ErrorF("%s %lld\n", prop->name, prop->values[v]);
-	    }
-	}
-
-	name = connector_enum_list[drm_connector->connector_type];
-
-	output = xf86OutputCreate(pScrn, &output_funcs, name);
-	if (!output)
-	    continue;
-
-	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
-	if (drm_encoder) {
-	    output->possible_crtcs = drm_encoder->crtcs;
-	    output->possible_clones = drm_encoder->clones;
-	} else {
-	    output->possible_crtcs = 0;
-	    output->possible_clones = 0;
-	}
-	output->driver_private = drm_connector;
-	output->subpixel_order = SubPixelHorizontalRGB;
-	output->interlaceAllowed = FALSE;
-	output->doubleScanAllowed = FALSE;
-    }
-
-  out:
-    drmModeFreeResources(res);
-}
commit e2f8315daefc6e56ac8395a9f58f87bbf0809039
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Mar 10 09:13:50 2011 +1000

    drop exa
    
    don't provide accel in this framework

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index e3cc3cc..23e78b7 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -38,7 +38,6 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 output.c \
 	 crtc.c \
-	 exa.c \
 	 dri2.c
 
 EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 0e6f4c8..6b70d4b 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -126,16 +126,6 @@ static const OptionInfoRec Options[] = {
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
-static const char *exaSymbols[] = {
-    "exaGetVersion",
-    "exaDriverInit",
-    "exaDriverFini",
-    "exaOffscreenAlloc",
-    "exaOffscreenFree",
-    "exaWaitSync",
-    NULL
-};
-
 static const char *fbSymbols[] = {
     "fbPictureInit",
     "fbScreenInit",
@@ -188,7 +178,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * Tell the loader about symbols from other modules that this module
 	 * might refer to.
 	 */
-	LoaderRefSymLists(exaSymbols, fbSymbols, ddcSymbols, NULL);
+	LoaderRefSymLists(fbSymbols, ddcSymbols, NULL);
 
 	/*
 	 * The return value must be non-NULL on success even though there
@@ -415,14 +405,11 @@ CreateFrontBuffer(ScrnInfoPtr pScrn)
     Bool fbAccessDisabled;
     int flags;
 
-    ms->noEvict = TRUE;
     pScreen->ModifyPixmapHeader(rootPixmap,
 				pScrn->virtualX, pScrn->virtualY,
 				pScrn->depth, pScrn->bitsPerPixel,
 				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
 				NULL);
-    ms->noEvict = FALSE;
-
     drmModeAddFB(ms->fd,
 		 pScrn->virtualX,
 		 pScrn->virtualY,
@@ -633,8 +620,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     xf86LoaderReqSymLists(fbSymbols, NULL);
 
-    xf86LoadSubModule(pScrn, "exa");
-
 #ifdef DRI2
     xf86LoadSubModule(pScrn, "dri2");
 #endif
@@ -667,8 +652,6 @@ CreateScreenResources(ScreenPtr pScreen)
     Bool ret;
     int flags;
 
-    ms->noEvict = TRUE;
-
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
@@ -678,8 +661,6 @@ CreateScreenResources(ScreenPtr pScreen)
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL))
 	FatalError("Couldn't adjust screen pixmap\n");
 
-    ms->noEvict = FALSE;
-
     drmModeAddFB(ms->fd,
 		 pScrn->virtualX,
 		 pScrn->virtualY,
@@ -771,8 +752,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     xf86SetBlackWhitePixels(pScreen);
 
-    ms->exa = ExaInit(pScrn);
-
     miInitializeBackingStore(pScreen);
     xf86SetBackingStore(pScreen);
     xf86SetSilkenMouse(pScreen);
@@ -933,9 +912,6 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 
     pScreen->CreateScreenResources = ms->createScreenResources;
 
-    if (ms->exa)
-	ExaClose(pScrn);
-
     drmClose(ms->fd);
     ms->fd = -1;
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 5b31188..a673f8f 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -32,7 +32,6 @@
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 #include <xf86mm.h>
-#include "exa.h"
 
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
 
@@ -71,10 +70,7 @@ typedef struct _modesettingRec
 
     CreateScreenResourcesProcPtr createScreenResources;
 
-    /* exa */
-    void *exa;
     void *driver;
-    Bool noEvict;
 
     /* dri2 */
     drm_context_t context;
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
deleted file mode 100644
index f688472..0000000
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ /dev/null
@@ -1,850 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-/* FIXME ! */
-#define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri"
-
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "driver.h"
-#include <dlfcn.h>
-
-#include "pipe/p_winsys.h"
-#include "pipe/p_format.h"
-#include "pipe/p_context.h"
-#include "pipe/p_util.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-
-/* EXA winsys */
-struct exa_context
-{
-};
-
-struct exa_winsys
-{
-    struct pipe_winsys base;
-    modesettingPtr ms;
-};
-
-struct exa_buffer
-{
-    struct pipe_buffer base;
-    drmBO bo;
-    boolean userBuffer;	/** Is this a user-space buffer? */
-    //void *data;
-    //void *mapped;
-};
-
-struct exa_surface
-{
-    struct pipe_surface surface;
-};
-
-struct exa_entity
-{
-    ExaDriverPtr pExa;
-    struct exa_context *c;
-    struct pipe_winsys *ws;
-    struct pipe_context *ctx;
-    struct pipe_screen *scrn;
-};
-
-static INLINE struct exa_winsys *
-exa_get_winsys(struct pipe_winsys *ws)
-{
-    return (struct exa_winsys *)ws;
-}
-
-static INLINE struct exa_surface *
-exa_get_surface(struct pipe_surface *ps)
-{
-    return (struct exa_surface *)ps;
-}
-
-static INLINE struct exa_buffer *
-exa_get_buffer(struct pipe_buffer *buf)
-{
-    return (struct exa_buffer *)buf;
-}
-
-static void *
-exa_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf,
-	       unsigned flags)
-{
-    struct exa_buffer *exa_buf = exa_get_buffer(buf);
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-    void *virtual;
-
-    drmBOMap(exa_winsys->ms->fd,
-	     &exa_buf->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
-
-    return virtual;
-}
-
-static void
-exa_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
-{
-    struct exa_buffer *exa_buf = exa_get_buffer(buf);
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-
-    drmBOUnmap(exa_winsys->ms->fd, &exa_buf->bo);
-}
-
-static void
-exa_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf)
-{
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-    struct exa_buffer *exa_buf = exa_get_buffer(buf);
-
-    drmBOUnreference(exa_winsys->ms->fd, &exa_buf->bo);
-
-    free(exa_buf);
-}
-
-static void
-exa_flush_frontbuffer(struct pipe_winsys *pws,
-		      struct pipe_surface *surf, void *context_private)
-{
-    struct exa_buffer *exa_buf = exa_get_buffer(surf->buffer);
-
-    ErrorF("WANT TO FLUSH\n");
-}
-
-static const char *
-exa_get_name(struct pipe_winsys *pws)
-{
-    return "EXA";
-}
-
-static struct pipe_buffer *
-exa_buffer_create(struct pipe_winsys *pws,
-		  unsigned alignment, unsigned usage, unsigned size)
-{
-    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-    unsigned int flags = 0;
-
-    buffer->base.refcount = 1;
-    buffer->base.alignment = alignment;
-    buffer->base.usage = usage;
-    buffer->base.size = size;
-
-    if (exa_winsys->ms->noEvict) {
-	flags = DRM_BO_FLAG_NO_EVICT;
-	ErrorF("DISPLAY TARGET\n");
-    }
-
-    ErrorF("SIZE %d %d\n", size, alignment);
-    if (!buffer->bo.handle) {
-	// buffer->data = align_malloc(size, alignment);
-	drmBOCreate(exa_winsys->ms->fd, size, 0, NULL,
-		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE |
-		    DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT |
-		    DRM_BO_FLAG_MAPPABLE | flags,
-		    0, &buffer->bo);
-    }
-
-    return &buffer->base;
-}
-
-static struct pipe_buffer *
-exa_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
-{
-    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
-
-    buffer->base.refcount = 1;
-    buffer->base.size = bytes;
-    buffer->userBuffer = TRUE;
-    //buffer->data = ptr;
-    ErrorF("USERBUFFER\n");
-
-    return &buffer->base;
-}
-
-/**
- * Round n up to next multiple.
- */
-static INLINE unsigned
-round_up(unsigned n, unsigned multiple)
-{
-    return (n + multiple - 1) & ~(multiple - 1);
-}
-
-static int
-exa_surface_alloc_storage(struct pipe_winsys *winsys,
-			  struct pipe_surface *surf,
-			  unsigned width, unsigned height,
-			  enum pipe_format format,
-			  unsigned flags, unsigned tex_usage)
-{
-    const unsigned alignment = 64;
-
-    surf->width = width;
-    surf->height = height;
-    surf->format = format;
-    pf_get_block(format, &surf->block);
-    surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
-
-    assert(!surf->buffer);
-    surf->buffer = winsys->buffer_create(winsys, alignment,
-					 PIPE_BUFFER_USAGE_PIXEL,
-					 surf->stride * height);
-    if (!surf->buffer)
-	return -1;
-
-    return 0;
-}
-
-/**
- * Called via winsys->surface_alloc() to create new surfaces.
- */
-static struct pipe_surface *
-exa_surface_alloc(struct pipe_winsys *ws)
-{
-    struct exa_surface *wms = xcalloc(1, sizeof(struct exa_surface));
-
-    assert(ws);
-
-    wms->surface.refcount = 1;
-    wms->surface.winsys = ws;
-
-    return &wms->surface;
-}
-
-static void
-exa_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
-{
-    struct pipe_surface *surf = *s;
-
-    surf->refcount--;
-    if (surf->refcount == 0) {
-	if (surf->buffer)
-	    pipe_buffer_reference(winsys, &surf->buffer, NULL);
-	free(surf);
-    }
-    *s = NULL;
-}
-
-/*
- * Fence functions - basically nothing to do, as we don't create any actual
- * fence objects.
- */
-static void
-exa_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
-		    struct pipe_fence_handle *fence)
-{
-}
-
-static int
-exa_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-		    unsigned flag)
-{
-    return 0;
-}
-
-static int
-exa_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-		 unsigned flag)
-{
-    return 0;
-}
-
-struct pipe_winsys *
-exa_get_pipe_winsys(modesettingPtr ms)
-{
-    static struct exa_winsys *ws = NULL;
-
-    if (!ws) {
-	ws = xcalloc(1, sizeof(struct exa_winsys));
-
-	/* Fill in this struct with callbacks that pipe will need to
-	 * communicate with the window system, buffer manager, etc. 
-	 */
-	ws->base.buffer_create = exa_buffer_create;
-	ws->base.user_buffer_create = exa_user_buffer_create;
-	ws->base.buffer_map = exa_buffer_map;
-	ws->base.buffer_unmap = exa_buffer_unmap;
-	ws->base.buffer_destroy = exa_buffer_destroy;
-
-	ws->base.surface_alloc = exa_surface_alloc;
-	ws->base.surface_alloc_storage = exa_surface_alloc_storage;
-	ws->base.surface_release = exa_surface_release;
-
-	ws->base.fence_reference = exa_fence_reference;
-	ws->base.fence_signalled = exa_fence_signalled;
-	ws->base.fence_finish = exa_fence_finish;
-
-	ws->base.flush_frontbuffer = exa_flush_frontbuffer;
-	ws->base.get_name = exa_get_name;
-
-	ws->ms = ms;
-    }
-
-    return &ws->base;
-}
-
-/* EXA functions */
-
-struct PixmapPriv
-{
-    drmBO bo;
-#if 0
-    dri_fence *fence;
-#endif
-    int flags;
-
-    struct pipe_texture *tex;
-    unsigned int color;
-    struct pipe_surface *src_surf;     /* for copies */
-};
-
-static enum pipe_format
-exa_get_pipe_format(int depth)
-{
-    switch (depth) {
-    case 32:
-    case 24:
-	return PIPE_FORMAT_A8R8G8B8_UNORM;
-    case 16:
-	return PIPE_FORMAT_R5G6B5_UNORM;
-    case 15:
-	return PIPE_FORMAT_A1R5G5B5_UNORM;
-    case 8:
-    case 4:
-    case 1:
-	return PIPE_FORMAT_A8R8G8B8_UNORM;	/* bad bad bad */
-    default:
-	assert(0);
-	return 0;
-    }
-}
-
-/*
- * EXA functions
- */
-
-static void
-ExaWaitMarker(ScreenPtr pScreen, int marker)
-{
-}
-
-static int
-ExaMarkSync(ScreenPtr pScreen)
-{
-    return 1;
-}
-
-Bool
-ExaPrepareAccess(PixmapPtr pPix, int index)
-{
-    ScreenPtr pScreen = pPix->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    struct exa_entity *exa = ms->exa;
-    struct PixmapPriv *priv;
-    int ret;
-
-    priv = exaGetPixmapDriverPrivate(pPix);
-
-    if (!priv)
-	return FALSE;
-
-    if (!priv->tex)
-	return FALSE;
-    {
-	struct pipe_surface *surf =
-	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				       PIPE_BUFFER_USAGE_CPU_READ |
-				       PIPE_BUFFER_USAGE_CPU_WRITE);
-	pPix->devPrivate.ptr =
-	    exa->scrn->surface_map(exa->scrn, surf,
-				   PIPE_BUFFER_USAGE_CPU_READ |
-				   PIPE_BUFFER_USAGE_CPU_WRITE);
-	exa->scrn->tex_surface_release(exa->scrn, &surf);
-    }
-
-    return TRUE;
-}
-
-void
-ExaFinishAccess(PixmapPtr pPix, int index)
-{
-    ScreenPtr pScreen = pPix->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    struct PixmapPriv *priv;
-    struct exa_entity *exa = ms->exa;
-    int ret;
-
-    priv = exaGetPixmapDriverPrivate(pPix);
-
-    if (!priv)
-	return;
-
-    if (!priv->tex)
-	return;
-    {
-	struct pipe_surface *surf =
-	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				       PIPE_BUFFER_USAGE_CPU_READ |
-				       PIPE_BUFFER_USAGE_CPU_WRITE);
-	exa->scrn->surface_unmap(exa->scrn, surf);
-	exa->scrn->tex_surface_release(exa->scrn, &surf);
-	pPix->devPrivate.ptr = NULL;
-    }
-}
-
-static void
-ExaDone(PixmapPtr pPixmap)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    struct exa_entity *exa = ms->exa;
-
-    if (!priv)
-	return;
-
-    if (priv->src_surf)
-	exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf);
-    priv->src_surf = NULL;
-}
-
-static void
-ExaDoneComposite(PixmapPtr pPixmap)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-}
-
-static Bool
-ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    struct exa_entity *exa = ms->exa;
-
-    if (pPixmap->drawable.depth < 15)
-	return FALSE;
-
-    if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
-	return FALSE;
-
-    if (!priv || !priv->tex)
-	return FALSE;
-
-    if (alu != GXcopy)
-	return FALSE;
-
-    if (!exa->ctx || !exa->ctx->surface_fill)
-	return FALSE;
-
-    priv->color = fg;
-
-    return TRUE;
-}
-
-static void
-ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    struct pipe_surface *surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_GPU_READ |
-				   PIPE_BUFFER_USAGE_GPU_WRITE);
-
-    exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0,
-			   priv->color);
-
-    exa->scrn->tex_surface_release(exa->scrn, &surf);
-}
-
-static Bool
-ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
-	       int ydir, int alu, Pixel planeMask)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct pipe_surface *src_surf;
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
-    struct PixmapPriv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap);
-
-    if (alu != GXcopy)
-	return FALSE;
-
-    if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15)
-	return FALSE;
-
-    if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
-	return FALSE;
-
-    if (!priv || !src_priv)
-	return FALSE;
-
-    if (!priv->tex || !src_priv->tex)
-	return FALSE;
-
-    if (!exa->ctx || !exa->ctx->surface_copy)
-	return FALSE;
-
-    priv->src_surf =
-	exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_GPU_READ |
-				   PIPE_BUFFER_USAGE_GPU_WRITE);
-
-    return FALSE;
-}
-
-static void
-ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
-	int width, int height)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
-    struct pipe_surface *surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_GPU_READ |
-				   PIPE_BUFFER_USAGE_GPU_WRITE);
-
-    exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf,
-			   srcX, srcY, width, height);
-    exa->scrn->tex_surface_release(exa->scrn, &surf);
-}
-
-static Bool
-ExaPrepareComposite(int op, PicturePtr pSrcPicture,
-		    PicturePtr pMaskPicture, PicturePtr pDstPicture,
-		    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
-{
-    ScreenPtr pScreen = pDst->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-
-    return FALSE;
-}
-
-static Bool
-ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
-		  int src_pitch)
-{
-    ScreenPtr pScreen = pDst->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-
-    ErrorF("UPLOAD\n");
-
-    return FALSE;
-}
-
-static void
-ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
-	     int dstX, int dstY, int width, int height)
-{
-    ScreenPtr pScreen = pDst->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-}
-
-static Bool
-ExaCheckComposite(int op,
-		  PicturePtr pSrcPicture, PicturePtr pMaskPicture,
-		  PicturePtr pDstPicture)
-{
-    DrawablePtr pDraw = pSrcPicture->pDrawable;
-    int w = pDraw->width;
-    int h = pDraw->height;
-
-    return FALSE;
-}
-
-static void *
-ExaCreatePixmap(ScreenPtr pScreen, int size, int align)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct PixmapPriv *priv;
-    void *virtual;
-
-    priv = xcalloc(1, sizeof(struct PixmapPriv));
-    if (!priv)
-	return NULL;
-
-    return priv;
-}
-
-static void
-ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
-{
-    struct PixmapPriv *priv = (struct PixmapPriv *)dPriv;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-
-    if (!priv)
-	return;
-
-    if (priv->tex)
-	exa->scrn->texture_release(exa->scrn, &priv->tex);
-
-    xfree(priv);
-}
-
-static Bool
-ExaPixmapIsOffscreen(PixmapPtr pPixmap)
-{
-    struct PixmapPriv *priv;
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-
-    priv = exaGetPixmapDriverPrivate(pPixmap);
-
-    if (!priv)
-	return FALSE;
-
-    if (priv->tex)
-	return TRUE;
-
-    return FALSE;
-}
-
-/* FIXME !! */
-unsigned int
-driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags)
-{
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct exa_buffer *exa_buf;
-    struct pipe_surface *surf;
-    struct PixmapPriv *priv;
-
-    *flags = 0;
-
-    if (!ms->exa) {
-	FatalError("NO MS->EXA\n");
-	return 0;
-    }
-
-    priv = exaGetPixmapDriverPrivate(pPixmap);
-
-    if (!priv) {
-	FatalError("NO PIXMAP PRIVATE\n");
-	return 0;
-    }
-
-    surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_CPU_READ |
-				   PIPE_BUFFER_USAGE_CPU_WRITE);
-    exa_buf = exa_get_buffer(surf->buffer);
-    exa->scrn->tex_surface_release(exa->scrn, &surf);
-
-    if (exa_buf->bo.handle)
-	return exa_buf->bo.handle;
-
-    return 0;
-}
-
-static Bool
-ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
-		      int depth, int bitsPerPixel, int devKind,
-		      pointer pPixData)
-{
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    struct exa_entity *exa = ms->exa;
-
-    if (!priv)
-	return FALSE;
-
-    if (depth <= 0)
-	depth = pPixmap->drawable.depth;
-
-    if (bitsPerPixel <= 0)
-	bitsPerPixel = pPixmap->drawable.bitsPerPixel;
-
-    if (width <= 0)
-	width = pPixmap->drawable.width;
-
-    if (height <= 0)
-	height = pPixmap->drawable.height;
-
-    if (width <= 0 || height <= 0 || depth <= 0)
-	return FALSE;
-
-    miModifyPixmapHeader(pPixmap, width, height, depth,
-			     bitsPerPixel, devKind, NULL);
-
-    /* Deal with screen resize */
-    if (priv->tex) {
-	struct pipe_surface *surf =
-	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				       PIPE_BUFFER_USAGE_CPU_READ |
-				       PIPE_BUFFER_USAGE_CPU_WRITE);
-
-	ErrorF("RESIZE %d %d to %d %d\n", surf->width, surf->height, width,
-	       height);
-	if (surf->width != width || surf->height != height) {
-	    exa->scrn->texture_release(exa->scrn, &priv->tex);
-	    priv->tex = NULL;
-	}
-	exa->scrn->tex_surface_release(exa->scrn, &surf);
-    }
-
-    if (!priv->tex) {
-	struct pipe_texture template;
-
-	memset(&template, 0, sizeof(template));
-	template.target = PIPE_TEXTURE_2D;
-	template.compressed = 0;
-	template.format = exa_get_pipe_format(depth);
-	pf_get_block(template.format, &template.block);
-	template.width[0] = width;
-	template.height[0] = height;
-	template.depth[0] = 1;
-	template.last_level = 0;
-	template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
-	priv->tex = exa->scrn->texture_create(exa->scrn, &template);
-    }
-
-    return TRUE;
-}
-
-void
-ExaClose(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-
-    exaDriverFini(pScrn->pScreen);
-
-    dlclose(ms->driver);
-}
-
-void *
-ExaInit(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa;
-    ExaDriverPtr pExa;
-
-    exa = xcalloc(1, sizeof(struct exa_entity));
-    if (!exa)
-	return NULL;
-
-    pExa = exaDriverAlloc();
-    if (!pExa) {
-	goto out_err;
-    }
-
-    memset(pExa, 0, sizeof(*pExa));
-    pExa->exa_major = 2;
-    pExa->exa_minor = 4;
-    pExa->memoryBase = 0;
-    pExa->memorySize = 0;
-    pExa->offScreenBase = 0;
-    pExa->pixmapOffsetAlign = 0;
-    pExa->pixmapPitchAlign = 1;
-    pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
-    pExa->maxX = 8191;		       /* FIXME */
-    pExa->maxY = 8191;		       /* FIXME */
-    pExa->WaitMarker = ExaWaitMarker;
-    pExa->MarkSync = ExaMarkSync;
-    pExa->PrepareSolid = ExaPrepareSolid;
-    pExa->Solid = ExaSolid;
-    pExa->DoneSolid = ExaDone;
-    pExa->PrepareCopy = ExaPrepareCopy;
-    pExa->Copy = ExaCopy;
-    pExa->DoneCopy = ExaDone;
-    pExa->CheckComposite = ExaCheckComposite;
-    pExa->PrepareComposite = ExaPrepareComposite;
-    pExa->Composite = ExaComposite;
-    pExa->DoneComposite = ExaDoneComposite;
-    pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
-    pExa->PrepareAccess = ExaPrepareAccess;
-    pExa->FinishAccess = ExaFinishAccess;
-    pExa->UploadToScreen = ExaUploadToScreen;
-    pExa->CreatePixmap = ExaCreatePixmap;
-    pExa->DestroyPixmap = ExaDestroyPixmap;
-    pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
-
-    if (!exaDriverInit(pScrn->pScreen, pExa)) {
-	goto out_err;
-    }
-
-    {
-	char filename[128];
-	char dri_driver_path[] = DRI_DRIVER_PATH;
-
-	snprintf(filename, sizeof filename,
-		 "%s/%s_dri.so", dri_driver_path, "i915");
-
-	ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL);
-	if (!ms->driver)
-		FatalError("failed to initialize i915 - for softpipe only.\n");
-
-	exa->c = xcalloc(1, sizeof(struct exa_context));
-
-	exa->ws = exa_get_pipe_winsys(ms);
-	if (!exa->ws)
-		FatalError("BAD WINSYS\n");
-
-	exa->scrn = softpipe_create_screen(exa->ws);
-	if (!exa->scrn)
-		FatalError("BAD SCREEN\n");
-
-	exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL);
-	if (!exa->ctx)
-	   	FatalError("BAD CTX\n");
-
-	exa->ctx->priv = exa->c;
-    }
-
-    return (void *)exa;
-
-  out_err:
-    ExaClose(pScrn);
-
-    return NULL;
-}
commit 1f0e69b3a13258b79bffdec76b46f7960eb334b3
Author: Matt Turner <mattst88 at gmail.com>
Date:   Mon Mar 8 10:54:21 2010 -0500

    Don't check for Xinerama.
    
    It doesn't seem to be used anywhere, so don't require it.
    
    CC: Jerome Glisse <jglisse at redhat.com>
    CC: Alex Deucher <alexdeucher at gmail.com>
    CC: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Matt Turner <mattst88 at gmail.com>
commit 9c4c323d50bd8b369e82a1dff28abdc15a219a5e
Author: Thomas Hellstrom <thomas-at-tungstengraphics.com>
Date:   Mon Jun 30 18:59:13 2008 +0100

    Avoid an EXA init segfault.
    Don't allocate each VRAM buffer with a 16MB alignment.

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 8368114..f688472 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -168,10 +168,10 @@ exa_buffer_create(struct pipe_winsys *pws,
     ErrorF("SIZE %d %d\n", size, alignment);
     if (!buffer->bo.handle) {
 	// buffer->data = align_malloc(size, alignment);
-	drmBOCreate(exa_winsys->ms->fd, size, 4096, NULL,
+	drmBOCreate(exa_winsys->ms->fd, size, 0, NULL,
 		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE |
 		    DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT |
-		    DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_CACHED_MAPPED | flags,
+		    DRM_BO_FLAG_MAPPABLE | flags,
 		    0, &buffer->bo);
     }
 
@@ -767,7 +767,7 @@ ExaInit(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
     struct exa_entity *exa;
-    ExaDriverPtr pExa = exa->pExa;
+    ExaDriverPtr pExa;
 
     exa = xcalloc(1, sizeof(struct exa_entity));
     if (!exa)
commit a65888d6785934a669ad3b822bf2d636db351858
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Fri Jun 27 17:32:28 2008 +0100

    fixes for gallium stride changes

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 5cf1d96..8368114 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -213,13 +213,13 @@ exa_surface_alloc_storage(struct pipe_winsys *winsys,
     surf->width = width;
     surf->height = height;
     surf->format = format;
-    surf->cpp = pf_get_size(format);
-    surf->pitch = round_up(width, alignment / surf->cpp);
+    pf_get_block(format, &surf->block);
+    surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
 
     assert(!surf->buffer);
     surf->buffer = winsys->buffer_create(winsys, alignment,
 					 PIPE_BUFFER_USAGE_PIXEL,
-					 surf->pitch * surf->cpp * height);
+					 surf->stride * height);
     if (!surf->buffer)
 	return -1;
 
@@ -739,7 +739,7 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
 	template.target = PIPE_TEXTURE_2D;
 	template.compressed = 0;
 	template.format = exa_get_pipe_format(depth);
-	template.cpp = pf_get_size(template.format);
+	pf_get_block(template.format, &template.block);
 	template.width[0] = width;
 	template.height[0] = height;
 	template.depth[0] = 1;
commit e0c43fff3208350995c45604624dd4825f40598c
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Fri Jun 27 09:46:24 2008 +0100

    More error checking

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index a804feb..5cf1d96 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -695,11 +695,6 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     struct exa_entity *exa = ms->exa;
 
-    if (rootPixmap == pPixmap) {
-	miModifyPixmapHeader(pPixmap, width, height, depth,
-			     bitsPerPixel, devKind, NULL);
-    }
-
     if (!priv)
 	return FALSE;
 
@@ -718,6 +713,9 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
     if (width <= 0 || height <= 0 || depth <= 0)
 	return FALSE;
 
+    miModifyPixmapHeader(pPixmap, width, height, depth,
+			     bitsPerPixel, devKind, NULL);
+
     /* Deal with screen resize */
     if (priv->tex) {
 	struct pipe_surface *surf =
@@ -750,9 +748,6 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
 	priv->tex = exa->scrn->texture_create(exa->scrn, &template);
     }
 
-    if (rootPixmap == pPixmap)
-	return TRUE;
-
     return TRUE;
 }
 
@@ -826,17 +821,22 @@ ExaInit(ScrnInfoPtr pScrn)
 		 "%s/%s_dri.so", dri_driver_path, "i915");
 
 	ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL);
+	if (!ms->driver)
+		FatalError("failed to initialize i915 - for softpipe only.\n");
 
 	exa->c = xcalloc(1, sizeof(struct exa_context));
 
 	exa->ws = exa_get_pipe_winsys(ms);
+	if (!exa->ws)
+		FatalError("BAD WINSYS\n");
 
 	exa->scrn = softpipe_create_screen(exa->ws);
+	if (!exa->scrn)
+		FatalError("BAD SCREEN\n");
 
 	exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL);
-
 	if (!exa->ctx)
-	    ErrorF("BAD CTX\n");
+	   	FatalError("BAD CTX\n");
 
 	exa->ctx->priv = exa->c;
     }
commit 387ec961f2a5e791fd010906a5115cf8393471f3
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 23:34:51 2008 +0100

    add --with-gallium-dir to specify location of gallium tree

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index a182d44..e3cc3cc 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -26,7 +26,8 @@ SUBDIRS =
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
 AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \
-	@XMODES_CFLAGS@
+	-I at GALLIUM_DIR@/src/gallium/include \
+	-I at GALLIUM_DIR@/src/gallium/auxiliary
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
 modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm
commit 410b0a4254ca48548b443c1e8fbbcf7a6b9aa862
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:49:33 2008 +0100

    NULL checks

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index cab6870..a804feb 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -463,7 +463,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
     if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
 	return FALSE;
 
-    if (!priv->tex)
+    if (!priv || !priv->tex)
 	return FALSE;
 
     if (alu != GXcopy)
@@ -515,6 +515,9 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
     if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
 	return FALSE;
 
+    if (!priv || !src_priv)
+	return FALSE;
+
     if (!priv->tex || !src_priv->tex)
 	return FALSE;
 
commit 621fa337fb53d535f53cec30bb7161801001bb7f
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:47:20 2008 +0100

    Fix copy surface

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 124dc03..cab6870 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -504,6 +504,7 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
     struct exa_entity *exa = ms->exa;
     struct pipe_surface *src_surf;
     struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
+    struct PixmapPriv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap);
 
     if (alu != GXcopy)
 	return FALSE;
@@ -514,14 +515,14 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
     if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
 	return FALSE;
 
-    if (!priv->tex)
+    if (!priv->tex || !src_priv->tex)
 	return FALSE;
 
     if (!exa->ctx || !exa->ctx->surface_copy)
 	return FALSE;
 
     priv->src_surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+	exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0,
 				   PIPE_BUFFER_USAGE_GPU_READ |
 				   PIPE_BUFFER_USAGE_GPU_WRITE);
 
@@ -691,7 +692,7 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     struct exa_entity *exa = ms->exa;
 
-    /*if (rootPixmap == pPixmap) */  {
+    if (rootPixmap == pPixmap) {
 	miModifyPixmapHeader(pPixmap, width, height, depth,
 			     bitsPerPixel, devKind, NULL);
     }
commit ccd0c76472a7d8a85aed0ea6fea4011109f305d6
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:27:44 2008 +0100

    Add EXA winsys for gallium pipe driver interface.
    
    Plug in the EXA framework into the pipe driver
    for surface_copy & surface_fill.
    
    Back pixmaps with drmBO's including the front buffer.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 6bf6388..0e6f4c8 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -40,7 +40,6 @@
 #include "xf86Resources.h"
 #include "mipointer.h"
 #include "micmap.h"
-#include "shadowfb.h"
 #include <X11/extensions/randr.h>
 #include "fb.h"
 #include "edid.h"
@@ -50,7 +49,6 @@
 #include "dixstruct.h"
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
-#include "shadow.h"
 #include <xorg-server.h>
 #if XSERVER_LIBPCIACCESS
 #include <pciaccess.h>
@@ -120,15 +118,11 @@ static PciChipsets PciDevices[] = {
 
 typedef enum
 {
-    OPTION_NOACCEL,
     OPTION_SW_CURSOR,
-    OPTION_SHADOWFB,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
-    {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
-    {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -154,12 +148,6 @@ static const char *ddcSymbols[] = {
     NULL
 };
 
-static const char *shadowSymbols[] = {
-    "shadowInit",
-    "shadowUpdatePackedWeak",
-    NULL
-};
-
 static const char *i2cSymbols[] = {
     "xf86CreateI2CBusRec",
     "xf86I2CBusInit",
@@ -200,7 +188,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * Tell the loader about symbols from other modules that this module
 	 * might refer to.
 	 */
-	LoaderRefSymLists(exaSymbols, fbSymbols, shadowSymbols, ddcSymbols, NULL);
+	LoaderRefSymLists(exaSymbols, fbSymbols, ddcSymbols, NULL);
 
 	/*
 	 * The return value must be non-NULL on success even though there
@@ -323,7 +311,6 @@ Probe(DriverPtr drv, int flags)
 	if (numUsed > 0)
 	    foundScreen = TRUE;
     } else {
-	ErrorF("NUMUSED %d\n", numUsed);
 	for (i = 0; i < numUsed; i++) {
 	    ScrnInfoPtr pScrn = NULL;
 
@@ -420,54 +407,21 @@ ProbeDDC(ScrnInfoPtr pScrn, int index)
 }
 
 static Bool
-MapMem(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    drmBOMap(ms->fd,
-	     &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
-
-    ms->virtual = ms->bo.virtual;
-
-    return TRUE;
-}
-
-static Bool
-UnmapMem(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    drmBOUnmap(ms->fd, &ms->bo);
-
-    return TRUE;
-}
-
-static void
-LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
-	    LOCO * colors, VisualPtr pVisual)
-{
-    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-}
-
-static Bool
 CreateFrontBuffer(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
     ScreenPtr pScreen = pScrn->pScreen;
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     Bool fbAccessDisabled;
-    CARD8 *fbstart;
+    int flags;
 
-    drmBOCreate(ms->fd,
-		pScrn->virtualY * pScrn->displayWidth *
-		pScrn->bitsPerPixel / 8, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-		| DRM_BO_FLAG_CACHED_MAPPED
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
-		0, &ms->bo);
-
-    MapMem(pScrn);
+    ms->noEvict = TRUE;
+    pScreen->ModifyPixmapHeader(rootPixmap,
+				pScrn->virtualX, pScrn->virtualY,
+				pScrn->depth, pScrn->bitsPerPixel,
+				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+				NULL);
+    ms->noEvict = FALSE;
 
     drmModeAddFB(ms->fd,
 		 pScrn->virtualX,
@@ -475,50 +429,12 @@ CreateFrontBuffer(ScrnInfoPtr pScrn)
 		 pScrn->depth,
 		 pScrn->bitsPerPixel,
 		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 ms->bo.handle, &ms->fb_id);
-
-    if (ms->shadowFB) {
-	if ((ms->shadowMem =
-	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
-			 pScrn->bitsPerPixel)) == NULL) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		       "Allocation of shadow memory failed\n");
-	    return FALSE;
-	}
-	fbstart = ms->shadowMem;
-    } else {
-	fbstart = ms->bo.virtual;
-    }
-
-    /*
-     * If we are in a fb disabled state, the virtual address of the root
-     * pixmap should always be NULL, and it will be overwritten later
-     * if we try to set it to something.
-     *
-     * Therefore, set it to NULL, and modify the backup copy instead.
-     */
-
-    fbAccessDisabled = (rootPixmap->devPrivate.ptr == NULL);
-
-    pScreen->ModifyPixmapHeader(rootPixmap,
-				pScrn->virtualX, pScrn->virtualY,
-				pScrn->depth, pScrn->bitsPerPixel,
-				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-				fbstart);
-
-    if (fbAccessDisabled) {
-	pScrn->pixmapPrivate.ptr = fbstart;
-	rootPixmap->devPrivate.ptr = NULL;
-    }
+		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
 
     pScrn->frameX0 = 0;
     pScrn->frameY0 = 0;
     AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
-    UnmapMem(pScrn);
-
-    ms->front = TRUE;
-
     return TRUE;
 }
 
@@ -538,22 +454,12 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 
     pScrn->virtualX = width;
     pScrn->virtualY = height;
-    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
 
-    if (ms->shadowMem) {
-	xfree(ms->shadowMem);
-	ms->shadowMem = NULL;
-    }
+    /* HW dependent - FIXME */
+    pScrn->displayWidth = pScrn->virtualX;
 
     drmModeRmFB(ms->fd, ms->fb_id);
 
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
-
-    /* unreference it */
-    drmBOUnreference(ms->fd, &ms->bo);
-    ms->front = FALSE;
-
     /* now create new frontbuffer */
     return CreateFrontBuffer(pScrn);
 }
@@ -571,7 +477,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    int flags24;
     char *BusID;
     int i;
     char *s;
@@ -645,13 +550,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
 
-    flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
-
-    if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
+    if (!xf86SetDepthBpp
+	(pScrn, 0, 0, 0,
+	 PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
 	return FALSE;
 
     switch (pScrn->depth) {
-    case 8:
     case 15:
     case 16:
     case 24:
@@ -684,23 +588,10 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     max_height = 8192;
     xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
 
-    if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
-	ms->noAccel = TRUE;
-    }
-
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
 	ms->SWCursor = TRUE;
     }
 
-    if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
-	if (!xf86LoadSubModule(pScrn, "shadow"))
-	    return FALSE;
-
-	xf86LoaderReqSymLists(shadowSymbols, NULL);
-
-	ms->shadowFB = TRUE;
-    }
-
     SaveHWState(pScrn);
 
     crtc_init(pScrn);
@@ -767,42 +658,37 @@ RestoreHWState(ScrnInfoPtr pScrn)
     return TRUE;
 }
 
-static void *
-WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
-	     CARD32 * size, void *closure)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    if (!pScrn->vtSema)
-	return NULL;
-
-    *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
-
-    return ((CARD8 *) ms->bo.virtual + row * (*size) + offset);
-}
-
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    PixmapPtr rootPixmap;
     Bool ret;
+    int flags;
+
+    ms->noEvict = TRUE;
 
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
 
-    if (ms->shadowFB)
-    	shadowAdd(pScreen, rootPixmap,
-	      ms->update, WindowLinear, 0, 0);
+    rootPixmap = pScreen->GetScreenPixmap(pScreen);
 
-    if (!pScreen->ModifyPixmapHeader(pScreen->GetScreenPixmap(pScreen),
-                                     -1, -1, -1, -1, -1,
-                                     ms->shadowFB ? (pointer)ms->shadowMem : (pointer)ms->bo.virtual))
+    if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL))
 	FatalError("Couldn't adjust screen pixmap\n");
 
+    ms->noEvict = FALSE;
+
+    drmModeAddFB(ms->fd,
+		 pScrn->virtualX,
+		 pScrn->virtualY,
+		 pScrn->depth,
+		 pScrn->bitsPerPixel,
+		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
+
+    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
     return ret;
 }
@@ -816,33 +702,33 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     unsigned long sys_mem;
     int c;
     MessageType from;
-    CARD8 *fbstart;
 
     /* deal with server regeneration */
     if (ms->fd < 0) {
-    	char *BusID;
+	char *BusID;
 
-    	BusID = xalloc(64);
-    	sprintf(BusID, "PCI:%d:%d:%d",
+	BusID = xalloc(64);
+	sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
-	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	    ms->PciInfo->dev, ms->PciInfo->func
+		((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+		ms->PciInfo->dev, ms->PciInfo->func
 #else
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+		((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+		((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+		((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
 #endif
-	);
+	    );
 
-    	ms->fd = drmOpen(NULL, BusID);
+	ms->fd = drmOpen(NULL, BusID);
 
-    	if (ms->fd < 0)
+	if (ms->fd < 0)
 	    return FALSE;
     }
 
     pScrn->pScreen = pScreen;
 
-    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+    /* HW dependent - FIXME */
+    pScrn->displayWidth = pScrn->virtualX;
 
     miClearVisualTypes();
 
@@ -857,39 +743,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
 
-    drmBOCreate(ms->fd,
-		pScrn->virtualY * pScrn->displayWidth *
-		pScrn->bitsPerPixel / 8, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-		| DRM_BO_FLAG_CACHED_MAPPED
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
-		0, &ms->bo);
-
-    MapMem(pScrn);
-
-    drmModeAddFB(ms->fd,
-		 pScrn->virtualX,
-		 pScrn->virtualY,
-		 pScrn->depth,
-		 pScrn->bitsPerPixel,
-		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 ms->bo.handle, &ms->fb_id);
-
-    if (ms->shadowFB) {
-	if ((ms->shadowMem =
-	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
-			 pScrn->bitsPerPixel)) == NULL) {
-	    xf86DrvMsg(scrnIndex, X_ERROR,
-		       "Allocation of shadow memory failed\n");
-	    return FALSE;
-	}
-	fbstart = ms->shadowMem;
-    } else {
-	fbstart = ms->bo.virtual;
-    }
-
-    if (!fbScreenInit(pScreen, fbstart,
+    if (!fbScreenInit(pScreen, NULL,
 		      pScrn->virtualX, pScrn->virtualY,
 		      pScrn->xDpi, pScrn->yDpi,
 		      pScrn->displayWidth, pScrn->bitsPerPixel))
@@ -911,26 +765,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     }
 
     fbPictureInit(pScreen, NULL, 0);
-    if (ms->shadowFB) {
-	ms->update = shadowUpdatePackedWeak();
-	if (!shadowSetup(pScreen)) {
-	    xf86DrvMsg(scrnIndex, X_ERROR,
-		       "Shadow framebuffer initialization failed.\n");
-	    return FALSE;
-	}
-    }
 
     ms->createScreenResources = pScreen->CreateScreenResources;
     pScreen->CreateScreenResources = CreateScreenResources;
 
     xf86SetBlackWhitePixels(pScreen);
 
-#if 0
-    glucoseScreenInit(pScreen, 0);
-#endif
-#if 1
-    ms->pExa = ExaInit(pScrn);
-#endif
+    ms->exa = ExaInit(pScrn);
 
     miInitializeBackingStore(pScreen);
     xf86SetBackingStore(pScreen);
@@ -939,9 +780,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     /* Need to extend HWcursor support to handle mask interleave */
     if (!ms->SWCursor)
-	xf86_cursors_init (pScreen, 64, 64,
-			       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
-			       HARDWARE_CURSOR_ARGB);
+	xf86_cursors_init(pScreen, 64, 64,
+			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
+			  HARDWARE_CURSOR_ARGB);
 
     /* Must force it before EnterVT, so we are in control of VT and
      * later memory should be bound when allocating, e.g rotate_mem */
@@ -957,20 +798,8 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!miCreateDefColormap(pScreen))
 	return FALSE;
 
-#if 0
-    if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
-			     CMAP_RELOAD_ON_MODE_SWITCH |
-			     CMAP_PALETTED_TRUECOLOR)) {
-	return FALSE;
-    }
-#endif
-
     xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
-#if 0
-    glucoseInitVideo(pScreen);
-#endif
-
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
@@ -978,11 +807,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     driScreenInit(pScreen);
 #endif
 
-    UnmapMem(pScrn);
-
-    ms->front = TRUE;
-
-    return EnterVT(scrnIndex, 0);
+    return EnterVT(scrnIndex, 1);
 }
 
 static void
@@ -1018,7 +843,7 @@ LeaveVT(int scrnIndex, int flags)
     for (o = 0; o < config->num_crtc; o++) {
 	xf86CrtcPtr crtc = config->crtc[o];
 
-    	cursor_destroy(crtc);
+	cursor_destroy(crtc);
 
 	if (crtc->rotatedPixmap || crtc->rotatedData) {
 	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
@@ -1030,12 +855,6 @@ LeaveVT(int scrnIndex, int flags)
 
     drmModeRmFB(ms->fd, ms->fb_id);
 
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
-
-    drmBOUnreference(ms->fd, &ms->bo);
-    ms->front = FALSE;
-
     RestoreHWState(pScrn);
 
 #if 0
@@ -1078,14 +897,12 @@ EnterVT(int scrnIndex, int flags)
 	SaveHWState(pScrn);
     }
 
-    if (!ms->front)
+    if (!flags)			       /* signals startup as we'll do this in CreateScreenResources */
 	CreateFrontBuffer(pScrn);
 
     if (!xf86SetDesiredModes(pScrn))
 	return FALSE;
 
-    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
-
     return TRUE;
 }
 
@@ -1104,25 +921,19 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
 
     if (pScrn->vtSema) {
-    	LeaveVT(scrnIndex, 0);
+	LeaveVT(scrnIndex, 0);
 #if 0
-    	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-    	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
 #endif
     }
-
 #ifdef DRI2
     driCloseScreen(pScreen);
 #endif
 
     pScreen->CreateScreenResources = ms->createScreenResources;
 
-    if (ms->shadowMem) {
-	xfree(ms->shadowMem);
-	ms->shadowMem = NULL;
-    }
-
-    if (ms->pExa)
+    if (ms->exa)
 	ExaClose(pScrn);
 
     drmClose(ms->fd);
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 7ac6466..5b31188 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -32,7 +32,6 @@
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 #include <xf86mm.h>
-#include "shadow.h"
 #include "exa.h"
 
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
@@ -49,14 +48,9 @@ typedef struct _modesettingRec
 {
     int fd;
     unsigned int fb_id;
-    void *virtual;
-    drmBO bo;
-    Bool front;
 
     EntPtr entityPrivate;
 
-    void (*PointerMoved) (int, int, int);
-
     int Chipset;
     EntityInfoPtr pEnt;
 #if XSERVER_LIBPCIACCESS
@@ -75,15 +69,12 @@ typedef struct _modesettingRec
 
     unsigned int SaveGeneration;
 
-    /* shadowfb */
-    CARD8 *shadowMem;
-    Bool shadowFB;
     CreateScreenResourcesProcPtr createScreenResources;
-    ShadowUpdateProc update;
 
     /* exa */
-    ExaDriverPtr pExa;
-    drmBO exa_bo;
+    void *exa;
+    void *driver;
+    Bool noEvict;
 
     /* dri2 */
     drm_context_t context;
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 9327cbc..124dc03 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -31,19 +31,329 @@
 #include "config.h"
 #endif
 
+/* FIXME ! */
+#define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri"
+
 #include "xf86.h"
 #include "xf86_OSproc.h"
-
 #include "driver.h"
+#include <dlfcn.h>
+
+#include "pipe/p_winsys.h"
+#include "pipe/p_format.h"
+#include "pipe/p_context.h"
+#include "pipe/p_util.h"
+#include "pipe/p_state.h"
+#include "pipe/p_inlines.h"
+
+/* EXA winsys */
+struct exa_context
+{
+};
+
+struct exa_winsys
+{
+    struct pipe_winsys base;
+    modesettingPtr ms;
+};
 
-struct PixmapPriv {
+struct exa_buffer
+{
+    struct pipe_buffer base;
     drmBO bo;
-    #if 0
+    boolean userBuffer;	/** Is this a user-space buffer? */
+    //void *data;
+    //void *mapped;
+};
+
+struct exa_surface
+{
+    struct pipe_surface surface;
+};
+
+struct exa_entity
+{
+    ExaDriverPtr pExa;
+    struct exa_context *c;
+    struct pipe_winsys *ws;
+    struct pipe_context *ctx;
+    struct pipe_screen *scrn;
+};
+
+static INLINE struct exa_winsys *
+exa_get_winsys(struct pipe_winsys *ws)
+{
+    return (struct exa_winsys *)ws;
+}
+
+static INLINE struct exa_surface *
+exa_get_surface(struct pipe_surface *ps)
+{
+    return (struct exa_surface *)ps;
+}
+
+static INLINE struct exa_buffer *
+exa_get_buffer(struct pipe_buffer *buf)
+{
+    return (struct exa_buffer *)buf;
+}
+
+static void *
+exa_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf,
+	       unsigned flags)
+{
+    struct exa_buffer *exa_buf = exa_get_buffer(buf);
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+    void *virtual;
+
+    drmBOMap(exa_winsys->ms->fd,
+	     &exa_buf->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
+
+    return virtual;
+}
+
+static void
+exa_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
+{
+    struct exa_buffer *exa_buf = exa_get_buffer(buf);
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+
+    drmBOUnmap(exa_winsys->ms->fd, &exa_buf->bo);
+}
+
+static void
+exa_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf)
+{
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+    struct exa_buffer *exa_buf = exa_get_buffer(buf);
+
+    drmBOUnreference(exa_winsys->ms->fd, &exa_buf->bo);
+
+    free(exa_buf);
+}
+
+static void
+exa_flush_frontbuffer(struct pipe_winsys *pws,
+		      struct pipe_surface *surf, void *context_private)
+{
+    struct exa_buffer *exa_buf = exa_get_buffer(surf->buffer);
+
+    ErrorF("WANT TO FLUSH\n");
+}
+
+static const char *
+exa_get_name(struct pipe_winsys *pws)
+{
+    return "EXA";
+}
+
+static struct pipe_buffer *
+exa_buffer_create(struct pipe_winsys *pws,
+		  unsigned alignment, unsigned usage, unsigned size)
+{
+    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+    unsigned int flags = 0;
+
+    buffer->base.refcount = 1;
+    buffer->base.alignment = alignment;
+    buffer->base.usage = usage;
+    buffer->base.size = size;
+
+    if (exa_winsys->ms->noEvict) {
+	flags = DRM_BO_FLAG_NO_EVICT;
+	ErrorF("DISPLAY TARGET\n");
+    }
+
+    ErrorF("SIZE %d %d\n", size, alignment);
+    if (!buffer->bo.handle) {
+	// buffer->data = align_malloc(size, alignment);
+	drmBOCreate(exa_winsys->ms->fd, size, 4096, NULL,
+		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE |
+		    DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT |
+		    DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_CACHED_MAPPED | flags,
+		    0, &buffer->bo);
+    }
+
+    return &buffer->base;
+}
+
+static struct pipe_buffer *
+exa_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
+{
+    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
+
+    buffer->base.refcount = 1;
+    buffer->base.size = bytes;
+    buffer->userBuffer = TRUE;
+    //buffer->data = ptr;
+    ErrorF("USERBUFFER\n");
+
+    return &buffer->base;
+}
+
+/**
+ * Round n up to next multiple.
+ */
+static INLINE unsigned
+round_up(unsigned n, unsigned multiple)
+{
+    return (n + multiple - 1) & ~(multiple - 1);
+}
+
+static int
+exa_surface_alloc_storage(struct pipe_winsys *winsys,
+			  struct pipe_surface *surf,
+			  unsigned width, unsigned height,
+			  enum pipe_format format,
+			  unsigned flags, unsigned tex_usage)
+{
+    const unsigned alignment = 64;
+
+    surf->width = width;
+    surf->height = height;
+    surf->format = format;
+    surf->cpp = pf_get_size(format);
+    surf->pitch = round_up(width, alignment / surf->cpp);
+
+    assert(!surf->buffer);
+    surf->buffer = winsys->buffer_create(winsys, alignment,
+					 PIPE_BUFFER_USAGE_PIXEL,
+					 surf->pitch * surf->cpp * height);
+    if (!surf->buffer)
+	return -1;
+
+    return 0;
+}
+
+/**
+ * Called via winsys->surface_alloc() to create new surfaces.
+ */
+static struct pipe_surface *
+exa_surface_alloc(struct pipe_winsys *ws)
+{
+    struct exa_surface *wms = xcalloc(1, sizeof(struct exa_surface));
+
+    assert(ws);
+
+    wms->surface.refcount = 1;
+    wms->surface.winsys = ws;
+
+    return &wms->surface;
+}
+
+static void
+exa_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
+{
+    struct pipe_surface *surf = *s;
+
+    surf->refcount--;
+    if (surf->refcount == 0) {
+	if (surf->buffer)
+	    pipe_buffer_reference(winsys, &surf->buffer, NULL);
+	free(surf);
+    }
+    *s = NULL;
+}
+
+/*
+ * Fence functions - basically nothing to do, as we don't create any actual
+ * fence objects.
+ */
+static void
+exa_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
+		    struct pipe_fence_handle *fence)
+{
+}
+
+static int
+exa_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
+		    unsigned flag)
+{
+    return 0;
+}
+
+static int
+exa_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
+		 unsigned flag)
+{
+    return 0;
+}
+
+struct pipe_winsys *
+exa_get_pipe_winsys(modesettingPtr ms)
+{
+    static struct exa_winsys *ws = NULL;
+
+    if (!ws) {
+	ws = xcalloc(1, sizeof(struct exa_winsys));
+
+	/* Fill in this struct with callbacks that pipe will need to
+	 * communicate with the window system, buffer manager, etc. 
+	 */
+	ws->base.buffer_create = exa_buffer_create;
+	ws->base.user_buffer_create = exa_user_buffer_create;
+	ws->base.buffer_map = exa_buffer_map;
+	ws->base.buffer_unmap = exa_buffer_unmap;
+	ws->base.buffer_destroy = exa_buffer_destroy;
+
+	ws->base.surface_alloc = exa_surface_alloc;
+	ws->base.surface_alloc_storage = exa_surface_alloc_storage;
+	ws->base.surface_release = exa_surface_release;
+
+	ws->base.fence_reference = exa_fence_reference;
+	ws->base.fence_signalled = exa_fence_signalled;
+	ws->base.fence_finish = exa_fence_finish;
+
+	ws->base.flush_frontbuffer = exa_flush_frontbuffer;
+	ws->base.get_name = exa_get_name;
+
+	ws->ms = ms;
+    }
+
+    return &ws->base;
+}
+
+/* EXA functions */
+
+struct PixmapPriv
+{
+    drmBO bo;
+#if 0
     dri_fence *fence;
-    #endif
+#endif
     int flags;
+
+    struct pipe_texture *tex;
+    unsigned int color;
+    struct pipe_surface *src_surf;     /* for copies */
 };
 
+static enum pipe_format
+exa_get_pipe_format(int depth)
+{
+    switch (depth) {
+    case 32:
+    case 24:
+	return PIPE_FORMAT_A8R8G8B8_UNORM;
+    case 16:
+	return PIPE_FORMAT_R5G6B5_UNORM;
+    case 15:
+	return PIPE_FORMAT_A1R5G5B5_UNORM;
+    case 8:
+    case 4:
+    case 1:
+	return PIPE_FORMAT_A8R8G8B8_UNORM;	/* bad bad bad */
+    default:
+	assert(0);
+	return 0;
+    }
+}
+
+/*
+ * EXA functions
+ */
+
 static void
 ExaWaitMarker(ScreenPtr pScreen, int marker)
 {
@@ -62,6 +372,7 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct exa_entity *exa = ms->exa;
     struct PixmapPriv *priv;
     int ret;
 
@@ -70,21 +381,20 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
     if (!priv)
 	return FALSE;
 
-    if (priv->bo.handle) {
-    	void *virtual;
-
-    	ret = drmBOMap(ms->fd,
-	     &priv->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
-	if (ret) {
-    	    driUnlock(pScreen);
-	    FatalError("Failed to map pixmap: %s\n", strerror(-ret));
-	    return;
-	}
-
-	pPix->devPrivate.ptr = priv->bo.virtual;
+    if (!priv->tex)
+	return FALSE;
+    {
+	struct pipe_surface *surf =
+	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				       PIPE_BUFFER_USAGE_CPU_READ |
+				       PIPE_BUFFER_USAGE_CPU_WRITE);
+	pPix->devPrivate.ptr =
+	    exa->scrn->surface_map(exa->scrn, surf,
+				   PIPE_BUFFER_USAGE_CPU_READ |
+				   PIPE_BUFFER_USAGE_CPU_WRITE);
+	exa->scrn->tex_surface_release(exa->scrn, &surf);
     }
 
-
     return TRUE;
 }
 
@@ -96,6 +406,7 @@ ExaFinishAccess(PixmapPtr pPix, int index)
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     struct PixmapPriv *priv;
+    struct exa_entity *exa = ms->exa;
     int ret;
 
     priv = exaGetPixmapDriverPrivate(pPix);
@@ -103,14 +414,15 @@ ExaFinishAccess(PixmapPtr pPix, int index)
     if (!priv)
 	return;
 
-    if (priv->bo.handle) {
-	ret = drmBOUnmap(ms->fd, &priv->bo);
-	if (ret) {
-	    driUnlock(pScreen);
-	    FatalError("Failed to unmap pixmap: %s\n", strerror(-ret));
-	    return;
-	}
-
+    if (!priv->tex)
+	return;
+    {
+	struct pipe_surface *surf =
+	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				       PIPE_BUFFER_USAGE_CPU_READ |
+				       PIPE_BUFFER_USAGE_CPU_WRITE);
+	exa->scrn->surface_unmap(exa->scrn, surf);
+	exa->scrn->tex_surface_release(exa->scrn, &surf);
 	pPix->devPrivate.ptr = NULL;
     }
 }
@@ -119,6 +431,16 @@ static void
 ExaDone(PixmapPtr pPixmap)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    struct exa_entity *exa = ms->exa;
+
+    if (!priv)
+	return;
+
+    if (priv->src_surf)
+	exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf);
+    priv->src_surf = NULL;
 }
 
 static void
@@ -131,23 +453,46 @@ static Bool
 ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    struct exa_entity *exa = ms->exa;
 
-    ErrorF("SOLID\n");
+    if (pPixmap->drawable.depth < 15)
+	return FALSE;
 
     if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
 	return FALSE;
 
-    /* can't do depth 4 */
-    if (pPixmap->drawable.depth == 4)
+    if (!priv->tex)
 	return FALSE;
 
-    return FALSE;
+    if (alu != GXcopy)
+	return FALSE;
+
+    if (!exa->ctx || !exa->ctx->surface_fill)
+	return FALSE;
+
+    priv->color = fg;
+
+    return TRUE;
 }
 
 static void
-ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
+ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    struct pipe_surface *surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_GPU_READ |
+				   PIPE_BUFFER_USAGE_GPU_WRITE);
+
+    exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0,
+			   priv->color);
+
+    exa->scrn->tex_surface_release(exa->scrn, &surf);
 }
 
 static Bool
@@ -155,13 +500,31 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 	       int ydir, int alu, Pixel planeMask)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct pipe_surface *src_surf;
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
+
+    if (alu != GXcopy)
+	return FALSE;
+
+    if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15)
+	return FALSE;
+
+    if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
+	return FALSE;
 
-    ErrorF("COPY\n");
+    if (!priv->tex)
+	return FALSE;
 
-    /* can't do depth 4 */
-    if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4)
+    if (!exa->ctx || !exa->ctx->surface_copy)
 	return FALSE;
 
+    priv->src_surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_GPU_READ |
+				   PIPE_BUFFER_USAGE_GPU_WRITE);
+
     return FALSE;
 }
 
@@ -170,6 +533,17 @@ ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
 	int width, int height)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
+    struct pipe_surface *surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_GPU_READ |
+				   PIPE_BUFFER_USAGE_GPU_WRITE);
+
+    exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf,
+			   srcX, srcY, width, height);
+    exa->scrn->tex_surface_release(exa->scrn, &surf);
 }
 
 static Bool
@@ -225,37 +599,29 @@ ExaCreatePixmap(ScreenPtr pScreen, int size, int align)
 
     priv = xcalloc(1, sizeof(struct PixmapPriv));
     if (!priv)
-        return NULL;
-
-    if (size == 0)
-	return priv;
-
-    drmBOCreate(ms->fd, size, 4096, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-		| DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_CACHED_MAPPED,
-		0, &priv->bo);
+	return NULL;
 
     return priv;
 }
 
-static void 
+static void
 ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
 {
     struct PixmapPriv *priv = (struct PixmapPriv *)dPriv;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
 
     if (!priv)
-    	return;
+	return;
 
-    if (priv->bo.handle)
-	drmBOUnreference(ms->fd, &priv->bo);
+    if (priv->tex)
+	exa->scrn->texture_release(exa->scrn, &priv->tex);
 
     xfree(priv);
 }
 
-static Bool 
+static Bool
 ExaPixmapIsOffscreen(PixmapPtr pPixmap)
 {
     struct PixmapPriv *priv;
@@ -265,10 +631,10 @@ ExaPixmapIsOffscreen(PixmapPtr pPixmap)
     priv = exaGetPixmapDriverPrivate(pPixmap);
 
     if (!priv)
-       return FALSE;
+	return FALSE;
 
-    if (priv->bo.handle)
-       return TRUE;
+    if (priv->tex)
+	return TRUE;
 
     return FALSE;
 }
@@ -281,87 +647,146 @@ driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags)
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct exa_buffer *exa_buf;
+    struct pipe_surface *surf;
     struct PixmapPriv *priv;
 
     *flags = 0;
 
-    if (rootPixmap == pPixmap)
-        return ms->bo.handle;
-
-    if (!ms->pExa)
-    	return 0;
+    if (!ms->exa) {
+	FatalError("NO MS->EXA\n");
+	return 0;
+    }
 
     priv = exaGetPixmapDriverPrivate(pPixmap);
 
-    if (!priv)
-       return 0;
+    if (!priv) {
+	FatalError("NO PIXMAP PRIVATE\n");
+	return 0;
+    }
+
+    surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_CPU_READ |
+				   PIPE_BUFFER_USAGE_CPU_WRITE);
+    exa_buf = exa_get_buffer(surf->buffer);
+    exa->scrn->tex_surface_release(exa->scrn, &surf);
 
-    if (priv->bo.handle)
-        return priv->bo.handle;
+    if (exa_buf->bo.handle)
+	return exa_buf->bo.handle;
 
     return 0;
 }
 
-static Bool 
+static Bool
 ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
 		      int depth, int bitsPerPixel, int devKind,
 		      pointer pPixData)
 {
-    ScreenPtr	pScreen = pPixmap->drawable.pScreen;
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct exa_entity *exa = ms->exa;
 
-    if (rootPixmap == pPixmap) {
+    /*if (rootPixmap == pPixmap) */  {
 	miModifyPixmapHeader(pPixmap, width, height, depth,
 			     bitsPerPixel, devKind, NULL);
+    }
 
-	return TRUE;
+    if (!priv)
+	return FALSE;
+
+    if (depth <= 0)
+	depth = pPixmap->drawable.depth;
+
+    if (bitsPerPixel <= 0)
+	bitsPerPixel = pPixmap->drawable.bitsPerPixel;
+
+    if (width <= 0)
+	width = pPixmap->drawable.width;
+
+    if (height <= 0)
+	height = pPixmap->drawable.height;
+
+    if (width <= 0 || height <= 0 || depth <= 0)
+	return FALSE;
+
+    /* Deal with screen resize */
+    if (priv->tex) {
+	struct pipe_surface *surf =
+	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				       PIPE_BUFFER_USAGE_CPU_READ |
+				       PIPE_BUFFER_USAGE_CPU_WRITE);
+
+	ErrorF("RESIZE %d %d to %d %d\n", surf->width, surf->height, width,
+	       height);
+	if (surf->width != width || surf->height != height) {
+	    exa->scrn->texture_release(exa->scrn, &priv->tex);
+	    priv->tex = NULL;
+	}
+	exa->scrn->tex_surface_release(exa->scrn, &surf);
     }
 
-    return FALSE;
-}
+    if (!priv->tex) {
+	struct pipe_texture template;
+
+	memset(&template, 0, sizeof(template));
+	template.target = PIPE_TEXTURE_2D;
+	template.compressed = 0;
+	template.format = exa_get_pipe_format(depth);
+	template.cpp = pf_get_size(template.format);
+	template.width[0] = width;
+	template.height[0] = height;
+	template.depth[0] = 1;
+	template.last_level = 0;
+	template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+	priv->tex = exa->scrn->texture_create(exa->scrn, &template);
+    }
+
+    if (rootPixmap == pPixmap)
+	return TRUE;
 
+    return TRUE;
+}
 
 void
 ExaClose(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
 
     exaDriverFini(pScrn->pScreen);
 
-#if 0
-    drmBOUnreference(ms->fd, &ms->exa_bo);
-#endif
+    dlclose(ms->driver);
 }
 
-ExaDriverPtr
+void *
 ExaInit(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
-    ExaDriverPtr pExa;
+    struct exa_entity *exa;
+    ExaDriverPtr pExa = exa->pExa;
+
+    exa = xcalloc(1, sizeof(struct exa_entity));
+    if (!exa)
+	return NULL;
 
     pExa = exaDriverAlloc();
     if (!pExa) {
 	goto out_err;
     }
 
-#if 0
-    /* Create a 256KB offscreen area */
-    drmBOCreate(ms->fd, 256 * 1024, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
-#endif
-
     memset(pExa, 0, sizeof(*pExa));
     pExa->exa_major = 2;
     pExa->exa_minor = 4;
-    pExa->memoryBase = 0; /* ms->exa_bo.virtual; */
-    pExa->memorySize = 0; /* ms->exa_bo.size; */
+    pExa->memoryBase = 0;
+    pExa->memorySize = 0;
     pExa->offScreenBase = 0;
-    pExa->pixmapOffsetAlign = 8;
-    pExa->pixmapPitchAlign = 32 * 4;
+    pExa->pixmapOffsetAlign = 0;
+    pExa->pixmapPitchAlign = 1;
     pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
     pExa->maxX = 8191;		       /* FIXME */
     pExa->maxY = 8191;		       /* FIXME */
@@ -389,7 +814,30 @@ ExaInit(ScrnInfoPtr pScrn)
 	goto out_err;
     }
 
-    return pExa;
+    {
+	char filename[128];
+	char dri_driver_path[] = DRI_DRIVER_PATH;
+
+	snprintf(filename, sizeof filename,
+		 "%s/%s_dri.so", dri_driver_path, "i915");
+
+	ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL);
+
+	exa->c = xcalloc(1, sizeof(struct exa_context));
+
+	exa->ws = exa_get_pipe_winsys(ms);
+
+	exa->scrn = softpipe_create_screen(exa->ws);
+
+	exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL);
+
+	if (!exa->ctx)
+	    ErrorF("BAD CTX\n");
+
+	exa->ctx->priv = exa->c;
+    }
+
+    return (void *)exa;
 
   out_err:
     ExaClose(pScrn);
commit 0e1aa03708d95cc1542bee31709a345d0f748f0c
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:27:14 2008 +0100

    yet more

diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index 484acb2..1f95a2f 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -67,7 +67,6 @@ static char *connector_enum_list[] = {
     "HDMI Type B",
 };
 
-
 static void
 dpms(xf86OutputPtr output, int mode)
 {
@@ -162,7 +161,6 @@ get_modes(xf86OutputPtr output)
 	    mode->VRefresh = xf86ModeVRefresh(mode);
 	    mode->Private = (void *)drm_mode;
 	    xf86SetModeDefaultName(mode);
-	    ErrorF("MODE %s\n",mode->name);
 	    modes = xf86ModesAdd(modes, mode);
 	    xf86PrintModeline(0, mode);
 	}
@@ -277,11 +275,11 @@ output_init(ScrnInfoPtr pScrn)
 
 	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
 	if (drm_encoder) {
-	output->possible_crtcs = drm_encoder->crtcs;
-	output->possible_clones = drm_encoder->clones;
+	    output->possible_crtcs = drm_encoder->crtcs;
+	    output->possible_clones = drm_encoder->clones;
 	} else {
-	output->possible_crtcs = 0;
-	output->possible_clones = 0;
+	    output->possible_crtcs = 0;
+	    output->possible_clones = 0;
 	}
 	output->driver_private = drm_connector;
 	output->subpixel_order = SubPixelHorizontalRGB;
commit 2b3a3bc9202f4e6f9886a08a4dfa597a83a5e933
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:26:16 2008 +0100

    more formatting fixes

diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
index eec8069..7fd9fca 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -76,7 +76,8 @@ driEndClipNotify(ScreenPtr pScreen)
     driUnlock(pScreen);
 }
 
-struct __DRILock {
+struct __DRILock
+{
     unsigned int block_header;
     drm_hw_lock_t lock;
     unsigned int next_id;
@@ -99,13 +100,13 @@ driScreenInit(ScreenPtr pScreen)
     dri2info.version = 1;
     dri2info.fd = ms->fd;
     dri2info.driverSareaSize = sizeof(struct __DRILock);
-    dri2info.driverName = "i915"; /* FIXME */
+    dri2info.driverName = "i915";      /* FIXME */
     dri2info.getPixmapHandle = driGetPixmapHandle;
     dri2info.beginClipNotify = driBeginClipNotify;
-    dri2info.endClipNotify   = driEndClipNotify;
+    dri2info.endClipNotify = driEndClipNotify;
 
     p = DRI2ScreenInit(pScreen, &dri2info);
-    if (!p) 
+    if (!p)
 	return;
 
     DRILock = p;
commit 2a45c28712a544c6f1c3eb753678ba1738cfdd67
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:25:17 2008 +0100

    formatting fixes

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index 89ffe92..d4f449b 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -47,7 +47,8 @@
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 
-struct crtc_private {
+struct crtc_private
+{
     drmModeCrtcPtr drm_crtc;
 
     /* hwcursor */
@@ -122,6 +123,8 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     drm_mode.hskew = mode->HSkew;
     drm_mode.vscan = mode->VScan;
     drm_mode.vrefresh = mode->VRefresh;
+    if (!mode->name)
+	xf86SetModeDefaultName(mode);
     strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
 
     drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
@@ -176,29 +179,30 @@ crtc_destroy(xf86CrtcPtr crtc)
 }
 
 static void
-crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
 {
     unsigned char *ptr;
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
     if (!crtcp->cursor_bo.handle)
-        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM,
-		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
+	drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
+		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE
+		    | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		    DRM_BO_FLAG_MEM_VRAM,
+		    DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
 
-    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
+    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE,
+	     DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
 
     if (ptr)
-	memcpy (ptr, image, 64 * 64 * 4);
+	memcpy(ptr, image, 64 * 64 * 4);
 
     drmBOUnmap(ms->fd, &crtcp->cursor_bo);
 }
 
 static void
-crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
 {
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
@@ -207,17 +211,18 @@ crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 }
 
 static void
-crtc_show_cursor (xf86CrtcPtr crtc)
+crtc_show_cursor(xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
     if (crtcp->cursor_bo.handle)
-	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
+	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id,
+			 crtcp->cursor_bo.handle, 64, 64);
 }
 
 static void
-crtc_hide_cursor (xf86CrtcPtr crtc)
+crtc_hide_cursor(xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
@@ -242,8 +247,8 @@ static const xf86CrtcFuncsRec crtc_funcs = {
     .set_cursor_position = crtc_set_cursor_position,
     .show_cursor = crtc_show_cursor,
     .hide_cursor = crtc_hide_cursor,
-    .load_cursor_image = NULL,	/* lets convert to argb only */
-    .set_cursor_colors = NULL, /* using argb only */
+    .load_cursor_image = NULL,	       /* lets convert to argb only */
+    .set_cursor_colors = NULL,	       /* using argb only */
     .load_cursor_argb = crtc_load_cursor_argb,
     .destroy = crtc_destroy,
 };
@@ -255,8 +260,8 @@ cursor_destroy(xf86CrtcPtr crtc)
     struct crtc_private *crtcp = crtc->driver_private;
 
     if (crtcp->cursor_bo.handle) {
-    	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
-    	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
+	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
     }
 }
 
@@ -291,10 +296,10 @@ crtc_init(ScrnInfoPtr pScrn)
 	    goto out;
 	}
 
- 	crtcp->drm_crtc = drm_crtc;
+	crtcp->drm_crtc = drm_crtc;
 
 	crtc->driver_private = crtcp;
-    
+
     }
 
   out:
commit 47969d79289ad92f658c9a6dd2a2fc6b5f1b6c99
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Mon Jun 16 15:07:39 2008 +0100

    Add DRI2 support.
    
    Add EXA stubs.
    
    Currently tested with i915.

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 17d884f..a182d44 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -37,6 +37,7 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 output.c \
 	 crtc.c \
-	 exa.c
+	 exa.c \
+	 dri2.c
 
 EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index 14ee53e..89ffe92 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -168,8 +168,11 @@ crtc_destroy(xf86CrtcPtr crtc)
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
-    drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+    if (crtcp->cursor_bo.handle)
+	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+
     drmModeFreeCrtc(crtcp->drm_crtc);
+    xfree(crtcp);
 }
 
 static void
@@ -179,9 +182,17 @@ crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
-    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, 0, (void **)&ptr);
+    if (!crtcp->cursor_bo.handle)
+        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM,
+		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
+
+    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
 
-    memcpy (ptr, image, 64 * 64 * 4);
+    if (ptr)
+	memcpy (ptr, image, 64 * 64 * 4);
 
     drmBOUnmap(ms->fd, &crtcp->cursor_bo);
 }
@@ -201,7 +212,8 @@ crtc_show_cursor (xf86CrtcPtr crtc)
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
-    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
+    if (crtcp->cursor_bo.handle)
+	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
 }
 
 static void
@@ -213,12 +225,6 @@ crtc_hide_cursor (xf86CrtcPtr crtc)
     drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
 }
 
-static void
-crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
-{
-    ScrnInfoPtr		scrn = crtc->scrn;
-}
-
 static const xf86CrtcFuncsRec crtc_funcs = {
     .dpms = crtc_dpms,
     .save = NULL,
@@ -233,16 +239,28 @@ static const xf86CrtcFuncsRec crtc_funcs = {
     .shadow_create = crtc_shadow_create,
     .shadow_allocate = crtc_shadow_allocate,
     .shadow_destroy = crtc_shadow_destroy,
-    .set_cursor_colors = crtc_set_cursor_colors,
     .set_cursor_position = crtc_set_cursor_position,
     .show_cursor = crtc_show_cursor,
     .hide_cursor = crtc_hide_cursor,
     .load_cursor_image = NULL,	/* lets convert to argb only */
+    .set_cursor_colors = NULL, /* using argb only */
     .load_cursor_argb = crtc_load_cursor_argb,
     .destroy = crtc_destroy,
 };
 
 void
+cursor_destroy(xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    if (crtcp->cursor_bo.handle) {
+    	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
+    	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+    }
+}
+
+void
 crtc_init(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -267,7 +285,7 @@ crtc_init(ScrnInfoPtr pScrn)
 	if (crtc == NULL)
 	    goto out;
 
-	crtcp = xalloc(sizeof(struct crtc_private));
+	crtcp = xcalloc(1, sizeof(struct crtc_private));
 	if (!crtcp) {
 	    xf86CrtcDestroy(crtc);
 	    goto out;
@@ -277,11 +295,6 @@ crtc_init(ScrnInfoPtr pScrn)
 
 	crtc->driver_private = crtcp;
     
-        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
     }
 
   out:
diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
new file mode 100644
index 0000000..eec8069
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include "driver.h"
+
+#include "dri2.h"
+
+extern unsigned int
+driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags);
+
+void
+driLock(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    if (!ms->lock_held)
+	DRM_LOCK(ms->fd, ms->lock, ms->context, 0);
+
+    ms->lock_held = 1;
+}
+
+void
+driUnlock(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    if (ms->lock_held)
+	DRM_UNLOCK(ms->fd, ms->lock, ms->context);
+
+    ms->lock_held = 0;
+}
+
+static void
+driBeginClipNotify(ScreenPtr pScreen)
+{
+    driLock(pScreen);
+}
+
+static void
+driEndClipNotify(ScreenPtr pScreen)
+{
+    driUnlock(pScreen);
+}
+
+struct __DRILock {
+    unsigned int block_header;
+    drm_hw_lock_t lock;
+    unsigned int next_id;
+};
+
+#define DRI2_SAREA_BLOCK_HEADER(type, size) (((type) << 16) | (size))
+#define DRI2_SAREA_BLOCK_LOCK		0x0001
+
+void
+driScreenInit(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    DRI2InfoRec dri2info;
+    const char *driverName;
+    unsigned int sarea_handle;
+    struct __DRILock *DRILock;
+    void *p;
+
+    dri2info.version = 1;
+    dri2info.fd = ms->fd;
+    dri2info.driverSareaSize = sizeof(struct __DRILock);
+    dri2info.driverName = "i915"; /* FIXME */
+    dri2info.getPixmapHandle = driGetPixmapHandle;
+    dri2info.beginClipNotify = driBeginClipNotify;
+    dri2info.endClipNotify   = driEndClipNotify;
+
+    p = DRI2ScreenInit(pScreen, &dri2info);
+    if (!p) 
+	return;
+
+    DRILock = p;
+    DRILock->block_header =
+	DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_LOCK, sizeof *DRILock);
+    ms->lock = &DRILock->lock;
+    ms->context = 1;
+    DRILock->next_id = 2;
+    driLock(pScreen);
+
+    DRI2Connect(pScreen, &ms->fd, &driverName, &sarea_handle);
+}
+
+void
+driCloseScreen(ScreenPtr pScreen)
+{
+    driUnlock(pScreen);
+    DRI2CloseScreen(pScreen);
+}
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8f1c905..6bf6388 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -132,6 +132,16 @@ static const OptionInfoRec Options[] = {
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
+static const char *exaSymbols[] = {
+    "exaGetVersion",
+    "exaDriverInit",
+    "exaDriverFini",
+    "exaOffscreenAlloc",
+    "exaOffscreenFree",
+    "exaWaitSync",
+    NULL
+};
+
 static const char *fbSymbols[] = {
     "fbPictureInit",
     "fbScreenInit",
@@ -190,7 +200,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * Tell the loader about symbols from other modules that this module
 	 * might refer to.
 	 */
-	LoaderRefSymLists(fbSymbols, shadowSymbols, ddcSymbols, NULL);
+	LoaderRefSymLists(exaSymbols, fbSymbols, shadowSymbols, ddcSymbols, NULL);
 
 	/*
 	 * The return value must be non-NULL on success even though there
@@ -417,6 +427,8 @@ MapMem(ScrnInfoPtr pScrn)
     drmBOMap(ms->fd,
 	     &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
 
+    ms->virtual = ms->bo.virtual;
+
     return TRUE;
 }
 
@@ -438,7 +450,7 @@ LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 }
 
 static Bool
-crtc_resize(ScrnInfoPtr pScrn, int width, int height)
+CreateFrontBuffer(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
     ScreenPtr pScreen = pScrn->pScreen;
@@ -446,37 +458,14 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
     Bool fbAccessDisabled;
     CARD8 *fbstart;
 
-    if (width == pScrn->virtualX && height == pScrn->virtualY)
-	return TRUE;
-
-    ErrorF("RESIZING TO %dx%d\n", width, height);
-
-    pScrn->virtualX = width;
-    pScrn->virtualY = height;
-    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
-
-    if (ms->shadowMem) {
-	xfree(ms->shadowMem);
-	ms->shadowMem = NULL;
-    }
-
-    UnmapMem(pScrn);
-
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-		   DRM_BO_HINT_DONT_FENCE, 0, 0);
-
-    /* unreference it */
-    drmBOUnreference(ms->fd, &ms->bo);
-
     drmBOCreate(ms->fd,
 		pScrn->virtualY * pScrn->displayWidth *
 		pScrn->bitsPerPixel / 8, 0, NULL,
 		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_CACHED_MAPPED
 		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
+		0, &ms->bo);
 
     MapMem(pScrn);
 
@@ -498,7 +487,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 	}
 	fbstart = ms->shadowMem;
     } else {
-	fbstart = ms->virtual;
+	fbstart = ms->bo.virtual;
     }
 
     /*
@@ -526,9 +515,49 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
     pScrn->frameY0 = 0;
     AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
+    UnmapMem(pScrn);
+
+    ms->front = TRUE;
+
     return TRUE;
 }
 
+static Bool
+crtc_resize(ScrnInfoPtr pScrn, int width, int height)
+{
+    modesettingPtr ms = modesettingPTR(pScrn);
+    ScreenPtr pScreen = pScrn->pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    Bool fbAccessDisabled;
+    CARD8 *fbstart;
+
+    if (width == pScrn->virtualX && height == pScrn->virtualY)
+	return TRUE;
+
+    ErrorF("RESIZING TO %dx%d\n", width, height);
+
+    pScrn->virtualX = width;
+    pScrn->virtualY = height;
+    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+    if (ms->shadowMem) {
+	xfree(ms->shadowMem);
+	ms->shadowMem = NULL;
+    }
+
+    drmModeRmFB(ms->fd, ms->fb_id);
+
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
+
+    /* unreference it */
+    drmBOUnreference(ms->fd, &ms->bo);
+    ms->front = FALSE;
+
+    /* now create new frontbuffer */
+    return CreateFrontBuffer(pScrn);
+}
+
 static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
     crtc_resize
 };
@@ -713,6 +742,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     xf86LoaderReqSymLists(fbSymbols, NULL);
 
+    xf86LoadSubModule(pScrn, "exa");
+
+#ifdef DRI2
+    xf86LoadSubModule(pScrn, "dri2");
+#endif
+
     return TRUE;
 }
 
@@ -744,7 +779,7 @@ WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
 
     *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
 
-    return ((CARD8 *) ms->virtual + row * (*size) + offset);
+    return ((CARD8 *) ms->bo.virtual + row * (*size) + offset);
 }
 
 static Bool
@@ -752,15 +787,23 @@ CreateScreenResources(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     Bool ret;
 
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
 
-    shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
+    if (ms->shadowFB)
+    	shadowAdd(pScreen, rootPixmap,
 	      ms->update, WindowLinear, 0, 0);
 
+    if (!pScreen->ModifyPixmapHeader(pScreen->GetScreenPixmap(pScreen),
+                                     -1, -1, -1, -1, -1,
+                                     ms->shadowFB ? (pointer)ms->shadowMem : (pointer)ms->bo.virtual))
+	FatalError("Couldn't adjust screen pixmap\n");
+
+
     return ret;
 }
 
@@ -775,6 +818,30 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     MessageType from;
     CARD8 *fbstart;
 
+    /* deal with server regeneration */
+    if (ms->fd < 0) {
+    	char *BusID;
+
+    	BusID = xalloc(64);
+    	sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	    ms->PciInfo->dev, ms->PciInfo->func
+#else
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	);
+
+    	ms->fd = drmOpen(NULL, BusID);
+
+    	if (ms->fd < 0)
+	    return FALSE;
+    }
+
+    pScrn->pScreen = pScreen;
+
     pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
 
     miClearVisualTypes();
@@ -787,9 +854,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!miSetPixmapDepths())
 	return FALSE;
 
-    if (!MapMem(pScrn))
-	return FALSE;
-
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
 
@@ -797,9 +861,10 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 		pScrn->virtualY * pScrn->displayWidth *
 		pScrn->bitsPerPixel / 8, 0, NULL,
 		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_CACHED_MAPPED
 		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
+		0, &ms->bo);
 
     MapMem(pScrn);
 
@@ -821,7 +886,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	}
 	fbstart = ms->shadowMem;
     } else {
-	fbstart = ms->virtual;
+	fbstart = ms->bo.virtual;
     }
 
     if (!fbScreenInit(pScreen, fbstart,
@@ -853,18 +918,18 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 		       "Shadow framebuffer initialization failed.\n");
 	    return FALSE;
 	}
-
-	ms->createScreenResources = pScreen->CreateScreenResources;
-	pScreen->CreateScreenResources = CreateScreenResources;
     }
 
+    ms->createScreenResources = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = CreateScreenResources;
+
     xf86SetBlackWhitePixels(pScreen);
 
 #if 0
     glucoseScreenInit(pScreen, 0);
 #endif
-#if 0
-    ms->pExa = ExaInit(pScreen);
+#if 1
+    ms->pExa = ExaInit(pScrn);
 #endif
 
     miInitializeBackingStore(pScreen);
@@ -872,8 +937,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     xf86SetSilkenMouse(pScreen);
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
-    /* Need to extend HWcursor support in kernel to handle mask interleave ?? */
-    xf86_cursors_init (pScreen, 64, 64,
+    /* Need to extend HWcursor support to handle mask interleave */
+    if (!ms->SWCursor)
+	xf86_cursors_init (pScreen, 64, 64,
 			       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
 			       HARDWARE_CURSOR_ARGB);
 
@@ -908,6 +974,14 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
+#ifdef DRI2
+    driScreenInit(pScreen);
+#endif
+
+    UnmapMem(pScrn);
+
+    ms->front = TRUE;
+
     return EnterVT(scrnIndex, 0);
 }
 
@@ -944,6 +1018,8 @@ LeaveVT(int scrnIndex, int flags)
     for (o = 0; o < config->num_crtc; o++) {
 	xf86CrtcPtr crtc = config->crtc[o];
 
+    	cursor_destroy(crtc);
+
 	if (crtc->rotatedPixmap || crtc->rotatedData) {
 	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
 					crtc->rotatedData);
@@ -952,11 +1028,25 @@ LeaveVT(int scrnIndex, int flags)
 	}
     }
 
-    xf86_hide_cursors(pScrn);
+    drmModeRmFB(ms->fd, ms->fb_id);
 
-    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
+
+    drmBOUnreference(ms->fd, &ms->bo);
+    ms->front = FALSE;
 
     RestoreHWState(pScrn);
+
+#if 0
+    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+    drmMMLock(ms->fd, DRM_BO_MEM_TT, 1, 0);
+#endif
+#ifdef DRI2
+    driLock(pScrn->pScreen);
+#endif
+
+    pScrn->vtSema = FALSE;
 }
 
 /*
@@ -968,6 +1058,17 @@ EnterVT(int scrnIndex, int flags)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
+#if 0
+    if (pScrn->vtSema) {
+	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
+    }
+#endif
+
+#ifdef DRI2
+    driUnlock(pScrn->pScreen);
+#endif
+
     /*
      * Only save state once per server generation since that's what most
      * drivers do.  Could change this to save state at each VT enter.
@@ -977,7 +1078,8 @@ EnterVT(int scrnIndex, int flags)
 	SaveHWState(pScrn);
     }
 
-    drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    if (!ms->front)
+	CreateFrontBuffer(pScrn);
 
     if (!xf86SetDesiredModes(pScrn))
 	return FALSE;
@@ -1001,15 +1103,19 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
-    if (pScrn->vtSema == TRUE) {
-	LeaveVT(scrnIndex, 0);
-	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    if (pScrn->vtSema) {
+    	LeaveVT(scrnIndex, 0);
+#if 0
+    	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
+#endif
     }
 
-    UnmapMem(pScrn);
+#ifdef DRI2
+    driCloseScreen(pScreen);
+#endif
 
-    if (ms->shadowFB)
-	pScreen->CreateScreenResources = ms->createScreenResources;
+    pScreen->CreateScreenResources = ms->createScreenResources;
 
     if (ms->shadowMem) {
 	xfree(ms->shadowMem);
@@ -1019,14 +1125,8 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     if (ms->pExa)
 	ExaClose(pScrn);
 
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-		   DRM_BO_HINT_DONT_FENCE, 0, 0);
-
-    drmBOUnreference(ms->fd, &ms->bo);
-
     drmClose(ms->fd);
+    ms->fd = -1;
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index c9cb764..7ac6466 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -31,6 +31,7 @@
 #include <drm.h>
 #include <xf86drm.h>
 #include <xf86drmMode.h>
+#include <xf86mm.h>
 #include "shadow.h"
 #include "exa.h"
 
@@ -50,6 +51,7 @@ typedef struct _modesettingRec
     unsigned int fb_id;
     void *virtual;
     drmBO bo;
+    Bool front;
 
     EntPtr entityPrivate;
 
@@ -68,9 +70,6 @@ typedef struct _modesettingRec
     Bool SWCursor;
     CloseScreenProcPtr CloseScreen;
 
-    Bool directRenderingDisabled;      /* DRI disabled in PreInit. */
-    Bool directRenderingEnabled;       /* DRI enabled this generation. */
-
     /* Broken-out options. */
     OptionInfoPtr Options;
 
@@ -85,6 +84,11 @@ typedef struct _modesettingRec
     /* exa */
     ExaDriverPtr pExa;
     drmBO exa_bo;
+
+    /* dri2 */
+    drm_context_t context;
+    drm_hw_lock_t *lock;
+    int lock_held;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 70968f0..9327cbc 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -36,6 +36,14 @@
 
 #include "driver.h"
 
+struct PixmapPriv {
+    drmBO bo;
+    #if 0
+    dri_fence *fence;
+    #endif
+    int flags;
+};
+
 static void
 ExaWaitMarker(ScreenPtr pScreen, int marker)
 {
@@ -44,10 +52,6 @@ ExaWaitMarker(ScreenPtr pScreen, int marker)
 static int
 ExaMarkSync(ScreenPtr pScreen)
 {
-    /*
-     * See ExaWaitMarker.
-     */
-
     return 1;
 }
 
@@ -56,6 +60,30 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
 {
     ScreenPtr pScreen = pPix->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct PixmapPriv *priv;
+    int ret;
+
+    priv = exaGetPixmapDriverPrivate(pPix);
+
+    if (!priv)
+	return FALSE;
+
+    if (priv->bo.handle) {
+    	void *virtual;
+
+    	ret = drmBOMap(ms->fd,
+	     &priv->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
+	if (ret) {
+    	    driUnlock(pScreen);
+	    FatalError("Failed to map pixmap: %s\n", strerror(-ret));
+	    return;
+	}
+
+	pPix->devPrivate.ptr = priv->bo.virtual;
+    }
+
 
     return TRUE;
 }
@@ -65,6 +93,26 @@ ExaFinishAccess(PixmapPtr pPix, int index)
 {
     ScreenPtr pScreen = pPix->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct PixmapPriv *priv;
+    int ret;
+
+    priv = exaGetPixmapDriverPrivate(pPix);
+
+    if (!priv)
+	return;
+
+    if (priv->bo.handle) {
+	ret = drmBOUnmap(ms->fd, &priv->bo);
+	if (ret) {
+	    driUnlock(pScreen);
+	    FatalError("Failed to unmap pixmap: %s\n", strerror(-ret));
+	    return;
+	}
+
+	pPix->devPrivate.ptr = NULL;
+    }
 }
 
 static void
@@ -84,6 +132,8 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
 
+    ErrorF("SOLID\n");
+
     if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
 	return FALSE;
 
@@ -91,7 +141,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
     if (pPixmap->drawable.depth == 4)
 	return FALSE;
 
-    return TRUE;
+    return FALSE;
 }
 
 static void
@@ -106,11 +156,13 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
 
+    ErrorF("COPY\n");
+
     /* can't do depth 4 */
     if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4)
 	return FALSE;
 
-    return TRUE;
+    return FALSE;
 }
 
 static void
@@ -138,6 +190,8 @@ ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
+    ErrorF("UPLOAD\n");
+
     return FALSE;
 }
 
@@ -158,18 +212,118 @@ ExaCheckComposite(int op,
     int w = pDraw->width;
     int h = pDraw->height;
 
-    return TRUE;
+    return FALSE;
 }
 
-static Bool
-ExaPixmapIsOffscreen(PixmapPtr p)
+static void *
+ExaCreatePixmap(ScreenPtr pScreen, int size, int align)
 {
-    ScreenPtr pScreen = p->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv;
+    void *virtual;
+
+    priv = xcalloc(1, sizeof(struct PixmapPriv));
+    if (!priv)
+        return NULL;
+
+    if (size == 0)
+	return priv;
+
+    drmBOCreate(ms->fd, size, 4096, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_CACHED_MAPPED,
+		0, &priv->bo);
+
+    return priv;
+}
+
+static void 
+ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
+{
+    struct PixmapPriv *priv = (struct PixmapPriv *)dPriv;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    if (!priv)
+    	return;
+
+    if (priv->bo.handle)
+	drmBOUnreference(ms->fd, &priv->bo);
+
+    xfree(priv);
+}
+
+static Bool 
+ExaPixmapIsOffscreen(PixmapPtr pPixmap)
+{
+    struct PixmapPriv *priv;
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    priv = exaGetPixmapDriverPrivate(pPixmap);
+
+    if (!priv)
+       return FALSE;
+
+    if (priv->bo.handle)
+       return TRUE;
 
     return FALSE;
 }
 
+/* FIXME !! */
+unsigned int
+driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags)
+{
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv;
+
+    *flags = 0;
+
+    if (rootPixmap == pPixmap)
+        return ms->bo.handle;
+
+    if (!ms->pExa)
+    	return 0;
+
+    priv = exaGetPixmapDriverPrivate(pPixmap);
+
+    if (!priv)
+       return 0;
+
+    if (priv->bo.handle)
+        return priv->bo.handle;
+
+    return 0;
+}
+
+static Bool 
+ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
+		      int depth, int bitsPerPixel, int devKind,
+		      pointer pPixData)
+{
+    ScreenPtr	pScreen = pPixmap->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    if (rootPixmap == pPixmap) {
+	miModifyPixmapHeader(pPixmap, width, height, depth,
+			     bitsPerPixel, devKind, NULL);
+
+	return TRUE;
+    }
+
+    return FALSE;
+}
+
+
 void
 ExaClose(ScrnInfoPtr pScrn)
 {
@@ -177,7 +331,9 @@ ExaClose(ScrnInfoPtr pScrn)
 
     exaDriverFini(pScrn->pScreen);
 
+#if 0
     drmBOUnreference(ms->fd, &ms->exa_bo);
+#endif
 }
 
 ExaDriverPtr
@@ -191,20 +347,22 @@ ExaInit(ScrnInfoPtr pScrn)
 	goto out_err;
     }
 
+#if 0
     /* Create a 256KB offscreen area */
     drmBOCreate(ms->fd, 256 * 1024, 0, NULL,
 		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT,
 		DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
+#endif
 
     memset(pExa, 0, sizeof(*pExa));
     pExa->exa_major = 2;
-    pExa->exa_minor = 2;
-    pExa->memoryBase = ms->exa_bo.virtual;
+    pExa->exa_minor = 4;
+    pExa->memoryBase = 0; /* ms->exa_bo.virtual; */
+    pExa->memorySize = 0; /* ms->exa_bo.size; */
     pExa->offScreenBase = 0;
-    pExa->memorySize = ms->exa_bo.size;
     pExa->pixmapOffsetAlign = 8;
     pExa->pixmapPitchAlign = 32 * 4;
-    pExa->flags = EXA_OFFSCREEN_PIXMAPS;
+    pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
     pExa->maxX = 8191;		       /* FIXME */
     pExa->maxY = 8191;		       /* FIXME */
     pExa->WaitMarker = ExaWaitMarker;
@@ -223,6 +381,9 @@ ExaInit(ScrnInfoPtr pScrn)
     pExa->PrepareAccess = ExaPrepareAccess;
     pExa->FinishAccess = ExaFinishAccess;
     pExa->UploadToScreen = ExaUploadToScreen;
+    pExa->CreatePixmap = ExaCreatePixmap;
+    pExa->DestroyPixmap = ExaDestroyPixmap;
+    pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
 
     if (!exaDriverInit(pScrn->pScreen, pExa)) {
 	goto out_err;
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index 7767ef2..484acb2 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -51,6 +51,23 @@
 
 #include "driver.h"
 
+static char *connector_enum_list[] = {
+    "Unknown",
+    "VGA",
+    "DVI-I",
+    "DVI-D",
+    "DVI-A",
+    "Composite",
+    "SVIDEO",
+    "LVDS",
+    "Component",
+    "9-pin DIN",
+    "DisplayPort",
+    "HDMI Type A",
+    "HDMI Type B",
+};
+
+
 static void
 dpms(xf86OutputPtr output, int mode)
 {
@@ -145,6 +162,7 @@ get_modes(xf86OutputPtr output)
 	    mode->VRefresh = xf86ModeVRefresh(mode);
 	    mode->Private = (void *)drm_mode;
 	    xf86SetModeDefaultName(mode);
+	    ErrorF("MODE %s\n",mode->name);
 	    modes = xf86ModesAdd(modes, mode);
 	    xf86PrintModeline(0, mode);
 	}
@@ -237,7 +255,6 @@ output_init(ScrnInfoPtr pScrn)
 	if (!drm_connector)
 	    goto out;
 
-#if 0
 	for (p = 0; p < drm_connector->count_props; p++) {
 	    drmModePropertyPtr prop;
 
@@ -249,41 +266,16 @@ output_init(ScrnInfoPtr pScrn)
 
 		for (v = 0; v < prop->count_values; v++)
 		    ErrorF("%s %lld\n", prop->name, prop->values[v]);
-
-		for (v = 0; v < prop->count_enums; v++) {
-		    ErrorF("%s %s\n", prop->name, prop->enums[v].name);
-		    if (drm_connector->prop_values[p] == prop->enums[v].value) {
-			if (!strncmp("Connector Type", prop->name, 14)) {
-			    ErrorF("WE'VE GOT %s\n", prop->enums[v].name);
-			    name = xalloc(strlen(prop->enums[v].name));
-			    strncpy(name, prop->enums[v].name, strlen(name));
-			}
-		    }
-		    if (name)
-			break;
-		}
-		if (name)
-		    break;
 	    }
 	}
 
-	if (!name)
-	    continue;
-#endif
-
-
-#if 0
-	free(name);
-#endif
-
-	
-	name = "Unknown";
+	name = connector_enum_list[drm_connector->connector_type];
 
 	output = xf86OutputCreate(pScrn, &output_funcs, name);
 	if (!output)
 	    continue;
 
-	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoder);
+	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
 	if (drm_encoder) {
 	output->possible_crtcs = drm_encoder->crtcs;
 	output->possible_clones = drm_encoder->clones;
commit 6a1910a0e562e36e0836e948b287ec37c90df02d
Author: Zack Rusin <zack at tungstengraphics.com>
Date:   Mon Jun 16 00:31:53 2008 -0400

    Adding some readme.
commit cba8b25a7e2608cd093283f86f08fba50a6a62f7
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Mon Jun 2 11:17:47 2008 +0100

    Bring inline with current modesetting-101 branch for connector/encoder changes

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index bf726b5..14ee53e 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -104,7 +104,7 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     xf86OutputPtr output = config->output[config->compat_output];
-    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeConnectorPtr drm_connector = output->driver_private;
     struct crtc_private *crtcp = crtc->driver_private;
     drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
     struct drm_mode_modeinfo drm_mode;
@@ -125,7 +125,7 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
 
     drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
-		   &drm_output->output_id, 1, &drm_mode);
+		   &drm_connector->connector_id, 1, &drm_mode);
 }
 
 void
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index 4a67ccc..7767ef2 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -103,9 +103,9 @@ commit(xf86OutputPtr output)
 static xf86OutputStatus
 detect(xf86OutputPtr output)
 {
-    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeConnectorPtr drm_connector = output->driver_private;
 
-    switch (drm_output->connection) {
+    switch (drm_connector->connection) {
     case DRM_MODE_CONNECTED:
 	return XF86OutputStatusConnected;
     case DRM_MODE_DISCONNECTED:
@@ -118,13 +118,13 @@ detect(xf86OutputPtr output)
 static DisplayModePtr
 get_modes(xf86OutputPtr output)
 {
-    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeConnectorPtr drm_connector = output->driver_private;
     struct drm_mode_modeinfo *drm_mode = NULL;
     DisplayModePtr modes = NULL, mode = NULL;
     int i;
 
-    for (i = 0; i < drm_output->count_modes; i++) {
-	drm_mode = &drm_output->modes[i];
+    for (i = 0; i < drm_connector->count_modes; i++) {
+	drm_mode = &drm_connector->modes[i];
 	if (drm_mode) {
 	    mode = xcalloc(1, sizeof(DisplayModeRec));
 	    if (!mode)
@@ -156,7 +156,7 @@ get_modes(xf86OutputPtr output)
 static void
 destroy(xf86OutputPtr output)
 {
-    drmModeFreeOutput(output->driver_private);
+    drmModeFreeConnector(output->driver_private);
 }
 
 static void
@@ -220,10 +220,11 @@ output_init(ScrnInfoPtr pScrn)
     modesettingPtr ms = modesettingPTR(pScrn);
     xf86OutputPtr output;
     drmModeResPtr res;
-    drmModeOutputPtr drm_output = NULL;
+    drmModeConnectorPtr drm_connector = NULL;
+    drmModeEncoderPtr drm_encoder = NULL;
     drmModeCrtcPtr crtc;
     char *name;
-    int o, v, p;
+    int c, v, p;
 
     res = drmModeGetResources(ms->fd);
     if (res == 0) {
@@ -231,15 +232,16 @@ output_init(ScrnInfoPtr pScrn)
 	return;
     }
 
-    for (o = 0; o < res->count_outputs; o++) {
-	drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
-	if (!drm_output)
+    for (c = 0; c < res->count_connectors; c++) {
+	drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
+	if (!drm_connector)
 	    goto out;
 
-	for (p = 0; p < drm_output->count_props; p++) {
+#if 0
+	for (p = 0; p < drm_connector->count_props; p++) {
 	    drmModePropertyPtr prop;
 
-	    prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
+	    prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
 
 	    name = NULL;
 	    if (prop) {
@@ -250,7 +252,7 @@ output_init(ScrnInfoPtr pScrn)
 
 		for (v = 0; v < prop->count_enums; v++) {
 		    ErrorF("%s %s\n", prop->name, prop->enums[v].name);
-		    if (drm_output->prop_values[p] == prop->enums[v].value) {
+		    if (drm_connector->prop_values[p] == prop->enums[v].value) {
 			if (!strncmp("Connector Type", prop->name, 14)) {
 			    ErrorF("WE'VE GOT %s\n", prop->enums[v].name);
 			    name = xalloc(strlen(prop->enums[v].name));
@@ -267,16 +269,29 @@ output_init(ScrnInfoPtr pScrn)
 
 	if (!name)
 	    continue;
+#endif
+
+
+#if 0
+	free(name);
+#endif
+
+	
+	name = "Unknown";
 
 	output = xf86OutputCreate(pScrn, &output_funcs, name);
 	if (!output)
 	    continue;
 
-	free(name);
-
-	output->possible_crtcs = drm_output->crtcs;
-	output->possible_clones = drm_output->clones;
-	output->driver_private = drm_output;
+	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoder);
+	if (drm_encoder) {
+	output->possible_crtcs = drm_encoder->crtcs;
+	output->possible_clones = drm_encoder->clones;
+	} else {
+	output->possible_crtcs = 0;
+	output->possible_clones = 0;
+	}
+	output->driver_private = drm_connector;
 	output->subpixel_order = SubPixelHorizontalRGB;
 	output->interlaceAllowed = FALSE;
 	output->doubleScanAllowed = FALSE;
commit 000ead4503ddcfdf66ce9fffc572a3a741f4055a
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Wed May 28 19:59:38 2008 +0100

    Plug in hardware cursor support

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index 66b23f6..bf726b5 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -47,6 +47,13 @@
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 
+struct crtc_private {
+    drmModeCrtcPtr drm_crtc;
+
+    /* hwcursor */
+    drmBO cursor_bo;
+};
+
 static void
 crtc_dpms(xf86CrtcPtr crtc, int mode)
 {
@@ -98,7 +105,8 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     xf86OutputPtr output = config->output[config->compat_output];
     drmModeOutputPtr drm_output = output->driver_private;
-    drmModeCrtcPtr drm_crtc = crtc->driver_private;
+    struct crtc_private *crtcp = crtc->driver_private;
+    drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
     struct drm_mode_modeinfo drm_mode;
 
     drm_mode.clock = mode->Clock;
@@ -157,13 +165,64 @@ crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
 static void
 crtc_destroy(xf86CrtcPtr crtc)
 {
-    drmModeFreeCrtc(crtc->driver_private);
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+    drmModeFreeCrtc(crtcp->drm_crtc);
+}
+
+static void
+crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+{
+    unsigned char *ptr;
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, 0, (void **)&ptr);
+
+    memcpy (ptr, image, 64 * 64 * 4);
+
+    drmBOUnmap(ms->fd, &crtcp->cursor_bo);
+}
+
+static void
+crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y);
+}
+
+static void
+crtc_show_cursor (xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
+}
+
+static void
+crtc_hide_cursor (xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
+}
+
+static void
+crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
 }
 
 static const xf86CrtcFuncsRec crtc_funcs = {
     .dpms = crtc_dpms,
-    .save = NULL,		       /* XXX */
-    .restore = NULL,		       /* XXX */
+    .save = NULL,
+    .restore = NULL,
     .lock = crtc_lock,
     .unlock = crtc_unlock,
     .mode_fixup = crtc_mode_fixup,
@@ -174,13 +233,13 @@ static const xf86CrtcFuncsRec crtc_funcs = {
     .shadow_create = crtc_shadow_create,
     .shadow_allocate = crtc_shadow_allocate,
     .shadow_destroy = crtc_shadow_destroy,
-//    .set_cursor_colors = crtc_set_cursor_colors,
-//    .set_cursor_position = crtc_set_cursor_position,
-//    .show_cursor = crtc_show_cursor,
-//    .hide_cursor = crtc_hide_cursor,
-//    .load_cursor_image = crtc_load_cursor_image, 
-//    .load_cursor_argb = crtc_load_cursor_argb,
-    .destroy = crtc_destroy,	       /* XXX */
+    .set_cursor_colors = crtc_set_cursor_colors,
+    .set_cursor_position = crtc_set_cursor_position,
+    .show_cursor = crtc_show_cursor,
+    .hide_cursor = crtc_hide_cursor,
+    .load_cursor_image = NULL,	/* lets convert to argb only */
+    .load_cursor_argb = crtc_load_cursor_argb,
+    .destroy = crtc_destroy,
 };
 
 void
@@ -190,6 +249,7 @@ crtc_init(ScrnInfoPtr pScrn)
     xf86CrtcPtr crtc;
     drmModeResPtr res;
     drmModeCrtcPtr drm_crtc = NULL;
+    struct crtc_private *crtcp;
     int c, k, p;
 
     res = drmModeGetResources(ms->fd);
@@ -207,7 +267,21 @@ crtc_init(ScrnInfoPtr pScrn)
 	if (crtc == NULL)
 	    goto out;
 
-	crtc->driver_private = drm_crtc;
+	crtcp = xalloc(sizeof(struct crtc_private));
+	if (!crtcp) {
+	    xf86CrtcDestroy(crtc);
+	    goto out;
+	}
+
+ 	crtcp->drm_crtc = drm_crtc;
+
+	crtc->driver_private = crtcp;
+    
+        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
     }
 
   out:
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index de4b260..8f1c905 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -872,6 +872,11 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     xf86SetSilkenMouse(pScreen);
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
+    /* Need to extend HWcursor support in kernel to handle mask interleave ?? */
+    xf86_cursors_init (pScreen, 64, 64,
+			       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
+			       HARDWARE_CURSOR_ARGB);
+
     /* Must force it before EnterVT, so we are in control of VT and
      * later memory should be bound when allocating, e.g rotate_mem */
     pScrn->vtSema = TRUE;
commit f9f7a872bf3f8522213aabb291d9d54e56d48c4b
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Wed May 28 15:55:36 2008 +0100

    Run indent

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index f168126..66b23f6 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -50,22 +50,22 @@
 static void
 crtc_dpms(xf86CrtcPtr crtc, int mode)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
-
-   switch (mode) {
-   case DPMSModeOn:
-   case DPMSModeStandby:
-   case DPMSModeSuspend:
-      break;
-   case DPMSModeOff:
-      break;
-   }
+    ScrnInfoPtr pScrn = crtc->scrn;
+
+    switch (mode) {
+    case DPMSModeOn:
+    case DPMSModeStandby:
+    case DPMSModeSuspend:
+	break;
+    case DPMSModeOff:
+	break;
+    }
 }
 
 static Bool
 crtc_lock(xf86CrtcPtr crtc)
 {
-   return FALSE;
+    return FALSE;
 }
 
 static void
@@ -87,43 +87,43 @@ static Bool
 crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
 		DisplayModePtr adjusted_mode)
 {
-   return TRUE;
+    return TRUE;
 }
 
 static void
 crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
 	      DisplayModePtr adjusted_mode, int x, int y)
 {
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-   modesettingPtr ms = modesettingPTR(crtc->scrn);
-   xf86OutputPtr output = config->output[config->compat_output];
-   drmModeOutputPtr drm_output = output->driver_private;
-   drmModeCrtcPtr drm_crtc = crtc->driver_private;
-   struct drm_mode_modeinfo drm_mode;
-
-   drm_mode.clock = mode->Clock;
-   drm_mode.hdisplay = mode->HDisplay;
-   drm_mode.hsync_start = mode->HSyncStart;
-   drm_mode.hsync_end = mode->HSyncEnd;
-   drm_mode.htotal = mode->HTotal;
-   drm_mode.vdisplay = mode->VDisplay;
-   drm_mode.vsync_start = mode->VSyncStart;
-   drm_mode.vsync_end = mode->VSyncEnd;
-   drm_mode.vtotal = mode->VTotal;
-   drm_mode.flags = mode->Flags;
-   drm_mode.hskew = mode->HSkew;
-   drm_mode.vscan = mode->VScan;
-   drm_mode.vrefresh = mode->VRefresh;
-   strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
-
-   drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
-		     &drm_output->output_id, 1, &drm_mode);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    xf86OutputPtr output = config->output[config->compat_output];
+    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeCrtcPtr drm_crtc = crtc->driver_private;
+    struct drm_mode_modeinfo drm_mode;
+
+    drm_mode.clock = mode->Clock;
+    drm_mode.hdisplay = mode->HDisplay;
+    drm_mode.hsync_start = mode->HSyncStart;
+    drm_mode.hsync_end = mode->HSyncEnd;
+    drm_mode.htotal = mode->HTotal;
+    drm_mode.vdisplay = mode->VDisplay;
+    drm_mode.vsync_start = mode->VSyncStart;
+    drm_mode.vsync_end = mode->VSyncEnd;
+    drm_mode.vtotal = mode->VTotal;
+    drm_mode.flags = mode->Flags;
+    drm_mode.hskew = mode->HSkew;
+    drm_mode.vscan = mode->VScan;
+    drm_mode.vrefresh = mode->VRefresh;
+    strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
+
+    drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
+		   &drm_output->output_id, 1, &drm_mode);
 }
 
 void
 crtc_load_lut(xf86CrtcPtr crtc)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 }
 
 static void
@@ -135,81 +135,81 @@ crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
 static void *
 crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 
-   return NULL;
+    return NULL;
 }
 
 static PixmapPtr
 crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 
-   return NULL;
+    return NULL;
 }
 
 static void
 crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 }
 
 static void
 crtc_destroy(xf86CrtcPtr crtc)
 {
-   drmModeFreeCrtc(crtc->driver_private);
+    drmModeFreeCrtc(crtc->driver_private);
 }
 
 static const xf86CrtcFuncsRec crtc_funcs = {
-   .dpms = crtc_dpms,
-   .save = NULL,			/* XXX */
-   .restore = NULL,			/* XXX */
-   .lock = crtc_lock,
-   .unlock = crtc_unlock,
-   .mode_fixup = crtc_mode_fixup,
-   .prepare = crtc_prepare,
-   .mode_set = crtc_mode_set,
-   .commit = crtc_commit,
-   .gamma_set = crtc_gamma_set,
-   .shadow_create = crtc_shadow_create,
-   .shadow_allocate = crtc_shadow_allocate,
-   .shadow_destroy = crtc_shadow_destroy,
+    .dpms = crtc_dpms,
+    .save = NULL,		       /* XXX */
+    .restore = NULL,		       /* XXX */
+    .lock = crtc_lock,
+    .unlock = crtc_unlock,
+    .mode_fixup = crtc_mode_fixup,
+    .prepare = crtc_prepare,
+    .mode_set = crtc_mode_set,
+    .commit = crtc_commit,
+    .gamma_set = crtc_gamma_set,
+    .shadow_create = crtc_shadow_create,
+    .shadow_allocate = crtc_shadow_allocate,
+    .shadow_destroy = crtc_shadow_destroy,
 //    .set_cursor_colors = crtc_set_cursor_colors,
 //    .set_cursor_position = crtc_set_cursor_position,
 //    .show_cursor = crtc_show_cursor,
 //    .hide_cursor = crtc_hide_cursor,
 //    .load_cursor_image = crtc_load_cursor_image, 
 //    .load_cursor_argb = crtc_load_cursor_argb,
-   .destroy = crtc_destroy,		/* XXX */
+    .destroy = crtc_destroy,	       /* XXX */
 };
 
 void
 crtc_init(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
-   xf86CrtcPtr crtc;
-   drmModeResPtr res;
-   drmModeCrtcPtr drm_crtc = NULL;
-   int c, k, p;
-
-   res = drmModeGetResources(ms->fd);
-   if (res == 0) {
-      ErrorF("Failed drmModeGetResources %d\n",errno);
-      return;
-   }
-
-   for (c = 0; c < res->count_crtcs; c++) {
-      drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
-      if (!drm_crtc)
-	 continue;
-
-      crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
-      if (crtc == NULL)
-	 goto out;
-
-      crtc->driver_private = drm_crtc;
-   }
-
-out:
-   drmModeFreeResources(res);
+    modesettingPtr ms = modesettingPTR(pScrn);
+    xf86CrtcPtr crtc;
+    drmModeResPtr res;
+    drmModeCrtcPtr drm_crtc = NULL;
+    int c, k, p;
+
+    res = drmModeGetResources(ms->fd);
+    if (res == 0) {
+	ErrorF("Failed drmModeGetResources %d\n", errno);
+	return;
+    }
+
+    for (c = 0; c < res->count_crtcs; c++) {
+	drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
+	if (!drm_crtc)
+	    continue;
+
+	crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
+	if (crtc == NULL)
+	    goto out;
+
+	crtc->driver_private = drm_crtc;
+    }
+
+  out:
+    drmModeFreeResources(res);
 }
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index ba6bfdf..de4b260 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -65,12 +65,15 @@ static Bool SaveHWState(ScrnInfoPtr pScrn);
 static Bool RestoreHWState(ScrnInfoPtr pScrn);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
-static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags);
+static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
+			    int flags);
 static void FreeScreen(int scrnIndex, int flags);
 static void LeaveVT(int scrnIndex, int flags);
 static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
-static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv);
+static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
+		       char **argv);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
+
 #if XSERVER_LIBPCIACCESS
 static Bool
 pci_probe(DriverPtr driver,
@@ -81,64 +84,64 @@ static Bool Probe(DriverPtr drv, int flags);
 
 #if XSERVER_LIBPCIACCESS
 static const struct pci_id_match device_match[] = {
-   {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
-   {0, 0, 0},
+    {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
+    {0, 0, 0},
 };
 #endif
 
 _X_EXPORT DriverRec modesetting = {
-   1,
-   "modesetting",
-   Identify,
+    1,
+    "modesetting",
+    Identify,
 #if XSERVER_LIBPCIACCESS
-   NULL,
+    NULL,
 #else
-   Probe,
+    Probe,
 #endif
-   AvailableOptions,
-   NULL,
-   0,
-   NULL,
+    AvailableOptions,
+    NULL,
+    0,
+    NULL,
 #if XSERVER_LIBPCIACCESS
-   device_match,
-   pci_probe
+    device_match,
+    pci_probe
 #endif
 };
 
 static SymTabRec Chipsets[] = {
-   {0x2592, "Intel Graphics Device"},
-   {-1, NULL}
+    {0x2592, "Intel Graphics Device"},
+    {-1, NULL}
 };
 
 static PciChipsets PciDevices[] = {
-   {0x2592, 0x2592, RES_SHARED_VGA},
-   {-1, -1, RES_UNDEFINED}
+    {0x2592, 0x2592, RES_SHARED_VGA},
+    {-1, -1, RES_UNDEFINED}
 };
 
 typedef enum
 {
-   OPTION_NOACCEL,
-   OPTION_SW_CURSOR,
-   OPTION_SHADOWFB,
+    OPTION_NOACCEL,
+    OPTION_SW_CURSOR,
+    OPTION_SHADOWFB,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
-   {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
-   {-1, NULL, OPTV_NONE, {0}, FALSE}
+    {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
+    {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
 static const char *fbSymbols[] = {
-   "fbPictureInit",
-   "fbScreenInit",
-   NULL
+    "fbPictureInit",
+    "fbScreenInit",
+    NULL
 };
 
 static const char *ddcSymbols[] = {
-   "xf86PrintEDID",
-   "xf86SetDDCproperties",
-   NULL
+    "xf86PrintEDID",
+    "xf86SetDDCproperties",
+    NULL
 };
 
 static const char *shadowSymbols[] = {
@@ -148,9 +151,9 @@ static const char *shadowSymbols[] = {
 };
 
 static const char *i2cSymbols[] = {
-   "xf86CreateI2CBusRec",
-   "xf86I2CBusInit",
-   NULL
+    "xf86CreateI2CBusRec",
+    "xf86I2CBusInit",
+    NULL
 };
 
 int modesettingEntityIndex = -1;
@@ -158,16 +161,16 @@ int modesettingEntityIndex = -1;
 static MODULESETUPPROTO(Setup);
 
 static XF86ModuleVersionInfo VersRec = {
-   "modesetting",
-   MODULEVENDORSTRING,
-   MODINFOSTRING1,
-   MODINFOSTRING2,
-   XORG_VERSION_CURRENT,
-   PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
-   ABI_CLASS_VIDEODRV,
-   ABI_VIDEODRV_VERSION,
-   MOD_CLASS_VIDEODRV,
-   {0, 0, 0, 0}
+    "modesetting",
+    MODULEVENDORSTRING,
+    MODINFOSTRING1,
+    MODINFOSTRING2,
+    XORG_VERSION_CURRENT,
+    PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
+    ABI_CLASS_VIDEODRV,
+    ABI_VIDEODRV_VERSION,
+    MOD_CLASS_VIDEODRV,
+    {0, 0, 0, 0}
 };
 
 _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
@@ -175,44 +178,43 @@ _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
 static pointer
 Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 {
-   static Bool setupDone = 0;
-
-   /* This module should be loaded only once, but check to be sure.
-    */
-   if (!setupDone) {
-      setupDone = 1;
-      xf86AddDriver(&modesetting, module, HaveDriverFuncs);
-
-      /*
-       * Tell the loader about symbols from other modules that this module
-       * might refer to.
-       */
-      LoaderRefSymLists(fbSymbols,
-			shadowSymbols, ddcSymbols, NULL);
-
-      /*
-       * The return value must be non-NULL on success even though there
-       * is no TearDownProc.
-       */
-      return (pointer) 1;
-   } else {
-      if (errmaj)
-	 *errmaj = LDR_ONCEONLY;
-      return NULL;
-   }
+    static Bool setupDone = 0;
+
+    /* This module should be loaded only once, but check to be sure.
+     */
+    if (!setupDone) {
+	setupDone = 1;
+	xf86AddDriver(&modesetting, module, HaveDriverFuncs);
+
+	/*
+	 * Tell the loader about symbols from other modules that this module
+	 * might refer to.
+	 */
+	LoaderRefSymLists(fbSymbols, shadowSymbols, ddcSymbols, NULL);
+
+	/*
+	 * The return value must be non-NULL on success even though there
+	 * is no TearDownProc.
+	 */
+	return (pointer) 1;
+    } else {
+	if (errmaj)
+	    *errmaj = LDR_ONCEONLY;
+	return NULL;
+    }
 }
 
 static void
 Identify(int flags)
 {
-   xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
-		     Chipsets);
+    xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
+		      Chipsets);
 }
 
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
 {
-   return Options;
+    return Options;
 }
 
 #if XSERVER_LIBPCIACCESS
@@ -220,267 +222,271 @@ static Bool
 pci_probe(DriverPtr driver,
 	  int entity_num, struct pci_device *device, intptr_t match_data)
 {
-   ScrnInfoPtr scrn = NULL;
-   EntityInfoPtr entity;
-   DevUnion *private;
-
-   scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
-			      NULL, NULL, NULL, NULL, NULL);
-   if (scrn != NULL) {
-      scrn->driverVersion = 1;
-      scrn->driverName = "modesetting";
-      scrn->name = "modesetting";
-      scrn->Probe = NULL;
-
-      entity = xf86GetEntityInfo(entity_num);
-
-      switch (device->device_id) {
-      case 0x2592:
-	 scrn->PreInit = PreInit;
-	 scrn->ScreenInit = ScreenInit;
-	 scrn->SwitchMode = SwitchMode;
-	 scrn->AdjustFrame = AdjustFrame;
-	 scrn->EnterVT = EnterVT;
-	 scrn->LeaveVT = LeaveVT;
-	 scrn->FreeScreen = FreeScreen;
-	 scrn->ValidMode = ValidMode;
-	 break;
-      }
-   }
-   return scrn != NULL;
+    ScrnInfoPtr scrn = NULL;
+    EntityInfoPtr entity;
+    DevUnion *private;
+
+    scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
+			       NULL, NULL, NULL, NULL, NULL);
+    if (scrn != NULL) {
+	scrn->driverVersion = 1;
+	scrn->driverName = "modesetting";
+	scrn->name = "modesetting";
+	scrn->Probe = NULL;
+
+	entity = xf86GetEntityInfo(entity_num);
+
+	switch (device->device_id) {
+	case 0x2592:
+	    scrn->PreInit = PreInit;
+	    scrn->ScreenInit = ScreenInit;
+	    scrn->SwitchMode = SwitchMode;
+	    scrn->AdjustFrame = AdjustFrame;
+	    scrn->EnterVT = EnterVT;
+	    scrn->LeaveVT = LeaveVT;
+	    scrn->FreeScreen = FreeScreen;
+	    scrn->ValidMode = ValidMode;
+	    break;
+	}
+    }
+    return scrn != NULL;
 }
 #else
 static Bool
 Probe(DriverPtr drv, int flags)
 {
-   int i, numUsed, numDevSections, *usedChips;
-   EntPtr msEnt = NULL;
-   DevUnion *pPriv;
-   GDevPtr *devSections;
-   Bool foundScreen = FALSE;
-   pciVideoPtr *VideoInfo;
-   pciVideoPtr *ppPci;
-   int numDevs;
-
-   /*
-    * Find the config file Device sections that match this
-    * driver, and return if there are none.
-    */
-   if ((numDevSections =
-	xf86MatchDevice("modesetting", &devSections)) <= 0) {
-      return FALSE;
-   }
-
-   /*
-    * This probing is just checking the PCI data the server already
-    * collected.
-    */
-   if (!(VideoInfo = xf86GetPciVideoInfo()))
-      return FALSE;
+    int i, numUsed, numDevSections, *usedChips;
+    EntPtr msEnt = NULL;
+    DevUnion *pPriv;
+    GDevPtr *devSections;
+    Bool foundScreen = FALSE;
+    pciVideoPtr *VideoInfo;
+    pciVideoPtr *ppPci;
+    int numDevs;
+
+    /*
+     * Find the config file Device sections that match this
+     * driver, and return if there are none.
+     */
+    if ((numDevSections = xf86MatchDevice("modesetting", &devSections)) <= 0) {
+	return FALSE;
+    }
+
+    /*
+     * This probing is just checking the PCI data the server already
+     * collected.
+     */
+    if (!(VideoInfo = xf86GetPciVideoInfo()))
+	return FALSE;
 
 #if 0
-   numUsed = 0;
-   for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
-      for (numDevs = 0; numDevs < numDevSections; numDevs++) {
-         if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
-	 if (xf86ComparePciBusString(devSections[numDevs]->busID, (*ppPci)->bus, (*ppPci)->device, (*ppPci)->func)) {
-         /* Claim slot */
-         if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
-				    (*ppPci)->func)) {
-	    usedChips[numUsed++] = xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
-				   (*ppPci)->func, drv, (*ppPci)->chipType,
-				   NULL, TRUE);
-				   ErrorF("CLAIMED %d %d %d\n",(*ppPci)->bus,(*ppPci)->device, (*ppPci)->func);
-	 }
-	 }
-	 }
-      }
-   }
+    numUsed = 0;
+    for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
+	for (numDevs = 0; numDevs < numDevSections; numDevs++) {
+	    if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
+		if (xf86ComparePciBusString
+		    (devSections[numDevs]->busID, (*ppPci)->bus,
+		     (*ppPci)->device, (*ppPci)->func)) {
+		    /* Claim slot */
+		    if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
+					 (*ppPci)->func)) {
+			usedChips[numUsed++] =
+			    xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
+					     (*ppPci)->func, drv,
+					     (*ppPci)->chipType, NULL, TRUE);
+			ErrorF("CLAIMED %d %d %d\n", (*ppPci)->bus,
+			       (*ppPci)->device, (*ppPci)->func);
+		    }
+		}
+	    }
+	}
+    }
 #else
-   /* Look for Intel i8xx devices. */
-   numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
-				   Chipsets, PciDevices,
-				   devSections, numDevSections,
-				   drv, &usedChips);
+    /* Look for Intel i8xx devices. */
+    numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
+				    Chipsets, PciDevices,
+				    devSections, numDevSections,
+				    drv, &usedChips);
 #endif
 
-   if (flags & PROBE_DETECT) {
-      if (numUsed > 0)
-	 foundScreen = TRUE;
-   } else {
-   ErrorF("NUMUSED %d\n",numUsed);
-      for (i = 0; i < numUsed; i++) {
-	 ScrnInfoPtr pScrn = NULL;
-
-	 /* Allocate new ScrnInfoRec and claim the slot */
-	 if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
-					  PciDevices, NULL, NULL, NULL,
-					  NULL, NULL))) {
-	    EntityInfoPtr pEnt;
-
-	    pEnt = xf86GetEntityInfo(usedChips[i]);
-
-	    pScrn->driverVersion = 1;
-	    pScrn->driverName = "modesetting";
-	    pScrn->name = "modesetting";
-	    pScrn->Probe = Probe;
+    if (flags & PROBE_DETECT) {
+	if (numUsed > 0)
 	    foundScreen = TRUE;
-	    {
-	       /* Allocate an entity private if necessary */
-	       if (modesettingEntityIndex < 0)
-		  modesettingEntityIndex = xf86AllocateEntityPrivateIndex();
-
-	       pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
-					    modesettingEntityIndex);
-	       if (!pPriv->ptr) {
-		  pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
-		  msEnt = pPriv->ptr;
-		  msEnt->lastInstance = -1;
-	       } else {
-		  msEnt = pPriv->ptr;
-	       }
-
-	       /*
-	        * Set the entity instance for this instance of the driver.
-	        * For dual head per card, instance 0 is the "master"
-	        * instance, driving the primary head, and instance 1 is
-	        * the "slave".
-	        */
-	       msEnt->lastInstance++;
-	       xf86SetEntityInstanceForScreen(pScrn,
-					      pScrn->entityList[0],
-					      msEnt->lastInstance);
-	       pScrn->PreInit = PreInit;
-	       pScrn->ScreenInit = ScreenInit;
-	       pScrn->SwitchMode = SwitchMode;
-	       pScrn->AdjustFrame = AdjustFrame;
-	       pScrn->EnterVT = EnterVT;
-	       pScrn->LeaveVT = LeaveVT;
-	       pScrn->FreeScreen = FreeScreen;
-	       pScrn->ValidMode = ValidMode;
-	       break;
-	    }
-	 } else
-	 	ErrorF("FAILED PSCRN\n");
-      }
-   }
+    } else {
+	ErrorF("NUMUSED %d\n", numUsed);
+	for (i = 0; i < numUsed; i++) {
+	    ScrnInfoPtr pScrn = NULL;
+
+	    /* Allocate new ScrnInfoRec and claim the slot */
+	    if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
+					     PciDevices, NULL, NULL, NULL,
+					     NULL, NULL))) {
+		EntityInfoPtr pEnt;
+
+		pEnt = xf86GetEntityInfo(usedChips[i]);
+
+		pScrn->driverVersion = 1;
+		pScrn->driverName = "modesetting";
+		pScrn->name = "modesetting";
+		pScrn->Probe = Probe;
+		foundScreen = TRUE;
+		{
+		    /* Allocate an entity private if necessary */
+		    if (modesettingEntityIndex < 0)
+			modesettingEntityIndex =
+			    xf86AllocateEntityPrivateIndex();
+
+		    pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
+						 modesettingEntityIndex);
+		    if (!pPriv->ptr) {
+			pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
+			msEnt = pPriv->ptr;
+			msEnt->lastInstance = -1;
+		    } else {
+			msEnt = pPriv->ptr;
+		    }
+
+		    /*
+		     * Set the entity instance for this instance of the driver.
+		     * For dual head per card, instance 0 is the "master"
+		     * instance, driving the primary head, and instance 1 is
+		     * the "slave".
+		     */
+		    msEnt->lastInstance++;
+		    xf86SetEntityInstanceForScreen(pScrn,
+						   pScrn->entityList[0],
+						   msEnt->lastInstance);
+		    pScrn->PreInit = PreInit;
+		    pScrn->ScreenInit = ScreenInit;
+		    pScrn->SwitchMode = SwitchMode;
+		    pScrn->AdjustFrame = AdjustFrame;
+		    pScrn->EnterVT = EnterVT;
+		    pScrn->LeaveVT = LeaveVT;
+		    pScrn->FreeScreen = FreeScreen;
+		    pScrn->ValidMode = ValidMode;
+		    break;
+		}
+	    } else
+		ErrorF("FAILED PSCRN\n");
+	}
+    }
 
-   xfree(usedChips);
-   xfree(devSections);
+    xfree(usedChips);
+    xfree(devSections);
 
-   return foundScreen;
+    return foundScreen;
 }
 #endif
 
 static Bool
 GetRec(ScrnInfoPtr pScrn)
 {
-   if (pScrn->driverPrivate)
-      return TRUE;
+    if (pScrn->driverPrivate)
+	return TRUE;
 
-   pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
+    pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
 
-   return TRUE;
+    return TRUE;
 }
 
 static void
 FreeRec(ScrnInfoPtr pScrn)
 {
-   if (!pScrn)
-      return;
+    if (!pScrn)
+	return;
 
-   if (!pScrn->driverPrivate)
-      return;
+    if (!pScrn->driverPrivate)
+	return;
 
-   xfree(pScrn->driverPrivate);
+    xfree(pScrn->driverPrivate);
 
-   pScrn->driverPrivate = NULL;
+    pScrn->driverPrivate = NULL;
 }
 
 static void
 ProbeDDC(ScrnInfoPtr pScrn, int index)
 {
-   ConfiguredMonitor = NULL;
+    ConfiguredMonitor = NULL;
 }
 
 static Bool
 MapMem(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   drmBOMap(ms->fd,
-	    &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
+    drmBOMap(ms->fd,
+	     &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 UnmapMem(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   drmBOUnmap(ms->fd, &ms->bo);
+    drmBOUnmap(ms->fd, &ms->bo);
 
-   return TRUE;
+    return TRUE;
 }
 
 static void
 LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 	    LOCO * colors, VisualPtr pVisual)
 {
-   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 }
 
 static Bool
 crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
-   ScreenPtr pScreen = pScrn->pScreen;
-   PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-   Bool fbAccessDisabled;
-   CARD8 *fbstart;
-
-   if (width == pScrn->virtualX && height == pScrn->virtualY)
-      return TRUE;
-
-   ErrorF("RESIZING TO %dx%d\n",width,height);
-
-   pScrn->virtualX = width;
-   pScrn->virtualY = height;
-   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
-
-   if (ms->shadowMem) {
-      xfree(ms->shadowMem);
-      ms->shadowMem = NULL;
-   }
-
-   UnmapMem(pScrn);
-
-   /* move old buffer out of the way */
-   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-				   DRM_BO_HINT_DONT_FENCE, 0, 0);
-
-   /* unreference it */
-   drmBOUnreference(ms->fd, &ms->bo);
-
-   drmBOCreate(ms->fd,
-	       pScrn->virtualY * pScrn->displayWidth *
-	       pScrn->bitsPerPixel / 8, 0, NULL,
-	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
-
-   MapMem(pScrn);
-
-   drmModeAddFB(ms->fd,
-		pScrn->virtualX,
-		pScrn->virtualY,
-		pScrn->depth,
-		pScrn->bitsPerPixel,
-		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		ms->bo.handle, 
-		&ms->fb_id);
+    modesettingPtr ms = modesettingPTR(pScrn);
+    ScreenPtr pScreen = pScrn->pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    Bool fbAccessDisabled;
+    CARD8 *fbstart;
+
+    if (width == pScrn->virtualX && height == pScrn->virtualY)
+	return TRUE;
+
+    ErrorF("RESIZING TO %dx%d\n", width, height);
+
+    pScrn->virtualX = width;
+    pScrn->virtualY = height;
+    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+    if (ms->shadowMem) {
+	xfree(ms->shadowMem);
+	ms->shadowMem = NULL;
+    }
+
+    UnmapMem(pScrn);
+
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+		   DRM_BO_HINT_DONT_FENCE, 0, 0);
+
+    /* unreference it */
+    drmBOUnreference(ms->fd, &ms->bo);
+
+    drmBOCreate(ms->fd,
+		pScrn->virtualY * pScrn->displayWidth *
+		pScrn->bitsPerPixel / 8, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+    MapMem(pScrn);
+
+    drmModeAddFB(ms->fd,
+		 pScrn->virtualX,
+		 pScrn->virtualY,
+		 pScrn->depth,
+		 pScrn->bitsPerPixel,
+		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		 ms->bo.handle, &ms->fb_id);
 
     if (ms->shadowFB) {
 	if ((ms->shadowMem =
@@ -488,7 +494,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 			 pScrn->bitsPerPixel)) == NULL) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		       "Allocation of shadow memory failed\n");
-		return FALSE;
+	    return FALSE;
 	}
 	fbstart = ms->shadowMem;
     } else {
@@ -508,7 +514,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
     pScreen->ModifyPixmapHeader(rootPixmap,
 				pScrn->virtualX, pScrn->virtualY,
 				pScrn->depth, pScrn->bitsPerPixel,
-				pScrn->displayWidth * pScrn->bitsPerPixel / 8, 
+				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
 				fbstart);
 
     if (fbAccessDisabled) {
@@ -516,148 +522,148 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 	rootPixmap->devPrivate.ptr = NULL;
     }
 
-   pScrn->frameX0 = 0;
-   pScrn->frameY0 = 0;
-   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+    pScrn->frameX0 = 0;
+    pScrn->frameY0 = 0;
+    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
-   return TRUE;
+    return TRUE;
 }
 
 static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
-   crtc_resize
+    crtc_resize
 };
 
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
-   xf86CrtcConfigPtr xf86_config;
-   modesettingPtr ms;
-   MessageType from = X_PROBED;
-   rgb defaultWeight = { 0, 0, 0 };
-   EntityInfoPtr pEnt;
-   EntPtr msEnt = NULL;
-   int flags24;
-   char *BusID;
-   int i;
-   char *s;
-   int num_pipe;
-   int max_width, max_height;
-
-   if (pScrn->numEntities != 1)
-      return FALSE;
-
-   pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
-
-   if (flags & PROBE_DETECT) {
-      ProbeDDC(pScrn, pEnt->index);
-      return TRUE;
-   }
-
-   /* Allocate driverPrivate */
-   if (!GetRec(pScrn))
-      return FALSE;
-
-   ms = modesettingPTR(pScrn);
-   ms->SaveGeneration = -1;
-   ms->pEnt = pEnt;
-
-   pScrn->displayWidth = 640;		/* default it */
-
-   if (ms->pEnt->location.type != BUS_PCI)
-      return FALSE;
-
-   ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-
-   /* Allocate an entity private if necessary */
-   if (xf86IsEntityShared(pScrn->entityList[0])) {
-      msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
-				   modesettingEntityIndex)->ptr;
-      ms->entityPrivate = msEnt;
-   } else
-      ms->entityPrivate = NULL;
-
-   if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
-      return FALSE;
-   }
-
-   if (xf86IsEntityShared(pScrn->entityList[0])) {
-      if (xf86IsPrimInitDone(pScrn->entityList[0])) {
-	 /* do something */
-      } else {
-	 xf86SetPrimInitDone(pScrn->entityList[0]);
-      }
-   }
-
-   BusID = xalloc(64);
-   sprintf(BusID, "PCI:%d:%d:%d",
+    xf86CrtcConfigPtr xf86_config;
+    modesettingPtr ms;
+    MessageType from = X_PROBED;
+    rgb defaultWeight = { 0, 0, 0 };
+    EntityInfoPtr pEnt;
+    EntPtr msEnt = NULL;
+    int flags24;
+    char *BusID;
+    int i;
+    char *s;
+    int num_pipe;
+    int max_width, max_height;
+
+    if (pScrn->numEntities != 1)
+	return FALSE;
+
+    pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
+
+    if (flags & PROBE_DETECT) {
+	ProbeDDC(pScrn, pEnt->index);
+	return TRUE;
+    }
+
+    /* Allocate driverPrivate */
+    if (!GetRec(pScrn))
+	return FALSE;
+
+    ms = modesettingPTR(pScrn);
+    ms->SaveGeneration = -1;
+    ms->pEnt = pEnt;
+
+    pScrn->displayWidth = 640;	       /* default it */
+
+    if (ms->pEnt->location.type != BUS_PCI)
+	return FALSE;
+
+    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+
+    /* Allocate an entity private if necessary */
+    if (xf86IsEntityShared(pScrn->entityList[0])) {
+	msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
+				     modesettingEntityIndex)->ptr;
+	ms->entityPrivate = msEnt;
+    } else
+	ms->entityPrivate = NULL;
+
+    if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
+	return FALSE;
+    }
+
+    if (xf86IsEntityShared(pScrn->entityList[0])) {
+	if (xf86IsPrimInitDone(pScrn->entityList[0])) {
+	    /* do something */
+	} else {
+	    xf86SetPrimInitDone(pScrn->entityList[0]);
+	}
+    }
+
+    BusID = xalloc(64);
+    sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
-	   ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	   ms->PciInfo->dev, ms->PciInfo->func
+	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	    ms->PciInfo->dev, ms->PciInfo->func
 #else
-	   ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	   ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	   ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
 #endif
-	 );
-
-   ms->fd = drmOpen(NULL, BusID);
-
-   if (ms->fd < 0)
-      return FALSE;
-
-   pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
-   pScrn->monitor = pScrn->confScreen->monitor;
-   pScrn->progClock = TRUE;
-   pScrn->rgbBits = 8;
-
-   flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
-
-   if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
-      return FALSE;
-
-   switch (pScrn->depth) {
-   case 8:
-   case 15:
-   case 16:
-   case 24:
-      break;
-   default:
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		 "Given depth (%d) is not supported by the driver\n",
-		 pScrn->depth);
-      return FALSE;
-   }
-   xf86PrintDepthBpp(pScrn);
-
-   if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
-      return FALSE;
-   if (!xf86SetDefaultVisual(pScrn, -1))
-      return FALSE;
-
-   /* Process the options */
-   xf86CollectOptions(pScrn, NULL);
-   if (!(ms->Options = xalloc(sizeof(Options))))
-      return FALSE;
-   memcpy(ms->Options, Options, sizeof(Options));
-   xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
-
-   /* Allocate an xf86CrtcConfig */
-   xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
-   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-   max_width = 8192;
-   max_height = 8192;
-   xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
-
-   if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
-      ms->noAccel = TRUE;
-   }
-
-   if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
-      ms->SWCursor = TRUE;
-   }
-
-   if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
+	);
+
+    ms->fd = drmOpen(NULL, BusID);
+
+    if (ms->fd < 0)
+	return FALSE;
+
+    pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
+    pScrn->monitor = pScrn->confScreen->monitor;
+    pScrn->progClock = TRUE;
+    pScrn->rgbBits = 8;
+
+    flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
+
+    if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
+	return FALSE;
+
+    switch (pScrn->depth) {
+    case 8:
+    case 15:
+    case 16:
+    case 24:
+	break;
+    default:
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		   "Given depth (%d) is not supported by the driver\n",
+		   pScrn->depth);
+	return FALSE;
+    }
+    xf86PrintDepthBpp(pScrn);
+
+    if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
+	return FALSE;
+    if (!xf86SetDefaultVisual(pScrn, -1))
+	return FALSE;
+
+    /* Process the options */
+    xf86CollectOptions(pScrn, NULL);
+    if (!(ms->Options = xalloc(sizeof(Options))))
+	return FALSE;
+    memcpy(ms->Options, Options, sizeof(Options));
+    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
+
+    /* Allocate an xf86CrtcConfig */
+    xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
+    xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+    max_width = 8192;
+    max_height = 8192;
+    xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
+
+    if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
+	ms->noAccel = TRUE;
+    }
+
+    if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
+	ms->SWCursor = TRUE;
+    }
+
+    if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
 	if (!xf86LoadSubModule(pScrn, "shadow"))
 	    return FALSE;
 
@@ -666,144 +672,144 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	ms->shadowFB = TRUE;
     }
 
-   SaveHWState(pScrn);
+    SaveHWState(pScrn);
 
-   crtc_init(pScrn);
-   output_init(pScrn);
+    crtc_init(pScrn);
+    output_init(pScrn);
 
-   if (!xf86InitialConfiguration(pScrn, TRUE)) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
-      RestoreHWState(pScrn);
-      return FALSE;
-   }
+    if (!xf86InitialConfiguration(pScrn, TRUE)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
+	RestoreHWState(pScrn);
+	return FALSE;
+    }
 
-   RestoreHWState(pScrn);
+    RestoreHWState(pScrn);
 
-   /*
-    * If the driver can do gamma correction, it should call xf86SetGamma() here.
-    */
-   {
-      Gamma zeros = { 0.0, 0.0, 0.0 };
+    /*
+     * If the driver can do gamma correction, it should call xf86SetGamma() here.
+     */
+    {
+	Gamma zeros = { 0.0, 0.0, 0.0 };
 
-      if (!xf86SetGamma(pScrn, zeros)) {
-	 return FALSE;
-      }
-   }
+	if (!xf86SetGamma(pScrn, zeros)) {
+	    return FALSE;
+	}
+    }
 
-   if (pScrn->modes == NULL) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
-      return FALSE;
-   }
+    if (pScrn->modes == NULL) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
+	return FALSE;
+    }
 
-   pScrn->currentMode = pScrn->modes;
+    pScrn->currentMode = pScrn->modes;
 
-   /* Set display resolution */
-   xf86SetDpi(pScrn, 0, 0);
+    /* Set display resolution */
+    xf86SetDpi(pScrn, 0, 0);
 
-   /* Load the required sub modules */
-   if (!xf86LoadSubModule(pScrn, "fb")) {
-      return FALSE;
-   }
+    /* Load the required sub modules */
+    if (!xf86LoadSubModule(pScrn, "fb")) {
+	return FALSE;
+    }
 
-   xf86LoaderReqSymLists(fbSymbols, NULL);
+    xf86LoaderReqSymLists(fbSymbols, NULL);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 SaveHWState(ScrnInfoPtr pScrn)
 {
-   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 RestoreHWState(ScrnInfoPtr pScrn)
 {
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
 
-   return TRUE;
+    return TRUE;
 }
 
 static void *
 WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
-		CARD32 * size, void *closure)
+	     CARD32 * size, void *closure)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   modesettingPtr ms = modesettingPTR(pScrn);
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   if (!pScrn->vtSema)
-      return NULL;
+    if (!pScrn->vtSema)
+	return NULL;
 
-   *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
+    *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
 
-   return ((CARD8 *) ms->virtual + row * (*size) + offset);
+    return ((CARD8 *) ms->virtual + row * (*size) + offset);
 }
 
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   modesettingPtr ms = modesettingPTR(pScrn);
-   Bool ret;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    Bool ret;
 
-   pScreen->CreateScreenResources = ms->createScreenResources;
-   ret = pScreen->CreateScreenResources(pScreen);
-   pScreen->CreateScreenResources = CreateScreenResources;
+    pScreen->CreateScreenResources = ms->createScreenResources;
+    ret = pScreen->CreateScreenResources(pScreen);
+    pScreen->CreateScreenResources = CreateScreenResources;
 
-   shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
+    shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
 	      ms->update, WindowLinear, 0, 0);
 
-   return ret;
+    return ret;
 }
 
 static Bool
 ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   modesettingPtr ms = modesettingPTR(pScrn);
-   VisualPtr visual;
-   unsigned long sys_mem;
-   int c;
-   MessageType from;
-   CARD8 *fbstart;
-
-   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
-
-   miClearVisualTypes();
-
-   if (!miSetVisualTypes(pScrn->depth,
-			 miGetDefaultVisualMask(pScrn->depth),
-			 pScrn->rgbBits, pScrn->defaultVisual))
-      return FALSE;
-
-   if (!miSetPixmapDepths())
-      return FALSE;
-
-   if (!MapMem(pScrn))
-      return FALSE;
-
-   pScrn->memPhysBase = 0;
-   pScrn->fbOffset = 0;
-
-   drmBOCreate(ms->fd,
-	       pScrn->virtualY * pScrn->displayWidth *
-	       pScrn->bitsPerPixel / 8, 0, NULL,
-	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
-
-   MapMem(pScrn);
-
-   drmModeAddFB(ms->fd,
-		pScrn->virtualX,
-		pScrn->virtualY,
-		pScrn->depth,
-		pScrn->bitsPerPixel,
-		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		ms->bo.handle, 
-		&ms->fb_id);
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    VisualPtr visual;
+    unsigned long sys_mem;
+    int c;
+    MessageType from;
+    CARD8 *fbstart;
+
+    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+    miClearVisualTypes();
+
+    if (!miSetVisualTypes(pScrn->depth,
+			  miGetDefaultVisualMask(pScrn->depth),
+			  pScrn->rgbBits, pScrn->defaultVisual))
+	return FALSE;
+
+    if (!miSetPixmapDepths())
+	return FALSE;
+
+    if (!MapMem(pScrn))
+	return FALSE;
+
+    pScrn->memPhysBase = 0;
+    pScrn->fbOffset = 0;
+
+    drmBOCreate(ms->fd,
+		pScrn->virtualY * pScrn->displayWidth *
+		pScrn->bitsPerPixel / 8, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+    MapMem(pScrn);
+
+    drmModeAddFB(ms->fd,
+		 pScrn->virtualX,
+		 pScrn->virtualY,
+		 pScrn->depth,
+		 pScrn->bitsPerPixel,
+		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		 ms->bo.handle, &ms->fb_id);
 
     if (ms->shadowFB) {
 	if ((ms->shadowMem =
@@ -811,140 +817,141 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 			 pScrn->bitsPerPixel)) == NULL) {
 	    xf86DrvMsg(scrnIndex, X_ERROR,
 		       "Allocation of shadow memory failed\n");
-		return FALSE;
+	    return FALSE;
 	}
 	fbstart = ms->shadowMem;
     } else {
 	fbstart = ms->virtual;
     }
 
-   if (!fbScreenInit(pScreen, fbstart,
-		     pScrn->virtualX, pScrn->virtualY,
-		     pScrn->xDpi, pScrn->yDpi,
-		     pScrn->displayWidth, pScrn->bitsPerPixel))
-      return FALSE;
-
-   if (pScrn->bitsPerPixel > 8) {
-      /* Fixup RGB ordering */
-      visual = pScreen->visuals + pScreen->numVisuals;
-      while (--visual >= pScreen->visuals) {
-	 if ((visual->class | DynamicClass) == DirectColor) {
-	    visual->offsetRed = pScrn->offset.red;
-	    visual->offsetGreen = pScrn->offset.green;
-	    visual->offsetBlue = pScrn->offset.blue;
-	    visual->redMask = pScrn->mask.red;
-	    visual->greenMask = pScrn->mask.green;
-	    visual->blueMask = pScrn->mask.blue;
-	 }
-      }
-   }
-
-   fbPictureInit(pScreen, NULL, 0);
+    if (!fbScreenInit(pScreen, fbstart,
+		      pScrn->virtualX, pScrn->virtualY,
+		      pScrn->xDpi, pScrn->yDpi,
+		      pScrn->displayWidth, pScrn->bitsPerPixel))
+	return FALSE;
+
+    if (pScrn->bitsPerPixel > 8) {
+	/* Fixup RGB ordering */
+	visual = pScreen->visuals + pScreen->numVisuals;
+	while (--visual >= pScreen->visuals) {
+	    if ((visual->class | DynamicClass) == DirectColor) {
+		visual->offsetRed = pScrn->offset.red;
+		visual->offsetGreen = pScrn->offset.green;
+		visual->offsetBlue = pScrn->offset.blue;
+		visual->redMask = pScrn->mask.red;
+		visual->greenMask = pScrn->mask.green;
+		visual->blueMask = pScrn->mask.blue;
+	    }
+	}
+    }
+
+    fbPictureInit(pScreen, NULL, 0);
     if (ms->shadowFB) {
 	ms->update = shadowUpdatePackedWeak();
 	if (!shadowSetup(pScreen)) {
 	    xf86DrvMsg(scrnIndex, X_ERROR,
 		       "Shadow framebuffer initialization failed.\n");
-	 	return FALSE;
+	    return FALSE;
 	}
 
 	ms->createScreenResources = pScreen->CreateScreenResources;
 	pScreen->CreateScreenResources = CreateScreenResources;
     }
 
-   xf86SetBlackWhitePixels(pScreen);
+    xf86SetBlackWhitePixels(pScreen);
 
 #if 0
-   glucoseScreenInit(pScreen, 0);
+    glucoseScreenInit(pScreen, 0);
 #endif
 #if 0
-   ms->pExa = ExaInit(pScreen);
+    ms->pExa = ExaInit(pScreen);
 #endif
 
-   miInitializeBackingStore(pScreen);
-   xf86SetBackingStore(pScreen);
-   xf86SetSilkenMouse(pScreen);
-   miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
+    miInitializeBackingStore(pScreen);
+    xf86SetBackingStore(pScreen);
+    xf86SetSilkenMouse(pScreen);
+    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
-   /* Must force it before EnterVT, so we are in control of VT and
-    * later memory should be bound when allocating, e.g rotate_mem */
-   pScrn->vtSema = TRUE;
+    /* Must force it before EnterVT, so we are in control of VT and
+     * later memory should be bound when allocating, e.g rotate_mem */
+    pScrn->vtSema = TRUE;
 
-   pScreen->SaveScreen = xf86SaveScreen;
-   ms->CloseScreen = pScreen->CloseScreen;
-   pScreen->CloseScreen = CloseScreen;
+    pScreen->SaveScreen = xf86SaveScreen;
+    ms->CloseScreen = pScreen->CloseScreen;
+    pScreen->CloseScreen = CloseScreen;
 
-   if (!xf86CrtcScreenInit(pScreen))
-      return FALSE;
+    if (!xf86CrtcScreenInit(pScreen))
+	return FALSE;
 
-   if (!miCreateDefColormap(pScreen))
-      return FALSE;
+    if (!miCreateDefColormap(pScreen))
+	return FALSE;
 
 #if 0
-   if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
-			    CMAP_RELOAD_ON_MODE_SWITCH |
-			    CMAP_PALETTED_TRUECOLOR)) {
-      return FALSE;
-   }
+    if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
+			     CMAP_RELOAD_ON_MODE_SWITCH |
+			     CMAP_PALETTED_TRUECOLOR)) {
+	return FALSE;
+    }
 #endif
 
-   xf86DPMSInit(pScreen, xf86DPMSSet, 0);
+    xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
 #if 0
-   glucoseInitVideo(pScreen);
+    glucoseInitVideo(pScreen);
 #endif
 
-   if (serverGeneration == 1)
-      xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
+    if (serverGeneration == 1)
+	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-   return EnterVT(scrnIndex, 0);
+    return EnterVT(scrnIndex, 0);
 }
 
 static void
 AdjustFrame(int scrnIndex, int x, int y, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-   xf86OutputPtr output = config->output[config->compat_output];
-   xf86CrtcPtr crtc = output->crtc;
-
-   if (crtc && crtc->enabled) {
-      crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, y);
-      crtc->x = output->initial_x + x;
-      crtc->y = output->initial_y + y;
-   }
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86OutputPtr output = config->output[config->compat_output];
+    xf86CrtcPtr crtc = output->crtc;
+
+    if (crtc && crtc->enabled) {
+	crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x,
+			      y);
+	crtc->x = output->initial_x + x;
+	crtc->y = output->initial_y + y;
+    }
 }
 
 static void
 FreeScreen(int scrnIndex, int flags)
 {
-   FreeRec(xf86Screens[scrnIndex]);
+    FreeRec(xf86Screens[scrnIndex]);
 }
 
 static void
 LeaveVT(int scrnIndex, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   modesettingPtr ms = modesettingPTR(pScrn);
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-   int o;
-
-   for (o = 0; o < config->num_crtc; o++) {
-      xf86CrtcPtr crtc = config->crtc[o];
-
-      if (crtc->rotatedPixmap || crtc->rotatedData) {
-	 crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
-				     crtc->rotatedData);
-	 crtc->rotatedPixmap = NULL;
-	 crtc->rotatedData = NULL;
-      }
-   }
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int o;
+
+    for (o = 0; o < config->num_crtc; o++) {
+	xf86CrtcPtr crtc = config->crtc[o];
+
+	if (crtc->rotatedPixmap || crtc->rotatedData) {
+	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
+					crtc->rotatedData);
+	    crtc->rotatedPixmap = NULL;
+	    crtc->rotatedData = NULL;
+	}
+    }
 
-   xf86_hide_cursors(pScrn);
+    xf86_hide_cursors(pScrn);
 
-   drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
 
-   RestoreHWState(pScrn);
+    RestoreHWState(pScrn);
 }
 
 /*
@@ -953,76 +960,76 @@ LeaveVT(int scrnIndex, int flags)
 static Bool
 EnterVT(int scrnIndex, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   modesettingPtr ms = modesettingPTR(pScrn);
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   /*
-    * Only save state once per server generation since that's what most
-    * drivers do.  Could change this to save state at each VT enter.
-    */
-   if (ms->SaveGeneration != serverGeneration) {
-      ms->SaveGeneration = serverGeneration;
-      SaveHWState(pScrn);
-   }
+    /*
+     * Only save state once per server generation since that's what most
+     * drivers do.  Could change this to save state at each VT enter.
+     */
+    if (ms->SaveGeneration != serverGeneration) {
+	ms->SaveGeneration = serverGeneration;
+	SaveHWState(pScrn);
+    }
 
-   drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
 
-   if (!xf86SetDesiredModes(pScrn))
-      return FALSE;
+    if (!xf86SetDesiredModes(pScrn))
+	return FALSE;
 
-   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
-   return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
+    return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
 }
 
 static Bool
 CloseScreen(int scrnIndex, ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   modesettingPtr ms = modesettingPTR(pScrn);
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   if (pScrn->vtSema == TRUE) {
-      LeaveVT(scrnIndex, 0);
-      drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-   }
+    if (pScrn->vtSema == TRUE) {
+	LeaveVT(scrnIndex, 0);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    }
 
-   UnmapMem(pScrn);
+    UnmapMem(pScrn);
 
-   if (ms->shadowFB)
-      pScreen->CreateScreenResources = ms->createScreenResources;
+    if (ms->shadowFB)
+	pScreen->CreateScreenResources = ms->createScreenResources;
 
-   if (ms->shadowMem) {
-      xfree(ms->shadowMem);
-      ms->shadowMem = NULL;
-   }
+    if (ms->shadowMem) {
+	xfree(ms->shadowMem);
+	ms->shadowMem = NULL;
+    }
 
-   if (ms->pExa)
-      ExaClose(pScrn);
+    if (ms->pExa)
+	ExaClose(pScrn);
 
-   /* move old buffer out of the way */
-   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-				   DRM_BO_HINT_DONT_FENCE, 0, 0);
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+		   DRM_BO_HINT_DONT_FENCE, 0, 0);
 
-   drmBOUnreference(ms->fd, &ms->bo);
+    drmBOUnreference(ms->fd, &ms->bo);
 
-   drmClose(ms->fd);
+    drmClose(ms->fd);
 
-   pScrn->vtSema = FALSE;
-   pScreen->CloseScreen = ms->CloseScreen;
-   return (*pScreen->CloseScreen) (scrnIndex, pScreen);
+    pScrn->vtSema = FALSE;
+    pScreen->CloseScreen = ms->CloseScreen;
+    return (*pScreen->CloseScreen) (scrnIndex, pScreen);
 }
 
 static ModeStatus
 ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
 {
-   return MODE_OK;
+    return MODE_OK;
 }
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 2a09903..c9cb764 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -36,53 +36,55 @@
 
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
 
-typedef struct {
-   int            lastInstance;
-   int            refCount;
-   ScrnInfoPtr    pScrn_1;
-   ScrnInfoPtr    pScrn_2;
+typedef struct
+{
+    int lastInstance;
+    int refCount;
+    ScrnInfoPtr pScrn_1;
+    ScrnInfoPtr pScrn_2;
 } EntRec, *EntPtr;
 
-typedef struct _modesettingRec {
-   int fd;
-   unsigned int fb_id;
-   void *virtual;
-   drmBO bo;
+typedef struct _modesettingRec
+{
+    int fd;
+    unsigned int fb_id;
+    void *virtual;
+    drmBO bo;
 
-   EntPtr entityPrivate;	
+    EntPtr entityPrivate;
 
-   void (*PointerMoved)(int, int, int);
+    void (*PointerMoved) (int, int, int);
 
-   int Chipset;
-   EntityInfoPtr pEnt;
+    int Chipset;
+    EntityInfoPtr pEnt;
 #if XSERVER_LIBPCIACCESS
-   struct pci_device *PciInfo;
+    struct pci_device *PciInfo;
 #else
-   pciVideoPtr PciInfo;
-   PCITAG PciTag;
+    pciVideoPtr PciInfo;
+    PCITAG PciTag;
 #endif
 
-   Bool noAccel;
-   Bool SWCursor;
-   CloseScreenProcPtr CloseScreen;
+    Bool noAccel;
+    Bool SWCursor;
+    CloseScreenProcPtr CloseScreen;
 
-   Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
-   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+    Bool directRenderingDisabled;      /* DRI disabled in PreInit. */
+    Bool directRenderingEnabled;       /* DRI enabled this generation. */
 
-   /* Broken-out options. */
-   OptionInfoPtr Options;
+    /* Broken-out options. */
+    OptionInfoPtr Options;
 
-   unsigned int SaveGeneration;
+    unsigned int SaveGeneration;
 
-   /* shadowfb */
-   CARD8 *shadowMem;
-   Bool shadowFB;
-   CreateScreenResourcesProcPtr createScreenResources;
-   ShadowUpdateProc update;
+    /* shadowfb */
+    CARD8 *shadowMem;
+    Bool shadowFB;
+    CreateScreenResourcesProcPtr createScreenResources;
+    ShadowUpdateProc update;
 
-   /* exa */
-   ExaDriverPtr pExa;
-   drmBO exa_bo;
+    /* exa */
+    ExaDriverPtr pExa;
+    drmBO exa_bo;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index a9be2c1..70968f0 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -102,7 +102,7 @@ ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
 
 static Bool
 ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
-		       int ydir, int alu, Pixel planeMask)
+	       int ydir, int alu, Pixel planeMask)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
 
@@ -115,15 +115,15 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 
 static void
 ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
-		int width, int height)
+	int width, int height)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
 }
 
 static Bool
 ExaPrepareComposite(int op, PicturePtr pSrcPicture,
-			    PicturePtr pMaskPicture, PicturePtr pDstPicture,
-			    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
+		    PicturePtr pMaskPicture, PicturePtr pDstPicture,
+		    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
 {
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -133,7 +133,7 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
 
 static Bool
 ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
-		     int src_pitch)
+		  int src_pitch)
 {
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -143,7 +143,7 @@ ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
 
 static void
 ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
-		     int dstX, int dstY, int width, int height)
+	     int dstX, int dstY, int width, int height)
 {
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -151,8 +151,8 @@ ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
 
 static Bool
 ExaCheckComposite(int op,
-		     PicturePtr pSrcPicture, PicturePtr pMaskPicture,
-		     PicturePtr pDstPicture)
+		  PicturePtr pSrcPicture, PicturePtr pMaskPicture,
+		  PicturePtr pDstPicture)
 {
     DrawablePtr pDraw = pSrcPicture->pDrawable;
     int w = pDraw->width;
@@ -173,17 +173,17 @@ ExaPixmapIsOffscreen(PixmapPtr p)
 void
 ExaClose(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
 
     exaDriverFini(pScrn->pScreen);
 
-   drmBOUnreference(ms->fd, &ms->exa_bo);
+    drmBOUnreference(ms->fd, &ms->exa_bo);
 }
 
 ExaDriverPtr
 ExaInit(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
     ExaDriverPtr pExa;
 
     pExa = exaDriverAlloc();
@@ -192,7 +192,9 @@ ExaInit(ScrnInfoPtr pScrn)
     }
 
     /* Create a 256KB offscreen area */
-    drmBOCreate(ms->fd, 256 * 1024, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
+    drmBOCreate(ms->fd, 256 * 1024, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
 
     memset(pExa, 0, sizeof(*pExa));
     pExa->exa_major = 2;
@@ -203,8 +205,8 @@ ExaInit(ScrnInfoPtr pScrn)
     pExa->pixmapOffsetAlign = 8;
     pExa->pixmapPitchAlign = 32 * 4;
     pExa->flags = EXA_OFFSCREEN_PIXMAPS;
-    pExa->maxX = 8191; /* FIXME */
-    pExa->maxY = 8191; /* FIXME */
+    pExa->maxX = 8191;		       /* FIXME */
+    pExa->maxY = 8191;		       /* FIXME */
     pExa->WaitMarker = ExaWaitMarker;
     pExa->MarkSync = ExaMarkSync;
     pExa->PrepareSolid = ExaPrepareSolid;
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index b25540e..4a67ccc 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -69,20 +69,20 @@ restore(xf86OutputPtr output)
 static int
 mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
 {
-   return MODE_OK;
+    return MODE_OK;
 }
 
 static Bool
 mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
 	   DisplayModePtr adjusted_mode)
 {
-   return TRUE;
+    return TRUE;
 }
 
 static void
 prepare(xf86OutputPtr output)
 {
-   dpms(output, DPMSModeOff);
+    dpms(output, DPMSModeOff);
 }
 
 static void
@@ -94,69 +94,69 @@ mode_set(xf86OutputPtr output, DisplayModePtr mode,
 static void
 commit(xf86OutputPtr output)
 {
-   dpms(output, DPMSModeOn);
+    dpms(output, DPMSModeOn);
 
-   if (output->scrn->pScreen != NULL)
-      xf86_reload_cursors(output->scrn->pScreen);
+    if (output->scrn->pScreen != NULL)
+	xf86_reload_cursors(output->scrn->pScreen);
 }
 
 static xf86OutputStatus
 detect(xf86OutputPtr output)
 {
-   drmModeOutputPtr drm_output = output->driver_private;
-
-   switch (drm_output->connection) {
-   	case DRM_MODE_CONNECTED:
-	    return XF86OutputStatusConnected;
-	case DRM_MODE_DISCONNECTED:
-	    return XF86OutputStatusDisconnected;
-	default:
-	    return XF86OutputStatusUnknown;
-   }
+    drmModeOutputPtr drm_output = output->driver_private;
+
+    switch (drm_output->connection) {
+    case DRM_MODE_CONNECTED:
+	return XF86OutputStatusConnected;
+    case DRM_MODE_DISCONNECTED:
+	return XF86OutputStatusDisconnected;
+    default:
+	return XF86OutputStatusUnknown;
+    }
 }
 
 static DisplayModePtr
 get_modes(xf86OutputPtr output)
 {
-   drmModeOutputPtr drm_output = output->driver_private;
-   struct drm_mode_modeinfo *drm_mode = NULL;
-   DisplayModePtr modes = NULL, mode = NULL;
-   int i;
-
-   for (i = 0; i < drm_output->count_modes; i++) {
-      drm_mode = &drm_output->modes[i];
-      if (drm_mode) {
-	 mode = xcalloc(1, sizeof(DisplayModeRec));
-	 if (!mode)
-	    continue;
-	 mode->type = 0;
-	 mode->Clock = drm_mode->clock;
-	 mode->HDisplay = drm_mode->hdisplay;
-	 mode->HSyncStart = drm_mode->hsync_start;
-	 mode->HSyncEnd = drm_mode->hsync_end;
-	 mode->HTotal = drm_mode->htotal;
-	 mode->VDisplay = drm_mode->vdisplay;
-	 mode->VSyncStart = drm_mode->vsync_start;
-	 mode->VSyncEnd = drm_mode->vsync_end;
-	 mode->VTotal = drm_mode->vtotal;
-	 mode->Flags = drm_mode->flags;
-	 mode->HSkew = drm_mode->hskew;
-	 mode->VScan = drm_mode->vscan;
-	 mode->VRefresh = xf86ModeVRefresh(mode);
-	 mode->Private = (void *)drm_mode;
-	 xf86SetModeDefaultName(mode);
-	 modes = xf86ModesAdd(modes, mode);
-	 xf86PrintModeline(0, mode);
-      }
-   }
-
-   return modes;
+    drmModeOutputPtr drm_output = output->driver_private;
+    struct drm_mode_modeinfo *drm_mode = NULL;
+    DisplayModePtr modes = NULL, mode = NULL;
+    int i;
+
+    for (i = 0; i < drm_output->count_modes; i++) {
+	drm_mode = &drm_output->modes[i];
+	if (drm_mode) {
+	    mode = xcalloc(1, sizeof(DisplayModeRec));
+	    if (!mode)
+		continue;
+	    mode->type = 0;
+	    mode->Clock = drm_mode->clock;
+	    mode->HDisplay = drm_mode->hdisplay;
+	    mode->HSyncStart = drm_mode->hsync_start;
+	    mode->HSyncEnd = drm_mode->hsync_end;
+	    mode->HTotal = drm_mode->htotal;
+	    mode->VDisplay = drm_mode->vdisplay;
+	    mode->VSyncStart = drm_mode->vsync_start;
+	    mode->VSyncEnd = drm_mode->vsync_end;
+	    mode->VTotal = drm_mode->vtotal;
+	    mode->Flags = drm_mode->flags;
+	    mode->HSkew = drm_mode->hskew;
+	    mode->VScan = drm_mode->vscan;
+	    mode->VRefresh = xf86ModeVRefresh(mode);
+	    mode->Private = (void *)drm_mode;
+	    xf86SetModeDefaultName(mode);
+	    modes = xf86ModesAdd(modes, mode);
+	    xf86PrintModeline(0, mode);
+	}
+    }
+
+    return modes;
 }
 
 static void
 destroy(xf86OutputPtr output)
 {
-   drmModeFreeOutput(output->driver_private);
+    drmModeFreeOutput(output->driver_private);
 }
 
 static void
@@ -170,7 +170,7 @@ create_resources(xf86OutputPtr output)
 static Bool
 set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
 {
-   return TRUE;
+    return TRUE;
 }
 #endif /* RANDR_12_INTERFACE */
 
@@ -178,7 +178,7 @@ set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
 static Bool
 get_property(xf86OutputPtr output, Atom property)
 {
-   return TRUE;
+    return TRUE;
 }
 #endif /* RANDR_13_INTERFACE */
 
@@ -186,100 +186,102 @@ get_property(xf86OutputPtr output, Atom property)
 static xf86CrtcPtr
 get_crtc(xf86OutputPtr output)
 {
-   return NULL;
+    return NULL;
 }
 #endif
 
 static const xf86OutputFuncsRec output_funcs = {
-   .create_resources = create_resources,
-   .dpms = dpms,
-   .save = save,
-   .restore = restore,
-   .mode_valid = mode_valid,
-   .mode_fixup = mode_fixup,
-   .prepare = prepare,
-   .mode_set = mode_set,
-   .commit = commit,
-   .detect = detect,
-   .get_modes = get_modes,
+    .create_resources = create_resources,
+    .dpms = dpms,
+    .save = save,
+    .restore = restore,
+    .mode_valid = mode_valid,
+    .mode_fixup = mode_fixup,
+    .prepare = prepare,
+    .mode_set = mode_set,
+    .commit = commit,
+    .detect = detect,
+    .get_modes = get_modes,
 #ifdef RANDR_12_INTERFACE
-   .set_property = set_property,
+    .set_property = set_property,
 #endif
 #ifdef RANDR_13_INTERFACE
-   .get_property = get_property,
+    .get_property = get_property,
 #endif
-   .destroy = destroy,
+    .destroy = destroy,
 #ifdef RANDR_GET_CRTC_INTERFACE
-   .get_crtc = get_crtc,
+    .get_crtc = get_crtc,
 #endif
 };
 
 void
 output_init(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
-   xf86OutputPtr output;
-   drmModeResPtr res;
-   drmModeOutputPtr drm_output = NULL;
-   drmModeCrtcPtr crtc;
-   char *name;
-   int o, v, p;
-
-   res = drmModeGetResources(ms->fd);
-   if (res == 0) {
-      DRV_ERROR("Failed drmModeGetResources\n");
-      return;
-   }
-
-   for (o = 0; o < res->count_outputs; o++) {
-      drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
-      if (!drm_output)
-         goto out;
-
-      for (p = 0; p < drm_output->count_props; p++) {
-	 drmModePropertyPtr prop;
-
-	 prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
-
-	 name = NULL;
-	 if (prop) {
-	 ErrorF("VALUES %d\n",prop->count_values);
-
-	    for (v=0;v<prop->count_values;v++) 
-	    	ErrorF("%s %lld\n", prop->name, prop->values[v]);
-
-	    for (v=0;v<prop->count_enums;v++) {
-	    	ErrorF("%s %s\n", prop->name, prop->enums[v].name);
-		if (drm_output->prop_values[p] == prop->enums[v].value) {
-		if (!strncmp("Connector Type", prop->name, 14)) {
-			ErrorF("WE'VE GOT %s\n",prop->enums[v].name);
-			name = xalloc(strlen(prop->enums[v].name));
-			strncpy(name, prop->enums[v].name, strlen(name));
-		}
+    modesettingPtr ms = modesettingPTR(pScrn);
+    xf86OutputPtr output;
+    drmModeResPtr res;
+    drmModeOutputPtr drm_output = NULL;
+    drmModeCrtcPtr crtc;
+    char *name;
+    int o, v, p;
+
+    res = drmModeGetResources(ms->fd);
+    if (res == 0) {
+	DRV_ERROR("Failed drmModeGetResources\n");
+	return;
+    }
+
+    for (o = 0; o < res->count_outputs; o++) {
+	drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
+	if (!drm_output)
+	    goto out;
+
+	for (p = 0; p < drm_output->count_props; p++) {
+	    drmModePropertyPtr prop;
+
+	    prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
+
+	    name = NULL;
+	    if (prop) {
+		ErrorF("VALUES %d\n", prop->count_values);
+
+		for (v = 0; v < prop->count_values; v++)
+		    ErrorF("%s %lld\n", prop->name, prop->values[v]);
+
+		for (v = 0; v < prop->count_enums; v++) {
+		    ErrorF("%s %s\n", prop->name, prop->enums[v].name);
+		    if (drm_output->prop_values[p] == prop->enums[v].value) {
+			if (!strncmp("Connector Type", prop->name, 14)) {
+			    ErrorF("WE'VE GOT %s\n", prop->enums[v].name);
+			    name = xalloc(strlen(prop->enums[v].name));
+			    strncpy(name, prop->enums[v].name, strlen(name));
+			}
+		    }
+		    if (name)
+			break;
 		}
-		if (name) break;
+		if (name)
+		    break;
 	    }
-	    if (name) break;
-	 }
-      }
+	}
 
-      if (!name)
-         continue;
+	if (!name)
+	    continue;
 
-      output = xf86OutputCreate(pScrn, &output_funcs, name);
-      if (!output)
-	 continue;
+	output = xf86OutputCreate(pScrn, &output_funcs, name);
+	if (!output)
+	    continue;
 
 	free(name);
 
-      output->possible_crtcs = drm_output->crtcs;
-      output->possible_clones = drm_output->clones;
-      output->driver_private = drm_output;
-      output->subpixel_order = SubPixelHorizontalRGB;
-      output->interlaceAllowed = FALSE;
-      output->doubleScanAllowed = FALSE;
-   }
+	output->possible_crtcs = drm_output->crtcs;
+	output->possible_clones = drm_output->clones;
+	output->driver_private = drm_output;
+	output->subpixel_order = SubPixelHorizontalRGB;
+	output->interlaceAllowed = FALSE;
+	output->doubleScanAllowed = FALSE;
+    }
 
-out:
-   drmModeFreeResources(res);
+  out:
+    drmModeFreeResources(res);
 }
commit 106bea5ad1bdd5795d6ed625fc6351a161bffa6e
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Wed May 28 13:33:07 2008 +0100

    Initial commit of new modesetting driver

diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING
new file mode 100644
index 0000000..7f33cbf
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/COPYING
@@ -0,0 +1,12 @@
+This is a stub file.  This package has not yet had its complete licensing
+information compiled.  Please see the individual source files for details on
+your rights to use and modify this software.
+
+Please submit updated COPYING files to the Xorg bugzilla:
+
+https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
+
+All licensing questions regarding this software should be directed at the
+Xorg mailing list:
+
+http://lists.freedesktop.org/mailman/listinfo/xorg
diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
new file mode 100644
index 0000000..17d884f
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -0,0 +1,42 @@
+#  Copyright 2005 Adam Jackson.
+#
+#  Permission is hereby granted, free of charge, to any person obtaining a
+#  copy of this software and associated documentation files (the "Software"),
+#  to deal in the Software without restriction, including without limitation
+#  on the rights to use, copy, modify, merge, publish, distribute, sub
+#  license, and/or sell copies of the Software, and to permit persons to whom
+#  the Software is furnished to do so, subject to the following conditions:
+#
+#  The above copyright notice and this permission notice (including the next
+#  paragraph) shall be included in all copies or substantial portions of the
+#  Software.
+#
+#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+#  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+#  ADAM JACKSON 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.
+SUBDIRS = 
+
+# this is obnoxious:
+# -module lets us name the module exactly how we want
+# -avoid-version prevents gratuitous .0.0.0 version numbers on the end
+# _ladir passes a dummy rpath to libtool so the thing will actually link
+# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
+
+AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \
+	@XMODES_CFLAGS@
+
+modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
+modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm
+modesetting_drv_ladir = @moduledir@/drivers
+
+modesetting_drv_la_SOURCES = \
+	 driver.c \
+	 driver.h \
+	 output.c \
+	 crtc.c \
+	 exa.c
+
+EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
new file mode 100644
index 0000000..f168126
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <math.h>
+#include <stdint.h>
+
+#include <xf86.h>
+#include <xf86i2c.h>
+#include <xf86Crtc.h>
+#include "driver.h"
+#include "xf86Modes.h"
+
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+
+static void
+crtc_dpms(xf86CrtcPtr crtc, int mode)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+
+   switch (mode) {
+   case DPMSModeOn:
+   case DPMSModeStandby:
+   case DPMSModeSuspend:
+      break;
+   case DPMSModeOff:
+      break;
+   }
+}
+
+static Bool
+crtc_lock(xf86CrtcPtr crtc)
+{
+   return FALSE;
+}
+
+static void
+crtc_unlock(xf86CrtcPtr crtc)
+{
+}
+
+static void
+crtc_prepare(xf86CrtcPtr crtc)
+{
+}
+
+static void
+crtc_commit(xf86CrtcPtr crtc)
+{
+}
+
+static Bool
+crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
+		DisplayModePtr adjusted_mode)
+{
+   return TRUE;
+}
+
+static void
+crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
+	      DisplayModePtr adjusted_mode, int x, int y)
+{
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+   modesettingPtr ms = modesettingPTR(crtc->scrn);
+   xf86OutputPtr output = config->output[config->compat_output];
+   drmModeOutputPtr drm_output = output->driver_private;
+   drmModeCrtcPtr drm_crtc = crtc->driver_private;
+   struct drm_mode_modeinfo drm_mode;
+
+   drm_mode.clock = mode->Clock;
+   drm_mode.hdisplay = mode->HDisplay;
+   drm_mode.hsync_start = mode->HSyncStart;
+   drm_mode.hsync_end = mode->HSyncEnd;
+   drm_mode.htotal = mode->HTotal;
+   drm_mode.vdisplay = mode->VDisplay;
+   drm_mode.vsync_start = mode->VSyncStart;
+   drm_mode.vsync_end = mode->VSyncEnd;
+   drm_mode.vtotal = mode->VTotal;
+   drm_mode.flags = mode->Flags;
+   drm_mode.hskew = mode->HSkew;
+   drm_mode.vscan = mode->VScan;
+   drm_mode.vrefresh = mode->VRefresh;
+   strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
+
+   drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
+		     &drm_output->output_id, 1, &drm_mode);
+}
+
+void
+crtc_load_lut(xf86CrtcPtr crtc)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+}
+
+static void
+crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
+	       int size)
+{
+}
+
+static void *
+crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+
+   return NULL;
+}
+
+static PixmapPtr
+crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+
+   return NULL;
+}
+
+static void
+crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+}
+
+static void
+crtc_destroy(xf86CrtcPtr crtc)
+{
+   drmModeFreeCrtc(crtc->driver_private);
+}
+
+static const xf86CrtcFuncsRec crtc_funcs = {
+   .dpms = crtc_dpms,
+   .save = NULL,			/* XXX */
+   .restore = NULL,			/* XXX */
+   .lock = crtc_lock,
+   .unlock = crtc_unlock,
+   .mode_fixup = crtc_mode_fixup,
+   .prepare = crtc_prepare,
+   .mode_set = crtc_mode_set,
+   .commit = crtc_commit,
+   .gamma_set = crtc_gamma_set,
+   .shadow_create = crtc_shadow_create,
+   .shadow_allocate = crtc_shadow_allocate,
+   .shadow_destroy = crtc_shadow_destroy,
+//    .set_cursor_colors = crtc_set_cursor_colors,
+//    .set_cursor_position = crtc_set_cursor_position,
+//    .show_cursor = crtc_show_cursor,
+//    .hide_cursor = crtc_hide_cursor,
+//    .load_cursor_image = crtc_load_cursor_image, 
+//    .load_cursor_argb = crtc_load_cursor_argb,
+   .destroy = crtc_destroy,		/* XXX */
+};
+
+void
+crtc_init(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+   xf86CrtcPtr crtc;
+   drmModeResPtr res;
+   drmModeCrtcPtr drm_crtc = NULL;
+   int c, k, p;
+
+   res = drmModeGetResources(ms->fd);
+   if (res == 0) {
+      ErrorF("Failed drmModeGetResources %d\n",errno);
+      return;
+   }
+
+   for (c = 0; c < res->count_crtcs; c++) {
+      drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
+      if (!drm_crtc)
+	 continue;
+
+      crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
+      if (crtc == NULL)
+	 goto out;
+
+      crtc->driver_private = drm_crtc;
+   }
+
+out:
+   drmModeFreeResources(res);
+}
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
new file mode 100644
index 0000000..ba6bfdf
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -0,0 +1,1028 @@
+/*
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "compiler.h"
+#include "xf86RAC.h"
+#include "xf86PciInfo.h"
+#include "xf86Pci.h"
+#include "xf86Resources.h"
+#include "mipointer.h"
+#include "micmap.h"
+#include "shadowfb.h"
+#include <X11/extensions/randr.h>
+#include "fb.h"
+#include "edid.h"
+#include "xf86i2c.h"
+#include "xf86Crtc.h"
+#include "miscstruct.h"
+#include "dixstruct.h"
+#include "xf86xv.h"
+#include <X11/extensions/Xv.h>
+#include "shadow.h"
+#include <xorg-server.h>
+#if XSERVER_LIBPCIACCESS
+#include <pciaccess.h>
+#endif
+
+#include "driver.h"
+
+static void AdjustFrame(int scrnIndex, int x, int y, int flags);
+static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
+static Bool EnterVT(int scrnIndex, int flags);
+static Bool SaveHWState(ScrnInfoPtr pScrn);
+static Bool RestoreHWState(ScrnInfoPtr pScrn);
+static void Identify(int flags);
+static const OptionInfoRec *AvailableOptions(int chipid, int busid);
+static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags);
+static void FreeScreen(int scrnIndex, int flags);
+static void LeaveVT(int scrnIndex, int flags);
+static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
+static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv);
+static Bool PreInit(ScrnInfoPtr pScrn, int flags);
+#if XSERVER_LIBPCIACCESS
+static Bool
+pci_probe(DriverPtr driver,
+	  int entity_num, struct pci_device *device, intptr_t match_data);
+#else
+static Bool Probe(DriverPtr drv, int flags);
+#endif
+
+#if XSERVER_LIBPCIACCESS
+static const struct pci_id_match device_match[] = {
+   {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
+   {0, 0, 0},
+};
+#endif
+
+_X_EXPORT DriverRec modesetting = {
+   1,
+   "modesetting",
+   Identify,
+#if XSERVER_LIBPCIACCESS
+   NULL,
+#else
+   Probe,
+#endif
+   AvailableOptions,
+   NULL,
+   0,
+   NULL,
+#if XSERVER_LIBPCIACCESS
+   device_match,
+   pci_probe
+#endif
+};
+
+static SymTabRec Chipsets[] = {
+   {0x2592, "Intel Graphics Device"},
+   {-1, NULL}
+};
+
+static PciChipsets PciDevices[] = {
+   {0x2592, 0x2592, RES_SHARED_VGA},
+   {-1, -1, RES_UNDEFINED}
+};
+
+typedef enum
+{
+   OPTION_NOACCEL,
+   OPTION_SW_CURSOR,
+   OPTION_SHADOWFB,
+} modesettingOpts;
+
+static const OptionInfoRec Options[] = {
+   {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
+   {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
+   {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
+   {-1, NULL, OPTV_NONE, {0}, FALSE}
+};
+
+static const char *fbSymbols[] = {
+   "fbPictureInit",
+   "fbScreenInit",
+   NULL
+};
+
+static const char *ddcSymbols[] = {
+   "xf86PrintEDID",
+   "xf86SetDDCproperties",
+   NULL
+};
+
+static const char *shadowSymbols[] = {
+    "shadowInit",
+    "shadowUpdatePackedWeak",
+    NULL
+};
+
+static const char *i2cSymbols[] = {
+   "xf86CreateI2CBusRec",
+   "xf86I2CBusInit",
+   NULL
+};
+
+int modesettingEntityIndex = -1;
+
+static MODULESETUPPROTO(Setup);
+
+static XF86ModuleVersionInfo VersRec = {
+   "modesetting",
+   MODULEVENDORSTRING,
+   MODINFOSTRING1,
+   MODINFOSTRING2,
+   XORG_VERSION_CURRENT,
+   PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
+   ABI_CLASS_VIDEODRV,
+   ABI_VIDEODRV_VERSION,
+   MOD_CLASS_VIDEODRV,
+   {0, 0, 0, 0}
+};
+
+_X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
+
+static pointer
+Setup(pointer module, pointer opts, int *errmaj, int *errmin)
+{
+   static Bool setupDone = 0;
+
+   /* This module should be loaded only once, but check to be sure.
+    */
+   if (!setupDone) {
+      setupDone = 1;
+      xf86AddDriver(&modesetting, module, HaveDriverFuncs);
+
+      /*
+       * Tell the loader about symbols from other modules that this module
+       * might refer to.
+       */
+      LoaderRefSymLists(fbSymbols,
+			shadowSymbols, ddcSymbols, NULL);
+
+      /*
+       * The return value must be non-NULL on success even though there
+       * is no TearDownProc.
+       */
+      return (pointer) 1;
+   } else {
+      if (errmaj)
+	 *errmaj = LDR_ONCEONLY;
+      return NULL;
+   }
+}
+
+static void
+Identify(int flags)
+{
+   xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
+		     Chipsets);
+}
+
+static const OptionInfoRec *
+AvailableOptions(int chipid, int busid)
+{
+   return Options;
+}
+
+#if XSERVER_LIBPCIACCESS
+static Bool
+pci_probe(DriverPtr driver,
+	  int entity_num, struct pci_device *device, intptr_t match_data)
+{
+   ScrnInfoPtr scrn = NULL;
+   EntityInfoPtr entity;
+   DevUnion *private;
+
+   scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
+			      NULL, NULL, NULL, NULL, NULL);
+   if (scrn != NULL) {
+      scrn->driverVersion = 1;
+      scrn->driverName = "modesetting";
+      scrn->name = "modesetting";
+      scrn->Probe = NULL;
+
+      entity = xf86GetEntityInfo(entity_num);
+
+      switch (device->device_id) {
+      case 0x2592:
+	 scrn->PreInit = PreInit;
+	 scrn->ScreenInit = ScreenInit;
+	 scrn->SwitchMode = SwitchMode;
+	 scrn->AdjustFrame = AdjustFrame;
+	 scrn->EnterVT = EnterVT;
+	 scrn->LeaveVT = LeaveVT;
+	 scrn->FreeScreen = FreeScreen;
+	 scrn->ValidMode = ValidMode;
+	 break;
+      }
+   }
+   return scrn != NULL;
+}
+#else
+static Bool
+Probe(DriverPtr drv, int flags)
+{
+   int i, numUsed, numDevSections, *usedChips;
+   EntPtr msEnt = NULL;
+   DevUnion *pPriv;
+   GDevPtr *devSections;
+   Bool foundScreen = FALSE;
+   pciVideoPtr *VideoInfo;
+   pciVideoPtr *ppPci;
+   int numDevs;
+
+   /*
+    * Find the config file Device sections that match this
+    * driver, and return if there are none.
+    */
+   if ((numDevSections =
+	xf86MatchDevice("modesetting", &devSections)) <= 0) {
+      return FALSE;
+   }
+
+   /*
+    * This probing is just checking the PCI data the server already
+    * collected.
+    */
+   if (!(VideoInfo = xf86GetPciVideoInfo()))
+      return FALSE;
+
+#if 0
+   numUsed = 0;
+   for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
+      for (numDevs = 0; numDevs < numDevSections; numDevs++) {
+         if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
+	 if (xf86ComparePciBusString(devSections[numDevs]->busID, (*ppPci)->bus, (*ppPci)->device, (*ppPci)->func)) {
+         /* Claim slot */
+         if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
+				    (*ppPci)->func)) {
+	    usedChips[numUsed++] = xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
+				   (*ppPci)->func, drv, (*ppPci)->chipType,
+				   NULL, TRUE);
+				   ErrorF("CLAIMED %d %d %d\n",(*ppPci)->bus,(*ppPci)->device, (*ppPci)->func);
+	 }
+	 }
+	 }
+      }
+   }
+#else
+   /* Look for Intel i8xx devices. */
+   numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
+				   Chipsets, PciDevices,
+				   devSections, numDevSections,
+				   drv, &usedChips);
+#endif
+
+   if (flags & PROBE_DETECT) {
+      if (numUsed > 0)
+	 foundScreen = TRUE;
+   } else {
+   ErrorF("NUMUSED %d\n",numUsed);
+      for (i = 0; i < numUsed; i++) {
+	 ScrnInfoPtr pScrn = NULL;
+
+	 /* Allocate new ScrnInfoRec and claim the slot */
+	 if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
+					  PciDevices, NULL, NULL, NULL,
+					  NULL, NULL))) {
+	    EntityInfoPtr pEnt;
+
+	    pEnt = xf86GetEntityInfo(usedChips[i]);
+
+	    pScrn->driverVersion = 1;
+	    pScrn->driverName = "modesetting";
+	    pScrn->name = "modesetting";
+	    pScrn->Probe = Probe;
+	    foundScreen = TRUE;
+	    {
+	       /* Allocate an entity private if necessary */
+	       if (modesettingEntityIndex < 0)
+		  modesettingEntityIndex = xf86AllocateEntityPrivateIndex();
+
+	       pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
+					    modesettingEntityIndex);
+	       if (!pPriv->ptr) {
+		  pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
+		  msEnt = pPriv->ptr;
+		  msEnt->lastInstance = -1;
+	       } else {
+		  msEnt = pPriv->ptr;
+	       }
+
+	       /*
+	        * Set the entity instance for this instance of the driver.
+	        * For dual head per card, instance 0 is the "master"
+	        * instance, driving the primary head, and instance 1 is
+	        * the "slave".
+	        */
+	       msEnt->lastInstance++;
+	       xf86SetEntityInstanceForScreen(pScrn,
+					      pScrn->entityList[0],
+					      msEnt->lastInstance);
+	       pScrn->PreInit = PreInit;
+	       pScrn->ScreenInit = ScreenInit;
+	       pScrn->SwitchMode = SwitchMode;
+	       pScrn->AdjustFrame = AdjustFrame;
+	       pScrn->EnterVT = EnterVT;
+	       pScrn->LeaveVT = LeaveVT;
+	       pScrn->FreeScreen = FreeScreen;
+	       pScrn->ValidMode = ValidMode;
+	       break;
+	    }
+	 } else
+	 	ErrorF("FAILED PSCRN\n");
+      }
+   }
+
+   xfree(usedChips);
+   xfree(devSections);
+
+   return foundScreen;
+}
+#endif
+
+static Bool
+GetRec(ScrnInfoPtr pScrn)
+{
+   if (pScrn->driverPrivate)
+      return TRUE;
+
+   pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
+
+   return TRUE;
+}
+
+static void
+FreeRec(ScrnInfoPtr pScrn)
+{
+   if (!pScrn)
+      return;
+
+   if (!pScrn->driverPrivate)
+      return;
+
+   xfree(pScrn->driverPrivate);
+
+   pScrn->driverPrivate = NULL;
+}
+
+static void
+ProbeDDC(ScrnInfoPtr pScrn, int index)
+{
+   ConfiguredMonitor = NULL;
+}
+
+static Bool
+MapMem(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   drmBOMap(ms->fd,
+	    &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
+
+   return TRUE;
+}
+
+static Bool
+UnmapMem(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   drmBOUnmap(ms->fd, &ms->bo);
+
+   return TRUE;
+}
+
+static void
+LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
+	    LOCO * colors, VisualPtr pVisual)
+{
+   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+}
+
+static Bool
+crtc_resize(ScrnInfoPtr pScrn, int width, int height)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+   ScreenPtr pScreen = pScrn->pScreen;
+   PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+   Bool fbAccessDisabled;
+   CARD8 *fbstart;
+
+   if (width == pScrn->virtualX && height == pScrn->virtualY)
+      return TRUE;
+
+   ErrorF("RESIZING TO %dx%d\n",width,height);
+
+   pScrn->virtualX = width;
+   pScrn->virtualY = height;
+   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+   if (ms->shadowMem) {
+      xfree(ms->shadowMem);
+      ms->shadowMem = NULL;
+   }
+
+   UnmapMem(pScrn);
+
+   /* move old buffer out of the way */
+   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+				   DRM_BO_HINT_DONT_FENCE, 0, 0);
+
+   /* unreference it */
+   drmBOUnreference(ms->fd, &ms->bo);
+
+   drmBOCreate(ms->fd,
+	       pScrn->virtualY * pScrn->displayWidth *
+	       pScrn->bitsPerPixel / 8, 0, NULL,
+	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+   MapMem(pScrn);
+
+   drmModeAddFB(ms->fd,
+		pScrn->virtualX,
+		pScrn->virtualY,
+		pScrn->depth,
+		pScrn->bitsPerPixel,
+		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		ms->bo.handle, 
+		&ms->fb_id);
+
+    if (ms->shadowFB) {
+	if ((ms->shadowMem =
+	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
+			 pScrn->bitsPerPixel)) == NULL) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		       "Allocation of shadow memory failed\n");
+		return FALSE;
+	}
+	fbstart = ms->shadowMem;
+    } else {
+	fbstart = ms->virtual;
+    }
+
+    /*
+     * If we are in a fb disabled state, the virtual address of the root
+     * pixmap should always be NULL, and it will be overwritten later
+     * if we try to set it to something.
+     *
+     * Therefore, set it to NULL, and modify the backup copy instead.
+     */
+
+    fbAccessDisabled = (rootPixmap->devPrivate.ptr == NULL);
+
+    pScreen->ModifyPixmapHeader(rootPixmap,
+				pScrn->virtualX, pScrn->virtualY,
+				pScrn->depth, pScrn->bitsPerPixel,
+				pScrn->displayWidth * pScrn->bitsPerPixel / 8, 
+				fbstart);
+
+    if (fbAccessDisabled) {
+	pScrn->pixmapPrivate.ptr = fbstart;
+	rootPixmap->devPrivate.ptr = NULL;
+    }
+
+   pScrn->frameX0 = 0;
+   pScrn->frameY0 = 0;
+   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+
+   return TRUE;
+}
+
+static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
+   crtc_resize
+};
+
+static Bool
+PreInit(ScrnInfoPtr pScrn, int flags)
+{
+   xf86CrtcConfigPtr xf86_config;
+   modesettingPtr ms;
+   MessageType from = X_PROBED;
+   rgb defaultWeight = { 0, 0, 0 };
+   EntityInfoPtr pEnt;
+   EntPtr msEnt = NULL;
+   int flags24;
+   char *BusID;
+   int i;
+   char *s;
+   int num_pipe;
+   int max_width, max_height;
+
+   if (pScrn->numEntities != 1)
+      return FALSE;
+
+   pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
+
+   if (flags & PROBE_DETECT) {
+      ProbeDDC(pScrn, pEnt->index);
+      return TRUE;
+   }
+
+   /* Allocate driverPrivate */
+   if (!GetRec(pScrn))
+      return FALSE;
+
+   ms = modesettingPTR(pScrn);
+   ms->SaveGeneration = -1;
+   ms->pEnt = pEnt;
+
+   pScrn->displayWidth = 640;		/* default it */
+
+   if (ms->pEnt->location.type != BUS_PCI)
+      return FALSE;
+
+   ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+
+   /* Allocate an entity private if necessary */
+   if (xf86IsEntityShared(pScrn->entityList[0])) {
+      msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
+				   modesettingEntityIndex)->ptr;
+      ms->entityPrivate = msEnt;
+   } else
+      ms->entityPrivate = NULL;
+
+   if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
+      return FALSE;
+   }
+
+   if (xf86IsEntityShared(pScrn->entityList[0])) {
+      if (xf86IsPrimInitDone(pScrn->entityList[0])) {
+	 /* do something */
+      } else {
+	 xf86SetPrimInitDone(pScrn->entityList[0]);
+      }
+   }
+
+   BusID = xalloc(64);
+   sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	   ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	   ms->PciInfo->dev, ms->PciInfo->func
+#else
+	   ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	   ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	   ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	 );
+
+   ms->fd = drmOpen(NULL, BusID);
+
+   if (ms->fd < 0)
+      return FALSE;
+
+   pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
+   pScrn->monitor = pScrn->confScreen->monitor;
+   pScrn->progClock = TRUE;
+   pScrn->rgbBits = 8;
+
+   flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
+
+   if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
+      return FALSE;
+
+   switch (pScrn->depth) {
+   case 8:
+   case 15:
+   case 16:
+   case 24:
+      break;
+   default:
+      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		 "Given depth (%d) is not supported by the driver\n",
+		 pScrn->depth);
+      return FALSE;
+   }
+   xf86PrintDepthBpp(pScrn);
+
+   if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
+      return FALSE;
+   if (!xf86SetDefaultVisual(pScrn, -1))
+      return FALSE;
+
+   /* Process the options */
+   xf86CollectOptions(pScrn, NULL);
+   if (!(ms->Options = xalloc(sizeof(Options))))
+      return FALSE;
+   memcpy(ms->Options, Options, sizeof(Options));
+   xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
+
+   /* Allocate an xf86CrtcConfig */
+   xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
+   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+   max_width = 8192;
+   max_height = 8192;
+   xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
+
+   if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
+      ms->noAccel = TRUE;
+   }
+
+   if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
+      ms->SWCursor = TRUE;
+   }
+
+   if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
+	if (!xf86LoadSubModule(pScrn, "shadow"))
+	    return FALSE;
+
+	xf86LoaderReqSymLists(shadowSymbols, NULL);
+
+	ms->shadowFB = TRUE;
+    }
+
+   SaveHWState(pScrn);
+
+   crtc_init(pScrn);
+   output_init(pScrn);
+
+   if (!xf86InitialConfiguration(pScrn, TRUE)) {
+      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
+      RestoreHWState(pScrn);
+      return FALSE;
+   }
+
+   RestoreHWState(pScrn);
+
+   /*
+    * If the driver can do gamma correction, it should call xf86SetGamma() here.
+    */
+   {
+      Gamma zeros = { 0.0, 0.0, 0.0 };
+
+      if (!xf86SetGamma(pScrn, zeros)) {
+	 return FALSE;
+      }
+   }
+
+   if (pScrn->modes == NULL) {
+      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
+      return FALSE;
+   }
+
+   pScrn->currentMode = pScrn->modes;
+
+   /* Set display resolution */
+   xf86SetDpi(pScrn, 0, 0);
+
+   /* Load the required sub modules */
+   if (!xf86LoadSubModule(pScrn, "fb")) {
+      return FALSE;
+   }
+
+   xf86LoaderReqSymLists(fbSymbols, NULL);
+
+   return TRUE;
+}
+
+static Bool
+SaveHWState(ScrnInfoPtr pScrn)
+{
+   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+   return TRUE;
+}
+
+static Bool
+RestoreHWState(ScrnInfoPtr pScrn)
+{
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+   return TRUE;
+}
+
+static void *
+WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
+		CARD32 * size, void *closure)
+{
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   if (!pScrn->vtSema)
+      return NULL;
+
+   *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
+
+   return ((CARD8 *) ms->virtual + row * (*size) + offset);
+}
+
+static Bool
+CreateScreenResources(ScreenPtr pScreen)
+{
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   modesettingPtr ms = modesettingPTR(pScrn);
+   Bool ret;
+
+   pScreen->CreateScreenResources = ms->createScreenResources;
+   ret = pScreen->CreateScreenResources(pScreen);
+   pScreen->CreateScreenResources = CreateScreenResources;
+
+   shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
+	      ms->update, WindowLinear, 0, 0);
+
+   return ret;
+}
+
+static Bool
+ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
+{
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   modesettingPtr ms = modesettingPTR(pScrn);
+   VisualPtr visual;
+   unsigned long sys_mem;
+   int c;
+   MessageType from;
+   CARD8 *fbstart;
+
+   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+   miClearVisualTypes();
+
+   if (!miSetVisualTypes(pScrn->depth,
+			 miGetDefaultVisualMask(pScrn->depth),
+			 pScrn->rgbBits, pScrn->defaultVisual))
+      return FALSE;
+
+   if (!miSetPixmapDepths())
+      return FALSE;
+
+   if (!MapMem(pScrn))
+      return FALSE;
+
+   pScrn->memPhysBase = 0;
+   pScrn->fbOffset = 0;
+
+   drmBOCreate(ms->fd,
+	       pScrn->virtualY * pScrn->displayWidth *
+	       pScrn->bitsPerPixel / 8, 0, NULL,
+	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+   MapMem(pScrn);
+
+   drmModeAddFB(ms->fd,
+		pScrn->virtualX,
+		pScrn->virtualY,
+		pScrn->depth,
+		pScrn->bitsPerPixel,
+		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		ms->bo.handle, 
+		&ms->fb_id);
+
+    if (ms->shadowFB) {
+	if ((ms->shadowMem =
+	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
+			 pScrn->bitsPerPixel)) == NULL) {
+	    xf86DrvMsg(scrnIndex, X_ERROR,
+		       "Allocation of shadow memory failed\n");
+		return FALSE;
+	}
+	fbstart = ms->shadowMem;
+    } else {
+	fbstart = ms->virtual;
+    }
+
+   if (!fbScreenInit(pScreen, fbstart,
+		     pScrn->virtualX, pScrn->virtualY,
+		     pScrn->xDpi, pScrn->yDpi,
+		     pScrn->displayWidth, pScrn->bitsPerPixel))
+      return FALSE;
+
+   if (pScrn->bitsPerPixel > 8) {
+      /* Fixup RGB ordering */
+      visual = pScreen->visuals + pScreen->numVisuals;
+      while (--visual >= pScreen->visuals) {
+	 if ((visual->class | DynamicClass) == DirectColor) {
+	    visual->offsetRed = pScrn->offset.red;
+	    visual->offsetGreen = pScrn->offset.green;
+	    visual->offsetBlue = pScrn->offset.blue;
+	    visual->redMask = pScrn->mask.red;
+	    visual->greenMask = pScrn->mask.green;
+	    visual->blueMask = pScrn->mask.blue;
+	 }
+      }
+   }
+
+   fbPictureInit(pScreen, NULL, 0);
+    if (ms->shadowFB) {
+	ms->update = shadowUpdatePackedWeak();
+	if (!shadowSetup(pScreen)) {
+	    xf86DrvMsg(scrnIndex, X_ERROR,
+		       "Shadow framebuffer initialization failed.\n");
+	 	return FALSE;
+	}
+
+	ms->createScreenResources = pScreen->CreateScreenResources;
+	pScreen->CreateScreenResources = CreateScreenResources;
+    }
+
+   xf86SetBlackWhitePixels(pScreen);
+
+#if 0
+   glucoseScreenInit(pScreen, 0);
+#endif
+#if 0
+   ms->pExa = ExaInit(pScreen);
+#endif
+
+   miInitializeBackingStore(pScreen);
+   xf86SetBackingStore(pScreen);
+   xf86SetSilkenMouse(pScreen);
+   miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
+
+   /* Must force it before EnterVT, so we are in control of VT and
+    * later memory should be bound when allocating, e.g rotate_mem */
+   pScrn->vtSema = TRUE;
+
+   pScreen->SaveScreen = xf86SaveScreen;
+   ms->CloseScreen = pScreen->CloseScreen;
+   pScreen->CloseScreen = CloseScreen;
+
+   if (!xf86CrtcScreenInit(pScreen))
+      return FALSE;
+
+   if (!miCreateDefColormap(pScreen))
+      return FALSE;
+
+#if 0
+   if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
+			    CMAP_RELOAD_ON_MODE_SWITCH |
+			    CMAP_PALETTED_TRUECOLOR)) {
+      return FALSE;
+   }
+#endif
+
+   xf86DPMSInit(pScreen, xf86DPMSSet, 0);
+
+#if 0
+   glucoseInitVideo(pScreen);
+#endif
+
+   if (serverGeneration == 1)
+      xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
+
+   return EnterVT(scrnIndex, 0);
+}
+
+static void
+AdjustFrame(int scrnIndex, int x, int y, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+   xf86OutputPtr output = config->output[config->compat_output];
+   xf86CrtcPtr crtc = output->crtc;
+
+   if (crtc && crtc->enabled) {
+      crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, y);
+      crtc->x = output->initial_x + x;
+      crtc->y = output->initial_y + y;
+   }
+}
+
+static void
+FreeScreen(int scrnIndex, int flags)
+{
+   FreeRec(xf86Screens[scrnIndex]);
+}
+
+static void
+LeaveVT(int scrnIndex, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   modesettingPtr ms = modesettingPTR(pScrn);
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+   int o;
+
+   for (o = 0; o < config->num_crtc; o++) {
+      xf86CrtcPtr crtc = config->crtc[o];
+
+      if (crtc->rotatedPixmap || crtc->rotatedData) {
+	 crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
+				     crtc->rotatedData);
+	 crtc->rotatedPixmap = NULL;
+	 crtc->rotatedData = NULL;
+      }
+   }
+
+   xf86_hide_cursors(pScrn);
+
+   drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+
+   RestoreHWState(pScrn);
+}
+
+/*
+ * This gets called when gaining control of the VT, and from ScreenInit().
+ */
+static Bool
+EnterVT(int scrnIndex, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   /*
+    * Only save state once per server generation since that's what most
+    * drivers do.  Could change this to save state at each VT enter.
+    */
+   if (ms->SaveGeneration != serverGeneration) {
+      ms->SaveGeneration = serverGeneration;
+      SaveHWState(pScrn);
+   }
+
+   drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+
+   if (!xf86SetDesiredModes(pScrn))
+      return FALSE;
+
+   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+
+   return TRUE;
+}
+
+static Bool
+SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+
+   return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
+}
+
+static Bool
+CloseScreen(int scrnIndex, ScreenPtr pScreen)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   if (pScrn->vtSema == TRUE) {
+      LeaveVT(scrnIndex, 0);
+      drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+   }
+
+   UnmapMem(pScrn);
+
+   if (ms->shadowFB)
+      pScreen->CreateScreenResources = ms->createScreenResources;
+
+   if (ms->shadowMem) {
+      xfree(ms->shadowMem);
+      ms->shadowMem = NULL;
+   }
+
+   if (ms->pExa)
+      ExaClose(pScrn);
+
+   /* move old buffer out of the way */
+   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+				   DRM_BO_HINT_DONT_FENCE, 0, 0);
+
+   drmBOUnreference(ms->fd, &ms->bo);
+
+   drmClose(ms->fd);
+
+   pScrn->vtSema = FALSE;
+   pScreen->CloseScreen = ms->CloseScreen;
+   return (*pScreen->CloseScreen) (scrnIndex, pScreen);
+}
+
+static ModeStatus
+ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+{
+   return MODE_OK;
+}
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
new file mode 100644
index 0000000..2a09903
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#include <errno.h>
+#include <drm.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include "shadow.h"
+#include "exa.h"
+
+#define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
+
+typedef struct {
+   int            lastInstance;
+   int            refCount;
+   ScrnInfoPtr    pScrn_1;
+   ScrnInfoPtr    pScrn_2;
+} EntRec, *EntPtr;
+
+typedef struct _modesettingRec {
+   int fd;
+   unsigned int fb_id;
+   void *virtual;
+   drmBO bo;
+
+   EntPtr entityPrivate;	
+
+   void (*PointerMoved)(int, int, int);
+
+   int Chipset;
+   EntityInfoPtr pEnt;
+#if XSERVER_LIBPCIACCESS
+   struct pci_device *PciInfo;
+#else
+   pciVideoPtr PciInfo;
+   PCITAG PciTag;
+#endif
+
+   Bool noAccel;
+   Bool SWCursor;
+   CloseScreenProcPtr CloseScreen;
+
+   Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
+   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+
+   /* Broken-out options. */
+   OptionInfoPtr Options;
+
+   unsigned int SaveGeneration;
+
+   /* shadowfb */
+   CARD8 *shadowMem;
+   Bool shadowFB;
+   CreateScreenResourcesProcPtr createScreenResources;
+   ShadowUpdateProc update;
+
+   /* exa */
+   ExaDriverPtr pExa;
+   drmBO exa_bo;
+} modesettingRec, *modesettingPtr;
+
+#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
new file mode 100644
index 0000000..a9be2c1
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include "driver.h"
+
+static void
+ExaWaitMarker(ScreenPtr pScreen, int marker)
+{
+}
+
+static int
+ExaMarkSync(ScreenPtr pScreen)
+{
+    /*
+     * See ExaWaitMarker.
+     */
+
+    return 1;
+}
+
+Bool
+ExaPrepareAccess(PixmapPtr pPix, int index)
+{
+    ScreenPtr pScreen = pPix->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return TRUE;
+}
+
+void
+ExaFinishAccess(PixmapPtr pPix, int index)
+{
+    ScreenPtr pScreen = pPix->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+}
+
+static void
+ExaDone(PixmapPtr pPixmap)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+}
+
+static void
+ExaDoneComposite(PixmapPtr pPixmap)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+}
+
+static Bool
+ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+
+    if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
+	return FALSE;
+
+    /* can't do depth 4 */
+    if (pPixmap->drawable.depth == 4)
+	return FALSE;
+
+    return TRUE;
+}
+
+static void
+ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+}
+
+static Bool
+ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
+		       int ydir, int alu, Pixel planeMask)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+
+    /* can't do depth 4 */
+    if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4)
+	return FALSE;
+
+    return TRUE;
+}
+
+static void
+ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
+		int width, int height)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+}
+
+static Bool
+ExaPrepareComposite(int op, PicturePtr pSrcPicture,
+			    PicturePtr pMaskPicture, PicturePtr pDstPicture,
+			    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
+{
+    ScreenPtr pScreen = pDst->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return FALSE;
+}
+
+static Bool
+ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
+		     int src_pitch)
+{
+    ScreenPtr pScreen = pDst->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return FALSE;
+}
+
+static void
+ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
+		     int dstX, int dstY, int width, int height)
+{
+    ScreenPtr pScreen = pDst->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+}
+
+static Bool
+ExaCheckComposite(int op,
+		     PicturePtr pSrcPicture, PicturePtr pMaskPicture,
+		     PicturePtr pDstPicture)
+{
+    DrawablePtr pDraw = pSrcPicture->pDrawable;
+    int w = pDraw->width;
+    int h = pDraw->height;
+
+    return TRUE;
+}
+
+static Bool
+ExaPixmapIsOffscreen(PixmapPtr p)
+{
+    ScreenPtr pScreen = p->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return FALSE;
+}
+
+void
+ExaClose(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+    exaDriverFini(pScrn->pScreen);
+
+   drmBOUnreference(ms->fd, &ms->exa_bo);
+}
+
+ExaDriverPtr
+ExaInit(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+    ExaDriverPtr pExa;
+
+    pExa = exaDriverAlloc();
+    if (!pExa) {
+	goto out_err;
+    }
+
+    /* Create a 256KB offscreen area */
+    drmBOCreate(ms->fd, 256 * 1024, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
+
+    memset(pExa, 0, sizeof(*pExa));
+    pExa->exa_major = 2;
+    pExa->exa_minor = 2;
+    pExa->memoryBase = ms->exa_bo.virtual;
+    pExa->offScreenBase = 0;
+    pExa->memorySize = ms->exa_bo.size;
+    pExa->pixmapOffsetAlign = 8;
+    pExa->pixmapPitchAlign = 32 * 4;
+    pExa->flags = EXA_OFFSCREEN_PIXMAPS;
+    pExa->maxX = 8191; /* FIXME */
+    pExa->maxY = 8191; /* FIXME */
+    pExa->WaitMarker = ExaWaitMarker;
+    pExa->MarkSync = ExaMarkSync;
+    pExa->PrepareSolid = ExaPrepareSolid;
+    pExa->Solid = ExaSolid;
+    pExa->DoneSolid = ExaDone;
+    pExa->PrepareCopy = ExaPrepareCopy;
+    pExa->Copy = ExaCopy;
+    pExa->DoneCopy = ExaDone;
+    pExa->CheckComposite = ExaCheckComposite;
+    pExa->PrepareComposite = ExaPrepareComposite;
+    pExa->Composite = ExaComposite;
+    pExa->DoneComposite = ExaDoneComposite;
+    pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
+    pExa->PrepareAccess = ExaPrepareAccess;
+    pExa->FinishAccess = ExaFinishAccess;
+    pExa->UploadToScreen = ExaUploadToScreen;
+
+    if (!exaDriverInit(pScrn->pScreen, pExa)) {
+	goto out_err;
+    }
+
+    return pExa;
+
+  out_err:
+    ExaClose(pScrn);
+
+    return NULL;
+}
diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man
new file mode 100644
index 0000000..e69de29
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
new file mode 100644
index 0000000..b25540e
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -0,0 +1,285 @@
+/*
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xf86.h>
+#include <xf86i2c.h>
+#include <xf86Crtc.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+
+#include "X11/Xatom.h"
+
+#include "driver.h"
+
+static void
+dpms(xf86OutputPtr output, int mode)
+{
+}
+
+static void
+save(xf86OutputPtr output)
+{
+}
+
+static void
+restore(xf86OutputPtr output)
+{
+}
+
+static int
+mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
+{
+   return MODE_OK;
+}
+
+static Bool
+mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
+	   DisplayModePtr adjusted_mode)
+{
+   return TRUE;
+}
+
+static void
+prepare(xf86OutputPtr output)
+{
+   dpms(output, DPMSModeOff);
+}
+
+static void
+mode_set(xf86OutputPtr output, DisplayModePtr mode,
+	 DisplayModePtr adjusted_mode)
+{
+}
+
+static void
+commit(xf86OutputPtr output)
+{
+   dpms(output, DPMSModeOn);
+
+   if (output->scrn->pScreen != NULL)
+      xf86_reload_cursors(output->scrn->pScreen);
+}
+
+static xf86OutputStatus
+detect(xf86OutputPtr output)
+{
+   drmModeOutputPtr drm_output = output->driver_private;
+
+   switch (drm_output->connection) {
+   	case DRM_MODE_CONNECTED:
+	    return XF86OutputStatusConnected;
+	case DRM_MODE_DISCONNECTED:
+	    return XF86OutputStatusDisconnected;
+	default:
+	    return XF86OutputStatusUnknown;
+   }
+}
+
+static DisplayModePtr
+get_modes(xf86OutputPtr output)
+{
+   drmModeOutputPtr drm_output = output->driver_private;
+   struct drm_mode_modeinfo *drm_mode = NULL;
+   DisplayModePtr modes = NULL, mode = NULL;
+   int i;
+
+   for (i = 0; i < drm_output->count_modes; i++) {
+      drm_mode = &drm_output->modes[i];
+      if (drm_mode) {
+	 mode = xcalloc(1, sizeof(DisplayModeRec));
+	 if (!mode)
+	    continue;
+	 mode->type = 0;
+	 mode->Clock = drm_mode->clock;
+	 mode->HDisplay = drm_mode->hdisplay;
+	 mode->HSyncStart = drm_mode->hsync_start;
+	 mode->HSyncEnd = drm_mode->hsync_end;
+	 mode->HTotal = drm_mode->htotal;
+	 mode->VDisplay = drm_mode->vdisplay;
+	 mode->VSyncStart = drm_mode->vsync_start;
+	 mode->VSyncEnd = drm_mode->vsync_end;
+	 mode->VTotal = drm_mode->vtotal;
+	 mode->Flags = drm_mode->flags;
+	 mode->HSkew = drm_mode->hskew;
+	 mode->VScan = drm_mode->vscan;
+	 mode->VRefresh = xf86ModeVRefresh(mode);
+	 mode->Private = (void *)drm_mode;
+	 xf86SetModeDefaultName(mode);
+	 modes = xf86ModesAdd(modes, mode);
+	 xf86PrintModeline(0, mode);
+      }
+   }
+
+   return modes;
+}
+
+static void
+destroy(xf86OutputPtr output)
+{
+   drmModeFreeOutput(output->driver_private);
+}
+
+static void
+create_resources(xf86OutputPtr output)
+{
+#ifdef RANDR_12_INTERFACE
+#endif /* RANDR_12_INTERFACE */
+}
+
+#ifdef RANDR_12_INTERFACE
+static Bool
+set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
+{
+   return TRUE;
+}
+#endif /* RANDR_12_INTERFACE */
+
+#ifdef RANDR_13_INTERFACE
+static Bool
+get_property(xf86OutputPtr output, Atom property)
+{
+   return TRUE;
+}
+#endif /* RANDR_13_INTERFACE */
+
+#ifdef RANDR_GET_CRTC_INTERFACE
+static xf86CrtcPtr
+get_crtc(xf86OutputPtr output)
+{
+   return NULL;
+}
+#endif
+
+static const xf86OutputFuncsRec output_funcs = {
+   .create_resources = create_resources,
+   .dpms = dpms,
+   .save = save,
+   .restore = restore,
+   .mode_valid = mode_valid,
+   .mode_fixup = mode_fixup,
+   .prepare = prepare,
+   .mode_set = mode_set,
+   .commit = commit,
+   .detect = detect,
+   .get_modes = get_modes,
+#ifdef RANDR_12_INTERFACE
+   .set_property = set_property,
+#endif
+#ifdef RANDR_13_INTERFACE
+   .get_property = get_property,
+#endif
+   .destroy = destroy,
+#ifdef RANDR_GET_CRTC_INTERFACE
+   .get_crtc = get_crtc,
+#endif
+};
+
+void
+output_init(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+   xf86OutputPtr output;
+   drmModeResPtr res;
+   drmModeOutputPtr drm_output = NULL;
+   drmModeCrtcPtr crtc;
+   char *name;
+   int o, v, p;
+
+   res = drmModeGetResources(ms->fd);
+   if (res == 0) {
+      DRV_ERROR("Failed drmModeGetResources\n");
+      return;
+   }
+
+   for (o = 0; o < res->count_outputs; o++) {
+      drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
+      if (!drm_output)
+         goto out;
+
+      for (p = 0; p < drm_output->count_props; p++) {
+	 drmModePropertyPtr prop;
+
+	 prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
+
+	 name = NULL;
+	 if (prop) {
+	 ErrorF("VALUES %d\n",prop->count_values);
+
+	    for (v=0;v<prop->count_values;v++) 
+	    	ErrorF("%s %lld\n", prop->name, prop->values[v]);
+
+	    for (v=0;v<prop->count_enums;v++) {
+	    	ErrorF("%s %s\n", prop->name, prop->enums[v].name);
+		if (drm_output->prop_values[p] == prop->enums[v].value) {
+		if (!strncmp("Connector Type", prop->name, 14)) {
+			ErrorF("WE'VE GOT %s\n",prop->enums[v].name);
+			name = xalloc(strlen(prop->enums[v].name));
+			strncpy(name, prop->enums[v].name, strlen(name));
+		}
+		}
+		if (name) break;
+	    }
+	    if (name) break;
+	 }
+      }
+
+      if (!name)
+         continue;
+
+      output = xf86OutputCreate(pScrn, &output_funcs, name);
+      if (!output)
+	 continue;
+
+	free(name);
+
+      output->possible_crtcs = drm_output->crtcs;
+      output->possible_clones = drm_output->clones;
+      output->driver_private = drm_output;
+      output->subpixel_order = SubPixelHorizontalRGB;
+      output->interlaceAllowed = FALSE;
+      output->doubleScanAllowed = FALSE;
+   }
+
+out:
+   drmModeFreeResources(res);
+}


More information about the xorg-commit mailing list