xf86-video-intel: Branch 'jbarnes-cleanup' - 20 commits - src/i830_accel.c src/i830_display.c src/i830_dri.c src/i830_driver.c src/i830_exa.c src/i830.h src/i830_memory.c src/i830_video.c

Jesse Barnes jbarnes at kemper.freedesktop.org
Fri Mar 7 09:04:54 PST 2008


 src/i830.h         |   21 +--
 src/i830_accel.c   |   15 +-
 src/i830_display.c |    4 
 src/i830_dri.c     |   10 -
 src/i830_driver.c  |  354 ++++++++++++++++++++++++++---------------------------
 src/i830_exa.c     |    6 
 src/i830_memory.c  |   17 +-
 src/i830_video.c   |   10 -
 8 files changed, 220 insertions(+), 217 deletions(-)

New commits:
commit 7343d18b408e0895c46a20bc598923adb87a14c0
Merge: 13ae79b... 46771cb...
Author: Jesse Barnes <jbarnes at hobbes.virtuousgeek.org>
Date:   Fri Mar 7 08:59:57 2008 -0800

    Merge ssh://people.freedesktop.org/~jbarnes/xf86-video-intel into jbarnes-cleanup
    
    Conflicts:
    
    	src/i830_driver.c
    
    Untested, but should compile with a default config.

diff --cc src/i830_accel.c
index fdc713b,3e10778..e74f9c1
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@@ -173,9 -173,6 +173,9 @@@ I830Sync(ScrnInfoPtr pScrn
     if (I810_DEBUG & (DEBUG_VERBOSE_ACCEL | DEBUG_VERBOSE_SYNC))
        ErrorF("I830Sync\n");
  
-    if (pI830->noAccel)
++   if (pI830->accel_method == ACCEL_NONE)
 +       return;
 +
  #ifdef XF86DRI
     /* VT switching tries to do this.
      */
diff --cc src/i830_driver.c
index 854e377,2589421..2c8d6bf
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@@ -1241,6 -1242,62 +1242,63 @@@ i830_detect_chipset(ScrnInfoPtr pScrn
      return TRUE;
  }
  
+ static enum accel_method
+ i830_get_accel_method(ScrnInfoPtr pScrn)
+ {
+     I830Ptr pI830 = I830PTR(pScrn);
+     enum accel_method method = ACCEL_NONE;
+     char *s;
+ 
+     /*
+      * The ugliness below:
+      * If either XAA or EXA (exclusive) is compiled in, default to it.
+      * 
+      * If both are compiled in, and the user didn't specify noAccel, use the
+      * config option AccelMethod to determine which to use, defaulting to EXA
+      * if none is specified, or if the string was unrecognized.
+      *
+      * All this *could* go away if we removed XAA support from this driver,
+      * for example. :)
+      */
+ 
+ #ifdef I830_USE_EXA
+     method = ACCEL_EXA;
+ #else
+     method = ACCEL_XAA;
+ #endif
+ 
+ #if defined(I830_USE_XAA) && defined(I830_USE_EXA)
+     if ((s = (char *)xf86GetOptValString(pI830->Options, OPTION_ACCELMETHOD))) {
+ 	if (!xf86NameCmp(s, "EXA"))
+ 	    method = ACCEL_EXA;
+ 	else if (!xf86NameCmp(s, "XAA"))
+ 	    method = ACCEL_XAA;
+     }
+ #endif
+ 
+     /* Noaccel overrides everything */
+     if (xf86ReturnOptValBool(pI830->Options, OPTION_NOACCEL, FALSE))
+ 	method = ACCEL_NONE;
+ 
+     switch (method) {
+     case ACCEL_EXA:
+ 	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using EXA for acceleration\n");
+ 	break;
+     case ACCEL_XAA:
+ 	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using XAA for acceleration\n");
+ 	break;
+     case ACCEL_NONE:
+ 	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "disabling acceleration\n");
+ 	break;
+     default:
+ 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "unknown acceleration method\n");
+ 	break;
+     }
+ 
+     return method;
+ }
+ 
++
  /**
   * This is called per zaphod head (so usually just once) to do initialization
   * before the Screen is created.
@@@ -2662,17 -2674,15 +2675,13 @@@ I830ScreenInit(int scrnIndex, ScreenPt
        pScrn->videoRam &= ~3;
     }
  
--#ifdef XF86DRI
-    /* If DRI hasn't been explicitly disabled, try to initialize it.
-     * It will be used by the memory allocator.
-     */
-    if (!pI830->directRenderingDisabled)
-       pI830->directRenderingEnabled = I830DRIScreenInit(pScreen);
-    else
-       pI830->directRenderingEnabled = FALSE;
- #else
-    pI830->directRenderingEnabled = FALSE;
- #endif
+    /* Try to init DRI if it's enabled */
+    if (pI830->directRendering) {
+        if (I830CheckDRIAvailable(pScrn))
+ 	   pI830->directRendering = I830DRIScreenInit(pScreen);
+        else
+ 	   pI830->directRendering = FALSE;
+    }
 -#endif
  
     /* Enable tiling by default */
     pI830->tiling = TRUE;
commit 46771cbd0fe970f29a6a7b970cd7124976d12b31
Author: Jesse Barnes <jbarnes at hobbes.virtuousgeek.org>
Date:   Fri Feb 22 15:45:22 2008 -0800

    Remove SaveHWState call from EnterVT
    
    We already do it at PreInit time, no need to do it again.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 5d53350..2589421 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3170,15 +3170,6 @@ I830EnterVT(int scrnIndex, int flags)
 
    DPRINTF(PFX, "Enter VT\n");
 
-   /*
-    * 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 (pI830->SaveGeneration != serverGeneration) {
-      pI830->SaveGeneration = serverGeneration;
-      SaveHWState(pScrn);
-   }
-
    pI830->leaving = FALSE;
 
 #ifdef XF86DRI_MM
commit 377e54a3dd343ee22f471072224fb185351ae448
Author: Jesse Barnes <jbarnes at hobbes.virtuousgeek.org>
Date:   Fri Feb 22 13:39:47 2008 -0800

    Don't walk into LpRing struct if it doesn't exist
    
    Fix from Lukas Hejtmanek <xhejtman at ics.muni.cz>.
    
    If we're called early on, the ring may not be allocated yet, so we can't just
    read the mem field w/o checking whether LpRing exits or not.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index ca6fbd7..5d53350 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1861,7 +1861,7 @@ i830_refresh_ring(ScrnInfoPtr pScrn)
    /* If we're reaching RefreshRing as a result of grabbing the DRI lock
     * before we've set up the ringbuffer, don't bother.
     */
-   if (pI830->LpRing->mem == NULL)
+   if (!pI830->LpRing || !pI830->LpRing->mem)
        return;
 
    pI830->LpRing->head = INREG(LP_RING + RING_HEAD) & I830_HEAD_MASK;
commit c905a380fac53ebf2d990bf0546b7b883ac39548
Merge: 10693b0... 975d783...
Author: Jesse Barnes <jbarnes at hobbes.virtuousgeek.org>
Date:   Fri Feb 22 13:36:35 2008 -0800

    Merge branch 'master' of ssh://git.freedesktop.org/git/xorg/driver/xf86-video-intel
    
    Conflicts:
    
    	src/i830_driver.c

diff --cc src/i830_driver.c
index 2bf5631,5cd0a34..ca6fbd7
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@@ -1019,262 -1036,6 +1037,267 @@@ i830SetHotkeyControl(ScrnInfoPtr pScrn
     pI830->writeControl(pI830, GRX, 0x18, gr18);
  }
  
 +static Bool
 +i830_detect_chipset(ScrnInfoPtr pScrn)
 +{
 +    I830Ptr pI830 = I830PTR(pScrn);
 +    MessageType from = X_PROBED;
 +    const char *chipname;
 +    uint32_t capid;
 +    int fb_bar, mmio_bar;
 +
 +    switch (DEVICE_ID(pI830->PciInfo)) {
 +    case PCI_CHIP_I830_M:
 +	chipname = "830M";
 +	break;
 +    case PCI_CHIP_845_G:
 +	chipname = "845G";
 +	break;
 +    case PCI_CHIP_I855_GM:
 +	/* Check capid register to find the chipset variant */
 +#if XSERVER_LIBPCIACCESS
 +	pci_device_cfg_read_u32 (pI830->PciInfo, &capid, I85X_CAPID);
 +#else
 +	capid = pciReadLong (pI830->PciTag, I85X_CAPID);
 +#endif
 +	pI830->variant = (capid >> I85X_VARIANT_SHIFT) & I85X_VARIANT_MASK;
 +	switch (pI830->variant) {
 +	case I855_GM:
 +	    chipname = "855GM";
 +	    break;
 +	case I855_GME:
 +	    chipname = "855GME";
 +	    break;
 +	case I852_GM:
 +	    chipname = "852GM";
 +	    break;
 +	case I852_GME:
 +	    chipname = "852GME";
 +	    break;
 +	default:
 +	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 +		       "Unknown 852GM/855GM variant: 0x%x)\n", pI830->variant);
 +	    chipname = "852GM/855GM (unknown variant)";
 +	    break;
 +	}
 +	break;
 +    case PCI_CHIP_I865_G:
 +	chipname = "865G";
 +	break;
 +    case PCI_CHIP_I915_G:
 +	chipname = "915G";
 +	break;
 +    case PCI_CHIP_E7221_G:
 +	chipname = "E7221 (i915)";
 +	break;
 +    case PCI_CHIP_I915_GM:
 +	chipname = "915GM";
 +	break;
 +    case PCI_CHIP_I945_G:
 +	chipname = "945G";
 +	break;
 +    case PCI_CHIP_I945_GM:
 +	chipname = "945GM";
 +	break;
 +    case PCI_CHIP_I945_GME:
 +	chipname = "945GME";
 +	break;
 +    case PCI_CHIP_I965_G:
-     case PCI_CHIP_I965_G_1:
 +	chipname = "965G";
 +	break;
++    case PCI_CHIP_G35_G:
++	chipname = "G35";
++	break;
 +    case PCI_CHIP_I965_Q:
 +	chipname = "965Q";
 +	break;
 +    case PCI_CHIP_I946_GZ:
 +	chipname = "946GZ";
 +	break;
 +    case PCI_CHIP_I965_GM:
 +	chipname = "965GM";
 +	break;
 +    case PCI_CHIP_I965_GME:
 +	chipname = "965GME/GLE";
 +	break;
 +    case PCI_CHIP_G33_G:
 +	chipname = "G33";
 +	break;
 +    case PCI_CHIP_Q35_G:
 +	chipname = "Q35";
 +	break;
 +    case PCI_CHIP_Q33_G:
 +	chipname = "Q33";
 +	break;
-     default:
++    case PCI_CHIP_IGD_GM:
++	chipname = "Intel Integrated Graphics Device";
++	break;
++   default:
 +	chipname = "unknown chipset";
 +	break;
 +    }
 +    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 +	       "Integrated Graphics Chipset: Intel(R) %s\n", chipname);
 +
 +    /* Set the Chipset and ChipRev, allowing config file entries to override. */
 +    if (pI830->pEnt->device->chipset && *pI830->pEnt->device->chipset) {
 +	pScrn->chipset = pI830->pEnt->device->chipset;
 +	from = X_CONFIG;
 +    } else if (pI830->pEnt->device->chipID >= 0) {
 +	pScrn->chipset = (char *)xf86TokenToString(I830Chipsets,
 +						   pI830->pEnt->device->chipID);
 +	from = X_CONFIG;
 +	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",
 +		   pI830->pEnt->device->chipID);
 +	DEVICE_ID(pI830->PciInfo) = pI830->pEnt->device->chipID;
 +    } else {
 +	from = X_PROBED;
 +	pScrn->chipset = (char *)xf86TokenToString(I830Chipsets,
 +						   DEVICE_ID(pI830->PciInfo));
 +    }
 +
 +    if (pI830->pEnt->device->chipRev >= 0) {
 +	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
 +		   pI830->pEnt->device->chipRev);
 +    }
 +
 +    xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n",
 +	       (pScrn->chipset != NULL) ? pScrn->chipset : "Unknown i8xx");
 +
 +    /* Now that we know the chipset, figure out the resource base addrs */
 +    if (IS_I9XX(pI830)) {
 +	fb_bar = 2;
 +	mmio_bar = 0;
 +    } else {
 +	fb_bar = 0;
 +	mmio_bar = 1;
 +    }
 +
 +    if (pI830->pEnt->device->MemBase != 0) {
 +	pI830->LinearAddr = pI830->pEnt->device->MemBase;
 +	from = X_CONFIG;
 +    } else {
 +	pI830->LinearAddr = I810_MEMBASE (pI830->PciInfo, fb_bar);
 +	if (pI830->LinearAddr == 0) {
 +	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 +		       "No valid FB address in PCI config space\n");
 +	    PreInitCleanup(pScrn);
 +	    return FALSE;
 +	}
 +    }
 +
 +    xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
 +	       (unsigned long)pI830->LinearAddr);
 +
 +    if (pI830->pEnt->device->IOBase != 0) {
 +	pI830->MMIOAddr = pI830->pEnt->device->IOBase;
 +	from = X_CONFIG;
 +    } else {
 +	pI830->MMIOAddr = I810_MEMBASE (pI830->PciInfo, mmio_bar);
 +	if (pI830->MMIOAddr == 0) {
 +	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 +		       "No valid MMIO address in PCI config space\n");
 +	    PreInitCleanup(pScrn);
 +	    return FALSE;
 +	}
 +    }
 +
 +    xf86DrvMsg(pScrn->scrnIndex, from, "IO registers at addr 0x%lX\n",
 +	       (unsigned long)pI830->MMIOAddr);
 +
 +    /* Now figure out mapsize on 8xx chips */
 +    if (IS_I830(pI830) || IS_845G(pI830)) {
 +#if XSERVER_LIBPCIACCESS
 +	uint16_t		gmch_ctrl;
 +	struct pci_device *bridge;
 +
 +	bridge = intel_host_bridge ();
 +	pci_device_cfg_read_u16 (bridge, &gmch_ctrl, I830_GMCH_CTRL);
 +#else
 +	PCITAG bridge;
 +	CARD16 gmch_ctrl;
 +
 +	bridge = pciTag(0, 0, 0);		/* This is always the host bridge */
 +	gmch_ctrl = pciReadWord(bridge, I830_GMCH_CTRL);
 +#endif
 +	if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
 +	    pI830->FbMapSize = 0x8000000;
 +	} else {
 +	    pI830->FbMapSize = 0x4000000; /* 64MB - has this been tested ?? */
 +	}
 +    } else {
 +	if (IS_I9XX(pI830)) {
 +#if XSERVER_LIBPCIACCESS
 +	    pI830->FbMapSize = pI830->PciInfo->regions[fb_bar].size;
 +#else
 +	    pI830->FbMapSize = 1UL << pciGetBaseSize(pI830->PciTag, 2, TRUE,
 +						     NULL);
 +#endif
 +	} else {
 +	    /* 128MB aperture for later i8xx series. */
 +	    pI830->FbMapSize = 0x8000000;
 +	}
 +    }
 +
 +    return TRUE;
 +}
 +
 +static enum accel_method
 +i830_get_accel_method(ScrnInfoPtr pScrn)
 +{
 +    I830Ptr pI830 = I830PTR(pScrn);
 +    enum accel_method method = ACCEL_NONE;
 +    char *s;
 +
 +    /*
 +     * The ugliness below:
 +     * If either XAA or EXA (exclusive) is compiled in, default to it.
 +     * 
 +     * If both are compiled in, and the user didn't specify noAccel, use the
 +     * config option AccelMethod to determine which to use, defaulting to EXA
 +     * if none is specified, or if the string was unrecognized.
 +     *
 +     * All this *could* go away if we removed XAA support from this driver,
 +     * for example. :)
 +     */
 +
 +#ifdef I830_USE_EXA
 +    method = ACCEL_EXA;
 +#else
 +    method = ACCEL_XAA;
 +#endif
 +
 +#if defined(I830_USE_XAA) && defined(I830_USE_EXA)
 +    if ((s = (char *)xf86GetOptValString(pI830->Options, OPTION_ACCELMETHOD))) {
 +	if (!xf86NameCmp(s, "EXA"))
 +	    method = ACCEL_EXA;
 +	else if (!xf86NameCmp(s, "XAA"))
 +	    method = ACCEL_XAA;
 +    }
 +#endif
 +
 +    /* Noaccel overrides everything */
 +    if (xf86ReturnOptValBool(pI830->Options, OPTION_NOACCEL, FALSE))
 +	method = ACCEL_NONE;
 +
 +    switch (method) {
 +    case ACCEL_EXA:
 +	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using EXA for acceleration\n");
 +	break;
 +    case ACCEL_XAA:
 +	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using XAA for acceleration\n");
 +	break;
 +    case ACCEL_NONE:
 +	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "disabling acceleration\n");
 +	break;
 +    default:
 +	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "unknown acceleration method\n");
 +	break;
 +    }
 +
 +    return method;
 +}
 +
  /**
   * This is called per zaphod head (so usually just once) to do initialization
   * before the Screen is created.
@@@ -2662,15 -2521,9 +2695,16 @@@ I830ScreenInit(int scrnIndex, ScreenPt
  	   pI830->tiling = FALSE;
     }
  
 +   /* Tiling only works with EXA, so disable it if needed */
 +   if (pI830->tiling == TRUE && (pI830->accel_method != ACCEL_EXA)) {
 +       xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Disabling tiling, only "
 +		  "supported with EXA\n");
 +       pI830->tiling = FALSE;
 +   }
 +
     /* Enable FB compression if possible */
