1 #include <linux/kernel.h>
2 #include <linux/types.h>
3 #include <linux/init.h>
4 #include <linux/bootmem.h>
5 #include <linux/ioport.h>
6 #include <linux/string.h>
7 #include <linux/kexec.h>
8 #include <linux/module.h>
10 #include <linux/efi.h>
12 #include <asm/pgtable.h>
18 EXPORT_SYMBOL(efi_enabled);
22 struct resource data_resource = {
23 .name = "Kernel data",
26 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
29 struct resource code_resource = {
30 .name = "Kernel code",
33 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
36 static struct resource system_rom_resource = {
40 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
43 static struct resource extension_rom_resource = {
44 .name = "Extension ROM",
47 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
50 static struct resource adapter_rom_resources[] = { {
51 .name = "Adapter ROM",
54 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
56 .name = "Adapter ROM",
59 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
61 .name = "Adapter ROM",
64 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
66 .name = "Adapter ROM",
69 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
71 .name = "Adapter ROM",
74 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
76 .name = "Adapter ROM",
79 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
82 static struct resource video_rom_resource = {
86 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
89 static struct resource video_ram_resource = {
90 .name = "Video RAM area",
93 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
96 static struct resource standard_io_resources[] = { {
100 .flags = IORESOURCE_BUSY | IORESOURCE_IO
105 .flags = IORESOURCE_BUSY | IORESOURCE_IO
110 .flags = IORESOURCE_BUSY | IORESOURCE_IO
115 .flags = IORESOURCE_BUSY | IORESOURCE_IO
120 .flags = IORESOURCE_BUSY | IORESOURCE_IO
122 .name = "dma page reg",
125 .flags = IORESOURCE_BUSY | IORESOURCE_IO
130 .flags = IORESOURCE_BUSY | IORESOURCE_IO
135 .flags = IORESOURCE_BUSY | IORESOURCE_IO
140 .flags = IORESOURCE_BUSY | IORESOURCE_IO
143 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
145 static int __init romchecksum(unsigned char *rom, unsigned long length)
147 unsigned char *p, sum = 0;
149 for (p = rom; p < rom + length; p++)
154 static void __init probe_roms(void)
156 unsigned long start, length, upper;
161 upper = adapter_rom_resources[0].start;
162 for (start = video_rom_resource.start; start < upper; start += 2048) {
163 rom = isa_bus_to_virt(start);
164 if (!romsignature(rom))
167 video_rom_resource.start = start;
169 /* 0 < length <= 0x7f * 512, historically */
170 length = rom[2] * 512;
172 /* if checksum okay, trust length byte */
173 if (length && romchecksum(rom, length))
174 video_rom_resource.end = start + length - 1;
176 request_resource(&iomem_resource, &video_rom_resource);
180 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
185 request_resource(&iomem_resource, &system_rom_resource);
186 upper = system_rom_resource.start;
188 /* check for extension rom (ignore length byte!) */
189 rom = isa_bus_to_virt(extension_rom_resource.start);
190 if (romsignature(rom)) {
191 length = extension_rom_resource.end - extension_rom_resource.start + 1;
192 if (romchecksum(rom, length)) {
193 request_resource(&iomem_resource, &extension_rom_resource);
194 upper = extension_rom_resource.start;
198 /* check for adapter roms on 2k boundaries */
199 for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
200 rom = isa_bus_to_virt(start);
201 if (!romsignature(rom))
204 /* 0 < length <= 0x7f * 512, historically */
205 length = rom[2] * 512;
207 /* but accept any length that fits if checksum okay */
208 if (!length || start + length > upper || !romchecksum(rom, length))
211 adapter_rom_resources[i].start = start;
212 adapter_rom_resources[i].end = start + length - 1;
213 request_resource(&iomem_resource, &adapter_rom_resources[i]);
215 start = adapter_rom_resources[i++].end & ~2047UL;
220 * Request address space for all standard RAM and ROM resources
221 * and also for regions reported as reserved by the e820.
224 legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
229 for (i = 0; i < e820.nr_map; i++) {
230 struct resource *res;
231 #ifndef CONFIG_RESOURCES_64BIT
232 if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
235 res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
236 switch (e820.map[i].type) {
237 case E820_RAM: res->name = "System RAM"; break;
238 case E820_ACPI: res->name = "ACPI Tables"; break;
239 case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
240 default: res->name = "reserved";
242 res->start = e820.map[i].addr;
243 res->end = res->start + e820.map[i].size - 1;
244 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
245 if (request_resource(&iomem_resource, res)) {
249 if (e820.map[i].type == E820_RAM) {
251 * We don't know which RAM region contains kernel data,
252 * so we try it repeatedly and let the resource manager
255 request_resource(res, code_resource);
256 request_resource(res, data_resource);
258 request_resource(res, &crashk_res);
265 * Request address space for all standard resources
267 * This is called just before pcibios_init(), which is also a
268 * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
270 static int __init request_standard_resources(void)
274 printk("Setting up standard PCI resources\n");
276 efi_initialize_iomem_resources(&code_resource, &data_resource);
278 legacy_init_iomem_resources(&code_resource, &data_resource);
280 /* EFI systems may still have VGA */
281 request_resource(&iomem_resource, &video_ram_resource);
283 /* request I/O space for devices used on all i[345]86 PCs */
284 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
285 request_resource(&ioport_resource, &standard_io_resources[i]);
289 subsys_initcall(request_standard_resources);