X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdevices%2Fpci_rom.c;h=1ae79e137dd315339af8142bdea74801f192ac91;hb=a953f371ddc0cebf2b3b9d1eebeb857e0567c709;hp=1869a5b74ccc8a5ef757138eca0973e46a351699;hpb=883b8793c9777544101261ebcbed6088e0df1593;p=coreboot.git diff --git a/src/devices/pci_rom.c b/src/devices/pci_rom.c index 1869a5b74..1ae79e137 100644 --- a/src/devices/pci_rom.c +++ b/src/devices/pci_rom.c @@ -1,82 +1,153 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2005 Li-Ta Lo + * Copyright (C) 2005 Tyan + * (Written by Yinghai Lu for Tyan) + * Copyright (C) 2005 Ronald G. Minnich + * Copyright (C) 2005-2007 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include #include #include #include #include +#include +#include -struct rom_header * pci_rom_probe(struct device *dev) +struct rom_header *pci_rom_probe(struct device *dev) { - unsigned long rom_address; struct rom_header *rom_header; struct pci_data *rom_data; - rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); - if (rom_address == 0x00000000 || rom_address == 0xffffffff) { - /* FixME: search in the LinuxBIOS Image for integrated - * devices? */ - return NULL; - } + /* If it's in FLASH, then don't check device for ROM. */ + rom_header = cbfs_load_optionrom(dev->vendor, dev->device, NULL); + + if (rom_header) { + printk(BIOS_DEBUG, "In CBFS, ROM address for %s = %p\n", + dev_path(dev), rom_header); + } else { + u32 rom_address; - printk_debug("%s, rom address for %s = %x\n", - __func__, dev_path(dev), rom_address); + rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); - /* enable expansion ROM address decoding */ - pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address|PCI_ROM_ADDRESS_ENABLE); + if (rom_address == 0x00000000 || rom_address == 0xffffffff) { +#if defined(CONFIG_BOARD_EMULATION_QEMU_X86) && CONFIG_BOARD_EMULATION_QEMU_X86 + if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA) + rom_address = 0xc0000; + else +#endif + return NULL; + } else { + /* Enable expansion ROM address decoding. */ + pci_write_config32(dev, PCI_ROM_ADDRESS, + rom_address|PCI_ROM_ADDRESS_ENABLE); + } + + printk(BIOS_DEBUG, "On card, ROM address for %s = %lx\n", + dev_path(dev), (unsigned long)rom_address); + rom_header = (struct rom_header *)rom_address; + } + + printk(BIOS_SPEW, "PCI expansion ROM, signature 0x%04x, " + "INIT size 0x%04x, data ptr 0x%04x\n", + le32_to_cpu(rom_header->signature), + rom_header->size * 512, le32_to_cpu(rom_header->data)); - rom_header = rom_address; - printk_debug("%s, PCI Expansion ROM, signature 0x%04x, \n\t" - "INIT size 0x%04x, data ptr 0x%04x\n", - __func__, le32_to_cpu(rom_header->signature), - rom_header->size * 512, le32_to_cpu(rom_header->data)); if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) { - printk_err("%s, Incorrect Expansion ROM Header Signature %04x\n", - __func__, le32_to_cpu(rom_header->signature)); + printk(BIOS_ERR, "Incorrect expansion ROM header " + "signature %04x\n", le32_to_cpu(rom_header->signature)); return NULL; } - rom_data = (unsigned char *) rom_header + le32_to_cpu(rom_header->data); - printk_debug("%s, PCI ROM Image, Vendor %04x, Device %04x,\n", - __func__, rom_data->vendor, rom_data->device); - if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) { - printk_err("%s, Device or Vendor ID mismatch\n"); + rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data)); + + printk(BIOS_SPEW, "PCI ROM image, vendor ID %04x, device ID %04x,\n", + rom_data->vendor, rom_data->device); + if (dev->vendor != rom_data->vendor + || dev->device != rom_data->device) { + printk(BIOS_ERR, "ID mismatch: vendor ID %04x, " + "device ID %04x\n", rom_data->vendor, rom_data->device); return NULL; } - printk_debug("%s, PCI ROM Image, Class Code %02x%04x, Code Type %02x\n", - __func__, rom_data->class_hi, rom_data->class_lo, - rom_data->type); - if ((dev->class >> 8) != (rom_data->class_hi << 16 | rom_data->class_lo)) { - printk_err("%s, Class Code mismatch %x\n", - __func__, dev->class); - return NULL; + printk(BIOS_SPEW, "PCI ROM image, Class Code %04x%02x, " + "Code Type %02x\n", rom_data->class_hi, rom_data->class_lo, + rom_data->type); + + if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) { + printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n", + (rom_data->class_hi << 8) | rom_data->class_lo, + dev->class); + // return NULL; } return rom_header; } -static void *pci_ram_image_start = PCI_RAM_IMAGE_START; -struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header) +static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START; + +struct rom_header *pci_rom_load(struct device *dev, + struct rom_header *rom_header) { struct pci_data * rom_data; - unsigned long rom_address; unsigned int rom_size; + unsigned int image_size=0; + + do { + /* Get next image. */ + rom_header = (struct rom_header *)((void *) rom_header + + image_size); + + rom_data = (struct pci_data *)((void *) rom_header + + le32_to_cpu(rom_header->data)); + + image_size = le32_to_cpu(rom_data->ilen) * 512; + } while ((rom_data->type != 0) && (rom_data->indicator != 0)); // make sure we got x86 version - rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); - rom_data = (unsigned char *) rom_header + le32_to_cpu(rom_header->data); - rom_size = rom_header->size*512; + if (rom_data->type != 0) + return NULL; + + rom_size = rom_header->size * 512; - if (PCI_CLASS_DISPLAY_VGA == (rom_data->class_hi << 16 | rom_data->class_lo)) { - printk_debug("%s, copying VGA ROM Image from %x to %x, %x bytes\n", - __func__, rom_header, PCI_VGA_RAM_IMAGE_START, rom_size); - memcpy(PCI_VGA_RAM_IMAGE_START, rom_header, rom_size); + /* + * We check to see if the device thinks it is a VGA device not + * whether the ROM image is for a VGA device because some + * devices have a mismatch between the hardware and the ROM. + */ + if (PCI_CLASS_DISPLAY_VGA == (dev->class >> 8)) { +#if CONFIG_CONSOLE_VGA == 1 && CONFIG_CONSOLE_VGA_MULTI == 0 + extern device_t vga_pri; /* Primary VGA device (device.c). */ + if (dev != vga_pri) return NULL; /* Only one VGA supported. */ +#endif + if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) { + printk(BIOS_DEBUG, "Copying VGA ROM Image from %p to " + "0x%x, 0x%x bytes\n", rom_header, + PCI_VGA_RAM_IMAGE_START, rom_size); + memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, + rom_size); + } return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START); - } else { - printk_debug("%s, copying non-VGA ROM Image from %x to %x, %x bytes\n", - __func__, rom_header, pci_ram_image_start, rom_size); - memcpy(pci_ram_image_start, rom_header, rom_size); - pci_ram_image_start += rom_size; - return (struct rom_header *) pci_ram_image_start; } - /* disable expansion ROM address decoding */ - pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address & ~PCI_ROM_ADDRESS_ENABLE); + + printk(BIOS_DEBUG, "Copying non-VGA ROM image from %p to %p, 0x%x " + "bytes\n", rom_header, pci_ram_image_start, rom_size); + + memcpy(pci_ram_image_start, rom_header, rom_size); + pci_ram_image_start += rom_size; + return (struct rom_header *) (pci_ram_image_start-rom_size); }