[PATCH 1/2] imstt libpciaccess conversion.

Paulo Cesar Pereira de Andrade pcpa at mandriva.com.br
Mon Feb 9 13:14:19 PST 2009


  Conversion based on method used on other drivers.

  Not tested due to lack of hardware, but should be functional,
and known to compile cleanly and not have missing symbols.

Signed-off-by: Paulo Cesar Pereira de Andrade <pcpa at mandriva.com.br>
---
 src/imstt.h           |    2 +-
 src/imstt_driver.c    |   57 ++++++++++++++++++++--
 src/imstt_pcirename.h |  122 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+), 7 deletions(-)
 create mode 100644 src/imstt_pcirename.h

diff --git a/src/imstt.h b/src/imstt.h
index 483002f..b7d07f9 100644
--- a/src/imstt.h
+++ b/src/imstt.h
@@ -7,7 +7,7 @@
 #include "xf86Pci.h"
 #include "xf86PciInfo.h"
 #include "xaa.h"
-
+#include "imstt_pcirename.h"
 
 typedef struct _IMSTTRec {
 	pciVideoPtr		PciInfo;
diff --git a/src/imstt_driver.c b/src/imstt_driver.c
index 1dfa30d..0fb35c9 100644
--- a/src/imstt_driver.c
+++ b/src/imstt_driver.c
@@ -39,7 +39,6 @@
 #include "xf86_OSproc.h"
 #include "xf86PciInfo.h"
 #include "xf86Pci.h"
-#include "xf86Version.h"
 #include "xf86Resources.h"
 #include "xf86fbman.h"
 #include "compiler.h"
@@ -275,8 +274,10 @@ static Bool IMSTTProbe(DriverPtr drv, int flags)
 	/* sanity checks */
 	if ((numDevSections = xf86MatchDevice("imstt", &devSections)) <= 0)
 		return FALSE;
+#ifndef XSERVER_LIBPCIACCESS
 	if (xf86GetPciVideoInfo() == NULL)
 		return FALSE;
+#endif
 
 	numUsed = xf86MatchPciInstances("imstt", PCI_VENDOR_IMS,
 					IMSTTChipsets, IMSTTPciChipsets,
@@ -444,7 +445,7 @@ static Bool IMSTTPreInit(ScrnInfoPtr pScrn, int flags)
 	xf86SetOperatingState(resVgaIo, pEnt->index, ResUnusedOpr);
 	xf86SetOperatingState(resVgaMem, pEnt->index, ResDisableOpr);
 
-	pScrn->memPhysBase = iptr->PciInfo->memBase[0];
+	pScrn->memPhysBase = PCI_REGION_BASE(iptr->PciInfo, 0, REGION_MEM);
 	pScrn->fbOffset = 0;
 
 	if (pEnt->device->chipset && *pEnt->device->chipset) {
@@ -457,7 +458,7 @@ static Bool IMSTTPreInit(ScrnInfoPtr pScrn, int flags)
 		xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",
 			   iptr->Chipset);
 	} else {
-		iptr->Chipset = iptr->PciInfo->chipType;
+		iptr->Chipset = PCI_DEV_DEVICE_ID(iptr->PciInfo);
 		pScrn->chipset = (char *)xf86TokenToString(IMSTTChipsets,
 							   iptr->Chipset);
 	}
@@ -467,14 +468,15 @@ static Bool IMSTTPreInit(ScrnInfoPtr pScrn, int flags)
 		xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
 			   iptr->ChipRev);
 	} else
-		iptr->ChipRev = iptr->PciInfo->chipRev;
+		iptr->ChipRev = PCI_DEV_REVISION(iptr->PciInfo);
 
 	xfree(pEnt);
 
 	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Chipset: \"%s\"\n", pScrn->chipset);
 
-	iptr->PciTag = pciTag(iptr->PciInfo->bus, iptr->PciInfo->device,
-			      iptr->PciInfo->func);
+#ifndef XSERVER_LIBPCIACCESS
+	iptr->PciTag = PCI_DEV_TAG(iptr->PciInfo);
+#endif
 
 	if (!xf86SetGamma(pScrn, gzeros))
 		return FALSE;
@@ -569,9 +571,19 @@ static Bool IMSTTMapMem(ScrnInfoPtr pScrn)
 
 	iptr = IMSTTPTR(pScrn);
 
+#ifndef XSERVER_LIBPCIACCESS
 	iptr->MMIOBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO, iptr->PciTag,
 				       iptr->PciInfo->memBase[0] + 0x800000,
 				       0x41000);
