From e7369daba58bb4fad5cef37fefbd851e59446045 Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Wed, 9 Feb 2005 11:12:54 +0000 Subject: [PATCH] Added PCI2Host bus translations for linux PPC and fixed fixed bugs in macros that apply these functions (Bill Randle Bugzilla #325 and #327). --- hw/xfree86/common/xf86pciBus.c | 6 ++-- hw/xfree86/os-support/bus/linuxPci.c | 53 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c index 17fb1b3f2..85f57e96f 100644 --- a/hw/xfree86/common/xf86pciBus.c +++ b/hw/xfree86/common/xf86pciBus.c @@ -105,11 +105,11 @@ static PciBusPtr xf86PciBus = NULL; #define PCI_MEM32_LENGTH_MAX 0xFFFFFFFF #define B2M(tag,base) pciBusAddrToHostAddr(tag,PCI_MEM,base) -#define B2I(tag,base) (base) +#define B2I(tag,base) pciBusAddrToHostAddr(tag,PCI_IO,base) #define B2H(tag,base,type) (((type & ResPhysMask) == ResMem) ? \ B2M(tag, base) : B2I(tag, base)) -#define M2B(tag,base) pciHostAddrToBusAddr(tag,PCI_IO,base) -#define I2B(tag,base) (base) +#define M2B(tag,base) pciHostAddrToBusAddr(tag,PCI_MEM,base) +#define I2B(tag,base) pciHostAddrToBusAddr(tag,PCI_IO,base) #define H2B(tag,base,type) (((type & ResPhysMask) == ResMem) ? \ M2B(tag, base) : I2B(tag, base)) #define TAG(pvp) (pciTag(pvp->bus,pvp->device,pvp->func)) diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c index 23f85e644..1f5e649db 100644 --- a/hw/xfree86/os-support/bus/linuxPci.c +++ b/hw/xfree86/os-support/bus/linuxPci.c @@ -59,13 +59,22 @@ static CARD32 linuxPciCfgRead(PCITAG tag, int off); static void linuxPciCfgWrite(PCITAG, int off, CARD32 val); static void linuxPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits); +#if defined(__powerpc__) +static ADDRESS linuxPpcBusAddrToHostAddr(PCITAG, PciAddrType, ADDRESS); +static ADDRESS linuxPpcHostAddrToBusAddr(PCITAG, PciAddrType, ADDRESS); +#endif static pciBusFuncs_t linuxFuncs0 = { /* pciReadLong */ linuxPciCfgRead, /* pciWriteLong */ linuxPciCfgWrite, /* pciSetBitsLong */ linuxPciCfgSetBits, +#if defined(__powerpc__) +/* pciAddrHostToBus */ linuxPpcHostAddrToBusAddr, +/* pciAddrBusToHost */ linuxPpcBusAddrToHostAddr +#else /* pciAddrHostToBus */ pciAddrNOOP, /* pciAddrBusToHost */ pciAddrNOOP +#endif }; static pciBusInfo_t linuxPci0 = { @@ -192,6 +201,50 @@ linuxPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits) } } +#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; +} + +static ADDRESS +linuxPpcHostAddrToBusAddr(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__ */ + #ifndef INCLUDE_XF86_NO_DOMAIN /*