xf86-video-ati: Branch 'master' - 13 commits

Michel Daenzer daenzer at kemper.freedesktop.org
Thu Oct 4 02:34:26 PDT 2007


 configure.ac         |   10 ++++
 src/Makefile.am      |   21 +++++---
 src/ati.c            |   62 +++++++++++++++++++++++--
 src/atidri.c         |   25 ++++------
 src/atimach64probe.c |    2 
 src/atipcirename.h   |  122 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/atipreinit.c     |  126 +++++++++++++++++++++------------------------------
 src/atiprint.c       |   10 ++--
 src/atiprobe.c       |   75 +++++++++++++++---------------
 src/atistruct.h      |    2 
 src/atividmem.c      |  122 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/r128_probe.c     |    2 
 src/radeon.h         |    6 +-
 src/radeon_accel.c   |    2 
 src/radeon_bios.c    |   26 ++++++++--
 src/radeon_dri.c     |   22 ++++----
 src/radeon_driver.c  |  124 +++++++++++++++++++++++++++++++++++++-------------
 src/radeon_probe.c   |    2 
 src/radeon_video.c   |    6 +-
 19 files changed, 574 insertions(+), 193 deletions(-)

New commits:
diff-tree abbafe6db7c0d24efc61a05950d4214c00d3f043 (from 1110957ba703475847b8e72023c6edcbd1068aef)
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Thu Oct 4 11:33:09 2007 +0200

    radeon: Fix compile warnings.

diff --git a/src/radeon_bios.c b/src/radeon_bios.c
index d5b7f5e..65c2bb0 100644
--- a/src/radeon_bios.c
+++ b/src/radeon_bios.c
@@ -765,7 +765,7 @@ Bool RADEONInitExtTMDSInfoFromBIOS (xf86
 		    val = RADEON_BIOS32(index);
 		    index += 4;
 		    ErrorF("WRITE INDEXED: 0x%x 0x%x\n",
-			   reg, (unsigned)val);
+			   (unsigned)reg, (unsigned)val);
 		    /*OUTREG(reg, val);*/
 		    break;
 		case 2:
@@ -777,13 +777,13 @@ Bool RADEONInitExtTMDSInfoFromBIOS (xf86
 		    val = INREG(reg);
 		    val = (val & andmask) | ormask;
 		    ErrorF("MASK DIRECT: 0x%x 0x%x 0x%x\n",
-			   reg, (unsigned)andmask, (unsigned)ormask);
+			   (unsigned)reg, (unsigned)andmask, (unsigned)ormask);
 		    /*OUTREG(reg, val);*/
 		    break;
 		case 4:
 		    val = RADEON_BIOS16(index);
 		    index += 2;
-		    ErrorF("delay: %d\n", val);
+		    ErrorF("delay: %u\n", (unsigned)val);
 		    usleep(val);
 		    break;
 		case 5:
@@ -793,7 +793,7 @@ Bool RADEONInitExtTMDSInfoFromBIOS (xf86
 		    ormask = RADEON_BIOS32(index);
 		    index += 4;
 		    ErrorF("MASK PLL: 0x%x 0x%x 0x%x\n",
-			   reg, (unsigned)andmask, (unsigned)ormask);
+			   (unsigned)reg, (unsigned)andmask, (unsigned)ormask);
 		    /*val = INPLL(pScrn, reg);
 		    val = (val & andmask) | ormask;
 		    OUTPLL(pScrn, reg, val);*/
