summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac12
-rw-r--r--src/ast.h10
-rw-r--r--src/ast_driver.c20
-rw-r--r--src/ast_pcirename.h122
-rw-r--r--src/ast_tool.c44
5 files changed, 196 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac
index c033ee2..52af4cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,10 +58,22 @@ PKG_CHECK_MODULES(XORG, [xorg-server >= 1.0.99.901 xproto fontsproto $REQUIRED_M
sdkdir=$(pkg-config --variable=sdkdir xorg-server)
# Checks for libraries.
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $XORG_CFLAGS"
+AC_CHECK_DECL(XSERVER_LIBPCIACCESS,
+ [XSERVER_LIBPCIACCESS=yes],[XSERVER_LIBPCIACCESS=no],
+ [#include "xorg-server.h"])
+CPPFLAGS="$SAVE_CPPFLAGS"
# Checks for header files.
AC_HEADER_STDC
+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([moduledir])
diff --git a/src/ast.h b/src/ast.h
index e7376c6..cc878e9 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -23,6 +23,8 @@
#include <string.h>
#include <stdlib.h>
+#include "ast_pcirename.h"
+
/* Compiler Options */
#define Accel_2D
/* #define MMIO_2D */
@@ -130,8 +132,12 @@ typedef struct {
typedef struct _ASTRec {
EntityInfoPtr pEnt;
- pciVideoPtr PciInfo;
- PCITAG PciTag;
+#ifndef XSERVER_LIBPCIACCESS
+ pciVideoPtr PciInfo;
+ PCITAG PciTag;
+#else
+ struct pci_device *PciInfo;
+#endif
OptionInfoPtr Options;
DisplayModePtr ModePtr;
diff --git a/src/ast_driver.c b/src/ast_driver.c
index da18748..5ae07e3 100644
--- a/src/ast_driver.c
+++ b/src/ast_driver.c
@@ -339,6 +339,7 @@ ASTProbe(DriverPtr drv, int flags)
return FALSE;
}
+#ifndef XSERVER_LIBPCIACCESS
/*
* This probing is just checking the PCI data the server already
* collected.
@@ -346,6 +347,7 @@ ASTProbe(DriverPtr drv, int flags)
if (xf86GetPciVideoInfo() == NULL) {
return FALSE;
}
+#endif
numUsed = xf86MatchPciInstances(AST_NAME, PCI_VENDOR_AST,
ASTChipsets, ASTPciChipsets,
@@ -517,8 +519,10 @@ ASTPreInit(ScrnInfoPtr pScrn, int flags)
pAST = ASTPTR(pScrn);
pAST->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
pAST->PciInfo = xf86GetPciInfoForEntity(pAST->pEnt->index);
+#ifndef XSERVER_LIBPCIACCESS
pAST->PciTag = pciTag(pAST->PciInfo->bus, pAST->PciInfo->device,
pAST->PciInfo->func);
+#endif
/* Process the options
* pScrn->confScreen, pScrn->display, pScrn->monitor, pScrn->numEntities,
@@ -549,7 +553,7 @@ ASTPreInit(ScrnInfoPtr pScrn, int flags)
} else {
from = X_PROBED;
pScrn->chipset = (char *)xf86TokenToString(ASTChipsets,
- pAST->PciInfo->chipType);
+ PCI_DEV_DEVICE_ID(pAST->PciInfo));
}
if (pAST->pEnt->device->chipRev >= 0) {
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
@@ -568,16 +572,16 @@ ASTPreInit(ScrnInfoPtr pScrn, int flags)
/* "Patch" the PIOOffset inside vgaHW in order to force
* the vgaHW module to use our relocated i/o ports.
*/
- VGAHWPTR(pScrn)->PIOOffset = pAST->PIOOffset = pAST->IODBase + pAST->PciInfo->ioBase[2] - 0x380;
+ VGAHWPTR(pScrn)->PIOOffset = pAST->PIOOffset = pAST->IODBase + PCI_REGION_BASE(pAST->PciInfo, 2, REGION_IO) - 0x380;
- pAST->RelocateIO = (IOADDRESS)(pAST->PciInfo->ioBase[2] + pAST->IODBase);
+ pAST->RelocateIO = (IOADDRESS)(PCI_REGION_BASE(pAST->PciInfo, 2, REGION_IO) + pAST->IODBase);
if (pAST->pEnt->device->MemBase != 0) {
pAST->FBPhysAddr = pAST->pEnt->device->MemBase;
from = X_CONFIG;
} else {
- if (pAST->PciInfo->memBase[0] != 0) {
- pAST->FBPhysAddr = pAST->PciInfo->memBase[0] & 0xFFF00000;
+ if (PCI_REGION_BASE(pAST->PciInfo, 0, REGION_MEM) != 0) {
+ pAST->FBPhysAddr = PCI_REGION_BASE(pAST->PciInfo, 0, REGION_MEM) & 0xFFF00000;
from = X_PROBED;
} else {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
@@ -593,8 +597,8 @@ ASTPreInit(ScrnInfoPtr pScrn, int flags)
pAST->MMIOPhysAddr = pAST->pEnt->device->IOBase;
from = X_CONFIG;
} else {
- if (pAST->PciInfo->memBase[1]) {
- pAST->MMIOPhysAddr = pAST->PciInfo->memBase[1] & 0xFFFF0000;
+ if (PCI_REGION_BASE(pAST->PciInfo, 1, REGION_MEM)) {
+ pAST->MMIOPhysAddr = PCI_REGION_BASE(pAST->PciInfo, 1, REGION_IO) & 0xFFFF0000;
from = X_PROBED;
} else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
@@ -633,7 +637,7 @@ ASTPreInit(ScrnInfoPtr pScrn, int flags)
pScrn->fbOffset = 0;
/* Get Revision */
- if (pAST->PciInfo->chipRev >= 0x10)
+ if (PCI_DEV_REVISION(pAST->PciInfo) >= 0x10)
pAST->jChipType = AST2100;
else
pAST->jChipType = AST2000;
diff --git a/src/ast_pcirename.h b/src/ast_pcirename.h
new file mode 100644
index 0000000..cbd3dcf
--- /dev/null
+++ b/src/ast_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 ASTPCIRENAME_H
+#define ASTPCIRENAME_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 /* CIRPCIRENAME_H */
diff --git a/src/ast_tool.c b/src/ast_tool.c
index 7a2165d..11d3085 100644
--- a/src/ast_tool.c
+++ b/src/ast_tool.c
@@ -67,10 +67,24 @@ ASTMapMem(ScrnInfoPtr pScrn)
{
ASTRecPtr pAST = ASTPTR(pScrn);
-
+#ifndef XSERVER_LIBPCIACCESS
pAST->FBVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER,
pAST->PciTag,
pAST->FBPhysAddr, pAST->FbMapSize);
+#else
+ {
+ void** result = (void**)&pAST->FBVirtualAddr;
+ int err = pci_device_map_range(pAST->PciInfo,
+ pAST->FBPhysAddr,
+ pAST->FbMapSize,
+ PCI_DEV_MAP_FLAG_WRITABLE |
+ PCI_DEV_MAP_FLAG_WRITE_COMBINE,
+ result);
+
+ if (err)
+ return FALSE;
+ }
+#endif
if (!pAST->FBVirtualAddr)
return FALSE;
@@ -82,9 +96,13 @@ Bool
ASTUnmapMem(ScrnInfoPtr pScrn)
{
ASTRecPtr pAST = ASTPTR(pScrn);
-
+
+#ifndef XSERVER_LIBPCIACCESS
xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pAST->FBVirtualAddr,
pAST->FbMapSize);
+#else
+ pci_device_unmap_range(pAST->PciInfo, pAST->FBVirtualAddr, pAST->FbMapSize);
+#endif
pAST->FBVirtualAddr = 0;
@@ -97,15 +115,33 @@ ASTMapMMIO(ScrnInfoPtr pScrn)
int mmioFlags;
ASTRecPtr pAST = ASTPTR(pScrn);
+#ifndef XSERVER_LIBPCIACCESS
+
#if !defined(__alpha__)
mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT;
#else
mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT | VIDMEM_SPARSE;
#endif
+
pAST->MMIOVirtualAddr = xf86MapPciMem(pScrn->scrnIndex, mmioFlags,
pAST->PciTag,
pAST->MMIOPhysAddr, pAST->MMIOMapSize);
+
+#else
+ {
+ void** result = (void**)&pAST->MMIOVirtualAddr;
+ int err = pci_device_map_range(pAST->PciInfo,
+ pAST->MMIOPhysAddr,
+ pAST->MMIOMapSize,
+ PCI_DEV_MAP_FLAG_WRITABLE,
+ result);
+
+ if (err)
+ return FALSE;
+ }
+
+#endif
if (!pAST->MMIOVirtualAddr)
return FALSE;
@@ -117,8 +153,12 @@ ASTUnmapMMIO(ScrnInfoPtr pScrn)
{
ASTRecPtr pAST = ASTPTR(pScrn);
+#ifndef XSERVER_LIBPCIACCESS
xf86UnMapVidMem(pScrn->scrnIndex, (pointer) pAST->MMIOVirtualAddr,
pAST->MMIOMapSize);
+#else
+ pci_device_unmap_range(pAST->PciInfo, pAST->MMIOVirtualAddr, pAST->MMIOMapSize);
+#endif
pAST->MMIOVirtualAddr = 0;
}