1 #include <linux/sched.h>
3 #include <linux/uaccess.h>
4 #include <linux/mmzone.h>
5 #include <linux/ioport.h>
6 #include <linux/seq_file.h>
7 #include <linux/console.h>
8 #include <linux/init.h>
10 #include <linux/dmi.h>
11 #include <linux/pfn.h>
12 #include <linux/pci.h>
13 #include <linux/export.h>
15 #include <asm/probe_roms.h>
16 #include <asm/pci-direct.h>
18 #include <asm/mmzone.h>
19 #include <asm/setup.h>
20 #include <asm/sections.h>
22 #include <asm/setup_arch.h>
24 static struct resource system_rom_resource
= {
28 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
31 static struct resource extension_rom_resource
= {
32 .name
= "Extension ROM",
35 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
38 static struct resource adapter_rom_resources
[] = { {
39 .name
= "Adapter ROM",
42 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
44 .name
= "Adapter ROM",
47 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
49 .name
= "Adapter ROM",
52 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
54 .name
= "Adapter ROM",
57 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
59 .name
= "Adapter ROM",
62 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
64 .name
= "Adapter ROM",
67 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
70 static struct resource video_rom_resource
= {
74 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
77 /* does this oprom support the given pci device, or any of the devices
78 * that the driver supports?
80 static bool match_id(struct pci_dev
*pdev
, unsigned short vendor
, unsigned short device
)
82 struct pci_driver
*drv
= pdev
->driver
;
83 const struct pci_device_id
*id
;
85 if (pdev
->vendor
== vendor
&& pdev
->device
== device
)
88 for (id
= drv
? drv
->id_table
: NULL
; id
&& id
->vendor
; id
++)
89 if (id
->vendor
== vendor
&& id
->device
== device
)
92 return id
&& id
->vendor
;
95 static bool probe_list(struct pci_dev
*pdev
, unsigned short vendor
,
96 const unsigned char *rom_list
)
98 unsigned short device
;
101 if (probe_kernel_address(rom_list
, device
) != 0)
104 if (device
&& match_id(pdev
, vendor
, device
))
113 static struct resource
*find_oprom(struct pci_dev
*pdev
)
115 struct resource
*oprom
= NULL
;
118 for (i
= 0; i
< ARRAY_SIZE(adapter_rom_resources
); i
++) {
119 struct resource
*res
= &adapter_rom_resources
[i
];
120 unsigned short offset
, vendor
, device
, list
, rev
;
121 const unsigned char *rom
;
126 rom
= isa_bus_to_virt(res
->start
);
127 if (probe_kernel_address(rom
+ 0x18, offset
) != 0)
130 if (probe_kernel_address(rom
+ offset
+ 0x4, vendor
) != 0)
133 if (probe_kernel_address(rom
+ offset
+ 0x6, device
) != 0)
136 if (match_id(pdev
, vendor
, device
)) {
141 if (probe_kernel_address(rom
+ offset
+ 0x8, list
) == 0 &&
142 probe_kernel_address(rom
+ offset
+ 0xc, rev
) == 0 &&
144 probe_list(pdev
, vendor
, rom
+ offset
+ list
)) {
153 void __iomem
*pci_map_biosrom(struct pci_dev
*pdev
)
155 struct resource
*oprom
= find_oprom(pdev
);
160 return ioremap(oprom
->start
, resource_size(oprom
));
162 EXPORT_SYMBOL(pci_map_biosrom
);
164 void pci_unmap_biosrom(void __iomem
*image
)
168 EXPORT_SYMBOL(pci_unmap_biosrom
);
170 size_t pci_biosrom_size(struct pci_dev
*pdev
)
172 struct resource
*oprom
= find_oprom(pdev
);
174 return oprom
? resource_size(oprom
) : 0;
176 EXPORT_SYMBOL(pci_biosrom_size
);
178 #define ROMSIGNATURE 0xaa55
180 static int __init
romsignature(const unsigned char *rom
)
182 const unsigned short * const ptr
= (const unsigned short *)rom
;
185 return probe_kernel_address(ptr
, sig
) == 0 && sig
== ROMSIGNATURE
;
188 static int __init
romchecksum(const unsigned char *rom
, unsigned long length
)
190 unsigned char sum
, c
;
192 for (sum
= 0; length
&& probe_kernel_address(rom
++, c
) == 0; length
--)
194 return !length
&& !sum
;
197 void __init
probe_roms(void)
199 const unsigned char *rom
;
200 unsigned long start
, length
, upper
;
205 upper
= adapter_rom_resources
[0].start
;
206 for (start
= video_rom_resource
.start
; start
< upper
; start
+= 2048) {
207 rom
= isa_bus_to_virt(start
);
208 if (!romsignature(rom
))
211 video_rom_resource
.start
= start
;
213 if (probe_kernel_address(rom
+ 2, c
) != 0)
216 /* 0 < length <= 0x7f * 512, historically */
219 /* if checksum okay, trust length byte */
220 if (length
&& romchecksum(rom
, length
))
221 video_rom_resource
.end
= start
+ length
- 1;
223 request_resource(&iomem_resource
, &video_rom_resource
);
227 start
= (video_rom_resource
.end
+ 1 + 2047) & ~2047UL;
232 request_resource(&iomem_resource
, &system_rom_resource
);
233 upper
= system_rom_resource
.start
;
235 /* check for extension rom (ignore length byte!) */
236 rom
= isa_bus_to_virt(extension_rom_resource
.start
);
237 if (romsignature(rom
)) {
238 length
= resource_size(&extension_rom_resource
);
239 if (romchecksum(rom
, length
)) {
240 request_resource(&iomem_resource
, &extension_rom_resource
);
241 upper
= extension_rom_resource
.start
;
245 /* check for adapter roms on 2k boundaries */
246 for (i
= 0; i
< ARRAY_SIZE(adapter_rom_resources
) && start
< upper
; start
+= 2048) {
247 rom
= isa_bus_to_virt(start
);
248 if (!romsignature(rom
))
251 if (probe_kernel_address(rom
+ 2, c
) != 0)
254 /* 0 < length <= 0x7f * 512, historically */
257 /* but accept any length that fits if checksum okay */
258 if (!length
|| start
+ length
> upper
|| !romchecksum(rom
, length
))
261 adapter_rom_resources
[i
].start
= start
;
262 adapter_rom_resources
[i
].end
= start
+ length
- 1;
263 request_resource(&iomem_resource
, &adapter_rom_resources
[i
]);
265 start
= adapter_rom_resources
[i
++].end
& ~2047UL;