]> git.karo-electronics.de Git - linux-beck.git/blob - arch/x86/kernel/e820_64.c
47952b1690b65c90235ce3c28986f34507c93f3e
[linux-beck.git] / arch / x86 / kernel / e820_64.c
1 /*
2  * Handle the memory map.
3  * The functions here do the job until bootmem takes over.
4  *
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>
9  *
10  */
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>
19 #include <linux/mm.h>
20 #include <linux/pfn.h>
21 #include <linux/pci.h>
22
23 #include <asm/pgtable.h>
24 #include <asm/page.h>
25 #include <asm/e820.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>
31
32 /*
33  * PFN of last memory page.
34  */
35 unsigned long end_pfn;
36
37 /*
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.
41  */
42 unsigned long max_pfn_mapped;
43
44 /*
45  * Mark e820 reserved areas as busy for the resource manager.
46  */
47 void __init e820_reserve_resources(void)
48 {
49         int i;
50         struct resource *res;
51
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";
59                 }
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);
64                 res++;
65         }
66 }
67
68 static void early_panic(char *msg)
69 {
70         early_printk(msg);
71         panic(msg);
72 }
73
74 /* We're not void only for x86 32-bit compat */
75 char *__init machine_specific_memory_setup(void)
76 {
77         char *who = "BIOS-e820";
78         int new_nr;
79         /*
80          * Try to copy the BIOS-supplied E820-map.
81          *
82          * Otherwise fake a memory map; one section from 0k->640k,
83          * the next section from 1mb->appropriate_mem_k
84          */
85         new_nr = boot_params.e820_entries;
86         sanitize_e820_map(boot_params.e820_map,
87                         ARRAY_SIZE(boot_params.e820_map),
88                         &new_nr);
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");
93         e820_print_map(who);
94
95         /* In case someone cares... */
96         return who;
97 }
98
99 int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
100 {
101         int i;
102
103         if (slot < 0 || slot >= e820.nr_map)
104                 return -1;
105         for (i = slot; i < e820.nr_map; i++) {
106                 if (e820.map[i].type != E820_RAM)
107                         continue;
108                 break;
109         }
110         if (i == e820.nr_map || e820.map[i].addr > (max_pfn << PAGE_SHIFT))
111                 return -1;
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;
115         return i + 1;
116 }