From 24506ea65be4cb29c5e1486aa0a529a40ce5c230 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 24 Jan 2007 15:33:49 -0800 Subject: [PATCH] Move xf86ReadLegacyBIOS to the one place that uses it. xf86ReadLegacyBIOS is only used by one function in int10/generic.c. Move a generic implementation of that function there, rename it to read_legcay_BIOS, and delete all remnants of it from all other places. --- hw/xfree86/int10/generic.c | 56 +++++++++++++++++++++++++++- hw/xfree86/loader/xf86sym.c | 1 - hw/xfree86/os-support/bus/Pci.c | 41 -------------------- hw/xfree86/os-support/bus/axpPci.c | 28 -------------- hw/xfree86/os-support/bus/linuxPci.c | 48 ------------------------ hw/xfree86/os-support/bus/sparcPci.c | 24 ------------ hw/xfree86/os-support/bus/xf86Pci.h | 1 - 7 files changed, 55 insertions(+), 144 deletions(-) diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c index b3a946076..6a0471145 100644 --- a/hw/xfree86/int10/generic.c +++ b/hw/xfree86/int10/generic.c @@ -62,6 +62,60 @@ static void UnmapVRam(xf86Int10InfoPtr pInt); static void *sysMem = NULL; +/** + * 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. + * + * \bug + * PCI ROMs can contain multiple BIOS images (e.g., OpenFirmware, x86 VGA, + * etc.). How do we know that \c pci_device_read_rom will return the + * legacy VGA BIOS image? + */ +static int +read_legacy_video_BIOS(struct pci_device *dev, unsigned char *Buf) +{ + const ADDRESS Base = 0xC0000; + const int Len = 0x10000 * 2; + const int pagemask = getpagesize() - 1; + const ADDRESS offset = Base & ~pagemask; + const unsigned long size = ((Base + Len + pagemask) & ~pagemask) - offset; + unsigned char *ptr, *src; + int len; + + + /* Try to use the civilized PCI interface first. + */ + if (pci_device_read_rom(dev, Buf) == 0) { + return dev->rom_size; + } + + ptr = xf86MapDomainMemory(-1, VIDMEM_READONLY, dev, offset, size); + + if (!ptr) + return -1; + + /* Using memcpy() here can hang the system */ + src = ptr + (Base - offset); + for (len = 0; len < (Len / 2); len++) { + Buf[len] = src[len]; + } + + if ((Buf[0] == 0x55) && (Buf[1] == 0xAA) && (Buf[2] > 0x80)) { + for ( /* empty */ ; len < Len; len++) { + Buf[len] = src[len]; + } + } + + xf86UnMapVidMem(-1, ptr, size); + + return Len; +} + + xf86Int10InfoPtr xf86ExtendedInitInt10(int entityIndex, int Flags) { @@ -216,7 +270,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags) */ vbiosMem = (char *)base + V_BIOS; (void)memset(vbiosMem, 0, 2 * V_BIOS_SIZE); - if (xf86ReadLegacyVideoBIOS(pInt->dev, vbiosMem) < V_BIOS_SIZE) { + if (read_legacy_video_BIOS(pInt->dev, vbiosMem) < V_BIOS_SIZE) { xf86DrvMsg(screen, X_WARNING, "Unable to retrieve all of segment 0x0C0000.\n"); } diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c index 75181f20d..952e7fe15 100644 --- a/hw/xfree86/loader/xf86sym.c +++ b/hw/xfree86/loader/xf86sym.c @@ -249,7 +249,6 @@ _X_HIDDEN void *xfree86LookupTab[] = { SYMFUNC(xf86UnMapVidMem) SYMFUNC(xf86MapReadSideEffects) SYMFUNC(xf86MapDomainMemory) - SYMFUNC(xf86ReadLegacyVideoBIOS) SYMFUNC(xf86UDelay) SYMFUNC(xf86IODelay) SYMFUNC(xf86SlowBcopy) diff --git a/hw/xfree86/os-support/bus/Pci.c b/hw/xfree86/os-support/bus/Pci.c index a53f34494..31e9023f0 100644 --- a/hw/xfree86/os-support/bus/Pci.c +++ b/hw/xfree86/os-support/bus/Pci.c @@ -23,8 +23,6 @@ * xf86MapDomainMemory() - Like xf86MapPciMem() but can handle * domain/host address translation * xf86MapLegacyIO() - Maps PCI I/O spaces - * xf86ReadLegacyVideoBIOS() - Like xf86ReadPciBIOS() but can handle - * domain/host address translation * * The actual PCI backend driver is selected by the pciInit() function * (see below) using either compile time definitions, run-time checks, @@ -305,43 +303,4 @@ xf86MapLegacyIO(struct pci_device *dev) return 0; } -_X_EXPORT int -xf86ReadLegacyVideoBIOS(struct pci_device *dev, unsigned char *Buf) -{ - const unsigned Len = (2 * 0x10000); - ADDRESS Base = 0xC0000; - int ret, length, rlength; - - /* Read in 64kB chunks */ - ret = 0; - - 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; - } - - 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; -} - #endif /* INCLUDE_XF86_NO_DOMAIN */ diff --git a/hw/xfree86/os-support/bus/axpPci.c b/hw/xfree86/os-support/bus/axpPci.c index e7e996a09..1f1547798 100644 --- a/hw/xfree86/os-support/bus/axpPci.c +++ b/hw/xfree86/os-support/bus/axpPci.c @@ -361,34 +361,6 @@ xf86MapLegacyIO(struct pci_device *dev) return pDomain->mapped_io; } -_X_EXPORT int -xf86ReadLegacyVideoBIOS(PCITAG Tag, unsigned char *Buf) -{ - 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; - int i; - - - /* - * VIDMEM_MMIO in order to get sparse mapping on sparse memory systems - * so we can use mmio functions to read (that way we can really get byte - * at a time reads on dense memory systems with byte/word instructions. - */ - MappedAddr = xf86MapDomainMemory(-1, VIDMEM_READONLY | VIDMEM_MMIO, - Tag, MapBase, MapSize); - - for (i = 0; i < Len; i++) { - *Buf++ = xf86ReadMmio8(MappedAddr, Base - MapBase + i); - } - - xf86UnMapVidMem(-1, MappedAddr, MapSize); - return Len; -} - resPtr xf86PciBusAccWindowsFromOS(void) { diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c index ec8ae011d..46ca0836e 100644 --- a/hw/xfree86/os-support/bus/linuxPci.c +++ b/hw/xfree86/os-support/bus/linuxPci.c @@ -547,54 +547,6 @@ xf86MapLegacyIO(struct pci_device *dev) return (IOADDRESS)DomainMmappedIO[domain]; } -/** - * 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 -xf86ReadLegacyVideoBIOS(struct pci_device *dev, unsigned char *Buf) -{ - const ADDRESS Base = 0xC0000; - const int Len = 0x10000 * 2; - const int pagemask = getpagesize() - 1; - const ADDRESS offset = Base & ~pagemask; - const unsigned long size = ((Base + Len + pagemask) & ~pagemask) - offset; - unsigned char *ptr, *src; - int len; - - - /* Try to use the civilized PCI interface first. - */ - if (pci_device_read_rom(dev, Buf) == 0) { - return dev->rom_size; - } - - ptr = xf86MapDomainMemory(-1, VIDMEM_READONLY, dev, offset, size); - - if (!ptr) - return -1; - - /* Using memcpy() here can hang the system */ - src = ptr + (Base - offset); - for (len = 0; len < (Len / 2); len++) { - Buf[len] = src[len]; - } - - if ((Buf[0] == 0x55) && (Buf[1] == 0xAA) && (Buf[2] > 0x80)) { - for ( /* empty */ ; len < Len; len++) { - Buf[len] = src[len]; - } - } - - xf86UnMapVidMem(-1, ptr, size); - - return Len; -} - resPtr xf86BusAccWindowsFromOS(void) { diff --git a/hw/xfree86/os-support/bus/sparcPci.c b/hw/xfree86/os-support/bus/sparcPci.c index f09ed9f0a..82b1d89b9 100644 --- a/hw/xfree86/os-support/bus/sparcPci.c +++ b/hw/xfree86/os-support/bus/sparcPci.c @@ -648,30 +648,6 @@ xf86MapLegacyIO(int ScreenNum, int Flags, PCITAG Tag, return (IOADDRESS)pDomain->io + Base; } -_X_EXPORT int -xf86ReadLegacyVideoBIOS(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf) -{ - unsigned char *ptr, *src; - ADDRESS offset; - unsigned long size; - int len; - - /* Ensure page boundaries */ - offset = Base & ~pagemask; - size = ((Base + Len + pagemask) & ~pagemask) - offset; - - ptr = xf86MapDomainMemory(-1, VIDMEM_READONLY, Tag, offset, size); - - /* Using memcpy() here hangs the system */ - src = ptr + (Base - offset); - for (len = Len; len-- > 0;) - *Buf++ = *src++; - - xf86UnMapVidMem(-1, ptr, size); - - return Len; -} - resPtr xf86BusAccWindowsFromOS(void) { diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h index eef3d2e0d..2b8a4f76b 100644 --- a/hw/xfree86/os-support/bus/xf86Pci.h +++ b/hw/xfree86/os-support/bus/xf86Pci.h @@ -261,6 +261,5 @@ extern int pciNumBuses; pointer xf86MapDomainMemory(int ScreenNum, int Flags, struct pci_device *dev, ADDRESS Base, unsigned long Size); IOADDRESS xf86MapLegacyIO(struct pci_device *dev); -int xf86ReadLegacyVideoBIOS(struct pci_device *dev, unsigned char *Buf); #endif /* _XF86PCI_H */