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>
|
|
|
|
|
|
|
|
struct rom_header * pci_rom_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
unsigned long rom_address;
|
|
|
|
struct rom_header *rom_header;
|
|
|
|
struct pci_data *rom_data;
|
|
|
|
|
2005-07-06 18:49:59 +02:00
|
|
|
if (dev->on_mainboard) {
|
|
|
|
// in case some device PCI_ROM_ADDRESS can not be set or readonly
|
|
|
|
rom_address = dev->rom_address;
|
|
|
|
} else {
|
|
|
|
rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
|
|
|
|
}
|
2005-01-14 23:04:49 +01:00
|
|
|
|
2005-01-11 00:16:22 +01:00
|
|
|
if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
|
2005-07-06 18:49:59 +02:00
|
|
|
return NULL;
|
2005-01-11 00:16:22 +01:00
|
|
|
}
|
|
|
|
|
2005-01-20 00:19:26 +01:00
|
|
|
printk_debug("rom address for %s = %x\n", dev_path(dev), rom_address);
|
2005-01-11 00:16:22 +01:00
|
|
|
|
|
|
|
/* enable expansion ROM address decoding */
|
2005-01-20 00:19:26 +01:00
|
|
|
pci_write_config32(dev, PCI_ROM_ADDRESS,
|
|
|
|
rom_address|PCI_ROM_ADDRESS_ENABLE);
|
2005-01-11 00:16:22 +01:00
|
|
|
|
|
|
|
rom_header = rom_address;
|
2005-01-18 04:10:46 +01:00
|
|
|
printk_spew("PCI Expansion ROM, signature 0x%04x, \n\t"
|
2005-01-11 23:48:54 +01:00
|
|
|
"INIT size 0x%04x, data ptr 0x%04x\n",
|
2005-01-18 04:10:46 +01:00
|
|
|
le32_to_cpu(rom_header->signature),
|
2005-01-11 23:48:54 +01:00
|
|
|
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) {
|
2005-01-18 04:10:46 +01:00
|
|
|
printk_err("Incorrect Expansion ROM Header Signature %04x\n",
|
|
|
|
le32_to_cpu(rom_header->signature));
|
2005-01-11 00:16:22 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rom_data = (unsigned char *) rom_header + le32_to_cpu(rom_header->data);
|
2005-01-20 00:19:26 +01:00
|
|
|
printk_spew("PCI ROM Image, Vendor %04x, Device %04x,\n",
|
2005-01-18 04:10:46 +01:00
|
|
|
rom_data->vendor, rom_data->device);
|
2005-01-11 00:16:22 +01:00
|
|
|
if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) {
|
2005-01-20 00:19:26 +01:00
|
|
|
printk_err("Device or Vendor ID mismatch Vendor %04x, Device %04x\n",
|
|
|
|
rom_data->vendor, rom_data->device);
|
2005-01-11 00:16:22 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-18 04:10:46 +01:00
|
|
|
printk_spew("PCI ROM Image, Class Code %04x%02x, Code Type %02x\n",
|
|
|
|
rom_data->class_hi, rom_data->class_lo,
|
2005-01-11 23:48:54 +01:00
|
|
|
rom_data->type);
|
2005-01-18 04:10:46 +01:00
|
|
|
if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
|
|
|
|
printk_err("Class Code mismatch ROM %08x, dev %08x\n",
|
|
|
|
(rom_data->class_hi << 8) | rom_data->class_lo, dev->class);
|
2005-07-06 19:15:48 +02:00
|
|
|
//return NULL;
|
2005-01-11 00:16:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rom_header;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *pci_ram_image_start = PCI_RAM_IMAGE_START;
|
2005-01-14 23:04:49 +01:00
|
|
|
|
|
|
|
#if CONFIG_CONSOLE_VGA == 1
|
2005-07-06 19:15:48 +02:00
|
|
|
int vga_inited = 0; // used by vga_console.c
|
|
|
|
extern device_t vga_pri; // the primary vga device, defined in device.c
|
2005-01-14 23:04:49 +01:00
|
|
|
#endif
|
|
|
|
|
2005-01-11 00:16:22 +01:00
|
|
|
struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header)
|
|
|
|
{
|
|
|
|
struct pci_data * rom_data;
|
|
|
|
unsigned long rom_address;
|
|
|
|
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
|
|
|
|
|
|
|
rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
|
2005-07-06 18:49:59 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
rom_header = (unsigned char *) rom_header + image_size; // get next image
|
|
|
|
rom_data = (unsigned char *) 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
|
|
|
|
|
|
|
|
if(rom_data->type!=0) return NULL;
|
|
|
|
|
|
|
|
rom_size = rom_header->size * 512;
|
2005-01-11 00:16:22 +01:00
|
|
|
|
2005-01-18 04:10:46 +01:00
|
|
|
if (PCI_CLASS_DISPLAY_VGA == rom_data->class_hi) {
|
2005-01-14 23:04:49 +01:00
|
|
|
#if CONFIG_CONSOLE_VGA == 1
|
2005-01-17 22:37:12 +01:00
|
|
|
if (dev != vga_pri) return NULL; // only one VGA supported
|
2005-07-06 18:49:59 +02:00
|
|
|
printk_debug("copying VGA ROM Image from %x to %x, %x bytes\n",
|
|
|
|
rom_header, PCI_VGA_RAM_IMAGE_START, rom_size);
|
2005-01-11 00:16:22 +01:00
|
|
|
memcpy(PCI_VGA_RAM_IMAGE_START, rom_header, rom_size);
|
2005-01-14 23:04:49 +01:00
|
|
|
vga_inited = 1;
|
2005-01-11 00:16:22 +01:00
|
|
|
return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
|
2005-01-14 23:04:49 +01:00
|
|
|
#endif
|
2005-01-11 00:16:22 +01:00
|
|
|
} else {
|
2005-01-11 23:48:54 +01:00
|
|
|
printk_spew("%s, copying non-VGA ROM Image from %x to %x, %x bytes\n",
|
|
|
|
__func__, rom_header, pci_ram_image_start, rom_size);
|
2005-01-11 00:16:22 +01:00
|
|
|
memcpy(pci_ram_image_start, rom_header, rom_size);
|
|
|
|
pci_ram_image_start += rom_size;
|
|
|
|
return (struct rom_header *) pci_ram_image_start;
|
|
|
|
}
|
|
|
|
/* disable expansion ROM address decoding */
|
|
|
|
pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address & ~PCI_ROM_ADDRESS_ENABLE);
|
2005-01-14 23:04:49 +01:00
|
|
|
|
|
|
|
return NULL;
|
2005-01-11 00:16:22 +01:00
|
|
|
}
|