Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 3 | * |
| 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 Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 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> |
Stefan Reinauer | d98cf5b | 2008-08-01 11:25:41 +0000 | [diff] [blame] | 29 | #include <string.h> |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 30 | #include <cbfs.h> |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 31 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 32 | struct rom_header *pci_rom_probe(struct device *dev) |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 33 | { |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 34 | struct rom_header *rom_header; |
| 35 | struct pci_data *rom_data; |
| 36 | |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 37 | /* 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. Minnich | 308312c | 2009-04-06 20:38:34 +0000 | [diff] [blame] | 39 | |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 40 | if (rom_header) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 41 | printk(BIOS_DEBUG, "In CBFS, ROM address for %s = %p\n", |
| 42 | dev_path(dev), rom_header); |
Ronald G. Minnich | a88db7b | 2009-06-09 14:44:37 +0000 | [diff] [blame] | 43 | } else { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 44 | u32 rom_address; |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 45 | |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 46 | rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 47 | |
| 48 | if (rom_address == 0x00000000 || rom_address == 0xffffffff) { |
Stefan Reinauer | 1d888a9 | 2011-04-21 20:24:43 +0000 | [diff] [blame] | 49 | #if CONFIG_BOARD_EMULATION_QEMU_X86 |
Myles Watson | ae3e998 | 2009-11-17 15:20:22 +0000 | [diff] [blame] | 50 | if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA) |
| 51 | rom_address = 0xc0000; |
| 52 | else |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 53 | #endif |
Myles Watson | ae3e998 | 2009-11-17 15:20:22 +0000 | [diff] [blame] | 54 | return NULL; |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 55 | } else { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 56 | /* Enable expansion ROM address decoding. */ |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 57 | pci_write_config32(dev, PCI_ROM_ADDRESS, |
| 58 | rom_address|PCI_ROM_ADDRESS_ENABLE); |
| 59 | } |
| 60 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 61 | printk(BIOS_DEBUG, "On card, ROM address for %s = %lx\n", |
| 62 | dev_path(dev), (unsigned long)rom_address); |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 63 | rom_header = (struct rom_header *)rom_address; |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 64 | } |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 65 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 66 | printk(BIOS_SPEW, "PCI expansion ROM, signature 0x%04x, " |
| 67 | "INIT size 0x%04x, data ptr 0x%04x\n", |
| 68 | le32_to_cpu(rom_header->signature), |
| 69 | rom_header->size * 512, le32_to_cpu(rom_header->data)); |
| 70 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 71 | if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 72 | printk(BIOS_ERR, "Incorrect expansion ROM header " |
| 73 | "signature %04x\n", le32_to_cpu(rom_header->signature)); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 74 | return NULL; |
| 75 | } |
| 76 | |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 77 | rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data)); |
| 78 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 79 | printk(BIOS_SPEW, "PCI ROM image, vendor ID %04x, device ID %04x,\n", |
| 80 | rom_data->vendor, rom_data->device); |
| 81 | if (dev->vendor != rom_data->vendor |
| 82 | || dev->device != rom_data->device) { |
| 83 | printk(BIOS_ERR, "ID mismatch: vendor ID %04x, " |
| 84 | "device ID %04x\n", rom_data->vendor, rom_data->device); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 85 | return NULL; |
| 86 | } |
| 87 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 88 | printk(BIOS_SPEW, "PCI ROM image, Class Code %04x%02x, " |
| 89 | "Code Type %02x\n", rom_data->class_hi, rom_data->class_lo, |
| 90 | rom_data->type); |
| 91 | |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 92 | if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 93 | printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 94 | (rom_data->class_hi << 8) | rom_data->class_lo, |
| 95 | dev->class); |
| 96 | // return NULL; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | return rom_header; |
| 100 | } |
| 101 | |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 102 | static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START; |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 103 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 104 | struct rom_header *pci_rom_load(struct device *dev, |
| 105 | struct rom_header *rom_header) |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 106 | { |
| 107 | struct pci_data * rom_data; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 108 | unsigned int rom_size; |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 109 | unsigned int image_size=0; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 110 | |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 111 | do { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 112 | /* Get next image. */ |
| 113 | rom_header = (struct rom_header *)((void *) rom_header |
| 114 | + image_size); |
| 115 | |
| 116 | rom_data = (struct pci_data *)((void *) rom_header |
| 117 | + le32_to_cpu(rom_header->data)); |
| 118 | |
| 119 | image_size = le32_to_cpu(rom_data->ilen) * 512; |
| 120 | } while ((rom_data->type != 0) && (rom_data->indicator != 0)); // make sure we got x86 version |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 121 | |
Stefan Reinauer | 4d59eaa | 2009-04-22 16:32:18 +0000 | [diff] [blame] | 122 | if (rom_data->type != 0) |
| 123 | return NULL; |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 124 | |
| 125 | rom_size = rom_header->size * 512; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 126 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 127 | /* |
| 128 | * We check to see if the device thinks it is a VGA device not |
| 129 | * whether the ROM image is for a VGA device because some |
| 130 | * devices have a mismatch between the hardware and the ROM. |
| 131 | */ |
Mark Marshall | 2fa7c2e | 2009-11-05 08:10:12 +0000 | [diff] [blame] | 132 | if (PCI_CLASS_DISPLAY_VGA == (dev->class >> 8)) { |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 133 | #if CONFIG_MULTIPLE_VGA_ADAPTERS == 0 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 134 | extern device_t vga_pri; /* Primary VGA device (device.c). */ |
| 135 | if (dev != vga_pri) return NULL; /* Only one VGA supported. */ |
Roman Kononov | d6d7a11 | 2007-04-09 22:50:12 +0000 | [diff] [blame] | 136 | #endif |
Ronald G. Minnich | a88db7b | 2009-06-09 14:44:37 +0000 | [diff] [blame] | 137 | if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 138 | printk(BIOS_DEBUG, "Copying VGA ROM Image from %p to " |
| 139 | "0x%x, 0x%x bytes\n", rom_header, |
| 140 | PCI_VGA_RAM_IMAGE_START, rom_size); |
| 141 | memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, |
| 142 | rom_size); |
Ronald G. Minnich | a88db7b | 2009-06-09 14:44:37 +0000 | [diff] [blame] | 143 | } |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 144 | return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 145 | } |
Stefan Reinauer | 4d59eaa | 2009-04-22 16:32:18 +0000 | [diff] [blame] | 146 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 147 | printk(BIOS_DEBUG, "Copying non-VGA ROM image from %p to %p, 0x%x " |
| 148 | "bytes\n", rom_header, pci_ram_image_start, rom_size); |
Stefan Reinauer | 4d59eaa | 2009-04-22 16:32:18 +0000 | [diff] [blame] | 149 | |
| 150 | memcpy(pci_ram_image_start, rom_header, rom_size); |
| 151 | pci_ram_image_start += rom_size; |
| 152 | return (struct rom_header *) (pci_ram_image_start-rom_size); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 153 | } |