5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #undef PCI_ROM_SCAN_VERBOSE
31 int pci_shadow_rom(pci_dev_t dev, unsigned char *dest)
33 struct pci_controller *hose;
47 hose = pci_bus_to_hose(PCI_BUS(dev));
49 debug("pci_shadow_rom() asked to shadow device %x to %x\n",
52 pci_read_config_word(dev, PCI_VENDOR_ID, &vendor);
53 pci_read_config_word(dev, PCI_DEVICE_ID, &device);
54 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_code);
56 class_code &= 0xffffff00;
59 debug("PCI Header Vendor %04x device %04x class %06x\n",
60 vendor, device, class_code);
62 /* Enable the rom addess decoder */
63 pci_write_config_dword(dev, PCI_ROM_ADDRESS, (u32)PCI_ROM_ADDRESS_MASK);
64 pci_read_config_dword(dev, PCI_ROM_ADDRESS, &addr_reg);
67 /* register unimplemented */
68 printf("pci_chadow_rom: device do not seem to have a rom\n");
72 size = (~(addr_reg&PCI_ROM_ADDRESS_MASK)) + 1;
74 debug("ROM is %d bytes\n", size);
76 rom_addr = pci_get_rom_window(hose, size);
78 debug("ROM mapped at %x\n", rom_addr);
80 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
81 pci_phys_to_mem(dev, rom_addr)
82 |PCI_ROM_ADDRESS_ENABLE);
85 for (i = rom_addr; i < rom_addr + size; i += 512) {
86 if (readw(i) == 0xaa55) {
87 #ifdef PCI_ROM_SCAN_VERBOSE
88 printf("ROM signature found\n");
90 pci_data = readw(0x18 + i);
93 if (0 == memcmp((void *)pci_data, "PCIR", 4)) {
94 #ifdef PCI_ROM_SCAN_VERBOSE
95 printf("Fount PCI rom image at offset %d\n",
97 printf("Vendor %04x device %04x class %06x\n",
98 readw(pci_data + 4), readw(pci_data + 6),
99 readl(pci_data + 0x0d) & 0xffffff);
101 (readw(pci_data + 0x15) & 0x80) ?
102 "Last image" : "More images follow");
103 switch (readb(pci_data + 0x14)) {
105 printf("X86 code\n");
108 printf("Openfirmware code\n");
111 printf("PARISC code\n");
114 printf("Image size %d\n",
115 readw(pci_data + 0x10) * 512);
118 * FixMe: I think we should compare the class
119 * code bytes as well but I have no reference
120 * on the exact order of these bytes in the PCI
123 if (readw(pci_data + 4) == vendor &&
124 readw(pci_data + 6) == device &&
125 readb(pci_data + 0x14) == 0) {
126 #ifdef PCI_ROM_SCAN_VERBOSE
127 printf("Suitable ROM image found\n");
129 memmove(dest, (void *)rom_addr,
130 readw(pci_data + 0x10) * 512);
136 if (readw(pci_data + 0x15) & 0x80)
143 #ifdef PCI_ROM_SCAN_VERBOSE
145 printf("No suitable image found\n");
147 /* disable PAR register and PCI device ROM address devocer */
148 pci_remove_rom_window(hose, rom_addr);
150 pci_write_config_dword(dev, PCI_ROM_ADDRESS, 0);
155 #ifdef PCI_BIOS_DEBUG
157 void print_bios_bios_stat(void)
159 printf("16 bit functions:\n");
160 printf("pci_bios_present: %d\n",
161 RELOC_16_LONG(0xf000, num_pci_bios_present));
162 printf("pci_bios_find_device: %d\n",
163 RELOC_16_LONG(0xf000, num_pci_bios_find_device));
164 printf("pci_bios_find_class: %d\n",
165 RELOC_16_LONG(0xf000, num_pci_bios_find_class));
166 printf("pci_bios_generate_special_cycle: %d\n",
167 RELOC_16_LONG(0xf000,
168 num_pci_bios_generate_special_cycle));
169 printf("pci_bios_read_cfg_byte: %d\n",
170 RELOC_16_LONG(0xf000, num_pci_bios_read_cfg_byte));
171 printf("pci_bios_read_cfg_word: %d\n",
172 RELOC_16_LONG(0xf000, num_pci_bios_read_cfg_word));
173 printf("pci_bios_read_cfg_dword: %d\n",
174 RELOC_16_LONG(0xf000, num_pci_bios_read_cfg_dword));
175 printf("pci_bios_write_cfg_byte: %d\n",
176 RELOC_16_LONG(0xf000, num_pci_bios_write_cfg_byte));
177 printf("pci_bios_write_cfg_word: %d\n",
178 RELOC_16_LONG(0xf000, num_pci_bios_write_cfg_word));
179 printf("pci_bios_write_cfg_dword: %d\n",
180 RELOC_16_LONG(0xf000, num_pci_bios_write_cfg_dword));
181 printf("pci_bios_get_irq_routing: %d\n",
182 RELOC_16_LONG(0xf000, num_pci_bios_get_irq_routing));
183 printf("pci_bios_set_irq: %d\n",
184 RELOC_16_LONG(0xf000, num_pci_bios_set_irq));
185 printf("pci_bios_unknown_function: %d\n",
186 RELOC_16_LONG(0xf000, num_pci_bios_unknown_function));