-    if (i830_fb_compression_supported(pI830) && !IS_I965GM(pI830))
+    if (i830_fb_compression_supported(pI830) && !IS_I965GM(pI830)
 -	   && !IS_IGD_GM(pI830))
++       && !IS_IGD_GM(pI830))
         pI830->fb_compression = TRUE;
     else
         pI830->fb_compression = FALSE;
@@@ -2827,9 -2815,9 +2861,9 @@@
      *       alone in that case.
      * Also make sure the DRM can handle the swap.
      */
-    if (I830LVDSPresent(pScrn) && !IS_I965GM(pI830) &&
+    if (I830LVDSPresent(pScrn) && !IS_I965GM(pI830) && !IS_IGD_GM(pI830) &&
 -       (!pI830->directRenderingEnabled ||
 -	(pI830->directRenderingEnabled && pI830->drmMinor >= 10))) {
 +       (!pI830->directRendering ||
 +	(pI830->directRendering && pI830->drmMinor >= 10))) {
         xf86DrvMsg(pScrn->scrnIndex, X_INFO, "adjusting plane->pipe mappings "
  		  "to allow for framebuffer compression\n");
         for (c = 0; c < config->num_crtc; c++) {
@@@ -2949,10 -2936,14 +2983,14 @@@
     /* Must be called before EnterVT, so we can acquire the DRI lock when
      * binding our memory.
      */
 -   if (pI830->directRenderingEnabled)
 -      pI830->directRenderingEnabled = I830DRIFinishScreenInit(pScreen);
 +   if (pI830->directRendering)
 +      pI830->directRendering = I830DRIFinishScreenInit(pScreen);
  #endif
  
+    /* 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;
+ 
     if (!I830EnterVT(scrnIndex, 0))
        return FALSE;
  
@@@ -3187,7 -3189,23 +3226,23 @@@ I830EnterVT(int scrnIndex, int flags
     SetHWOperatingState(pScrn);
  
  #ifdef XF86DRI
 -   if (pI830->directRenderingEnabled) {
 +   if (pI830->directRendering) {
+        /* HW status is fixed, we need to set it up before any drm
+ 	* operation which accessing that page, like irq install, etc.
+ 	*/
+        if (pI830->starting) {
+ 	   if (HWS_NEED_GFX(pI830) && !I830DRISetHWS(pScrn)) {
+ 		   xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+ 			   "Fail to setup hardware status page.\n");
+ 		   I830DRICloseScreen(pScrn->pScreen);
+ 		   return FALSE;
+ 	   }
+ 	   if (!I830DRIInstIrqHandler(pScrn)) {
+ 	       I830DRICloseScreen(pScrn->pScreen);
+ 	       return FALSE;
+ 	   }
+        }
+ 
        /* Update buffer offsets in sarea and mappings, since buffer offsets
         * may have changed.
         */
commit 10693b04da868709b204eb5dcbd55a2dda698fba
Merge: 15bfe68... f2ffc0f...
Author: Jesse Barnes <jbarnes at hobbes.virtuousgeek.org>
Date:   Thu Jan 3 12:06:19 2008 -0800

    Merge ssh://git.freedesktop.org/git/xorg/driver/xf86-video-intel

commit 15bfe6844c6bd404b0f5806e0849c28cb924f3ed
Author: Jesse Barnes <jbarnes at nietzche.virtuousgeek.org>
Date:   Fri Dec 7 12:34:01 2007 -0800

    Fix some bugs in the refactored code
    
    We weren't properly setting & clearing the directRendering & tiling
    flags in pI830, so set them correctly if the tiled or dri allocations
    fail.  Part of this involves removing the 'tiled' flag from
    try_memory_allocation and just using the pI830 fields directly.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 1289028..158f2ba 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2358,9 +2358,11 @@ i830_fixup_mtrrs(ScrnInfoPtr pScrn)
 }
 
 static Bool
-i830_try_memory_allocation(ScrnInfoPtr pScrn, Bool tiled)
+i830_try_memory_allocation(ScrnInfoPtr pScrn)
 {
     I830Ptr pI830 = I830PTR(pScrn);
+    Bool tiled = pI830->tiling;
+    Bool dri = pI830->directRendering;
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 	       "Attempting memory allocation with %stiled buffers.\n",
@@ -2369,7 +2371,7 @@ i830_try_memory_allocation(ScrnInfoPtr pScrn, Bool tiled)
     if (!i830_allocate_2d_memory(pScrn))
 	goto failed;
 
-    if (pI830->directRendering && !i830_allocate_3d_memory(pScrn))
+    if (dri && !i830_allocate_3d_memory(pScrn))
 	goto failed;
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%siled allocation successful.\n",
@@ -2402,7 +2404,7 @@ i830_memory_init(ScrnInfoPtr pScrn)
     /*
      * Adjust the display width to allow for front buffer tiling if possible
      */
-    if (pI830->directRendering && pI830->tiling) {
+    if (pI830->tiling) {
 	if (IS_I965G(pI830)) {
 	    int tile_pixels = 512 / pI830->cpp;
 	    pScrn->displayWidth = (pScrn->displayWidth + tile_pixels - 1) &
@@ -2450,12 +2452,17 @@ i830_memory_init(ScrnInfoPtr pScrn)
 	pI830->CacheLines = -1;
     }
 
-    /* Tiled first */
-    if (tiled && i830_try_memory_allocation(pScrn, TRUE))
+    /* Tiled first if we got a good displayWidth */
+    if (tiled) {
+	if (i830_try_memory_allocation(pScrn))
 	    return TRUE;
+	else {
+	    i830_reset_allocations(pScrn);
+	    pI830->tiling = FALSE;
+	}
+    }  
 
     /* If tiling fails we have to disable page flipping & FBC */
-    pI830->tiling = FALSE;
     pScrn->displayWidth = savedDisplayWidth;
     if (pI830->allowPageFlip)
 	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
@@ -2469,17 +2476,18 @@ i830_memory_init(ScrnInfoPtr pScrn)
     pI830->fb_compression = FALSE;
 
     /* Try again, but leave DRI enabled */
-    if (i830_try_memory_allocation(pScrn, FALSE))
+    if (pI830->directRendering) {
+	if (i830_try_memory_allocation(pScrn))
 	    return TRUE;
+	else {
+	    i830_reset_allocations(pScrn);
+	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Couldn't allocate 3D memory, "
+		       "disabling DRI.\n");
+	    pI830->directRendering = FALSE;
+	}
+    }
 
-    /* Fail, try to disable DRI as a last ditch effort */
-    if (pI830->directRendering)
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Couldn't allocated 3D memory, "
-		   "disabling DRI.\n");
-    pI830->directRendering = FALSE;
-
-    i830_reset_allocations(pScrn);
-    if (i830_allocate_2d_memory(pScrn))
+    if (i830_try_memory_allocation(pScrn))
 	return TRUE;
 
     return FALSE;
commit cef46978fd6a44621096138957388dbe92dbd7e2
Author: Jesse Barnes <jbarnes at nietzche.virtuousgeek.org>
Date:   Fri Dec 7 11:26:58 2007 -0800

    Refactor memory allocation a bit more
    
    Pull the main allocation code into its own function and cleanup the
    memory init code a little more.  Should make the code fairly
    self-evident and make it easy to remove bogus fallbacks (like untiled
    allocation) in the future.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 9bd26f3..1289028 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2357,6 +2357,31 @@ i830_fixup_mtrrs(ScrnInfoPtr pScrn)
 #endif
 }
 
+static Bool
+i830_try_memory_allocation(ScrnInfoPtr pScrn, Bool tiled)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+	       "Attempting memory allocation with %stiled buffers.\n",
+	       tiled ? "" : "un");
+
+    if (!i830_allocate_2d_memory(pScrn))
+	goto failed;
+
+    if (pI830->directRendering && !i830_allocate_3d_memory(pScrn))
+	goto failed;
+
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%siled allocation successful.\n",
+	       tiled ? "T" : "Unt");
+    return TRUE;
+
+failed:
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%siled allocation failed.\n",
+	       tiled ? "T" : "Unt");
+    return FALSE;
+}
+
 /*
  * Try to allocate memory in several ways:
  *  1) If direct rendering is enabled, try to allocate enough memory for tiled
@@ -2374,6 +2399,9 @@ i830_memory_init(ScrnInfoPtr pScrn)
     int i;
     Bool tiled = FALSE;
 
+    /*
+     * Adjust the display width to allow for front buffer tiling if possible
+     */
     if (pI830->directRendering && pI830->tiling) {
 	if (IS_I965G(pI830)) {
 	    int tile_pixels = 512 / pI830->cpp;
@@ -2422,36 +2450,11 @@ i830_memory_init(ScrnInfoPtr pScrn)
 	pI830->CacheLines = -1;
     }
 
-    if (!tiled) {
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to find a tileable pitch, "
-		   "falling back to untiled allocation.\n");
-	goto allocate_untiled;
-    }
-
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-	       "Attempting memory allocation with tiled buffers.\n");
-    if (pScrn->displayWidth != savedDisplayWidth) {
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-		   "Increasing the scanline pitch for tiled allocation "
-		   "(%d -> %d).\n",
-		   savedDisplayWidth, pScrn->displayWidth);
-    }
+    /* Tiled first */
+    if (tiled && i830_try_memory_allocation(pScrn, TRUE))
+	    return TRUE;
 
