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.
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
28 /* Rmodules don't like weak symbols. */
29 u32
__attribute__((weak
)) map_oprom_vendev(u32 vendev
) { return vendev
; }
31 struct rom_header
*pci_rom_probe(struct device
*dev
)
33 struct rom_header
*rom_header
;
34 struct pci_data
*rom_data
;
36 /* If it's in FLASH, then don't check device for ROM. */
37 rom_header
= cbfs_boot_map_optionrom(dev
->vendor
, dev
->device
);
39 u32 vendev
= (dev
->vendor
<< 16) | dev
->device
;
40 u32 mapped_vendev
= vendev
;
42 mapped_vendev
= map_oprom_vendev(vendev
);
45 if (vendev
!= mapped_vendev
) {
46 rom_header
= cbfs_boot_map_optionrom(
48 mapped_vendev
& 0xffff);
53 printk(BIOS_DEBUG
, "In CBFS, ROM address for %s = %p\n",
54 dev_path(dev
), rom_header
);
56 uintptr_t rom_address
;
58 rom_address
= pci_read_config32(dev
, PCI_ROM_ADDRESS
);
60 if (rom_address
== 0x00000000 || rom_address
== 0xffffffff) {
61 #if CONFIG_BOARD_EMULATION_QEMU_X86
62 if ((dev
->class >> 8) == PCI_CLASS_DISPLAY_VGA
)
63 rom_address
= 0xc0000;
68 /* Enable expansion ROM address decoding. */
69 pci_write_config32(dev
, PCI_ROM_ADDRESS
,
70 rom_address
|PCI_ROM_ADDRESS_ENABLE
);
73 #if CONFIG_ON_DEVICE_ROM_RUN
74 printk(BIOS_DEBUG
, "Option ROM address for %s = %lx\n",
75 dev_path(dev
), (unsigned long)rom_address
);
76 rom_header
= (struct rom_header
*)rom_address
;
78 printk(BIOS_DEBUG
, "Option ROM execution disabled "
79 "for %s\n", dev_path(dev
));
84 printk(BIOS_SPEW
, "PCI expansion ROM, signature 0x%04x, "
85 "INIT size 0x%04x, data ptr 0x%04x\n",
86 le32_to_cpu(rom_header
->signature
),
87 rom_header
->size
* 512, le32_to_cpu(rom_header
->data
));
89 if (le32_to_cpu(rom_header
->signature
) != PCI_ROM_HDR
) {
90 printk(BIOS_ERR
, "Incorrect expansion ROM header "
91 "signature %04x\n", le32_to_cpu(rom_header
->signature
));
95 rom_data
= (((void *)rom_header
) + le32_to_cpu(rom_header
->data
));
97 printk(BIOS_SPEW
, "PCI ROM image, vendor ID %04x, device ID %04x,\n",
98 rom_data
->vendor
, rom_data
->device
);
99 /* If the device id is mapped, a mismatch is expected */
100 if ((dev
->vendor
!= rom_data
->vendor
101 || dev
->device
!= rom_data
->device
)
102 && (vendev
== mapped_vendev
)) {
103 printk(BIOS_ERR
, "ID mismatch: vendor ID %04x, "
104 "device ID %04x\n", rom_data
->vendor
, rom_data
->device
);
108 printk(BIOS_SPEW
, "PCI ROM image, Class Code %04x%02x, "
109 "Code Type %02x\n", rom_data
->class_hi
, rom_data
->class_lo
,
112 if (dev
->class != ((rom_data
->class_hi
<< 8) | rom_data
->class_lo
)) {
113 printk(BIOS_DEBUG
, "Class Code mismatch ROM %08x, dev %08x\n",
114 (rom_data
->class_hi
<< 8) | rom_data
->class_lo
,
122 static void *pci_ram_image_start
= (void *)PCI_RAM_IMAGE_START
;
124 struct rom_header
*pci_rom_load(struct device
*dev
,
125 struct rom_header
*rom_header
)
127 struct pci_data
* rom_data
;
128 unsigned int rom_size
;
129 unsigned int image_size
=0;
132 /* Get next image. */
133 rom_header
= (struct rom_header
*)((void *) rom_header
136 rom_data
= (struct pci_data
*)((void *) rom_header
137 + le32_to_cpu(rom_header
->data
));
139 image_size
= le32_to_cpu(rom_data
->ilen
) * 512;
140 } while ((rom_data
->type
!= 0) && (rom_data
->indicator
!= 0)); // make sure we got x86 version
142 if (rom_data
->type
!= 0)
145 rom_size
= rom_header
->size
* 512;
148 * We check to see if the device thinks it is a VGA device not
149 * whether the ROM image is for a VGA device because some
150 * devices have a mismatch between the hardware and the ROM.
152 if (PCI_CLASS_DISPLAY_VGA
== (dev
->class >> 8)) {
153 #if !CONFIG_MULTIPLE_VGA_ADAPTERS
154 extern device_t vga_pri
; /* Primary VGA device (device.c). */
155 if (dev
!= vga_pri
) return NULL
; /* Only one VGA supported. */
157 if ((void *)PCI_VGA_RAM_IMAGE_START
!= rom_header
) {
158 printk(BIOS_DEBUG
, "Copying VGA ROM Image from %p to "
159 "0x%x, 0x%x bytes\n", rom_header
,
160 PCI_VGA_RAM_IMAGE_START
, rom_size
);
161 memcpy((void *)PCI_VGA_RAM_IMAGE_START
, rom_header
,
164 return (struct rom_header
*) (PCI_VGA_RAM_IMAGE_START
);
167 printk(BIOS_DEBUG
, "Copying non-VGA ROM image from %p to %p, 0x%x "
168 "bytes\n", rom_header
, pci_ram_image_start
, rom_size
);
170 memcpy(pci_ram_image_start
, rom_header
, rom_size
);
171 pci_ram_image_start
+= rom_size
;
172 return (struct rom_header
*) (pci_ram_image_start
-rom_size
);