[PATCH 1/3] Add libpciaccess support.
Paulo Cesar Pereira de Andrade
pcpa at mandriva.com.br
Fri Feb 6 14:01:04 PST 2009
This matches the pattern used for all other lesser maintained
drivers, and, if not already functional, should require very few
changes to finish libpciaccess conversion.
It compiles cleanly and doesn't have any missing symbols.
Signed-off-by: Paulo Cesar Pereira de Andrade <pcpa at mandriva.com.br>
---
configure.ac | 8 +++
src/Makefile.am | 1 +
src/cyrix.h | 1 +
src/cyrix_driver.c | 70 +++++++++++++++-------------
src/cyrix_pcirename.h | 122 +++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 170 insertions(+), 32 deletions(-)
create mode 100644 src/cyrix_pcirename.h
diff --git a/configure.ac b/configure.ac
index c163f0b..a6fc9ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,6 +57,14 @@ XORG_DRIVER_CHECK_EXT(XFreeXDGA, xf86dgaproto)
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.0.99.901 xproto fontsproto $REQUIRED_MODULES])
sdkdir=$(pkg-config --variable=sdkdir xorg-server)
+save_CFLAGS="$CFLAGS"
+CFLAGS="$XORG_CFLAGS"
+AC_CHECK_DECL(xf86ConfigIsaEntity,
+ [AC_DEFINE(HAVE_ISA, 1, [Have ISA support])],
+ [],
+ [#include "xf86.h"])
+CFLAGS="$save_CFLAGS"
+
# Checks for libraries.
# Checks for header files.
diff --git a/src/Makefile.am b/src/Makefile.am
index 24bcbff..778e7cc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,4 +34,5 @@ cyrix_drv_la_SOURCES = \
cyrix_driver.c \
cyrix.h \
cyrix_helper.c \
+ cyrix_pcirename.h \
cyrix_shadow.c
diff --git a/src/cyrix.h b/src/cyrix.h
index 162b009..9edd1d8 100644
--- a/src/cyrix.h
+++ b/src/cyrix.h
@@ -45,6 +45,7 @@
#include "xaa.h"
#include "xf86Cursor.h"
#include "vgaHW.h"
+#include "cyrix_pcirename.h"
#include <string.h>
/* this code is partly based on the MediaGX sources from the GGI project
diff --git a/src/cyrix_driver.c b/src/cyrix_driver.c
index 66fb89b..721d127 100644
--- a/src/cyrix_driver.c
+++ b/src/cyrix_driver.c
@@ -61,7 +61,6 @@
#include "micmap.h"
#include "xf86.h"
#include "xf86_OSproc.h"
-#include "xf86Version.h"
#include "xf86PciInfo.h"
#include "xf86Pci.h"
#include "xf86cmap.h"
@@ -154,10 +153,12 @@ static SymTabRec CYRIXChipsets[] = {
{ -1, NULL }
};
+#if HAVE_ISA
static IsaChipsets CYRIXISAChipsets[] = {
{ CHIP_CYRIXmediagx, RES_EXCLUSIVE_VGA },
{ -1, 0 }
};
+#endif
typedef enum {
OPTION_SW_CURSOR,
@@ -362,7 +363,7 @@ static PciChipsets CYRIXPCIchipsets[] = {
static Bool
CYRIXProbe(DriverPtr drv, int flags)
{
- int i, numDevSections, numUsed, *usedChips;
+ int i, numDevSections, numUsed, *usedChips = NULL;
GDevPtr *devSections;
ScrnInfoPtr pScrn;
Bool foundScreen = FALSE;
@@ -395,41 +396,44 @@ CYRIXProbe(DriverPtr drv, int flags)
/* Should look like an ISA device */
/* PCI BUS */
- if (xf86GetPciVideoInfo() ) {
- numUsed = xf86MatchPciInstances(CYRIX_NAME, PCI_VENDOR_CYRIX,
- CYRIXChipsets, CYRIXPCIchipsets,
- devSections,numDevSections,
- drv, &usedChips);
-
- if (numUsed > 0) {
- if (flags & PROBE_DETECT)
+#ifndef XSERVER_LIBPCIACCESS
+ if (xf86GetPciVideoInfo())
+ return FALSE;
+#endif
+
+ numUsed = xf86MatchPciInstances(CYRIX_NAME, PCI_VENDOR_CYRIX,
+ CYRIXChipsets, CYRIXPCIchipsets,
+ devSections,numDevSections,
+ drv, &usedChips);
+
+ if (numUsed > 0) {
+ if (flags & PROBE_DETECT)
+ foundScreen = TRUE;
+ else for (i = 0; i < numUsed; i++) {
+ ScrnInfoPtr pScrn = NULL;
+ /* Allocate a ScrnInfoRec and claim the slot */
+ if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
+ CYRIXPCIchipsets,NULL, NULL,
+ NULL, NULL, NULL))) {
+ pScrn->driverVersion = CYRIX_VERSION;
+ pScrn->driverName = CYRIX_DRIVER_NAME;
+ pScrn->name = CYRIX_NAME;
+ pScrn->Probe = CYRIXProbe;
+ pScrn->PreInit = CYRIXPreInit;
+ pScrn->ScreenInit = CYRIXScreenInit;
+ pScrn->SwitchMode = CYRIXSwitchMode;
+ pScrn->AdjustFrame = CYRIXAdjustFrame;
+ pScrn->LeaveVT = CYRIXLeaveVT;
+ pScrn->EnterVT = CYRIXEnterVT;
+ pScrn->FreeScreen = CYRIXFreeScreen;
+ pScrn->ValidMode = CYRIXValidMode;
foundScreen = TRUE;
- else for (i = 0; i < numUsed; i++) {
- ScrnInfoPtr pScrn = NULL;
- /* Allocate a ScrnInfoRec and claim the slot */
- if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
- CYRIXPCIchipsets,NULL, NULL,
- NULL, NULL, NULL))) {
- pScrn->driverVersion = CYRIX_VERSION;
- pScrn->driverName = CYRIX_DRIVER_NAME;
- pScrn->name = CYRIX_NAME;
- pScrn->Probe = CYRIXProbe;
- pScrn->PreInit = CYRIXPreInit;
- pScrn->ScreenInit = CYRIXScreenInit;
- pScrn->SwitchMode = CYRIXSwitchMode;
- pScrn->AdjustFrame = CYRIXAdjustFrame;
- pScrn->LeaveVT = CYRIXLeaveVT;
- pScrn->EnterVT = CYRIXEnterVT;
- pScrn->FreeScreen = CYRIXFreeScreen;
- pScrn->ValidMode = CYRIXValidMode;
- foundScreen = TRUE;
- }
}
- xfree(usedChips);
}
+ xfree(usedChips);
}
-
+#if HAVE_ISA
numUsed = xf86MatchIsaInstances(CYRIX_NAME,CYRIXChipsets,
CYRIXISAChipsets,drv,
CYRIXFindIsaDevice,devSections,
@@ -465,6 +469,8 @@ CYRIXProbe(DriverPtr drv, int flags)
}
}
xfree(usedChips);
+#endif
+
return (foundScreen);
}
diff --git a/src/cyrix_pcirename.h b/src/cyrix_pcirename.h
new file mode 100644
index 0000000..93dcc1d
--- /dev/null
+++ b/src/cyrix_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 CYRIX_PCIRENAME_H
+#define CYRIX_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 /* SMIPCIRENAME_H */
--
1.6.1
------=_20090206205709_24023--
More information about the xorg-devel
mailing list