aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/setup.c')
-rw-r--r--arch/x86/kernel/setup.c234
1 files changed, 114 insertions, 120 deletions
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 7d5ee08c982d..21c6746338af 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -31,6 +31,7 @@
31#include <linux/apm_bios.h> 31#include <linux/apm_bios.h>
32#include <linux/initrd.h> 32#include <linux/initrd.h>
33#include <linux/bootmem.h> 33#include <linux/bootmem.h>
34#include <linux/memblock.h>
34#include <linux/seq_file.h> 35#include <linux/seq_file.h>
35#include <linux/console.h> 36#include <linux/console.h>
36#include <linux/mca.h> 37#include <linux/mca.h>
@@ -83,7 +84,6 @@
83#include <asm/dmi.h> 84#include <asm/dmi.h>
84#include <asm/io_apic.h> 85#include <asm/io_apic.h>
85#include <asm/ist.h> 86#include <asm/ist.h>
86#include <asm/vmi.h>
87#include <asm/setup_arch.h> 87#include <asm/setup_arch.h>
88#include <asm/bios_ebda.h> 88#include <asm/bios_ebda.h>
89#include <asm/cacheflush.h> 89#include <asm/cacheflush.h>
@@ -107,11 +107,12 @@
107#include <asm/percpu.h> 107#include <asm/percpu.h>
108#include <asm/topology.h> 108#include <asm/topology.h>
109#include <asm/apicdef.h> 109#include <asm/apicdef.h>
110#include <asm/k8.h> 110#include <asm/amd_nb.h>
111#ifdef CONFIG_X86_64 111#ifdef CONFIG_X86_64
112#include <asm/numa_64.h> 112#include <asm/numa_64.h>
113#endif 113#endif
114#include <asm/mce.h> 114#include <asm/mce.h>
115#include <asm/alternative.h>
115 116
116/* 117/*
117 * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries. 118 * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
@@ -301,7 +302,7 @@ static inline void init_gbpages(void)
301static void __init reserve_brk(void) 302static void __init reserve_brk(void)
302{ 303{
303 if (_brk_end > _brk_start) 304 if (_brk_end > _brk_start)
304 reserve_early(__pa(_brk_start), __pa(_brk_end), "BRK"); 305 memblock_x86_reserve_range(__pa(_brk_start), __pa(_brk_end), "BRK");
305 306
306 /* Mark brk area as locked down and no longer taking any 307 /* Mark brk area as locked down and no longer taking any
307 new allocations */ 308 new allocations */
@@ -323,17 +324,16 @@ static void __init relocate_initrd(void)
323 char *p, *q; 324 char *p, *q;
324 325
325 /* We need to move the initrd down into lowmem */ 326 /* We need to move the initrd down into lowmem */
326 ramdisk_here = find_e820_area(0, end_of_lowmem, area_size, 327 ramdisk_here = memblock_find_in_range(0, end_of_lowmem, area_size,
327 PAGE_SIZE); 328 PAGE_SIZE);
328 329
329 if (ramdisk_here == -1ULL) 330 if (ramdisk_here == MEMBLOCK_ERROR)
330 panic("Cannot find place for new RAMDISK of size %lld\n", 331 panic("Cannot find place for new RAMDISK of size %lld\n",
331 ramdisk_size); 332 ramdisk_size);
332 333
333 /* Note: this includes all the lowmem currently occupied by 334 /* Note: this includes all the lowmem currently occupied by
334 the initrd, we rely on that fact to keep the data intact. */ 335 the initrd, we rely on that fact to keep the data intact. */
335 reserve_early(ramdisk_here, ramdisk_here + area_size, 336 memblock_x86_reserve_range(ramdisk_here, ramdisk_here + area_size, "NEW RAMDISK");
336 "NEW RAMDISK");
337 initrd_start = ramdisk_here + PAGE_OFFSET; 337 initrd_start = ramdisk_here + PAGE_OFFSET;
338 initrd_end = initrd_start + ramdisk_size; 338 initrd_end = initrd_start + ramdisk_size;
339 printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n", 339 printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
@@ -389,7 +389,7 @@ static void __init reserve_initrd(void)
389 initrd_start = 0; 389 initrd_start = 0;
390 390
391 if (ramdisk_size >= (end_of_lowmem>>1)) { 391 if (ramdisk_size >= (end_of_lowmem>>1)) {
392 free_early(ramdisk_image, ramdisk_end); 392 memblock_x86_free_range(ramdisk_image, ramdisk_end);
393 printk(KERN_ERR "initrd too large to handle, " 393 printk(KERN_ERR "initrd too large to handle, "
394 "disabling initrd\n"); 394 "disabling initrd\n");
395 return; 395 return;
@@ -412,7 +412,7 @@ static void __init reserve_initrd(void)
412 412
413 relocate_initrd(); 413 relocate_initrd();
414 414
415 free_early(ramdisk_image, ramdisk_end); 415 memblock_x86_free_range(ramdisk_image, ramdisk_end);
416} 416}
417#else 417#else
418static void __init reserve_initrd(void) 418static void __init reserve_initrd(void)
@@ -468,7 +468,7 @@ static void __init e820_reserve_setup_data(void)
468 e820_print_map("reserve setup_data"); 468 e820_print_map("reserve setup_data");
469} 469}
470 470
471static void __init reserve_early_setup_data(void) 471static void __init memblock_x86_reserve_range_setup_data(void)
472{ 472{
473 struct setup_data *data; 473 struct setup_data *data;
474 u64 pa_data; 474 u64 pa_data;
@@ -480,7 +480,7 @@ static void __init reserve_early_setup_data(void)
480 while (pa_data) { 480 while (pa_data) {
481 data = early_memremap(pa_data, sizeof(*data)); 481 data = early_memremap(pa_data, sizeof(*data));
482 sprintf(buf, "setup data %x", data->type); 482 sprintf(buf, "setup data %x", data->type);
483 reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf); 483 memblock_x86_reserve_range(pa_data, pa_data+sizeof(*data)+data->len, buf);
484 pa_data = data->next; 484 pa_data = data->next;
485 early_iounmap(data, sizeof(*data)); 485 early_iounmap(data, sizeof(*data));
486 } 486 }
@@ -501,6 +501,7 @@ static inline unsigned long long get_total_mem(void)
501 return total << PAGE_SHIFT; 501 return total << PAGE_SHIFT;
502} 502}
503 503
504#define DEFAULT_BZIMAGE_ADDR_MAX 0x37FFFFFF
504static void __init reserve_crashkernel(void) 505static void __init reserve_crashkernel(void)
505{ 506{
506 unsigned long long total_mem; 507 unsigned long long total_mem;
@@ -518,23 +519,27 @@ static void __init reserve_crashkernel(void)
518 if (crash_base <= 0) { 519 if (crash_base <= 0) {
519 const unsigned long long alignment = 16<<20; /* 16M */ 520 const unsigned long long alignment = 16<<20; /* 16M */
520 521
521 crash_base = find_e820_area(alignment, ULONG_MAX, crash_size, 522 /*
522 alignment); 523 * kexec want bzImage is below DEFAULT_BZIMAGE_ADDR_MAX
523 if (crash_base == -1ULL) { 524 */
525 crash_base = memblock_find_in_range(alignment,
526 DEFAULT_BZIMAGE_ADDR_MAX, crash_size, alignment);
527
528 if (crash_base == MEMBLOCK_ERROR) {
524 pr_info("crashkernel reservation failed - No suitable area found.\n"); 529 pr_info("crashkernel reservation failed - No suitable area found.\n");
525 return; 530 return;
526 } 531 }
527 } else { 532 } else {
528 unsigned long long start; 533 unsigned long long start;
529 534
530 start = find_e820_area(crash_base, ULONG_MAX, crash_size, 535 start = memblock_find_in_range(crash_base,
531 1<<20); 536 crash_base + crash_size, crash_size, 1<<20);
532 if (start != crash_base) { 537 if (start != crash_base) {
533 pr_info("crashkernel reservation failed - memory is in use.\n"); 538 pr_info("crashkernel reservation failed - memory is in use.\n");
534 return; 539 return;
535 } 540 }
536 } 541 }
537 reserve_early(crash_base, crash_base + crash_size, "CRASH KERNEL"); 542 memblock_x86_reserve_range(crash_base, crash_base + crash_size, "CRASH KERNEL");
538 543
539 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " 544 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
540 "for crashkernel (System RAM: %ldMB)\n", 545 "for crashkernel (System RAM: %ldMB)\n",
@@ -614,82 +619,10 @@ static __init void reserve_ibft_region(void)
614 addr = find_ibft_region(&size); 619 addr = find_ibft_region(&size);
615 620
616 if (size) 621 if (size)
617 reserve_early_overlap_ok(addr, addr + size, "ibft"); 622 memblock_x86_reserve_range(addr, addr + size, "* ibft");
618} 623}
619 624
620#ifdef CONFIG_X86_RESERVE_LOW_64K 625static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
621static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
622{
623 printk(KERN_NOTICE
624 "%s detected: BIOS may corrupt low RAM, working around it.\n",
625 d->ident);
626
627 e820_update_range(0, 0x10000, E820_RAM, E820_RESERVED);
628 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
629
630 return 0;
631}
632#endif
633
634/* List of systems that have known low memory corruption BIOS problems */
635static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
636#ifdef CONFIG_X86_RESERVE_LOW_64K
637 {
638 .callback = dmi_low_memory_corruption,
639 .ident = "AMI BIOS",
640 .matches = {
641 DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
642 },
643 },
644 {
645 .callback = dmi_low_memory_corruption,
646 .ident = "Phoenix BIOS",
647 .matches = {
648 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies"),
649 },
650 },
651 {
652 .callback = dmi_low_memory_corruption,
653 .ident = "Phoenix/MSC BIOS",
654 .matches = {
655 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix/MSC"),
656 },
657 },
658 /*
659 * AMI BIOS with low memory corruption was found on Intel DG45ID and
660 * DG45FC boards.
661 * It has a different DMI_BIOS_VENDOR = "Intel Corp.", for now we will
662 * match only DMI_BOARD_NAME and see if there is more bad products
663 * with this vendor.
664 */
665 {
666 .callback = dmi_low_memory_corruption,
667 .ident = "AMI BIOS",
668 .matches = {
669 DMI_MATCH(DMI_BOARD_NAME, "DG45ID"),
670 },
671 },
672 {
673 .callback = dmi_low_memory_corruption,
674 .ident = "AMI BIOS",
675 .matches = {
676 DMI_MATCH(DMI_BOARD_NAME, "DG45FC"),
677 },
678 },
679 /*
680 * The Dell Inspiron Mini 1012 has DMI_BIOS_VENDOR = "Dell Inc.", so
681 * match on the product name.
682 */
683 {
684 .callback = dmi_low_memory_corruption,
685 .ident = "Phoenix BIOS",
686 .matches = {
687 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1012"),
688 },
689 },
690#endif
691 {}
692};
693 626
694static void __init trim_bios_range(void) 627static void __init trim_bios_range(void)
695{ 628{
@@ -697,8 +630,14 @@ static void __init trim_bios_range(void)
697 * A special case is the first 4Kb of memory; 630 * A special case is the first 4Kb of memory;
698 * This is a BIOS owned area, not kernel ram, but generally 631 * This is a BIOS owned area, not kernel ram, but generally
699 * not listed as such in the E820 table. 632 * not listed as such in the E820 table.
633 *
634 * This typically reserves additional memory (64KiB by default)
635 * since some BIOSes are known to corrupt low memory. See the
636 * Kconfig help text for X86_RESERVE_LOW.
700 */ 637 */
701 e820_update_range(0, PAGE_SIZE, E820_RAM, E820_RESERVED); 638 e820_update_range(0, ALIGN(reserve_low, PAGE_SIZE),
639 E820_RAM, E820_RESERVED);
640
702 /* 641 /*
703 * special case: Some BIOSen report the PC BIOS 642 * special case: Some BIOSen report the PC BIOS
704 * area (640->1Mb) as ram even though it is not. 643 * area (640->1Mb) as ram even though it is not.
@@ -708,6 +647,37 @@ static void __init trim_bios_range(void)
708 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); 647 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
709} 648}
710 649
650static int __init parse_reservelow(char *p)
651{
652 unsigned long long size;
653
654 if (!p)
655 return -EINVAL;
656
657 size = memparse(p, &p);
658
659 if (size < 4096)
660 size = 4096;
661
662 if (size > 640*1024)
663 size = 640*1024;
664
665 reserve_low = size;
666
667 return 0;
668}
669
670early_param("reservelow", parse_reservelow);
671
672static u64 __init get_max_mapped(void)
673{
674 u64 end = max_pfn_mapped;
675
676 end <<= PAGE_SHIFT;
677
678 return end;
679}
680
711/* 681/*
712 * Determine if we were loaded by an EFI loader. If so, then we have also been 682 * Determine if we were loaded by an EFI loader. If so, then we have also been
713 * passed the efi memmap, systab, etc., so we should use these data structures 683 * passed the efi memmap, systab, etc., so we should use these data structures
@@ -725,18 +695,30 @@ void __init setup_arch(char **cmdline_p)
725{ 695{
726 int acpi = 0; 696 int acpi = 0;
727 int k8 = 0; 697 int k8 = 0;
698 unsigned long flags;
728 699
729#ifdef CONFIG_X86_32 700#ifdef CONFIG_X86_32
730 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); 701 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
731 visws_early_detect(); 702 visws_early_detect();
703
704 /*
705 * copy kernel address range established so far and switch
706 * to the proper swapper page table
707 */
708 clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
709 initial_page_table + KERNEL_PGD_BOUNDARY,
710 KERNEL_PGD_PTRS);
711
712 load_cr3(swapper_pg_dir);
713 __flush_tlb_all();
732#else 714#else
733 printk(KERN_INFO "Command line: %s\n", boot_command_line); 715 printk(KERN_INFO "Command line: %s\n", boot_command_line);
734#endif 716#endif
735 717
736 /* VMI may relocate the fixmap; do this before touching ioremap area */ 718 /*
737 vmi_init(); 719 * If we have OLPC OFW, we might end up relocating the fixmap due to
738 720 * reserve_top(), so do this before touching the ioremap area.
739 /* OFW also may relocate the fixmap */ 721 */
740 olpc_ofw_detect(); 722 olpc_ofw_detect();
741 723
742 early_trap_init(); 724 early_trap_init();
@@ -781,12 +763,14 @@ void __init setup_arch(char **cmdline_p)
781#endif 763#endif
782 4)) { 764 4)) {
783 efi_enabled = 1; 765 efi_enabled = 1;
784 efi_reserve_early(); 766 efi_memblock_x86_reserve_range();
785 } 767 }
786#endif 768#endif
787 769
788 x86_init.oem.arch_setup(); 770 x86_init.oem.arch_setup();
789 771
772 resource_alloc_from_bottom = 0;
773 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
790 setup_memory_map(); 774 setup_memory_map();
791 parse_setup_data(); 775 parse_setup_data();
792 /* update the e820_saved too */ 776 /* update the e820_saved too */
@@ -837,11 +821,8 @@ void __init setup_arch(char **cmdline_p)
837 821
838 x86_report_nx(); 822 x86_report_nx();
839 823
840 /* Must be before kernel pagetables are setup */
841 vmi_activate();
842
843 /* after early param, so could get panic from serial */ 824 /* after early param, so could get panic from serial */
844 reserve_early_setup_data(); 825 memblock_x86_reserve_range_setup_data();
845 826
846 if (acpi_mps_check()) { 827 if (acpi_mps_check()) {
847#ifdef CONFIG_X86_LOCAL_APIC 828#ifdef CONFIG_X86_LOCAL_APIC
@@ -862,8 +843,6 @@ void __init setup_arch(char **cmdline_p)
862 843
863 dmi_scan_machine(); 844 dmi_scan_machine();
864 845
865 dmi_check_system(bad_bios_dmi_table);
866
867 /* 846 /*
868 * VMware detection requires dmi to be available, so this 847 * VMware detection requires dmi to be available, so this
869 * needs to be done after dmi_scan_machine, for the BP. 848 * needs to be done after dmi_scan_machine, for the BP.
@@ -896,8 +875,6 @@ void __init setup_arch(char **cmdline_p)
896 */ 875 */
897 max_pfn = e820_end_of_ram_pfn(); 876 max_pfn = e820_end_of_ram_pfn();
898 877
899 /* preallocate 4k for mptable mpc */
900 early_reserve_e820_mpc_new();
901 /* update e820 for memory not covered by WB MTRRs */ 878 /* update e820 for memory not covered by WB MTRRs */
902 mtrr_bp_init(); 879 mtrr_bp_init();
903 if (mtrr_trim_uncached_memory(max_pfn)) 880 if (mtrr_trim_uncached_memory(max_pfn))
@@ -919,18 +896,8 @@ void __init setup_arch(char **cmdline_p)
919 max_low_pfn = max_pfn; 896 max_low_pfn = max_pfn;
920 897
921 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 898 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
922 max_pfn_mapped = KERNEL_IMAGE_SIZE >> PAGE_SHIFT;
923#endif 899#endif
924 900
925#ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
926 setup_bios_corruption_check();
927#endif
928
929 printk(KERN_DEBUG "initial memory mapped : 0 - %08lx\n",
930 max_pfn_mapped<<PAGE_SHIFT);
931
932 reserve_brk();
933
934 /* 901 /*
935 * Find and reserve possible boot-time SMP configuration: 902 * Find and reserve possible boot-time SMP configuration:
936 */ 903 */
@@ -938,6 +905,26 @@ void __init setup_arch(char **cmdline_p)
938 905
939 reserve_ibft_region(); 906 reserve_ibft_region();
940 907
908 /*
909 * Need to conclude brk, before memblock_x86_fill()
910 * it could use memblock_find_in_range, could overlap with
911 * brk area.
912 */
913 reserve_brk();
914
915 memblock.current_limit = get_max_mapped();
916 memblock_x86_fill();
917
918 /* preallocate 4k for mptable mpc */
919 early_reserve_e820_mpc_new();
920
921#ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
922 setup_bios_corruption_check();
923#endif
924
925 printk(KERN_DEBUG "initial memory mapped : 0 - %08lx\n",
926 max_pfn_mapped<<PAGE_SHIFT);
927
941 reserve_trampoline_memory(); 928 reserve_trampoline_memory();
942 929
943#ifdef CONFIG_ACPI_SLEEP 930#ifdef CONFIG_ACPI_SLEEP
@@ -961,6 +948,7 @@ void __init setup_arch(char **cmdline_p)
961 max_low_pfn = max_pfn; 948 max_low_pfn = max_pfn;
962 } 949 }
963#endif 950#endif
951 memblock.current_limit = get_max_mapped();
964 952
965 /* 953 /*
966 * NOTE: On x86-32, only from this point on, fixmaps are ready for use. 954 * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
@@ -999,10 +987,7 @@ void __init setup_arch(char **cmdline_p)
999#endif 987#endif
1000 988
1001 initmem_init(0, max_pfn, acpi, k8); 989 initmem_init(0, max_pfn, acpi, k8);
1002#ifndef CONFIG_NO_BOOTMEM 990 memblock_find_dma_reserve();
1003 early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
1004#endif
1005
1006 dma32_reserve_bootmem(); 991 dma32_reserve_bootmem();
1007 992
1008#ifdef CONFIG_KVM_CLOCK 993#ifdef CONFIG_KVM_CLOCK
@@ -1013,7 +998,12 @@ void __init setup_arch(char **cmdline_p)
1013 paging_init(); 998 paging_init();
1014 x86_init.paging.pagetable_setup_done(swapper_pg_dir); 999 x86_init.paging.pagetable_setup_done(swapper_pg_dir);
1015 1000
1016 setup_trampoline_page_table(); 1001#ifdef CONFIG_X86_32
1002 /* sync back kernel address range */
1003 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
1004 swapper_pg_dir + KERNEL_PGD_BOUNDARY,
1005 KERNEL_PGD_PTRS);
1006#endif
1017 1007
1018 tboot_probe(); 1008 tboot_probe();
1019 1009
@@ -1070,6 +1060,10 @@ void __init setup_arch(char **cmdline_p)
1070 x86_init.oem.banner(); 1060 x86_init.oem.banner();
1071 1061
1072 mcheck_init(); 1062 mcheck_init();
1063
1064 local_irq_save(flags);
1065 arch_init_ideal_nop5();
1066 local_irq_restore(flags);
1073} 1067}
1074 1068
1075#ifdef CONFIG_X86_32 1069#ifdef CONFIG_X86_32