+#else
+	if (pci_device_map_range(iptr->PciInfo,
+				 /* FIXME Is this correct? */
+				 PCI_REGION_BASE(iptr->PciInfo, 0, REGION_MEM)
+				     + 0x800000, 0x41000,
+				 PCI_DEV_MAP_FLAG_WRITABLE,
+				 (void **)&iptr->MMIOBase))
+		return FALSE;
+#endif
 	if (!iptr->MMIOBase) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 			   "Internal error: could not map MMIO\n");
@@ -585,9 +597,19 @@ static Bool IMSTTMapMem(ScrnInfoPtr pScrn)
 	if (iptr->FBDev) {
 		iptr->FBBase = fbdevHWMapVidmem(pScrn);
 	} else {
+#ifndef XSERVER_LIBPCIACCESS
 		iptr->FBBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER, iptr->PciTag,
 					     iptr->PciInfo->memBase[0],
 					     iptr->videoRam);
+#else
+	if (pci_device_map_range(iptr->PciInfo,
+				 PCI_REGION_BASE(iptr->PciInfo, 0, REGION_MEM),
+				 iptr->videoRam,
+				 PCI_DEV_MAP_FLAG_WRITABLE |
+				 PCI_DEV_MAP_FLAG_WRITE_COMBINE,
+				 (void **)&iptr->FBBase))
+		return FALSE;
+#endif
 	}
 	if (!iptr->FBBase) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
@@ -596,9 +618,19 @@ static Bool IMSTTMapMem(ScrnInfoPtr pScrn)
 	}
 
 	if (iptr->InitDAC) {
+#ifndef XSERVER_LIBPCIACCESS
 		iptr->CMAPBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO, iptr->PciTag,
 					       iptr->PciInfo->memBase[0] + 0x840000,
 					       0x1000);
+#else
+		if (pci_device_map_range(iptr->PciInfo,
+					 /* FIXME Is this correct? */
+					 PCI_REGION_BASE(iptr->PciInfo, 0, REGION_MEM)
+					     + 0x840000, 0x1000,
+					 PCI_DEV_MAP_FLAG_WRITABLE,
+					 (void **)&iptr->MMIOBase))
+			return FALSE;
+#endif
 		if (!iptr->CMAPBase) {
 			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 				   "Internal error: could not map CMAP\n");
@@ -621,20 +653,33 @@ static void IMSTTUnmapMem(ScrnInfoPtr pScrn)
 	if (iptr->FBDev) {
 		fbdevHWUnmapMMIO(pScrn);
 	} else {
+#ifndef XSERVER_LIBPCIACCESS
 		xf86UnMapVidMem(pScrn->scrnIndex, (pointer)iptr->MMIOBase,
 				0x1000);
+#else
+		pci_device_unmap_range(iptr->PciInfo, iptr->MMIOBase, 0x1000);
+#endif
 	}
 
 	if (iptr->InitDAC) {
+#ifndef XSERVER_LIBPCIACCESS
 		xf86UnMapVidMem(pScrn->scrnIndex, (pointer)iptr->CMAPBase,
 				0x1000);
+#else
+		pci_device_unmap_range(iptr->PciInfo, iptr->CMAPBase, 0x1000);
+#endif
 	}
 
 	if (iptr->FBDev) {
 		fbdevHWUnmapVidmem(pScrn);
 	} else {
+#ifndef XSERVER_LIBPCIACCESS
 		xf86UnMapVidMem(pScrn->scrnIndex, (pointer)iptr->FBBase,
 				iptr->videoRam);
+#else
+		pci_device_unmap_range(iptr->PciInfo, iptr->FBBase,
+				       iptr->videoRam);
+#endif
 	}
 
 	return;
diff --git a/src/imstt_pcirename.h b/src/imstt_pcirename.h
new file mode 100644
index 0000000..f7eb4fe
--- /dev/null
+++ b/src/imstt_pcirename.h
@@ -0,0 +1,122 @@
+/*
+ * 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 IMSTT_PCIRENAME_H
+#define IMSTT_PCIRENAME_H
+
+enum region_type {
+    REGION_MEM,
+    REGION_IO
+};
+
+#ifndef XSERVER_LIBPCIACCESS
+
+/* 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_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)
+#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_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))
+
+#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
+    pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value))
+
+#else /* XSERVER_LIBPCIACCESS */
+
+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)
+
+#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)
+
+/* 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_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))
+
+#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
+    pci_device_cfg_write_u32((_pcidev), (_value), (_offset))
+
+#endif /* XSERVER_LIBPCIACCESS */
+
+#endif /* IMSTT_PCIRENAME_H */
-- 
1.6.1

------=_20090209194625_59915--



More information about the xorg-devel mailing list