Remove address from GPLv2 headers
[coreboot.git] / src / device / pci_rom.c
blob04db05c09f069a3601fd4b90d633fb38dc517ef7
1 /*
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.
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>
29 #include <string.h>
30 #include <cbfs.h>
32 /* Rmodules don't like weak symbols. */
33 u32 __attribute__((weak)) map_oprom_vendev(u32 vendev) { return vendev; }
35 struct rom_header *pci_rom_probe(struct device *dev)
37 struct rom_header *rom_header;
38 struct pci_data *rom_data;
40 /* If it's in FLASH, then don't check device for ROM. */
41 rom_header = cbfs_load_optionrom(CBFS_DEFAULT_MEDIA, dev->vendor,
42 dev->device, NULL);
44 u32 vendev = (dev->vendor << 16) | dev->device;
45 u32 mapped_vendev = vendev;
47 mapped_vendev = map_oprom_vendev(vendev);
49 if (!rom_header) {
50 if (vendev != mapped_vendev) {
51 rom_header = cbfs_load_optionrom(
52 CBFS_DEFAULT_MEDIA,
53 mapped_vendev >> 16,
54 mapped_vendev & 0xffff, NULL);
58 if (rom_header) {
59 printk(BIOS_DEBUG, "In CBFS, ROM address for %s = %p\n",
60 dev_path(dev), rom_header);
61 } else {
62 u32 rom_address;
64 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
66 if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
67 #if CONFIG_BOARD_EMULATION_QEMU_X86
68 if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
69 rom_address = 0xc0000;
70 else
71 #endif
72 return NULL;
73 } else {
74 /* Enable expansion ROM address decoding. */
75 pci_write_config32(dev, PCI_ROM_ADDRESS,
76 rom_address|PCI_ROM_ADDRESS_ENABLE);
79 #if CONFIG_ON_DEVICE_ROM_RUN
80 printk(BIOS_DEBUG, "Option ROM address for %s = %lx\n",
81 dev_path(dev), (unsigned long)rom_address);
82 rom_header = (struct rom_header *)rom_address;
83 #else
84 printk(BIOS_DEBUG, "Option ROM execution disabled "
85 "for %s\n", dev_path(dev));
86 return NULL;
87 #endif
90 printk(BIOS_SPEW, "PCI expansion ROM, signature 0x%04x, "
91 "INIT size 0x%04x, data ptr 0x%04x\n",
92 le32_to_cpu(rom_header->signature),
93 rom_header->size * 512, le32_to_cpu(rom_header->data));
95 if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
96 printk(BIOS_ERR, "Incorrect expansion ROM header "
97 "signature %04x\n", le32_to_cpu(rom_header->signature));
98 return NULL;
101 rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data));
103 printk(BIOS_SPEW, "PCI ROM image, vendor ID %04x, device ID %04x,\n",
104 rom_data->vendor, rom_data->device);
105 /* If the device id is mapped, a mismatch is expected */
106 if ((dev->vendor != rom_data->vendor
107 || dev->device != rom_data->device)
108 && (vendev == mapped_vendev)) {
109 printk(BIOS_ERR, "ID mismatch: vendor ID %04x, "
110 "device ID %04x\n", rom_data->vendor, rom_data->device);
111 return NULL;
114 printk(BIOS_SPEW, "PCI ROM image, Class Code %04x%02x, "
115 "Code Type %02x\n", rom_data->class_hi, rom_data->class_lo,
116 rom_data->type);
118 if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
119 printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n",
120 (rom_data->class_hi << 8) | rom_data->class_lo,
121 dev->class);
122 // return NULL;
125 return rom_header;
128 static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START;
130 struct rom_header *pci_rom_load(struct device *dev,
131 struct rom_header *rom_header)
133 struct pci_data * rom_data;
134 unsigned int rom_size;
135 unsigned int image_size=0;
137 do {
138 /* Get next image. */
139 rom_header = (struct rom_header *)((void *) rom_header
140 + image_size);
142 rom_data = (struct pci_data *)((void *) rom_header
143 + le32_to_cpu(rom_header->data));
145 image_size = le32_to_cpu(rom_data->ilen) * 512;
146 } while ((rom_data->type != 0) && (rom_data->indicator != 0)); // make sure we got x86 version
148 if (rom_data->type != 0)
149 return NULL;
151 rom_size = rom_header->size * 512;
154 * We check to see if the device thinks it is a VGA device not
155 * whether the ROM image is for a VGA device because some
156 * devices have a mismatch between the hardware and the ROM.
158 if (PCI_CLASS_DISPLAY_VGA == (dev->class >> 8)) {
159 #if !CONFIG_MULTIPLE_VGA_ADAPTERS
160 extern device_t vga_pri; /* Primary VGA device (device.c). */
161 if (dev != vga_pri) return NULL; /* Only one VGA supported. */
162 #endif
163 if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) {
164 printk(BIOS_DEBUG, "Copying VGA ROM Image from %p to "
165 "0x%x, 0x%x bytes\n", rom_header,
166 PCI_VGA_RAM_IMAGE_START, rom_size);
167 memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header,
168 rom_size);
170 return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
173 printk(BIOS_DEBUG, "Copying non-VGA ROM image from %p to %p, 0x%x "
174 "bytes\n", rom_header, pci_ram_image_start, rom_size);
176 memcpy(pci_ram_image_start, rom_header, rom_size);
177 pci_ram_image_start += rom_size;
178 return (struct rom_header *) (pci_ram_image_start-rom_size);