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 | |
| 32 | struct rom_header * pci_rom_probe(struct device *dev) |
| 33 | { |
Ronald G. Minnich | 308312c | 2009-04-06 20:38:34 +0000 | [diff] [blame] | 34 | unsigned long rom_address = 0; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 35 | struct rom_header *rom_header; |
| 36 | struct pci_data *rom_data; |
| 37 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 38 | if (CONFIG_CBFS) { |
Ronald G. Minnich | 308312c | 2009-04-06 20:38:34 +0000 | [diff] [blame] | 39 | void *v; |
Ronald G. Minnich | 662d52d | 2009-04-06 16:03:53 +0000 | [diff] [blame] | 40 | /* if it's in FLASH, then it's as if dev->on_mainboard was true */ |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 41 | v = cbfs_load_optionrom(dev->vendor, dev->device, NULL); |
Ronald G. Minnich | 308312c | 2009-04-06 20:38:34 +0000 | [diff] [blame] | 42 | printk_debug("In cbfs, rom address for %s = %lx\n", |
| 43 | dev_path(dev), rom_address); |
| 44 | if (v) { |
Patrick Georgi | 16cdbb2 | 2009-04-21 20:14:31 +0000 | [diff] [blame^] | 45 | dev->rom_address = (u32)v; |
Ronald G. Minnich | 308312c | 2009-04-06 20:38:34 +0000 | [diff] [blame] | 46 | dev->on_mainboard = 1; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if (dev->on_mainboard) { |
Ronald G. Minnich | 662d52d | 2009-04-06 16:03:53 +0000 | [diff] [blame] | 51 | /* this is here as a legacy path. We hope it goes away soon. Users should not have to |
| 52 | * compute the ROM address at build time! |
| 53 | */ |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 54 | // in case some device PCI_ROM_ADDRESS can not be set or readonly |
| 55 | rom_address = dev->rom_address; |
Ronald G. Minnich | 308312c | 2009-04-06 20:38:34 +0000 | [diff] [blame] | 56 | printk_debug("On mainboard, rom address for %s = %lx\n", |
| 57 | dev_path(dev), rom_address); |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 58 | } else { |
| 59 | rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); |
Ronald G. Minnich | 308312c | 2009-04-06 20:38:34 +0000 | [diff] [blame] | 60 | printk_debug("On card, rom address for %s = %lx\n", |
| 61 | dev_path(dev), rom_address); |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 62 | } |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 63 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 64 | if (rom_address == 0x00000000 || rom_address == 0xffffffff) { |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 65 | return NULL; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 68 | if(!dev->on_mainboard) { |
| 69 | /* enable expansion ROM address decoding */ |
| 70 | pci_write_config32(dev, PCI_ROM_ADDRESS, |
| 71 | rom_address|PCI_ROM_ADDRESS_ENABLE); |
| 72 | } |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 73 | |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 74 | rom_header = (struct rom_header *)rom_address; |
| 75 | printk_spew("PCI Expansion ROM, signature 0x%04x, INIT size 0x%04x, data ptr 0x%04x\n", |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 76 | le32_to_cpu(rom_header->signature), |
Li-Ta Lo | 515f6c7 | 2005-01-11 22:48:54 +0000 | [diff] [blame] | 77 | rom_header->size * 512, le32_to_cpu(rom_header->data)); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 78 | if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) { |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 79 | printk_err("Incorrect Expansion ROM Header Signature %04x\n", |
| 80 | le32_to_cpu(rom_header->signature)); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 81 | return NULL; |
| 82 | } |
| 83 | |
Stefan Reinauer | d98cf5b | 2008-08-01 11:25:41 +0000 | [diff] [blame] | 84 | rom_data = (struct pci_data *) ((void *)rom_header + le32_to_cpu(rom_header->data)); |
Li-Ta Lo | bec039c | 2005-01-19 23:19:26 +0000 | [diff] [blame] | 85 | printk_spew("PCI ROM Image, Vendor %04x, Device %04x,\n", |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 86 | rom_data->vendor, rom_data->device); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 87 | if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) { |
Li-Ta Lo | bec039c | 2005-01-19 23:19:26 +0000 | [diff] [blame] | 88 | printk_err("Device or Vendor ID mismatch Vendor %04x, Device %04x\n", |
| 89 | rom_data->vendor, rom_data->device); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 90 | return NULL; |
| 91 | } |
| 92 | |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 93 | printk_spew("PCI ROM Image, Class Code %04x%02x, Code Type %02x\n", |
| 94 | rom_data->class_hi, rom_data->class_lo, |
Li-Ta Lo | 515f6c7 | 2005-01-11 22:48:54 +0000 | [diff] [blame] | 95 | rom_data->type); |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 96 | if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) { |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 97 | printk_debug("Class Code mismatch ROM %08x, dev %08x\n", |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 98 | (rom_data->class_hi << 8) | rom_data->class_lo, dev->class); |
arch import user (historical) | dc81118 | 2005-07-06 17:16:09 +0000 | [diff] [blame] | 99 | //return NULL; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | return rom_header; |
| 103 | } |
| 104 | |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 105 | static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START; |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 106 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 107 | struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header) |
| 108 | { |
| 109 | struct pci_data * rom_data; |
| 110 | unsigned long rom_address; |
| 111 | unsigned int rom_size; |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 112 | unsigned int image_size=0; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 113 | |
| 114 | rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 115 | |
| 116 | do { |
Stefan Reinauer | d98cf5b | 2008-08-01 11:25:41 +0000 | [diff] [blame] | 117 | rom_header = (struct rom_header *)((void *) rom_header + image_size); // get next image |
| 118 | rom_data = (struct pci_data *)((void *) rom_header + le32_to_cpu(rom_header->data)); |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 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 |
| 121 | |
| 122 | if(rom_data->type!=0) return NULL; |
| 123 | |
| 124 | rom_size = rom_header->size * 512; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 125 | |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 126 | if (PCI_CLASS_DISPLAY_VGA == rom_data->class_hi) { |
Roman Kononov | d6d7a11 | 2007-04-09 22:50:12 +0000 | [diff] [blame] | 127 | #if CONFIG_CONSOLE_VGA == 1 && CONFIG_CONSOLE_VGA_MULTI == 0 |
| 128 | extern device_t vga_pri; // the primary vga device, defined in device.c |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 129 | if (dev != vga_pri) return NULL; // only one VGA supported |
Roman Kononov | d6d7a11 | 2007-04-09 22:50:12 +0000 | [diff] [blame] | 130 | #endif |
Myles Watson | c4ddbff | 2009-02-09 17:52:54 +0000 | [diff] [blame] | 131 | printk_debug("copying VGA ROM Image from %p to 0x%x, 0x%x bytes\n", |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 132 | rom_header, PCI_VGA_RAM_IMAGE_START, rom_size); |
Stefan Reinauer | d98cf5b | 2008-08-01 11:25:41 +0000 | [diff] [blame] | 133 | memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, rom_size); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 134 | return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START); |
| 135 | } else { |
Myles Watson | c4ddbff | 2009-02-09 17:52:54 +0000 | [diff] [blame] | 136 | printk_debug("copying non-VGA ROM Image from %p to %p, 0x%x bytes\n", |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 137 | rom_header, pci_ram_image_start, rom_size); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 138 | memcpy(pci_ram_image_start, rom_header, rom_size); |
| 139 | pci_ram_image_start += rom_size; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 140 | return (struct rom_header *) (pci_ram_image_start-rom_size); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 141 | } |
| 142 | /* disable expansion ROM address decoding */ |
| 143 | pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address & ~PCI_ROM_ADDRESS_ENABLE); |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 144 | |
| 145 | return NULL; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 146 | } |