summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2008-03-11 10:45:08 +1000
committerDave Airlie <airlied@redhat.com>2008-03-11 10:45:22 +1000
commitd1e29902483a82e86b07cd30d41d411e71b776ea (patch)
tree4e3d37cba2a8a192c2f79f42fa1a87396b28c510 /src
parent5d2abb8ff9fdcfab6d5fe4f16acf302cb6811d58 (diff)
pcirename conversion
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/apm.h3
-rw-r--r--src/apm_driver.c51
-rw-r--r--src/apm_pcirename.h122
4 files changed, 173 insertions, 6 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d641e62..8a6779e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,7 +35,8 @@ apm_drv_la_SOURCES = \
apm_driver.c \
apm.h \
apm_i2c.c \
- apm_regs.h
+ apm_regs.h \
+ apm_pcirename.h
if XF86RUSH
apm_drv_la_SOURCES += apm_rush.c
diff --git a/src/apm.h b/src/apm.h
index a9f9e79..f938257 100644
--- a/src/apm.h
+++ b/src/apm.h
@@ -1,5 +1,6 @@
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/apm/apm.h,v 1.19tsi Exp $ */
+#include "apm_pcirename.h"
#include <string.h>
/* All drivers should typically include these */
@@ -104,7 +105,9 @@ typedef struct {
typedef struct {
pciVideoPtr PciInfo;
+#ifndef XSERVER_LIBPCIACCESS
PCITAG PciTag;
+#endif
int scrnIndex;
int Chipset;
int ChipRev;
diff --git a/src/apm_driver.c b/src/apm_driver.c
index 81356a0..831a463 100644
--- a/src/apm_driver.c
+++ b/src/apm_driver.c
@@ -550,12 +550,16 @@ ApmPreInit(ScrnInfoPtr pScrn, int flags)
pEnt = pApm->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
if (pEnt->location.type == BUS_PCI) {
pApm->PciInfo = xf86GetPciInfoForEntity(pEnt->index);
+#ifndef XSERVER_LIBPCIACCESS
pApm->PciTag = pciTag(pApm->PciInfo->bus, pApm->PciInfo->device,
pApm->PciInfo->func);
+#endif
}
else {
pApm->PciInfo = NULL;
+#ifndef XSERVER_LIBPCIACCESS
pApm->PciTag = 0;
+#endif
}
if (flags & PROBE_DETECT) {
@@ -653,10 +657,15 @@ ApmPreInit(ScrnInfoPtr pScrn, int flags)
/* Default to 8 */
pScrn->rgbBits = 8;
}
+#ifndef XSERVER_LIBPCIACCESS
+ /* you're getting a linear framebuffer with pciaccess */
if (xf86ReturnOptValBool(pApm->Options, OPTION_NOLINEAR, FALSE)) {
pApm->noLinear = TRUE;
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "No linear framebuffer\n");
}
+#else
+ pApm->noLinear = FALSE;
+#endif
from = X_DEFAULT;
pApm->hwCursor = FALSE;
if (xf86GetOptValBool(pApm->Options, OPTION_HW_CURSOR, &pApm->hwCursor))
@@ -778,7 +787,7 @@ ApmPreInit(ScrnInfoPtr pScrn, int flags)
} else {
from = X_PROBED;
if (pApm->PciInfo)
- pApm->Chipset = pApm->PciInfo->chipType;
+ pApm->Chipset = PCI_DEV_DEVICE_ID(pApm->PciInfo);
else
pApm->Chipset = pEnt->chipset;
pScrn->chipset = (char *)xf86TokenToString(ApmChipsets, pApm->Chipset);
@@ -794,7 +803,7 @@ ApmPreInit(ScrnInfoPtr pScrn, int flags)
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
pApm->ChipRev);
} else if (pApm->PciInfo) {
- pApm->ChipRev = pApm->PciInfo->chipRev;
+ pApm->ChipRev = PCI_DEV_REVISION(pApm->PciInfo);
}
/*
@@ -818,7 +827,7 @@ ApmPreInit(ScrnInfoPtr pScrn, int flags)
pApm->LinAddress = pEnt->device->MemBase;
from = X_CONFIG;
} else if (pApm->PciInfo) {
- pApm->LinAddress = pApm->PciInfo->memBase[0] & 0xFF800000;
+ pApm->LinAddress = PCI_REGION_BASE(pApm->PciInfo, 0, REGION_MEM) & 0xFF800000;
from = X_PROBED;
} else {
/*
@@ -883,9 +892,24 @@ ApmPreInit(ScrnInfoPtr pScrn, int flags)
/*unsigned long save;*/
volatile unsigned char *LinMap;
+#ifndef XSERVER_LIBPCIACCESS
LinMap = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO,
pApm->PciTag, pApm->LinAddress,
pApm->LinMapSize);
+#else
+ {
+ void** result = (void**)&LinMap;
+ int err = pci_device_map_range(pApm->PciInfo,
+ pApm->LinAddress,
+ pApm->LinMapSize,
+ PCI_DEV_MAP_FLAG_WRITABLE,
+ result);
+
+ if (err)
+ return FALSE;
+ }
+#endif
+
/*save = pciReadLong(pApm->PciTag, PCI_CMD_STAT_REG);
pciWriteLong(pApm->PciTag, PCI_CMD_STAT_REG, save | PCI_CMD_MEM_ENABLE);*/
d9 = LinMap[0xFFECD9];
@@ -1211,10 +1235,27 @@ ApmMapMem(ScrnInfoPtr pScrn)
APMDECL(pScrn);
vgaHWPtr hwp = VGAHWPTR(pScrn);
+#ifndef XSERVER_LIBPCIACCESS
pApm->LinMap = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER,
pApm->PciTag,
(unsigned long)pApm->LinAddress,
pApm->LinMapSize);
+#else
+ {
+ void** result = (void**)&pApm->LinMap;
+ int err = pci_device_map_range(pApm->PciInfo,
+ pApm->LinAddress,
+ pApm->LinMapSize,
+ PCI_DEV_MAP_FLAG_WRITABLE |
+ PCI_DEV_MAP_FLAG_WRITE_COMBINE,
+ result);
+
+ if (err)
+ return FALSE;
+ }
+#endif
+
+
if (pApm->LinMap == NULL)
return FALSE;
@@ -1877,8 +1918,8 @@ ApmScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
/* Map the chip memory and MMIO areas */
if (pApm->noLinear) {
- pApm->saveCmd = pciReadLong(pApm->PciTag, PCI_CMD_STAT_REG);
- pciWriteLong(pApm->PciTag, PCI_CMD_STAT_REG, pApm->saveCmd | (PCI_CMD_IO_ENABLE|PCI_CMD_MEM_ENABLE));
+ PCI_READ_LONG(pApm->PciInfo, &pApm->saveCmd, PCI_CMD_STAT_REG);
+ PCI_WRITE_LONG(pApm->PciInfo, pApm->saveCmd | (PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE), PCI_CMD_STAT_REG);
pApm->FbBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER,
pApm->PciTag, 0xA0000, 0x10000);
}
diff --git a/src/apm_pcirename.h b/src/apm_pcirename.h
new file mode 100644
index 0000000..f0f5cf8
--- /dev/null
+++ b/src/apm_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 CIRPCIRENAME_H
+#define CIRPCIRENAME_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 */