ARM: 7709/1: mcpm: Add explicit AFLAGS to support v6/v7 multiplatform kernels
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / x86 / kernel / setup.c
1 /*
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>
26 #include <linux/mmzone.h>
27 #include <linux/screen_info.h>
28 #include <linux/ioport.h>
29 #include <linux/acpi.h>
30 #include <linux/sfi.h>
31 #include <linux/apm_bios.h>
32 #include <linux/initrd.h>
33 #include <linux/bootmem.h>
34 #include <linux/memblock.h>
35 #include <linux/seq_file.h>
36 #include <linux/console.h>
37 #include <linux/root_dev.h>
38 #include <linux/highmem.h>
39 #include <linux/module.h>
40 #include <linux/efi.h>
41 #include <linux/init.h>
42 #include <linux/edd.h>
43 #include <linux/iscsi_ibft.h>
44 #include <linux/nodemask.h>
45 #include <linux/kexec.h>
46 #include <linux/dmi.h>
47 #include <linux/pfn.h>
48 #include <linux/pci.h>
49 #include <asm/pci-direct.h>
50 #include <linux/init_ohci1394_dma.h>
51 #include <linux/kvm_para.h>
52 #include <linux/dma-contiguous.h>
53
54 #include <linux/errno.h>
55 #include <linux/kernel.h>
56 #include <linux/stddef.h>
57 #include <linux/unistd.h>
58 #include <linux/ptrace.h>
59 #include <linux/user.h>
60 #include <linux/delay.h>
61
62 #include <linux/kallsyms.h>
63 #include <linux/cpufreq.h>
64 #include <linux/dma-mapping.h>
65 #include <linux/ctype.h>
66 #include <linux/uaccess.h>
67
68 #include <linux/percpu.h>
69 #include <linux/crash_dump.h>
70 #include <linux/tboot.h>
71 #include <linux/jiffies.h>
72
73 #include <video/edid.h>
74
75 #include <asm/mtrr.h>
76 #include <asm/apic.h>
77 #include <asm/realmode.h>
78 #include <asm/e820.h>
79 #include <asm/mpspec.h>
80 #include <asm/setup.h>
81 #include <asm/efi.h>
82 #include <asm/timer.h>
83 #include <asm/i8259.h>
84 #include <asm/sections.h>
85 #include <asm/dmi.h>
86 #include <asm/io_apic.h>
87 #include <asm/ist.h>
88 #include <asm/setup_arch.h>
89 #include <asm/bios_ebda.h>
90 #include <asm/cacheflush.h>
91 #include <asm/processor.h>
92 #include <asm/bugs.h>
93
94 #include <asm/vsyscall.h>
95 #include <asm/cpu.h>
96 #include <asm/desc.h>
97 #include <asm/dma.h>
98 #include <asm/iommu.h>
99 #include <asm/gart.h>
100 #include <asm/mmu_context.h>
101 #include <asm/proto.h>
102
103 #include <asm/paravirt.h>
104 #include <asm/hypervisor.h>
105 #include <asm/olpc_ofw.h>
106
107 #include <asm/percpu.h>
108 #include <asm/topology.h>
109 #include <asm/apicdef.h>
110 #include <asm/amd_nb.h>
111 #include <asm/mce.h>
112 #include <asm/alternative.h>
113 #include <asm/prom.h>
114
115 /*
116 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
117 * max_pfn_mapped: highest direct mapped pfn over 4GB
118 *
119 * The direct mapping only covers E820_RAM regions, so the ranges and gaps are
120 * represented by pfn_mapped
121 */
122 unsigned long max_low_pfn_mapped;
123 unsigned long max_pfn_mapped;
124
125 #ifdef CONFIG_DMI
126 RESERVE_BRK(dmi_alloc, 65536);
127 #endif
128
129
130 static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
131 unsigned long _brk_end = (unsigned long)__brk_base;
132
133 #ifdef CONFIG_X86_64
134 int default_cpu_present_to_apicid(int mps_cpu)
135 {
136 return __default_cpu_present_to_apicid(mps_cpu);
137 }
138
139 int default_check_phys_apicid_present(int phys_apicid)
140 {
141 return __default_check_phys_apicid_present(phys_apicid);
142 }
143 #endif
144
145 struct boot_params boot_params;
146
147 /*
148 * Machine setup..
149 */
150 static struct resource data_resource = {
151 .name = "Kernel data",
152 .start = 0,
153 .end = 0,
154 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
155 };
156
157 static struct resource code_resource = {
158 .name = "Kernel code",
159 .start = 0,
160 .end = 0,
161 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
162 };
163
164 static struct resource bss_resource = {
165 .name = "Kernel bss",
166 .start = 0,
167 .end = 0,
168 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
169 };
170
171
172 #ifdef CONFIG_X86_32
173 /* cpu data as detected by the assembly code in head.S */
174 struct cpuinfo_x86 new_cpu_data __cpuinitdata = {
175 .wp_works_ok = -1,
176 .fdiv_bug = -1,
177 };
178 /* common cpu data for all cpus */
179 struct cpuinfo_x86 boot_cpu_data __read_mostly = {
180 .wp_works_ok = -1,
181 .fdiv_bug = -1,
182 };
183 EXPORT_SYMBOL(boot_cpu_data);
184
185 unsigned int def_to_bigsmp;
186
187 /* for MCA, but anyone else can use it if they want */
188 unsigned int machine_id;
189 unsigned int machine_submodel_id;
190 unsigned int BIOS_revision;
191
192 struct apm_info apm_info;
193 EXPORT_SYMBOL(apm_info);
194
195 #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
196 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
197 struct ist_info ist_info;
198 EXPORT_SYMBOL(ist_info);
199 #else
200 struct ist_info ist_info;
201 #endif
202
203 #else
204 struct cpuinfo_x86 boot_cpu_data __read_mostly = {
205 .x86_phys_bits = MAX_PHYSMEM_BITS,
206 };
207 EXPORT_SYMBOL(boot_cpu_data);
208 #endif
209
210
211 #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
212 unsigned long mmu_cr4_features;
213 #else
214 unsigned long mmu_cr4_features = X86_CR4_PAE;
215 #endif
216
217 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
218 int bootloader_type, bootloader_version;
219
220 /*
221 * Setup options
222 */
223 struct screen_info screen_info;
224 EXPORT_SYMBOL(screen_info);
225 struct edid_info edid_info;
226 EXPORT_SYMBOL_GPL(edid_info);
227
228 extern int root_mountflags;
229
230 unsigned long saved_video_mode;
231
232 #define RAMDISK_IMAGE_START_MASK 0x07FF
233 #define RAMDISK_PROMPT_FLAG 0x8000
234 #define RAMDISK_LOAD_FLAG 0x4000
235
236 static char __initdata command_line[COMMAND_LINE_SIZE];
237 #ifdef CONFIG_CMDLINE_BOOL
238 static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
239 #endif
240
241 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
242 struct edd edd;
243 #ifdef CONFIG_EDD_MODULE
244 EXPORT_SYMBOL(edd);
245 #endif
246 /**
247 * copy_edd() - Copy the BIOS EDD information
248 * from boot_params into a safe place.
249 *
250 */
251 static inline void __init copy_edd(void)
252 {
253 memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
254 sizeof(edd.mbr_signature));
255 memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
256 edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
257 edd.edd_info_nr = boot_params.eddbuf_entries;
258 }
259 #else
260 static inline void __init copy_edd(void)
261 {
262 }
263 #endif
264
265 void * __init extend_brk(size_t size, size_t align)
266 {
267 size_t mask = align - 1;
268 void *ret;
269
270 BUG_ON(_brk_start == 0);
271 BUG_ON(align & mask);
272
273 _brk_end = (_brk_end + mask) & ~mask;
274 BUG_ON((char *)(_brk_end + size) > __brk_limit);
275
276 ret = (void *)_brk_end;
277 _brk_end += size;
278
279 memset(ret, 0, size);
280
281 return ret;
282 }
283
284 #ifdef CONFIG_X86_32
285 static void __init cleanup_highmap(void)
286 {
287 }
288 #endif
289
290 static void __init reserve_brk(void)
291 {
292 if (_brk_end > _brk_start)
293 memblock_reserve(__pa_symbol(_brk_start),
294 _brk_end - _brk_start);
295
296 /* Mark brk area as locked down and no longer taking any
297 new allocations */
298 _brk_start = 0;
299 }
300
301 #ifdef CONFIG_BLK_DEV_INITRD
302
303 static u64 __init get_ramdisk_image(void)
304 {
305 u64 ramdisk_image = boot_params.hdr.ramdisk_image;
306
307 ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
308
309 return ramdisk_image;
310 }
311 static u64 __init get_ramdisk_size(void)
312 {
313 u64 ramdisk_size = boot_params.hdr.ramdisk_size;
314
315 ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
316
317 return ramdisk_size;
318 }
319
320 #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
321 static void __init relocate_initrd(void)
322 {
323 /* Assume only end is not page aligned */
324 u64 ramdisk_image = get_ramdisk_image();
325 u64 ramdisk_size = get_ramdisk_size();
326 u64 area_size = PAGE_ALIGN(ramdisk_size);
327 u64 ramdisk_here;
328 unsigned long slop, clen, mapaddr;
329 char *p, *q;
330
331 /* We need to move the initrd down into directly mapped mem */
332 ramdisk_here = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
333 area_size, PAGE_SIZE);
334
335 if (!ramdisk_here)
336 panic("Cannot find place for new RAMDISK of size %lld\n",
337 ramdisk_size);
338
339 /* Note: this includes all the mem currently occupied by
340 the initrd, we rely on that fact to keep the data intact. */
341 memblock_reserve(ramdisk_here, area_size);
342 initrd_start = ramdisk_here + PAGE_OFFSET;
343 initrd_end = initrd_start + ramdisk_size;
344 printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
345 ramdisk_here, ramdisk_here + ramdisk_size - 1);
346
347 q = (char *)initrd_start;
348
349 /* Copy the initrd */
350 while (ramdisk_size) {
351 slop = ramdisk_image & ~PAGE_MASK;
352 clen = ramdisk_size;
353 if (clen > MAX_MAP_CHUNK-slop)
354 clen = MAX_MAP_CHUNK-slop;
355 mapaddr = ramdisk_image & PAGE_MASK;
356 p = early_memremap(mapaddr, clen+slop);
357 memcpy(q, p+slop, clen);
358 early_iounmap(p, clen+slop);
359 q += clen;
360 ramdisk_image += clen;
361 ramdisk_size -= clen;
362 }
363
364 ramdisk_image = get_ramdisk_image();
365 ramdisk_size = get_ramdisk_size();
366 printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
367 " [mem %#010llx-%#010llx]\n",
368 ramdisk_image, ramdisk_image + ramdisk_size - 1,
369 ramdisk_here, ramdisk_here + ramdisk_size - 1);
370 }
371
372 static void __init early_reserve_initrd(void)
373 {
374 /* Assume only end is not page aligned */
375 u64 ramdisk_image = get_ramdisk_image();
376 u64 ramdisk_size = get_ramdisk_size();
377 u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
378
379 if (!boot_params.hdr.type_of_loader ||
380 !ramdisk_image || !ramdisk_size)
381 return; /* No initrd provided by bootloader */
382
383 memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
384 }
385 static void __init reserve_initrd(void)
386 {
387 /* Assume only end is not page aligned */
388 u64 ramdisk_image = get_ramdisk_image();
389 u64 ramdisk_size = get_ramdisk_size();
390 u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
391 u64 mapped_size;
392
393 if (!boot_params.hdr.type_of_loader ||
394 !ramdisk_image || !ramdisk_size)
395 return; /* No initrd provided by bootloader */
396
397 initrd_start = 0;
398
399 mapped_size = memblock_mem_size(max_pfn_mapped);
400 if (ramdisk_size >= (mapped_size>>1))
401 panic("initrd too large to handle, "
402 "disabling initrd (%lld needed, %lld available)\n",
403 ramdisk_size, mapped_size>>1);
404
405 printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
406 ramdisk_end - 1);
407
408 if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image),
409 PFN_DOWN(ramdisk_end))) {
410 /* All are mapped, easy case */
411 initrd_start = ramdisk_image + PAGE_OFFSET;
412 initrd_end = initrd_start + ramdisk_size;
413 return;
414 }
415
416 relocate_initrd();
417
418 memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
419 }
420 #else
421 static void __init early_reserve_initrd(void)
422 {
423 }
424 static void __init reserve_initrd(void)
425 {
426 }
427 #endif /* CONFIG_BLK_DEV_INITRD */
428
429 static void __init parse_setup_data(void)
430 {
431 struct setup_data *data;
432 u64 pa_data;
433
434 pa_data = boot_params.hdr.setup_data;
435 while (pa_data) {
436 u32 data_len, map_len;
437
438 map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
439 (u64)sizeof(struct setup_data));
440 data = early_memremap(pa_data, map_len);
441 data_len = data->len + sizeof(struct setup_data);
442 if (data_len > map_len) {
443 early_iounmap(data, map_len);
444 data = early_memremap(pa_data, data_len);
445 map_len = data_len;
446 }
447
448 switch (data->type) {
449 case SETUP_E820_EXT:
450 parse_e820_ext(data);
451 break;
452 case SETUP_DTB:
453 add_dtb(pa_data);
454 break;
455 default:
456 break;
457 }
458 pa_data = data->next;
459 early_iounmap(data, map_len);
460 }
461 }
462
463 static void __init e820_reserve_setup_data(void)
464 {
465 struct setup_data *data;
466 u64 pa_data;
467 int found = 0;
468
469 pa_data = boot_params.hdr.setup_data;
470 while (pa_data) {
471 data = early_memremap(pa_data, sizeof(*data));
472 e820_update_range(pa_data, sizeof(*data)+data->len,
473 E820_RAM, E820_RESERVED_KERN);
474 found = 1;
475 pa_data = data->next;
476 early_iounmap(data, sizeof(*data));
477 }
478 if (!found)
479 return;
480
481 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
482 memcpy(&e820_saved, &e820, sizeof(struct e820map));
483 printk(KERN_INFO "extended physical RAM map:\n");
484 e820_print_map("reserve setup_data");
485 }
486
487 static void __init memblock_x86_reserve_range_setup_data(void)
488 {
489 struct setup_data *data;
490 u64 pa_data;
491
492 pa_data = boot_params.hdr.setup_data;
493 while (pa_data) {
494 data = early_memremap(pa_data, sizeof(*data));
495 memblock_reserve(pa_data, sizeof(*data) + data->len);
496 pa_data = data->next;
497 early_iounmap(data, sizeof(*data));
498 }
499 }
500
501 /*
502 * --------- Crashkernel reservation ------------------------------
503 */
504
505 #ifdef CONFIG_KEXEC
506
507 /*
508 * Keep the crash kernel below this limit. On 32 bits earlier kernels
509 * would limit the kernel to the low 512 MiB due to mapping restrictions.
510 */
511 #ifdef CONFIG_X86_32
512 # define CRASH_KERNEL_ADDR_MAX (512 << 20)
513 #else
514 # define CRASH_KERNEL_ADDR_MAX MAXMEM
515 #endif
516
517 static void __init reserve_crashkernel_low(void)
518 {
519 #ifdef CONFIG_X86_64
520 const unsigned long long alignment = 16<<20; /* 16M */
521 unsigned long long low_base = 0, low_size = 0;
522 unsigned long total_low_mem;
523 unsigned long long base;
524 int ret;
525
526 total_low_mem = memblock_mem_size(1UL<<(32-PAGE_SHIFT));
527 ret = parse_crashkernel_low(boot_command_line, total_low_mem,
528 &low_size, &base);
529 if (ret != 0 || low_size <= 0)
530 return;
531
532 low_base = memblock_find_in_range(low_size, (1ULL<<32),
533 low_size, alignment);
534
535 if (!low_base) {
536 pr_info("crashkernel low reservation failed - No suitable area found.\n");
537
538 return;
539 }
540
541 memblock_reserve(low_base, low_size);
542 pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n",
543 (unsigned long)(low_size >> 20),
544 (unsigned long)(low_base >> 20),
545 (unsigned long)(total_low_mem >> 20));
546 crashk_low_res.start = low_base;
547 crashk_low_res.end = low_base + low_size - 1;
548 insert_resource(&iomem_resource, &crashk_low_res);
549 #endif
550 }
551
552 static void __init reserve_crashkernel(void)
553 {
554 const unsigned long long alignment = 16<<20; /* 16M */
555 unsigned long long total_mem;
556 unsigned long long crash_size, crash_base;
557 int ret;
558
559 total_mem = memblock_phys_mem_size();
560
561 ret = parse_crashkernel(boot_command_line, total_mem,
562 &crash_size, &crash_base);
563 if (ret != 0 || crash_size <= 0)
564 return;
565
566 /* 0 means: find the address automatically */
567 if (crash_base <= 0) {
568 /*
569 * kexec want bzImage is below CRASH_KERNEL_ADDR_MAX
570 */
571 crash_base = memblock_find_in_range(alignment,
572 CRASH_KERNEL_ADDR_MAX, crash_size, alignment);
573
574 if (!crash_base) {
575 pr_info("crashkernel reservation failed - No suitable area found.\n");
576 return;
577 }
578
579 } else {
580 unsigned long long start;
581
582 start = memblock_find_in_range(crash_base,
583 crash_base + crash_size, crash_size, 1<<20);
584 if (start != crash_base) {
585 pr_info("crashkernel reservation failed - memory is in use.\n");
586 return;
587 }
588 }
589 memblock_reserve(crash_base, crash_size);
590
591 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
592 "for crashkernel (System RAM: %ldMB)\n",
593 (unsigned long)(crash_size >> 20),
594 (unsigned long)(crash_base >> 20),
595 (unsigned long)(total_mem >> 20));
596
597 crashk_res.start = crash_base;
598 crashk_res.end = crash_base + crash_size - 1;
599 insert_resource(&iomem_resource, &crashk_res);
600
601 if (crash_base >= (1ULL<<32))
602 reserve_crashkernel_low();
603 }
604 #else
605 static void __init reserve_crashkernel(void)
606 {
607 }
608 #endif
609
610 static struct resource standard_io_resources[] = {
611 { .name = "dma1", .start = 0x00, .end = 0x1f,
612 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
613 { .name = "pic1", .start = 0x20, .end = 0x21,
614 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
615 { .name = "timer0", .start = 0x40, .end = 0x43,
616 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
617 { .name = "timer1", .start = 0x50, .end = 0x53,
618 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
619 { .name = "keyboard", .start = 0x60, .end = 0x60,
620 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
621 { .name = "keyboard", .start = 0x64, .end = 0x64,
622 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
623 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
624 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
625 { .name = "pic2", .start = 0xa0, .end = 0xa1,
626 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
627 { .name = "dma2", .start = 0xc0, .end = 0xdf,
628 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
629 { .name = "fpu", .start = 0xf0, .end = 0xff,
630 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
631 };
632
633 void __init reserve_standard_io_resources(void)
634 {
635 int i;
636
637 /* request I/O space for devices used on all i[345]86 PCs */
638 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
639 request_resource(&ioport_resource, &standard_io_resources[i]);
640
641 }
642
643 static __init void reserve_ibft_region(void)
644 {
645 unsigned long addr, size = 0;
646
647 addr = find_ibft_region(&size);
648
649 if (size)
650 memblock_reserve(addr, size);
651 }
652
653 static bool __init snb_gfx_workaround_needed(void)
654 {
655 #ifdef CONFIG_PCI
656 int i;
657 u16 vendor, devid;
658 static const __initconst u16 snb_ids[] = {
659 0x0102,
660 0x0112,
661 0x0122,
662 0x0106,
663 0x0116,
664 0x0126,
665 0x010a,
666 };
667
668 /* Assume no if something weird is going on with PCI */
669 if (!early_pci_allowed())
670 return false;
671
672 vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID);
673 if (vendor != 0x8086)
674 return false;
675
676 devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID);
677 for (i = 0; i < ARRAY_SIZE(snb_ids); i++)
678 if (devid == snb_ids[i])
679 return true;
680 #endif
681
682 return false;
683 }
684
685 /*
686 * Sandy Bridge graphics has trouble with certain ranges, exclude
687 * them from allocation.
688 */
689 static void __init trim_snb_memory(void)
690 {
691 static const __initconst unsigned long bad_pages[] = {
692 0x20050000,
693 0x20110000,
694 0x20130000,
695 0x20138000,
696 0x40004000,
697 };
698 int i;
699
700 if (!snb_gfx_workaround_needed())
701 return;
702
703 printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n");
704
705 /*
706 * Reserve all memory below the 1 MB mark that has not
707 * already been reserved.
708 */
709 memblock_reserve(0, 1<<20);
710
711 for (i = 0; i < ARRAY_SIZE(bad_pages); i++) {
712 if (memblock_reserve(bad_pages[i], PAGE_SIZE))
713 printk(KERN_WARNING "failed to reserve 0x%08lx\n",
714 bad_pages[i]);
715 }
716 }
717
718 /*
719 * Here we put platform-specific memory range workarounds, i.e.
720 * memory known to be corrupt or otherwise in need to be reserved on
721 * specific platforms.
722 *
723 * If this gets used more widely it could use a real dispatch mechanism.
724 */
725 static void __init trim_platform_memory_ranges(void)
726 {
727 trim_snb_memory();
728 }
729
730 static void __init trim_bios_range(void)
731 {
732 /*
733 * A special case is the first 4Kb of memory;
734 * This is a BIOS owned area, not kernel ram, but generally
735 * not listed as such in the E820 table.
736 *
737 * This typically reserves additional memory (64KiB by default)
738 * since some BIOSes are known to corrupt low memory. See the
739 * Kconfig help text for X86_RESERVE_LOW.
740 */
741 e820_update_range(0, PAGE_SIZE, E820_RAM, E820_RESERVED);
742
743 /*
744 * special case: Some BIOSen report the PC BIOS
745 * area (640->1Mb) as ram even though it is not.
746 * take them out.
747 */
748 e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
749
750 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
751 }
752
753 /* called before trim_bios_range() to spare extra sanitize */
754 static void __init e820_add_kernel_range(void)
755 {
756 u64 start = __pa_symbol(_text);
757 u64 size = __pa_symbol(_end) - start;
758
759 /*
760 * Complain if .text .data and .bss are not marked as E820_RAM and
761 * attempt to fix it by adding the range. We may have a confused BIOS,
762 * or the user may have used memmap=exactmap or memmap=xxM$yyM to
763 * exclude kernel range. If we really are running on top non-RAM,
764 * we will crash later anyways.
765 */
766 if (e820_all_mapped(start, start + size, E820_RAM))
767 return;
768
769 pr_warn(".text .data .bss are not marked as E820_RAM!\n");
770 e820_remove_range(start, size, E820_RAM, 0);
771 e820_add_region(start, size, E820_RAM);
772 }
773
774 static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
775
776 static int __init parse_reservelow(char *p)
777 {
778 unsigned long long size;
779
780 if (!p)
781 return -EINVAL;
782
783 size = memparse(p, &p);
784
785 if (size < 4096)
786 size = 4096;
787
788 if (size > 640*1024)
789 size = 640*1024;
790
791 reserve_low = size;
792
793 return 0;
794 }
795
796 early_param("reservelow", parse_reservelow);
797
798 static void __init trim_low_memory_range(void)
799 {
800 memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE));
801 }
802
803 /*
804 * Determine if we were loaded by an EFI loader. If so, then we have also been
805 * passed the efi memmap, systab, etc., so we should use these data structures
806 * for initialization. Note, the efi init code path is determined by the
807 * global efi_enabled. This allows the same kernel image to be used on existing
808 * systems (with a traditional BIOS) as well as on EFI systems.
809 */
810 /*
811 * setup_arch - architecture-specific boot-time initializations
812 *
813 * Note: On x86_64, fixmaps are ready for use even before this is called.
814 */
815
816 void __init setup_arch(char **cmdline_p)
817 {
818 memblock_reserve(__pa_symbol(_text),
819 (unsigned long)__bss_stop - (unsigned long)_text);
820
821 early_reserve_initrd();
822
823 /*
824 * At this point everything still needed from the boot loader
825 * or BIOS or kernel text should be early reserved or marked not
826 * RAM in e820. All other memory is free game.
827 */
828
829 #ifdef CONFIG_X86_32
830 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
831 visws_early_detect();
832
833 /*
834 * copy kernel address range established so far and switch
835 * to the proper swapper page table
836 */
837 clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
838 initial_page_table + KERNEL_PGD_BOUNDARY,
839 KERNEL_PGD_PTRS);
840
841 load_cr3(swapper_pg_dir);
842 __flush_tlb_all();
843 #else
844 printk(KERN_INFO "Command line: %s\n", boot_command_line);
845 #endif
846
847 /*
848 * If we have OLPC OFW, we might end up relocating the fixmap due to
849 * reserve_top(), so do this before touching the ioremap area.
850 */
851 olpc_ofw_detect();
852
853 early_trap_init();
854 early_cpu_init();
855 early_ioremap_init();
856
857 setup_olpc_ofw_pgd();
858
859 ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
860 screen_info = boot_params.screen_info;
861 edid_info = boot_params.edid_info;
862 #ifdef CONFIG_X86_32
863 apm_info.bios = boot_params.apm_bios_info;
864 ist_info = boot_params.ist_info;
865 if (boot_params.sys_desc_table.length != 0) {
866 machine_id = boot_params.sys_desc_table.table[0];
867 machine_submodel_id = boot_params.sys_desc_table.table[1];
868 BIOS_revision = boot_params.sys_desc_table.table[2];
869 }
870 #endif
871 saved_video_mode = boot_params.hdr.vid_mode;
872 bootloader_type = boot_params.hdr.type_of_loader;
873 if ((bootloader_type >> 4) == 0xe) {
874 bootloader_type &= 0xf;
875 bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4;
876 }
877 bootloader_version = bootloader_type & 0xf;
878 bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
879
880 #ifdef CONFIG_BLK_DEV_RAM
881 rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
882 rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
883 rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
884 #endif
885 #ifdef CONFIG_EFI
886 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
887 "EL32", 4)) {
888 set_bit(EFI_BOOT, &x86_efi_facility);
889 } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
890 "EL64", 4)) {
891 set_bit(EFI_BOOT, &x86_efi_facility);
892 set_bit(EFI_64BIT, &x86_efi_facility);
893 }
894
895 if (efi_enabled(EFI_BOOT))
896 efi_memblock_x86_reserve_range();
897 #endif
898
899 x86_init.oem.arch_setup();
900
901 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
902 setup_memory_map();
903 parse_setup_data();
904 /* update the e820_saved too */
905 e820_reserve_setup_data();
906
907 copy_edd();
908
909 if (!boot_params.hdr.root_flags)
910 root_mountflags &= ~MS_RDONLY;
911 init_mm.start_code = (unsigned long) _text;
912 init_mm.end_code = (unsigned long) _etext;
913 init_mm.end_data = (unsigned long) _edata;
914 init_mm.brk = _brk_end;
915
916 code_resource.start = __pa_symbol(_text);
917 code_resource.end = __pa_symbol(_etext)-1;
918 data_resource.start = __pa_symbol(_etext);
919 data_resource.end = __pa_symbol(_edata)-1;
920 bss_resource.start = __pa_symbol(__bss_start);
921 bss_resource.end = __pa_symbol(__bss_stop)-1;
922
923 #ifdef CONFIG_CMDLINE_BOOL
924 #ifdef CONFIG_CMDLINE_OVERRIDE
925 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
926 #else
927 if (builtin_cmdline[0]) {
928 /* append boot loader cmdline to builtin */
929 strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
930 strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
931 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
932 }
933 #endif
934 #endif
935
936 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
937 *cmdline_p = command_line;
938
939 /*
940 * x86_configure_nx() is called before parse_early_param() to detect
941 * whether hardware doesn't support NX (so that the early EHCI debug
942 * console setup can safely call set_fixmap()). It may then be called
943 * again from within noexec_setup() during parsing early parameters
944 * to honor the respective command line option.
945 */
946 x86_configure_nx();
947
948 parse_early_param();
949
950 x86_report_nx();
951
952 /* after early param, so could get panic from serial */
953 memblock_x86_reserve_range_setup_data();
954
955 if (acpi_mps_check()) {
956 #ifdef CONFIG_X86_LOCAL_APIC
957 disable_apic = 1;
958 #endif
959 setup_clear_cpu_cap(X86_FEATURE_APIC);
960 }
961
962 #ifdef CONFIG_PCI
963 if (pci_early_dump_regs)
964 early_dump_pci_devices();
965 #endif
966
967 finish_e820_parsing();
968
969 if (efi_enabled(EFI_BOOT))
970 efi_init();
971
972 dmi_scan_machine();
973
974 /*
975 * VMware detection requires dmi to be available, so this
976 * needs to be done after dmi_scan_machine, for the BP.
977 */
978 init_hypervisor_platform();
979
980 x86_init.resources.probe_roms();
981
982 /* after parse_early_param, so could debug it */
983 insert_resource(&iomem_resource, &code_resource);
984 insert_resource(&iomem_resource, &data_resource);
985 insert_resource(&iomem_resource, &bss_resource);
986
987 e820_add_kernel_range();
988 trim_bios_range();
989 #ifdef CONFIG_X86_32
990 if (ppro_with_ram_bug()) {
991 e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
992 E820_RESERVED);
993 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
994 printk(KERN_INFO "fixed physical RAM map:\n");
995 e820_print_map("bad_ppro");
996 }
997 #else
998 early_gart_iommu_check();
999 #endif
1000
1001 /*
1002 * partially used pages are not usable - thus
1003 * we are rounding upwards:
1004 */
1005 max_pfn = e820_end_of_ram_pfn();
1006
1007 /* update e820 for memory not covered by WB MTRRs */
1008 mtrr_bp_init();
1009 if (mtrr_trim_uncached_memory(max_pfn))
1010 max_pfn = e820_end_of_ram_pfn();
1011
1012 #ifdef CONFIG_X86_32
1013 /* max_low_pfn get updated here */
1014 find_low_pfn_range();
1015 #else
1016 num_physpages = max_pfn;
1017
1018 check_x2apic();
1019
1020 /* How many end-of-memory variables you have, grandma! */
1021 /* need this before calling reserve_initrd */
1022 if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
1023 max_low_pfn = e820_end_of_low_ram_pfn();
1024 else
1025 max_low_pfn = max_pfn;
1026
1027 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
1028 #endif
1029
1030 /*
1031 * Find and reserve possible boot-time SMP configuration:
1032 */
1033 find_smp_config();
1034
1035 reserve_ibft_region();
1036
1037 early_alloc_pgt_buf();
1038
1039 /*
1040 * Need to conclude brk, before memblock_x86_fill()
1041 * it could use memblock_find_in_range, could overlap with
1042 * brk area.
1043 */
1044 reserve_brk();
1045
1046 cleanup_highmap();
1047
1048 memblock.current_limit = ISA_END_ADDRESS;
1049 memblock_x86_fill();
1050
1051 /*
1052 * The EFI specification says that boot service code won't be called
1053 * after ExitBootServices(). This is, in fact, a lie.
1054 */
1055 if (efi_enabled(EFI_MEMMAP))
1056 efi_reserve_boot_services();
1057
1058 /* preallocate 4k for mptable mpc */
1059 early_reserve_e820_mpc_new();
1060
1061 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
1062 setup_bios_corruption_check();
1063 #endif
1064
1065 #ifdef CONFIG_X86_32
1066 printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n",
1067 (max_pfn_mapped<<PAGE_SHIFT) - 1);
1068 #endif
1069
1070 reserve_real_mode();
1071
1072 trim_platform_memory_ranges();
1073 trim_low_memory_range();
1074
1075 init_mem_mapping();
1076
1077 early_trap_pf_init();
1078
1079 setup_real_mode();
1080
1081 memblock.current_limit = get_max_mapped();
1082 dma_contiguous_reserve(0);
1083
1084 /*
1085 * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
1086 */
1087
1088 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
1089 if (init_ohci1394_dma_early)
1090 init_ohci1394_dma_on_all_controllers();
1091 #endif
1092 /* Allocate bigger log buffer */
1093 setup_log_buf(1);
1094
1095 reserve_initrd();
1096
1097 #if defined(CONFIG_ACPI) && defined(CONFIG_BLK_DEV_INITRD)
1098 acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);
1099 #endif
1100
1101 reserve_crashkernel();
1102
1103 vsmp_init();
1104
1105 io_delay_init();
1106
1107 /*
1108 * Parse the ACPI tables for possible boot-time SMP configuration.
1109 */
1110 acpi_boot_table_init();
1111
1112 early_acpi_boot_init();
1113
1114 initmem_init();
1115 memblock_find_dma_reserve();
1116
1117 #ifdef CONFIG_KVM_GUEST
1118 kvmclock_init();
1119 #endif
1120
1121 x86_init.paging.pagetable_init();
1122
1123 if (boot_cpu_data.cpuid_level >= 0) {
1124 /* A CPU has %cr4 if and only if it has CPUID */
1125 mmu_cr4_features = read_cr4();
1126 if (trampoline_cr4_features)
1127 *trampoline_cr4_features = mmu_cr4_features;
1128 }
1129
1130 #ifdef CONFIG_X86_32
1131 /* sync back kernel address range */
1132 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
1133 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
1134 KERNEL_PGD_PTRS);
1135 #endif
1136
1137 tboot_probe();
1138
1139 #ifdef CONFIG_X86_64
1140 map_vsyscall();
1141 #endif
1142
1143 generic_apic_probe();
1144
1145 early_quirks();
1146
1147 /*
1148 * Read APIC and some other early information from ACPI tables.
1149 */
1150 acpi_boot_init();
1151 sfi_init();
1152 x86_dtb_init();
1153
1154 /*
1155 * get boot-time SMP configuration:
1156 */
1157 if (smp_found_config)
1158 get_smp_config();
1159
1160 prefill_possible_map();
1161
1162 init_cpu_to_node();
1163
1164 init_apic_mappings();
1165 if (x86_io_apic_ops.init)
1166 x86_io_apic_ops.init();
1167
1168 kvm_guest_init();
1169
1170 e820_reserve_resources();
1171 e820_mark_nosave_regions(max_low_pfn);
1172
1173 x86_init.resources.reserve_resources();
1174
1175 e820_setup_gap();
1176
1177 #ifdef CONFIG_VT
1178 #if defined(CONFIG_VGA_CONSOLE)
1179 if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
1180 conswitchp = &vga_con;
1181 #elif defined(CONFIG_DUMMY_CONSOLE)
1182 conswitchp = &dummy_con;
1183 #endif
1184 #endif
1185 x86_init.oem.banner();
1186
1187 x86_init.timers.wallclock_init();
1188
1189 mcheck_init();
1190
1191 arch_init_ideal_nops();
1192
1193 register_refined_jiffies(CLOCK_TICK_RATE);
1194
1195 #ifdef CONFIG_EFI
1196 /* Once setup is done above, unmap the EFI memory map on
1197 * mismatched firmware/kernel archtectures since there is no
1198 * support for runtime services.
1199 */
1200 if (efi_enabled(EFI_BOOT) && !efi_is_native()) {
1201 pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n");
1202 efi_unmap_memmap();
1203 }
1204 #endif
1205 }
1206
1207 #ifdef CONFIG_X86_32
1208
1209 static struct resource video_ram_resource = {
1210 .name = "Video RAM area",
1211 .start = 0xa0000,
1212 .end = 0xbffff,
1213 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
1214 };
1215
1216 void __init i386_reserve_resources(void)
1217 {
1218 request_resource(&iomem_resource, &video_ram_resource);
1219 reserve_standard_io_resources();
1220 }
1221
1222 #endif /* CONFIG_X86_32 */