xf86-video-ati: Branch 'pci-rework' - 7 commits

George Sapountzis gsap7 at kemper.freedesktop.org
Wed Mar 21 20:20:03 EET 2007


 src/Makefile.am    |    3 
 src/ati.c          |    9 +-
 src/atidri.c       |   25 ++----
 src/atipcirename.h |  110 ++++++++++++++++++++++++++++
 src/atipreinit.c   |  126 ++++++++++++++------------------
 src/atiprint.c     |   10 +-
 src/atiprobe.c     |   73 +++++++++----------
 src/atistruct.h    |    4 -
 src/atividmem.c    |  203 ++++++++++++++++++++---------------------------------
 9 files changed, 305 insertions(+), 258 deletions(-)

New commits:
diff-tree 2e3d43af1e5077cc61dd8668551a6291368d9ed2 (from e7defc0e930f1b2d83623a769b2bfdb05c66a5fe)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Mon Mar 19 19:05:04 2007 +0200

    [mach64] Compute MMIO address once for each case (PIO, MMIO).
    
    For an MMIO-only driver, the extra MMIO address probing is not needed since we
    already compute the MMIO address during probe and do not make any BIOS calls.
    
    For a PIO driver, this extra probing could even result in a wrong MMIO address
    since the checking is done by reading through PIO, not MMIO. The MMIO address
    is later corrected but having the extra probe there is useless.

diff --git a/src/atipreinit.c b/src/atipreinit.c
index f63784f..018f2fb 100644
--- a/src/atipreinit.c
+++ b/src/atipreinit.c
@@ -100,24 +100,6 @@ static const rgb   defaultWeight = {0, 0
 static const Gamma defaultGamma  = {0.0, 0.0, 0.0};
 
 /*
- * ATIMach64Map --
- *
- * This function attempts to mmap() a Mach64's MMIO aperture.
- */
-static void
-ATIMach64Map
-(
-    int    iScreen,
-    ATIPtr pATI
-)
-{
-    (void)ATIMapApertures(iScreen, pATI);
-    if (!pATI->pBlock[0] ||
-        (pATI->config_chip_id != inr(CONFIG_CHIP_ID)))
-        ATIUnmapApertures(iScreen, pATI);
-}
-
-/*
  * ATIPrintNoiseIfRequested --
  *
  * This function formats debugging information on the server's stderr when
@@ -174,7 +156,6 @@ ATIPreInit
     resPtr           pResources;
     pciVideoPtr      pVideo;
     DisplayModePtr   pMode;
-    unsigned long    Block0Base;
     CARD32           IOValue;
     int              i, j;
     int              Numerator, Denominator;
@@ -401,6 +382,8 @@ ATIPreInit
         return TRUE;
     }
 
+#ifndef AVOID_CPIO
+
     /* I/O bases might no longer be valid after BIOS initialisation */
     {
         if (pATI->CPIODecoding == BLOCK_IO)
@@ -415,6 +398,8 @@ ATIPreInit
         }
     }
 
+#endif /* AVOID_CPIO */
+
 #ifdef AVOID_CPIO
 
     pScreenInfo->racMemFlags =
@@ -437,38 +422,17 @@ ATIPreInit
 
     /* Finish probing the adapter */
     {
-
-            Block0Base = pATI->Block0Base; /* save */
-
-            do
-            {
-                /*
-                 * Find and mmap() MMIO area.  Allow only auxiliary aperture if
-                 * it exists.
-                 */
-                if (!pATI->Block0Base)
-                {
-                        /* Check tail end of linear (8MB or 4MB) aperture */
-                        if ((pATI->Block0Base = PCI_REGION_BASE(pVideo, 0, REGION_MEM)))
-                        {
-                            pATI->MMIOInLinear = TRUE;
-
-                            pATI->Block0Base += 0x007FFC00U;
-                            ATIMach64Map(pScreenInfo->scrnIndex, pATI);
-                            if (pATI->pBlock[0])
-                                break;
-
-                            pATI->Block0Base -= 0x00400000U;
-                            ATIMach64Map(pScreenInfo->scrnIndex, pATI);
-                            if (pATI->pBlock[0])
-                                break;
-                        }
-                }
-
-                ATIMach64Map(pScreenInfo->scrnIndex, pATI);
-            } while (0);
-
-            pATI->Block0Base = Block0Base; /* restore */
+        /*
+         * For MMIO register access, the MMIO address is computed when probing
+         * and there are no BIOS calls. This mapping should always succeed.
+         *
+         * For CPIO register access, the MMIO address is computed above in the
+         * presence of an auxiliary aperture. Otherwise, it is set to zero and
+         * gets computed when we read the linear aperture configuration. This
+         * mapping is either irrelevant or a no-op.
+         */
+        if (!ATIMapApertures(pScreenInfo->scrnIndex, pATI))
+            return FALSE;
 
 #ifdef AVOID_CPIO
 
@@ -481,15 +445,25 @@ ATIPreInit
 
 #endif /* AVOID_CPIO */
 
+            /*
+             * Verify register access by comparing against the CONFIG_CHIP_ID
+             * value saved by adapter detection.
+             */
+            if (pATI->config_chip_id != inr(CONFIG_CHIP_ID))
+            {
+                xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
+                    "Adapter registers not mapped correctly.\n");
+                ATIUnmapApertures(pScreenInfo->scrnIndex, pATI);
+                return FALSE;
+            }
+
             pATIHW->crtc_gen_cntl = inr(CRTC_GEN_CNTL);
             if (!(pATIHW->crtc_gen_cntl & CRTC_EN) &&
                 (pATI->Chip >= ATI_CHIP_264CT))
             {
                 xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
                     "Adapter has not been initialised.\n");
-                ATIPrintNoiseIfRequested(pATI, BIOS, BIOSSize);
-                ATIUnmapApertures(pScreenInfo->scrnIndex, pATI);
-                return FALSE;
+                goto bail_locked;
             }
 
 #ifdef AVOID_CPIO
@@ -499,9 +473,7 @@ ATIPreInit
                 xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
                     "Adapters found to be in VGA mode on server entry are not"
                     " supported by the MMIO-only version of this driver.\n");
-                ATIPrintNoiseIfRequested(pATI, BIOS, BIOSSize);
-                ATIUnmapApertures(pScreenInfo->scrnIndex, pATI);
-                return FALSE;
+                goto bail_locked;
             }
 
 #endif /* AVOID_CPIO */
