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);
40 u32 vendev = dev->vendor | (dev->device << 16);
41 u32 mapped_vendev = vendev;
44 mapped_vendev = map_oprom_vendev(vendev);
47 if (vendev != mapped_vendev) {
48 rom_header = cbfs_load_optionrom(mapped_vendev &
49 0xffff, mapped_vendev >> 16, NULL);
54 printk(BIOS_DEBUG, "In CBFS, ROM address for %s = %p\n",
55 dev_path(dev), rom_header);
59 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
61 if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
62 #if CONFIG_BOARD_EMULATION_QEMU_X86
63 if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
64 rom_address = 0xc0000;
69 /* Enable expansion ROM address decoding. */
70 pci_write_config32(dev, PCI_ROM_ADDRESS,
71 rom_address|PCI_ROM_ADDRESS_ENABLE);
74 #if CONFIG_ON_DEVICE_ROM_RUN
75 printk(BIOS_DEBUG, "Option ROM address for %s = %lx\n",
76 dev_path(dev), (unsigned long)rom_address);
77 rom_header = (struct rom_header *)rom_address;
79 printk(BIOS_DEBUG, "Option ROM execution disabled "
80 "for %s\n", dev_path(dev));
85 printk(BIOS_SPEW, "PCI expansion ROM, signature 0x%04x, "
86 "INIT size 0x%04x, data ptr 0x%04x\n",
87 le32_to_cpu(rom_header->signature),
88 rom_header->size * 512, le32_to_cpu(rom_header->data));
90 if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
91 printk(BIOS_ERR, "Incorrect expansion ROM header "
92 "signature %04x\n", le32_to_cpu(rom_header->signature));
96 rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data));
98 printk(BIOS_SPEW, "PCI ROM image, vendor ID %04x, device ID %04x,\n",
99 rom_data->vendor, rom_data->device);
100 /* If the device id is mapped, a mismatch is expected */
101 if ((dev->vendor != rom_data->vendor
102 || dev->device != rom_data->device)
103 && (vendev == mapped_vendev)) {
104 printk(BIOS_ERR, "ID mismatch: vendor ID %04x, "
105 "device ID %04x\n", rom_data->vendor, rom_data->device);
109 printk(BIOS_SPEW, "PCI ROM image, Class Code %04x%02x, "
110 "Code Type %02x\n", rom_data->class_hi, rom_data->class_lo,
113 if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
114 printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n",
115 (rom_data->class_hi << 8) | rom_data->class_lo,
123 static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START;
125 struct rom_header *pci_rom_load(struct device *dev,
126 struct rom_header *rom_header)
128 struct pci_data * rom_data;
129 unsigned int rom_size;
130 unsigned int image_size=0;
133 /* Get next image. */
134 rom_header = (struct rom_header *)((void *) rom_header
137 rom_data = (struct pci_data *)((void *) rom_header
138 + le32_to_cpu(rom_header->data));
140 image_size = le32_to_cpu(rom_data->ilen) * 512;
141 } while ((rom_data->type != 0) && (rom_data->indicator != 0)); // make sure we got x86 version
143 if (rom_data->type != 0)
146 rom_size = rom_header->size * 512;
149 * We check to see if the device thinks it is a VGA device not
150 * whether the ROM image is for a VGA device because some
151 * devices have a mismatch between the hardware and the ROM.
153 if (PCI_CLASS_DISPLAY_VGA == (dev->class >> 8)) {
154 #if CONFIG_MULTIPLE_VGA_ADAPTERS == 0
155 extern device_t vga_pri; /* Primary VGA device (device.c). */
156 if (dev != vga_pri) return NULL; /* Only one VGA supported. */
158 if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) {
159 printk(BIOS_DEBUG, "Copying VGA ROM Image from %p to "
160 "0x%x, 0x%x bytes\n", rom_header,
161 PCI_VGA_RAM_IMAGE_START, rom_size);
162 memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header,
165 return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
168 printk(BIOS_DEBUG, "Copying non-VGA ROM image from %p to %p, 0x%x "
169 "bytes\n", rom_header, pci_ram_image_start, rom_size);
171 memcpy(pci_ram_image_start, rom_header, rom_size);
172 pci_ram_image_start += rom_size;
173 return (struct rom_header *) (pci_ram_image_start-rom_size);