2 * Handle the memory map.
3 * The functions here do the job until bootmem takes over.
5 * Getting sanitize_e820_map() in sync with i386 version by applying change:
6 * - Provisions for empty E820 memory regions (reported by certain BIOSes).
7 * Alex Achenbach <xela@slit.de>, December 2002.
8 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/bootmem.h>
15 #include <linux/ioport.h>
16 #include <linux/string.h>
17 #include <linux/kexec.h>
18 #include <linux/module.h>
20 #include <linux/pfn.h>
21 #include <linux/pci.h>
23 #include <asm/pgtable.h>
26 #include <asm/proto.h>
27 #include <asm/setup.h>
28 #include <asm/sections.h>
29 #include <asm/kdebug.h>
30 #include <asm/trampoline.h>
33 * PFN of last memory page.
35 unsigned long end_pfn;
38 * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
39 * The direct mapping extends to max_pfn_mapped, so that we can directly access
40 * apertures, ACPI and other tables without having to play with fixmaps.
42 unsigned long max_pfn_mapped;
45 * Mark e820 reserved areas as busy for the resource manager.
47 void __init e820_reserve_resources(void)
52 res = alloc_bootmem_low(sizeof(struct resource) * e820.nr_map);
53 for (i = 0; i < e820.nr_map; i++) {
54 switch (e820.map[i].type) {
55 case E820_RAM: res->name = "System RAM"; break;
56 case E820_ACPI: res->name = "ACPI Tables"; break;
57 case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
58 default: res->name = "reserved";
60 res->start = e820.map[i].addr;
61 res->end = res->start + e820.map[i].size - 1;
62 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
63 insert_resource(&iomem_resource, res);
68 static void early_panic(char *msg)
74 /* We're not void only for x86 32-bit compat */
75 char *__init machine_specific_memory_setup(void)
77 char *who = "BIOS-e820";
80 * Try to copy the BIOS-supplied E820-map.
82 * Otherwise fake a memory map; one section from 0k->640k,
83 * the next section from 1mb->appropriate_mem_k
85 new_nr = boot_params.e820_entries;
86 sanitize_e820_map(boot_params.e820_map,
87 ARRAY_SIZE(boot_params.e820_map),
89 boot_params.e820_entries = new_nr;
90 if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries) < 0)
91 early_panic("Cannot find a valid memory map");
92 printk(KERN_INFO "BIOS-provided physical RAM map:\n");
95 /* In case someone cares... */
99 int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
103 if (slot < 0 || slot >= e820.nr_map)
105 for (i = slot; i < e820.nr_map; i++) {
106 if (e820.map[i].type != E820_RAM)
110 if (i == e820.nr_map || e820.map[i].addr > (max_pfn << PAGE_SHIFT))
112 *addr = e820.map[i].addr;
113 *size = min_t(u64, e820.map[i].size + e820.map[i].addr,
114 max_pfn << PAGE_SHIFT) - *addr;