2 * This file is part of the coreboot project.
4 * Copyright (C) 2005 Li-Ta Lo <ollie@lanl.gov>
5 * Copyright (C) 2005 Tyan
6 * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
7 * Copyright (C) 2005 Ronald G. Minnich <rminnich@gmail.com>
8 * Copyright (C) 2005-2007 Stefan Reinauer <stepan@openbios.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <console/console.h>
25 #include <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
28 #include <device/pci_ops.h>
32 struct rom_header * pci_rom_probe(struct device *dev)
34 struct rom_header *rom_header;
35 struct pci_data *rom_data;
37 /* If it's in FLASH, then don't check device for ROM. */
38 rom_header = cbfs_load_optionrom(dev->vendor, dev->device, NULL);
41 printk_debug("In cbfs, rom address for %s = %p\n",
42 dev_path(dev), rom_header);
44 unsigned long rom_address;
46 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
48 if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
49 #if defined(CONFIG_BOARD_EMULATION_QEMU_X86) \
50 && CONFIG_BOARD_EMULATION_QEMU_X86
51 if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
52 rom_address = 0xc0000;
57 /* enable expansion ROM address decoding */
58 pci_write_config32(dev, PCI_ROM_ADDRESS,
59 rom_address|PCI_ROM_ADDRESS_ENABLE);
62 printk_debug("On card, rom address for %s = %lx\n",
63 dev_path(dev), rom_address);
64 rom_header = (struct rom_header *)rom_address;
67 printk_spew("PCI Expansion ROM, signature 0x%04x, INIT size 0x%04x, data ptr 0x%04x\n",
68 le32_to_cpu(rom_header->signature),
69 rom_header->size * 512, le32_to_cpu(rom_header->data));
70 if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
71 printk_err("Incorrect Expansion ROM Header Signature %04x\n",
72 le32_to_cpu(rom_header->signature));
76 rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data));
78 printk_spew("PCI ROM Image, Vendor %04x, Device %04x,\n",
79 rom_data->vendor, rom_data->device);
80 if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) {
81 printk_err("ID mismatch: Vendor ID %04x, Device ID %04x\n",
82 rom_data->vendor, rom_data->device);
86 printk_spew("PCI ROM Image, Class Code %04x%02x, Code Type %02x\n",
87 rom_data->class_hi, rom_data->class_lo,
89 if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
90 printk_debug("Class Code mismatch ROM %08x, dev %08x\n",
91 (rom_data->class_hi << 8) | rom_data->class_lo,
99 static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START;
101 struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header)
103 struct pci_data * rom_data;
104 unsigned int rom_size;
105 unsigned int image_size=0;
108 rom_header = (struct rom_header *)((void *) rom_header + image_size); // get next image
109 rom_data = (struct pci_data *)((void *) rom_header + le32_to_cpu(rom_header->data));
110 image_size = le32_to_cpu(rom_data->ilen) * 512;
111 } while ((rom_data->type!=0) && (rom_data->indicator!=0)); // make sure we got x86 version
113 if (rom_data->type != 0)
116 rom_size = rom_header->size * 512;
118 // We check to see if the device thinks it is a VGA device not
119 // whether the ROM image is for a VGA device because some
120 // devices have a mismatch between the hardware and the ROM
121 if (PCI_CLASS_DISPLAY_VGA == (dev->class >> 8)) {
122 #if CONFIG_CONSOLE_VGA == 1 && CONFIG_CONSOLE_VGA_MULTI == 0
123 extern device_t vga_pri; // the primary vga device, defined in device.c
124 if (dev != vga_pri) return NULL; // only one VGA supported
126 if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) {
127 printk_debug("copying VGA ROM Image from %p to 0x%x, 0x%x bytes\n",
128 rom_header, PCI_VGA_RAM_IMAGE_START, rom_size);
129 memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, rom_size);
131 return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
134 printk_debug("copying non-VGA ROM Image from %p to %p, 0x%x bytes\n",
135 rom_header, pci_ram_image_start, rom_size);
137 memcpy(pci_ram_image_start, rom_header, rom_size);
138 pci_ram_image_start += rom_size;
139 return (struct rom_header *) (pci_ram_image_start-rom_size);