@@ -1810,7 +1782,7 @@ ATIPreInit
             {
                 int AcceleratorVideoRAM = 0, ServerVideoRAM;
 
-                pATI->MMIOInLinear = FALSE;
+#ifndef AVOID_CPIO
 
                 /*
                  * Unless specified in PCI configuration space, set MMIO
@@ -1823,6 +1795,8 @@ ATIPreInit
                     pATI->MMIOInLinear = TRUE;
                 }
 
+#endif /* AVOID_CPIO */
+
                 AcceleratorVideoRAM = pATI->LinearSize >> 10;
 
                 /*
@@ -2479,6 +2453,8 @@ ATIPreInit
 
 bail:
     ATILock(pATI);
+
+bail_locked:
     ATIPrintNoiseIfRequested(pATI, BIOS, BIOSSize);
     ATIUnmapApertures(pScreenInfo->scrnIndex, pATI);
 
diff-tree e7defc0e930f1b2d83623a769b2bfdb05c66a5fe (from 3dfdba195f1ff794ab00585ab80e7ea6ac92fcf4)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Mon Mar 19 19:04:10 2007 +0200

    [mach64] Move setting of PIO and MMIO addresses up, after BIOS init.
    
    Partially revert "Minor refactoring of pATI->Block0Base computation."
    
    This parially reverts commit 2c8b33b761e4411451aea1eea3a89d629aeea40d.

diff --git a/src/atipreinit.c b/src/atipreinit.c
index 62fd660..f63784f 100644
--- a/src/atipreinit.c
+++ b/src/atipreinit.c
@@ -401,6 +401,20 @@ ATIPreInit
         return TRUE;
     }
 
+    /* I/O bases might no longer be valid after BIOS initialisation */
+    {
+        if (pATI->CPIODecoding == BLOCK_IO)
+            pATI->CPIOBase = PCI_REGION_BASE(pVideo, 1, REGION_IO);
+
+        pATI->MMIOInLinear = FALSE;
+
+        /* Set MMIO address from PCI configuration space, if available */
+        if ((pATI->Block0Base = PCI_REGION_BASE(pVideo, 2, REGION_MEM)))
+        {
+            pATI->Block0Base += 0x0400U;
+        }
+    }
+
 #ifdef AVOID_CPIO
 
     pScreenInfo->racMemFlags =
@@ -423,19 +437,6 @@ ATIPreInit
 
     /* Finish probing the adapter */
     {
-        /* I/O bases might no longer be valid after BIOS initialisation */
-
-        /* Set CPIO address from PCI configuration space, for block I/O */
-        if (pATI->CPIODecoding == BLOCK_IO)
-            pATI->CPIOBase = PCI_REGION_BASE(pVideo, 1, REGION_IO);
-
-        pATI->MMIOInLinear = FALSE;
-
-        /* Set MMIO address from PCI configuration space, if available */
-        if ((pATI->Block0Base = PCI_REGION_BASE(pVideo, 2, REGION_MEM)))
-        {
-            pATI->Block0Base += 0x0400U;
-        }
 
             Block0Base = pATI->Block0Base; /* save */
 
diff-tree 3dfdba195f1ff794ab00585ab80e7ea6ac92fcf4 (from 321db6d87c9110654ab386e5ec270116eca1e04f)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Sun Mar 18 16:40:07 2007 +0200

    [mach64] Make mapping code friendlier to pci-rework source-code compatibility.

diff --git a/src/atividmem.c b/src/atividmem.c
index 947f265..7ab203e 100644
--- a/src/atividmem.c
+++ b/src/atividmem.c
@@ -182,7 +182,7 @@ ATIMapApertures
                 PCI_CFG_TAG(pVideo), 0x000A0000U, 0x00010000U);
 
         if (!pATI->pBank)
-            return FALSE;
+            goto bail;
 
         pATI->Mapped = TRUE;
     }
@@ -205,17 +205,7 @@ ATIMapApertures
                                         (1U << pVideo->size[0]));
 
         if (!pATI->pMemoryLE)
-        {
-
-#ifndef AVOID_CPIO
-
-            ATIUnmapVGA(iScreen, pATI);
-
-#endif /* AVOID_CPIO */
-
-            pATI->Mapped = FALSE;
-            return FALSE;
-        }
+            goto bail;
 
         pATI->Mapped = TRUE;
 
@@ -246,18 +236,7 @@ ATIMapApertures
                                     getpagesize());
 
         if (!pATI->pMMIO)
-        {
-            ATIUnmapLinear(iScreen, pATI);
-
-#ifndef AVOID_CPIO
-
-            ATIUnmapVGA(iScreen, pATI);
-
-#endif /* AVOID_CPIO */
-
-            pATI->Mapped = FALSE;
-            return FALSE;
-        }
+            goto bail;
 
         pATI->Mapped = TRUE;
 
@@ -282,18 +261,7 @@ ATIMapApertures
          * extended BE aperture which would give a size of 8MB).
          */
         if (mmio_offset + 0x00000400U > linear_size)
-        {
-            ATIUnmapLinear(iScreen, pATI);
-
-#ifndef AVOID_CPIO
-
-            ATIUnmapVGA(iScreen, pATI);
-
-#endif /* AVOID_CPIO */
-
-            pATI->Mapped = FALSE;
-            return FALSE;
-        }
+            goto bail;
 
         pATI->Mapped = TRUE;
 
@@ -304,6 +272,20 @@ ATIMapApertures
     }
 
     return TRUE;
+
+bail:
+
+    ATIUnmapLinear(iScreen, pATI);
+
+#ifndef AVOID_CPIO
+
+    ATIUnmapVGA(iScreen, pATI);
+
+#endif /* AVOID_CPIO */
+
+    pATI->Mapped = FALSE;
+
+    return FALSE;
 }
 
 /*
diff-tree 321db6d87c9110654ab386e5ec270116eca1e04f (from dfd07b6e99020d1db43d7ce0cae4423d8c6b1f05)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Sun Mar 18 16:15:20 2007 +0200

    [mach64] Add macros for pci-rework source-code compatibilty.

diff --git a/src/Makefile.am b/src/Makefile.am
index 5c1bee6..2528d2a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -186,4 +186,5 @@ EXTRA_DIST = \
 	theatre_detect.h \
 	theatre.h \
 	theatre_reg.h \
-	atipciids.h
+	atipciids.h \
+	atipcirename.h
diff --git a/src/ati.c b/src/ati.c
index e7a5aee..803ac0b 100644
--- a/src/ati.c
+++ b/src/ati.c
@@ -57,6 +57,8 @@
 #include "config.h"
 #endif
 
+#include "atipcirename.h"
+
 #include "ati.h"
 #include "atichip.h"
 #include "ativersion.h"
@@ -118,12 +120,13 @@ ATIProbe
     {
         for (i = 0;  (pVideo = xf86PciVideoInfo[i++]);  )
         {
-            if ((pVideo->vendor != PCI_VENDOR_ATI) ||
-                (pVideo->chipType == PCI_CHIP_MACH32))
+            if ((PCI_DEV_VENDOR_ID(pVideo) != PCI_VENDOR_ATI) ||
+                (PCI_DEV_DEVICE_ID(pVideo) == PCI_CHIP_MACH32))
                 continue;
 
             /* Check for Rage128's, Radeon's and later adapters */
