Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/i386/kernel/setup.c |
| 3 | * |
| 4 | * Copyright (C) 1995 Linus Torvalds |
| 5 | * |
| 6 | * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 |
| 7 | * |
| 8 | * Memory region support |
| 9 | * David Parsons <orc@pell.chi.il.us>, July-August 1999 |
| 10 | * |
| 11 | * Added E820 sanitization routine (removes overlapping memory regions); |
| 12 | * Brian Moyle <bmoyle@mvista.com>, February 2001 |
| 13 | * |
| 14 | * Moved CPU detection code to cpu/${cpu}.c |
| 15 | * Patrick Mochel <mochel@osdl.org>, March 2002 |
| 16 | * |
| 17 | * Provisions for empty E820 memory regions (reported by certain BIOSes). |
| 18 | * Alex Achenbach <xela@slit.de>, December 2002. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file handles the architecture-dependent parts of initialization |
| 24 | */ |
| 25 | |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/mm.h> |
Andy Whitcroft | 05b79bd | 2005-06-23 00:07:57 -0700 | [diff] [blame] | 28 | #include <linux/mmzone.h> |
Jon Smirl | 894673e | 2006-07-10 04:44:13 -0700 | [diff] [blame] | 29 | #include <linux/screen_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/ioport.h> |
| 31 | #include <linux/acpi.h> |
| 32 | #include <linux/apm_bios.h> |
| 33 | #include <linux/initrd.h> |
| 34 | #include <linux/bootmem.h> |
| 35 | #include <linux/seq_file.h> |
Michael Neuling | e5c6c8e | 2006-03-14 00:11:50 -0500 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/console.h> |
| 38 | #include <linux/mca.h> |
| 39 | #include <linux/root_dev.h> |
| 40 | #include <linux/highmem.h> |
| 41 | #include <linux/module.h> |
| 42 | #include <linux/efi.h> |
| 43 | #include <linux/init.h> |
| 44 | #include <linux/edd.h> |
| 45 | #include <linux/nodemask.h> |
Eric W. Biederman | 1bc3b91 | 2005-06-25 14:58:01 -0700 | [diff] [blame] | 46 | #include <linux/kexec.h> |
Vivek Goyal | 2030eae | 2005-06-25 14:58:20 -0700 | [diff] [blame] | 47 | #include <linux/crash_dump.h> |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 48 | #include <linux/dmi.h> |
Dave Hansen | 22a9835 | 2006-03-27 01:16:04 -0800 | [diff] [blame] | 49 | #include <linux/pfn.h> |
Eric W. Biederman | 1bc3b91 | 2005-06-25 14:58:01 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <video/edid.h> |
Eric W. Biederman | 1bc3b91 | 2005-06-25 14:58:01 -0700 | [diff] [blame] | 52 | |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 53 | #include <asm/apic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/e820.h> |
| 55 | #include <asm/mpspec.h> |
keith mannthey | 9102330 | 2006-09-25 23:31:03 -0700 | [diff] [blame] | 56 | #include <asm/mmzone.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <asm/setup.h> |
| 58 | #include <asm/arch_hooks.h> |
| 59 | #include <asm/sections.h> |
| 60 | #include <asm/io_apic.h> |
| 61 | #include <asm/ist.h> |
| 62 | #include <asm/io.h> |
Jeremy Fitzhardinge | e75eac3 | 2006-06-25 05:46:50 -0700 | [diff] [blame] | 63 | #include <setup_arch.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <bios_ebda.h> |
| 65 | |
Vivek Goyal | 92aa63a | 2005-06-25 14:58:18 -0700 | [diff] [blame] | 66 | /* Forward Declaration. */ |
| 67 | void __init find_max_pfn(void); |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /* This value is set up by the early boot code to point to the value |
| 70 | immediately after the boot time page tables. It contains a *physical* |
| 71 | address, and must not be in the .bss segment! */ |
| 72 | unsigned long init_pg_tables_end __initdata = ~0UL; |
| 73 | |
Li Shaohua | 0bb3184 | 2005-06-25 14:54:55 -0700 | [diff] [blame] | 74 | int disable_pse __devinitdata = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Machine setup.. |
| 78 | */ |
bibo,mao | 269c2d8 | 2006-12-07 02:14:06 +0100 | [diff] [blame^] | 79 | extern struct e820map e820; |
| 80 | extern struct resource code_resource; |
| 81 | extern struct resource data_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* cpu data as detected by the assembly code in head.S */ |
| 84 | struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 }; |
| 85 | /* common cpu data for all cpus */ |
Christoph Lameter | c3d8c14 | 2005-09-06 15:16:33 -0700 | [diff] [blame] | 86 | struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 }; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 87 | EXPORT_SYMBOL(boot_cpu_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | unsigned long mmu_cr4_features; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* for MCA, but anyone else can use it if they want */ |
| 92 | unsigned int machine_id; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 93 | #ifdef CONFIG_MCA |
| 94 | EXPORT_SYMBOL(machine_id); |
| 95 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | unsigned int machine_submodel_id; |
| 97 | unsigned int BIOS_revision; |
| 98 | unsigned int mca_pentium_flag; |
| 99 | |
| 100 | /* For PCI or other memory-mapped resources */ |
| 101 | unsigned long pci_mem_start = 0x10000000; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 102 | #ifdef CONFIG_PCI |
| 103 | EXPORT_SYMBOL(pci_mem_start); |
| 104 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* Boot loader ID as an integer, for the benefit of proc_dointvec */ |
| 107 | int bootloader_type; |
| 108 | |
| 109 | /* user-defined highmem size */ |
| 110 | static unsigned int highmem_pages = -1; |
| 111 | |
| 112 | /* |
| 113 | * Setup options |
| 114 | */ |
| 115 | struct drive_info_struct { char dummy[32]; } drive_info; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 116 | #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || \ |
| 117 | defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE) |
| 118 | EXPORT_SYMBOL(drive_info); |
| 119 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | struct screen_info screen_info; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 121 | EXPORT_SYMBOL(screen_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | struct apm_info apm_info; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 123 | EXPORT_SYMBOL(apm_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | struct sys_desc_table_struct { |
| 125 | unsigned short length; |
| 126 | unsigned char table[0]; |
| 127 | }; |
| 128 | struct edid_info edid_info; |
Antonino A. Daplas | 5e518d7 | 2005-09-09 13:04:34 -0700 | [diff] [blame] | 129 | EXPORT_SYMBOL_GPL(edid_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | struct ist_info ist_info; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 131 | #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ |
| 132 | defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) |
| 133 | EXPORT_SYMBOL(ist_info); |
| 134 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | extern void early_cpu_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | extern int root_mountflags; |
| 138 | |
| 139 | unsigned long saved_videomode; |
| 140 | |
| 141 | #define RAMDISK_IMAGE_START_MASK 0x07FF |
| 142 | #define RAMDISK_PROMPT_FLAG 0x8000 |
| 143 | #define RAMDISK_LOAD_FLAG 0x4000 |
| 144 | |
| 145 | static char command_line[COMMAND_LINE_SIZE]; |
| 146 | |
| 147 | unsigned char __initdata boot_params[PARAM_SIZE]; |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static void __init limit_regions(unsigned long long size) |
| 150 | { |
| 151 | unsigned long long current_addr = 0; |
| 152 | int i; |
| 153 | |
| 154 | if (efi_enabled) { |
Matt Tolentino | 7ae65fd | 2005-09-03 15:56:27 -0700 | [diff] [blame] | 155 | efi_memory_desc_t *md; |
| 156 | void *p; |
| 157 | |
| 158 | for (p = memmap.map, i = 0; p < memmap.map_end; |
| 159 | p += memmap.desc_size, i++) { |
| 160 | md = p; |
| 161 | current_addr = md->phys_addr + (md->num_pages << 12); |
| 162 | if (md->type == EFI_CONVENTIONAL_MEMORY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | if (current_addr >= size) { |
Matt Tolentino | 7ae65fd | 2005-09-03 15:56:27 -0700 | [diff] [blame] | 164 | md->num_pages -= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | (((current_addr-size) + PAGE_SIZE-1) >> PAGE_SHIFT); |
| 166 | memmap.nr_map = i + 1; |
| 167 | return; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | for (i = 0; i < e820.nr_map; i++) { |
Dave Hansen | f014a55 | 2005-10-30 14:59:37 -0800 | [diff] [blame] | 173 | current_addr = e820.map[i].addr + e820.map[i].size; |
| 174 | if (current_addr < size) |
| 175 | continue; |
| 176 | |
| 177 | if (e820.map[i].type != E820_RAM) |
| 178 | continue; |
| 179 | |
| 180 | if (e820.map[i].addr >= size) { |
| 181 | /* |
| 182 | * This region starts past the end of the |
| 183 | * requested size, skip it completely. |
| 184 | */ |
| 185 | e820.nr_map = i; |
| 186 | } else { |
| 187 | e820.nr_map = i + 1; |
| 188 | e820.map[i].size -= current_addr - size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
Dave Hansen | f014a55 | 2005-10-30 14:59:37 -0800 | [diff] [blame] | 190 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Jeremy Fitzhardinge | e75eac3 | 2006-06-25 05:46:50 -0700 | [diff] [blame] | 194 | void __init add_memory_region(unsigned long long start, |
| 195 | unsigned long long size, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | int x; |
| 198 | |
| 199 | if (!efi_enabled) { |
| 200 | x = e820.nr_map; |
| 201 | |
| 202 | if (x == E820MAX) { |
| 203 | printk(KERN_ERR "Ooops! Too many entries in the memory map!\n"); |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | e820.map[x].addr = start; |
| 208 | e820.map[x].size = size; |
| 209 | e820.map[x].type = type; |
| 210 | e820.nr_map++; |
| 211 | } |
| 212 | } /* add_memory_region */ |
| 213 | |
| 214 | #define E820_DEBUG 1 |
| 215 | |
| 216 | static void __init print_memory_map(char *who) |
| 217 | { |
| 218 | int i; |
| 219 | |
| 220 | for (i = 0; i < e820.nr_map; i++) { |
| 221 | printk(" %s: %016Lx - %016Lx ", who, |
| 222 | e820.map[i].addr, |
| 223 | e820.map[i].addr + e820.map[i].size); |
| 224 | switch (e820.map[i].type) { |
| 225 | case E820_RAM: printk("(usable)\n"); |
| 226 | break; |
| 227 | case E820_RESERVED: |
| 228 | printk("(reserved)\n"); |
| 229 | break; |
| 230 | case E820_ACPI: |
| 231 | printk("(ACPI data)\n"); |
| 232 | break; |
| 233 | case E820_NVS: |
| 234 | printk("(ACPI NVS)\n"); |
| 235 | break; |
| 236 | default: printk("type %lu\n", e820.map[i].type); |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * Sanitize the BIOS e820 map. |
| 244 | * |
| 245 | * Some e820 responses include overlapping entries. The following |
| 246 | * replaces the original e820 map with a new one, removing overlaps. |
| 247 | * |
| 248 | */ |
| 249 | struct change_member { |
| 250 | struct e820entry *pbios; /* pointer to original bios entry */ |
| 251 | unsigned long long addr; /* address for this change point */ |
| 252 | }; |
| 253 | static struct change_member change_point_list[2*E820MAX] __initdata; |
| 254 | static struct change_member *change_point[2*E820MAX] __initdata; |
| 255 | static struct e820entry *overlap_list[E820MAX] __initdata; |
| 256 | static struct e820entry new_bios[E820MAX] __initdata; |
| 257 | |
Jeremy Fitzhardinge | e75eac3 | 2006-06-25 05:46:50 -0700 | [diff] [blame] | 258 | int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | struct change_member *change_tmp; |
| 261 | unsigned long current_type, last_type; |
| 262 | unsigned long long last_addr; |
| 263 | int chgidx, still_changing; |
| 264 | int overlap_entries; |
| 265 | int new_bios_entry; |
| 266 | int old_nr, new_nr, chg_nr; |
| 267 | int i; |
| 268 | |
| 269 | /* |
| 270 | Visually we're performing the following (1,2,3,4 = memory types)... |
| 271 | |
| 272 | Sample memory map (w/overlaps): |
| 273 | ____22__________________ |
| 274 | ______________________4_ |
| 275 | ____1111________________ |
| 276 | _44_____________________ |
| 277 | 11111111________________ |
| 278 | ____________________33__ |
| 279 | ___________44___________ |
| 280 | __________33333_________ |
| 281 | ______________22________ |
| 282 | ___________________2222_ |
| 283 | _________111111111______ |
| 284 | _____________________11_ |
| 285 | _________________4______ |
| 286 | |
| 287 | Sanitized equivalent (no overlap): |
| 288 | 1_______________________ |
| 289 | _44_____________________ |
| 290 | ___1____________________ |
| 291 | ____22__________________ |
| 292 | ______11________________ |
| 293 | _________1______________ |
| 294 | __________3_____________ |
| 295 | ___________44___________ |
| 296 | _____________33_________ |
| 297 | _______________2________ |
| 298 | ________________1_______ |
| 299 | _________________4______ |
| 300 | ___________________2____ |
| 301 | ____________________33__ |
| 302 | ______________________4_ |
| 303 | */ |
| 304 | |
| 305 | /* if there's only one memory region, don't bother */ |
| 306 | if (*pnr_map < 2) |
| 307 | return -1; |
| 308 | |
| 309 | old_nr = *pnr_map; |
| 310 | |
| 311 | /* bail out if we find any unreasonable addresses in bios map */ |
| 312 | for (i=0; i<old_nr; i++) |
| 313 | if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr) |
| 314 | return -1; |
| 315 | |
| 316 | /* create pointers for initial change-point information (for sorting) */ |
| 317 | for (i=0; i < 2*old_nr; i++) |
| 318 | change_point[i] = &change_point_list[i]; |
| 319 | |
| 320 | /* record all known change-points (starting and ending addresses), |
| 321 | omitting those that are for empty memory regions */ |
| 322 | chgidx = 0; |
| 323 | for (i=0; i < old_nr; i++) { |
| 324 | if (biosmap[i].size != 0) { |
| 325 | change_point[chgidx]->addr = biosmap[i].addr; |
| 326 | change_point[chgidx++]->pbios = &biosmap[i]; |
| 327 | change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size; |
| 328 | change_point[chgidx++]->pbios = &biosmap[i]; |
| 329 | } |
| 330 | } |
| 331 | chg_nr = chgidx; /* true number of change-points */ |
| 332 | |
| 333 | /* sort change-point list by memory addresses (low -> high) */ |
| 334 | still_changing = 1; |
| 335 | while (still_changing) { |
| 336 | still_changing = 0; |
| 337 | for (i=1; i < chg_nr; i++) { |
| 338 | /* if <current_addr> > <last_addr>, swap */ |
| 339 | /* or, if current=<start_addr> & last=<end_addr>, swap */ |
| 340 | if ((change_point[i]->addr < change_point[i-1]->addr) || |
| 341 | ((change_point[i]->addr == change_point[i-1]->addr) && |
| 342 | (change_point[i]->addr == change_point[i]->pbios->addr) && |
| 343 | (change_point[i-1]->addr != change_point[i-1]->pbios->addr)) |
| 344 | ) |
| 345 | { |
| 346 | change_tmp = change_point[i]; |
| 347 | change_point[i] = change_point[i-1]; |
| 348 | change_point[i-1] = change_tmp; |
| 349 | still_changing=1; |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /* create a new bios memory map, removing overlaps */ |
| 355 | overlap_entries=0; /* number of entries in the overlap table */ |
| 356 | new_bios_entry=0; /* index for creating new bios map entries */ |
| 357 | last_type = 0; /* start with undefined memory type */ |
| 358 | last_addr = 0; /* start with 0 as last starting address */ |
| 359 | /* loop through change-points, determining affect on the new bios map */ |
| 360 | for (chgidx=0; chgidx < chg_nr; chgidx++) |
| 361 | { |
| 362 | /* keep track of all overlapping bios entries */ |
| 363 | if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr) |
| 364 | { |
| 365 | /* add map entry to overlap list (> 1 entry implies an overlap) */ |
| 366 | overlap_list[overlap_entries++]=change_point[chgidx]->pbios; |
| 367 | } |
| 368 | else |
| 369 | { |
| 370 | /* remove entry from list (order independent, so swap with last) */ |
| 371 | for (i=0; i<overlap_entries; i++) |
| 372 | { |
| 373 | if (overlap_list[i] == change_point[chgidx]->pbios) |
| 374 | overlap_list[i] = overlap_list[overlap_entries-1]; |
| 375 | } |
| 376 | overlap_entries--; |
| 377 | } |
| 378 | /* if there are overlapping entries, decide which "type" to use */ |
| 379 | /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */ |
| 380 | current_type = 0; |
| 381 | for (i=0; i<overlap_entries; i++) |
| 382 | if (overlap_list[i]->type > current_type) |
| 383 | current_type = overlap_list[i]->type; |
| 384 | /* continue building up new bios map based on this information */ |
| 385 | if (current_type != last_type) { |
| 386 | if (last_type != 0) { |
| 387 | new_bios[new_bios_entry].size = |
| 388 | change_point[chgidx]->addr - last_addr; |
| 389 | /* move forward only if the new size was non-zero */ |
| 390 | if (new_bios[new_bios_entry].size != 0) |
| 391 | if (++new_bios_entry >= E820MAX) |
| 392 | break; /* no more space left for new bios entries */ |
| 393 | } |
| 394 | if (current_type != 0) { |
| 395 | new_bios[new_bios_entry].addr = change_point[chgidx]->addr; |
| 396 | new_bios[new_bios_entry].type = current_type; |
| 397 | last_addr=change_point[chgidx]->addr; |
| 398 | } |
| 399 | last_type = current_type; |
| 400 | } |
| 401 | } |
| 402 | new_nr = new_bios_entry; /* retain count for new bios entries */ |
| 403 | |
| 404 | /* copy new bios mapping into original location */ |
| 405 | memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry)); |
| 406 | *pnr_map = new_nr; |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * Copy the BIOS e820 map into a safe place. |
| 413 | * |
| 414 | * Sanity-check it while we're at it.. |
| 415 | * |
| 416 | * If we're lucky and live on a modern system, the setup code |
| 417 | * will have given us a memory map that we can use to properly |
| 418 | * set up memory. If we aren't, we'll fake a memory map. |
| 419 | * |
| 420 | * We check to see that the memory map contains at least 2 elements |
| 421 | * before we'll use it, because the detection code in setup.S may |
| 422 | * not be perfect and most every PC known to man has two memory |
| 423 | * regions: one from 0 to 640k, and one from 1mb up. (The IBM |
| 424 | * thinkpad 560x, for example, does not cooperate with the memory |
| 425 | * detection code.) |
| 426 | */ |
Jeremy Fitzhardinge | e75eac3 | 2006-06-25 05:46:50 -0700 | [diff] [blame] | 427 | int __init copy_e820_map(struct e820entry * biosmap, int nr_map) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
| 429 | /* Only one memory region (or negative)? Ignore it */ |
| 430 | if (nr_map < 2) |
| 431 | return -1; |
| 432 | |
| 433 | do { |
| 434 | unsigned long long start = biosmap->addr; |
| 435 | unsigned long long size = biosmap->size; |
| 436 | unsigned long long end = start + size; |
| 437 | unsigned long type = biosmap->type; |
| 438 | |
| 439 | /* Overflow in 64 bits? Ignore the memory map. */ |
| 440 | if (start > end) |
| 441 | return -1; |
| 442 | |
| 443 | /* |
| 444 | * Some BIOSes claim RAM in the 640k - 1M region. |
| 445 | * Not right. Fix it up. |
| 446 | */ |
| 447 | if (type == E820_RAM) { |
| 448 | if (start < 0x100000ULL && end > 0xA0000ULL) { |
| 449 | if (start < 0xA0000ULL) |
| 450 | add_memory_region(start, 0xA0000ULL-start, type); |
| 451 | if (end <= 0x100000ULL) |
| 452 | continue; |
| 453 | start = 0x100000ULL; |
| 454 | size = end - start; |
| 455 | } |
| 456 | } |
| 457 | add_memory_region(start, size, type); |
| 458 | } while (biosmap++,--nr_map); |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) |
| 463 | struct edd edd; |
| 464 | #ifdef CONFIG_EDD_MODULE |
| 465 | EXPORT_SYMBOL(edd); |
| 466 | #endif |
| 467 | /** |
| 468 | * copy_edd() - Copy the BIOS EDD information |
| 469 | * from boot_params into a safe place. |
| 470 | * |
| 471 | */ |
| 472 | static inline void copy_edd(void) |
| 473 | { |
| 474 | memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature)); |
| 475 | memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info)); |
| 476 | edd.mbr_signature_nr = EDD_MBR_SIG_NR; |
| 477 | edd.edd_info_nr = EDD_NR; |
| 478 | } |
| 479 | #else |
| 480 | static inline void copy_edd(void) |
| 481 | { |
| 482 | } |
| 483 | #endif |
| 484 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 485 | static int __initdata user_defined_memmap = 0; |
| 486 | |
| 487 | /* |
| 488 | * "mem=nopentium" disables the 4MB page tables. |
| 489 | * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM |
| 490 | * to <mem>, overriding the bios size. |
| 491 | * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from |
| 492 | * <start> to <start>+<mem>, overriding the bios size. |
| 493 | * |
| 494 | * HPA tells me bootloaders need to parse mem=, so no new |
| 495 | * option should be mem= [also see Documentation/i386/boot.txt] |
| 496 | */ |
| 497 | static int __init parse_mem(char *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 499 | if (!arg) |
| 500 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 502 | if (strcmp(arg, "nopentium") == 0) { |
| 503 | clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability); |
| 504 | disable_pse = 1; |
| 505 | } else { |
| 506 | /* If the user specifies memory size, we |
| 507 | * limit the BIOS-provided memory map to |
| 508 | * that size. exactmap can be used to specify |
| 509 | * the exact map. mem=number can be used to |
| 510 | * trim the existing memory map. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | */ |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 512 | unsigned long long mem_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 514 | mem_size = memparse(arg, &arg); |
| 515 | limit_regions(mem_size); |
| 516 | user_defined_memmap = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 518 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 520 | early_param("mem", parse_mem); |
| 521 | |
| 522 | static int __init parse_memmap(char *arg) |
| 523 | { |
| 524 | if (!arg) |
| 525 | return -EINVAL; |
| 526 | |
| 527 | if (strcmp(arg, "exactmap") == 0) { |
| 528 | #ifdef CONFIG_CRASH_DUMP |
| 529 | /* If we are doing a crash dump, we |
| 530 | * still need to know the real mem |
| 531 | * size before original memory map is |
| 532 | * reset. |
| 533 | */ |
| 534 | find_max_pfn(); |
| 535 | saved_max_pfn = max_pfn; |
| 536 | #endif |
| 537 | e820.nr_map = 0; |
| 538 | user_defined_memmap = 1; |
| 539 | } else { |
| 540 | /* If the user specifies memory size, we |
| 541 | * limit the BIOS-provided memory map to |
| 542 | * that size. exactmap can be used to specify |
| 543 | * the exact map. mem=number can be used to |
| 544 | * trim the existing memory map. |
| 545 | */ |
| 546 | unsigned long long start_at, mem_size; |
| 547 | |
| 548 | mem_size = memparse(arg, &arg); |
| 549 | if (*arg == '@') { |
| 550 | start_at = memparse(arg+1, &arg); |
| 551 | add_memory_region(start_at, mem_size, E820_RAM); |
| 552 | } else if (*arg == '#') { |
| 553 | start_at = memparse(arg+1, &arg); |
| 554 | add_memory_region(start_at, mem_size, E820_ACPI); |
| 555 | } else if (*arg == '$') { |
| 556 | start_at = memparse(arg+1, &arg); |
| 557 | add_memory_region(start_at, mem_size, E820_RESERVED); |
| 558 | } else { |
| 559 | limit_regions(mem_size); |
| 560 | user_defined_memmap = 1; |
| 561 | } |
| 562 | } |
| 563 | return 0; |
| 564 | } |
| 565 | early_param("memmap", parse_memmap); |
| 566 | |
| 567 | #ifdef CONFIG_PROC_VMCORE |
| 568 | /* elfcorehdr= specifies the location of elf core header |
| 569 | * stored by the crashed kernel. |
| 570 | */ |
| 571 | static int __init parse_elfcorehdr(char *arg) |
| 572 | { |
| 573 | if (!arg) |
| 574 | return -EINVAL; |
| 575 | |
| 576 | elfcorehdr_addr = memparse(arg, &arg); |
| 577 | return 0; |
| 578 | } |
| 579 | early_param("elfcorehdr", parse_elfcorehdr); |
| 580 | #endif /* CONFIG_PROC_VMCORE */ |
| 581 | |
| 582 | /* |
| 583 | * highmem=size forces highmem to be exactly 'size' bytes. |
| 584 | * This works even on boxes that have no highmem otherwise. |
| 585 | * This also works to reduce highmem size on bigger boxes. |
| 586 | */ |
| 587 | static int __init parse_highmem(char *arg) |
| 588 | { |
| 589 | if (!arg) |
| 590 | return -EINVAL; |
| 591 | |
| 592 | highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT; |
| 593 | return 0; |
| 594 | } |
| 595 | early_param("highmem", parse_highmem); |
| 596 | |
| 597 | /* |
| 598 | * vmalloc=size forces the vmalloc area to be exactly 'size' |
| 599 | * bytes. This can be used to increase (or decrease) the |
| 600 | * vmalloc area - the default is 128m. |
| 601 | */ |
| 602 | static int __init parse_vmalloc(char *arg) |
| 603 | { |
| 604 | if (!arg) |
| 605 | return -EINVAL; |
| 606 | |
| 607 | __VMALLOC_RESERVE = memparse(arg, &arg); |
| 608 | return 0; |
| 609 | } |
| 610 | early_param("vmalloc", parse_vmalloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | /* |
Zachary Amsden | 461a9aff | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 613 | * reservetop=size reserves a hole at the top of the kernel address space which |
| 614 | * a hypervisor can load into later. Needed for dynamically loaded hypervisors, |
| 615 | * so relocating the fixmap can be done before paging initialization. |
| 616 | */ |
| 617 | static int __init parse_reservetop(char *arg) |
| 618 | { |
| 619 | unsigned long address; |
| 620 | |
| 621 | if (!arg) |
| 622 | return -EINVAL; |
| 623 | |
| 624 | address = memparse(arg, &arg); |
| 625 | reserve_top_address(address); |
| 626 | return 0; |
| 627 | } |
| 628 | early_param("reservetop", parse_reservetop); |
| 629 | |
| 630 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | * Callback for efi_memory_walk. |
| 632 | */ |
| 633 | static int __init |
| 634 | efi_find_max_pfn(unsigned long start, unsigned long end, void *arg) |
| 635 | { |
| 636 | unsigned long *max_pfn = arg, pfn; |
| 637 | |
| 638 | if (start < end) { |
| 639 | pfn = PFN_UP(end -1); |
| 640 | if (pfn > *max_pfn) |
| 641 | *max_pfn = pfn; |
| 642 | } |
| 643 | return 0; |
| 644 | } |
| 645 | |
Andy Whitcroft | 215c340 | 2006-01-06 00:12:06 -0800 | [diff] [blame] | 646 | static int __init |
| 647 | efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg) |
| 648 | { |
bibo,mao | ae74589 | 2006-10-28 10:38:29 -0700 | [diff] [blame] | 649 | memory_present(0, PFN_UP(start), PFN_DOWN(end)); |
Andy Whitcroft | 215c340 | 2006-01-06 00:12:06 -0800 | [diff] [blame] | 650 | return 0; |
| 651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Linus Torvalds | 79e453d | 2006-09-19 08:15:22 -0700 | [diff] [blame] | 653 | /* |
| 654 | * This function checks if the entire range <start,end> is mapped with type. |
| 655 | * |
| 656 | * Note: this function only works correct if the e820 table is sorted and |
| 657 | * not-overlapping, which is the case |
| 658 | */ |
| 659 | int __init |
| 660 | e820_all_mapped(unsigned long s, unsigned long e, unsigned type) |
| 661 | { |
| 662 | u64 start = s; |
| 663 | u64 end = e; |
| 664 | int i; |
| 665 | for (i = 0; i < e820.nr_map; i++) { |
| 666 | struct e820entry *ei = &e820.map[i]; |
| 667 | if (type && ei->type != type) |
| 668 | continue; |
| 669 | /* is the region (part) in overlap with the current region ?*/ |
| 670 | if (ei->addr >= end || ei->addr + ei->size <= start) |
| 671 | continue; |
| 672 | /* if the region is at the beginning of <start,end> we move |
| 673 | * start to the end of the region since it's ok until there |
| 674 | */ |
| 675 | if (ei->addr <= start) |
| 676 | start = ei->addr + ei->size; |
| 677 | /* if start is now at or beyond end, we're done, full |
| 678 | * coverage */ |
| 679 | if (start >= end) |
| 680 | return 1; /* we're done */ |
| 681 | } |
| 682 | return 0; |
| 683 | } |
| 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | /* |
| 686 | * Find the highest page frame number we have available |
| 687 | */ |
| 688 | void __init find_max_pfn(void) |
| 689 | { |
| 690 | int i; |
| 691 | |
| 692 | max_pfn = 0; |
| 693 | if (efi_enabled) { |
| 694 | efi_memmap_walk(efi_find_max_pfn, &max_pfn); |
Andy Whitcroft | 215c340 | 2006-01-06 00:12:06 -0800 | [diff] [blame] | 695 | efi_memmap_walk(efi_memory_present_wrapper, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | return; |
| 697 | } |
| 698 | |
| 699 | for (i = 0; i < e820.nr_map; i++) { |
| 700 | unsigned long start, end; |
| 701 | /* RAM? */ |
| 702 | if (e820.map[i].type != E820_RAM) |
| 703 | continue; |
| 704 | start = PFN_UP(e820.map[i].addr); |
| 705 | end = PFN_DOWN(e820.map[i].addr + e820.map[i].size); |
| 706 | if (start >= end) |
| 707 | continue; |
| 708 | if (end > max_pfn) |
| 709 | max_pfn = end; |
Andy Whitcroft | 215c340 | 2006-01-06 00:12:06 -0800 | [diff] [blame] | 710 | memory_present(0, start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * Determine low and high memory ranges: |
| 716 | */ |
| 717 | unsigned long __init find_max_low_pfn(void) |
| 718 | { |
| 719 | unsigned long max_low_pfn; |
| 720 | |
| 721 | max_low_pfn = max_pfn; |
| 722 | if (max_low_pfn > MAXMEM_PFN) { |
| 723 | if (highmem_pages == -1) |
| 724 | highmem_pages = max_pfn - MAXMEM_PFN; |
| 725 | if (highmem_pages + MAXMEM_PFN < max_pfn) |
| 726 | max_pfn = MAXMEM_PFN + highmem_pages; |
| 727 | if (highmem_pages + MAXMEM_PFN > max_pfn) { |
| 728 | printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages)); |
| 729 | highmem_pages = 0; |
| 730 | } |
| 731 | max_low_pfn = MAXMEM_PFN; |
| 732 | #ifndef CONFIG_HIGHMEM |
| 733 | /* Maximum memory usable is what is directly addressable */ |
| 734 | printk(KERN_WARNING "Warning only %ldMB will be used.\n", |
| 735 | MAXMEM>>20); |
| 736 | if (max_pfn > MAX_NONPAE_PFN) |
| 737 | printk(KERN_WARNING "Use a PAE enabled kernel.\n"); |
| 738 | else |
| 739 | printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n"); |
| 740 | max_pfn = MAXMEM_PFN; |
| 741 | #else /* !CONFIG_HIGHMEM */ |
| 742 | #ifndef CONFIG_X86_PAE |
| 743 | if (max_pfn > MAX_NONPAE_PFN) { |
| 744 | max_pfn = MAX_NONPAE_PFN; |
| 745 | printk(KERN_WARNING "Warning only 4GB will be used.\n"); |
| 746 | printk(KERN_WARNING "Use a PAE enabled kernel.\n"); |
| 747 | } |
| 748 | #endif /* !CONFIG_X86_PAE */ |
| 749 | #endif /* !CONFIG_HIGHMEM */ |
| 750 | } else { |
| 751 | if (highmem_pages == -1) |
| 752 | highmem_pages = 0; |
| 753 | #ifdef CONFIG_HIGHMEM |
| 754 | if (highmem_pages >= max_pfn) { |
| 755 | printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn)); |
| 756 | highmem_pages = 0; |
| 757 | } |
| 758 | if (highmem_pages) { |
| 759 | if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){ |
| 760 | printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages)); |
| 761 | highmem_pages = 0; |
| 762 | } |
| 763 | max_low_pfn -= highmem_pages; |
| 764 | } |
| 765 | #else |
| 766 | if (highmem_pages) |
| 767 | printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n"); |
| 768 | #endif |
| 769 | } |
| 770 | return max_low_pfn; |
| 771 | } |
| 772 | |
| 773 | /* |
| 774 | * Free all available memory for boot time allocation. Used |
| 775 | * as a callback function by efi_memory_walk() |
| 776 | */ |
| 777 | |
| 778 | static int __init |
| 779 | free_available_memory(unsigned long start, unsigned long end, void *arg) |
| 780 | { |
| 781 | /* check max_low_pfn */ |
Tolentino, Matthew E | 23dd842 | 2006-03-26 01:37:09 -0800 | [diff] [blame] | 782 | if (start >= (max_low_pfn << PAGE_SHIFT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | return 0; |
Tolentino, Matthew E | 23dd842 | 2006-03-26 01:37:09 -0800 | [diff] [blame] | 784 | if (end >= (max_low_pfn << PAGE_SHIFT)) |
| 785 | end = max_low_pfn << PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | if (start < end) |
| 787 | free_bootmem(start, end - start); |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | /* |
| 792 | * Register fully available low RAM pages with the bootmem allocator. |
| 793 | */ |
| 794 | static void __init register_bootmem_low_pages(unsigned long max_low_pfn) |
| 795 | { |
| 796 | int i; |
| 797 | |
| 798 | if (efi_enabled) { |
| 799 | efi_memmap_walk(free_available_memory, NULL); |
| 800 | return; |
| 801 | } |
| 802 | for (i = 0; i < e820.nr_map; i++) { |
| 803 | unsigned long curr_pfn, last_pfn, size; |
| 804 | /* |
| 805 | * Reserve usable low memory |
| 806 | */ |
| 807 | if (e820.map[i].type != E820_RAM) |
| 808 | continue; |
| 809 | /* |
| 810 | * We are rounding up the start address of usable memory: |
| 811 | */ |
| 812 | curr_pfn = PFN_UP(e820.map[i].addr); |
| 813 | if (curr_pfn >= max_low_pfn) |
| 814 | continue; |
| 815 | /* |
| 816 | * ... and at the end of the usable range downwards: |
| 817 | */ |
| 818 | last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size); |
| 819 | |
| 820 | if (last_pfn > max_low_pfn) |
| 821 | last_pfn = max_low_pfn; |
| 822 | |
| 823 | /* |
| 824 | * .. finally, did all the rounding and playing |
| 825 | * around just make the area go away? |
| 826 | */ |
| 827 | if (last_pfn <= curr_pfn) |
| 828 | continue; |
| 829 | |
| 830 | size = last_pfn - curr_pfn; |
| 831 | free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size)); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | /* |
| 836 | * workaround for Dell systems that neglect to reserve EBDA |
| 837 | */ |
| 838 | static void __init reserve_ebda_region(void) |
| 839 | { |
| 840 | unsigned int addr; |
| 841 | addr = get_bios_ebda(); |
| 842 | if (addr) |
| 843 | reserve_bootmem(addr, PAGE_SIZE); |
| 844 | } |
| 845 | |
Andy Whitcroft | 05b79bd | 2005-06-23 00:07:57 -0700 | [diff] [blame] | 846 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | void __init setup_bootmem_allocator(void); |
| 848 | static unsigned long __init setup_memory(void) |
| 849 | { |
| 850 | /* |
| 851 | * partially used pages are not usable - thus |
| 852 | * we are rounding upwards: |
| 853 | */ |
| 854 | min_low_pfn = PFN_UP(init_pg_tables_end); |
| 855 | |
| 856 | find_max_pfn(); |
| 857 | |
| 858 | max_low_pfn = find_max_low_pfn(); |
| 859 | |
| 860 | #ifdef CONFIG_HIGHMEM |
| 861 | highstart_pfn = highend_pfn = max_pfn; |
| 862 | if (max_pfn > max_low_pfn) { |
| 863 | highstart_pfn = max_low_pfn; |
| 864 | } |
| 865 | printk(KERN_NOTICE "%ldMB HIGHMEM available.\n", |
| 866 | pages_to_mb(highend_pfn - highstart_pfn)); |
Jan Beulich | ba9c231 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 867 | num_physpages = highend_pfn; |
| 868 | high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1; |
| 869 | #else |
| 870 | num_physpages = max_low_pfn; |
| 871 | high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1; |
| 872 | #endif |
| 873 | #ifdef CONFIG_FLATMEM |
| 874 | max_mapnr = num_physpages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | #endif |
| 876 | printk(KERN_NOTICE "%ldMB LOWMEM available.\n", |
| 877 | pages_to_mb(max_low_pfn)); |
| 878 | |
| 879 | setup_bootmem_allocator(); |
| 880 | |
| 881 | return max_low_pfn; |
| 882 | } |
| 883 | |
| 884 | void __init zone_sizes_init(void) |
| 885 | { |
Mel Gorman | 6391af1 | 2006-10-11 01:20:39 -0700 | [diff] [blame] | 886 | unsigned long max_zone_pfns[MAX_NR_ZONES]; |
| 887 | memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); |
| 888 | max_zone_pfns[ZONE_DMA] = |
| 889 | virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT; |
| 890 | max_zone_pfns[ZONE_NORMAL] = max_low_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | #ifdef CONFIG_HIGHMEM |
Mel Gorman | 6391af1 | 2006-10-11 01:20:39 -0700 | [diff] [blame] | 892 | max_zone_pfns[ZONE_HIGHMEM] = highend_pfn; |
Mel Gorman | 4cfee88 | 2006-09-27 01:49:51 -0700 | [diff] [blame] | 893 | add_active_range(0, 0, highend_pfn); |
| 894 | #else |
Mel Gorman | 4cfee88 | 2006-09-27 01:49:51 -0700 | [diff] [blame] | 895 | add_active_range(0, 0, max_low_pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | #endif |
Mel Gorman | 4cfee88 | 2006-09-27 01:49:51 -0700 | [diff] [blame] | 897 | |
| 898 | free_area_init_nodes(max_zone_pfns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | } |
| 900 | #else |
Andy Whitcroft | 05b79bd | 2005-06-23 00:07:57 -0700 | [diff] [blame] | 901 | extern unsigned long __init setup_memory(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | extern void zone_sizes_init(void); |
Andy Whitcroft | 05b79bd | 2005-06-23 00:07:57 -0700 | [diff] [blame] | 903 | #endif /* !CONFIG_NEED_MULTIPLE_NODES */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | void __init setup_bootmem_allocator(void) |
| 906 | { |
| 907 | unsigned long bootmap_size; |
| 908 | /* |
| 909 | * Initialize the boot-time allocator (with low memory only): |
| 910 | */ |
| 911 | bootmap_size = init_bootmem(min_low_pfn, max_low_pfn); |
| 912 | |
| 913 | register_bootmem_low_pages(max_low_pfn); |
| 914 | |
| 915 | /* |
| 916 | * Reserve the bootmem bitmap itself as well. We do this in two |
| 917 | * steps (first step was init_bootmem()) because this catches |
| 918 | * the (very unlikely) case of us accidentally initializing the |
| 919 | * bootmem allocator with an invalid RAM area. |
| 920 | */ |
Eric W. Biederman | 8621b81 | 2006-12-07 02:14:03 +0100 | [diff] [blame] | 921 | reserve_bootmem(__pa_symbol(_text), (PFN_PHYS(min_low_pfn) + |
| 922 | bootmap_size + PAGE_SIZE-1) - __pa_symbol(_text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
| 924 | /* |
| 925 | * reserve physical page 0 - it's a special BIOS page on many boxes, |
| 926 | * enabling clean reboots, SMP operation, laptop functions. |
| 927 | */ |
| 928 | reserve_bootmem(0, PAGE_SIZE); |
| 929 | |
| 930 | /* reserve EBDA region, it's a 4K region */ |
| 931 | reserve_ebda_region(); |
| 932 | |
| 933 | /* could be an AMD 768MPX chipset. Reserve a page before VGA to prevent |
| 934 | PCI prefetch into it (errata #56). Usually the page is reserved anyways, |
| 935 | unless you have no PS/2 mouse plugged in. */ |
| 936 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD && |
| 937 | boot_cpu_data.x86 == 6) |
| 938 | reserve_bootmem(0xa0000 - 4096, 4096); |
| 939 | |
| 940 | #ifdef CONFIG_SMP |
| 941 | /* |
| 942 | * But first pinch a few for the stack/trampoline stuff |
| 943 | * FIXME: Don't need the extra page at 4K, but need to fix |
| 944 | * trampoline before removing it. (see the GDT stuff) |
| 945 | */ |
| 946 | reserve_bootmem(PAGE_SIZE, PAGE_SIZE); |
| 947 | #endif |
| 948 | #ifdef CONFIG_ACPI_SLEEP |
| 949 | /* |
| 950 | * Reserve low memory region for sleep support. |
| 951 | */ |
| 952 | acpi_reserve_bootmem(); |
| 953 | #endif |
| 954 | #ifdef CONFIG_X86_FIND_SMP_CONFIG |
| 955 | /* |
| 956 | * Find and reserve possible boot-time SMP configuration: |
| 957 | */ |
| 958 | find_smp_config(); |
| 959 | #endif |
keith mannthey | 9102330 | 2006-09-25 23:31:03 -0700 | [diff] [blame] | 960 | numa_kva_reserve(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | #ifdef CONFIG_BLK_DEV_INITRD |
| 962 | if (LOADER_TYPE && INITRD_START) { |
| 963 | if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) { |
| 964 | reserve_bootmem(INITRD_START, INITRD_SIZE); |
| 965 | initrd_start = |
| 966 | INITRD_START ? INITRD_START + PAGE_OFFSET : 0; |
| 967 | initrd_end = initrd_start+INITRD_SIZE; |
| 968 | } |
| 969 | else { |
| 970 | printk(KERN_ERR "initrd extends beyond end of memory " |
| 971 | "(0x%08lx > 0x%08lx)\ndisabling initrd\n", |
| 972 | INITRD_START + INITRD_SIZE, |
| 973 | max_low_pfn << PAGE_SHIFT); |
| 974 | initrd_start = 0; |
| 975 | } |
| 976 | } |
| 977 | #endif |
Eric W. Biederman | 1bc3b91 | 2005-06-25 14:58:01 -0700 | [diff] [blame] | 978 | #ifdef CONFIG_KEXEC |
| 979 | if (crashk_res.start != crashk_res.end) |
| 980 | reserve_bootmem(crashk_res.start, |
| 981 | crashk_res.end - crashk_res.start + 1); |
| 982 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | /* |
| 986 | * The node 0 pgdat is initialized before all of these because |
| 987 | * it's needed for bootmem. node>0 pgdats have their virtual |
| 988 | * space allocated before the pagetables are in place to access |
| 989 | * them, so they can't be cleared then. |
| 990 | * |
| 991 | * This should all compile down to nothing when NUMA is off. |
| 992 | */ |
| 993 | void __init remapped_pgdat_init(void) |
| 994 | { |
| 995 | int nid; |
| 996 | |
| 997 | for_each_online_node(nid) { |
| 998 | if (nid != 0) |
| 999 | memset(NODE_DATA(nid), 0, sizeof(struct pglist_data)); |
| 1000 | } |
| 1001 | } |
| 1002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
Linus Torvalds | b408cbc | 2006-02-22 15:50:30 -0800 | [diff] [blame] | 1004 | |
| 1005 | static void __init register_memory(void) |
| 1006 | { |
| 1007 | unsigned long gapstart, gapsize, round; |
| 1008 | unsigned long long last; |
| 1009 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
| 1011 | /* |
| 1012 | * Search for the bigest gap in the low 32 bits of the e820 |
| 1013 | * memory space. |
| 1014 | */ |
| 1015 | last = 0x100000000ull; |
| 1016 | gapstart = 0x10000000; |
| 1017 | gapsize = 0x400000; |
| 1018 | i = e820.nr_map; |
| 1019 | while (--i >= 0) { |
| 1020 | unsigned long long start = e820.map[i].addr; |
| 1021 | unsigned long long end = start + e820.map[i].size; |
| 1022 | |
| 1023 | /* |
| 1024 | * Since "last" is at most 4GB, we know we'll |
| 1025 | * fit in 32 bits if this condition is true |
| 1026 | */ |
| 1027 | if (last > end) { |
| 1028 | unsigned long gap = last - end; |
| 1029 | |
| 1030 | if (gap > gapsize) { |
| 1031 | gapsize = gap; |
| 1032 | gapstart = end; |
| 1033 | } |
| 1034 | } |
| 1035 | if (start < last) |
| 1036 | last = start; |
| 1037 | } |
| 1038 | |
| 1039 | /* |
Daniel Ritz | f0eca96 | 2005-09-09 00:57:14 +0200 | [diff] [blame] | 1040 | * See how much we want to round up: start off with |
| 1041 | * rounding to the next 1MB area. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | */ |
Daniel Ritz | f0eca96 | 2005-09-09 00:57:14 +0200 | [diff] [blame] | 1043 | round = 0x100000; |
| 1044 | while ((gapsize >> 4) > round) |
| 1045 | round += round; |
| 1046 | /* Fun with two's complement */ |
| 1047 | pci_mem_start = (gapstart + round) & -round; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
| 1049 | printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n", |
| 1050 | pci_mem_start, gapstart, gapsize); |
| 1051 | } |
| 1052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | #ifdef CONFIG_MCA |
| 1054 | static void set_mca_bus(int x) |
| 1055 | { |
| 1056 | MCA_bus = x; |
| 1057 | } |
| 1058 | #else |
| 1059 | static void set_mca_bus(int x) { } |
| 1060 | #endif |
| 1061 | |
| 1062 | /* |
| 1063 | * Determine if we were loaded by an EFI loader. If so, then we have also been |
| 1064 | * passed the efi memmap, systab, etc., so we should use these data structures |
| 1065 | * for initialization. Note, the efi init code path is determined by the |
| 1066 | * global efi_enabled. This allows the same kernel image to be used on existing |
| 1067 | * systems (with a traditional BIOS) as well as on EFI systems. |
| 1068 | */ |
| 1069 | void __init setup_arch(char **cmdline_p) |
| 1070 | { |
| 1071 | unsigned long max_low_pfn; |
| 1072 | |
| 1073 | memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); |
| 1074 | pre_setup_arch_hook(); |
| 1075 | early_cpu_init(); |
| 1076 | |
| 1077 | /* |
| 1078 | * FIXME: This isn't an official loader_type right |
| 1079 | * now but does currently work with elilo. |
| 1080 | * If we were configured as an EFI kernel, check to make |
| 1081 | * sure that we were loaded correctly from elilo and that |
| 1082 | * the system table is valid. If not, then initialize normally. |
| 1083 | */ |
| 1084 | #ifdef CONFIG_EFI |
| 1085 | if ((LOADER_TYPE == 0x50) && EFI_SYSTAB) |
| 1086 | efi_enabled = 1; |
| 1087 | #endif |
| 1088 | |
| 1089 | ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV); |
| 1090 | drive_info = DRIVE_INFO; |
| 1091 | screen_info = SCREEN_INFO; |
| 1092 | edid_info = EDID_INFO; |
| 1093 | apm_info.bios = APM_BIOS_INFO; |
| 1094 | ist_info = IST_INFO; |
| 1095 | saved_videomode = VIDEO_MODE; |
| 1096 | if( SYS_DESC_TABLE.length != 0 ) { |
| 1097 | set_mca_bus(SYS_DESC_TABLE.table[3] & 0x2); |
| 1098 | machine_id = SYS_DESC_TABLE.table[0]; |
| 1099 | machine_submodel_id = SYS_DESC_TABLE.table[1]; |
| 1100 | BIOS_revision = SYS_DESC_TABLE.table[2]; |
| 1101 | } |
| 1102 | bootloader_type = LOADER_TYPE; |
| 1103 | |
| 1104 | #ifdef CONFIG_BLK_DEV_RAM |
| 1105 | rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK; |
| 1106 | rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0); |
| 1107 | rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0); |
| 1108 | #endif |
| 1109 | ARCH_SETUP |
| 1110 | if (efi_enabled) |
| 1111 | efi_init(); |
| 1112 | else { |
| 1113 | printk(KERN_INFO "BIOS-provided physical RAM map:\n"); |
| 1114 | print_memory_map(machine_specific_memory_setup()); |
| 1115 | } |
| 1116 | |
| 1117 | copy_edd(); |
| 1118 | |
| 1119 | if (!MOUNT_ROOT_RDONLY) |
| 1120 | root_mountflags &= ~MS_RDONLY; |
| 1121 | init_mm.start_code = (unsigned long) _text; |
| 1122 | init_mm.end_code = (unsigned long) _etext; |
| 1123 | init_mm.end_data = (unsigned long) _edata; |
| 1124 | init_mm.brk = init_pg_tables_end + PAGE_OFFSET; |
| 1125 | |
| 1126 | code_resource.start = virt_to_phys(_text); |
| 1127 | code_resource.end = virt_to_phys(_etext)-1; |
| 1128 | data_resource.start = virt_to_phys(_etext); |
| 1129 | data_resource.end = virt_to_phys(_edata)-1; |
| 1130 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1131 | parse_early_param(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1133 | if (user_defined_memmap) { |
| 1134 | printk(KERN_INFO "user-defined physical RAM map:\n"); |
| 1135 | print_memory_map("user"); |
Stas Sergeev | 99b7de3 | 2006-03-23 02:59:41 -0800 | [diff] [blame] | 1136 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1137 | |
| 1138 | strlcpy(command_line, saved_command_line, COMMAND_LINE_SIZE); |
| 1139 | *cmdline_p = command_line; |
Stas Sergeev | 99b7de3 | 2006-03-23 02:59:41 -0800 | [diff] [blame] | 1140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | max_low_pfn = setup_memory(); |
| 1142 | |
| 1143 | /* |
| 1144 | * NOTE: before this point _nobody_ is allowed to allocate |
| 1145 | * any memory using the bootmem allocator. Although the |
| 1146 | * alloctor is now initialised only the first 8Mb of the kernel |
| 1147 | * virtual address space has been mapped. All allocations before |
| 1148 | * paging_init() has completed must use the alloc_bootmem_low_pages() |
| 1149 | * variant (which allocates DMA'able memory) and care must be taken |
| 1150 | * not to exceed the 8Mb limit. |
| 1151 | */ |
| 1152 | |
| 1153 | #ifdef CONFIG_SMP |
| 1154 | smp_alloc_memory(); /* AP processor realmode stacks in low memory*/ |
| 1155 | #endif |
| 1156 | paging_init(); |
| 1157 | remapped_pgdat_init(); |
Andy Whitcroft | 05b79bd | 2005-06-23 00:07:57 -0700 | [diff] [blame] | 1158 | sparse_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | zone_sizes_init(); |
| 1160 | |
| 1161 | /* |
| 1162 | * NOTE: at this point the bootmem allocator is fully available. |
| 1163 | */ |
| 1164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | dmi_scan_machine(); |
| 1166 | |
| 1167 | #ifdef CONFIG_X86_GENERICARCH |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1168 | generic_apic_probe(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | #endif |
| 1170 | if (efi_enabled) |
| 1171 | efi_map_memmap(); |
| 1172 | |
Len Brown | 888ba6c | 2005-08-24 12:07:20 -0400 | [diff] [blame] | 1173 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | /* |
| 1175 | * Parse the ACPI tables for possible boot-time SMP configuration. |
| 1176 | */ |
| 1177 | acpi_boot_table_init(); |
Andy Currid | d44647b | 2006-06-08 00:43:38 -0700 | [diff] [blame] | 1178 | #endif |
| 1179 | |
Andi Kleen | f157cbb | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 1180 | #ifdef CONFIG_PCI |
Andy Currid | d44647b | 2006-06-08 00:43:38 -0700 | [diff] [blame] | 1181 | #ifdef CONFIG_X86_IO_APIC |
| 1182 | check_acpi_pci(); /* Checks more than just ACPI actually */ |
| 1183 | #endif |
Andi Kleen | f157cbb | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 1184 | #endif |
Andy Currid | d44647b | 2006-06-08 00:43:38 -0700 | [diff] [blame] | 1185 | |
| 1186 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | acpi_boot_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 1189 | #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC) |
| 1190 | if (def_to_bigsmp) |
| 1191 | printk(KERN_WARNING "More than 8 CPUs detected and " |
| 1192 | "CONFIG_X86_PC cannot handle it.\nUse " |
| 1193 | "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n"); |
| 1194 | #endif |
| 1195 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | #ifdef CONFIG_X86_LOCAL_APIC |
| 1197 | if (smp_found_config) |
| 1198 | get_smp_config(); |
| 1199 | #endif |
| 1200 | |
| 1201 | register_memory(); |
| 1202 | |
| 1203 | #ifdef CONFIG_VT |
| 1204 | #if defined(CONFIG_VGA_CONSOLE) |
| 1205 | if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) |
| 1206 | conswitchp = &vga_con; |
| 1207 | #elif defined(CONFIG_DUMMY_CONSOLE) |
| 1208 | conswitchp = &dummy_con; |
| 1209 | #endif |
| 1210 | #endif |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 1211 | tsc_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Michael Neuling | e5c6c8e | 2006-03-14 00:11:50 -0500 | [diff] [blame] | 1214 | static __init int add_pcspkr(void) |
| 1215 | { |
| 1216 | struct platform_device *pd; |
| 1217 | int ret; |
| 1218 | |
| 1219 | pd = platform_device_alloc("pcspkr", -1); |
| 1220 | if (!pd) |
| 1221 | return -ENOMEM; |
| 1222 | |
| 1223 | ret = platform_device_add(pd); |
| 1224 | if (ret) |
| 1225 | platform_device_put(pd); |
| 1226 | |
| 1227 | return ret; |
| 1228 | } |
| 1229 | device_initcall(add_pcspkr); |
| 1230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | /* |
| 1232 | * Local Variables: |
| 1233 | * mode:c |
| 1234 | * c-file-style:"k&r" |
| 1235 | * c-basic-offset:8 |
| 1236 | * End: |
| 1237 | */ |