Rename xf86ReadDomainMemory to xf86ReadLegacyVideoBIOS, since that's

what it is actually used for.  Modify a few routines in linuxPci.c to
take pci_device structures as parameters in stead of PCITAGs.
This commit is contained in:
Ian Romanick 2006-08-08 16:42:23 -07:00
parent 83ebf61ec0
commit 9df53d903e
7 changed files with 82 additions and 130 deletions

View File

@ -216,26 +216,15 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
setup_int_vect(pInt);
set_return_trap(pInt);
/*
* Retrieve two segments: one at V_BIOS, the other 64kB beyond the first.
* This'll catch any BIOS that might have been initialised before server
* entry.
/* Retrieve the entire legacy video BIOS segment. This can be upto
* 128KiB.
*/
vbiosMem = (char *)base + V_BIOS;
(void)memset(vbiosMem, 0, 2 * V_BIOS_SIZE);
if (xf86ReadDomainMemory(pInt->Tag, V_BIOS, V_BIOS_SIZE, vbiosMem) <
V_BIOS_SIZE) {
if (xf86ReadLegacyVideoBIOS(pInt->Tag, vbiosMem) < V_BIOS_SIZE) {
xf86DrvMsg(screen, X_WARNING,
"Unable to retrieve all of segment 0x0C0000.\n");
}
else if ((((unsigned char *)vbiosMem)[0] == 0x55) &&
(((unsigned char *)vbiosMem)[1] == 0xAA) &&
(((unsigned char *)vbiosMem)[2] > 0x80)) {
if (xf86ReadDomainMemory(pInt->Tag, V_BIOS + V_BIOS_SIZE, V_BIOS_SIZE,
(unsigned char *)vbiosMem + V_BIOS_SIZE) < V_BIOS_SIZE)
xf86DrvMsg(screen, X_WARNING,
"Unable to retrieve all of segment 0x0D0000.\n");
}
/*
* If this adapter is the primary, use its post-init BIOS (if we can find

View File

@ -251,7 +251,7 @@ _X_HIDDEN void *xfree86LookupTab[] = {
SYMFUNC(xf86MapReadSideEffects)
SYMFUNC(xf86GetPciDomain)
SYMFUNC(xf86MapDomainMemory)
SYMFUNC(xf86ReadDomainMemory)
SYMFUNC(xf86ReadLegacyVideoBIOS)
SYMFUNC(xf86UDelay)
SYMFUNC(xf86IODelay)
SYMFUNC(xf86SlowBcopy)

View File

@ -25,7 +25,7 @@
* xf86MapDomainMemory() - Like xf86MapPciMem() but can handle
* domain/host address translation
* xf86MapLegacyIO() - Maps PCI I/O spaces
* xf86ReadDomainMemory() - Like xf86ReadPciBIOS() but can handle
* xf86ReadLegacyVideoBIOS() - Like xf86ReadPciBIOS() but can handle
* domain/host address translation
*
* The actual PCI backend driver is selected by the pciInit() function
@ -282,20 +282,6 @@ pciTag(int busnum, int devnum, int funcnum)
return(PCI_MAKE_TAG(busnum,devnum,funcnum));
}
CARD32
pciByteSwap(CARD32 u)
{
#if X_BYTE_ORDER == X_BIG_ENDIAN
return lswapl(u);
#else /* !BIG_ENDIAN */
return(u);
#endif
}
ADDRESS
pciAddrNOOP(PCITAG tag, PciAddrType type, ADDRESS addr)
{
@ -347,24 +333,39 @@ xf86MapLegacyIO(struct pci_device *dev)
}
_X_EXPORT int
xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
xf86ReadLegacyVideoBIOS(PCITAG Tag, unsigned char *Buf)
{
const unsigned Len = (2 * 0x10000);
ADDRESS Base = 0xC0000;
int ret, length, rlength;
/* Read in 64kB chunks */
ret = 0;
while ((length = Len) > 0) {
if (length > 0x010000) length = 0x010000;
rlength = xf86ReadBIOS(Base, 0, Buf, length);
for (length = 0x10000; length > 0; /* empty */) {
rlength = xf86ReadBIOS(Base, 0, & Buf[ret], length);
if (rlength < 0) {
ret = rlength;
break;
}
ret += rlength;
if (rlength < length) break;
length -= rlength;
Base += rlength;
Buf += rlength;
Len -= rlength;
}
if ((Buf[0] == 0x55) && (Buf[1] == 0xAA) && (Buf[2] > 0x80)) {
for (length = 0x10000; length > 0; /* empty */) {
rlength = xf86ReadBIOS(Base, 0, & Buf[ret], length);
if (rlength < 0) {
ret = rlength;
break;
}
ret += rlength;
length -= rlength;
Base += rlength;
}
}
return ret;

View File

@ -362,19 +362,16 @@ xf86MapLegacyIO(struct pci_device *dev)
}
_X_EXPORT int
xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
xf86ReadLegacyVideoBIOS(PCITAG Tag, unsigned char *Buf)
{
static unsigned long pagemask = 0;
const unsigned long pagemask = xf86getpagesize() - 1;
const ADDRESS Base = 0xC0000;
const int Len = 0x20000;
const ADDRESS MapBase = Base & ~pagemask;
unsigned long MapSize = ((Base + Len + pagemask) & ~pagemask) - MapBase;
unsigned char *MappedAddr;
unsigned long MapSize;
ADDRESS MapBase;
int i;
if (!pagemask) pagemask = xf86getpagesize() - 1;
/* Ensure page boundaries */
MapBase = Base & ~pagemask;
MapSize = ((Base + Len + pagemask) & ~pagemask) - MapBase;
/*
* VIDMEM_MMIO in order to get sparse mapping on sparse memory systems

View File

@ -95,8 +95,6 @@ static const struct pci_id_match match_host_bridge = {
0x0000ffff00, 0
};
/* from lnx_pci.c. */
extern int lnxPciInit(void);
void
linuxPciInit(void)
@ -358,19 +356,10 @@ linuxGetSizesStruct(const struct pci_device *dev)
}
static __inline__ unsigned long
linuxGetIOSize(PCITAG Tag)
linuxGetIOSize(const struct pci_device *dev)
{
const struct pci_device * const dev = pci_device_find_by_slot(PCI_DOM_FROM_TAG(Tag),
PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag)),
PCI_DEV_FROM_TAG(Tag),
PCI_FUNC_FROM_TAG(Tag));
if (dev != NULL) {
const struct pciSizes * const sizes = linuxGetSizesStruct(dev);
return sizes->io_size;
} else {
/* Default to 64KB I/O. */
return (1U << 16);
}
const struct pciSizes * const sizes = linuxGetSizesStruct(dev);
return sizes->io_size;
}
_X_EXPORT int
@ -387,7 +376,7 @@ xf86GetPciDomain(PCITAG Tag)
if ((result = PCI_DOM_FROM_TAG(Tag)) != 0)
return result;
if ((fd = linuxPciOpenFile(Tag, FALSE)) < 0)
if ((fd = linuxPciOpenFile(dev, FALSE)) < 0)
return 0;
if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
@ -397,19 +386,19 @@ xf86GetPciDomain(PCITAG Tag)
}
static pointer
linuxMapPci(int ScreenNum, int Flags, PCITAG Tag,
linuxMapPci(int ScreenNum, int Flags, struct pci_device *dev,
ADDRESS Base, unsigned long Size, int mmap_ioctl)
{
/* Align to page boundary */
const ADDRESS realBase = Base & ~(getpagesize() - 1);
const ADDRESS Offset = Base - realBase;
do {
struct pci_device *dev;
unsigned char *result;
ADDRESS realBase, Offset;
int fd, mmapflags, prot;
xf86InitVidMem();
dev = xf86GetPciHostConfigFromTag(Tag);
/* FIXME: What if dev == NULL? */
if (((fd = linuxPciOpenFile(dev, FALSE)) < 0) ||
@ -442,9 +431,6 @@ linuxMapPci(int ScreenNum, int Flags, PCITAG Tag,
#endif /* ?__ia64__ */
/* Align to page boundary */
realBase = Base & ~(getpagesize() - 1);
Offset = Base - realBase;
if (Flags & VIDMEM_READONLY)
prot = PROT_READ;
@ -472,24 +458,18 @@ static pointer DomainMmappedIO[MAX_DOMAINS];
static pointer DomainMmappedMem[MAX_DOMAINS];
static int
linuxOpenLegacy(PCITAG Tag, char *name)
linuxOpenLegacy(struct pci_device *dev, char *name)
{
#define PREFIX "/sys/class/pci_bus/%04x:%02x/%s"
char *path;
int domain, bus;
pciBusInfo_t *pBusInfo;
struct pci_device *dev;
int fd;
path = xalloc(strlen(PREFIX) + strlen(name));
if (!path)
return -1;
dev = pci_device_find_by_slot(PCI_DOM_FROM_TAG(Tag),
PCI_BUS_NO_DOM(PCI_BUS_FROM_TAG(Tag)),
PCI_DEV_FROM_TAG(Tag),
PCI_FUNC_FROM_TAG(Tag));
while (dev != NULL) {
sprintf(path, PREFIX, dev->domain, dev->bus, name);
fd = open(path, O_RDWR);
@ -524,21 +504,17 @@ xf86MapDomainMemory(int ScreenNum, int Flags, PCITAG Tag,
ADDRESS Base, unsigned long Size)
{
int domain = xf86GetPciDomain(Tag);
const struct pci_device *dev = xf86GetPciHostConfigFromTag(Tag);
int fd;
/*
* We use /proc/bus/pci on non-legacy addresses or if the Linux sysfs
* legacy_mem interface is unavailable.
*/
if (Base > 1024*1024)
return linuxMapPci(ScreenNum, Flags, Tag, Base, Size,
if ((Base > 1024*1024) || ((fd = linuxOpenLegacy(dev, "legacy_mem")) < 0))
return linuxMapPci(ScreenNum, Flags, dev, Base, Size,
PCIIOC_MMAP_IS_MEM);
if ((fd = linuxOpenLegacy(Tag, "legacy_mem")) < 0)
return linuxMapPci(ScreenNum, Flags, Tag, Base, Size,
PCIIOC_MMAP_IS_MEM);
/* If we haven't already mapped this legacy space, try to. */
if (!DomainMmappedMem[domain]) {
DomainMmappedMem[domain] = mmap(NULL, 1024*1024, PROT_READ|PROT_WRITE,
@ -575,6 +551,7 @@ xf86MapLegacyIO(struct pci_device *dev)
const PCITAG tag = PCI_MAKE_TAG(PCI_MAKE_BUS(dev->domain, dev->bus),
dev->dev, dev->func);
const int domain = xf86GetPciDomain(tag);
const struct pci_device *bridge = xf86GetPciHostConfigFromTag(Tag);
int fd;
if ((domain <= 0) || (domain >= MAX_DOMAINS))
@ -584,8 +561,8 @@ xf86MapLegacyIO(struct pci_device *dev)
return (IOADDRESS)DomainMmappedIO[domain];
/* Permanently map all of I/O space */
if ((fd = linuxOpenLegacy(tag, "legacy_io")) < 0) {
DomainMmappedIO[domain] = linuxMapPci(-1, VIDMEM_MMIO, tag,
if ((fd = linuxOpenLegacy(bridge, "legacy_io")) < 0) {
DomainMmappedIO[domain] = linuxMapPci(-1, VIDMEM_MMIO, bridge,
0, linuxGetIOSize(tag),
PCIIOC_MMAP_IS_IO);
/* ia64 can't mmap legacy IO port space */
@ -599,55 +576,37 @@ xf86MapLegacyIO(struct pci_device *dev)
return (IOADDRESS)DomainMmappedIO[domain];
}
/*
* xf86ReadDomainMemory - copy from domain memory into a caller supplied buffer
/**
* Read legacy VGA video BIOS associated with specified domain.
*
* Attempts to read up to 128KiB of legacy VGA video BIOS.
*
* \return
* The number of bytes read on success or -1 on failure.
*/
_X_EXPORT int
xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
xf86ReadLegacyVideoBIOS(PCITAG Tag, unsigned char *Buf)
{
const ADDRESS Base = V_BIOS;
const int Len = V_BIOS_SIZE * 2;
const int pagemask = getpagesize() - 1;
const ADDRESS offset = Base & ~pagemask;
const unsigned long size = ((Base + Len + pagemask) & ~pagemask) - offset;
const struct pci_device * const dev =
pci_device_find_by_slot(PCI_DOM_FROM_TAG(Tag),
PCI_BUS_NO_DOM(PCI_BUS_FROM_TAG(Tag)),
PCI_DEV_FROM_TAG(Tag),
PCI_FUNC_FROM_TAG(Tag));
unsigned char *ptr, *src;
ADDRESS offset;
unsigned long size;
int len, pagemask = getpagesize() - 1;
int len;
unsigned int i, dom, bus, dev, func;
unsigned int fd;
char file[256];
struct stat st;
dom = PCI_DOM_FROM_TAG(Tag);
bus = PCI_BUS_FROM_TAG(Tag);
dev = PCI_DEV_FROM_TAG(Tag);
func = PCI_FUNC_FROM_TAG(Tag);
sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
dom, bus, dom, bus, dev, func);
/*
* If the caller wants the ROM and the sysfs rom interface exists,
* try to use it instead of reading it from /proc/bus/pci.
/* Try to use the civilized PCI interface first.
*/
if (((Base & 0xfffff) == 0xC0000) && (stat(file, &st) == 0)) {
if ((fd = open(file, O_RDWR)))
Base = 0x0;
/* enable the ROM first */
write(fd, "1", 2);
lseek(fd, 0, SEEK_SET);
/* copy the ROM until we hit Len, EOF or read error */
for (i = 0; i < Len && read(fd, Buf, 1) > 0; Buf++, i++)
;
write(fd, "0", 2);
close(fd);
return Len;
if (pci_device_read_rom(dev, Buf) == 0) {
return dev->rom_size;
}
/* Ensure page boundaries */
offset = Base & ~pagemask;
size = ((Base + Len + pagemask) & ~pagemask) - offset;
ptr = xf86MapDomainMemory(-1, VIDMEM_READONLY, Tag, offset, size);
if (!ptr)
@ -655,8 +614,15 @@ xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
/* Using memcpy() here can hang the system */
src = ptr + (Base - offset);
for (len = Len; len-- > 0;)
*Buf++ = *src++;
for (len = 0; len < V_BIOS_SIZE; len++) {
Buf[len] = src[len];
}
if ((buf[0] == 0x55) && (buf[1] == 0xAA) && (buf[2] > 0x80)) {
for ( /* empty */ ; len < (2 * V_BIOS_SIZE); len++) {
Buf[len] = src[len];
}
}
xf86UnMapVidMem(-1, ptr, size);

View File

@ -649,7 +649,7 @@ xf86MapLegacyIO(int ScreenNum, int Flags, PCITAG Tag,
}
_X_EXPORT int
xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
xf86ReadLegacyVideoBIOS(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
{
unsigned char *ptr, *src;
ADDRESS offset;

View File

@ -263,7 +263,6 @@ int xf86GetPciDomain(PCITAG tag);
pointer xf86MapDomainMemory(int ScreenNum, int Flags, PCITAG Tag,
ADDRESS Base, unsigned long Size);
IOADDRESS xf86MapLegacyIO(struct pci_device *dev);
int xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len,
unsigned char *Buf);
int xf86ReadLegacyVideoBIOS(PCITAG Tag, unsigned char *Buf);
#endif /* _XF86PCI_H */