-            Chip = ATIChipID(pVideo->chipType, pVideo->chipRev);
+            Chip = ATIChipID(PCI_DEV_DEVICE_ID(pVideo), PCI_DEV_REVISION(pVideo));
+
             if (Chip > ATI_CHIP_Mach64)
             {
                 if (Chip <= ATI_CHIP_Rage128)
diff --git a/src/atidri.c b/src/atidri.c
index 83cb25f..d017040 100644
--- a/src/atidri.c
+++ b/src/atidri.c
@@ -774,8 +774,8 @@ static Bool ATIDRISetAgpMode( ScreenPtr 
    xf86DrvMsg( pScreen->myNum, X_INFO,
 	       "[agp] Mode 0x%08lx [AGP 0x%04x/0x%04x; Card 0x%04x/0x%04x]\n",
 	       mode, vendor, device,
-	       pATI->PCIInfo->vendor,
-	       pATI->PCIInfo->chipType );
+	       PCI_DEV_VENDOR_ID(pATI->PCIInfo),
+	       PCI_DEV_DEVICE_ID(pATI->PCIInfo) );
 
    if ( drmAgpEnable( pATI->drmFD, mode ) < 0 ) {
       xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not enabled\n" );
@@ -1134,18 +1134,15 @@ static Bool ATIDRIIrqInit( ScreenPtr pSc
 
    if ( pATI->irq <= 0 ) {
       pATI->irq = drmGetInterruptFromBusID(pATI->drmFD,
-					   ((pciConfigPtr)pATI->PCIInfo
-					    ->thisCard)->busnum,
-					   ((pciConfigPtr)pATI->PCIInfo
-					    ->thisCard)->devnum,
-					   ((pciConfigPtr)pATI->PCIInfo
-					    ->thisCard)->funcnum);
+					   PCI_CFG_BUS(pATI->PCIInfo),
+					   PCI_CFG_DEV(pATI->PCIInfo),
+					   PCI_CFG_FUNC(pATI->PCIInfo));
       if ( pATI->irq <= 0 ) {
 	 xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
 		    "[drm] Couldn't find IRQ for bus id %d:%d:%d\n",
-		    ((pciConfigPtr)pATI->PCIInfo->thisCard)->busnum,
-		    ((pciConfigPtr)pATI->PCIInfo->thisCard)->devnum,
-		    ((pciConfigPtr)pATI->PCIInfo->thisCard)->funcnum);
+		    PCI_CFG_BUS(pATI->PCIInfo),
+		    PCI_CFG_DEV(pATI->PCIInfo),
+		    PCI_CFG_FUNC(pATI->PCIInfo));
 	 pATI->irq = 0;
       } else if ((drmCtlInstHandler(pATI->drmFD, pATI->irq)) != 0) {
  	 xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
@@ -1243,9 +1240,9 @@ Bool ATIDRIScreenInit( ScreenPtr pScreen
       pDRIInfo->busIdString = xalloc( 64 );
       sprintf( pDRIInfo->busIdString,
 	       "PCI:%d:%d:%d",
-	       pATI->PCIInfo->bus,
-	       pATI->PCIInfo->device,
-	       pATI->PCIInfo->func );
+	       PCI_DEV_BUS(pATI->PCIInfo),
+	       PCI_DEV_DEV(pATI->PCIInfo),
+	       PCI_DEV_FUNC(pATI->PCIInfo) );
    }
    pDRIInfo->ddxDriverMajorVersion = ATI_VERSION_MAJOR;
    pDRIInfo->ddxDriverMinorVersion = ATI_VERSION_MINOR;
diff --git a/src/atipcirename.h b/src/atipcirename.h
new file mode 100644
index 0000000..280a81a
--- /dev/null
+++ b/src/atipcirename.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2007 George Sapountzis
+ *
+ * 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.
+ */
+
+/**
+ * Macros for porting drivers from legacy xfree86 PCI code to the pciaccess
+ * library. The main purpose being to facilitate source code compatibility.
+ */
+
+#ifndef ATIPCIRENAME_H
+#define ATIPCIRENAME_H
+
+enum region_type {
+    REGION_MEM,
+    REGION_IO 
+};
+
+#ifndef PCIACCESS
+
+/* pciVideoPtr */
+#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor)
+#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->chipType)
+#define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->chipRev)
+
+#define PCI_DEV_TAG(_pcidev) pciTag((_pcidev)->bus,    \
+                                    (_pcidev)->device, \
+                                    (_pcidev)->func)
+#define PCI_DEV_BUS(_pcidev)       ((_pcidev)->bus)
+#define PCI_DEV_DEV(_pcidev)       ((_pcidev)->device)
+#define PCI_DEV_FUNC(_pcidev)      ((_pcidev)->func)
+
+/* pciConfigPtr */
+#define PCI_CFG_TAG(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->tag)
+#define PCI_CFG_BUS(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->busnum)
+#define PCI_CFG_DEV(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->devnum)
+#define PCI_CFG_FUNC(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->funcnum)
+
+/* region addr: xfree86 uses different fields for memory regions and I/O ports */
+#define PCI_REGION_BASE(_pcidev, _b, _type)             \
+    (((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \
+                             : (_pcidev)->ioBase[(_b)])
+
+/* region size: xfree86 uses the log2 of the region size,
+ * but with zero meaning no region, not size of one XXX */
+#define PCI_REGION_SIZE(_pcidev, _b) \
+    (((_pcidev)->size[(_b)] > 0) ? (1 << (_pcidev)->size[(_b)]) : 0)
+
+/* read/write PCI configuration space */
+#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
+    *(_value_ptr) = pciReadLong(PCI_CFG_TAG(_pcidev), (_offset))
+
+#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
+    pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value))
+
+#else /* PCIACCESS */
+
+typedef struct pci_device *pciVideoPtr;
+
+#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor_id)
+#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->device_id)
+#define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->revision)
+
+/* pci-rework functions take a 'pci_device' parameter instead of a tag */
+#define PCI_DEV_TAG(_pcidev)        (_pcidev)
+
+/* PCI_DEV macros, typically used in printf's, add domain ? XXX */
+#define PCI_DEV_BUS(_pcidev)       ((_pcidev)->bus)
+#define PCI_DEV_DEV(_pcidev)       ((_pcidev)->dev)
+#define PCI_DEV_FUNC(_pcidev)      ((_pcidev)->func)
+
+/* pci-rework functions take a 'pci_device' parameter instead of a tag */
+#define PCI_CFG_TAG(_pcidev)        (_pcidev)
+
+/* PCI_CFG macros, typically used in DRI init, contain the domain */
+#define PCI_CFG_BUS(_pcidev)      (((_pcidev)->domain << 8) | \
+                                    (_pcidev)->bus)
+#define PCI_CFG_DEV(_pcidev)       ((_pcidev)->dev)
+#define PCI_CFG_FUNC(_pcidev)      ((_pcidev)->func)
+
+#define PCI_REGION_BASE(_pcidev, _b, _type) ((_pcidev)->regions[(_b)].base_addr)
+#define PCI_REGION_SIZE(_pcidev, _b)        ((_pcidev)->regions[(_b)].size)
+
+#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
+    pci_device_cfg_read_u32((_pcidev), (_value_ptr), (_offset))
+
+#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
+    pci_device_cfg_write_u32((_pcidev), (_value), (_offset))
+
+#endif /* PCIACCESS */
+
+#endif /* ATIPCIRENAME_H */
diff --git a/src/atipreinit.c b/src/atipreinit.c
index f5cf6b3..62fd660 100644
--- a/src/atipreinit.c
+++ b/src/atipreinit.c
@@ -427,12 +427,12 @@ ATIPreInit
 
         /* Set CPIO address from PCI configuration space, for block I/O */
         if (pATI->CPIODecoding == BLOCK_IO)
