blob: ac2e413cc0e1715018f3f9608b38546834926090 [file] [log] [blame]
Li-Ta Lo883b8792005-01-10 23:16:22 +00001#include <console/console.h>
2#include <device/device.h>
3#include <device/pci.h>
4#include <device/pci_ids.h>
5#include <device/pci_ops.h>
6
7struct rom_header * pci_rom_probe(struct device *dev)
8{
9 unsigned long rom_address;
10 struct rom_header *rom_header;
11 struct pci_data *rom_data;
12
arch import user (historical)23053642005-07-06 16:49:59 +000013 if (dev->on_mainboard) {
14 // in case some device PCI_ROM_ADDRESS can not be set or readonly
15 rom_address = dev->rom_address;
16 } else {
17 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
18 }
Yinghai Lu9e4faef2005-01-14 22:04:49 +000019
Li-Ta Lo883b8792005-01-10 23:16:22 +000020 if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
arch import user (historical)23053642005-07-06 16:49:59 +000021 return NULL;
Li-Ta Lo883b8792005-01-10 23:16:22 +000022 }
23
Li-Ta Lobec039c2005-01-19 23:19:26 +000024 printk_debug("rom address for %s = %x\n", dev_path(dev), rom_address);
Li-Ta Lo883b8792005-01-10 23:16:22 +000025
26 /* enable expansion ROM address decoding */
Li-Ta Lobec039c2005-01-19 23:19:26 +000027 pci_write_config32(dev, PCI_ROM_ADDRESS,
28 rom_address|PCI_ROM_ADDRESS_ENABLE);
Li-Ta Lo883b8792005-01-10 23:16:22 +000029
30 rom_header = rom_address;
Yinghai Lu54ab3112005-01-18 03:10:46 +000031 printk_spew("PCI Expansion ROM, signature 0x%04x, \n\t"
Li-Ta Lo515f6c72005-01-11 22:48:54 +000032 "INIT size 0x%04x, data ptr 0x%04x\n",
Yinghai Lu54ab3112005-01-18 03:10:46 +000033 le32_to_cpu(rom_header->signature),
Li-Ta Lo515f6c72005-01-11 22:48:54 +000034 rom_header->size * 512, le32_to_cpu(rom_header->data));
Li-Ta Lo883b8792005-01-10 23:16:22 +000035 if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
Yinghai Lu54ab3112005-01-18 03:10:46 +000036 printk_err("Incorrect Expansion ROM Header Signature %04x\n",
37 le32_to_cpu(rom_header->signature));
Li-Ta Lo883b8792005-01-10 23:16:22 +000038 return NULL;
39 }
40
41 rom_data = (unsigned char *) rom_header + le32_to_cpu(rom_header->data);
Li-Ta Lobec039c2005-01-19 23:19:26 +000042 printk_spew("PCI ROM Image, Vendor %04x, Device %04x,\n",
Yinghai Lu54ab3112005-01-18 03:10:46 +000043 rom_data->vendor, rom_data->device);
Li-Ta Lo883b8792005-01-10 23:16:22 +000044 if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) {
Li-Ta Lobec039c2005-01-19 23:19:26 +000045 printk_err("Device or Vendor ID mismatch Vendor %04x, Device %04x\n",
46 rom_data->vendor, rom_data->device);
Li-Ta Lo883b8792005-01-10 23:16:22 +000047 return NULL;
48 }
49
Yinghai Lu54ab3112005-01-18 03:10:46 +000050 printk_spew("PCI ROM Image, Class Code %04x%02x, Code Type %02x\n",
51 rom_data->class_hi, rom_data->class_lo,
Li-Ta Lo515f6c72005-01-11 22:48:54 +000052 rom_data->type);
Yinghai Lu54ab3112005-01-18 03:10:46 +000053 if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
54 printk_err("Class Code mismatch ROM %08x, dev %08x\n",
55 (rom_data->class_hi << 8) | rom_data->class_lo, dev->class);
arch import user (historical)dc811182005-07-06 17:16:09 +000056 //return NULL;
Li-Ta Lo883b8792005-01-10 23:16:22 +000057 }
58
59 return rom_header;
60}
61
62static void *pci_ram_image_start = PCI_RAM_IMAGE_START;
Yinghai Lu9e4faef2005-01-14 22:04:49 +000063
64#if CONFIG_CONSOLE_VGA == 1
arch import user (historical)dc811182005-07-06 17:16:09 +000065int vga_inited = 0; // used by vga_console.c
66extern device_t vga_pri; // the primary vga device, defined in device.c
Yinghai Lu9e4faef2005-01-14 22:04:49 +000067#endif
68
Li-Ta Lo883b8792005-01-10 23:16:22 +000069struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header)
70{
71 struct pci_data * rom_data;
72 unsigned long rom_address;
73 unsigned int rom_size;
arch import user (historical)23053642005-07-06 16:49:59 +000074 unsigned int image_size=0;
Li-Ta Lo883b8792005-01-10 23:16:22 +000075
76 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
arch import user (historical)23053642005-07-06 16:49:59 +000077
78 do {
79 rom_header = (unsigned char *) rom_header + image_size; // get next image
80 rom_data = (unsigned char *) rom_header + le32_to_cpu(rom_header->data);
81 image_size = le32_to_cpu(rom_data->ilen) * 512;
82 } while ((rom_data->type!=0) && (rom_data->indicator!=0)); // make sure we got x86 version
83
84 if(rom_data->type!=0) return NULL;
85
86 rom_size = rom_header->size * 512;
Li-Ta Lo883b8792005-01-10 23:16:22 +000087
Yinghai Lu54ab3112005-01-18 03:10:46 +000088 if (PCI_CLASS_DISPLAY_VGA == rom_data->class_hi) {
Yinghai Lu9e4faef2005-01-14 22:04:49 +000089#if CONFIG_CONSOLE_VGA == 1
Yinghai Lu1f1085b2005-01-17 21:37:12 +000090 if (dev != vga_pri) return NULL; // only one VGA supported
arch import user (historical)23053642005-07-06 16:49:59 +000091 printk_debug("copying VGA ROM Image from %x to %x, %x bytes\n",
92 rom_header, PCI_VGA_RAM_IMAGE_START, rom_size);
Li-Ta Lo883b8792005-01-10 23:16:22 +000093 memcpy(PCI_VGA_RAM_IMAGE_START, rom_header, rom_size);
Yinghai Lu9e4faef2005-01-14 22:04:49 +000094 vga_inited = 1;
Li-Ta Lo883b8792005-01-10 23:16:22 +000095 return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
Yinghai Lu9e4faef2005-01-14 22:04:49 +000096#endif
Li-Ta Lo883b8792005-01-10 23:16:22 +000097 } else {
Li-Ta Lo515f6c72005-01-11 22:48:54 +000098 printk_spew("%s, copying non-VGA ROM Image from %x to %x, %x bytes\n",
99 __func__, rom_header, pci_ram_image_start, rom_size);
Li-Ta Lo883b8792005-01-10 23:16:22 +0000100 memcpy(pci_ram_image_start, rom_header, rom_size);
101 pci_ram_image_start += rom_size;
102 return (struct rom_header *) pci_ram_image_start;
103 }
104 /* disable expansion ROM address decoding */
105 pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address & ~PCI_ROM_ADDRESS_ENABLE);
Yinghai Lu9e4faef2005-01-14 22:04:49 +0000106
107 return NULL;
Li-Ta Lo883b8792005-01-10 23:16:22 +0000108}