2007-04-22 21:08:13 +02:00
|
|
|
/*
|
2008-01-18 11:35:56 +01:00
|
|
|
* This file is part of the coreboot project.
|
2007-04-22 21:08:13 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Li-Ta Lo <ollie@lanl.gov>
|
|
|
|
* Copyright (C) 2005 Tyan
|
|
|
|
* (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
|
|
|
|
* Copyright (C) 2005 Ronald G. Minnich <rminnich@gmail.com>
|
|
|
|
* Copyright (C) 2005-2007 Stefan Reinauer <stepan@openbios.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2013-02-23 18:37:27 +01:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-04-22 21:08:13 +02:00
|
|
|
*/
|
|
|
|
|
2005-01-11 00:16:22 +01:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <device/pci_ids.h>
|
|
|
|
#include <device/pci_ops.h>
|
2008-08-01 13:25:41 +02:00
|
|
|
#include <string.h>
|
2009-04-14 09:40:01 +02:00
|
|
|
#include <cbfs.h>
|
2005-01-11 00:16:22 +01:00
|
|
|
|
2014-12-26 12:29:09 +01:00
|
|
|
/* Rmodules don't like weak symbols. */
|
|
|
|
u32 __attribute__((weak)) map_oprom_vendev(u32 vendev) { return vendev; }
|
|
|
|
|
2010-10-17 21:01:48 +02:00
|
|
|
struct rom_header *pci_rom_probe(struct device *dev)
|
2005-01-11 00:16:22 +01:00
|
|
|
{
|
|
|
|
struct rom_header *rom_header;
|
|
|
|
struct pci_data *rom_data;
|
|
|
|
|
2009-11-07 00:42:26 +01:00
|
|
|
/* If it's in FLASH, then don't check device for ROM. */
|
Extend CBFS to support arbitrary ROM source media.
Summary:
Isolate CBFS underlying I/O to board/arch-specific implementations as
"media stream", to allow loading and booting romstage on non-x86.
CBFS functions now all take a new "media source" parameter; use
CBFS_DEFAULT_MEDIA if you simply want to load from main firmware.
API Changes:
cbfs_find => cbfs_get_file.
cbfs_find_file => cbfs_get_file_content.
cbfs_get_file => cbfs_get_file_content with correct type.
CBFS used to work only on memory-mapped ROM (all x86). For platforms like ARM,
the ROM may come from USB, UART, or SPI -- any serial devices and not available
for memory mapping.
To support these devices (and allowing CBFS to read from multiple source
at the same time), CBFS operations are now virtual-ized into "cbfs_media". To
simplify porting existing code, every media source must support both "reading
into pre-allocated memory (read)" and "read and return an allocated buffer
(map)". For devices without native memory-mapped ROM, "cbfs_simple_buffer*"
provides simple memory mapping simulation.
Every CBFS function now takes a cbfs_media* as parameter. CBFS_DEFAULT_MEDIA
is defined for CBFS functions to automatically initialize a per-board default
media (CBFS will internally calls init_default_cbfs_media). Also revised CBFS
function names relying on memory mapped backend (ex, "cbfs_find" => actually
loads files). Now we only have two getters:
struct cbfs_file *entry = cbfs_get_file(media, name);
void *data = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type);
Test results:
- Verified to work on x86/qemu.
- Compiles on ARM, and follow up commit will provide working SPI driver.
Change-Id: Iac911ded25a6f2feffbf3101a81364625bb07746
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2182
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2013-01-22 11:57:56 +01:00
|
|
|
rom_header = cbfs_load_optionrom(CBFS_DEFAULT_MEDIA, dev->vendor,
|
|
|
|
dev->device, NULL);
|
2009-04-06 22:38:34 +02:00
|
|
|
|
2012-04-27 00:04:18 +02:00
|
|
|
u32 vendev = (dev->vendor << 16) | dev->device;
|
2012-01-23 23:17:52 +01:00
|
|
|
u32 mapped_vendev = vendev;
|
|
|
|
|
2014-12-26 12:29:09 +01:00
|
|
|
mapped_vendev = map_oprom_vendev(vendev);
|
2012-01-23 23:17:52 +01:00
|
|
|
|
|
|
|
if (!rom_header) {
|
|
|
|
if (vendev != mapped_vendev) {
|
Extend CBFS to support arbitrary ROM source media.
Summary:
Isolate CBFS underlying I/O to board/arch-specific implementations as
"media stream", to allow loading and booting romstage on non-x86.
CBFS functions now all take a new "media source" parameter; use
CBFS_DEFAULT_MEDIA if you simply want to load from main firmware.
API Changes:
cbfs_find => cbfs_get_file.
cbfs_find_file => cbfs_get_file_content.
cbfs_get_file => cbfs_get_file_content with correct type.
CBFS used to work only on memory-mapped ROM (all x86). For platforms like ARM,
the ROM may come from USB, UART, or SPI -- any serial devices and not available
for memory mapping.
To support these devices (and allowing CBFS to read from multiple source
at the same time), CBFS operations are now virtual-ized into "cbfs_media". To
simplify porting existing code, every media source must support both "reading
into pre-allocated memory (read)" and "read and return an allocated buffer
(map)". For devices without native memory-mapped ROM, "cbfs_simple_buffer*"
provides simple memory mapping simulation.
Every CBFS function now takes a cbfs_media* as parameter. CBFS_DEFAULT_MEDIA
is defined for CBFS functions to automatically initialize a per-board default
media (CBFS will internally calls init_default_cbfs_media). Also revised CBFS
function names relying on memory mapped backend (ex, "cbfs_find" => actually
loads files). Now we only have two getters:
struct cbfs_file *entry = cbfs_get_file(media, name);
void *data = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type);
Test results:
- Verified to work on x86/qemu.
- Compiles on ARM, and follow up commit will provide working SPI driver.
Change-Id: Iac911ded25a6f2feffbf3101a81364625bb07746
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2182
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2013-01-22 11:57:56 +01:00
|
|
|
rom_header = cbfs_load_optionrom(
|
|
|
|
CBFS_DEFAULT_MEDIA,
|
|
|
|
mapped_vendev >> 16,
|
|
|
|
mapped_vendev & 0xffff, NULL);
|
2012-01-23 23:17:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-07 00:42:26 +01:00
|
|
|
if (rom_header) {
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_DEBUG, "In CBFS, ROM address for %s = %p\n",
|
|
|
|
dev_path(dev), rom_header);
|
2009-06-09 16:44:37 +02:00
|
|
|
} else {
|
2010-11-05 00:23:47 +01:00
|
|
|
u32 rom_address;
|
2005-01-14 23:04:49 +01:00
|
|
|
|
2009-11-07 00:42:26 +01:00
|
|
|
rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
|
2005-01-11 00:16:22 +01:00
|
|
|
|
2009-11-07 00:42:26 +01:00
|
|
|
if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
|
2011-04-21 22:24:43 +02:00
|
|
|
#if CONFIG_BOARD_EMULATION_QEMU_X86
|
2009-11-17 16:20:22 +01:00
|
|
|
if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
|
|
|
|
rom_address = 0xc0000;
|
|
|
|
else
|
2010-11-05 00:23:47 +01:00
|
|
|
#endif
|
2009-11-17 16:20:22 +01:00
|
|
|
return NULL;
|
2009-11-07 00:42:26 +01:00
|
|
|
} else {
|
2010-11-05 00:23:47 +01:00
|
|
|
/* Enable expansion ROM address decoding. */
|
2009-11-07 00:42:26 +01:00
|
|
|
pci_write_config32(dev, PCI_ROM_ADDRESS,
|
|
|
|
rom_address|PCI_ROM_ADDRESS_ENABLE);
|
|
|
|
}
|
|
|
|
|
2011-10-07 01:47:51 +02:00
|
|
|
#if CONFIG_ON_DEVICE_ROM_RUN
|
|
|
|
printk(BIOS_DEBUG, "Option ROM address for %s = %lx\n",
|
2010-11-05 00:23:47 +01:00
|
|
|
dev_path(dev), (unsigned long)rom_address);
|
2009-11-07 00:42:26 +01:00
|
|
|
rom_header = (struct rom_header *)rom_address;
|
2011-10-07 01:47:51 +02:00
|
|
|
#else
|
|
|
|
printk(BIOS_DEBUG, "Option ROM execution disabled "
|
|
|
|
"for %s\n", dev_path(dev));
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2005-12-02 22:52:30 +01:00
|
|
|
}
|
2005-01-11 00:16:22 +01:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_SPEW, "PCI expansion ROM, signature 0x%04x, "
|
|
|
|
"INIT size 0x%04x, data ptr 0x%04x\n",
|
|
|
|
le32_to_cpu(rom_header->signature),
|
|
|
|
rom_header->size * 512, le32_to_cpu(rom_header->data));
|
|
|
|
|
2005-01-11 00:16:22 +01:00
|
|
|
if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_ERR, "Incorrect expansion ROM header "
|
|
|
|
"signature %04x\n", le32_to_cpu(rom_header->signature));
|
2005-01-11 00:16:22 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-07 00:42:26 +01:00
|
|
|
rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data));
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_SPEW, "PCI ROM image, vendor ID %04x, device ID %04x,\n",
|
|
|
|
rom_data->vendor, rom_data->device);
|
2012-01-23 23:17:52 +01:00
|
|
|
/* If the device id is mapped, a mismatch is expected */
|
|
|
|
if ((dev->vendor != rom_data->vendor
|
|
|
|
|| dev->device != rom_data->device)
|
|
|
|
&& (vendev == mapped_vendev)) {
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_ERR, "ID mismatch: vendor ID %04x, "
|
|
|
|
"device ID %04x\n", rom_data->vendor, rom_data->device);
|
2005-01-11 00:16:22 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_SPEW, "PCI ROM image, Class Code %04x%02x, "
|
|
|
|
"Code Type %02x\n", rom_data->class_hi, rom_data->class_lo,
|
|
|
|
rom_data->type);
|
|
|
|
|
2005-01-18 04:10:46 +01:00
|
|
|
if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
|
2010-04-27 08:56:47 +02:00
|
|
|
printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n",
|
2010-11-05 00:23:47 +01:00
|
|
|
(rom_data->class_hi << 8) | rom_data->class_lo,
|
|
|
|
dev->class);
|
|
|
|
// return NULL;
|
2005-01-11 00:16:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rom_header;
|
|
|
|
}
|
|
|
|
|
2005-12-02 22:52:30 +01:00
|
|
|
static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START;
|
2005-01-14 23:04:49 +01:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
struct rom_header *pci_rom_load(struct device *dev,
|
|
|
|
struct rom_header *rom_header)
|
2005-01-11 00:16:22 +01:00
|
|
|
{
|
|
|
|
struct pci_data * rom_data;
|
|
|
|
unsigned int rom_size;
|
2005-07-06 18:49:59 +02:00
|
|
|
unsigned int image_size=0;
|
2005-01-11 00:16:22 +01:00
|
|
|
|
2005-07-06 18:49:59 +02:00
|
|
|
do {
|
2010-11-05 00:23:47 +01:00
|
|
|
/* Get next image. */
|
|
|
|
rom_header = (struct rom_header *)((void *) rom_header
|
|
|
|
+ image_size);
|
|
|
|
|
|
|
|
rom_data = (struct pci_data *)((void *) rom_header
|
|
|
|
+ le32_to_cpu(rom_header->data));
|
|
|
|
|
|
|
|
image_size = le32_to_cpu(rom_data->ilen) * 512;
|
|
|
|
} while ((rom_data->type != 0) && (rom_data->indicator != 0)); // make sure we got x86 version
|
2005-07-06 18:49:59 +02:00
|
|
|
|
2009-04-22 18:32:18 +02:00
|
|
|
if (rom_data->type != 0)
|
|
|
|
return NULL;
|
2005-07-06 18:49:59 +02:00
|
|
|
|
|
|
|
rom_size = rom_header->size * 512;
|
2005-01-11 00:16:22 +01:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/*
|
|
|
|
* We check to see if the device thinks it is a VGA device not
|
|
|
|
* whether the ROM image is for a VGA device because some
|
|
|
|
* devices have a mismatch between the hardware and the ROM.
|
|
|
|
*/
|
2009-11-05 09:10:12 +01:00
|
|
|
if (PCI_CLASS_DISPLAY_VGA == (dev->class >> 8)) {
|
Clean up #ifs
Replace #if CONFIG_FOO==1 with #if CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*1[[:space:]]*\$,#if \1," {} +
Replace #if (CONFIG_FOO==1) with #if CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*(\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*1)[[:space:]]*\$,#if \1," {} +
Replace #if CONFIG_FOO==0 with #if !CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*0[[:space:]]*\$,#if \!\1," {} +
Replace #if (CONFIG_FOO==0) with #if !CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*(\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*0)[[:space:]]*\$,#if \!\1," {} +
(and some manual changes to fix false positives)
Change-Id: Iac6ca7605a5f99885258cf1a9a2473a92de27c42
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-on: http://review.coreboot.org/1004
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Martin Roth <martin@se-eng.com>
2012-05-05 15:29:32 +02:00
|
|
|
#if !CONFIG_MULTIPLE_VGA_ADAPTERS
|
2010-11-05 00:23:47 +01:00
|
|
|
extern device_t vga_pri; /* Primary VGA device (device.c). */
|
|
|
|
if (dev != vga_pri) return NULL; /* Only one VGA supported. */
|
2007-04-10 00:50:12 +02:00
|
|
|
#endif
|
2009-06-09 16:44:37 +02:00
|
|
|
if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) {
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_DEBUG, "Copying VGA ROM Image from %p to "
|
|
|
|
"0x%x, 0x%x bytes\n", rom_header,
|
|
|
|
PCI_VGA_RAM_IMAGE_START, rom_size);
|
|
|
|
memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header,
|
|
|
|
rom_size);
|
2009-06-09 16:44:37 +02:00
|
|
|
}
|
2005-01-11 00:16:22 +01:00
|
|
|
return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
|
|
|
|
}
|
2009-04-22 18:32:18 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_DEBUG, "Copying non-VGA ROM image from %p to %p, 0x%x "
|
|
|
|
"bytes\n", rom_header, pci_ram_image_start, rom_size);
|
2009-04-22 18:32:18 +02:00
|
|
|
|
|
|
|
memcpy(pci_ram_image_start, rom_header, rom_size);
|
|
|
|
pci_ram_image_start += rom_size;
|
|
|
|
return (struct rom_header *) (pci_ram_image_start-rom_size);
|
2005-01-11 00:16:22 +01:00
|
|
|
}
|