-            pATI->CPIOBase = pVideo->ioBase[1];
+            pATI->CPIOBase = PCI_REGION_BASE(pVideo, 1, REGION_IO);
 
         pATI->MMIOInLinear = FALSE;
 
         /* Set MMIO address from PCI configuration space, if available */
-        if ((pATI->Block0Base = pVideo->memBase[2]))
+        if ((pATI->Block0Base = PCI_REGION_BASE(pVideo, 2, REGION_MEM)))
         {
             pATI->Block0Base += 0x0400U;
         }
@@ -448,7 +448,7 @@ ATIPreInit
                 if (!pATI->Block0Base)
                 {
                         /* Check tail end of linear (8MB or 4MB) aperture */
-                        if ((pATI->Block0Base = pVideo->memBase[0]))
+                        if ((pATI->Block0Base = PCI_REGION_BASE(pVideo, 0, REGION_MEM)))
                         {
                             pATI->MMIOInLinear = TRUE;
 
diff --git a/src/atiprint.c b/src/atiprint.c
index d435e21..60d9c21 100644
--- a/src/atiprint.c
+++ b/src/atiprint.c
@@ -355,8 +355,6 @@ ATIPrintRegisters
     ATIPtr pATI
 )
 {
-    pciVideoPtr  pVideo = pATI->PCIInfo;
-    pciConfigPtr pPCI = pVideo->thisCard;
     int          Index;
     CARD32       lcd_index, tv_out_index, lcd_gen_ctrl;
     CARD8        dac_read, dac_mask, dac_write;
@@ -642,10 +640,14 @@ ATIPrintRegisters
         xf86ErrorFVerb(4, "\n\n PCI configuration register values:");
         for (Index = 0;  Index < 256;  Index+= 4)
         {
+            pciVideoPtr pVideo = pATI->PCIInfo;
+            uint32_t    data;
+
+            PCI_READ_LONG(pVideo, &data, Index);
+
             if (!(Index & 15))
                 xf86ErrorFVerb(4, "\n 0x%02X: ", Index);
-            xf86ErrorFVerb(4, " 0x%08lX",
-			   (unsigned long)pciReadLong(pPCI->tag, Index));
+            xf86ErrorFVerb(4, " 0x%08X", data);
         }
     }
 
diff --git a/src/atiprobe.c b/src/atiprobe.c
index 13cb2e8..b82ea5f 100644
--- a/src/atiprobe.c
+++ b/src/atiprobe.c
@@ -215,7 +215,7 @@ ATIMach64Probe
     const ATIChipType Chip
 )
 {
-    CARD16 ChipType = pVideo->chipType;
+    CARD16 ChipType = PCI_DEV_DEVICE_ID(pVideo);
 
         pATI->MMIOInLinear = FALSE;
 
@@ -224,8 +224,8 @@ ATIMach64Probe
          * apertures can be enabled/disabled only through PCI, this probes no
          * further.
          */
-        if ((pVideo->size[2] >= 12) &&
-            (pATI->Block0Base = pVideo->memBase[2]))
+        if ((PCI_REGION_SIZE(pVideo, 2) >= (1 << 12)) &&
+            (pATI->Block0Base = PCI_REGION_BASE(pVideo, 2, REGION_MEM)))
         {
             pATI->Block0Base += 0x00000400U;
             if (ATIMach64Detect(pATI, ChipType, Chip))
@@ -238,13 +238,13 @@ ATIMach64Probe
          * Probe through the primary MMIO aperture that exists at the tail end
          * of the linear aperture.  Test for both 8MB and 4MB linear apertures.
          */
-        if ((pVideo->size[0] >= 22) &&
-            (pATI->Block0Base = pVideo->memBase[0]))
+        if ((PCI_REGION_SIZE(pVideo, 0) >= (1 << 22)) &&
+            (pATI->Block0Base = PCI_REGION_BASE(pVideo, 0, REGION_MEM)))
         {
             pATI->MMIOInLinear = TRUE;
 
             pATI->Block0Base += 0x007FFC00U;
-            if ((pVideo->size[0] >= 23) &&
+            if ((PCI_REGION_SIZE(pVideo, 0) >= (1 << 23)) &&
                 ATIMach64Detect(pATI, ChipType, Chip))
                 return pATI;
 
@@ -273,10 +273,10 @@ ATIMach64Probe
 )
 {
     CARD32 IOValue;
-    CARD16 ChipType = pVideo->chipType;
+    CARD16 ChipType = PCI_DEV_DEVICE_ID(pVideo);
 
         if ((pATI->CPIODecoding == BLOCK_IO) &&
-            (pVideo->size[1] < 8))
+            (PCI_REGION_SIZE(pVideo, 1) < (1 << 8)))
             return NULL;
 
     if (!ATIMach64Detect(pATI, ChipType, Chip))
@@ -376,21 +376,22 @@ ATIMach64ProbeIO
 #ifndef AVOID_CPIO
 
     /* Next, look for sparse I/O Mach64's */
-    if (!pVideo->size[1])
+    if (!PCI_REGION_SIZE(pVideo, 1))
     {
         static const IOADDRESS Mach64SparseIOBases[] = {
             0x02ECU,
             0x01CCU,
             0x01C8U
         };
+        uint32_t PciReg;
+        uint32_t j;
+
         pciConfigPtr pPCI = pVideo->thisCard;
-        CARD32       PciReg;
-        CARD32       j;
 
         if (pPCI == NULL)
             goto SkipSparse;
 
-        PciReg = pciReadLong(pPCI->tag, PCI_REG_USERCONFIG);
+        PCI_READ_LONG(pVideo, &PciReg, PCI_REG_USERCONFIG);
         j = PciReg & 0x03U;
 
         if (j == 0x03U)
@@ -398,7 +399,7 @@ ATIMach64ProbeIO
             xf86Msg(X_WARNING, ATI_NAME ": "
                 "PCI Mach64 in slot %d:%d:%d cannot be enabled\n"
                 "because it has neither a block, nor a sparse, I/O base.\n",
-                pVideo->bus, pVideo->device, pVideo->func);
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
 
             goto SkipSparse;
         }
@@ -418,14 +419,17 @@ ATIMach64ProbeIO
             xf86Msg(X_WARNING, ATI_NAME ": "
                 "PCI Mach64 in slot %d:%d:%d will not be probed\n"
                 "set option \"probe_sparse\" to force sparse I/O probing.\n",
-                pVideo->bus, pVideo->device, pVideo->func);
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
 
             goto SkipSparse;
         }
 
         /* Possibly fix block I/O indicator */
         if (PciReg & 0x00000004U)
-            pciWriteLong(pPCI->tag, PCI_REG_USERCONFIG, PciReg & ~0x00000004U);
+        {
+            PciReg &= ~0x00000004U;
+            PCI_WRITE_LONG(pVideo, PciReg, PCI_REG_USERCONFIG);
+        }
 
         pATI->CPIOBase = Mach64SparseIOBases[j];
         pATI->CPIODecoding = SPARSE_IO;
@@ -435,7 +439,7 @@ ATIMach64ProbeIO
         {
             xf86Msg(X_WARNING, ATI_NAME ": "
                 "PCI Mach64 in slot %d:%d:%d could not be detected!\n",
-                pVideo->bus, pVideo->device, pVideo->func);
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
         }
         else
         {
@@ -443,7 +447,7 @@ ATIMach64ProbeIO
             xf86Msg(X_INFO, ATI_NAME ": "
                 "Shared PCI Mach64 in slot %d:%d:%d with sparse PIO base"
                 " 0x%04lX detected.\n",
-                pVideo->bus, pVideo->device, pVideo->func,
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo),
                 Mach64SparseIOBases[j]);
 
             if (pATI->VGAAdapter)
@@ -455,7 +459,7 @@ SkipSparse:
 
 #else /* AVOID_CPIO */
 
-    if (!pVideo->size[1])
+    if (!PCI_REGION_SIZE(pVideo, 1))
     {
         /* The adapter's CPIO base is of little concern here */
         pATI->CPIOBase = 0;
@@ -468,23 +472,23 @@ SkipSparse:
             xf86Msg(X_INFO, ATI_NAME ": "
                 "Shared PCI Mach64 in slot %d:%d:%d with Block 0 base"
                 " 0x%08lX detected.\n",
-                pVideo->bus, pVideo->device, pVideo->func,
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo),
                 pATI->Block0Base);
         }
         else
         {
             xf86Msg(X_WARNING, ATI_NAME ": "
                 "PCI Mach64 in slot %d:%d:%d could not be detected!\n",
-                pVideo->bus, pVideo->device, pVideo->func);
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
         }
     }
 
 #endif /* AVOID_CPIO */
 
     /* Lastly, look for block I/O devices */
