Fix domain insanity.
Eliminate xf86GetPciDomain. The domain from libpciaccess is the domain. Period. This means that 0 is a valid domain. Make sure that INCLUDE_XF86_NO_DOMAIN is *not* set. Always run in "domain mode," even if the only domain possible is 0.
This commit is contained in:
parent
079a6a55a5
commit
31bd8d1507
|
@ -1072,5 +1072,5 @@ pciConvertRange2Host(int entityIndex, resRange *pRange)
|
||||||
|
|
||||||
/* Set domain number */
|
/* Set domain number */
|
||||||
pRange->type &= ~(ResDomain | ResBus);
|
pRange->type &= ~(ResDomain | ResBus);
|
||||||
pRange->type |= xf86GetPciDomain(tag) << 24;
|
pRange->type |= pvp->domain << 24;
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,6 @@ _X_HIDDEN void *xfree86LookupTab[] = {
|
||||||
SYMFUNC(xf86MapVidMem)
|
SYMFUNC(xf86MapVidMem)
|
||||||
SYMFUNC(xf86UnMapVidMem)
|
SYMFUNC(xf86UnMapVidMem)
|
||||||
SYMFUNC(xf86MapReadSideEffects)
|
SYMFUNC(xf86MapReadSideEffects)
|
||||||
SYMFUNC(xf86GetPciDomain)
|
|
||||||
SYMFUNC(xf86MapDomainMemory)
|
SYMFUNC(xf86MapDomainMemory)
|
||||||
SYMFUNC(xf86ReadLegacyVideoBIOS)
|
SYMFUNC(xf86ReadLegacyVideoBIOS)
|
||||||
SYMFUNC(xf86UDelay)
|
SYMFUNC(xf86UDelay)
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
* function
|
* function
|
||||||
* pciBusAddrToHostAddr() - Convert a PCI address to a host address
|
* pciBusAddrToHostAddr() - Convert a PCI address to a host address
|
||||||
* xf86scanpci() - Return info about all PCI devices
|
* xf86scanpci() - Return info about all PCI devices
|
||||||
* xf86GetPciDomain() - Return domain number from a PCITAG
|
|
||||||
* xf86MapDomainMemory() - Like xf86MapPciMem() but can handle
|
* xf86MapDomainMemory() - Like xf86MapPciMem() but can handle
|
||||||
* domain/host address translation
|
* domain/host address translation
|
||||||
* xf86MapLegacyIO() - Maps PCI I/O spaces
|
* xf86MapLegacyIO() - Maps PCI I/O spaces
|
||||||
|
@ -297,12 +296,6 @@ xf86scanpci(void)
|
||||||
|
|
||||||
#ifdef INCLUDE_XF86_NO_DOMAIN
|
#ifdef INCLUDE_XF86_NO_DOMAIN
|
||||||
|
|
||||||
_X_EXPORT int
|
|
||||||
xf86GetPciDomain(PCITAG Tag)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_X_EXPORT pointer
|
_X_EXPORT pointer
|
||||||
xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
|
xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
|
||||||
ADDRESS Base, unsigned long Size)
|
ADDRESS Base, unsigned long Size)
|
||||||
|
|
|
@ -283,6 +283,8 @@
|
||||||
#error No PCI support available for this architecture/OS combination
|
#error No PCI support available for this architecture/OS combination
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#undef INCLUDE_XF86_NO_DOMAIN
|
||||||
|
|
||||||
extern void ARCH_PCI_INIT(void);
|
extern void ARCH_PCI_INIT(void);
|
||||||
#if defined(ARCH_PCI_OS_INIT)
|
#if defined(ARCH_PCI_OS_INIT)
|
||||||
extern void ARCH_PCI_OS_INIT(void);
|
extern void ARCH_PCI_OS_INIT(void);
|
||||||
|
|
|
@ -99,22 +99,26 @@ static const struct pci_id_match match_host_bridge = {
|
||||||
0x0000ffff00, 0
|
0x0000ffff00, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef INCLUDE_XF86_NO_DOMAIN
|
||||||
static Bool domain_support = FALSE;
|
#define MAX_DOMAINS 257
|
||||||
|
static pointer DomainMmappedIO[MAX_DOMAINS];
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
linuxPciInit(void)
|
linuxPciInit(void)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
#ifndef INCLUDE_XF86_NO_DOMAIN
|
||||||
|
(void) memset(DomainMmappedIO, 0, sizeof(DomainMmappedIO));
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((xf86Info.pciFlags == PCIForceNone) ||
|
if ((xf86Info.pciFlags == PCIForceNone) ||
|
||||||
(-1 == stat("/proc/bus/pci", &st))) {
|
(-1 == stat("/proc/bus/pci", &st))) {
|
||||||
/* when using this as default for all linux architectures,
|
/* when using this as default for all linux architectures,
|
||||||
we'll need a fallback for 2.0 kernels here */
|
we'll need a fallback for 2.0 kernels here */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifndef INCLUDE_XF86_NO_DOMAIN
|
|
||||||
domain_support = linuxDomainSupport();
|
|
||||||
#endif
|
|
||||||
pciNumBuses = 1;
|
pciNumBuses = 1;
|
||||||
pciBusInfo[0] = &linuxPci0;
|
pciBusInfo[0] = &linuxPci0;
|
||||||
}
|
}
|
||||||
|
@ -337,10 +341,12 @@ linuxGetSizesStruct(const struct pci_device *dev)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Look up vendor/device */
|
/* Look up vendor/device */
|
||||||
for (i = 0; i < NUM_SIZES; i++) {
|
if (dev != NULL) {
|
||||||
if ((dev->vendor_id == pciControllerSizes[i].vendor)
|
for (i = 0; i < NUM_SIZES; i++) {
|
||||||
&& (dev->device_id == pciControllerSizes[i].device)) {
|
if ((dev->vendor_id == pciControllerSizes[i].vendor)
|
||||||
return & pciControllerSizes[i];
|
&& (dev->device_id == pciControllerSizes[i].device)) {
|
||||||
|
return & pciControllerSizes[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,29 +361,6 @@ linuxGetIOSize(const struct pci_device *dev)
|
||||||
return sizes->io_size;
|
return sizes->io_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT int
|
|
||||||
xf86GetPciDomain(PCITAG Tag)
|
|
||||||
{
|
|
||||||
const struct pci_device *dev;
|
|
||||||
int fd, result;
|
|
||||||
|
|
||||||
dev = xf86GetPciHostConfigFromTag(Tag);
|
|
||||||
|
|
||||||
if (!dev)
|
|
||||||
return 1; /* Domain 0 is reserved */
|
|
||||||
|
|
||||||
if ((result = PCI_DOM_FROM_TAG(Tag)) != 0)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
if ((fd = linuxPciOpenFile(dev, FALSE)) < 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return result + 1; /* Domain 0 is reserved */
|
|
||||||
}
|
|
||||||
|
|
||||||
static pointer
|
static pointer
|
||||||
linuxMapPci(int ScreenNum, int Flags, struct pci_device *dev,
|
linuxMapPci(int ScreenNum, int Flags, struct pci_device *dev,
|
||||||
ADDRESS Base, unsigned long Size, int mmap_ioctl)
|
ADDRESS Base, unsigned long Size, int mmap_ioctl)
|
||||||
|
@ -446,41 +429,30 @@ linuxMapPci(int ScreenNum, int Flags, struct pci_device *dev,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_DOMAINS 257
|
|
||||||
static pointer DomainMmappedIO[MAX_DOMAINS];
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
linuxOpenLegacy(struct pci_device *dev, char *name)
|
linuxOpenLegacy(struct pci_device *dev, char *name)
|
||||||
{
|
{
|
||||||
#define PREFIX "/sys/class/pci_bus/%04x:%02x/%s"
|
static const char PREFIX[] = "/sys/class/pci_bus/%04x:%02x/legacy_%s";
|
||||||
char *path;
|
char path[sizeof(PREFIX) + 3];
|
||||||
int domain, bus;
|
|
||||||
pciBusInfo_t *pBusInfo;
|
pciBusInfo_t *pBusInfo;
|
||||||
int fd;
|
int fd = -1;
|
||||||
|
|
||||||
path = xalloc(strlen(PREFIX) + strlen(name));
|
|
||||||
if (!path)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
while (dev != NULL) {
|
while (dev != NULL) {
|
||||||
sprintf(path, PREFIX, dev->domain, dev->bus, name);
|
snprintf(path, sizeof(path) - 1, PREFIX, dev->domain, dev->bus, name);
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
xfree(path);
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBusInfo = pciBusInfo[PCI_MAKE_BUS(dev->domain, dev->bus)];
|
pBusInfo = pciBusInfo[PCI_MAKE_BUS(dev->domain, dev->bus)];
|
||||||
if (!pBusInfo || (bridge == pBusInfo->bridge) ||
|
if (!pBusInfo || (dev == pBusInfo->bridge) ||
|
||||||
!pBusInfo->bridge) {
|
!pBusInfo->bridge) {
|
||||||
xfree(path);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = pBusInfo->bridge;
|
dev = pBusInfo->bridge;
|
||||||
}
|
}
|
||||||
|
|
||||||
xfree(path);
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,24 +509,22 @@ xf86MapLegacyIO(struct pci_device *dev)
|
||||||
{
|
{
|
||||||
const PCITAG tag = PCI_MAKE_TAG(PCI_MAKE_BUS(dev->domain, dev->bus),
|
const PCITAG tag = PCI_MAKE_TAG(PCI_MAKE_BUS(dev->domain, dev->bus),
|
||||||
dev->dev, dev->func);
|
dev->dev, dev->func);
|
||||||
const int domain = xf86GetPciDomain(tag);
|
const int domain = dev->domain;
|
||||||
const struct pci_device *bridge = xf86GetPciHostConfigFromTag(tag);
|
struct pci_device *bridge = xf86GetPciHostConfigFromTag(tag);
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if ((domain <= 0) || (domain >= MAX_DOMAINS))
|
if (domain >= MAX_DOMAINS)
|
||||||
FatalError("xf86MapLegacyIO(): domain out of range\n");
|
FatalError("xf86MapLegacyIO(): domain out of range\n");
|
||||||
|
|
||||||
if (DomainMmappedIO[domain])
|
if (DomainMmappedIO[domain])
|
||||||
return (IOADDRESS)DomainMmappedIO[domain];
|
return (IOADDRESS)DomainMmappedIO[domain];
|
||||||
|
|
||||||
/* Permanently map all of I/O space */
|
/* Permanently map all of I/O space */
|
||||||
if ((fd = linuxOpenLegacy(bridge, "legacy_io")) < 0) {
|
fd = linuxOpenLegacy(bridge, "legacy_io");
|
||||||
DomainMmappedIO[domain] = linuxMapPci(-1, VIDMEM_MMIO, bridge,
|
if (fd < 0) {
|
||||||
0, linuxGetIOSize(bridge),
|
DomainMmappedIO[domain] = linuxMapPci(-1, VIDMEM_MMIO, bridge,
|
||||||
PCIIOC_MMAP_IS_IO);
|
0, linuxGetIOSize(bridge),
|
||||||
/* ia64 can't mmap legacy IO port space */
|
PCIIOC_MMAP_IS_IO);
|
||||||
if (!DomainMmappedIO[domain])
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
else { /* legacy_io file exists, encode fd */
|
else { /* legacy_io file exists, encode fd */
|
||||||
DomainMmappedIO[domain] = (pointer)(fd << 24);
|
DomainMmappedIO[domain] = (pointer)(fd << 24);
|
||||||
|
@ -574,8 +544,8 @@ xf86MapLegacyIO(struct pci_device *dev)
|
||||||
_X_EXPORT int
|
_X_EXPORT int
|
||||||
xf86ReadLegacyVideoBIOS(struct pci_device *dev, unsigned char *Buf)
|
xf86ReadLegacyVideoBIOS(struct pci_device *dev, unsigned char *Buf)
|
||||||
{
|
{
|
||||||
const ADDRESS Base = V_BIOS;
|
const ADDRESS Base = 0xC0000;
|
||||||
const int Len = V_BIOS_SIZE * 2;
|
const int Len = 0x10000 * 2;
|
||||||
const int pagemask = getpagesize() - 1;
|
const int pagemask = getpagesize() - 1;
|
||||||
const ADDRESS offset = Base & ~pagemask;
|
const ADDRESS offset = Base & ~pagemask;
|
||||||
const unsigned long size = ((Base + Len + pagemask) & ~pagemask) - offset;
|
const unsigned long size = ((Base + Len + pagemask) & ~pagemask) - offset;
|
||||||
|
@ -596,12 +566,12 @@ xf86ReadLegacyVideoBIOS(struct pci_device *dev, unsigned char *Buf)
|
||||||
|
|
||||||
/* Using memcpy() here can hang the system */
|
/* Using memcpy() here can hang the system */
|
||||||
src = ptr + (Base - offset);
|
src = ptr + (Base - offset);
|
||||||
for (len = 0; len < V_BIOS_SIZE; len++) {
|
for (len = 0; len < (Len / 2); len++) {
|
||||||
Buf[len] = src[len];
|
Buf[len] = src[len];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[0] == 0x55) && (buf[1] == 0xAA) && (buf[2] > 0x80)) {
|
if ((Buf[0] == 0x55) && (Buf[1] == 0xAA) && (Buf[2] > 0x80)) {
|
||||||
for ( /* empty */ ; len < (2 * V_BIOS_SIZE); len++) {
|
for ( /* empty */ ; len < Len; len++) {
|
||||||
Buf[len] = src[len];
|
Buf[len] = src[len];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,15 +585,13 @@ resPtr
|
||||||
xf86BusAccWindowsFromOS(void)
|
xf86BusAccWindowsFromOS(void)
|
||||||
{
|
{
|
||||||
struct pci_device *dev;
|
struct pci_device *dev;
|
||||||
sturct pci_device_iterator *iter;
|
struct pci_device_iterator *iter;
|
||||||
resPtr pRes = NULL;
|
resPtr pRes = NULL;
|
||||||
resRange range;
|
resRange range;
|
||||||
|
|
||||||
iter = pci_id_match_iterator_create(& match_host_bridge);
|
iter = pci_id_match_iterator_create(& match_host_bridge);
|
||||||
while ((dev = pci_device_next(iter)) != NULL) {
|
while ((dev = pci_device_next(iter)) != NULL) {
|
||||||
const PCITAG tag = PCI_MAKE_TAG(PCI_MAKE_BUS(dev->domain, dev->bus),
|
const int domain = dev->domain;
|
||||||
dev->dev, dev->func);
|
|
||||||
const int domain = xf86GetPciDomain(tag);
|
|
||||||
const struct pciSizes * const sizes = linuxGetSizesStruct(dev);
|
const struct pciSizes * const sizes = linuxGetSizesStruct(dev);
|
||||||
|
|
||||||
RANGE(range, 0, (ADDRESS)(sizes->mem_size - 1),
|
RANGE(range, 0, (ADDRESS)(sizes->mem_size - 1),
|
||||||
|
@ -634,8 +602,14 @@ xf86BusAccWindowsFromOS(void)
|
||||||
RANGE_TYPE(ResExcIoBlock, domain));
|
RANGE_TYPE(ResExcIoBlock, domain));
|
||||||
pRes = xf86AddResToList(pRes, &range, -1);
|
pRes = xf86AddResToList(pRes, &range, -1);
|
||||||
|
|
||||||
|
/* FIXME: The old code reserved domain 0 for a special purpose. The
|
||||||
|
* FIXME: new code just uses whatever domains the kernel tells it,
|
||||||
|
* FIXME: but there is no way to get a domain < 0. What should
|
||||||
|
* FIXME: happen here?
|
||||||
|
*
|
||||||
if (domain <= 0)
|
if (domain <= 0)
|
||||||
break;
|
break;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pci_iterator_destroy(iter);
|
pci_iterator_destroy(iter);
|
||||||
|
@ -654,14 +628,12 @@ resPtr
|
||||||
xf86AccResFromOS(resPtr pRes)
|
xf86AccResFromOS(resPtr pRes)
|
||||||
{
|
{
|
||||||
struct pci_device *dev;
|
struct pci_device *dev;
|
||||||
sturct pci_device_iterator *iter;
|
struct pci_device_iterator *iter;
|
||||||
resRange range;
|
resRange range;
|
||||||
|
|
||||||
iter = pci_id_match_iterator_create(& match_host_bridge);
|
iter = pci_id_match_iterator_create(& match_host_bridge);
|
||||||
while ((dev = pci_device_next(iter)) != NULL) {
|
while ((dev = pci_device_next(iter)) != NULL) {
|
||||||
const PCITAG tag = PCI_MAKE_TAG(PCI_MAKE_BUS(dev->domain, dev->bus),
|
const int domain = dev->domain;
|
||||||
dev->dev, dev->func);
|
|
||||||
const int domain = xf86GetPciDomain(tag);
|
|
||||||
const struct pciSizes * const sizes = linuxGetSizesStruct(dev);
|
const struct pciSizes * const sizes = linuxGetSizesStruct(dev);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -692,8 +664,14 @@ xf86AccResFromOS(resPtr pRes)
|
||||||
RANGE_TYPE(ResExcIoBlock, domain));
|
RANGE_TYPE(ResExcIoBlock, domain));
|
||||||
pRes = xf86AddResToList(pRes, &range, -1);
|
pRes = xf86AddResToList(pRes, &range, -1);
|
||||||
|
|
||||||
|
/* FIXME: The old code reserved domain 0 for a special purpose. The
|
||||||
|
* FIXME: new code just uses whatever domains the kernel tells it,
|
||||||
|
* FIXME: but there is no way to get a domain < 0. What should
|
||||||
|
* FIXME: happen here?
|
||||||
|
*
|
||||||
if (domain <= 0)
|
if (domain <= 0)
|
||||||
break;
|
break;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pci_iterator_destroy(iter);
|
pci_iterator_destroy(iter);
|
||||||
|
|
|
@ -106,6 +106,7 @@
|
||||||
#include <X11/Xarch.h>
|
#include <X11/Xarch.h>
|
||||||
#include <X11/Xfuncproto.h>
|
#include <X11/Xfuncproto.h>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include <pciaccess.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PCI cfg space definitions (e.g. stuff right out of the PCI spec)
|
* PCI cfg space definitions (e.g. stuff right out of the PCI spec)
|
||||||
|
@ -257,7 +258,6 @@ Bool xf86scanpci(void);
|
||||||
extern int pciNumBuses;
|
extern int pciNumBuses;
|
||||||
|
|
||||||
/* Domain access functions. Some of these probably shouldn't be public */
|
/* Domain access functions. Some of these probably shouldn't be public */
|
||||||
int xf86GetPciDomain(PCITAG tag);
|
|
||||||
pointer xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
|
pointer xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev,
|
||||||
ADDRESS Base, unsigned long Size);
|
ADDRESS Base, unsigned long Size);
|
||||||
IOADDRESS xf86MapLegacyIO(struct pci_device *dev);
|
IOADDRESS xf86MapLegacyIO(struct pci_device *dev);
|
||||||
|
|
Loading…
Reference in New Issue