-    if (!i830_allocate_2d_memory(pScrn)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate tiled 2D "
-		   "objects.  Falling back to untiled allocation.\n");
-	goto allocate_untiled;
-    }
-    if (pI830->directRendering && !i830_allocate_3d_memory(pScrn)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate tiled 3D "
-		   "objects.  Falling back to untiled allocation.\n");
-	goto allocate_untiled;
-    }
-
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Tiled allocation successful.\n");
-    return TRUE;
-
-allocate_untiled:
+    /* If tiling fails we have to disable page flipping & FBC */
     pI830->tiling = FALSE;
     pScrn->displayWidth = savedDisplayWidth;
     if (pI830->allowPageFlip)
@@ -2465,24 +2468,17 @@ allocate_untiled:
 		   "disabled\n");
     pI830->fb_compression = FALSE;
 
-    if (!i830_allocate_2d_memory(pScrn)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate untiled 2D "
-		   "objects.  Disabling DRI.\n");
-	goto allocate_no_dri;
-    }
-    if (pI830->directRendering && !i830_allocate_3d_memory(pScrn)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate untiled 3D "
-		   "objects.  Disabling DRI.\n");
-	goto allocate_no_dri;
-    }
+    /* Try again, but leave DRI enabled */
+    if (i830_try_memory_allocation(pScrn, FALSE))
+	    return TRUE;
 
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Untiled allocation successful.\n");
-    return TRUE;
-
-allocate_no_dri:
-    i830_reset_allocations(pScrn);
+    /* Fail, try to disable DRI as a last ditch effort */
+    if (pI830->directRendering)
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Couldn't allocated 3D memory, "
+		   "disabling DRI.\n");
     pI830->directRendering = FALSE;
 
+    i830_reset_allocations(pScrn);
     if (i830_allocate_2d_memory(pScrn))
 	return TRUE;
 
commit a0f71fd88d28a7cbf04fc02110bbeabe1602dbd1
Author: Jesse Barnes <jbarnes at nietzche.virtuousgeek.org>
Date:   Fri Dec 7 10:51:42 2007 -0800

    Account for FBC LL cache in memory reservation
    
    When we reserve memory (memory that won't be managed by the kernel) make
    sure to reserve space for the FBC LL cache as well.

diff --git a/src/i830_memory.c b/src/i830_memory.c
index 8b769bd..bdfa100 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -464,7 +464,7 @@ i830_allocator_init(ScrnInfoPtr pScrn, unsigned long offset, unsigned long size)
 		    ROUND_TO(HWCURSOR_SIZE_ARGB, GTT_PAGE_SIZE));
 	}
 	if (pI830->fb_compression)
-	    mmsize -= MB(6);
+	    mmsize -= MB(6) + ROUND_TO_PAGE(FBC_LL_SIZE + FBC_LL_PAD);
 	/* Can't do TTM on stolen memory */
 	mmsize -= pI830->stolen_size;
 
commit d4e5543e209764275a5902a20559d5e9d7b9c780
Author: Jesse Barnes <jbarnes at nietzche.virtuousgeek.org>
Date:   Fri Dec 7 10:50:45 2007 -0800

    Refactor memory allocation into a separate function
    
    This simplifies the memory allocation code and fixes a number of bugs.
    Prior to this change, some flags may have been set after memory
    allocation occurred, meaning they had no effect.  It should also make
    the allocation logic clearer.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 1418464..9bd26f3 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2357,6 +2357,138 @@ i830_fixup_mtrrs(ScrnInfoPtr pScrn)
 #endif
 }
 
+/*
+ * Try to allocate memory in several ways:
+ *  1) If direct rendering is enabled, try to allocate enough memory for tiled
+ *     surfaces by rounding up the display width to a tileable one.
+ *  2) If that fails or the allocations themselves fail, try again with untiled
+ *     allocations (if this works DRI will stay enabled).
+ *  3) And if all else fails, disable DRI and try just 2D allocations.
+ *  4) Give up and fail ScreenInit.
+ */
+static Bool
+i830_memory_init(ScrnInfoPtr pScrn)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    int savedDisplayWidth = pScrn->displayWidth;
+    int i;
+    Bool tiled = FALSE;
+
+    if (pI830->directRendering && pI830->tiling) {
+	if (IS_I965G(pI830)) {
+	    int tile_pixels = 512 / pI830->cpp;
+	    pScrn->displayWidth = (pScrn->displayWidth + tile_pixels - 1) &
+		~(tile_pixels - 1);
+	    tiled = TRUE;
+	} else {
+	    /* Good pitches to allow tiling.  Don't care about pitches < 1024
+	     * pixels.
+	     */
+	    static const int pitches[] = {
+		1024,
+		2048,
+		4096,
+		8192,
+		0
+	    };
+
+	    for (i = 0; pitches[i] != 0; i++) {
+		if (pitches[i] >= pScrn->displayWidth) {
+		    pScrn->displayWidth = pitches[i];
+		    tiled = TRUE;
+		    break;
+		}
+	    }
+	}
+    }
+
+    /* Set up our video memory allocator for the chosen videoRam */
+    if (!i830_allocator_init(pScrn, 0, pScrn->videoRam * KB(1))) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		   "Couldn't initialize video memory allocator\n");
+	PreInitCleanup(pScrn);
+	return FALSE;
+    }
+
+    xf86DrvMsg(pScrn->scrnIndex,
+	       pI830->pEnt->device->videoRam ? X_CONFIG : X_DEFAULT,
+	       "VideoRam: %d KB\n", pScrn->videoRam);
+
+    if (xf86GetOptValInteger(pI830->Options, OPTION_CACHE_LINES,
+			     &(pI830->CacheLines))) {
+	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Requested %d cache lines\n",
+		   pI830->CacheLines);
+    } else {
+	pI830->CacheLines = -1;
+    }
+
+    if (!tiled) {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to find a tileable pitch, "
+		   "falling back to untiled allocation.\n");
+	goto allocate_untiled;
+    }
+
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+	       "Attempting memory allocation with tiled buffers.\n");
+    if (pScrn->displayWidth != savedDisplayWidth) {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		   "Increasing the scanline pitch for tiled allocation "
+		   "(%d -> %d).\n",
+		   savedDisplayWidth, pScrn->displayWidth);
+    }
+
+    if (!i830_allocate_2d_memory(pScrn)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate tiled 2D "
+		   "objects.  Falling back to untiled allocation.\n");
+	goto allocate_untiled;
+    }
+    if (pI830->directRendering && !i830_allocate_3d_memory(pScrn)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate tiled 3D "
+		   "objects.  Falling back to untiled allocation.\n");
+	goto allocate_untiled;
+    }
+
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Tiled allocation successful.\n");
+    return TRUE;
+
+allocate_untiled:
+    pI830->tiling = FALSE;
+    pScrn->displayWidth = savedDisplayWidth;
+    if (pI830->allowPageFlip)
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		   "Couldn't allocate tiled memory, page flipping "
+		   "disabled\n");
+    pI830->allowPageFlip = FALSE;
+    if (pI830->fb_compression)
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		   "Couldn't allocate tiled memory, fb compression "
+		   "disabled\n");
+    pI830->fb_compression = FALSE;
+
+    if (!i830_allocate_2d_memory(pScrn)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate untiled 2D "
+		   "objects.  Disabling DRI.\n");
+	goto allocate_no_dri;
+    }
+    if (pI830->directRendering && !i830_allocate_3d_memory(pScrn)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Failed to allocate untiled 3D "
+		   "objects.  Disabling DRI.\n");
+	goto allocate_no_dri;
+    }
+
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Untiled allocation successful.\n");
+    return TRUE;
+
+allocate_no_dri:
+    i830_reset_allocations(pScrn);
+    pI830->directRendering = FALSE;
+
+    if (i830_allocate_2d_memory(pScrn))
+	return TRUE;
+
+    return FALSE;
+}
+
 static Bool
 I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
@@ -2366,8 +2498,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    VisualPtr visual;
    I830Ptr pI8301 = NULL;
    unsigned long sys_mem;
-   int i, c;
-   Bool allocation_done = FALSE;
+   int c;
    MessageType from;
 #ifdef XF86DRI
    xf86CrtcConfigPtr config;
@@ -2475,26 +2606,6 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    }
 #endif
 
-   /* Set up our video memory allocator for the chosen videoRam */
-   if (!i830_allocator_init(pScrn, 0, pScrn->videoRam * KB(1))) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		 "Couldn't initialize video memory allocator\n");
-      PreInitCleanup(pScrn);
-      return FALSE;
-   }
-
-   xf86DrvMsg(pScrn->scrnIndex,
-	      pI830->pEnt->device->videoRam ? X_CONFIG : X_DEFAULT,
-	      "VideoRam: %d KB\n", pScrn->videoRam);
-
-   if (xf86GetOptValInteger(pI830->Options, OPTION_CACHE_LINES,
-			    &(pI830->CacheLines))) {
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Requested %d cache lines\n",
-		 pI830->CacheLines);
-   } else {
-      pI830->CacheLines = -1;
-   }
-
    /* Enable tiling by default */
    pI830->tiling = TRUE;
 
@@ -2561,13 +2672,6 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    /* Need MMIO mapped to do GTT lookups during memory allocation. */
    I830MapMMIO(pScrn);
 
-#if defined(XF86DRI)
-   /*
-    * If DRI is potentially usable, check if there is enough memory available
-    * for it, and if there's also enough to allow tiling to be enabled.
-    */
-
-
 #ifdef I830_XV
     /*
      * Set this so that the overlay allocation is factored in when
@@ -2576,103 +2680,6 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     pI830->XvEnabled = !pI830->XvDisabled;
 #endif
 
-   if (pI830->directRendering) {
-      int savedDisplayWidth = pScrn->displayWidth;
-      Bool tiled = FALSE;
-
-      if (IS_I965G(pI830)) {
-	 int tile_pixels = 512 / pI830->cpp;
-	 pScrn->displayWidth = (pScrn->displayWidth + tile_pixels - 1) &
-	    ~(tile_pixels - 1);
-	 tiled = TRUE;
-      } else {
-	 /* Good pitches to allow tiling.  Don't care about pitches < 1024
-	  * pixels.
-	  */
-	 static const int pitches[] = {
-	    1024,
-	    2048,
-	    4096,
-	    8192,
-	    0
-	 };
-
-	 for (i = 0; pitches[i] != 0; i++) {
-	    if (pitches[i] >= pScrn->displayWidth) {
-	       pScrn->displayWidth = pitches[i];
-	       tiled = TRUE;
-	       break;
-	    }
-	 }
-      }
-
-      /* Attempt two rounds of allocation to get 2d and 3d memory to fit:
-       *
-       * 0: untiled
-       * 1: tiled
-       */
-
-#define MM_TURNS 2
-      for (i = 0; i < MM_TURNS; i++) {
-	 if (!tiled && i == 0)
-	    continue;
-
-	 if (i >= 1) {
-	    /* For further allocations, disable tiling */
-	    pI830->tiling = FALSE;
-	    pScrn->displayWidth = savedDisplayWidth;
-	    if (pI830->allowPageFlip)
-	       xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-			  "Couldn't allocate tiled memory, page flipping "
-			  "disabled\n");
-	    pI830->allowPageFlip = FALSE;
-	    if (pI830->fb_compression)
-	       xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-			  "Couldn't allocate tiled memory, fb compression "
-			  "disabled\n");
-	    pI830->fb_compression = FALSE;
-	 }
-
-	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-		    "Attempting memory allocation with %s buffers.\n",
-		    (i & 1) ? "untiled" : "tiled");
-
-	 if (i830_allocate_2d_memory(pScrn) &&
-	     i830_allocate_3d_memory(pScrn))
-	 {
-	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Success.\n");
-	    if (pScrn->displayWidth != savedDisplayWidth) {
-	       xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-			  "Increasing the scanline pitch to allow tiling mode "
-			  "(%d -> %d).\n",
-			  savedDisplayWidth, pScrn->displayWidth);
-	    }
-	    allocation_done = TRUE;
-	    break;
-	 }
-
-	 i830_reset_allocations(pScrn);
-      }
-
-      if (i == MM_TURNS) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		    "Not enough video memory.  Disabling DRI.\n");
-	 pI830->directRendering = FALSE;
-      }
-   }
-#endif
-
-   if (!allocation_done) {
-      if (!i830_allocate_2d_memory(pScrn)) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		    "Couldn't allocate video memory\n");
-	 return FALSE;
-      }
-      allocation_done = TRUE;
-   }
-
-   I830UnmapMMIO(pScrn);
-
    if (!IS_I965G(pI830) && pScrn->displayWidth > 2048) {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		 "Cannot support DRI with frame buffer width > 2048.\n");
