3 * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
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,
30 #undef PCI_ROM_SCAN_VERBOSE
32 int pci_shadow_rom(pci_dev_t dev
, unsigned char *dest
)
34 struct pci_controller
*hose
;
46 hose
= pci_bus_to_hose(PCI_BUS(dev
));
48 printf("pci_shadow_rom() asked to shadow device %x to %x\n",
51 pci_read_config_word(dev
, PCI_VENDOR_ID
, &vendor
);
52 pci_read_config_word(dev
, PCI_DEVICE_ID
, &device
);
53 pci_read_config_dword(dev
, PCI_CLASS_REVISION
, &class_code
);
55 class_code
&= 0xffffff00;
59 printf("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
, 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;
75 printf("ROM is %d bytes\n", size
);
77 rom_addr
= pci_get_rom_window(hose
, size
);
79 printf("ROM mapped at %x \n", rom_addr
);
81 pci_write_config_dword(dev
, PCI_ROM_ADDRESS
,
82 pci_phys_to_mem(dev
, rom_addr
)
83 |PCI_ROM_ADDRESS_ENABLE
);
86 for (i
=rom_addr
;i
<rom_addr
+size
; i
+=512) {
89 if (readw(i
) == 0xaa55) {
91 #ifdef PCI_ROM_SCAN_VERBOSE
92 printf("ROM signature found\n");
94 pci_data
= readw(0x18+i
);
97 if (0==memcmp((void*)pci_data
, "PCIR", 4)) {
98 #ifdef PCI_ROM_SCAN_VERBOSE
99 printf("Fount PCI rom image at offset %d\n", i
-rom_addr
);
100 printf("Vendor %04x device %04x class %06x\n",
101 readw(pci_data
+4), readw(pci_data
+6),
102 readl(pci_data
+0x0d)&0xffffff);
104 (readw(pci_data
+0x15) &0x80)?
105 "Last image":"More images follow");
106 switch (readb(pci_data
+0x14)) {
108 printf("X86 code\n");
111 printf("Openfirmware code\n");
114 printf("PARISC code\n");
117 printf("Image size %d\n", readw(pci_data
+0x10) * 512);
119 /* FixMe: I think we should compare the class code
120 * bytes as well but I have no reference on the
121 * exact order of these bytes in the PCI ROM header */
122 if (readw(pci_data
+4) == vendor
&&
123 readw(pci_data
+6) == device
&&
124 /* (readl(pci_data+0x0d)&0xffffff) == class_code && */
125 readb(pci_data
+0x14) == 0 /* x86 code image */ ) {
126 #ifdef PCI_ROM_SCAN_VERBOSE
127 printf("Suitable ROM image found, copying\n");
129 memmove(dest
, (void*)rom_addr
, readw(pci_data
+0x10) * 512);
134 if (readw(pci_data
+0x15) &0x80) {
142 #ifdef PCI_ROM_SCAN_VERBOSE
144 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);