@@ -802,7 +802,8 @@ Bool RADEONInitExtTMDSInfoFromBIOS (xf86
 		    reg = id & 0x1fff;
 		    val = RADEON_BIOS8(index);
 		    index += 1;
-		    ErrorF("i2c write: 0x%x, 0x%x\n", reg, val);
+		    ErrorF("i2c write: 0x%x, 0x%x\n", (unsigned)reg,
+			   (unsigned)val);
 		    RADEONDVOWriteByte(radeon_output->DVOChip, reg, val);
 		    break;
 		default:
diff-tree 1110957ba703475847b8e72023c6edcbd1068aef (from 7addf41885ec5658f531624a9c24ea5bd7d22d19)
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Thu Oct 4 11:32:48 2007 +0200

    radeon: Fix for pci-rework.
    
    Surprisingly easy, thanks to George's pci-rework changes.

diff --git a/src/Makefile.am b/src/Makefile.am
index 16cbb66..1eea432 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,16 +66,6 @@ atimisc_drv_la_SOURCES = \
 	atiload.c atimisc.c atimach64probe.c $(ATIMISC_CPIO_SOURCES) \
 	$(ATIMISC_DGA_SOURCES) $(ATIMISC_DRI_SRCS) $(ATIMISC_EXA_SOURCES)
 
-if XSERVER_LIBPCIACCESS
-# r128, radeon and theatre have not been ported yet
-else
-r128_drv_la_LTLIBRARIES = r128_drv.la
-r128_drv_la_LDFLAGS = -module -avoid-version
-r128_drv_ladir = @moduledir@/drivers
-r128_drv_la_SOURCES = \
-	r128_accel.c r128_cursor.c r128_dga.c r128_driver.c \
-	r128_video.c r128_misc.c r128_probe.c $(R128_DRI_SRCS)
-
 radeon_drv_la_LTLIBRARIES = radeon_drv.la
 radeon_drv_la_LDFLAGS = -module -avoid-version
 radeon_drv_ladir = @moduledir@/drivers
@@ -86,6 +76,16 @@ radeon_drv_la_SOURCES = \
 	radeon_crtc.c radeon_output.c radeon_modes.c radeon_tv.c \
 	$(RADEON_DRI_SRCS) $(RADEON_EXA_SOURCES)
 
+if XSERVER_LIBPCIACCESS
+# r128 and theatre have not been ported yet
+else
+r128_drv_la_LTLIBRARIES = r128_drv.la
+r128_drv_la_LDFLAGS = -module -avoid-version
+r128_drv_ladir = @moduledir@/drivers
+r128_drv_la_SOURCES = \
+	r128_accel.c r128_cursor.c r128_dga.c r128_driver.c \
+	r128_video.c r128_misc.c r128_probe.c $(R128_DRI_SRCS)
+
 theatre_detect_drv_la_LTLIBRARIES = theatre_detect_drv.la
 theatre_detect_drv_la_LDFLAGS = -module -avoid-version
 theatre_detect_drv_ladir = @moduledir@/multimedia
diff --git a/src/atipcirename.h b/src/atipcirename.h
index e30d10c..5aa6b80 100644
--- a/src/atipcirename.h
+++ b/src/atipcirename.h
@@ -41,6 +41,9 @@ enum region_type {
 #define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->chipType)
 #define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->chipRev)
 
+#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subsysVendor)
+#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subsysCard)
+
 #define PCI_DEV_TAG(_pcidev) pciTag((_pcidev)->bus,    \
                                     (_pcidev)->device, \
                                     (_pcidev)->func)
@@ -65,6 +68,9 @@ enum region_type {
     (((_pcidev)->size[(_b)] > 0) ? (1 << (_pcidev)->size[(_b)]) : 0)
 
 /* read/write PCI configuration space */
+#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \
+    *(_value_ptr) = pciReadByte(PCI_CFG_TAG(_pcidev), (_offset))
+
 #define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
     *(_value_ptr) = pciReadLong(PCI_CFG_TAG(_pcidev), (_offset))
 
@@ -79,6 +85,9 @@ typedef struct pci_device *pciVideoPtr;
 #define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->device_id)
 #define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->revision)
 
+#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subvendor_id)
+#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subdevice_id)
+
 /* pci-rework functions take a 'pci_device' parameter instead of a tag */
 #define PCI_DEV_TAG(_pcidev)        (_pcidev)
 
@@ -99,6 +108,9 @@ typedef struct pci_device *pciVideoPtr;
 #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_BYTE(_pcidev, _value_ptr, _offset) \
+    pci_device_cfg_read_u8((_pcidev), (_value_ptr), (_offset))
+
 #define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
     pci_device_cfg_read_u32((_pcidev), (_value_ptr), (_offset))
 
diff --git a/src/radeon.h b/src/radeon.h
index 610e2b3..ad94cc5 100644
--- a/src/radeon.h
+++ b/src/radeon.h
@@ -88,6 +88,8 @@
 #include "picturestr.h"
 #endif
 
+#include "atipcirename.h"
+
 #ifndef MAX
 #define MAX(a,b) ((a)>(b)?(a):(b))
 #endif
@@ -456,8 +458,8 @@ typedef struct {
     CARD32            mc_fb_location;
     CARD32            mc_agp_location;
 
-    unsigned char     *MMIO;            /* Map of MMIO region                */
-    unsigned char     *FB;              /* Map of frame buffer               */
+    void              *MMIO;            /* Map of MMIO region                */
+    void              *FB;              /* Map of frame buffer               */
     CARD8             *VBIOS;           /* Video BIOS pointer                */
 
     Bool              IsAtomBios;       /* New BIOS used in R420 etc.        */
diff --git a/src/radeon_accel.c b/src/radeon_accel.c
index b739988..6028aff 100644
--- a/src/radeon_accel.c
+++ b/src/radeon_accel.c
@@ -621,7 +621,7 @@ RADEONHostDataParams(ScrnInfoPtr pScrn, 
 		     CARD32 *dstPitchOff, int *x, int *y)
 {
     RADEONInfoPtr info = RADEONPTR( pScrn );
-    CARD32 dstOffs = dst - info->FB + info->fbLocation;
+    CARD32 dstOffs = dst - (CARD8*)info->FB + info->fbLocation;
 
     *dstPitchOff = pitch << 16 | (dstOffs & ~RADEON_BUFFER_ALIGN) >> 10;
     *y = ( dstOffs & RADEON_BUFFER_ALIGN ) / pitch;
diff --git a/src/radeon_bios.c b/src/radeon_bios.c
index cfa5d2b..d5b7f5e 100644
--- a/src/radeon_bios.c
+++ b/src/radeon_bios.c
@@ -48,7 +48,13 @@ Bool RADEONGetBIOSInfo(ScrnInfoPtr pScrn
     int tmp;
     unsigned short dptr;
 
-    if (!(info->VBIOS = xalloc(RADEON_VBIOS_SIZE))) {
+    if (!(info->VBIOS = xalloc(
+#ifdef XSERVER_LIBPCIACCESS
+			       info->PciInfo->rom_size
+#else
+			       RADEON_VBIOS_SIZE
+#endif
+			       ))) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		   "Cannot allocate space for hold Video BIOS!\n");
 	return FALSE;
@@ -58,6 +64,12 @@ Bool RADEONGetBIOSInfo(ScrnInfoPtr pScrn
 	    (void)memcpy(info->VBIOS, xf86int10Addr(pInt10, info->BIOSAddr),
 			 RADEON_VBIOS_SIZE);
 	} else {
+#ifdef XSERVER_LIBPCIACCESS
+	    if (pci_device_read_rom(info->PciInfo, info->VBIOS)) {
+		xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+			   "Failed to read PCI ROM!\n");
+	    }
+#else
 	    xf86ReadPciBIOS(0, info->PciTag, 0, info->VBIOS, RADEON_VBIOS_SIZE);
 	    if (info->VBIOS[0] != 0x55 || info->VBIOS[1] != 0xaa) {
 		xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
@@ -69,6 +81,7 @@ Bool RADEONGetBIOSInfo(ScrnInfoPtr pScrn
 		xf86ReadDomainMemory(info->PciTag, info->BIOSAddr,
 				     RADEON_VBIOS_SIZE, info->VBIOS);
 	    }
+#endif
 	}
     }
 
diff --git a/src/radeon_dri.c b/src/radeon_dri.c
index 24018e8..2c533b1 100644
--- a/src/radeon_dri.c
+++ b/src/radeon_dri.c
@@ -795,8 +795,8 @@ static Bool RADEONSetAgpMode(RADEONInfoP
     xf86DrvMsg(pScreen->myNum, X_INFO,
 	       "[agp] Mode 0x%08lx [AGP 0x%04x/0x%04x; Card 0x%04x/0x%04x]\n",
 	       mode, vendor, device,
-	       info->PciInfo->vendor,
-	       info->PciInfo->chipType);
+	       PCI_DEV_VENDOR_ID(info->PciInfo),
+	       PCI_DEV_DEVICE_ID(info->PciInfo));
 
     if (drmAgpEnable(info->drmFD, mode) < 0) {
 	xf86DrvMsg(pScreen->myNum, X_ERROR, "[agp] AGP not enabled\n");
@@ -1183,9 +1183,9 @@ static void RADEONDRIIrqInit(RADEONInfoP
     if (!info->irq) {
 	info->irq = drmGetInterruptFromBusID(
 	    info->drmFD,
-	    ((pciConfigPtr)info->PciInfo->thisCard)->busnum,
-	    ((pciConfigPtr)info->PciInfo->thisCard)->devnum,
-	    ((pciConfigPtr)info->PciInfo->thisCard)->funcnum);
+	    PCI_CFG_BUS(info->PciInfo),
+	    PCI_CFG_DEV(info->PciInfo),
+	    PCI_CFG_FUNC(info->PciInfo));
 
 	if ((drmCtlInstHandler(info->drmFD, info->irq)) != 0) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
@@ -1291,9 +1291,9 @@ Bool RADEONDRIGetVersion(ScrnInfoPtr pSc
 	busId = xalloc(64);
 	sprintf(busId,
 		"PCI:%d:%d:%d",
-		info->PciInfo->bus,
-		info->PciInfo->device,
-		info->PciInfo->func);
+		PCI_DEV_BUS(info->PciInfo),
+		PCI_DEV_DEV(info->PciInfo),
+		PCI_DEV_FUNC(info->PciInfo));
     }
 
     /* Low level DRM open */
@@ -1431,9 +1431,9 @@ Bool RADEONDRIScreenInit(ScreenPtr pScre
 	pDRIInfo->busIdString            = xalloc(64);
 	sprintf(pDRIInfo->busIdString,
 		"PCI:%d:%d:%d",
-		info->PciInfo->bus,
-		info->PciInfo->device,
-		info->PciInfo->func);
+		PCI_DEV_BUS(info->PciInfo),
+		PCI_DEV_DEV(info->PciInfo),
+		PCI_DEV_FUNC(info->PciInfo));
     }
     pDRIInfo->ddxDriverMajorVersion      = info->allowColorTiling ?
     				RADEON_VERSION_MAJOR_TILED : RADEON_VERSION_MAJOR;
diff --git a/src/radeon_driver.c b/src/radeon_driver.c
index d434116..6f8a753 100644
--- a/src/radeon_driver.c
+++ b/src/radeon_driver.c
@@ -525,6 +525,8 @@ static Bool RADEONMapMMIO(ScrnInfoPtr pS
 {
     RADEONInfoPtr  info = RADEONPTR(pScrn);
 
+#ifndef XSERVER_LIBPCIACCESS
+
     info->MMIO = xf86MapPciMem(pScrn->scrnIndex,
 			       VIDMEM_MMIO | VIDMEM_READSIDEEFFECT,
 			       info->PciTag,
@@ -532,6 +534,25 @@ static Bool RADEONMapMMIO(ScrnInfoPtr pS
 			       info->MMIOSize);
 
     if (!info->MMIO) return FALSE;
+
+#else
+
+    void** result = (void**)&info->MMIO;
+    int err = pci_device_map_range(info->PciInfo,
+				   info->MMIOAddr,
+				   info->MMIOSize,
+				   PCI_DEV_MAP_FLAG_WRITABLE,
+				   result);
+
+    if (err) {
+	xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
+                    "Unable to map MMIO aperture. %s (%d)\n",
+                    strerror (err), err);
+	return FALSE;
+    }
+
+#endif
+
     return TRUE;
 }
 
@@ -542,7 +563,11 @@ static Bool RADEONUnmapMMIO(ScrnInfoPtr 
 {
     RADEONInfoPtr  info = RADEONPTR(pScrn);
 
+#ifndef XSERVER_LIBPCIACCESS
     xf86UnMapVidMem(pScrn->scrnIndex, info->MMIO, info->MMIOSize);
+#else
+    pci_device_unmap_range(info->PciInfo, info->MMIO, info->MMIOSize);
+#endif
 
     info->MMIO = NULL;
     return TRUE;
@@ -555,6 +580,9 @@ static Bool RADEONMapFB(ScrnInfoPtr pScr
 
     xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
 		   "Map: 0x%08lx, 0x%08lx\n", info->LinearAddr, info->FbMapSize);
+
+#ifndef XSERVER_LIBPCIACCESS
+
     info->FB = xf86MapPciMem(pScrn->scrnIndex,
 			     VIDMEM_FRAMEBUFFER,
 			     info->PciTag,
@@ -562,6 +590,25 @@ static Bool RADEONMapFB(ScrnInfoPtr pScr
 			     info->FbMapSize);
 
     if (!info->FB) return FALSE;
+
+#else
+
+    int err = pci_device_map_range(info->PciInfo,
+				   info->LinearAddr,
+				   info->FbMapSize,
+				   PCI_DEV_MAP_FLAG_WRITABLE |
+				   PCI_DEV_MAP_FLAG_WRITE_COMBINE,
+				   &info->FB);
+
+    if (err) {
+	xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
+                    "Unable to map FB aperture. %s (%d)\n",
+                    strerror (err), err);
+	return FALSE;
+    }
+
+#endif
+
     return TRUE;
 }
 
@@ -570,7 +617,12 @@ static Bool RADEONUnmapFB(ScrnInfoPtr pS
 {
     RADEONInfoPtr  info = RADEONPTR(pScrn);
 
+#ifndef XSERVER_LIBPCIACCESS
     xf86UnMapVidMem(pScrn->scrnIndex, info->FB, info->FbMapSize);
+#else
+    pci_device_unmap_range(info->PciInfo, info->FB, info->FbMapSize);
+#endif
+
     info->FB = NULL;
     return TRUE;
 }
@@ -1271,6 +1323,7 @@ static CARD32 RADEONGetAccessibleVRAM(Sc
     RADEONInfoPtr  info   = RADEONPTR(pScrn);
     unsigned char *RADEONMMIO = info->MMIO;
     CARD32	   aper_size = INREG(RADEON_CONFIG_APER_SIZE) / 1024;
+    unsigned char  byte;
 
 #ifdef XF86DRI
     /* If we use the DRI, we need to check if it's a version that has the
@@ -1311,7 +1364,8 @@ static CARD32 RADEONGetAccessibleVRAM(Sc
      * check if it's a multifunction card by reading the PCI config
      * header type... Limit those to one aperture size
      */
-    if (pciReadByte(info->PciTag, 0xe) & 0x80) {
+    PCI_READ_BYTE(info->PciInfo, &byte, 0xe);
+    if (byte & 0x80) {
 	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		   "Generation 1 PCI interface in multifunction mode"
 		   ", accessible memory limited to one aperture\n");
@@ -1359,7 +1413,7 @@ static Bool RADEONPreInitVRAM(ScrnInfoPt
     accessible = RADEONGetAccessibleVRAM(pScrn);
 
     /* Crop it to the size of the PCI BAR */
-    bar_size = (1ul << info->PciInfo->size[0]) / 1024;
+    bar_size = PCI_REGION_SIZE(info->PciInfo, 0) / 1024;
     if (bar_size == 0)
 	bar_size = 0x20000;
     if (accessible > bar_size)
@@ -1419,6 +1473,7 @@ static Bool RADEONPreInitChipType(ScrnIn
     MessageType    from = X_PROBED;
 #ifdef XF86DRI
     const char *s;
+    uint32_t cmd_stat;
 #endif
 
     /* Chipset */
@@ -1430,7 +1485,7 @@ static Bool RADEONPreInitChipType(ScrnIn
 	info->Chipset  = dev->chipID;
 	from           = X_CONFIG;
     } else {
-	info->Chipset = info->PciInfo->chipType;
+	info->Chipset = PCI_DEV_DEVICE_ID(info->PciInfo);
     }
 
     pScrn->chipset = (char *)xf86TokenToString(RADEONChipsets, info->Chipset);
@@ -1470,17 +1525,17 @@ static Bool RADEONPreInitChipType(ScrnIn
 	info->ChipFamily = CHIP_FAMILY_RV100;
 
 	/* DELL triple-head configuration. */
-	if ((info->PciInfo->subsysVendor == PCI_VENDOR_DELL) &&
-	    ((info->PciInfo->subsysCard  == 0x016c) ||
-	    (info->PciInfo->subsysCard   == 0x016d) ||
-	    (info->PciInfo->subsysCard   == 0x016e) ||
-	    (info->PciInfo->subsysCard   == 0x016f) ||
-	    (info->PciInfo->subsysCard   == 0x0170) ||
-	    (info->PciInfo->subsysCard   == 0x017d) ||
-	    (info->PciInfo->subsysCard   == 0x017e) ||
-	    (info->PciInfo->subsysCard   == 0x0183) ||
-	    (info->PciInfo->subsysCard   == 0x018a) ||
-	    (info->PciInfo->subsysCard   == 0x019a))) {
+	if ((PCI_SUB_VENDOR_ID(info->PciInfo) == PCI_VENDOR_DELL) &&
+	    ((PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016c) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016d) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016e) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016f) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x0170) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x017d) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x017e) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x0183) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x018a) ||
+	     (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x019a))) {
 	    info->IsDellServer = TRUE;
 	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "DELL server detected, force to special setup\n");
 	}
@@ -1702,7 +1757,7 @@ static Bool RADEONPreInitChipType(ScrnIn
 
 
     from               = X_PROBED;
-    info->LinearAddr   = info->PciInfo->memBase[0] & 0xfe000000;
+    info->LinearAddr   = PCI_REGION_BASE(info->PciInfo, 0, REGION_MEM) & 0xfe000000;
     pScrn->memPhysBase = info->LinearAddr;
     if (dev->MemBase) {
 	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
@@ -1719,6 +1774,7 @@ static Bool RADEONPreInitChipType(ScrnIn
     xf86DrvMsg(pScrn->scrnIndex, from,
 	       "Linear framebuffer at 0x%08lx\n", info->LinearAddr);
 
+#ifndef XSERVER_LIBPCIACCESS
 				/* BIOS */
     from              = X_PROBED;
     info->BIOSAddr    = info->PciInfo->biosBase & 0xfffe0000;
@@ -1734,6 +1790,7 @@ static Bool RADEONPreInitChipType(ScrnIn
 	xf86DrvMsg(pScrn->scrnIndex, from,
 		   "BIOS at 0x%08lx\n", info->BIOSAddr);
     }
+#endif
 
 				/* Read registers used to determine options */
     /* Check chip errata */
@@ -1796,15 +1853,15 @@ static Bool RADEONPreInitChipType(ScrnIn
 
     info->cardType = CARD_PCI;
 
-    if (pciReadLong(info->PciTag, PCI_CMD_STAT_REG) & RADEON_CAP_LIST) {
-	CARD32 cap_ptr, cap_id;
-	
-	cap_ptr = pciReadLong(info->PciTag,
-			      RADEON_CAPABILITIES_PTR_PCI_CONFIG)
-	    & RADEON_CAP_PTR_MASK;
+    PCI_READ_LONG(info->PciInfo, &cmd_stat, PCI_CMD_STAT_REG);
+    if (cmd_stat & RADEON_CAP_LIST) {
+	uint32_t cap_ptr, cap_id;
+
+	PCI_READ_LONG(info->PciInfo, &cap_ptr, RADEON_CAPABILITIES_PTR_PCI_CONFIG);
+	cap_ptr &= RADEON_CAP_PTR_MASK;
 
 	while(cap_ptr != RADEON_CAP_ID_NULL) {
-	    cap_id = pciReadLong(info->PciTag, cap_ptr);
+	    PCI_READ_LONG(info->PciInfo, &cap_id, cap_ptr);
 	    if ((cap_id & 0xff)== RADEON_CAP_ID_AGP) {
 		info->cardType = CARD_AGP;
 		break;
@@ -1991,7 +2048,7 @@ static Bool RADEONPreInitInt10(ScrnInfoP
 	/* The VGA BIOS on the RV100/QY cannot be read when the digital output
 	 * is enabled.  Clear and restore FP2_ON around int10 to avoid this.
 	 */
-	if (info->PciInfo->chipType == PCI_CHIP_RV100_QY) {
+	if (PCI_DEV_DEVICE_ID(info->PciInfo) == PCI_CHIP_RV100_QY) {
 	    fp2_gen_ctl_save = INREG(RADEON_FP2_GEN_CNTL);
 	    if (fp2_gen_ctl_save & RADEON_FP2_ON) {
 		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "disabling digital out\n");
@@ -2527,11 +2584,11 @@ _X_EXPORT Bool RADEONPreInit(ScrnInfoPtr
     if (info->pEnt->location.type != BUS_PCI) goto fail;
 
     info->PciInfo = xf86GetPciInfoForEntity(info->pEnt->index);
-    info->PciTag  = pciTag(info->PciInfo->bus,
-			   info->PciInfo->device,
-			   info->PciInfo->func);
-    info->MMIOAddr   = info->PciInfo->memBase[2] & 0xffffff00;
-    info->MMIOSize  = (1 << info->PciInfo->size[2]);
+    info->PciTag  = pciTag(PCI_DEV_BUS(info->PciInfo),
+			   PCI_DEV_DEV(info->PciInfo),
+			   PCI_DEV_FUNC(info->PciInfo));
+    info->MMIOAddr = PCI_REGION_BASE(info->PciInfo, 2, REGION_MEM) & 0xffffff00;
+    info->MMIOSize = PCI_REGION_SIZE(info->PciInfo, 2);
     if (info->pEnt->device->IOBase) {
 	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
 		   "MMIO address override, using 0x%08lx instead of 0x%08lx\n",
@@ -2552,7 +2609,10 @@ _X_EXPORT Bool RADEONPreInit(ScrnInfoPtr
     }
 
 #if !defined(__alpha__)
-    if (xf86GetPciDomain(info->PciTag) ||
+    if (
+#ifndef XSERVER_LIBPCIACCESS
+	xf86GetPciDomain(info->PciTag) ||
+#endif
 	!xf86IsPrimaryPci(info->PciInfo))
 	RADEONPreInt10Save(pScrn, &int10_save);
 #else
@@ -2574,9 +2634,9 @@ _X_EXPORT Bool RADEONPreInit(ScrnInfoPtr
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 	       "PCI bus %d card %d func %d\n",
-	       info->PciInfo->bus,
-	       info->PciInfo->device,
-	       info->PciInfo->func);
+	       PCI_DEV_BUS(info->PciInfo),
+	       PCI_DEV_DEV(info->PciInfo),
+	       PCI_DEV_FUNC(info->PciInfo));
 
     if (xf86RegisterResources(info->pEnt->index, 0, ResExclusive))
 	goto fail;
diff --git a/src/radeon_video.c b/src/radeon_video.c
index dca9695..26857a5 100644
--- a/src/radeon_video.c
+++ b/src/radeon_video.c
@@ -1213,9 +1213,11 @@ RADEONResetVideo(ScrnInfoPtr pScrn)
 
     xvAdjustment      = MAKE_ATOM("XV_DEBUG_ADJUSTMENT");
 
-    sprintf(tmp, "RXXX:%d.%d.%d", info->PciInfo->vendor, info->PciInfo->chipType, info->PciInfo->chipRev);
+    sprintf(tmp, "RXXX:%d.%d.%d", PCI_DEV_VENDOR_ID(info->PciInfo),
+	    PCI_DEV_DEVICE_ID(info->PciInfo), PCI_DEV_REVISION(info->PciInfo));
     pPriv->device_id = MAKE_ATOM(tmp);
-    sprintf(tmp, "PCI:%02d:%02d.%d", info->PciInfo->bus, info->PciInfo->device, info->PciInfo->func);
+    sprintf(tmp, "PCI:%02d:%02d.%d", PCI_DEV_BUS(info->PciInfo),
+	    PCI_DEV_DEV(info->PciInfo), PCI_DEV_FUNC(info->PciInfo));
     pPriv->location_id = MAKE_ATOM(tmp);
     sprintf(tmp, "INSTANCE:%d", pScrn->scrnIndex);
     pPriv->instance_id = MAKE_ATOM(tmp);
diff-tree 7addf41885ec5658f531624a9c24ea5bd7d22d19 (from parents)
Merge: 3a958ba136c3fae5a4ddd56373ac7cd47046f10e 78c6bd305f2ea70629d1dda3c0c48c067451f5fb
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Thu Oct 4 11:06:08 2007 +0200

    Merge remote branch 'origin/pci-rework'

diff-tree 78c6bd305f2ea70629d1dda3c0c48c067451f5fb (from 6ff0645ecfe65727e8ef5d5e6215b4e03078e1a5)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Mon Sep 10 19:00:16 2007 +0300

    [mach64] Revert to multiple mappings per BAR.
    
    libpciaccess added subrange mappings and mtrr handling.
    
    compile-tested only.

diff --git a/src/atistruct.h b/src/atistruct.h
index 3496d2a..d574947 100644
--- a/src/atistruct.h
+++ b/src/atistruct.h
@@ -338,7 +338,7 @@ typedef struct _ATIRec
      * Cursor-related definitions.
      */
     xf86CursorInfoPtr pCursorInfo;
-    pointer pCursorImage;
+    pointer pCursorPage, pCursorImage;
     unsigned long CursorBase;
     CARD32 CursorOffset;
     CARD16 CursorXOffset, CursorYOffset;
diff --git a/src/atividmem.c b/src/atividmem.c
index 69d89ef..8910c73 100644
--- a/src/atividmem.c
+++ b/src/atividmem.c
@@ -67,23 +67,6 @@ 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).
- */
-#ifndef XSERVER_LIBPCIACCESS
-#define nop_setWC(_screenNum, _base, _size, _enable) \
-do {                                                 \
-} while (0)
-#else
-#define nop_setWC(_screenNum, _base, _size, _enable) \
-do {                                                 \
-    /* XXX */                                        \
-} while (0)
-#endif
-
 #ifndef AVOID_CPIO
 
 /*
@@ -122,21 +105,30 @@ ATIUnmapLinear
 {
     pciVideoPtr pVideo = pATI->PCIInfo;
 
-    if (pATI->pMemoryLE)
+    if (pATI->pMemory)
     {
-        if (pATI->LinearBase)
-            nop_setWC(iScreen, pATI->LinearBase, pATI->LinearSize, FALSE);
+#ifndef XSERVER_LIBPCIACCESS
+        xf86UnMapVidMem(iScreen, pATI->pMemory, pATI->LinearSize);
+#else
+        pci_device_unmap_range(pVideo, pATI->pMemory, pATI->LinearSize);
+#endif
+
+#if X_BYTE_ORDER != X_LITTLE_ENDIAN
 
+        if (pATI->pMemoryLE)
+        {
 #ifndef XSERVER_LIBPCIACCESS
-        xf86UnMapVidMem(iScreen, pATI->pMemoryLE, (1U << pVideo->size[0]));
+            xf86UnMapVidMem(iScreen, pATI->pMemoryLE, pATI->LinearSize);
 #else
-        pci_device_unmap_region(pVideo, 0);
+            pci_device_unmap_range(pVideo, pATI->pMemoryLE, pATI->LinearSize);
 #endif
+        }
+
+#endif /* X_BYTE_ORDER */
+
     }
 
     pATI->pMemory = pATI->pMemoryLE = NULL;
-
-    pATI->pCursorImage = NULL;
 }
 
 /*
@@ -158,7 +150,7 @@ ATIUnmapMMIO
 #ifndef XSERVER_LIBPCIACCESS
         xf86UnMapVidMem(iScreen, pATI->pMMIO, getpagesize());
 #else
-        pci_device_unmap_region(pVideo, 2);
+        pci_device_unmap_range(pVideo, pATI->pMMIO, getpagesize());
 #endif
     }
 
@@ -166,6 +158,32 @@ ATIUnmapMMIO
 }
 
 /*
+ * ATIUnmapCursor --
+ *
+ * Unmap hardware cursor image area.
+ */
+static void
+ATIUnmapCursor
+(
+    int    iScreen,
+    ATIPtr pATI
+)
+{
+    pciVideoPtr pVideo = pATI->PCIInfo;
+
+    if (pATI->pCursorPage)
+    {
+#ifndef XSERVER_LIBPCIACCESS
+        xf86UnMapVidMem(iScreen, pATI->pCursorPage, getpagesize());
+#else
+        pci_device_unmap_range(pVideo, pATI->pCursorPage, getpagesize());
+#endif
+    }
+
+    pATI->pCursorPage = pATI->pCursorImage = NULL;
+}
+
+/*
  * ATIMapApertures --
  *
  * This function maps all apertures used by the driver.
@@ -182,7 +200,13 @@ ATIMapApertures
     ATIPtr pATI
 )
 {
-    pciVideoPtr pVideo = pATI->PCIInfo;
+    pciVideoPtr   pVideo = pATI->PCIInfo;
+#ifndef XSERVER_LIBPCIACCESS
+    PCITAG        Tag = PCI_CFG_TAG(pVideo);
+#else
+    pciVideoPtr   Tag = pVideo;
+#endif
+    unsigned long PageSize = getpagesize();
 
     if (pATI->Mapped)
         return TRUE;
@@ -197,10 +221,10 @@ ATIMapApertures
          * aperture is supported.  Hence, the hard-coded values here...
          */
             pATI->pBank = xf86MapDomainMemory(iScreen, VIDMEM_MMIO_32BIT,
-                PCI_CFG_TAG(pVideo), 0x000A0000U, 0x00010000U);
+                Tag, 0x000A0000U, 0x00010000U);
 
         if (!pATI->pBank)
-            goto bail;
+            return FALSE;
 
         pATI->Mapped = TRUE;
     }
@@ -208,131 +232,226 @@ ATIMapApertures
 #endif /* AVOID_CPIO */
 
     /* Map linear aperture */
-    if (pATI->LinearBase || (pATI->Block0Base && pATI->MMIOInLinear))
+    if (pATI->LinearBase)
     {
 
 #ifndef XSERVER_LIBPCIACCESS
 
-        int 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, PCI_CFG_TAG(pVideo),
-                                        pVideo->memBase[0],
-                                        (1U << pVideo->size[0]));
+            pATI->pMemory = xf86MapPciMem(iScreen, VIDMEM_FRAMEBUFFER,
+                Tag, pATI->LinearBase, pATI->LinearSize);
 
 #else /* XSERVER_LIBPCIACCESS */
 
-        int err = pci_device_map_region(pVideo, 0, TRUE);
-    
+        int mode = PCI_DEV_MAP_FLAG_WRITABLE | PCI_DEV_MAP_FLAG_WRITE_COMBINE;
+
+        int err = pci_device_map_range(pVideo,
+                                       pATI->LinearBase,
+                                       pATI->LinearSize,
+                                       mode, &pATI->pMemory);
+
         if (err)
-            pATI->pMemoryLE = NULL;
-        else
-            pATI->pMemoryLE = pVideo->regions[0].memory;
+        {
+            xf86DrvMsg (iScreen, X_ERROR,
+                    "Unable to map linear aperture. %s (%d)\n",
+                    strerror (err), err);
+        }
 
 #endif /* XSERVER_LIBPCIACCESS */
 
-        if (!pATI->pMemoryLE)
-            goto bail;
+        if (!pATI->pMemory)
+        {
+
+#ifndef AVOID_CPIO
+
+            ATIUnmapVGA(iScreen, pATI);
+
+#endif /* AVOID_CPIO */
+
+            pATI->Mapped = FALSE;
+            return FALSE;
+        }
 
         pATI->Mapped = TRUE;
 
 #if X_BYTE_ORDER == X_LITTLE_ENDIAN
 
-        pATI->pMemory = pATI->pMemoryLE;
+        if ((pATI->CursorBase >= pATI->LinearBase) &&
+            ((pATI->CursorOffset + 0x00000400UL) <= (CARD32)pATI->LinearSize))
+            pATI->pCursorImage = (char *)pATI->pMemory + pATI->CursorOffset;
+
+        pATI->pMemoryLE = pATI->pMemory;
 
 #else /* if X_BYTE_ORDER != X_LITTLE_ENDIAN */
 
-        pATI->pMemory = (char *)pATI->pMemoryLE + 0x00800000U;
+        /*
+         * Map the little-endian aperture (used for video, etc.).  Note that
+         * caching of this area is _not_ wanted.
+         */
+        {
+
+#ifndef XSERVER_LIBPCIACCESS
+
+            pATI->pMemoryLE = xf86MapPciMem(iScreen, VIDMEM_MMIO, Tag,
+                pATI->LinearBase - 0x00800000U, pATI->LinearSize);
 
-#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);
+#else /* XSERVER_LIBPCIACCESS */
+
+        int mode = PCI_DEV_MAP_FLAG_WRITABLE;
+
+        int err = pci_device_map_range(pVideo,
+                                       pATI->LinearBase - 0x00800000U,
+                                       pATI->LinearSize,
+                                       mode, &pATI->pMemoryLE);
+
+        if (err)
+        {
+            xf86DrvMsg (iScreen, X_ERROR,
+                    "Unable to map extended linear aperture. %s (%d)\n",
+                    strerror (err), err);
+        }
+
+#endif /* XSERVER_LIBPCIACCESS */
+
+            if (!pATI->pMemoryLE)
+            {
+                ATIUnmapLinear(iScreen, pATI);
+
+#ifndef AVOID_CPIO
+
+                ATIUnmapVGA(iScreen, pATI);
+
+#endif /* AVOID_CPIO */
+
+                pATI->Mapped = FALSE;
+                return FALSE;
+            }
+        }
+
+#endif /* X_BYTE_ORDER */
 
-        if (pATI->CursorBase)
-            pATI->pCursorImage = (char *)pATI->pMemoryLE + pATI->CursorOffset;
     }
 
     /* Map MMIO aperture */
-    if (pATI->Block0Base && !pATI->MMIOInLinear)
+    if (pATI->Block0Base)
     {
+        unsigned long MMIOBase = pATI->Block0Base & ~(PageSize - 1);
 
 #ifndef XSERVER_LIBPCIACCESS
 
-        int mode = VIDMEM_MMIO;
-    
-        pATI->pMMIO = xf86MapPciMem(iScreen, mode, PCI_CFG_TAG(pVideo),
-                                    pVideo->memBase[2],
-                                    getpagesize());
+            pATI->pMMIO = xf86MapPciMem(iScreen, VIDMEM_MMIO,
+                Tag, MMIOBase, PageSize);
 
 #else /* XSERVER_LIBPCIACCESS */
 
-        int err = pci_device_map_region(pVideo, 2, TRUE);
-    
+        int mode = PCI_DEV_MAP_FLAG_WRITABLE;
+
+        int err = pci_device_map_range(pVideo,
+                                       MMIOBase,
+                                       PageSize,
+                                       mode, &pATI->pMMIO);
+
         if (err)
-            pATI->pMMIO = NULL;
-        else
-            pATI->pMMIO = pVideo->regions[2].memory;
+        {
+            xf86DrvMsg (iScreen, X_ERROR,
+                    "Unable to map mmio aperture. %s (%d)\n",
+                    strerror (err), err);
+        }
 
 #endif /* XSERVER_LIBPCIACCESS */
 
         if (!pATI->pMMIO)
-            goto bail;
+        {
 
-        pATI->Mapped = TRUE;
+#if X_BYTE_ORDER == X_LITTLE_ENDIAN
 
-        pATI->pBlock[0] = (char *)pATI->pMMIO + 0x00000400U;
+            ATIUnmapCursor(iScreen, pATI);
 
-        if (pATI->Block1Base)
-            pATI->pBlock[1] = (char *)pATI->pBlock[0] - 0x00000400U;
-    }
-    else if (pATI->Block0Base)
-    {
-        unsigned long mmio_offset, linear_size;
+#endif /* X_BYTE_ORDER */
 
-        mmio_offset = pATI->Block0Base - PCI_REGION_BASE(pVideo, 0, REGION_MEM);
+            ATIUnmapLinear(iScreen, pATI);
 
-        linear_size = PCI_REGION_SIZE(pVideo, 0);
+#ifndef AVOID_CPIO
 
-        pATI->pMMIO = NULL;
+            ATIUnmapVGA(iScreen, pATI);
 
-        /* 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)
-            goto bail;
+#endif /* AVOID_CPIO */
+
+            pATI->Mapped = FALSE;
+            return FALSE;
+        }
 
         pATI->Mapped = TRUE;
 
-        pATI->pBlock[0] = (char *)pATI->pMemoryLE + mmio_offset;
+        pATI->pBlock[0] = (char *)pATI->pMMIO +
+            (pATI->Block0Base - MMIOBase);
 
         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);
+        }
     }
 
-    return TRUE;
+    /* Map hardware cursor image area */
+    if (pATI->CursorBase && !pATI->pCursorImage)
+    {
+        unsigned long CursorBase = pATI->CursorBase & ~(PageSize - 1);
 
-bail:
+#ifndef XSERVER_LIBPCIACCESS
 
-    ATIUnmapLinear(iScreen, pATI);
+            pATI->pCursorPage = xf86MapPciMem(iScreen, VIDMEM_FRAMEBUFFER,
+                Tag, CursorBase, PageSize);
+
+#else /* XSERVER_LIBPCIACCESS */
+
+        int mode = PCI_DEV_MAP_FLAG_WRITABLE | PCI_DEV_MAP_FLAG_WRITE_COMBINE;
+
+        int err = pci_device_map_range(pVideo,
+                                       CursorBase,
+                                       PageSize,
+                                       mode, &pATI->pCursorPage);
+
+        if (err)
+        {
+            xf86DrvMsg (iScreen, X_ERROR,
+                    "Unable to map cursor aperture. %s (%d)\n",
+                    strerror (err), err);
+        }
+
+#endif /* XSERVER_LIBPCIACCESS */
+
+        if (!pATI->pCursorPage)
+        {
+            ATIUnmapCursor(iScreen, pATI);
+            ATIUnmapMMIO(iScreen, pATI);
+            ATIUnmapLinear(iScreen, pATI);
 
 #ifndef AVOID_CPIO
 
-    ATIUnmapVGA(iScreen, pATI);
+            ATIUnmapVGA(iScreen, pATI);
 
 #endif /* AVOID_CPIO */
 
-    pATI->Mapped = FALSE;
+            pATI->Mapped = FALSE;
+            return FALSE;
+        }
+
+        pATI->pCursorImage = (char *)pATI->pCursorPage +
+            (pATI->CursorBase - CursorBase);
+    }
 
-    return FALSE;
+    return TRUE;
 }
 
 /*
@@ -351,6 +470,9 @@ ATIUnmapApertures
         return;
     pATI->Mapped = FALSE;
 
+    /* Unmap hardware cursor image area */
+    ATIUnmapCursor(iScreen, pATI);
+
     /* Unmap MMIO area */
     ATIUnmapMMIO(iScreen, pATI);
 
diff-tree 6ff0645ecfe65727e8ef5d5e6215b4e03078e1a5 (from 7b38d9a1209f87255e5bb0aefe46a363ce4fb6ef)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Tue Aug 28 15:37:11 2007 +0300

    [mach64] Convert to pci-rework, keeping source-code compatibility.
    
    It still uses the old probe method though, this is due to the ati wrapper.

diff --git a/configure.ac b/configure.ac
index 0c413c8..03b3440 100644
--- a/configure.ac
+++ b/configure.ac
@@ -204,10 +204,20 @@ AC_CHECK_DECL(xf86XVFillKeyHelperDrawabl
 	      [],
 	      [#include <xf86xv.h>])
 
+AC_CHECK_DECL(XSERVER_LIBPCIACCESS,
+	      [XSERVER_LIBPCIACCESS=yes],[XSERVER_LIBPCIACCESS=no],
+	      [#include "xorg-server.h"])
+
 CPPFLAGS="$SAVE_CPPFLAGS"
 
 AM_CONDITIONAL(USE_EXA, test "x$USE_EXA" = xyes)
 
+if test "x$XSERVER_LIBPCIACCESS" = xyes; then
+    PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.8.0])
+    XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
+fi
+AM_CONDITIONAL(XSERVER_LIBPCIACCESS, test "x$XSERVER_LIBPCIACCESS" = xyes)
+
 AC_SUBST([XORG_CFLAGS])
 AC_SUBST([DRI_CFLAGS])
 AC_SUBST([moduledir])
diff --git a/src/Makefile.am b/src/Makefile.am
index dd7007e..16cbb66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,6 +66,9 @@ atimisc_drv_la_SOURCES = \
 	atiload.c atimisc.c atimach64probe.c $(ATIMISC_CPIO_SOURCES) \
 	$(ATIMISC_DGA_SOURCES) $(ATIMISC_DRI_SRCS) $(ATIMISC_EXA_SOURCES)
 
+if XSERVER_LIBPCIACCESS
+# r128, radeon and theatre have not been ported yet
+else
 r128_drv_la_LTLIBRARIES = r128_drv.la
 r128_drv_la_LDFLAGS = -module -avoid-version
 r128_drv_ladir = @moduledir@/drivers
@@ -103,6 +106,7 @@ theatre200_drv_la_CFLAGS = \
 	$(AM_CFLAGS) -DMICROC_DIR=\"$(theatre200_drv_ladir)\"
 theatre200_drv_la_SOURCES = \
 	theatre200.c theatre200_module.c
+endif
 
 EXTRA_DIST = \
 	atimach64render.c \
diff --git a/src/ati.c b/src/ati.c
index 3f6cc0c..ada165f 100644
--- a/src/ati.c
+++ b/src/ati.c
@@ -57,6 +57,9 @@
 #include "config.h"
 #endif
 
+#ifdef XSERVER_LIBPCIACCESS
+#include <pciaccess.h>
+#endif
 #include "atipcirename.h"
 
 #include "ati.h"
@@ -67,6 +70,22 @@
 #include "radeon_probe.h"
 #include "r128_probe.h"
 
+#ifdef XSERVER_LIBPCIACCESS
+static const struct pci_id_match ati_device_match = {
+    PCI_VENDOR_ATI, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0
+};
+
+/* Stolen from xf86pciBus.c */
+/* PCI classes that get included in xf86PciVideoInfo */
+#define PCIINFOCLASSES(c) \
+    (  (((c) & 0x00ff0000) == (PCI_CLASS_PREHISTORIC << 16)) ||           \
+       (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) ||               \
+      ((((c) & 0x00ffff00) == ((PCI_CLASS_MULTIMEDIA << 16) |             \
+                               (PCI_SUBCLASS_MULTIMEDIA_VIDEO << 8)))) || \
+      ((((c) & 0x00ffff00) == ((PCI_CLASS_PROCESSOR << 16) |              \
+                               (PCI_SUBCLASS_PROCESSOR_COPROC << 8)))) )
+#endif
+
 /*
  * ATIIdentify --
  *
@@ -101,11 +120,17 @@ ATIProbe
 )
 {
     pciVideoPtr pVideo;
+#ifndef XSERVER_LIBPCIACCESS
     pciVideoPtr *xf86PciVideoInfo;
+#else
+    struct pci_device_iterator *pVideoIter;
+#endif
     Bool        DoMach64 = FALSE;
     Bool        DoRage128 = FALSE, DoRadeon = FALSE;
     ATIChipType Chip;
 
+#ifndef XSERVER_LIBPCIACCESS
+
     xf86PciVideoInfo = xf86GetPciVideoInfo();
 
     if (xf86PciVideoInfo == NULL)
@@ -127,6 +152,35 @@ ATIProbe
             DoRadeon = TRUE;
     }
 
+#else /* XSERVER_LIBPCIACCESS */
+
+    pVideoIter = pci_id_match_iterator_create(&ati_device_match);
+
+    while ((pVideo = pci_device_next(pVideoIter)) != NULL)
+    {
+        /* Check for non-video devices */
+        if (!PCIINFOCLASSES(pVideo->device_class))
+            continue;
+
+        /* Check for prehistoric PCI 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(PCI_DEV_DEVICE_ID(pVideo), PCI_DEV_REVISION(pVideo));
+        if (Chip <= ATI_CHIP_Mach64)
+            DoMach64 = TRUE;
+        else if (Chip <= ATI_CHIP_Rage128)
+            DoRage128 = TRUE;
+        else if (Chip <= ATI_CHIP_Radeon)
+            DoRadeon = TRUE;
+    }
+
+    pci_iterator_destroy(pVideoIter);
+
+#endif /* XSERVER_LIBPCIACCESS */
+
     /* Call Radeon driver probe */
     if (DoRadeon)
     {
diff --git a/src/atimach64probe.c b/src/atimach64probe.c
index c5330cc..2f716a1 100644
--- a/src/atimach64probe.c
+++ b/src/atimach64probe.c
@@ -146,8 +146,10 @@ Mach64Probe(DriverPtr pDriver, int flags
     int     numUsed;
     Bool    ProbeSuccess = FALSE;
 
+#ifndef XSERVER_LIBPCIACCESS
     if (xf86GetPciVideoInfo() == NULL)
         return FALSE;
+#endif
 
     if ((numDevSections = xf86MatchDevice(ATI_DRIVER_NAME, &devSections)) <= 0)
         return FALSE;
diff --git a/src/atipcirename.h b/src/atipcirename.h
index 280a81a..e30d10c 100644
--- a/src/atipcirename.h
+++ b/src/atipcirename.h
@@ -34,7 +34,7 @@ enum region_type {
     REGION_IO 
 };
 
-#ifndef PCIACCESS
+#ifndef XSERVER_LIBPCIACCESS
 
 /* pciVideoPtr */
 #define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor)
@@ -71,7 +71,7 @@ enum region_type {
 #define PCI_WRITE_LONG(_pcidev, _value, _offset) \
     pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value))
 
-#else /* PCIACCESS */
+#else /* XSERVER_LIBPCIACCESS */
 
 typedef struct pci_device *pciVideoPtr;
 
@@ -105,6 +105,6 @@ typedef struct pci_device *pciVideoPtr;
 #define PCI_WRITE_LONG(_pcidev, _value, _offset) \
     pci_device_cfg_write_u32((_pcidev), (_value), (_offset))
 
-#endif /* PCIACCESS */
+#endif /* XSERVER_LIBPCIACCESS */
 
 #endif /* ATIPCIRENAME_H */
diff --git a/src/atiprobe.c b/src/atiprobe.c
index cddcc61..78b3edd 100644
--- a/src/atiprobe.c
+++ b/src/atiprobe.c
@@ -385,10 +385,12 @@ ATIMach64ProbeIO
         uint32_t PciReg;
         uint32_t j;
 
+#ifndef XSERVER_LIBPCIACCESS
         pciConfigPtr pPCI = pVideo->thisCard;
 
         if (pPCI == NULL)
             goto SkipSparse;
+#endif
 
         PCI_READ_LONG(pVideo, &PciReg, PCI_REG_USERCONFIG);
         j = PciReg & 0x03U;
diff --git a/src/atividmem.c b/src/atividmem.c
index 7ab203e..69d89ef 100644
--- a/src/atividmem.c
+++ b/src/atividmem.c
@@ -73,9 +73,16 @@ const char *ATIMemoryTypeNames_264xT[] =
  *
  * It is called implicitely by xf86MapPciMem(VIDMEM_FRAMEBUFFER).
  */
+#ifndef XSERVER_LIBPCIACCESS
 #define nop_setWC(_screenNum, _base, _size, _enable) \
 do {                                                 \
 } while (0)
+#else
+#define nop_setWC(_screenNum, _base, _size, _enable) \
+do {                                                 \
+    /* XXX */                                        \
+} while (0)
+#endif
 
 #ifndef AVOID_CPIO
 
@@ -120,7 +127,11 @@ ATIUnmapLinear
         if (pATI->LinearBase)
             nop_setWC(iScreen, pATI->LinearBase, pATI->LinearSize, FALSE);
 
+#ifndef XSERVER_LIBPCIACCESS
         xf86UnMapVidMem(iScreen, pATI->pMemoryLE, (1U << pVideo->size[0]));
+#else
+        pci_device_unmap_region(pVideo, 0);
+#endif
     }
 
     pATI->pMemory = pATI->pMemoryLE = NULL;
@@ -140,8 +151,16 @@ ATIUnmapMMIO
     ATIPtr pATI
 )
 {
+    pciVideoPtr pVideo = pATI->PCIInfo;
+
     if (pATI->pMMIO)
+    {
+#ifndef XSERVER_LIBPCIACCESS
         xf86UnMapVidMem(iScreen, pATI->pMMIO, getpagesize());
+#else
+        pci_device_unmap_region(pVideo, 2);
+#endif
+    }
 
     pATI->pMMIO = pATI->pBlock[0] = pATI->pBlock[1] = NULL;
 }
@@ -163,8 +182,7 @@ ATIMapApertures
     ATIPtr pATI
 )
 {
-    pciVideoPtr   pVideo = pATI->PCIInfo;
-    int           mode;
+    pciVideoPtr pVideo = pATI->PCIInfo;
 
     if (pATI->Mapped)
         return TRUE;
@@ -192,18 +210,32 @@ ATIMapApertures
     /* Map linear aperture */
     if (pATI->LinearBase || (pATI->Block0Base && pATI->MMIOInLinear))
     {
-        mode = VIDMEM_FRAMEBUFFER;
 
+#ifndef XSERVER_LIBPCIACCESS
+
+        int 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, PCI_CFG_TAG(pVideo),
                                         pVideo->memBase[0],
                                         (1U << pVideo->size[0]));
 
+#else /* XSERVER_LIBPCIACCESS */
+
+        int err = pci_device_map_region(pVideo, 0, TRUE);
+    
+        if (err)
+            pATI->pMemoryLE = NULL;
+        else
+            pATI->pMemoryLE = pVideo->regions[0].memory;
+
+#endif /* XSERVER_LIBPCIACCESS */
+
         if (!pATI->pMemoryLE)
             goto bail;
 
@@ -230,11 +262,26 @@ ATIMapApertures
     /* Map MMIO aperture */
     if (pATI->Block0Base && !pATI->MMIOInLinear)
     {
-        mode = VIDMEM_MMIO;
+
+#ifndef XSERVER_LIBPCIACCESS
+
+        int mode = VIDMEM_MMIO;
+    
         pATI->pMMIO = xf86MapPciMem(iScreen, mode, PCI_CFG_TAG(pVideo),
                                     pVideo->memBase[2],
                                     getpagesize());
 
+#else /* XSERVER_LIBPCIACCESS */
+
+        int err = pci_device_map_region(pVideo, 2, TRUE);
+    
+        if (err)
+            pATI->pMMIO = NULL;
+        else
+            pATI->pMMIO = pVideo->regions[2].memory;
+
+#endif /* XSERVER_LIBPCIACCESS */
+
         if (!pATI->pMMIO)
             goto bail;
 
diff --git a/src/r128_probe.c b/src/r128_probe.c
index 81ff663..b2298df 100644
--- a/src/r128_probe.c
+++ b/src/r128_probe.c
@@ -144,7 +144,9 @@ R128Probe(DriverPtr drv, int flags)
     Bool          foundScreen = FALSE;
     int           i;
 
+#ifndef XSERVER_LIBPCIACCESS
     if (!xf86GetPciVideoInfo()) return FALSE;
+#endif
 
     /* Collect unclaimed device sections for both driver names */
     nATIGDev = xf86MatchDevice(ATI_NAME, &ATIGDevs);
diff --git a/src/radeon_probe.c b/src/radeon_probe.c
index c697f65..b7c38ad 100644
--- a/src/radeon_probe.c
+++ b/src/radeon_probe.c
@@ -237,7 +237,9 @@ RADEONProbe(DriverPtr drv, int flags)
     Bool     foundScreen = FALSE;
     int      i;
 
+#ifndef XSERVER_LIBPCIACCESS
     if (!xf86GetPciVideoInfo()) return FALSE;
+#endif
 
     /* Collect unclaimed device sections for both driver names */
     nATIGDev    = xf86MatchDevice(ATI_NAME, &ATIGDevs);
diff-tree 7b38d9a1209f87255e5bb0aefe46a363ce4fb6ef (from parents)
Merge: 2e3d43af1e5077cc61dd8668551a6291368d9ed2 673f799729824f4439dd5f681f75dd5aab50947f
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Tue Aug 28 16:01:12 2007 +0300

    Merge branch 'master' into pci-rework
    
    Conflicts:
    
    	src/ati.c

diff --cc src/ati.c
index 803ac0b,423fd95..3f6cc0c
@@@ -57,10 -57,8 +57,10 @@@
  #include "config.h"
  #endif
  
 +#include "atipcirename.h"
 +
  #include "ati.h"
- #include "atichip.h"
+ #include "atimodule.h"
  #include "ativersion.h"
  #include "atimach64probe.h"
  
@@@ -99,20 -98,30 +100,30 @@@
      int       flags
  )
  {
-     pciVideoPtr pVideo, *xf86PciVideoInfo = xf86GetPciVideoInfo();
-     Bool        ProbeSuccess = FALSE;
+     pciVideoPtr pVideo;
+     pciVideoPtr *xf86PciVideoInfo;
      Bool        DoMach64 = FALSE;
      Bool        DoRage128 = FALSE, DoRadeon = FALSE;
-     int         i;
      ATIChipType Chip;
  
-     if (!(flags & PROBE_DETECT))
+     xf86PciVideoInfo = xf86GetPciVideoInfo();
+ 
+     if (xf86PciVideoInfo == NULL)
+         return FALSE;
+ 
+     while ((pVideo = *xf86PciVideoInfo++) != NULL)
      {
-         if (xf86MatchDevice(ATI_NAME, NULL) > 0)
 -        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)
              DoMach64 = TRUE;
-         if (xf86MatchDevice(R128_NAME, NULL) > 0)
+         else if (Chip <= ATI_CHIP_Rage128)
              DoRage128 = TRUE;
-         if (xf86MatchDevice(RADEON_NAME, NULL) > 0)
+         else if (Chip <= ATI_CHIP_Radeon)
              DoRadeon = TRUE;
      }
  
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