@@ -2680,6 +2687,14 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       pI830->directRendering = FALSE;
    }
 
+   if (!i830_memory_init(pScrn)) {
+       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		  "Couldn't allocate video memory\n");
+       return FALSE;
+   }
+
+   I830UnmapMMIO(pScrn);
+
    i830_fixup_mtrrs(pScrn);
 
    pI830->starting = TRUE;
commit 0a02655b49f70288ed7fc87a72273bc871aa2a6b
Merge: 6f92200... c8a16fc...
Author: Jesse Barnes <jbarnes at nietzche.virtuousgeek.org>
Date:   Thu Dec 6 17:14:57 2007 -0800

    Merge git://people.freedesktop.org/~jbarnes/xf86-video-intel

diff --cc src/i830.h
index fe4d6c5,1a8e34f..2a627de
--- a/src/i830.h
+++ b/src/i830.h
@@@ -340,12 -340,22 +340,22 @@@ enum last_3d 
   */
  
  enum backlight_control {
 -    NATIVE = 0,
 -    LEGACY,
 -    COMBO,
 -    KERNEL,
 +    BCM_NATIVE = 0,
 +    BCM_LEGACY,
 +    BCM_COMBO,
 +    BCM_KERNEL,
  };
  
+ /*
+  * Already we have two too many accel methods.  None is equivalent to the
+  * noaccel case.
+  */
+ enum accel_method {
+     ACCEL_NONE = 0,
+     ACCEL_EXA,
+     ACCEL_XAA,
+ };
+ 
  typedef struct _I830Rec {
     unsigned char *MMIOBase;
     unsigned char *GTTBase;
commit c8a16fc73747744836359e695935ac1a74f300b7
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 18:30:13 2007 -0800

    Remove unused variables in EnterVT

diff --git a/src/i830_driver.c b/src/i830_driver.c
index eb26f1a..1418464 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3068,8 +3068,6 @@ I830EnterVT(int scrnIndex, int flags)
 {
    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
    I830Ptr  pI830 = I830PTR(pScrn);
-   xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
-   int o;
 
    DPRINTF(PFX, "Enter VT\n");
 
commit ab75ff4bd7d52f329af0816ee4f68f05ea9518b6
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 18:29:41 2007 -0800

    Move MTRR fixup to its own routine

diff --git a/src/i830_driver.c b/src/i830_driver.c
index bb616f4..eb26f1a 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2313,6 +2313,50 @@ I830BlockHandler(int i,
     I830VideoBlockHandler(i, blockData, pTimeout, pReadmask);
 }
 
+static void
+i830_fixup_mtrrs(ScrnInfoPtr pScrn)
+{
+#ifdef HAS_MTRR_SUPPORT
+    I830Ptr pI830 = I830PTR(pScrn);
+    int fd;
+    struct mtrr_gentry gentry;
+    struct mtrr_sentry sentry;
+
+    if ( ( fd = open ("/proc/mtrr", O_RDONLY, 0) ) != -1 ) {
+	for (gentry.regnum = 0; ioctl (fd, MTRRIOC_GET_ENTRY, &gentry) == 0;
+	     ++gentry.regnum) {
+
+	    if (gentry.size < 1) {
+		/* DISABLED */
+		continue;
+	    }
+
+	    /* Check the MTRR range is one we like and if not - remove it.
+	     * The Xserver common layer will then setup the right range
+	     * for us.
+	     */
+	    if (gentry.base == pI830->LinearAddr && 
+		gentry.size < pI830->FbMapSize) {
+
+		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+			   "Removing bad MTRR range (base 0x%lx, size 0x%x)\n",
+			   gentry.base, gentry.size);
+
+		sentry.base = gentry.base;
+		sentry.size = gentry.size;
+		sentry.type = gentry.type;
+
+		if (ioctl (fd, MTRRIOC_DEL_ENTRY, &sentry) == -1) {
+		    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			       "Failed to remove bad MTRR range\n");
+		}
+	    }
+	}
+	close(fd);
+    }
+#endif
+}
+
 static Bool
 I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
@@ -2636,44 +2680,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       pI830->directRendering = FALSE;
    }
 
-#ifdef HAS_MTRR_SUPPORT
-   int fd;
-   struct mtrr_gentry gentry;
-   struct mtrr_sentry sentry;
-
-   if ( ( fd = open ("/proc/mtrr", O_RDONLY, 0) ) != -1 ) {
-       for (gentry.regnum = 0; ioctl (fd, MTRRIOC_GET_ENTRY, &gentry) == 0;
-	    ++gentry.regnum) {
-
-	   if (gentry.size < 1) {
-	       /* DISABLED */
-	       continue;
-	   }
-
-	   /* Check the MTRR range is one we like and if not - remove it.
-	    * The Xserver common layer will then setup the right range
-	    * for us.
-	    */
-	   if (gentry.base == pI830->LinearAddr && 
-	       gentry.size < pI830->FbMapSize) {
-
-	       xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-			  "Removing bad MTRR range (base 0x%lx, size 0x%x)\n",
-			  gentry.base, gentry.size);
-
-	       sentry.base = gentry.base;
-	       sentry.size = gentry.size;
-	       sentry.type = gentry.type;
-
-	       if (ioctl (fd, MTRRIOC_DEL_ENTRY, &sentry) == -1) {
-		   xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-			      "Failed to remove bad MTRR range\n");
-	       }
-	   }
-       }
-       close(fd);
-   }
-#endif
+   i830_fixup_mtrrs(pScrn);
 
    pI830->starting = TRUE;
 
commit 4244677aa0878e4bc99c27904e0b36374b06d825
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 18:28:17 2007 -0800

    Cleanup DRI handling
    
    Remove the dual "directRenderingDisabled" & "directRenderingEnabled" fields,
    replacing them with a single "directRendering" one.  This cleans up much of the
    DRI checking logic.

diff --git a/src/i830.h b/src/i830.h
index 7f6b8f2..1a8e34f 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -515,8 +515,7 @@ typedef struct _I830Rec {
    CARD32 mapstate[6];
    CARD32 samplerstate[6];
 
-   Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
-   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+   Bool directRendering;
 
 #ifdef XF86DRI
    Bool directRenderingOpen;
diff --git a/src/i830_accel.c b/src/i830_accel.c
index 327401d..3e10778 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -136,7 +136,7 @@ I830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis)
 	     i830_dump_error_state(pScrn);
 	 ErrorF("space: %d wanted %d\n", ring->space, n);
 #ifdef XF86DRI
-	 if (pI830->directRenderingEnabled) {
+	 if (pI830->directRendering) {
 	    DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
 	    DRICloseScreen(screenInfo.screens[pScrn->scrnIndex]);
 	 }
@@ -176,7 +176,7 @@ I830Sync(ScrnInfoPtr pScrn)
 #ifdef XF86DRI
    /* VT switching tries to do this.
     */
-   if (!pI830->LockHeld && pI830->directRenderingEnabled) {
+   if (!pI830->LockHeld && pI830->directRendering) {
       return;
    }
 #endif
diff --git a/src/i830_display.c b/src/i830_display.c
index 0e42624..06bbd67 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -419,7 +419,7 @@ i830PipeSetBase(xf86CrtcPtr crtc, int x, int y)
     }
 
 #ifdef XF86DRI
-    if (pI830->directRenderingEnabled) {
+    if (pI830->directRendering) {
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 
 	if (!sPriv)
@@ -766,7 +766,7 @@ i830_crtc_dpms(xf86CrtcPtr crtc, int mode)
     intel_crtc->dpms_mode = mode;
 
 #ifdef XF86DRI
-    if (pI830->directRenderingEnabled) {
+    if (pI830->directRendering) {
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 	Bool enabled = crtc->enabled && mode != DPMSModeOff;
 
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 4c87ae2..9318669 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1748,7 +1748,7 @@ I830DRISetVBlankInterrupt (ScrnInfoPtr pScrn, Bool on)
     if (!pI830->want_vblank_interrupts)
 	on = FALSE;
 
-    if (pI830->directRenderingEnabled && pI830->drmMinor >= 5) {
+    if (pI830->directRendering && pI830->drmMinor >= 5) {
 	if (on) {
 	    if (xf86_config->num_crtc > 1 && xf86_config->crtc[1]->enabled)
 		if (pI830->drmMinor >= 6)
@@ -1774,7 +1774,7 @@ I830DRILock(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
-   if (pI830->directRenderingEnabled && !pI830->LockHeld) {
+   if (pI830->directRendering && !pI830->LockHeld) {
       DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
       pI830->LockHeld = 1;
       i830_refresh_ring(pScrn);
@@ -1791,7 +1791,7 @@ I830DRIUnlock(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
-   if (pI830->directRenderingEnabled && pI830->LockHeld) {
+   if (pI830->directRendering && pI830->LockHeld) {
       DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
       pI830->LockHeld = 0;
    }
diff --git a/src/i830_driver.c b/src/i830_driver.c
index c5e46ad..bb616f4 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1493,22 +1493,19 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
       pI830->SWCursor = TRUE;
    }
 
-   pI830->directRenderingDisabled =
-	!xf86ReturnOptValBool(pI830->Options, OPTION_DRI, TRUE);
+   /* Try to enable DRI unless explicitly disabled */
+   pI830->directRendering = xf86ReturnOptValBool(pI830->Options, OPTION_DRI,
+						 TRUE);
 
 #ifdef XF86DRI
-   if (!pI830->directRenderingDisabled) {
-       if ((pI830->accel_method == ACCEL_NONE) || pI830->SWCursor) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "
-		    "needs HW cursor and 2D acceleration.\n");
-	 pI830->directRenderingDisabled = TRUE;
-      } else if (pScrn->depth != 16 && pScrn->depth != 24) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "
-		    "runs only at depths 16 and 24.\n");
-	 pI830->directRenderingDisabled = TRUE;
-      }
-
-      if (!pI830->directRenderingDisabled) {
+   if (pI830->directRendering) {
+      if ((pI830->accel_method == ACCEL_NONE) || pI830->SWCursor ||
+	  ((pScrn->depth != 16) && (pScrn->depth != 24))) {
+	 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI disabled because it "
+		    "needs HW cursor, 2D acceleration and 16 or 24 bit "
+		    "color.\n");
+	 pI830->directRendering = FALSE;
+      } else {
 	 pI830->allocate_classic_textures = TRUE;
 
 	 from = X_PROBED;
@@ -1526,9 +1523,10 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 	 }
 #endif
       }
-   } 
-   
-#endif
+   }
+#else /* !XF86DRI */
+   pI830->directRendering = FALSE;
+#endif /* XF86DRI */
 
    I830PreInitDDC(pScrn);
    for (i = 0; i < num_pipe; i++) {
@@ -1594,7 +1592,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 
 #ifdef XF86DRI
    pI830->allowPageFlip = FALSE;
-   from = (!pI830->directRenderingDisabled &&
+   from = (pI830->directRendering &&
 	   xf86GetOptValBool(pI830->Options, OPTION_PAGEFLIP,
 			     &pI830->allowPageFlip)) ? X_CONFIG : X_DEFAULT;
 
@@ -1604,7 +1602,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 
 #ifdef XF86DRI
    pI830->TripleBuffer = FALSE;
-   from =  (!pI830->directRenderingDisabled &&
+   from =  (pI830->directRendering &&
 	    xf86GetOptValBool(pI830->Options, OPTION_TRIPLEBUFFER,
 			      &pI830->TripleBuffer)) ? X_CONFIG : X_DEFAULT;
 
@@ -1738,8 +1736,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 
 #if defined(XF86DRI)
    /* Load the dri module if requested. */
-   if (xf86ReturnOptValBool(pI830->Options, OPTION_DRI, FALSE) &&
-       !pI830->directRenderingDisabled) {
+   if (pI830->directRendering) {
       if (xf86LoadSubModule(pScrn, "dri")) {
 	 xf86LoaderReqSymLists(I810driSymbols, I810drmSymbols, NULL);
       }
@@ -2264,7 +2261,7 @@ IntelEmitInvarientState(ScrnInfoPtr pScrn)
       return;
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering) {
       drmI830Sarea *sarea = DRIGetSAREAPrivate(pScrn->pScreen);
 
       /* Mark that the X Server was the last holder of the context */
@@ -2425,20 +2422,13 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    }
 
 #ifdef XF86DRI
-   /* Check for appropriate bpp and module support to initialize DRI. */
-   if (!I830CheckDRIAvailable(pScrn)) {
-      pI830->directRenderingDisabled = TRUE;
+   /* Try to init DRI if it's enabled */
+   if (pI830->directRendering) {
+       if (I830CheckDRIAvailable(pScrn))
+	   pI830->directRendering = I830DRIScreenInit(pScreen);
+       else
+	   pI830->directRendering = FALSE;
    }
-
-   /* If DRI hasn't been explicitly disabled, try to initialize it.
-    * It will be used by the memory allocator.
-    */
-   if (!pI830->directRenderingDisabled)
-      pI830->directRenderingEnabled = I830DRIScreenInit(pScreen);
-   else
-      pI830->directRenderingEnabled = FALSE;
-#else
-   pI830->directRenderingEnabled = FALSE;
 #endif
 
    /* Set up our video memory allocator for the chosen videoRam */
@@ -2542,7 +2532,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     pI830->XvEnabled = !pI830->XvDisabled;
 #endif
 
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering) {
       int savedDisplayWidth = pScrn->displayWidth;
       Bool tiled = FALSE;
 
@@ -2623,7 +2613,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       if (i == MM_TURNS) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 		    "Not enough video memory.  Disabling DRI.\n");
-	 pI830->directRenderingEnabled = FALSE;
+	 pI830->directRendering = FALSE;
       }
    }
 #endif
@@ -2643,47 +2633,45 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		 "Cannot support DRI with frame buffer width > 2048.\n");
       pI830->tiling = FALSE;
-      pI830->directRenderingEnabled = FALSE;
+      pI830->directRendering = FALSE;
    }
 
 #ifdef HAS_MTRR_SUPPORT
-   {
-      int fd;
-      struct mtrr_gentry gentry;
-      struct mtrr_sentry sentry;
+   int fd;
+   struct mtrr_gentry gentry;
+   struct mtrr_sentry sentry;
 
-      if ( ( fd = open ("/proc/mtrr", O_RDONLY, 0) ) != -1 ) {
-         for (gentry.regnum = 0; ioctl (fd, MTRRIOC_GET_ENTRY, &gentry) == 0;
-	      ++gentry.regnum) {
+   if ( ( fd = open ("/proc/mtrr", O_RDONLY, 0) ) != -1 ) {
+       for (gentry.regnum = 0; ioctl (fd, MTRRIOC_GET_ENTRY, &gentry) == 0;
+	    ++gentry.regnum) {
 
-	    if (gentry.size < 1) {
+	   if (gentry.size < 1) {
 	       /* DISABLED */
 	       continue;
-	    }
+	   }
 
-            /* Check the MTRR range is one we like and if not - remove it.
-             * The Xserver common layer will then setup the right range
-             * for us.
-             */
-	    if (gentry.base == pI830->LinearAddr && 
-	        gentry.size < pI830->FbMapSize) {
-
-               xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-		  "Removing bad MTRR range (base 0x%lx, size 0x%x)\n",
-		  gentry.base, gentry.size);
-
-    	       sentry.base = gentry.base;
-               sentry.size = gentry.size;
-               sentry.type = gentry.type;
-
-               if (ioctl (fd, MTRRIOC_DEL_ENTRY, &sentry) == -1) {
-                  xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		     "Failed to remove bad MTRR range\n");
-               }
-	    }
-         }
-         close(fd);
-      }
+	   /* Check the MTRR range is one we like and if not - remove it.
+	    * The Xserver common layer will then setup the right range
+	    * for us.
+	    */
+	   if (gentry.base == pI830->LinearAddr && 
+	       gentry.size < pI830->FbMapSize) {
+
+	       xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+			  "Removing bad MTRR range (base 0x%lx, size 0x%x)\n",
+			  gentry.base, gentry.size);
+
+	       sentry.base = gentry.base;
+	       sentry.size = gentry.size;
+	       sentry.type = gentry.type;
+
+	       if (ioctl (fd, MTRRIOC_DEL_ENTRY, &sentry) == -1) {
+		   xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			      "Failed to remove bad MTRR range\n");
+	       }
+	   }
+       }
+       close(fd);
    }
 #endif
 
@@ -2747,20 +2735,20 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     * InitGLXVisuals call back.
     */
 
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering) {
       if ((pI830->accel_method == ACCEL_NONE) || pI830->SWCursor ||
 	  (pI830->StolenOnly && I830IsPrimary(pScrn))) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "DRI is disabled because it "
 		    "needs HW cursor, 2D accel and AGPGART.\n");
-	 pI830->directRenderingEnabled = FALSE;
+	 pI830->directRendering = FALSE;
       }
    }
 
-   if (pI830->directRenderingEnabled)
-      pI830->directRenderingEnabled = I830DRIDoMappings(pScreen);
+   if (pI830->directRendering)
+      pI830->directRendering = I830DRIDoMappings(pScreen);
 
    /* If we failed for any reason, free DRI memory. */
-   if (!pI830->directRenderingEnabled)
+   if (!pI830->directRendering)
       i830_free_3d_memory(pScrn);
 
    config = XF86_CRTC_CONFIG_PTR(pScrn);
@@ -2773,8 +2761,8 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     * Also make sure the DRM can handle the swap.
     */
    if (I830LVDSPresent(pScrn) && !IS_I965GM(pI830) &&
-       (!pI830->directRenderingEnabled ||
-	(pI830->directRenderingEnabled && pI830->drmMinor >= 10))) {
+       (!pI830->directRendering ||
+	(pI830->directRendering && pI830->drmMinor >= 10))) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "adjusting plane->pipe mappings "
 		  "to allow for framebuffer compression\n");
        for (c = 0; c < config->num_crtc; c++) {
@@ -2789,7 +2777,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    }
 
 #else
