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

George Sapountzis gsap7 at kemper.freedesktop.org
Fri Mar 16 18:41:33 EET 2007


 src/Makefile.am    |    3 -
 src/atidri.c       |   25 +++++-------
 src/atipcirename.h |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/atipreinit.c   |    2 
 src/atiprint.c     |   10 ++--
 src/atiprobe.c     |   52 +++++++++++++------------
 src/atistruct.h    |    2 
 src/atividmem.c    |   11 ++---
 8 files changed, 165 insertions(+), 50 deletions(-)

New commits:
diff-tree c3b57b1e6ea0c37ef0e84680b8451b4b6ac81f5b (from 246005c80e1e3e9e4fe67bbda3c3b9f1169500d4)
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Fri Mar 16 18:40:53 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/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 7cc9908..0dc6d9a 100644
--- a/src/atipreinit.c
+++ b/src/atipreinit.c
@@ -1770,7 +1770,7 @@ ATIPreInit
                 int AcceleratorVideoRAM = 0, ServerVideoRAM;
 
                 /* 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;
                 }
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 1a55d9e..0b5357d 100644
--- a/src/atiprobe.c
+++ b/src/atiprobe.c
@@ -215,15 +215,15 @@ ATIMach64Probe
     const ATIChipType Chip
 )
 {
-    CARD16 ChipType = pVideo->chipType;
+    CARD16 ChipType = PCI_DEV_DEVICE_ID(pVideo);
 
         /*
          * Probe through auxiliary MMIO aperture if one exists.  Because such
          * 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))
@@ -236,13 +236,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;
 
@@ -271,10 +271,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))
@@ -374,21 +374,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)
@@ -396,7 +397,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;
         }
@@ -416,14 +417,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;
@@ -433,7 +437,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
         {
@@ -441,7 +445,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)
@@ -453,7 +457,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;
@@ -466,23 +470,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;
 
@@ -491,7 +495,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
 
@@ -505,7 +509,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 597ebd9..b6c4090 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 043bfe4..e6e15c9 100644
--- a/src/atividmem.c
+++ b/src/atividmem.c
@@ -149,7 +149,6 @@ ATIMapApertures
 )
 {
     pciVideoPtr   pVideo = pATI->PCIInfo;
-    PCITAG        Tag = ((pciConfigPtr)(pVideo->thisCard))->tag;
     int           mode;
 
     if (pATI->Mapped)
@@ -165,7 +164,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;
@@ -186,7 +185,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]));
 
@@ -229,7 +228,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());
 
@@ -258,9 +257,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;
 



More information about the xorg-commit mailing list