[PATCH] PCI: Remove pciBusAddrToHostAddr and associated nonsense
Adam Jackson
ajax at redhat.com
Fri Feb 13 15:39:08 PST 2009
This was all a glorified no-op. We rely on pciaccess to create device
maps anyway, so we should have no reason to care about what the host
address is.
---
hw/xfree86/common/xf86pciBus.c | 31 -----
hw/xfree86/os-support/bus/Pci.c | 17 ---
hw/xfree86/os-support/bus/Pci.h | 13 --
hw/xfree86/os-support/bus/linuxPci.c | 77 ------------
hw/xfree86/os-support/linux/Makefile.am | 2 +-
hw/xfree86/os-support/linux/lnx_pci.c | 193 -------------------------------
hw/xfree86/os-support/xf86_OSproc.h | 2 -
7 files changed, 1 insertions(+), 334 deletions(-)
delete mode 100644 hw/xfree86/os-support/linux/lnx_pci.c
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 786a2b9..854a837 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -920,37 +920,6 @@ pciConvertRange2Host(int entityIndex, resRange *pRange)
if (!(pRange->type & ResBus))
return;
- switch(pRange->type & ResPhysMask) {
- case ResMem:
- switch(pRange->type & ResExtMask) {
- case ResBlock:
- pRange->rBegin = pciBusAddrToHostAddr(tag,PCI_MEM, pRange->rBegin);
- pRange->rEnd = pciBusAddrToHostAddr(tag,PCI_MEM, pRange->rEnd);
- break;
- case ResSparse:
- pRange->rBase = pciBusAddrToHostAddr(tag,PCI_MEM_SPARSE_BASE,
- pRange->rBegin);
- pRange->rMask = pciBusAddrToHostAddr(tag,PCI_MEM_SPARSE_MASK,
- pRange->rEnd);
- break;
- }
- break;
- case ResIo:
- switch(pRange->type & ResExtMask) {
- case ResBlock:
- pRange->rBegin = pciBusAddrToHostAddr(tag,PCI_IO, pRange->rBegin);
- pRange->rEnd = pciBusAddrToHostAddr(tag,PCI_IO, pRange->rEnd);
- break;
- case ResSparse:
- pRange->rBase = pciBusAddrToHostAddr(tag,PCI_IO_SPARSE_BASE
- , pRange->rBegin);
- pRange->rMask = pciBusAddrToHostAddr(tag,PCI_IO_SPARSE_MASK
- , pRange->rEnd);
- break;
- }
- break;
- }
-
/* Set domain number */
pRange->type &= ~(ResDomain | ResBus);
pRange->type |= pvp->domain << 24;
diff --git a/hw/xfree86/os-support/bus/Pci.c b/hw/xfree86/os-support/bus/Pci.c
index 8c1aa6e..6a1c6a8 100644
--- a/hw/xfree86/os-support/bus/Pci.c
+++ b/hw/xfree86/os-support/bus/Pci.c
@@ -138,29 +138,12 @@
/* Global data */
-pciBusFuncs_t *pciBusFuncs = NULL;
-
-ADDRESS
-pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
-{
- if (pciBusFuncs && pciBusFuncs->pciAddrBusToHost)
- return pciBusFuncs->pciAddrBusToHost(tag, type, addr);
- else
- return addr;
-}
-
PCITAG
pciTag(int busnum, int devnum, int funcnum)
{
return(PCI_MAKE_TAG(busnum,devnum,funcnum));
}
-ADDRESS
-pciAddrNOOP(PCITAG tag, PciAddrType type, ADDRESS addr)
-{
- return(addr);
-}
-
Bool
xf86scanpci(void)
{
diff --git a/hw/xfree86/os-support/bus/Pci.h b/hw/xfree86/os-support/bus/Pci.h
index 5feb733..3a3f3d7 100644
--- a/hw/xfree86/os-support/bus/Pci.h
+++ b/hw/xfree86/os-support/bus/Pci.h
@@ -183,17 +183,4 @@
extern void ARCH_PCI_INIT(void);
-/*
- * Table of functions used to access a specific PCI bus domain
- * (e.g. a primary PCI bus and all of its secondaries)
- */
-typedef struct pci_bus_funcs {
- ADDRESS (*pciAddrBusToHost)(PCITAG, PciAddrType, ADDRESS);
-} pciBusFuncs_t, *pciBusFuncs_p;
-
-/* Generic PCI service functions and helpers */
-ADDRESS pciAddrNOOP(PCITAG tag, PciAddrType type, ADDRESS);
-
-extern pciBusFuncs_t *pciBusFuncs;
-
#endif /* _PCI_H */
diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
index a84ac8f..a60df25 100644
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ b/hw/xfree86/os-support/bus/linuxPci.c
@@ -57,29 +57,6 @@
#include "Pci.h"
#include <dirent.h>
-/*
- * linux platform specific PCI access functions -- using /proc/bus/pci
- * needs kernel version 2.2.x
- */
-static ADDRESS linuxTransAddrBusToHost(PCITAG tag, PciAddrType type, ADDRESS addr);
-#if defined(__powerpc__)
-static ADDRESS linuxPpcBusAddrToHostAddr(PCITAG, PciAddrType, ADDRESS);
-#endif
-
-static pciBusFuncs_t linuxFuncs0 = {
-#if defined(__powerpc__)
-/* pciAddrBusToHost */ linuxPpcBusAddrToHostAddr,
-#else
-/* linuxTransAddrBusToHost is busted on sparc64 but the PCI rework tree
- * makes it all moot, so we kludge it for now */
-#if defined(__sparc__)
-/* pciAddrBusToHost */ pciAddrNOOP,
-#else
-/* pciAddrBusToHost */ linuxTransAddrBusToHost,
-#endif /* __sparc64__ */
-#endif
-};
-
static const struct pci_id_match match_host_bridge = {
PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
(PCI_CLASS_BRIDGE << 16) | (PCI_SUBCLASS_BRIDGE_HOST << 8),
@@ -95,13 +72,6 @@ linuxPciInit(void)
struct stat st;
memset(DomainMmappedIO, 0, sizeof(DomainMmappedIO));
-
- if (-1 == stat("/proc/bus/pci", &st)) {
- /* when using this as default for all linux architectures,
- we'll need a fallback for 2.0 kernels here */
- return;
- }
- pciBusFuncs = &linuxFuncs0;
}
/**
@@ -179,53 +149,6 @@ linuxPciOpenFile(struct pci_device *dev, Bool write)
}
/*
- * This function will convert a BAR address into a host address
- * suitable for passing into the mmap function of a /proc/bus
- * device.
- */
-ADDRESS linuxTransAddrBusToHost(PCITAG tag, PciAddrType type, ADDRESS addr)
-{
- ADDRESS ret = xf86GetOSOffsetFromPCI(tag, PCI_MEM|PCI_IO, addr);
-
- if (ret)
- return ret;
-
- /*
- * if it is not a BAR address, it must be legacy, (or wrong)
- * return it as is..
- */
- return addr;
-}
-
-
-#if defined(__powerpc__)
-
-#ifndef __NR_pciconfig_iobase
-#define __NR_pciconfig_iobase 200
-#endif
-
-static ADDRESS
-linuxPpcBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
-{
- if (type == PCI_MEM)
- {
- ADDRESS membase = syscall(__NR_pciconfig_iobase, 1,
- PCI_BUS_FROM_TAG(tag), PCI_DFN_FROM_TAG(tag));
- return (addr + membase);
- }
- else if (type == PCI_IO)
- {
- ADDRESS iobase = syscall(__NR_pciconfig_iobase, 2,
- PCI_BUS_FROM_TAG(tag), PCI_DFN_FROM_TAG(tag));
- return (addr + iobase);
- }
- else return addr;
-}
-
-#endif /* __powerpc__ */
-
-
-/*
* Compiling the following simply requires the presence of <linux/pci.c>.
* Actually running this is another matter altogether...
*
diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index da1dcf6..81bd055 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -26,7 +26,7 @@ XORG_CFLAGS += -DHAVE_APM
endif
liblinux_la_SOURCES = lnx_init.c lnx_video.c \
- lnx_pci.c lnx_agp.c lnx_kmod.c lnx_bell.c \
+ lnx_agp.c lnx_kmod.c lnx_bell.c \
$(srcdir)/../shared/bios_mmap.c \
$(srcdir)/../shared/VTsw_usl.c \
$(srcdir)/../shared/posix_tty.c \
diff --git a/hw/xfree86/os-support/linux/lnx_pci.c b/hw/xfree86/os-support/linux/lnx_pci.c
deleted file mode 100644
index 8eedfa4..0000000
--- a/hw/xfree86/os-support/linux/lnx_pci.c
+++ /dev/null
@@ -1,193 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <X11/X.h>
-#include "os.h"
-#include "xf86.h"
-#include "xf86Priv.h"
-#define XF86_OS_PRIVS
-#include "xf86_OSproc.h"
-#include "xf86Pci.h"
-#include "Pci.h"
-
-#ifdef __sparc__
-#define PCIADDR_TYPE long long
-#define PCIADDR_IGNORE_FMT "%*x"
-#define PCIADDR_FMT "%llx"
-#else
-#define PCIADDR_TYPE long
-#define PCIADDR_IGNORE_FMT "%*x"
-#define PCIADDR_FMT "%lx"
-#endif
-
-struct pci_dev {
- unsigned int domain;
- unsigned int bus;
- unsigned int dev;
- unsigned int fn;
- PCIADDR_TYPE offset[7];
- PCIADDR_TYPE size[7];
- struct pci_dev *next;
-};
-
-struct pci_dev *xf86OSLinuxPCIDevs = NULL;
-int xf86OSLinuxNumPciDevs = 0;
-
-static struct pci_dev *xf86OSLinuxGetPciDevs(void) {
- char c[0x200];
- FILE *file = NULL;
- DIR *dir;
- struct dirent *dirent;
- struct pci_dev *tmp, *ret = NULL;
- unsigned int i, num, devfn;
- unsigned PCIADDR_TYPE begin, end;
- char *res;
-
- /* Try 2.6 devices first, with domain support */
- if ( (dir = opendir ("/sys/bus/pci/devices")) ) {
- xf86OSLinuxNumPciDevs = 0;
- while ( (dirent = readdir (dir)) ) {
- unsigned int domain, bus, dev, fn;
- if (sscanf (dirent->d_name, "%04x:%02x:%02x.%01x",
- &domain, &bus, &dev, &fn) == 4) {
- tmp = xcalloc (sizeof(struct pci_dev), 1);
- tmp->domain = domain;
- tmp->bus = bus;
- tmp->dev = dev;
- tmp->fn = fn;
- sprintf (c, "/sys/bus/pci/devices/%12s/resource",
- dirent->d_name);
- i = 0;
- if ( (file = fopen (c, "r")) ) {
- while (i < 7 && fgets (c, 0x200, file)) {
- if (sscanf (c, PCIADDR_FMT " " PCIADDR_FMT " "
- PCIADDR_IGNORE_FMT, &begin, &end) == 2) {
- tmp->offset[i] = begin;
- tmp->size[i] = begin ? end-begin+1 : 0;
- i++;
- }
- }
- fclose (file);
- }
- if (i > 0) {
- tmp->next = ret;
- ret = tmp;
- xf86OSLinuxNumPciDevs++;
- } else
- xfree (tmp);
- }
- }
- closedir (dir);
- }
-
- if (ret)
- return ret;
-
- file = fopen("/proc/bus/pci/devices", "r");
- if (!file) return NULL;
-
- xf86OSLinuxNumPciDevs = 0;
-
- do {
- res = fgets(c, 0x1ff, file);
- if (res) {
- tmp = xcalloc(sizeof(struct pci_dev),1);
- num = sscanf(res,
- /*bus+dev vendorid deviceid irq */
- "%02x%02x\t%*04x%*04x\t%*x"
- /* 7 PCI resource base addresses */
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- /* 7 PCI resource sizes, and then optionally a driver name */
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT
- "\t" PCIADDR_FMT,
- &tmp->bus,&devfn,&tmp->offset[0],&tmp->offset[1],&tmp->offset[2],&tmp->offset[3],
- &tmp->offset[4],&tmp->offset[5],&tmp->offset[6], &tmp->size[0], &tmp->size[1], &tmp->size[2],
- &tmp->size[3], &tmp->size[4], &tmp->size[5], &tmp->size[6]);
- tmp->dev = devfn >> 3;
- tmp->fn = devfn & 0x7;
- if (num != 16) { /* apparantly not 2.3 style */
- xfree(tmp);
- fclose(file);
- return NULL;
- }
- if (ret) {
- tmp->next = ret;
- }
- ret = tmp;
- xf86OSLinuxNumPciDevs++;
- }
- } while (res);
- fclose(file);
- return ret;
-}
-
-/* Query the kvirt address (64bit) of a BAR range from size for a given TAG */
-unsigned long
-xf86GetOSOffsetFromPCI(PCITAG tag, int space, unsigned long base)
-{
- unsigned int ndx;
- struct pci_dev *device;
- struct pci_device *dev;
-
- if (!xf86OSLinuxPCIDevs) {
- xf86OSLinuxPCIDevs = xf86OSLinuxGetPciDevs();
- }
- if (!xf86OSLinuxPCIDevs) {
- return FALSE;
- }
-
- for (device = xf86OSLinuxPCIDevs; device; device = device->next) {
- dev = pci_device_find_by_slot(device->domain, device->bus,
- device->dev, device->fn);
- if (dev != NULL) {
- /* ok now look through all the BAR values of this device */
- for (ndx=0; ndx<7; ndx++) {
- uint32_t savePtr;
- uint32_t flagMask;
-
- /* The ROM BAR isn't with the other BARs.
- */
- const pciaddr_t offset = (ndx == 6)
- ? (4 * 12) : (4 * ndx) + 16;
-
- pci_device_cfg_read_u32(dev, &savePtr, offset);
-
- /* Ignore unset base addresses. The kernel may have reported
- * non-zero size and address even if they are disabled (e.g.,
- * disabled ROM BAR).
- */
- if (savePtr == 0)
- continue;
-
- /* Remove memory attribute bits, different for IO
- * and memory ranges.
- */
- flagMask = (savePtr & 0x1) ? ~0x3UL : ~0xFUL;
- savePtr &= flagMask;
-
- /* find the index of the incoming base */
- if (base >= savePtr && base < (savePtr + device->size[ndx])) {
- return (device->offset[ndx] & flagMask) + (base - savePtr);
- }
- }
- }
- }
-
- return 0;
-}
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index cd2394e..5760888 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -224,8 +224,6 @@ extern _X_EXPORT resPtr xf86StdAccResFromOS(resPtr ret);
extern _X_EXPORT resPtr xf86AccResFromOS(resPtr ret);
#endif /* NEED_OS_RAC_PROTOS */
-extern _X_EXPORT unsigned long xf86GetOSOffsetFromPCI(PCITAG tag, int space, unsigned long base);
-
extern _X_EXPORT void xf86MakeNewMapping(int, int, unsigned long, unsigned long, pointer);
extern _X_EXPORT void xf86InitVidMem(void);
--
1.6.1.3
More information about the xorg-devel
mailing list