-   pI830->directRenderingEnabled = FALSE;
+   pI830->directRendering = FALSE;
 #endif
 
 #ifdef XF86DRI
@@ -2894,8 +2882,8 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    /* Must be called before EnterVT, so we can acquire the DRI lock when
     * binding our memory.
     */
-   if (pI830->directRenderingEnabled)
-      pI830->directRenderingEnabled = I830DRIFinishScreenInit(pScreen);
+   if (pI830->directRendering)
+      pI830->directRendering = I830DRIFinishScreenInit(pScreen);
 #endif
 
    if (!I830EnterVT(scrnIndex, 0))
@@ -2924,14 +2912,11 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    IntelEmitInvarientState(pScrn);
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering) {
       pI830->directRenderingOpen = TRUE;
       xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Enabled\n");
    } else {
-      if (pI830->directRenderingDisabled)
-	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Disabled\n");
-      else
-	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Failed\n");
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Disabled\n");
    }
 #else
    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Not available\n");
@@ -3093,7 +3078,7 @@ I830EnterVT(int scrnIndex, int flags)
    pI830->leaving = FALSE;
 
 #ifdef XF86DRI_MM
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering) {
       /* Unlock the memory manager first of all so that we can pin our
        * buffer objects
        */
@@ -3137,7 +3122,7 @@ I830EnterVT(int scrnIndex, int flags)
    SetHWOperatingState(pScrn);
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering) {
       /* Update buffer offsets in sarea and mappings, since buffer offsets
        * may have changed.
        */
@@ -3208,7 +3193,7 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
    if (pScrn->vtSema == TRUE) {
       I830LeaveVT(scrnIndex, 0);
 #ifdef XF86DRI_MM
-      if (pI830->directRenderingEnabled) {
+      if (pI830->directRendering) {
  	 if (pI830->memory_manager != NULL) {
 	    drmMMUnlock(pI830->drmSubFD, DRM_BO_MEM_TT, 1);
 	 }
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 38fecba..8b769bd 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -435,7 +435,7 @@ i830_allocator_init(ScrnInfoPtr pScrn, unsigned long offset, unsigned long size)
      * 5.4 or newer so we can rely on the lock being held after DRIScreenInit,
      * rather than after DRIFinishScreenInit.
      */
-    if (pI830->directRenderingEnabled && pI830->drmMinor >= 7 &&
+    if (pI830->directRendering && pI830->drmMinor >= 7 &&
 	(dri_major > 5 || (dri_major == 5 && dri_minor >= 4)))
     {
 	int mmsize;
commit 9bf6d258b1b54c965b72e747f5c810a6f807cf70
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 17:47:28 2007 -0800

    Correct accel_method & tiling handling
    
    Tiling depends on accel_method, and it was wrong, so fix it up.  All
    combinations should be properly supported now (though tiling is disabled in
    every case except for the accel_method == ACCEL_EXA one).

diff --git a/src/i830.h b/src/i830.h
index 739f9c6..7f6b8f2 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -814,15 +814,8 @@ static inline int i830_fb_compression_supported(I830Ptr pI830)
 	return FALSE;
     if (IS_I810(pI830) || IS_I815(pI830) || IS_I830(pI830))
 	return FALSE;
-    /* fbc depends on tiled surface. And we don't support tiled
-     * front buffer with XAA now.
-     */
     if (!pI830->tiling)
 	return FALSE;
-    if (IS_I965G(pI830))
-	return FALSE;
-    if (!(pI830->accel_method == ACCEL_EXA))
-	return FALSE;
     return TRUE;
 }
 
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 9deb04c..c5e46ad 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1223,7 +1223,7 @@ static enum accel_method
 i830_get_accel_method(ScrnInfoPtr pScrn)
 {
     I830Ptr pI830 = I830PTR(pScrn);
-    enum accel_method method;
+    enum accel_method method = ACCEL_NONE;
     char *s;
 
     /*
@@ -1247,9 +1247,9 @@ i830_get_accel_method(ScrnInfoPtr pScrn)
 #if defined(I830_USE_XAA) && defined(I830_USE_EXA)
     if ((s = (char *)xf86GetOptValString(pI830->Options, OPTION_ACCELMETHOD))) {
 	if (!xf86NameCmp(s, "EXA"))
-	    pI830->accel_method = ACCEL_EXA;
+	    method = ACCEL_EXA;
 	else if (!xf86NameCmp(s, "XAA"))
-	    pI830->accel_method = ACCEL_XAA;
+	    method = ACCEL_XAA;
     }
 #endif
 
@@ -1257,6 +1257,21 @@ i830_get_accel_method(ScrnInfoPtr pScrn)
     if (xf86ReturnOptValBool(pI830->Options, OPTION_NOACCEL, FALSE))
 	method = ACCEL_NONE;
 
+    switch (method) {
+    case ACCEL_EXA:
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using EXA for acceleration\n");
+	break;
+    case ACCEL_XAA:
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using XAA for acceleration\n");
+	break;
+    case ACCEL_NONE:
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "disabling acceleration\n");
+	break;
+    default:
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "unknown acceleration method\n");
+	break;
+    }
+
     return method;
 }
 
@@ -1677,7 +1692,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 #endif
 
 #ifdef I830_USE_EXA
-   if (pI830->accel_method == ACCEL_XAA) {
+   if (pI830->accel_method == ACCEL_EXA) {
       XF86ModReqInfo req;
       int errmaj, errmin;
 
@@ -2457,6 +2472,13 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	   pI830->tiling = FALSE;
    }
 
+   /* Tiling only works with EXA, so disable it if needed */
+   if (pI830->tiling == TRUE && (pI830->accel_method != ACCEL_EXA)) {
+       xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Disabling tiling, only "
+		  "supported with EXA\n");
+       pI830->tiling = FALSE;
+   }
+
    /* Enable FB compression if possible */
    if (i830_fb_compression_supported(pI830) && !IS_I965GM(pI830))
        pI830->fb_compression = TRUE;
commit 32baa94741296e406d0a529d3678ba01633d4753
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 17:31:07 2007 -0800

    Cleanup acceleration method handling
    
    Move accel method checking into its own routine and use an enum for it rather
    than the current mess of useEXA vs noAccel.  Move the basic resource detection
    into i830_detect_chipset.

diff --git a/src/i830.h b/src/i830.h
index 2c1ac86..739f9c6 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -346,6 +346,16 @@ enum backlight_control {
     KERNEL,
 };
 
+/*
+ * Already we have two too many accel methods.  None is equivalent to the
+ * noaccel case.
+ */
+enum accel_method {
+    ACCEL_NONE = 0,
+    ACCEL_EXA,
+    ACCEL_XAA,
+};
+
 typedef struct _I830Rec {
    unsigned char *MMIOBase;
    unsigned char *GTTBase;
@@ -458,8 +468,7 @@ typedef struct _I830Rec {
 
    Bool fence_used[FENCE_NEW_NR];
 
-   Bool useEXA;
-   Bool noAccel;
+   enum accel_method accel_method;
    Bool SWCursor;
 #ifdef I830_USE_XAA
    XAAInfoRecPtr AccelInfoRec;
@@ -808,7 +817,11 @@ static inline int i830_fb_compression_supported(I830Ptr pI830)
     /* fbc depends on tiled surface. And we don't support tiled
      * front buffer with XAA now.
      */
-    if (!pI830->tiling || (IS_I965G(pI830) && !pI830->useEXA))
+    if (!pI830->tiling)
+	return FALSE;
+    if (IS_I965G(pI830))
+	return FALSE;
+    if (!(pI830->accel_method == ACCEL_EXA))
 	return FALSE;
     return TRUE;
 }
diff --git a/src/i830_accel.c b/src/i830_accel.c
index 7501c2b..327401d 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -68,7 +68,7 @@ intel_get_pixmap_offset(PixmapPtr pPix)
     I830Ptr pI830 = I830PTR(pScrn);
 
 #ifdef I830_USE_EXA
-    if (pI830->useEXA)
+    if (pI830->accel_method == ACCEL_EXA)
 	return exaGetPixmapOffset(pPix);
 #endif
     return (unsigned long)pPix->devPrivate.ptr - (unsigned long)pI830->FbBase;
@@ -82,7 +82,7 @@ intel_get_pixmap_pitch(PixmapPtr pPix)
     I830Ptr pI830 = I830PTR(pScrn);
 
 #ifdef I830_USE_EXA
-    if (pI830->useEXA)
+    if (pI830->accel_method == ACCEL_EXA)
 	return exaGetPixmapPitch(pPix);
 #endif
 #ifdef I830_USE_XAA
@@ -260,11 +260,12 @@ I830AccelInit(ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     I830Ptr pI830 = I830PTR(pScrn);
 
-    if (pI830->useEXA)
+    if (pI830->accel_method == ACCEL_EXA)
 	return I830EXAInit(pScreen);
 #endif
 #ifdef I830_USE_XAA
-    return I830XAAInit(pScreen);
+    if (pI830->accel_method == ACCEL_XAA)
+	return I830XAAInit(pScreen);
 #endif
     return FALSE;
 }
diff --git a/src/i830_dri.c b/src/i830_dri.c
index f52a7c3..4c87ae2 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -594,8 +594,8 @@ I830DRIScreenInit(ScreenPtr pScreen)
 
 #if DRIINFO_MAJOR_VERSION > 5 || \
     (DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 3)
-      if (pI830->useEXA)
-	 pDRIInfo->texOffsetStart = I830TexOffsetStart;
+   if (pI830->accel_method == ACCEL_EXA)
+       pDRIInfo->texOffsetStart = I830TexOffsetStart;
 #endif
 
 #if DRI_SUPPORTS_CLIP_NOTIFY
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 60792f2..9deb04c 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1019,13 +1019,14 @@ i830SetHotkeyControl(ScrnInfoPtr pScrn, int mode)
    pI830->writeControl(pI830, GRX, 0x18, gr18);
 }
 
-static void
+static Bool
 i830_detect_chipset(ScrnInfoPtr pScrn)
 {
     I830Ptr pI830 = I830PTR(pScrn);
     MessageType from = X_PROBED;
     const char *chipname;
     uint32_t capid;
+    int fb_bar, mmio_bar;
 
     switch (DEVICE_ID(pI830->PciInfo)) {
     case PCI_CHIP_I830_M:
@@ -1139,6 +1140,124 @@ i830_detect_chipset(ScrnInfoPtr pScrn)
 
     xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n",
 	       (pScrn->chipset != NULL) ? pScrn->chipset : "Unknown i8xx");
+
+    /* Now that we know the chipset, figure out the resource base addrs */
+    if (IS_I9XX(pI830)) {
+	fb_bar = 2;
+	mmio_bar = 0;
+    } else {
+	fb_bar = 0;
+	mmio_bar = 1;
+    }
+
+    if (pI830->pEnt->device->MemBase != 0) {
+	pI830->LinearAddr = pI830->pEnt->device->MemBase;
+	from = X_CONFIG;
+    } else {
+	pI830->LinearAddr = I810_MEMBASE (pI830->PciInfo, fb_bar);
+	if (pI830->LinearAddr == 0) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		       "No valid FB address in PCI config space\n");
+	    PreInitCleanup(pScrn);
+	    return FALSE;
+	}
+    }
+
+    xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
+	       (unsigned long)pI830->LinearAddr);
+
+    if (pI830->pEnt->device->IOBase != 0) {
+	pI830->MMIOAddr = pI830->pEnt->device->IOBase;
+	from = X_CONFIG;
+    } else {
+	pI830->MMIOAddr = I810_MEMBASE (pI830->PciInfo, mmio_bar);
+	if (pI830->MMIOAddr == 0) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		       "No valid MMIO address in PCI config space\n");
+	    PreInitCleanup(pScrn);
+	    return FALSE;
+	}
+    }
+
+    xf86DrvMsg(pScrn->scrnIndex, from, "IO registers at addr 0x%lX\n",
+	       (unsigned long)pI830->MMIOAddr);
+
+    /* Now figure out mapsize on 8xx chips */
+    if (IS_I830(pI830) || IS_845G(pI830)) {
+#if XSERVER_LIBPCIACCESS
+	uint16_t		gmch_ctrl;
+	struct pci_device *bridge;
+
+	bridge = intel_host_bridge ();
+	pci_device_cfg_read_u16 (bridge, &gmch_ctrl, I830_GMCH_CTRL);
+#else
+	PCITAG bridge;
+	CARD16 gmch_ctrl;
+
+	bridge = pciTag(0, 0, 0);		/* This is always the host bridge */
+	gmch_ctrl = pciReadWord(bridge, I830_GMCH_CTRL);
+#endif
+	if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
+	    pI830->FbMapSize = 0x8000000;
+	} else {
+	    pI830->FbMapSize = 0x4000000; /* 64MB - has this been tested ?? */
+	}
+    } else {
+	if (IS_I9XX(pI830)) {
+#if XSERVER_LIBPCIACCESS
+	    pI830->FbMapSize = pI830->PciInfo->regions[fb_bar].size;
+#else
+	    pI830->FbMapSize = 1UL << pciGetBaseSize(pI830->PciTag, 2, TRUE,
+						     NULL);
+#endif
+	} else {
+	    /* 128MB aperture for later i8xx series. */
+	    pI830->FbMapSize = 0x8000000;
+	}
+    }
+
+    return TRUE;
+}
+
+static enum accel_method
+i830_get_accel_method(ScrnInfoPtr pScrn)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    enum accel_method method;
+    char *s;
+
+    /*
+     * The ugliness below:
+     * If either XAA or EXA (exclusive) is compiled in, default to it.
+     * 
+     * If both are compiled in, and the user didn't specify noAccel, use the
+     * config option AccelMethod to determine which to use, defaulting to EXA
+     * if none is specified, or if the string was unrecognized.
+     *
+     * All this *could* go away if we removed XAA support from this driver,
+     * for example. :)
+     */
+
+#ifdef I830_USE_EXA
+    method = ACCEL_EXA;
+#else
+    method = ACCEL_XAA;
+#endif
+
+#if defined(I830_USE_XAA) && defined(I830_USE_EXA)
+    if ((s = (char *)xf86GetOptValString(pI830->Options, OPTION_ACCELMETHOD))) {
+	if (!xf86NameCmp(s, "EXA"))
+	    pI830->accel_method = ACCEL_EXA;
+	else if (!xf86NameCmp(s, "XAA"))
+	    pI830->accel_method = ACCEL_XAA;
+    }
+#endif
+
+    /* Noaccel overrides everything */
+    if (xf86ReturnOptValBool(pI830->Options, OPTION_NOACCEL, FALSE))
+	method = ACCEL_NONE;
+
+    return method;
 }
 
 /**
@@ -1160,11 +1279,9 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    I830EntPtr pI830Ent = NULL;					
    int flags24;
    int i;
-   char *s;
    pointer pVBEModule = NULL;
    int num_pipe;
    int max_width, max_height;
-   int fb_bar, mmio_bar;
 
    if (pScrn->numEntities != 1)
       return FALSE;
@@ -1301,47 +1418,8 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    /* We have to use PIO to probe, because we haven't mapped yet. */
    I830SetPIOAccess(pI830);
 