-    if (pVideo->size[1])
+    if (PCI_REGION_SIZE(pVideo, 1))
     {
-        pATI->CPIOBase = pVideo->ioBase[1];
+        pATI->CPIOBase = PCI_REGION_BASE(pVideo, 1, REGION_IO);
         pATI->CPIODecoding = BLOCK_IO;
         pATI->PCIInfo = pVideo;
 
@@ -493,7 +497,7 @@ SkipSparse:
             ProbeSuccess = TRUE;
             xf86Msg(X_INFO, ATI_NAME ": "
                 "Shared PCI/AGP Mach64 in slot %d:%d:%d detected.\n",
-                pVideo->bus, pVideo->device, pVideo->func);
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
 
 #ifndef AVOID_CPIO
 
@@ -507,7 +511,7 @@ SkipSparse:
         {
             xf86Msg(X_WARNING, ATI_NAME ": "
                 "PCI/AGP Mach64 in slot %d:%d:%d could not be detected!\n",
-                pVideo->bus, pVideo->device, pVideo->func);
+                PCI_DEV_BUS(pVideo), PCI_DEV_DEV(pVideo), PCI_DEV_FUNC(pVideo));
         }
     }
 
diff --git a/src/atistruct.h b/src/atistruct.h
index a1c76dc..3496d2a 100644
--- a/src/atistruct.h
+++ b/src/atistruct.h
@@ -61,6 +61,8 @@
 #include "xf86Pci.h"
 #include "xf86Resources.h"
 
+#include "atipcirename.h"
+
 #define CacheSlotOf(____Register) ((____Register) / UnitOf(DWORD_SELECT))
 
 /*
diff --git a/src/atividmem.c b/src/atividmem.c
index 01b0099..947f265 100644
--- a/src/atividmem.c
+++ b/src/atividmem.c
@@ -164,7 +164,6 @@ ATIMapApertures
 )
 {
     pciVideoPtr   pVideo = pATI->PCIInfo;
-    PCITAG        Tag = ((pciConfigPtr)(pVideo->thisCard))->tag;
     int           mode;
 
     if (pATI->Mapped)
@@ -180,7 +179,7 @@ ATIMapApertures
          * aperture is supported.  Hence, the hard-coded values here...
          */
             pATI->pBank = xf86MapDomainMemory(iScreen, VIDMEM_MMIO_32BIT,
-                Tag, 0x000A0000U, 0x00010000U);
+                PCI_CFG_TAG(pVideo), 0x000A0000U, 0x00010000U);
 
         if (!pATI->pBank)
             return FALSE;
@@ -201,7 +200,7 @@ ATIMapApertures
         if (pATI->MMIOInLinear)
             mode = VIDMEM_MMIO;
 
