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 <asm/pci-direct.h>
17 #include <asm/mmzone.h>
18 #include <asm/setup.h>
19 #include <asm/sections.h>
21 #include <setup_arch.h>
23 static struct resource system_rom_resource
= {
27 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
30 static struct resource extension_rom_resource
= {
31 .name
= "Extension ROM",
34 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
37 static struct resource adapter_rom_resources
[] = { {
38 .name
= "Adapter ROM",
41 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
43 .name
= "Adapter ROM",
46 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
48 .name
= "Adapter ROM",
51 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
53 .name
= "Adapter ROM",
56 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
58 .name
= "Adapter ROM",
61 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
63 .name
= "Adapter ROM",
66 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
69 static struct resource video_rom_resource
= {
73 .flags
= IORESOURCE_BUSY
| IORESOURCE_READONLY
| IORESOURCE_MEM
76 #define ROMSIGNATURE 0xaa55
78 static int __init
romsignature(const unsigned char *rom
)
80 const unsigned short * const ptr
= (const unsigned short *)rom
;
83 return probe_kernel_address(ptr
, sig
) == 0 && sig
== ROMSIGNATURE
;
86 static int __init
romchecksum(const unsigned char *rom
, unsigned long length
)
90 for (sum
= 0; length
&& probe_kernel_address(rom
++, c
) == 0; length
--)
92 return !length
&& !sum
;
95 void __init
probe_roms(void)
97 const unsigned char *rom
;
98 unsigned long start
, length
, upper
;
103 upper
= adapter_rom_resources
[0].start
;
104 for (start
= video_rom_resource
.start
; start
< upper
; start
+= 2048) {
105 rom
= isa_bus_to_virt(start
);
106 if (!romsignature(rom
))
109 video_rom_resource
.start
= start
;
111 if (probe_kernel_address(rom
+ 2, c
) != 0)
114 /* 0 < length <= 0x7f * 512, historically */
117 /* if checksum okay, trust length byte */
118 if (length
&& romchecksum(rom
, length
))
119 video_rom_resource
.end
= start
+ length
- 1;
121 request_resource(&iomem_resource
, &video_rom_resource
);
125 start
= (video_rom_resource
.end
+ 1 + 2047) & ~2047UL;
130 request_resource(&iomem_resource
, &system_rom_resource
);
131 upper
= system_rom_resource
.start
;
133 /* check for extension rom (ignore length byte!) */
134 rom
= isa_bus_to_virt(extension_rom_resource
.start
);
135 if (romsignature(rom
)) {
136 length
= extension_rom_resource
.end
- extension_rom_resource
.start
+ 1;
137 if (romchecksum(rom
, length
)) {
138 request_resource(&iomem_resource
, &extension_rom_resource
);
139 upper
= extension_rom_resource
.start
;
143 /* check for adapter roms on 2k boundaries */
144 for (i
= 0; i
< ARRAY_SIZE(adapter_rom_resources
) && start
< upper
; start
+= 2048) {
145 rom
= isa_bus_to_virt(start
);
146 if (!romsignature(rom
))
149 if (probe_kernel_address(rom
+ 2, c
) != 0)
152 /* 0 < length <= 0x7f * 512, historically */
155 /* but accept any length that fits if checksum okay */
156 if (!length
|| start
+ length
> upper
|| !romchecksum(rom
, length
))
159 adapter_rom_resources
[i
].start
= start
;
160 adapter_rom_resources
[i
].end
= start
+ length
- 1;
161 request_resource(&iomem_resource
, &adapter_rom_resources
[i
]);
163 start
= adapter_rom_resources
[i
++].end
& ~2047UL;