-   i830_detect_chipset(pScrn);
-
-   if (IS_I9XX(pI830)) {
-      fb_bar = 2;
-      mmio_bar = 0;
-   } else {
-      fb_bar = 0;
-      mmio_bar = 1;
-   }
-
-   if (pI830->pEnt->device->MemBase != 0) {
-      pI830->LinearAddr = pI830->pEnt->device->MemBase;
-      from = X_CONFIG;
-   } else {
-      pI830->LinearAddr = I810_MEMBASE (pI830->PciInfo, fb_bar);
-      if (pI830->LinearAddr == 0) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		    "No valid FB address in PCI config space\n");
-	 PreInitCleanup(pScrn);
-	 return FALSE;
-      }
-   }
-
-   xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
-	      (unsigned long)pI830->LinearAddr);
-
-   if (pI830->pEnt->device->IOBase != 0) {
-      pI830->MMIOAddr = pI830->pEnt->device->IOBase;
-      from = X_CONFIG;
-   } else {
-      pI830->MMIOAddr = I810_MEMBASE (pI830->PciInfo, mmio_bar);
-      if (pI830->MMIOAddr == 0) {
-	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		    "No valid MMIO address in PCI config space\n");
-	 PreInitCleanup(pScrn);
-	 return FALSE;
-      }
-   }
-
-   xf86DrvMsg(pScrn->scrnIndex, from, "IO registers at addr 0x%lX\n",
-	      (unsigned long)pI830->MMIOAddr);
+   if (!i830_detect_chipset(pScrn))
+       return FALSE;
 
    /* check quirks */
    i830_fixup_devices(pScrn);
@@ -1361,39 +1439,6 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    }
    xf86CrtcSetSizeRange (pScrn, 320, 200, max_width, max_height);
 
-   if (IS_I830(pI830) || IS_845G(pI830)) {
-#if XSERVER_LIBPCIACCESS
-      uint16_t		gmch_ctrl;
-      struct pci_device *bridge;
-
-      bridge = intel_host_bridge ();
-      pci_device_cfg_read_u16 (bridge, &gmch_ctrl, I830_GMCH_CTRL);
-#else
-      PCITAG bridge;
-      CARD16 gmch_ctrl;
-
-      bridge = pciTag(0, 0, 0);		/* This is always the host bridge */
-      gmch_ctrl = pciReadWord(bridge, I830_GMCH_CTRL);
-#endif
-      if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
-	 pI830->FbMapSize = 0x8000000;
-      } else {
-	 pI830->FbMapSize = 0x4000000; /* 64MB - has this been tested ?? */
-      }
-   } else {
-      if (IS_I9XX(pI830)) {
-#if XSERVER_LIBPCIACCESS
-	 pI830->FbMapSize = pI830->PciInfo->regions[fb_bar].size;
-#else
-	 pI830->FbMapSize = 1UL << pciGetBaseSize(pI830->PciTag, 2, TRUE,
-						  NULL);
-#endif
-      } else {
-	 /* 128MB aperture for later i8xx series. */
-	 pI830->FbMapSize = 0x8000000;
-      }
-   }
-
    /* Some of the probing needs MMIO access, so map it here. */
    I830MapMMIO(pScrn);
 
@@ -1427,44 +1472,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%d display pipe%s available.\n",
 	      num_pipe, num_pipe > 1 ? "s" : "");
 