-        pATI->pMemoryLE = xf86MapPciMem(iScreen, mode, Tag,
+        pATI->pMemoryLE = xf86MapPciMem(iScreen, mode, PCI_CFG_TAG(pVideo),
                                         pVideo->memBase[0],
                                         (1U << pVideo->size[0]));
 
@@ -242,7 +241,7 @@ ATIMapApertures
     if (pATI->Block0Base && !pATI->MMIOInLinear)
     {
         mode = VIDMEM_MMIO;
-        pATI->pMMIO = xf86MapPciMem(iScreen, mode, Tag,
+        pATI->pMMIO = xf86MapPciMem(iScreen, mode, PCI_CFG_TAG(pVideo),
                                     pVideo->memBase[2],
                                     getpagesize());
 
@@ -271,9 +270,9 @@ ATIMapApertures
     {
         unsigned long mmio_offset, linear_size;
 
-        mmio_offset = pATI->Block0Base - pVideo->memBase[0];
+        mmio_offset = pATI->Block0Base - PCI_REGION_BASE(pVideo, 0, REGION_MEM);
 
-        linear_size = (1 << pVideo->size[0]);
+        linear_size = PCI_REGION_SIZE(pVideo, 0);
 
         pATI->pMMIO = NULL;
 
diff-tree dfd07b6e99020d1db43d7ce0cae4423d8c6b1f05 (from e674338a98c50800637b8ebc01adf3aec2a3eb38)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Sun Mar 18 16:38:26 2007 +0200

    [mach64] Drop checking that BAR base + size fits in 32 bit.
    
    I can't see how these tests could fail on 32-bit. OTOH they are potentially
    problematic with 64-bit PCI addresses.

diff --git a/src/atipreinit.c b/src/atipreinit.c
index 62bd926..f5cf6b3 100644
--- a/src/atipreinit.c
+++ b/src/atipreinit.c
@@ -434,10 +434,7 @@ ATIPreInit
         /* Set MMIO address from PCI configuration space, if available */
         if ((pATI->Block0Base = pVideo->memBase[2]))
         {
-            if (pATI->Block0Base >= (CARD32)(-1 << pVideo->size[2]))
-                pATI->Block0Base = 0;
-            else
-                pATI->Block0Base += 0x0400U;
+            pATI->Block0Base += 0x0400U;
         }
 
             Block0Base = pATI->Block0Base; /* save */
diff --git a/src/atiprobe.c b/src/atiprobe.c
index 36df11d..13cb2e8 100644
--- a/src/atiprobe.c
+++ b/src/atiprobe.c
@@ -225,8 +225,7 @@ ATIMach64Probe
          * further.
          */
         if ((pVideo->size[2] >= 12) &&
-            (pATI->Block0Base = pVideo->memBase[2]) &&
-            (pATI->Block0Base < (CARD32)(-1 << pVideo->size[2])))
+            (pATI->Block0Base = pVideo->memBase[2]))
         {
             pATI->Block0Base += 0x00000400U;
             if (ATIMach64Detect(pATI, ChipType, Chip))
@@ -277,8 +276,7 @@ ATIMach64Probe
     CARD16 ChipType = pVideo->chipType;
 
         if ((pATI->CPIODecoding == BLOCK_IO) &&
-            ((pVideo->size[1] < 8) ||
-             (pATI->CPIOBase >= (CARD32)(-1 << pVideo->size[1]))))
+            (pVideo->size[1] < 8))
             return NULL;
 
     if (!ATIMach64Detect(pATI, ChipType, Chip))
diff-tree e674338a98c50800637b8ebc01adf3aec2a3eb38 (from e7969de8ec572d8801806f9525a9a081a58a03f1)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Sun Mar 18 15:50:41 2007 +0200

    [mach64] Single mapping per BAR.
    
    - We reset write-combining of the FB when MMIO registers fall in the linear
      aperture.
    
    - We set MMIOInLinear in all three aperture mappings since the mapping code
      depends on it.
    
    - We map the linear aperture in its entirety for MMIOInLinear also.
      This simplifies mapping of HW cursor and the LE aperture on BE archs, as
      they always fall in the linear aperture.
    
    - I assumed that BAR[2] is page-aligned (we know it's 4K-aligned for sure).

diff --git a/src/atipreinit.c b/src/atipreinit.c
index 2e5903d..62bd926 100644
--- a/src/atipreinit.c
+++ b/src/atipreinit.c
@@ -429,6 +429,8 @@ ATIPreInit
         if (pATI->CPIODecoding == BLOCK_IO)
             pATI->CPIOBase = pVideo->ioBase[1];
 
+        pATI->MMIOInLinear = FALSE;
+
         /* Set MMIO address from PCI configuration space, if available */
         if ((pATI->Block0Base = pVideo->memBase[2]))
         {
@@ -451,6 +453,8 @@ ATIPreInit
                         /* Check tail end of linear (8MB or 4MB) aperture */
                         if ((pATI->Block0Base = pVideo->memBase[0]))
                         {
+                            pATI->MMIOInLinear = TRUE;
+
                             pATI->Block0Base += 0x007FFC00U;
                             ATIMach64Map(pScreenInfo->scrnIndex, pATI);
                             if (pATI->pBlock[0])
@@ -1808,6 +1812,8 @@ ATIPreInit
             {
                 int AcceleratorVideoRAM = 0, ServerVideoRAM;
 
+                pATI->MMIOInLinear = FALSE;
+
                 /*
                  * Unless specified in PCI configuration space, set MMIO
                  * address to tail end of linear aperture.
diff --git a/src/atiprobe.c b/src/atiprobe.c
index 01c5763..36df11d 100644
--- a/src/atiprobe.c
+++ b/src/atiprobe.c
@@ -217,6 +217,8 @@ ATIMach64Probe
 {
     CARD16 ChipType = pVideo->chipType;
 
+        pATI->MMIOInLinear = FALSE;
+
         /*
          * Probe through auxiliary MMIO aperture if one exists.  Because such
          * apertures can be enabled/disabled only through PCI, this probes no
@@ -237,8 +239,11 @@ ATIMach64Probe
          * Probe through the primary MMIO aperture that exists at the tail end
          * of the linear aperture.  Test for both 8MB and 4MB linear apertures.
          */
-        if ((pVideo->size[0] >= 22) && (pATI->Block0Base = pVideo->memBase[0]))
+        if ((pVideo->size[0] >= 22) &&
+            (pATI->Block0Base = pVideo->memBase[0]))
         {
+            pATI->MMIOInLinear = TRUE;
+
             pATI->Block0Base += 0x007FFC00U;
             if ((pVideo->size[0] >= 23) &&
                 ATIMach64Detect(pATI, ChipType, Chip))
diff --git a/src/atistruct.h b/src/atistruct.h
index 99be359..a1c76dc 100644
--- a/src/atistruct.h
+++ b/src/atistruct.h
@@ -336,7 +336,7 @@ typedef struct _ATIRec
      * Cursor-related definitions.
      */
     xf86CursorInfoPtr pCursorInfo;
-    pointer pCursorPage, pCursorImage;
+    pointer pCursorImage;
     unsigned long CursorBase;
     CARD32 CursorOffset;
     CARD16 CursorXOffset, CursorYOffset;
diff --git a/src/atividmem.c b/src/atividmem.c
index b1a7a8d..01b0099 100644
--- a/src/atividmem.c
+++ b/src/atividmem.c
@@ -67,6 +67,16 @@ const char *ATIMemoryTypeNames_264xT[] =
     "Unknown video memory type"
 };
 
+/*
+ * FIXME: This is an internal Xserver function that should be exported and
+ * called explicitely with pci-rework, pci-rework does not setup mtrr's.
+ *
+ * It is called implicitely by xf86MapPciMem(VIDMEM_FRAMEBUFFER).
+ */
+#define nop_setWC(_screenNum, _base, _size, _enable) \
+do {                                                 \
+} while (0)
+
 #ifndef AVOID_CPIO
 
 /*
@@ -103,20 +113,19 @@ ATIUnmapLinear
     ATIPtr pATI
 )
 {
-    if (pATI->pMemory)
-    {
-        xf86UnMapVidMem(iScreen, pATI->pMemory, pATI->LinearSize);
-
-#if X_BYTE_ORDER != X_LITTLE_ENDIAN
+    pciVideoPtr pVideo = pATI->PCIInfo;
 
-        if (pATI->pMemoryLE)
-            xf86UnMapVidMem(iScreen, pATI->pMemoryLE, pATI->LinearSize);
-
-#endif /* X_BYTE_ORDER */
+    if (pATI->pMemoryLE)
+    {
+        if (pATI->LinearBase)
+            nop_setWC(iScreen, pATI->LinearBase, pATI->LinearSize, FALSE);
 
+        xf86UnMapVidMem(iScreen, pATI->pMemoryLE, (1U << pVideo->size[0]));
     }
 
     pATI->pMemory = pATI->pMemoryLE = NULL;
+
+    pATI->pCursorImage = NULL;
 }
 
 /*
@@ -138,27 +147,14 @@ ATIUnmapMMIO
 }
 
 /*
- * ATIUnmapCursor --
- *
- * Unmap hardware cursor image area.
- */
-static void
-ATIUnmapCursor
-(
-    int    iScreen,
-    ATIPtr pATI
-)
-{
-    if (pATI->pCursorPage)
-        xf86UnMapVidMem(iScreen, pATI->pCursorPage, getpagesize());
-
-    pATI->pCursorPage = pATI->pCursorImage = NULL;
-}
-
-/*
  * ATIMapApertures --
  *
  * This function maps all apertures used by the driver.
+ *
+ * It is called three times:
+ * - to setup MMIO for an MMIO-only driver during Probe
+ * - to setup MMIO for an MMIO-only driver during PreInit
+ * - to setup MMIO (with Block0Base set) and FB (with LinearBase set)
  */
 Bool
 ATIMapApertures
@@ -169,7 +165,7 @@ ATIMapApertures
 {
     pciVideoPtr   pVideo = pATI->PCIInfo;
     PCITAG        Tag = ((pciConfigPtr)(pVideo->thisCard))->tag;
-    unsigned long PageSize = getpagesize();
+    int           mode;
 
     if (pATI->Mapped)
         return TRUE;
@@ -195,12 +191,21 @@ ATIMapApertures
 #endif /* AVOID_CPIO */
 
     /* Map linear aperture */
-    if (pATI->LinearBase)
+    if (pATI->LinearBase || (pATI->Block0Base && pATI->MMIOInLinear))
     {
-            pATI->pMemory = xf86MapPciMem(iScreen, VIDMEM_FRAMEBUFFER,
-                Tag, pATI->LinearBase, pATI->LinearSize);
+        mode = VIDMEM_FRAMEBUFFER;
+
+        /* Reset write-combining for the whole FB when MMIO registers fall in
+         * the linear aperture.
+         */
+        if (pATI->MMIOInLinear)
+            mode = VIDMEM_MMIO;
+
+        pATI->pMemoryLE = xf86MapPciMem(iScreen, mode, Tag,
+                                        pVideo->memBase[0],
+                                        (1U << pVideo->size[0]));
 
-        if (!pATI->pMemory)
+        if (!pATI->pMemoryLE)
         {
 
 #ifndef AVOID_CPIO
@@ -217,58 +222,32 @@ ATIMapApertures
 
 #if X_BYTE_ORDER == X_LITTLE_ENDIAN
 
-        if ((pATI->CursorBase >= pATI->LinearBase) &&
-            ((pATI->CursorOffset + 0x00000400UL) <= (CARD32)pATI->LinearSize))
-            pATI->pCursorImage = (char *)pATI->pMemory + pATI->CursorOffset;
-
-        pATI->pMemoryLE = pATI->pMemory;
+        pATI->pMemory = pATI->pMemoryLE;
 
 #else /* if X_BYTE_ORDER != X_LITTLE_ENDIAN */
 
-        /*
-         * Map the little-endian aperture (used for video, etc.).  Note that
-         * caching of this area is _not_ wanted.
-         */
-        {
-            pATI->pMemoryLE = xf86MapPciMem(iScreen, VIDMEM_MMIO, Tag,
-                pATI->LinearBase - 0x00800000U, pATI->LinearSize);
-
-            if (!pATI->pMemoryLE)
-            {
-                ATIUnmapLinear(iScreen, pATI);
-
-#ifndef AVOID_CPIO
-
-                ATIUnmapVGA(iScreen, pATI);
-
-#endif /* AVOID_CPIO */
-
-                pATI->Mapped = FALSE;
-                return FALSE;
-            }
-        }
+        pATI->pMemory = (char *)pATI->pMemoryLE + 0x00800000U;
 
 #endif /* X_BYTE_ORDER */
 
+        /* Set write-combining for the FB (and the HW cursor on LE) */
+        if (pATI->LinearBase)
+            nop_setWC(iScreen, pATI->LinearBase, pATI->LinearSize, TRUE);
+
+        if (pATI->CursorBase)
+            pATI->pCursorImage = (char *)pATI->pMemoryLE + pATI->CursorOffset;
     }
 
     /* Map MMIO aperture */
-    if (pATI->Block0Base)
+    if (pATI->Block0Base && !pATI->MMIOInLinear)
     {
-        unsigned long MMIOBase = pATI->Block0Base & ~(PageSize - 1);
-
-            pATI->pMMIO = xf86MapPciMem(iScreen, VIDMEM_MMIO,
-                Tag, MMIOBase, PageSize);
+        mode = VIDMEM_MMIO;
+        pATI->pMMIO = xf86MapPciMem(iScreen, mode, Tag,
+                                    pVideo->memBase[2],
+                                    getpagesize());
 
         if (!pATI->pMMIO)
         {
-
-#if X_BYTE_ORDER == X_LITTLE_ENDIAN
-
-            ATIUnmapCursor(iScreen, pATI);
-
-#endif /* X_BYTE_ORDER */
-
             ATIUnmapLinear(iScreen, pATI);
 
 #ifndef AVOID_CPIO
@@ -283,38 +262,28 @@ ATIMapApertures
 
         pATI->Mapped = TRUE;
 
-        pATI->pBlock[0] = (char *)pATI->pMMIO +
-            (pATI->Block0Base - MMIOBase);
+        pATI->pBlock[0] = (char *)pATI->pMMIO + 0x00000400U;
 
         if (pATI->Block1Base)
             pATI->pBlock[1] = (char *)pATI->pBlock[0] - 0x00000400U;
-
-#if X_BYTE_ORDER == X_LITTLE_ENDIAN
-
-        if (!pATI->pCursorImage)
-
-#endif /* X_BYTE_ORDER */
-
-        {
-            if ((pATI->CursorBase >= MMIOBase) &&
-                ((pATI->CursorBase + 0x00000400UL) <= (MMIOBase + PageSize)))
-                pATI->pCursorImage = (char *)pATI->pMMIO +
-                    (pATI->CursorBase - MMIOBase);
-        }
     }
-
-    /* Map hardware cursor image area */
-    if (pATI->CursorBase && !pATI->pCursorImage)
+    else if (pATI->Block0Base)
     {
-        unsigned long CursorBase = pATI->CursorBase & ~(PageSize - 1);
+        unsigned long mmio_offset, linear_size;
+
+        mmio_offset = pATI->Block0Base - pVideo->memBase[0];
 
-            pATI->pCursorPage = xf86MapPciMem(iScreen, VIDMEM_FRAMEBUFFER,
-                Tag, CursorBase, PageSize);
+        linear_size = (1 << pVideo->size[0]);
 
-        if (!pATI->pCursorPage)
+        pATI->pMMIO = NULL;
+
+        /* Check that requested MMIO offset falls in the linear aperture. This
+         * ensures that we do not poke outside a mapped region and bails early
+         * for old mach64 cards with a 4MB linear aperture (unless they have an
+         * extended BE aperture which would give a size of 8MB).
+         */
+        if (mmio_offset + 0x00000400U > linear_size)
         {
-            ATIUnmapCursor(iScreen, pATI);
-            ATIUnmapMMIO(iScreen, pATI);
             ATIUnmapLinear(iScreen, pATI);
 
 #ifndef AVOID_CPIO
@@ -327,8 +296,12 @@ ATIMapApertures
             return FALSE;
         }
 
-        pATI->pCursorImage = (char *)pATI->pCursorPage +
-            (pATI->CursorBase - CursorBase);
+        pATI->Mapped = TRUE;
+
+        pATI->pBlock[0] = (char *)pATI->pMemoryLE + mmio_offset;
+
+        if (pATI->Block1Base)
+            pATI->pBlock[1] = (char *)pATI->pBlock[0] - 0x00000400U;
     }
 
     return TRUE;
@@ -350,9 +323,6 @@ ATIUnmapApertures
         return;
     pATI->Mapped = FALSE;
 
-    /* Unmap hardware cursor image area */
-    ATIUnmapCursor(iScreen, pATI);
-
     /* Unmap MMIO area */
     ATIUnmapMMIO(iScreen, pATI);
 
diff-tree e7969de8ec572d8801806f9525a9a081a58a03f1 (from 2d2fb54ba370c1df9ef5102e83c17a7ff5c55403)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Sun Mar 18 15:35:25 2007 +0200

    [mach64] Drop poking the VGA MMIO aperture.
    
    We will not be able to handle this when we do mappings for PCI BARs only and
    it should be handled with a CPIO driver anyway.

diff --git a/src/atipreinit.c b/src/atipreinit.c
index 8f80824..2e5903d 100644
--- a/src/atipreinit.c
+++ b/src/atipreinit.c
@@ -423,7 +423,9 @@ ATIPreInit
 
     /* Finish probing the adapter */
     {
+        /* I/O bases might no longer be valid after BIOS initialisation */
 
+        /* Set CPIO address from PCI configuration space, for block I/O */
         if (pATI->CPIODecoding == BLOCK_IO)
             pATI->CPIOBase = pVideo->ioBase[1];
 
@@ -459,9 +461,6 @@ ATIPreInit
                             if (pATI->pBlock[0])
                                 break;
                         }
-
-                    /* Check VGA MMIO aperture */
-                    pATI->Block0Base = 0x000BFC00U;
                 }
 
                 ATIMach64Map(pScreenInfo->scrnIndex, pATI);
@@ -1807,8 +1806,7 @@ ATIPreInit
 
             if (pATI->LinearBase && pATI->LinearSize)
             {
-                int AcceleratorVideoRAM = pATI->LinearSize >> 10;
-                int ServerVideoRAM = pATI->VideoRAM;
+                int AcceleratorVideoRAM = 0, ServerVideoRAM;
 
                 /*
                  * Unless specified in PCI configuration space, set MMIO
@@ -1821,6 +1819,8 @@ ATIPreInit
                     pATI->MMIOInLinear = TRUE;
                 }
 
+                AcceleratorVideoRAM = pATI->LinearSize >> 10;
+
                 /*
                  * Account for MMIO area at the tail end of the linear
                  * aperture, if it is needed or if it cannot be disabled.
@@ -1828,6 +1828,8 @@ ATIPreInit
                 if (pATI->MMIOInLinear || (pATI->Chip < ATI_CHIP_264VTB))
                     AcceleratorVideoRAM -= 2;
 
+                ServerVideoRAM = pATI->VideoRAM;
+
                 if (pATI->Cursor > ATI_CURSOR_SOFTWARE)
                 {
                     /*
diff --git a/src/atiprobe.c b/src/atiprobe.c
index 4a70f81..01c5763 100644
--- a/src/atiprobe.c
+++ b/src/atiprobe.c
@@ -227,7 +227,10 @@ ATIMach64Probe
             (pATI->Block0Base < (CARD32)(-1 << pVideo->size[2])))
         {
             pATI->Block0Base += 0x00000400U;
-            goto LastProbe;
+            if (ATIMach64Detect(pATI, ChipType, Chip))
+                return pATI;
+
+            return NULL;
         }
 
         /*
@@ -246,17 +249,6 @@ ATIMach64Probe
                 return pATI;
         }
 
-    /*
-     * A last, perhaps desparate, probe attempt.  Note that if this succeeds,
-     * there's a VGA in the system and it's likely the PIO version of the
-     * driver should be used instead (barring OS issues).
-     */
-    pATI->Block0Base = 0x000BFC00U;
-
-LastProbe:
-    if (ATIMach64Detect(pATI, ChipType, Chip))
-        return pATI;
-
     return NULL;
 }
 



More information about the xorg-commit mailing list