blob: 0ed347b4e7a1d36651bdfbb67e9104caa09c108d [file] [log] [blame]
Uwe Hermannb80dbf02007-04-22 19:08:13 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermannb80dbf02007-04-22 19:08:13 +00003 *
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>
9 *
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.
13 *
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.
18 *
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
22 */
23
Li-Ta Lo883b8792005-01-10 23:16:22 +000024#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>
Stefan Reinauerd98cf5b2008-08-01 11:25:41 +000029#include <string.h>
Peter Stuge483b7bb2009-04-14 07:40:01 +000030#include <cbfs.h>
Li-Ta Lo883b8792005-01-10 23:16:22 +000031
32struct rom_header * pci_rom_probe(struct device *dev)
33{
Li-Ta Lo883b8792005-01-10 23:16:22 +000034 struct rom_header *rom_header;
35 struct pci_data *rom_data;
36
Myles Watsond27c08c2009-11-06 23:42:26 +000037 /* If it's in FLASH, then don't check device for ROM. */
38 rom_header = cbfs_load_optionrom(dev->vendor, dev->device, NULL);
Ronald G. Minnich308312c2009-04-06 20:38:34 +000039
Myles Watsond27c08c2009-11-06 23:42:26 +000040 if (rom_header) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000041 printk(BIOS_DEBUG, "In cbfs, rom address for %s = %p\n",
Myles Watsond27c08c2009-11-06 23:42:26 +000042 dev_path(dev), rom_header);
Ronald G. Minnicha88db7b2009-06-09 14:44:37 +000043 } else {
Myles Watsond27c08c2009-11-06 23:42:26 +000044 unsigned long rom_address;
45
arch import user (historical)23053642005-07-06 16:49:59 +000046 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
Myles Watsond27c08c2009-11-06 23:42:26 +000047
48 if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
Myles Watsonae3e9982009-11-17 15:20:22 +000049 #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;
53 else
Myles Watsond27c08c2009-11-06 23:42:26 +000054 #endif
Myles Watsonae3e9982009-11-17 15:20:22 +000055 return NULL;
Myles Watsond27c08c2009-11-06 23:42:26 +000056 } else {
57 /* enable expansion ROM address decoding */
58 pci_write_config32(dev, PCI_ROM_ADDRESS,
59 rom_address|PCI_ROM_ADDRESS_ENABLE);
60 }
61
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000062 printk(BIOS_DEBUG, "On card, rom address for %s = %lx\n",
Ronald G. Minnich308312c2009-04-06 20:38:34 +000063 dev_path(dev), rom_address);
Myles Watsond27c08c2009-11-06 23:42:26 +000064 rom_header = (struct rom_header *)rom_address;
arch import user (historical)23053642005-07-06 16:49:59 +000065 }
Yinghai Lu9e4faef2005-01-14 22:04:49 +000066
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000067 printk(BIOS_SPEW, "PCI Expansion ROM, signature 0x%04x, INIT size 0x%04x, data ptr 0x%04x\n",
Yinghai Lu54ab3112005-01-18 03:10:46 +000068 le32_to_cpu(rom_header->signature),
Li-Ta Lo515f6c72005-01-11 22:48:54 +000069 rom_header->size * 512, le32_to_cpu(rom_header->data));
Li-Ta Lo883b8792005-01-10 23:16:22 +000070 if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000071 printk(BIOS_ERR, "Incorrect Expansion ROM Header Signature %04x\n",
Yinghai Lu54ab3112005-01-18 03:10:46 +000072 le32_to_cpu(rom_header->signature));
Li-Ta Lo883b8792005-01-10 23:16:22 +000073 return NULL;
74 }
75
Myles Watsond27c08c2009-11-06 23:42:26 +000076 rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data));
77
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000078 printk(BIOS_SPEW, "PCI ROM Image, Vendor %04x, Device %04x,\n",
Yinghai Lu54ab3112005-01-18 03:10:46 +000079 rom_data->vendor, rom_data->device);
Li-Ta Lo883b8792005-01-10 23:16:22 +000080 if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000081 printk(BIOS_ERR, "ID mismatch: Vendor ID %04x, Device ID %04x\n",
Li-Ta Lobec039c2005-01-19 23:19:26 +000082 rom_data->vendor, rom_data->device);
Li-Ta Lo883b8792005-01-10 23:16:22 +000083 return NULL;
84 }
85
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000086 printk(BIOS_SPEW, "PCI ROM Image, Class Code %04x%02x, Code Type %02x\n",
Yinghai Lu54ab3112005-01-18 03:10:46 +000087 rom_data->class_hi, rom_data->class_lo,
Li-Ta Lo515f6c72005-01-11 22:48:54 +000088 rom_data->type);
Yinghai Lu54ab3112005-01-18 03:10:46 +000089 if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000090 printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n",
Myles Watsond27c08c2009-11-06 23:42:26 +000091 (rom_data->class_hi << 8) | rom_data->class_lo,
92 dev->class);
arch import user (historical)dc811182005-07-06 17:16:09 +000093 //return NULL;
Li-Ta Lo883b8792005-01-10 23:16:22 +000094 }
95
96 return rom_header;
97}
98
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000099static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START;
Yinghai Lu9e4faef2005-01-14 22:04:49 +0000100
Li-Ta Lo883b8792005-01-10 23:16:22 +0000101struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header)
102{
103 struct pci_data * rom_data;
Li-Ta Lo883b8792005-01-10 23:16:22 +0000104 unsigned int rom_size;
arch import user (historical)23053642005-07-06 16:49:59 +0000105 unsigned int image_size=0;
Li-Ta Lo883b8792005-01-10 23:16:22 +0000106
arch import user (historical)23053642005-07-06 16:49:59 +0000107 do {
Stefan Reinauerd98cf5b2008-08-01 11:25:41 +0000108 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));
arch import user (historical)23053642005-07-06 16:49:59 +0000110 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
112
Stefan Reinauer4d59eaa2009-04-22 16:32:18 +0000113 if (rom_data->type != 0)
114 return NULL;
arch import user (historical)23053642005-07-06 16:49:59 +0000115
116 rom_size = rom_header->size * 512;
Li-Ta Lo883b8792005-01-10 23:16:22 +0000117
Mark Marshall2fa7c2e2009-11-05 08:10:12 +0000118 // 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)) {
Roman Kononovd6d7a112007-04-09 22:50:12 +0000122#if CONFIG_CONSOLE_VGA == 1 && CONFIG_CONSOLE_VGA_MULTI == 0
123 extern device_t vga_pri; // the primary vga device, defined in device.c
Yinghai Lu1f1085b2005-01-17 21:37:12 +0000124 if (dev != vga_pri) return NULL; // only one VGA supported
Roman Kononovd6d7a112007-04-09 22:50:12 +0000125#endif
Ronald G. Minnicha88db7b2009-06-09 14:44:37 +0000126 if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000127 printk(BIOS_DEBUG, "copying VGA ROM Image from %p to 0x%x, 0x%x bytes\n",
arch import user (historical)23053642005-07-06 16:49:59 +0000128 rom_header, PCI_VGA_RAM_IMAGE_START, rom_size);
Ronald G. Minnicha88db7b2009-06-09 14:44:37 +0000129 memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, rom_size);
130 }
Li-Ta Lo883b8792005-01-10 23:16:22 +0000131 return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
Li-Ta Lo883b8792005-01-10 23:16:22 +0000132 }
Stefan Reinauer4d59eaa2009-04-22 16:32:18 +0000133
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000134 printk(BIOS_DEBUG, "copying non-VGA ROM Image from %p to %p, 0x%x bytes\n",
Stefan Reinauer4d59eaa2009-04-22 16:32:18 +0000135 rom_header, pci_ram_image_start, rom_size);
136
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);
Li-Ta Lo883b8792005-01-10 23:16:22 +0000140}