blob: 92f0b0980f8b8a359a533346058e56bf49cb7175 [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
13 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
Yinghai Lu9e4faef2005-01-14 22:04:49 +000014
Li-Ta Lo883b8792005-01-10 23:16:22 +000015 if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
Li-Ta Lo883b8792005-01-10 23:16:22 +000016 return NULL;
17 }
18
Yinghai Lu9e4faef2005-01-14 22:04:49 +000019 printk_debug("%s, rom address for %s = %x\n",
Li-Ta Lo515f6c72005-01-11 22:48:54 +000020 __func__, dev_path(dev), rom_address);
Li-Ta Lo883b8792005-01-10 23:16:22 +000021
22 /* enable expansion ROM address decoding */
23 pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address|PCI_ROM_ADDRESS_ENABLE);
24
25 rom_header = rom_address;
Li-Ta Lo515f6c72005-01-11 22:48:54 +000026 printk_spew("%s, PCI Expansion ROM, signature 0x%04x, \n\t"
27 "INIT size 0x%04x, data ptr 0x%04x\n",
28 __func__, le32_to_cpu(rom_header->signature),
29 rom_header->size * 512, le32_to_cpu(rom_header->data));
Li-Ta Lo883b8792005-01-10 23:16:22 +000030 if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
31 printk_err("%s, Incorrect Expansion ROM Header Signature %04x\n",
32 __func__, le32_to_cpu(rom_header->signature));
33 return NULL;
34 }
35
36 rom_data = (unsigned char *) rom_header + le32_to_cpu(rom_header->data);
Li-Ta Lo515f6c72005-01-11 22:48:54 +000037 printk_spew("%s, PCI ROM Image, Vendor %04x, Device %04x,\n",
38 __func__, rom_data->vendor, rom_data->device);
Li-Ta Lo883b8792005-01-10 23:16:22 +000039 if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) {
40 printk_err("%s, Device or Vendor ID mismatch\n");
41 return NULL;
42 }
43
Li-Ta Lo515f6c72005-01-11 22:48:54 +000044 printk_spew("%s, PCI ROM Image, Class Code %02x%04x, Code Type %02x\n",
45 __func__, rom_data->class_hi, rom_data->class_lo,
46 rom_data->type);
Li-Ta Lo883b8792005-01-10 23:16:22 +000047 if ((dev->class >> 8) != (rom_data->class_hi << 16 | rom_data->class_lo)) {
48 printk_err("%s, Class Code mismatch %x\n",
49 __func__, dev->class);
50 return NULL;
51 }
52
53 return rom_header;
54}
55
56static void *pci_ram_image_start = PCI_RAM_IMAGE_START;
Yinghai Lu9e4faef2005-01-14 22:04:49 +000057
58#if CONFIG_CONSOLE_VGA == 1
59int vga_inited = 0; // it will be used by vga_console
Yinghai Lu1f1085b2005-01-17 21:37:12 +000060extern device_t vga_pri; // The only VGA
Yinghai Lu9e4faef2005-01-14 22:04:49 +000061#endif
62
Li-Ta Lo883b8792005-01-10 23:16:22 +000063struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header)
64{
65 struct pci_data * rom_data;
66 unsigned long rom_address;
67 unsigned int rom_size;
68
69 rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
70 rom_data = (unsigned char *) rom_header + le32_to_cpu(rom_header->data);
71 rom_size = rom_header->size*512;
72
73 if (PCI_CLASS_DISPLAY_VGA == (rom_data->class_hi << 16 | rom_data->class_lo)) {
Yinghai Lu9e4faef2005-01-14 22:04:49 +000074#if CONFIG_CONSOLE_VGA == 1
Yinghai Lu1f1085b2005-01-17 21:37:12 +000075 if (dev != vga_pri) return NULL; // only one VGA supported
Li-Ta Lo515f6c72005-01-11 22:48:54 +000076 printk_spew("%s, copying VGA ROM Image from %x to %x, %x bytes\n",
77 __func__, rom_header, PCI_VGA_RAM_IMAGE_START, rom_size);
Li-Ta Lo883b8792005-01-10 23:16:22 +000078 memcpy(PCI_VGA_RAM_IMAGE_START, rom_header, rom_size);
Yinghai Lu9e4faef2005-01-14 22:04:49 +000079 vga_inited = 1;
Li-Ta Lo883b8792005-01-10 23:16:22 +000080 return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
Yinghai Lu9e4faef2005-01-14 22:04:49 +000081#endif
Li-Ta Lo883b8792005-01-10 23:16:22 +000082 } else {
Li-Ta Lo515f6c72005-01-11 22:48:54 +000083 printk_spew("%s, copying non-VGA ROM Image from %x to %x, %x bytes\n",
84 __func__, rom_header, pci_ram_image_start, rom_size);
Li-Ta Lo883b8792005-01-10 23:16:22 +000085 memcpy(pci_ram_image_start, rom_header, rom_size);
86 pci_ram_image_start += rom_size;
87 return (struct rom_header *) pci_ram_image_start;
88 }
89 /* disable expansion ROM address decoding */
90 pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address & ~PCI_ROM_ADDRESS_ENABLE);
Yinghai Lu9e4faef2005-01-14 22:04:49 +000091
92 return NULL;
Li-Ta Lo883b8792005-01-10 23:16:22 +000093}