x86 boot: pass E820 memory map entries more than 128 via linked list of setup data
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / x86 / kernel / setup_32.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Copyright (C) 1995 Linus Torvalds
3 *
4 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
5 *
6 * Memory region support
7 * David Parsons <orc@pell.chi.il.us>, July-August 1999
8 *
9 * Added E820 sanitization routine (removes overlapping memory regions);
10 * Brian Moyle <bmoyle@mvista.com>, February 2001
11 *
12 * Moved CPU detection code to cpu/${cpu}.c
13 * Patrick Mochel <mochel@osdl.org>, March 2002
14 *
15 * Provisions for empty E820 memory regions (reported by certain BIOSes).
16 * Alex Achenbach <xela@slit.de>, December 2002.
17 *
18 */
19
20/*
21 * This file handles the architecture-dependent parts of initialization
22 */
23
24#include <linux/sched.h>
25#include <linux/mm.h>
05b79bdc 26#include <linux/mmzone.h>
894673ee 27#include <linux/screen_info.h>
1da177e4
LT
28#include <linux/ioport.h>
29#include <linux/acpi.h>
30#include <linux/apm_bios.h>
31#include <linux/initrd.h>
32#include <linux/bootmem.h>
33#include <linux/seq_file.h>
34#include <linux/console.h>
35#include <linux/mca.h>
36#include <linux/root_dev.h>
37#include <linux/highmem.h>
38#include <linux/module.h>
39#include <linux/efi.h>
40#include <linux/init.h>
41#include <linux/edd.h>
138fe4e0 42#include <linux/iscsi_ibft.h>
1da177e4 43#include <linux/nodemask.h>
1bc3b91a 44#include <linux/kexec.h>
2030eae5 45#include <linux/crash_dump.h>
e9928674 46#include <linux/dmi.h>
22a9835c 47#include <linux/pfn.h>
376ff035 48#include <linux/pci.h>
f212ec4b 49#include <linux/init_ohci1394_dma.h>
790c73f6 50#include <linux/kvm_para.h>
1bc3b91a 51
1da177e4 52#include <video/edid.h>
1bc3b91a 53
093af8d7 54#include <asm/mtrr.h>
9635b47d 55#include <asm/apic.h>
1da177e4
LT
56#include <asm/e820.h>
57#include <asm/mpspec.h>
91023300 58#include <asm/mmzone.h>
1da177e4
LT
59#include <asm/setup.h>
60#include <asm/arch_hooks.h>
61#include <asm/sections.h>
62#include <asm/io_apic.h>
63#include <asm/ist.h>
64#include <asm/io.h>
7ce0bcfd 65#include <asm/vmi.h>
e75eac33 66#include <setup_arch.h>
ce3fe6b2 67#include <asm/bios_ebda.h>
00bf4098 68#include <asm/cacheflush.h>
2fde61fd 69#include <asm/processor.h>
ecacf09f 70#include <asm/efi.h>
1da177e4
LT
71
72/* This value is set up by the early boot code to point to the value
73 immediately after the boot time page tables. It contains a *physical*
74 address, and must not be in the .bss segment! */
f0d43100 75unsigned long init_pg_tables_start __initdata = ~0UL;
1da177e4
LT
76unsigned long init_pg_tables_end __initdata = ~0UL;
77
1da177e4
LT
78/*
79 * Machine setup..
80 */
c9cce83d
BW
81static struct resource data_resource = {
82 .name = "Kernel data",
83 .start = 0,
84 .end = 0,
85 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
86};
87
88static struct resource code_resource = {
89 .name = "Kernel code",
90 .start = 0,
91 .end = 0,
92 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
93};
94
95static struct resource bss_resource = {
96 .name = "Kernel bss",
97 .start = 0,
98 .end = 0,
99 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
100};
101
102static struct resource video_ram_resource = {
103 .name = "Video RAM area",
104 .start = 0xa0000,
105 .end = 0xbffff,
106 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
107};
108
109static struct resource standard_io_resources[] = { {
110 .name = "dma1",
111 .start = 0x0000,
112 .end = 0x001f,
113 .flags = IORESOURCE_BUSY | IORESOURCE_IO
114}, {
115 .name = "pic1",
116 .start = 0x0020,
117 .end = 0x0021,
118 .flags = IORESOURCE_BUSY | IORESOURCE_IO
119}, {
120 .name = "timer0",
121 .start = 0x0040,
122 .end = 0x0043,
123 .flags = IORESOURCE_BUSY | IORESOURCE_IO
124}, {
125 .name = "timer1",
126 .start = 0x0050,
127 .end = 0x0053,
128 .flags = IORESOURCE_BUSY | IORESOURCE_IO
129}, {
130 .name = "keyboard",
131 .start = 0x0060,
9096bd7a
HW
132 .end = 0x0060,
133 .flags = IORESOURCE_BUSY | IORESOURCE_IO
134}, {
135 .name = "keyboard",
136 .start = 0x0064,
137 .end = 0x0064,
c9cce83d
BW
138 .flags = IORESOURCE_BUSY | IORESOURCE_IO
139}, {
140 .name = "dma page reg",
141 .start = 0x0080,
142 .end = 0x008f,
143 .flags = IORESOURCE_BUSY | IORESOURCE_IO
144}, {
145 .name = "pic2",
146 .start = 0x00a0,
147 .end = 0x00a1,
148 .flags = IORESOURCE_BUSY | IORESOURCE_IO
149}, {
150 .name = "dma2",
151 .start = 0x00c0,
152 .end = 0x00df,
153 .flags = IORESOURCE_BUSY | IORESOURCE_IO
154}, {
155 .name = "fpu",
156 .start = 0x00f0,
157 .end = 0x00ff,
158 .flags = IORESOURCE_BUSY | IORESOURCE_IO
159} };
1da177e4
LT
160
161/* cpu data as detected by the assembly code in head.S */
4a5d107a 162struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
1da177e4 163/* common cpu data for all cpus */
c3d8c141 164struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
129f6946 165EXPORT_SYMBOL(boot_cpu_data);
1da177e4 166
0c254e38
AS
167unsigned int def_to_bigsmp;
168
551889a6 169#ifndef CONFIG_X86_PAE
1da177e4 170unsigned long mmu_cr4_features;
551889a6
IC
171#else
172unsigned long mmu_cr4_features = X86_CR4_PAE;
173#endif
1da177e4 174
1da177e4
LT
175/* for MCA, but anyone else can use it if they want */
176unsigned int machine_id;
177unsigned int machine_submodel_id;
178unsigned int BIOS_revision;
1da177e4 179
1da177e4
LT
180/* Boot loader ID as an integer, for the benefit of proc_dointvec */
181int bootloader_type;
182
183/* user-defined highmem size */
184static unsigned int highmem_pages = -1;
185
186/*
187 * Setup options
188 */
1da177e4 189struct screen_info screen_info;
129f6946 190EXPORT_SYMBOL(screen_info);
1da177e4 191struct apm_info apm_info;
129f6946 192EXPORT_SYMBOL(apm_info);
1da177e4 193struct edid_info edid_info;
5e518d76 194EXPORT_SYMBOL_GPL(edid_info);
1da177e4 195struct ist_info ist_info;
129f6946
AD
196#if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
197 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
198EXPORT_SYMBOL(ist_info);
199#endif
1da177e4
LT
200
201extern void early_cpu_init(void);
1da177e4
LT
202extern int root_mountflags;
203
e44b7b75 204unsigned long saved_video_mode;
1da177e4 205
cf8fa920 206#define RAMDISK_IMAGE_START_MASK 0x07FF
1da177e4 207#define RAMDISK_PROMPT_FLAG 0x8000
cf8fa920 208#define RAMDISK_LOAD_FLAG 0x4000
1da177e4 209
4e498b66 210static char __initdata command_line[COMMAND_LINE_SIZE];
1da177e4 211
6d7d7433 212#ifndef CONFIG_DEBUG_BOOT_PARAMS
48c7ae67 213struct boot_params __initdata boot_params;
6d7d7433
HY
214#else
215struct boot_params boot_params;
216#endif
1da177e4 217
1da177e4
LT
218#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
219struct edd edd;
220#ifdef CONFIG_EDD_MODULE
221EXPORT_SYMBOL(edd);
222#endif
223/**
224 * copy_edd() - Copy the BIOS EDD information
225 * from boot_params into a safe place.
226 *
227 */
228static inline void copy_edd(void)
229{
30c82645
PA
230 memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
231 sizeof(edd.mbr_signature));
232 memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
233 edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
234 edd.edd_info_nr = boot_params.eddbuf_entries;
1da177e4
LT
235}
236#else
237static inline void copy_edd(void)
238{
239}
240#endif
241
1a3f239d
RR
242#ifdef CONFIG_PROC_VMCORE
243/* elfcorehdr= specifies the location of elf core header
244 * stored by the crashed kernel.
245 */
246static int __init parse_elfcorehdr(char *arg)
247{
248 if (!arg)
249 return -EINVAL;
66759a01 250
1a3f239d
RR
251 elfcorehdr_addr = memparse(arg, &arg);
252 return 0;
253}
254early_param("elfcorehdr", parse_elfcorehdr);
255#endif /* CONFIG_PROC_VMCORE */
1da177e4 256
1a3f239d
RR
257/*
258 * highmem=size forces highmem to be exactly 'size' bytes.
259 * This works even on boxes that have no highmem otherwise.
260 * This also works to reduce highmem size on bigger boxes.
261 */
262static int __init parse_highmem(char *arg)
263{
264 if (!arg)
265 return -EINVAL;
9635b47d 266
1a3f239d
RR
267 highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
268 return 0;
269}
270early_param("highmem", parse_highmem);
9635b47d 271
1a3f239d
RR
272/*
273 * vmalloc=size forces the vmalloc area to be exactly 'size'
274 * bytes. This can be used to increase (or decrease) the
275 * vmalloc area - the default is 128m.
276 */
277static int __init parse_vmalloc(char *arg)
278{
279 if (!arg)
280 return -EINVAL;
1bc3b91a 281
1a3f239d
RR
282 __VMALLOC_RESERVE = memparse(arg, &arg);
283 return 0;
1da177e4 284}
1a3f239d 285early_param("vmalloc", parse_vmalloc);
1da177e4 286
461a9aff
ZA
287/*
288 * reservetop=size reserves a hole at the top of the kernel address space which
289 * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
290 * so relocating the fixmap can be done before paging initialization.
291 */
292static int __init parse_reservetop(char *arg)
293{
294 unsigned long address;
295
296 if (!arg)
297 return -EINVAL;
298
299 address = memparse(arg, &arg);
300 reserve_top_address(address);
301 return 0;
302}
303early_param("reservetop", parse_reservetop);
304
1da177e4
LT
305/*
306 * Determine low and high memory ranges:
307 */
308unsigned long __init find_max_low_pfn(void)
309{
310 unsigned long max_low_pfn;
311
312 max_low_pfn = max_pfn;
313 if (max_low_pfn > MAXMEM_PFN) {
314 if (highmem_pages == -1)
315 highmem_pages = max_pfn - MAXMEM_PFN;
316 if (highmem_pages + MAXMEM_PFN < max_pfn)
317 max_pfn = MAXMEM_PFN + highmem_pages;
318 if (highmem_pages + MAXMEM_PFN > max_pfn) {
319 printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
320 highmem_pages = 0;
321 }
322 max_low_pfn = MAXMEM_PFN;
323#ifndef CONFIG_HIGHMEM
324 /* Maximum memory usable is what is directly addressable */
325 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
326 MAXMEM>>20);
327 if (max_pfn > MAX_NONPAE_PFN)
c673f1a9 328 printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
1da177e4
LT
329 else
330 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
331 max_pfn = MAXMEM_PFN;
332#else /* !CONFIG_HIGHMEM */
c673f1a9 333#ifndef CONFIG_HIGHMEM64G
1da177e4
LT
334 if (max_pfn > MAX_NONPAE_PFN) {
335 max_pfn = MAX_NONPAE_PFN;
336 printk(KERN_WARNING "Warning only 4GB will be used.\n");
c673f1a9 337 printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
1da177e4 338 }
c673f1a9 339#endif /* !CONFIG_HIGHMEM64G */
1da177e4
LT
340#endif /* !CONFIG_HIGHMEM */
341 } else {
342 if (highmem_pages == -1)
343 highmem_pages = 0;
344#ifdef CONFIG_HIGHMEM
345 if (highmem_pages >= max_pfn) {
346 printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
347 highmem_pages = 0;
348 }
349 if (highmem_pages) {
350 if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
351 printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
352 highmem_pages = 0;
353 }
354 max_low_pfn -= highmem_pages;
355 }
356#else
357 if (highmem_pages)
358 printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
359#endif
360 }
361 return max_low_pfn;
362}
363
05b79bdc 364#ifndef CONFIG_NEED_MULTIPLE_NODES
a4928cff 365static void __init setup_bootmem_allocator(void);
1da177e4
LT
366static unsigned long __init setup_memory(void)
367{
368 /*
369 * partially used pages are not usable - thus
370 * we are rounding upwards:
371 */
372 min_low_pfn = PFN_UP(init_pg_tables_end);
373
1da177e4
LT
374 max_low_pfn = find_max_low_pfn();
375
376#ifdef CONFIG_HIGHMEM
377 highstart_pfn = highend_pfn = max_pfn;
378 if (max_pfn > max_low_pfn) {
379 highstart_pfn = max_low_pfn;
380 }
f19dc2f2 381 memory_present(0, 0, highend_pfn);
1da177e4
LT
382 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
383 pages_to_mb(highend_pfn - highstart_pfn));
ba9c231f
JB
384 num_physpages = highend_pfn;
385 high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
386#else
f19dc2f2 387 memory_present(0, 0, max_low_pfn);
ba9c231f
JB
388 num_physpages = max_low_pfn;
389 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
390#endif
391#ifdef CONFIG_FLATMEM
392 max_mapnr = num_physpages;
1da177e4
LT
393#endif
394 printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
395 pages_to_mb(max_low_pfn));
396
397 setup_bootmem_allocator();
398
399 return max_low_pfn;
400}
401
a4928cff 402static void __init zone_sizes_init(void)
1da177e4 403{
6391af17
MG
404 unsigned long max_zone_pfns[MAX_NR_ZONES];
405 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
406 max_zone_pfns[ZONE_DMA] =
407 virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
408 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
7b2a0a6c 409 remove_all_active_ranges();
1da177e4 410#ifdef CONFIG_HIGHMEM
6391af17 411 max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
7b2a0a6c 412 e820_register_active_regions(0, 0, highend_pfn);
4cfee88a 413#else
7b2a0a6c 414 e820_register_active_regions(0, 0, max_low_pfn);
1da177e4 415#endif
4cfee88a
MG
416
417 free_area_init_nodes(max_zone_pfns);
1da177e4
LT
418}
419#else
05b79bdc 420extern unsigned long __init setup_memory(void);
1da177e4 421extern void zone_sizes_init(void);
05b79bdc 422#endif /* !CONFIG_NEED_MULTIPLE_NODES */
1da177e4 423
d62cc471
BW
424static inline unsigned long long get_total_mem(void)
425{
426 unsigned long long total;
427
428 total = max_low_pfn - min_low_pfn;
429#ifdef CONFIG_HIGHMEM
430 total += highend_pfn - highstart_pfn;
431#endif
432
433 return total << PAGE_SHIFT;
434}
435
436#ifdef CONFIG_KEXEC
437static void __init reserve_crashkernel(void)
438{
439 unsigned long long total_mem;
440 unsigned long long crash_size, crash_base;
441 int ret;
442
443 total_mem = get_total_mem();
444
445 ret = parse_crashkernel(boot_command_line, total_mem,
446 &crash_size, &crash_base);
447 if (ret == 0 && crash_size > 0) {
448 if (crash_base > 0) {
449 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
450 "for crashkernel (System RAM: %ldMB)\n",
451 (unsigned long)(crash_size >> 20),
452 (unsigned long)(crash_base >> 20),
453 (unsigned long)(total_mem >> 20));
d3942cff
BW
454
455 if (reserve_bootmem(crash_base, crash_size,
456 BOOTMEM_EXCLUSIVE) < 0) {
457 printk(KERN_INFO "crashkernel reservation "
458 "failed - memory is in use\n");
459 return;
460 }
461
d62cc471
BW
462 crashk_res.start = crash_base;
463 crashk_res.end = crash_base + crash_size - 1;
d62cc471
BW
464 } else
465 printk(KERN_INFO "crashkernel reservation failed - "
466 "you have to specify a base address\n");
467 }
468}
469#else
470static inline void __init reserve_crashkernel(void)
471{}
472#endif
473
cf8fa920
PA
474#ifdef CONFIG_BLK_DEV_INITRD
475
476static bool do_relocate_initrd = false;
477
478static void __init reserve_initrd(void)
479{
ba5b14cc
YL
480 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
481 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
482 u64 ramdisk_end = ramdisk_image + ramdisk_size;
483 u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
484 u64 ramdisk_here;
cf8fa920 485
cf8fa920
PA
486 if (!boot_params.hdr.type_of_loader ||
487 !ramdisk_image || !ramdisk_size)
488 return; /* No initrd provided by bootloader */
489
a4c81cf6
YL
490 initrd_start = 0;
491
cf8fa920 492 if (ramdisk_size >= end_of_lowmem/2) {
3945e2c9 493 free_early(ramdisk_image, ramdisk_end);
cf8fa920
PA
494 printk(KERN_ERR "initrd too large to handle, "
495 "disabling initrd\n");
496 return;
497 }
a4c81cf6 498
f0d43100
YL
499 printk(KERN_INFO "old RAMDISK: %08llx - %08llx\n", ramdisk_image,
500 ramdisk_end);
501
502
cf8fa920
PA
503 if (ramdisk_end <= end_of_lowmem) {
504 /* All in lowmem, easy case */
a4c81cf6
YL
505 /*
506 * don't need to reserve again, already reserved early
ba5b14cc 507 * in i386_start_kernel
a4c81cf6 508 */
cf8fa920
PA
509 initrd_start = ramdisk_image + PAGE_OFFSET;
510 initrd_end = initrd_start+ramdisk_size;
511 return;
512 }
513
514 /* We need to move the initrd down into lowmem */
ba5b14cc
YL
515 ramdisk_here = find_e820_area(min_low_pfn<<PAGE_SHIFT,
516 end_of_lowmem, ramdisk_size,
517 PAGE_SIZE);
cf8fa920 518
3945e2c9
YL
519 if (ramdisk_here == -1ULL)
520 panic("Cannot find place for new RAMDISK of size %lld\n",
521 ramdisk_size);
522
cf8fa920
PA
523 /* Note: this includes all the lowmem currently occupied by
524 the initrd, we rely on that fact to keep the data intact. */
3945e2c9 525 reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
ba5b14cc 526 "NEW RAMDISK");
cf8fa920
PA
527 initrd_start = ramdisk_here + PAGE_OFFSET;
528 initrd_end = initrd_start + ramdisk_size;
f0d43100
YL
529 printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
530 ramdisk_here, ramdisk_here + ramdisk_size);
cf8fa920
PA
531
532 do_relocate_initrd = true;
533}
534
535#define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
536
537static void __init relocate_initrd(void)
538{
ba5b14cc
YL
539 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
540 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
541 u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
542 u64 ramdisk_here;
cf8fa920
PA
543 unsigned long slop, clen, mapaddr;
544 char *p, *q;
545
546 if (!do_relocate_initrd)
547 return;
548
549 ramdisk_here = initrd_start - PAGE_OFFSET;
550
551 q = (char *)initrd_start;
552
553 /* Copy any lowmem portion of the initrd */
554 if (ramdisk_image < end_of_lowmem) {
555 clen = end_of_lowmem - ramdisk_image;
556 p = (char *)__va(ramdisk_image);
557 memcpy(q, p, clen);
558 q += clen;
a4c81cf6 559 /* need to free these low pages...*/
ba5b14cc
YL
560 printk(KERN_INFO "Freeing old partial RAMDISK %08llx-%08llx\n",
561 ramdisk_image, ramdisk_image + clen - 1);
a4c81cf6 562 free_bootmem(ramdisk_image, clen);
cf8fa920
PA
563 ramdisk_image += clen;
564 ramdisk_size -= clen;
565 }
566
567 /* Copy the highmem portion of the initrd */
568 while (ramdisk_size) {
569 slop = ramdisk_image & ~PAGE_MASK;
570 clen = ramdisk_size;
571 if (clen > MAX_MAP_CHUNK-slop)
572 clen = MAX_MAP_CHUNK-slop;
573 mapaddr = ramdisk_image & PAGE_MASK;
beacfaac 574 p = early_ioremap(mapaddr, clen+slop);
cf8fa920 575 memcpy(q, p+slop, clen);
beacfaac 576 early_iounmap(p, clen+slop);
cf8fa920
PA
577 q += clen;
578 ramdisk_image += clen;
579 ramdisk_size -= clen;
580 }
a4c81cf6 581 /* high pages is not converted by early_res_to_bootmem */
ba5b14cc
YL
582 ramdisk_image = boot_params.hdr.ramdisk_image;
583 ramdisk_size = boot_params.hdr.ramdisk_size;
584 printk(KERN_INFO "Copied RAMDISK from %016llx - %016llx to %08llx - %08llx\n",
585 ramdisk_image, ramdisk_image + ramdisk_size - 1,
586 ramdisk_here, ramdisk_here + ramdisk_size - 1);
9a27f5c5
YL
587
588 /* need to free that, otherwise init highmem will reserve it again */
589 free_early(ramdisk_image, ramdisk_image+ramdisk_size);
cf8fa920
PA
590}
591
592#endif /* CONFIG_BLK_DEV_INITRD */
593
1da177e4
LT
594void __init setup_bootmem_allocator(void)
595{
7b2a0a6c 596 int i;
a4c81cf6 597 unsigned long bootmap_size, bootmap;
1da177e4
LT
598 /*
599 * Initialize the boot-time allocator (with low memory only):
600 */
a4c81cf6
YL
601 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
602 bootmap = find_e820_area(min_low_pfn<<PAGE_SHIFT,
6af61a76 603 max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
a4c81cf6
YL
604 PAGE_SIZE);
605 if (bootmap == -1L)
606 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
3945e2c9 607 reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
ba5b14cc
YL
608#ifdef CONFIG_BLK_DEV_INITRD
609 reserve_initrd();
610#endif
a4c81cf6 611 bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, max_low_pfn);
6af61a76
YL
612 printk(KERN_INFO " mapped low ram: 0 - %08lx\n",
613 max_pfn_mapped<<PAGE_SHIFT);
ba5b14cc
YL
614 printk(KERN_INFO " low ram: %08lx - %08lx\n",
615 min_low_pfn<<PAGE_SHIFT, max_low_pfn<<PAGE_SHIFT);
3945e2c9
YL
616 printk(KERN_INFO " bootmap %08lx - %08lx\n",
617 bootmap, bootmap + bootmap_size);
7b2a0a6c
YL
618 for_each_online_node(i)
619 free_bootmem_with_active_regions(i, max_low_pfn);
a4c81cf6 620 early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
1da177e4 621
673d5b43 622#ifdef CONFIG_ACPI_SLEEP
1da177e4
LT
623 /*
624 * Reserve low memory region for sleep support.
625 */
626 acpi_reserve_bootmem();
627#endif
628#ifdef CONFIG_X86_FIND_SMP_CONFIG
629 /*
630 * Find and reserve possible boot-time SMP configuration:
631 */
632 find_smp_config();
1da177e4 633#endif
d62cc471 634 reserve_crashkernel();
138fe4e0
KR
635
636 reserve_ibft_region();
1da177e4
LT
637}
638
639/*
640 * The node 0 pgdat is initialized before all of these because
641 * it's needed for bootmem. node>0 pgdats have their virtual
642 * space allocated before the pagetables are in place to access
643 * them, so they can't be cleared then.
644 *
645 * This should all compile down to nothing when NUMA is off.
646 */
10079ae3 647static void __init remapped_pgdat_init(void)
1da177e4
LT
648{
649 int nid;
650
651 for_each_online_node(nid) {
652 if (nid != 0)
653 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
654 }
655}
656
1da177e4
LT
657#ifdef CONFIG_MCA
658static void set_mca_bus(int x)
659{
660 MCA_bus = x;
661}
662#else
663static void set_mca_bus(int x) { }
664#endif
665
ccf82085
GOC
666#ifdef CONFIG_NUMA
667/*
668 * In the golden day, when everything among i386 and x86_64 will be
669 * integrated, this will not live here
670 */
671void *x86_cpu_to_node_map_early_ptr;
672int x86_cpu_to_node_map_init[NR_CPUS] = {
673 [0 ... NR_CPUS-1] = NUMA_NO_NODE
674};
675DEFINE_PER_CPU(int, x86_cpu_to_node_map) = NUMA_NO_NODE;
676#endif
677
1da177e4
LT
678/*
679 * Determine if we were loaded by an EFI loader. If so, then we have also been
680 * passed the efi memmap, systab, etc., so we should use these data structures
681 * for initialization. Note, the efi init code path is determined by the
682 * global efi_enabled. This allows the same kernel image to be used on existing
683 * systems (with a traditional BIOS) as well as on EFI systems.
684 */
685void __init setup_arch(char **cmdline_p)
686{
687 unsigned long max_low_pfn;
688
689 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
690 pre_setup_arch_hook();
691 early_cpu_init();
beacfaac 692 early_ioremap_init();
c45a707d 693 reserve_setup_data();
1da177e4 694
1da177e4 695#ifdef CONFIG_EFI
e429795c 696 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
ecacf09f 697 "EL32", 4)) {
1da177e4 698 efi_enabled = 1;
ecacf09f
HY
699 efi_reserve_early();
700 }
1da177e4
LT
701#endif
702
30c82645
PA
703 ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
704 screen_info = boot_params.screen_info;
705 edid_info = boot_params.edid_info;
706 apm_info.bios = boot_params.apm_bios_info;
707 ist_info = boot_params.ist_info;
e44b7b75 708 saved_video_mode = boot_params.hdr.vid_mode;
30c82645
PA
709 if( boot_params.sys_desc_table.length != 0 ) {
710 set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
711 machine_id = boot_params.sys_desc_table.table[0];
712 machine_submodel_id = boot_params.sys_desc_table.table[1];
713 BIOS_revision = boot_params.sys_desc_table.table[2];
1da177e4 714 }
30c82645 715 bootloader_type = boot_params.hdr.type_of_loader;
1da177e4
LT
716
717#ifdef CONFIG_BLK_DEV_RAM
30c82645
PA
718 rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
719 rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
720 rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
1da177e4
LT
721#endif
722 ARCH_SETUP
2215e69d 723
0dbfafa5 724 setup_memory_map();
2215e69d 725
1da177e4
LT
726 copy_edd();
727
30c82645 728 if (!boot_params.hdr.root_flags)
1da177e4
LT
729 root_mountflags &= ~MS_RDONLY;
730 init_mm.start_code = (unsigned long) _text;
731 init_mm.end_code = (unsigned long) _etext;
732 init_mm.end_data = (unsigned long) _edata;
733 init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
734
735 code_resource.start = virt_to_phys(_text);
736 code_resource.end = virt_to_phys(_etext)-1;
737 data_resource.start = virt_to_phys(_etext);
738 data_resource.end = virt_to_phys(_edata)-1;
00bf4098
BW
739 bss_resource.start = virt_to_phys(&__bss_start);
740 bss_resource.end = virt_to_phys(&__bss_stop)-1;
1da177e4 741
c45a707d
HY
742 parse_setup_data();
743
1a3f239d 744 parse_early_param();
1da177e4 745
0dbfafa5 746 finish_e820_parsing();
1a3f239d 747
4e498b66 748 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
1a3f239d 749 *cmdline_p = command_line;
99b7de33 750
8b2cb7a8
HY
751 if (efi_enabled)
752 efi_init();
753
7b2a0a6c
YL
754 e820_register_active_regions(0, 0, -1UL);
755 /*
756 * partially used pages are not usable - thus
757 * we are rounding upwards:
758 */
759 max_pfn = e820_end_of_ram();
760
6780711e
YL
761 /* preallocate 4k for mptable mpc */
762 early_reserve_e820_mpc_new();
093af8d7
YL
763 /* update e820 for memory not covered by WB MTRRs */
764 mtrr_bp_init();
7b2a0a6c
YL
765 if (mtrr_trim_uncached_memory(max_pfn)) {
766 remove_all_active_ranges();
767 e820_register_active_regions(0, 0, -1UL);
768 max_pfn = e820_end_of_ram();
769 }
76c32418
YL
770
771 max_low_pfn = setup_memory();
093af8d7 772
790c73f6
GOC
773#ifdef CONFIG_KVM_CLOCK
774 kvmclock_init();
775#endif
776
7ce0bcfd
ZA
777#ifdef CONFIG_VMI
778 /*
779 * Must be after max_low_pfn is determined, and before kernel
780 * pagetables are setup.
781 */
782 vmi_init();
783#endif
0cf1bfd2 784 kvm_guest_init();
7ce0bcfd 785
1da177e4
LT
786 /*
787 * NOTE: before this point _nobody_ is allowed to allocate
788 * any memory using the bootmem allocator. Although the
27b46d76 789 * allocator is now initialised only the first 8Mb of the kernel
1da177e4
LT
790 * virtual address space has been mapped. All allocations before
791 * paging_init() has completed must use the alloc_bootmem_low_pages()
792 * variant (which allocates DMA'able memory) and care must be taken
793 * not to exceed the 8Mb limit.
794 */
795
1da177e4 796 paging_init();
f212ec4b
BK
797
798 /*
799 * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
800 */
801
802#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
803 if (init_ohci1394_dma_early)
804 init_ohci1394_dma_on_all_controllers();
805#endif
806
1da177e4
LT
807 /*
808 * NOTE: at this point the bootmem allocator is fully available.
809 */
810
cf8fa920
PA
811#ifdef CONFIG_BLK_DEV_INITRD
812 relocate_initrd();
813#endif
814
9a27f5c5
YL
815 remapped_pgdat_init();
816 sparse_init();
817 zone_sizes_init();
818
6996d3b6
JF
819 paravirt_post_allocator_init();
820
1da177e4
LT
821 dmi_scan_machine();
822
cf8fa920 823 io_delay_init();
b02aae9c 824
ccf82085
GOC
825#ifdef CONFIG_X86_SMP
826 /*
827 * setup to use the early static init tables during kernel startup
828 * X86_SMP will exclude sub-arches that don't deal well with it.
829 */
830 x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
831 x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
832#ifdef CONFIG_NUMA
833 x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
834#endif
835#endif
836
1da177e4 837#ifdef CONFIG_X86_GENERICARCH
1a3f239d 838 generic_apic_probe();
cf8fa920 839#endif
1da177e4 840
888ba6c6 841#ifdef CONFIG_ACPI
1da177e4
LT
842 /*
843 * Parse the ACPI tables for possible boot-time SMP configuration.
844 */
845 acpi_boot_table_init();
d44647b0
AC
846#endif
847
54ef3400 848 early_quirks();
d44647b0
AC
849
850#ifdef CONFIG_ACPI
1da177e4 851 acpi_boot_init();
e0da3364
YL
852#endif
853#if defined(CONFIG_X86_MPPARSE) || defined(CONFIG_X86_VISWS)
854 if (smp_found_config)
855 get_smp_config();
856#endif
911a62d4
VP
857#if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
858 if (def_to_bigsmp)
859 printk(KERN_WARNING "More than 8 CPUs detected and "
860 "CONFIG_X86_PC cannot handle it.\nUse "
861 "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
862#endif
1da177e4 863
b79cd8f1 864 e820_setup_gap();
bf62f398 865 e820_mark_nosave_regions(max_low_pfn);
1da177e4
LT
866
867#ifdef CONFIG_VT
868#if defined(CONFIG_VGA_CONSOLE)
869 if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
870 conswitchp = &vga_con;
871#elif defined(CONFIG_DUMMY_CONSOLE)
872 conswitchp = &dummy_con;
873#endif
874#endif
875}
c9cce83d
BW
876
877/*
878 * Request address space for all standard resources
879 *
880 * This is called just before pcibios_init(), which is also a
881 * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
882 */
883static int __init request_standard_resources(void)
884{
885 int i;
886
887 printk(KERN_INFO "Setting up standard PCI resources\n");
2215e69d 888 init_iomem_resources(&code_resource, &data_resource, &bss_resource);
c9cce83d 889
c9cce83d
BW
890 request_resource(&iomem_resource, &video_ram_resource);
891
892 /* request I/O space for devices used on all i[345]86 PCs */
893 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
894 request_resource(&ioport_resource, &standard_io_resources[i]);
895 return 0;
896}
897
898subsys_initcall(request_standard_resources);