-   if (xf86ReturnOptValBool(pI830->Options, OPTION_NOACCEL, FALSE)) {
-      pI830->noAccel = TRUE;
-   }
-
-   /*
-    * The ugliness below:
-    * If either XAA or EXA (exclusive) is compiled in, default to it.
-    * 
-    * If both are compiled in, and the user didn't specify noAccel, use the
-    * config option AccelMethod to determine which to use, defaulting to EXA
-    * if none is specified, or if the string was unrecognized.
-    *
-    * All this *could* go away if we removed XAA support from this driver,
-    * for example. :)
-    */
-   if (!pI830->noAccel) {
-#ifdef I830_USE_EXA
-       pI830->useEXA = TRUE;
-#else
-       pI830->useEXA = FALSE;
-#endif
-#if defined(I830_USE_XAA) && defined(I830_USE_EXA)
-       int from = X_DEFAULT;
-       if ((s = (char *)xf86GetOptValString(pI830->Options,
-					    OPTION_ACCELMETHOD))) {
-	   if (!xf86NameCmp(s, "EXA")) {
-	       from = X_CONFIG;
-	       pI830->useEXA = TRUE;
-	   }
-	   else if (!xf86NameCmp(s, "XAA")) {
-	       from = X_CONFIG;
-	       pI830->useEXA = FALSE;
-	   }
-       }
-#endif
-       xf86DrvMsg(pScrn->scrnIndex, from, "Using %s for acceleration\n",
-		  pI830->useEXA ? "EXA" : "XAA");
-   }
+   pI830->accel_method =  i830_get_accel_method(pScrn);
 
    if (xf86ReturnOptValBool(pI830->Options, OPTION_SW_CURSOR, FALSE)) {
       pI830->SWCursor = TRUE;
@@ -1475,7 +1483,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 
 #ifdef XF86DRI
    if (!pI830->directRenderingDisabled) {
-      if (pI830->noAccel || pI830->SWCursor) {
+       if ((pI830->accel_method == ACCEL_NONE) || pI830->SWCursor) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "
 		    "needs HW cursor and 2D acceleration.\n");
 	 pI830->directRenderingDisabled = TRUE;
@@ -1638,7 +1646,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 
    if (!IS_I965G(pI830) && pScrn->virtualY > 2048) {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot support > 2048 vertical lines. disabling acceleration.\n");
-      pI830->noAccel = TRUE;
+      pI830->accel_method = ACCEL_NONE;
    }
 
    /* Don't need MMIO access anymore. */
@@ -1659,7 +1667,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    xf86LoaderReqSymLists(I810fbSymbols, NULL);
 
 #ifdef I830_USE_XAA
-   if (!pI830->noAccel && !pI830->useEXA) {
+   if (pI830->accel_method == ACCEL_XAA) {
       if (!xf86LoadSubModule(pScrn, "xaa")) {
 	 PreInitCleanup(pScrn);
 	 return FALSE;
@@ -1669,7 +1677,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 #endif
 
 #ifdef I830_USE_EXA
-   if (!pI830->noAccel && pI830->useEXA) {
+   if (pI830->accel_method == ACCEL_XAA) {
       XF86ModReqInfo req;
       int errmaj, errmin;
 
@@ -1747,20 +1755,22 @@ i830_stop_ring(ScrnInfoPtr pScrn, Bool flush)
    if (pI830->entityPrivate)
       pI830->entityPrivate->RingRunning = 0;
 
-   /* Flush the ring buffer (if enabled), then disable it. */
-   if (!pI830->noAccel) {
-      temp = INREG(LP_RING + RING_LEN);
-      if (temp & RING_VALID) {
-	 i830_refresh_ring(pScrn);
-	 I830Sync(pScrn);
-	 DO_RING_IDLE();
-      }
+   /* In the ACCEL_NONE case we don't have a ring buffer */
+   if (pI830->accel_method == ACCEL_NONE)
+       return;
 
-      OUTREG(LP_RING + RING_LEN, 0);
-      OUTREG(LP_RING + RING_HEAD, 0);
-      OUTREG(LP_RING + RING_TAIL, 0);
-      OUTREG(LP_RING + RING_START, 0);
+   /* Flush the ring buffer (if enabled), then disable it. */
+   temp = INREG(LP_RING + RING_LEN);
+   if (temp & RING_VALID) {
+       i830_refresh_ring(pScrn);
+       I830Sync(pScrn);
+       DO_RING_IDLE();
    }
+
+   OUTREG(LP_RING + RING_LEN, 0);
+   OUTREG(LP_RING + RING_HEAD, 0);
+   OUTREG(LP_RING + RING_TAIL, 0);
+   OUTREG(LP_RING + RING_START, 0);
 }
 
 static void
@@ -1770,8 +1780,9 @@ i830_start_ring(ScrnInfoPtr pScrn)
    unsigned int itemp;
 
    DPRINTF(PFX, "SetRingRegs\n");
-
-   if (pI830->noAccel)
+   
+   /* In the ACCEL_NONE case we don't have a ring buffer */
+   if (pI830->accel_method == ACCEL_NONE)
       return;
 
    if (!I830IsPrimary(pScrn)) return;
@@ -2234,7 +2245,7 @@ IntelEmitInvarientState(ScrnInfoPtr pScrn)
    I830Ptr pI830 = I830PTR(pScrn);
    CARD32 ctx_addr;
 
-   if (pI830->noAccel)
+   if (pI830->accel_method == ACCEL_NONE)
       return;
 
 #ifdef XF86DRI
@@ -2668,12 +2679,11 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    pI830->XvEnabled = !pI830->XvDisabled;
    if (pI830->XvEnabled) {
       if (!I830IsPrimary(pScrn)) {
-         if (!pI8301->XvEnabled || pI830->noAccel) {
+	 if (!pI8301->XvEnabled || (pI830->accel_method == ACCEL_NONE)) {
             pI830->XvEnabled = FALSE;
 	    xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Xv is disabled.\n");
          }
-      } else
-      if (pI830->noAccel || pI830->StolenOnly) {
+      } else if ((pI830->accel_method == ACCEL_NONE) || pI830->StolenOnly) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Xv is disabled because it "
 		    "needs 2D accel and AGPGART.\n");
 	 pI830->XvEnabled = FALSE;
@@ -2683,18 +2693,18 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    pI830->XvEnabled = FALSE;
 #endif
 
-   if (!pI830->noAccel) {
+   if (!(pI830->accel_method == ACCEL_NONE)) {
       if (pI830->LpRing->mem->size == 0) {
 	  xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 		     "Disabling acceleration because the ring buffer "
 		      "allocation failed.\n");
-	   pI830->noAccel = TRUE;
+	  pI830->accel_method = ACCEL_NONE;
       }
    }
 
 #ifdef I830_XV
    if (pI830->XvEnabled) {
-      if (pI830->noAccel) {
+      if (pI830->accel_method == ACCEL_NONE) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Disabling Xv because it "
 		    "needs 2D acceleration.\n");
 	 pI830->XvEnabled = FALSE;
@@ -2716,7 +2726,8 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     */
 
    if (pI830->directRenderingEnabled) {
-      if (pI830->noAccel || pI830->SWCursor || (pI830->StolenOnly && I830IsPrimary(pScrn))) {
+      if ((pI830->accel_method == ACCEL_NONE) || pI830->SWCursor ||
+	  (pI830->StolenOnly && I830IsPrimary(pScrn))) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "DRI is disabled because it "
 		    "needs HW cursor, 2D accel and AGPGART.\n");
 	 pI830->directRenderingEnabled = FALSE;
@@ -2788,7 +2799,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
    DPRINTF(PFX, "assert( if(!I830EnterVT(scrnIndex, 0)) )\n");
 
-   if (!pI830->useEXA) {
+   if (!(pI830->accel_method == ACCEL_EXA)) {
       if (I830IsPrimary(pScrn)) {
 	 if (!I830InitFBManager(pScreen, &(pI830->FbMemBox))) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
@@ -2836,10 +2847,11 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    DPRINTF(PFX,
 	   "assert( if(!I830InitFBManager(pScreen, &(pI830->FbMemBox))) )\n");
 
-   if (!pI830->noAccel) {
+   if (!(pI830->accel_method == ACCEL_NONE)) {
       if (!I830AccelInit(pScreen)) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		    "Hardware acceleration initialization failed\n");
+		    "Hardware acceleration initialization failed, disabling.\n");
+	 pI830->accel_method = ACCEL_NONE;
       }
    }
 
@@ -3204,7 +3216,7 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
    }
 #endif
 #ifdef I830_USE_EXA
-   if (pI830->useEXA && pI830->EXADriverPtr) {
+   if ((pI830->accel_method == ACCEL_EXA) && pI830->EXADriverPtr) {
        exaDriverFini(pScreen);
        xfree(pI830->EXADriverPtr);
        pI830->EXADriverPtr = NULL;
@@ -3419,14 +3431,14 @@ i830WaitSync(ScrnInfoPtr pScrn)
    I830Ptr pI830 = I830PTR(pScrn);
 
 #ifdef I830_USE_XAA
-   if (!pI830->noAccel && !pI830->useEXA && pI830->AccelInfoRec 
-	&& pI830->AccelInfoRec->NeedToSync) {
+   if ((pI830->accel_method == ACCEL_XAA) && pI830->AccelInfoRec 
+       && pI830->AccelInfoRec->NeedToSync) {
       (*pI830->AccelInfoRec->Sync)(pScrn);
       pI830->AccelInfoRec->NeedToSync = FALSE;
    }
 #endif
 #ifdef I830_USE_EXA
-   if (!pI830->noAccel && pI830->useEXA && pI830->EXADriverPtr) {
+   if ((pI830->accel_method == ACCEL_EXA) && pI830->EXADriverPtr) {
 	ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
 	exaWaitSync(pScreen);
    }
@@ -3439,11 +3451,11 @@ i830MarkSync(ScrnInfoPtr pScrn)
    I830Ptr pI830 = I830PTR(pScrn);
 
 #ifdef I830_USE_XAA
-   if (!pI830->useEXA && pI830->AccelInfoRec)
+   if ((pI830->accel_method == ACCEL_XAA) && pI830->AccelInfoRec)
       pI830->AccelInfoRec->NeedToSync = TRUE;
 #endif
 #ifdef I830_USE_EXA
-   if (pI830->useEXA && pI830->EXADriverPtr) {
+   if ((pI830->accel_method == ACCEL_EXA) && pI830->EXADriverPtr) {
       ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
       exaMarkSync(pScreen);
    }
diff --git a/src/i830_exa.c b/src/i830_exa.c
index 32c55dd..5612956 100644
--- a/src/i830_exa.c
+++ b/src/i830_exa.c
@@ -461,10 +461,9 @@ I830EXAInit(ScreenPtr pScreen)
     I830Ptr pI830 = I830PTR(pScrn);
 
     pI830->EXADriverPtr = exaDriverAlloc();
-    if (pI830->EXADriverPtr == NULL) {
-	pI830->noAccel = TRUE;
+    if (pI830->EXADriverPtr == NULL)
 	return FALSE;
-    }
+
     memset(pI830->EXADriverPtr, 0, sizeof(*pI830->EXADriverPtr));
 
     pI830->bufferOffset = 0;
@@ -594,7 +593,6 @@ I830EXAInit(ScreenPtr pScreen)
 	pI830->EXADriverPtr->exa_minor = 0;
 	if(!exaDriverInit(pScreen, pI830->EXADriverPtr)) {
 	    xfree(pI830->EXADriverPtr);
-	    pI830->noAccel = TRUE;
 	    return FALSE;
 	}
     }
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 85b6528..38fecba 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -446,7 +446,7 @@ i830_allocator_init(ScrnInfoPtr pScrn, unsigned long offset, unsigned long size)
 	mmsize = size;
 
 	/* EXA area is fixed. */
-	if (pI830->useEXA) {
+	if (pI830->accel_method == ACCEL_EXA) {
 	    mmsize -= ROUND_TO_PAGE(3 * pScrn->displayWidth * pI830->cpp *
 				    pScrn->virtualY);
 	}
@@ -997,7 +997,7 @@ i830_allocate_ringbuffer(ScrnInfoPtr pScrn)
 {
     I830Ptr pI830 = I830PTR(pScrn);
 
-    if (pI830->noAccel || pI830->LpRing->mem != NULL)
+    if ((pI830->accel_method == ACCEL_NONE) || pI830->LpRing->mem != NULL)
 	return TRUE;
 
     /* We don't have any mechanism in the DRM yet to alert it that we've moved
@@ -1141,7 +1141,7 @@ i830_allocate_framebuffer(ScrnInfoPtr pScrn, I830Ptr pI830, BoxPtr FbMemBox,
     minspace = pitch * pScrn->virtualY;
     avail = pScrn->videoRam * 1024;
 
-    if (!pI830->useEXA) {
+    if (!(pI830->accel_method == ACCEL_EXA)) {
 	maxCacheLines = (avail - minspace) / pitch;
 	/* This shouldn't happen. */
 	if (maxCacheLines < 0) {
@@ -1187,7 +1187,7 @@ i830_allocate_framebuffer(ScrnInfoPtr pScrn, I830Ptr pI830, BoxPtr FbMemBox,
      * acceleration operations (non-XY COLOR_BLT) can't be done to tiled
      * buffers.
      */
-    if (!pI830->useEXA && IS_I965G(pI830))
+    if ((pI830->accel_method != ACCEL_EXA) && IS_I965G(pI830))
 	tiling = FALSE;
     else
 	tiling = pI830->tiling;
@@ -1366,7 +1366,8 @@ i830_allocate_2d_memory(ScrnInfoPtr pScrn)
     }
 
     /* even in XAA, 965G needs state mem buffer for rendering */
-    if (IS_I965G(pI830) && !pI830->noAccel && pI830->exa_965_state == NULL) {
+    if (IS_I965G(pI830) && (pI830->accel_method != ACCEL_XAA) &&
+	pI830->exa_965_state == NULL) {
 	pI830->exa_965_state =
 	    i830_allocate_memory(pScrn, "exa G965 state buffer",
 		    EXA_LINEAR_EXTRA, GTT_PAGE_SIZE, 0);
@@ -1401,7 +1402,7 @@ i830_allocate_2d_memory(ScrnInfoPtr pScrn)
 	return FALSE;
 
 #ifdef I830_USE_EXA
-    if (pI830->useEXA) {
+    if (pI830->accel_method == ACCEL_EXA) {
 	if (pI830->exa_offscreen == NULL) {
 	    /* Default EXA to having 3 screens worth of offscreen memory space
 	     * (for pixmaps).
@@ -1429,7 +1430,7 @@ i830_allocate_2d_memory(ScrnInfoPtr pScrn)
     }
 #endif /* I830_USE_EXA */
 
-    if (!pI830->noAccel && !pI830->useEXA) {
+    if (pI830->accel_method == ACCEL_XAA) {
 	/* The lifetime fixed offset of xaa scratch is probably not required,
 	 * but we do some setup using it at XAAInit() time.  And XAA may not
 	 * end up being supported with TTM anyway.
diff --git a/src/i830_video.c b/src/i830_video.c
index 5325bbd..efd4723 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2392,16 +2392,16 @@ I830PutImage(ScrnInfoPtr pScrn,
     }
 
 #ifdef I830_USE_EXA
-    if (pI830->useEXA) {
+    if (pI830->accel_method == ACCEL_EXA) {
 	/* Force the pixmap into framebuffer so we can draw to it. */
 	exaMoveInPixmap(pPixmap);
     }
 #endif
 
-    if (!pI830->useEXA &&
-	    (((char *)pPixmap->devPrivate.ptr < (char *)pI830->FbBase) ||
-	     ((char *)pPixmap->devPrivate.ptr >= (char *)pI830->FbBase +
-	      pI830->FbMapSize))) {
+    if (!(pI830->accel_method == ACCEL_EXA) &&
+	(((char *)pPixmap->devPrivate.ptr < (char *)pI830->FbBase) ||
+	 ((char *)pPixmap->devPrivate.ptr >= (char *)pI830->FbBase +
+	  pI830->FbMapSize))) {
 	/* If the pixmap wasn't in framebuffer, then we have no way in XAA to
 	 * force it there.  So, we simply refuse to draw and fail.
 	 */
commit f2ff95b19f3d2053ac4099f7765169444d8d6702
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 16:41:14 2007 -0800

    Minor coding style cleanup in PreInit

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 6b21ee1..60792f2 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1303,13 +1303,10 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 
    i830_detect_chipset(pScrn);
 
-   if (IS_I9XX(pI830))
-   {
+   if (IS_I9XX(pI830)) {
       fb_bar = 2;
       mmio_bar = 0;
-   }
-   else
-   {
+   } else {
       fb_bar = 0;
       mmio_bar = 1;
    }
commit db4cc8539b48acfcd35c8ec32d131a03da1d2d97
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 16:39:36 2007 -0800

    Restore hardware state if PreInit fails
    
    Complements the patch which removes the RestoreHWState call from PreInit

diff --git a/src/i830_driver.c b/src/i830_driver.c
index f48573d..6b21ee1 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -952,6 +952,7 @@ PreInitCleanup(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
+   RestoreHWState(pScrn);
    if (I830IsPrimary(pScrn)) {
       if (pI830->entityPrivate)
 	 pI830->entityPrivate->pScrn_1 = NULL;
commit db31ae6bd35cefddcbf4041b186909175c986329
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 16:18:51 2007 -0800

    Pull chipset detection out of PreInit into its own function

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 644f66c..f48573d 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1018,6 +1018,128 @@ i830SetHotkeyControl(ScrnInfoPtr pScrn, int mode)
    pI830->writeControl(pI830, GRX, 0x18, gr18);
 }
 
+static void
+i830_detect_chipset(ScrnInfoPtr pScrn)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    MessageType from = X_PROBED;
+    const char *chipname;
+    uint32_t capid;
+
+    switch (DEVICE_ID(pI830->PciInfo)) {
+    case PCI_CHIP_I830_M:
+	chipname = "830M";
+	break;
+    case PCI_CHIP_845_G:
+	chipname = "845G";
+	break;
+    case PCI_CHIP_I855_GM:
+	/* Check capid register to find the chipset variant */
+#if XSERVER_LIBPCIACCESS
+	pci_device_cfg_read_u32 (pI830->PciInfo, &capid, I85X_CAPID);
+#else
+	capid = pciReadLong (pI830->PciTag, I85X_CAPID);
+#endif
+	pI830->variant = (capid >> I85X_VARIANT_SHIFT) & I85X_VARIANT_MASK;
+	switch (pI830->variant) {
+	case I855_GM:
+	    chipname = "855GM";
+	    break;
+	case I855_GME:
+	    chipname = "855GME";
+	    break;
+	case I852_GM:
+	    chipname = "852GM";
+	    break;
+	case I852_GME:
+	    chipname = "852GME";
+	    break;
+	default:
+	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		       "Unknown 852GM/855GM variant: 0x%x)\n", pI830->variant);
+	    chipname = "852GM/855GM (unknown variant)";
+	    break;
+	}
+	break;
+    case PCI_CHIP_I865_G:
+	chipname = "865G";
+	break;
+    case PCI_CHIP_I915_G:
+	chipname = "915G";
+	break;
+    case PCI_CHIP_E7221_G:
+	chipname = "E7221 (i915)";
+	break;
+    case PCI_CHIP_I915_GM:
+	chipname = "915GM";
+	break;
+    case PCI_CHIP_I945_G:
+	chipname = "945G";
+	break;
+    case PCI_CHIP_I945_GM:
+	chipname = "945GM";
+	break;
+    case PCI_CHIP_I945_GME:
+	chipname = "945GME";
+	break;
+    case PCI_CHIP_I965_G:
+    case PCI_CHIP_I965_G_1:
+	chipname = "965G";
+	break;
+    case PCI_CHIP_I965_Q:
+	chipname = "965Q";
+	break;
+    case PCI_CHIP_I946_GZ:
+	chipname = "946GZ";
+	break;
+    case PCI_CHIP_I965_GM:
+	chipname = "965GM";
+	break;
+    case PCI_CHIP_I965_GME:
+	chipname = "965GME/GLE";
+	break;
+    case PCI_CHIP_G33_G:
+	chipname = "G33";
+	break;
+    case PCI_CHIP_Q35_G:
+	chipname = "Q35";
+	break;
+    case PCI_CHIP_Q33_G:
+	chipname = "Q33";
+	break;
+    default:
+	chipname = "unknown chipset";
+	break;
+    }
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+	       "Integrated Graphics Chipset: Intel(R) %s\n", chipname);
+
+    /* Set the Chipset and ChipRev, allowing config file entries to override. */
+    if (pI830->pEnt->device->chipset && *pI830->pEnt->device->chipset) {
+	pScrn->chipset = pI830->pEnt->device->chipset;
+	from = X_CONFIG;
+    } else if (pI830->pEnt->device->chipID >= 0) {
+	pScrn->chipset = (char *)xf86TokenToString(I830Chipsets,
+						   pI830->pEnt->device->chipID);
+	from = X_CONFIG;
+	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",
+		   pI830->pEnt->device->chipID);
+	DEVICE_ID(pI830->PciInfo) = pI830->pEnt->device->chipID;
+    } else {
+	from = X_PROBED;
+	pScrn->chipset = (char *)xf86TokenToString(I830Chipsets,
+						   DEVICE_ID(pI830->PciInfo));
+    }
+
+    if (pI830->pEnt->device->chipRev >= 0) {
+	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
+		   pI830->pEnt->device->chipRev);
+    }
+
+    xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n",
+	       (pScrn->chipset != NULL) ? pScrn->chipset : "Unknown i8xx");
+}
+
 /**
  * This is called per zaphod head (so usually just once) to do initialization
  * before the Screen is created.
@@ -1039,10 +1161,8 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    int i;
    char *s;
    pointer pVBEModule = NULL;
-   const char *chipname;
    int num_pipe;
    int max_width, max_height;
-   uint32_t	capid;
    int fb_bar, mmio_bar;
 
    if (pScrn->numEntities != 1)
@@ -1180,118 +1300,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    /* We have to use PIO to probe, because we haven't mapped yet. */
    I830SetPIOAccess(pI830);
 
-   switch (DEVICE_ID(pI830->PciInfo)) {
-   case PCI_CHIP_I830_M:
-      chipname = "830M";
-      break;
-   case PCI_CHIP_845_G:
-      chipname = "845G";
-      break;
-   case PCI_CHIP_I855_GM:
-      /* Check capid register to find the chipset variant */
-#if XSERVER_LIBPCIACCESS
-      pci_device_cfg_read_u32 (pI830->PciInfo, &capid, I85X_CAPID);
-#else
-      capid = pciReadLong (pI830->PciTag, I85X_CAPID);
-#endif
-      pI830->variant = (capid >> I85X_VARIANT_SHIFT) & I85X_VARIANT_MASK;
-      switch (pI830->variant) {
-      case I855_GM:
-	 chipname = "855GM";
-	 break;
-      case I855_GME:
-	 chipname = "855GME";
-	 break;
-      case I852_GM:
-	 chipname = "852GM";
-	 break;
-      case I852_GME:
-	 chipname = "852GME";
-	 break;
-      default:
-	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-		    "Unknown 852GM/855GM variant: 0x%x)\n", pI830->variant);
-	 chipname = "852GM/855GM (unknown variant)";
-	 break;
-      }
-      break;
-   case PCI_CHIP_I865_G:
-      chipname = "865G";
-      break;
-   case PCI_CHIP_I915_G:
-      chipname = "915G";
-      break;
-   case PCI_CHIP_E7221_G:
-      chipname = "E7221 (i915)";
-      break;
-   case PCI_CHIP_I915_GM:
-      chipname = "915GM";
-      break;
-   case PCI_CHIP_I945_G:
-      chipname = "945G";
-      break;
-   case PCI_CHIP_I945_GM:
-      chipname = "945GM";
-      break;
-   case PCI_CHIP_I945_GME:
-      chipname = "945GME";
-      break;
-   case PCI_CHIP_I965_G:
-   case PCI_CHIP_I965_G_1:
-      chipname = "965G";
-      break;
-   case PCI_CHIP_I965_Q:
-      chipname = "965Q";
-      break;
-   case PCI_CHIP_I946_GZ:
-      chipname = "946GZ";
-      break;
-   case PCI_CHIP_I965_GM:
-      chipname = "965GM";
-      break;
-   case PCI_CHIP_I965_GME:
-      chipname = "965GME/GLE";
-      break;
-   case PCI_CHIP_G33_G:
-      chipname = "G33";
-      break;
-   case PCI_CHIP_Q35_G:
-      chipname = "Q35";
-      break;
-   case PCI_CHIP_Q33_G:
-      chipname = "Q33";
-      break;
-   default:
-      chipname = "unknown chipset";
-      break;
-   }
-   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-	      "Integrated Graphics Chipset: Intel(R) %s\n", chipname);
-
-   /* Set the Chipset and ChipRev, allowing config file entries to override. */
-   if (pI830->pEnt->device->chipset && *pI830->pEnt->device->chipset) {
-      pScrn->chipset = pI830->pEnt->device->chipset;
-      from = X_CONFIG;
-   } else if (pI830->pEnt->device->chipID >= 0) {
-      pScrn->chipset = (char *)xf86TokenToString(I830Chipsets,
-						 pI830->pEnt->device->chipID);
-      from = X_CONFIG;
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",
-		 pI830->pEnt->device->chipID);
-      DEVICE_ID(pI830->PciInfo) = pI830->pEnt->device->chipID;
-   } else {
-      from = X_PROBED;
-      pScrn->chipset = (char *)xf86TokenToString(I830Chipsets,
-						 DEVICE_ID(pI830->PciInfo));
-   }
-
-   if (pI830->pEnt->device->chipRev >= 0) {
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
-		 pI830->pEnt->device->chipRev);
-   }
-
-   xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n",
-	      (pScrn->chipset != NULL) ? pScrn->chipset : "Unknown i8xx");
+   i830_detect_chipset(pScrn);
 
    if (IS_I9XX(pI830))
    {
commit 162446bcdd7da264e59490fec4da0f0fae9436e4
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 16:07:41 2007 -0800

    Remove superfluous RestoreHWState() call
    
    We should save hw state once at server startup time, and only restore it when
    returning to our original VT.  So remove the call to restore the state in
    PreInit (except for error paths).

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 95d1df4..644f66c 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1514,7 +1514,6 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
       PreInitCleanup(pScrn);
       return FALSE;
    }
-   RestoreHWState(pScrn);
 
    /* XXX This should go away, replaced by xf86Crtc.c support for it */
    pI830->rotation = RR_Rotate_0;
commit 966912c4f39f9491416625eda43bd3ebde876c26
Author: Jesse Barnes <jesse.barnes at intel.com>
Date:   Mon Dec 3 16:05:06 2007 -0800

    Reduce startup flicker
    
    Remove a couple of extra calls to the output off routines to avoid some nasty
    mode setting flicker at startup time.  We could go even further if it's
    possible to leave outputs on during mode set (leaving LVDS active in particular
    makes for a nice, fast, flicker free startup).

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 7818ee4..95d1df4 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2005,13 +2005,6 @@ RestoreHWState(ScrnInfoPtr pScrn)
 #ifdef XF86DRI
    I830DRISetVBlankInterrupt (pScrn, FALSE);
 #endif
-   /* Disable outputs */
-   for (i = 0; i < xf86_config->num_output; i++) {
-      xf86OutputPtr   output = xf86_config->output[i];
-      output->funcs->dpms(output, DPMSModeOff);
-   }
-   i830WaitForVblank(pScrn);
-   
    /* Disable pipes */
    for (i = 0; i < xf86_config->num_crtc; i++) {
       xf86CrtcPtr crtc = xf86_config->crtc[i];
@@ -3091,11 +3084,6 @@ I830EnterVT(int scrnIndex, int flags)
    memset(pI830->FbBase + pScrn->fbOffset, 0,
 	  pScrn->virtualY * pScrn->displayWidth * pI830->cpp);
 
-   for (o = 0; o < config->num_output; o++) {
-   	xf86OutputPtr  output = config->output[o];
-	output->funcs->dpms(output, DPMSModeOff);
-   }
-
    if (!xf86SetDesiredModes (pScrn))
       return FALSE;
    


More information about the xorg-commit mailing list