Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (C) 1995 Linus Torvalds |
| 4 | * |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 5 | * This file contains the setup_arch() code, which handles the architecture-dependent |
| 6 | * parts of early kernel initialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
Nathan Chancellor | ea7b424 | 2021-09-01 09:07:01 -0700 | [diff] [blame] | 8 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/console.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 10 | #include <linux/crash_dump.h> |
Christoph Hellwig | 0b1abd1 | 2020-09-11 10:56:52 +0200 | [diff] [blame] | 11 | #include <linux/dma-map-ops.h> |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 12 | #include <linux/dmi.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 13 | #include <linux/efi.h> |
Bernhard Kaindl | f212ec4 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 14 | #include <linux/init_ohci1394_dma.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 15 | #include <linux/initrd.h> |
| 16 | #include <linux/iscsi_ibft.h> |
| 17 | #include <linux/memblock.h> |
Andy Shevchenko | f39650d | 2021-06-30 18:54:59 -0700 | [diff] [blame] | 18 | #include <linux/panic_notifier.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 19 | #include <linux/pci.h> |
| 20 | #include <linux/root_dev.h> |
Roman Gushchin | cf11e85 | 2020-04-10 14:32:45 -0700 | [diff] [blame] | 21 | #include <linux/hugetlb.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 22 | #include <linux/tboot.h> |
| 23 | #include <linux/usb/xhci-dbgp.h> |
Peter Zijlstra | a945c83 | 2020-08-18 15:57:51 +0200 | [diff] [blame] | 24 | #include <linux/static_call.h> |
Christoph Hellwig | 0a0f0d8 | 2020-09-22 15:31:03 +0200 | [diff] [blame] | 25 | #include <linux/swiotlb.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 26 | |
David Howells | e262e32d | 2018-11-01 23:07:23 +0000 | [diff] [blame] | 27 | #include <uapi/linux/mount.h> |
Eric W. Biederman | 1bc3b91 | 2005-06-25 14:58:01 -0700 | [diff] [blame] | 28 | |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 29 | #include <xen/xen.h> |
Yinghai Lu | 46d671b | 2008-06-25 17:51:29 -0700 | [diff] [blame] | 30 | |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 31 | #include <asm/apic.h> |
Ingo Molnar | 13c0113 | 2020-08-06 14:34:32 +0200 | [diff] [blame] | 32 | #include <asm/numa.h> |
Alexey Starikovskiy | ce3fe6b | 2008-03-17 22:08:17 +0300 | [diff] [blame] | 33 | #include <asm/bios_ebda.h> |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 34 | #include <asm/bugs.h> |
Jaswinder Singh Rajput | 6e5385d | 2009-01-07 18:11:35 +0530 | [diff] [blame] | 35 | #include <asm/cpu.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 36 | #include <asm/efi.h> |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 37 | #include <asm/gart.h> |
Alok Kataria | 88b094f | 2008-10-27 10:41:46 -0700 | [diff] [blame] | 38 | #include <asm/hypervisor.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 39 | #include <asm/io_apic.h> |
| 40 | #include <asm/kasan.h> |
Thomas Garnier | 0483e1f | 2016-06-21 17:47:02 -0700 | [diff] [blame] | 41 | #include <asm/kaslr.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 42 | #include <asm/mce.h> |
| 43 | #include <asm/mtrr.h> |
Sean Christopherson | ca947b7 | 2019-11-26 08:54:07 -0800 | [diff] [blame] | 44 | #include <asm/realmode.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 45 | #include <asm/olpc_ofw.h> |
| 46 | #include <asm/pci-direct.h> |
| 47 | #include <asm/prom.h> |
| 48 | #include <asm/proto.h> |
Borislav Petkov | 9a90ed0 | 2021-05-27 11:02:26 +0200 | [diff] [blame] | 49 | #include <asm/thermal.h> |
Josh Poimboeuf | ee9f8fc | 2017-07-24 18:36:57 -0500 | [diff] [blame] | 50 | #include <asm/unwind.h> |
Ingo Molnar | 1260901 | 2019-11-18 15:49:22 +0100 | [diff] [blame] | 51 | #include <asm/vsyscall.h> |
Ingo Molnar | 186525b | 2019-11-29 08:17:25 +0100 | [diff] [blame] | 52 | #include <linux/vmalloc.h> |
Yinghai Lu | 46d671b | 2008-06-25 17:51:29 -0700 | [diff] [blame] | 53 | |
Pekka Enberg | 2b72394 | 2009-04-28 16:00:49 +0300 | [diff] [blame] | 54 | /* |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 55 | * max_low_pfn_mapped: highest directly mapped pfn < 4 GB |
| 56 | * max_pfn_mapped: highest directly mapped pfn > 4 GB |
Jacob Shin | 66520eb | 2012-11-16 19:38:52 -0800 | [diff] [blame] | 57 | * |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 58 | * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 59 | * represented by pfn_mapped[]. |
Pekka Enberg | 2b72394 | 2009-04-28 16:00:49 +0300 | [diff] [blame] | 60 | */ |
| 61 | unsigned long max_low_pfn_mapped; |
| 62 | unsigned long max_pfn_mapped; |
| 63 | |
Thadeu Lima de Souza Cascardo | e808bae | 2010-02-09 21:38:45 -0200 | [diff] [blame] | 64 | #ifdef CONFIG_DMI |
Jeremy Fitzhardinge | 796216a | 2009-03-12 16:09:49 -0700 | [diff] [blame] | 65 | RESERVE_BRK(dmi_alloc, 65536); |
Thadeu Lima de Souza Cascardo | e808bae | 2010-02-09 21:38:45 -0200 | [diff] [blame] | 66 | #endif |
Jeremy Fitzhardinge | 796216a | 2009-03-12 16:09:49 -0700 | [diff] [blame] | 67 | |
Ingo Molnar | c0b5842 | 2009-01-27 17:13:05 +0100 | [diff] [blame] | 68 | |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 69 | /* |
| 70 | * Range of the BSS area. The size of the BSS area is determined |
Cao jin | 81519f7 | 2021-03-11 16:39:19 +0800 | [diff] [blame] | 71 | * at link time, with RESERVE_BRK() facility reserving additional |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 72 | * chunks. |
| 73 | */ |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 74 | unsigned long _brk_start = (unsigned long)__brk_base; |
| 75 | unsigned long _brk_end = (unsigned long)__brk_base; |
Jeremy Fitzhardinge | 93dbda7 | 2009-02-26 17:35:44 -0800 | [diff] [blame] | 76 | |
Yinghai Lu | 217b8ce | 2008-06-25 17:55:20 -0700 | [diff] [blame] | 77 | struct boot_params boot_params; |
Yinghai Lu | 217b8ce | 2008-06-25 17:55:20 -0700 | [diff] [blame] | 78 | |
Linus Torvalds | 4046d6e | 2016-04-14 11:18:57 -0700 | [diff] [blame] | 79 | /* |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 80 | * These are the four main kernel memory regions, we put them into |
| 81 | * the resource tree so that kdump tools and other debugging tools |
| 82 | * recover it: |
Linus Torvalds | 4046d6e | 2016-04-14 11:18:57 -0700 | [diff] [blame] | 83 | */ |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 84 | |
Kees Cook | a329975 | 2019-10-29 14:13:50 -0700 | [diff] [blame] | 85 | static struct resource rodata_resource = { |
| 86 | .name = "Kernel rodata", |
| 87 | .start = 0, |
| 88 | .end = 0, |
| 89 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM |
| 90 | }; |
| 91 | |
Linus Torvalds | 4046d6e | 2016-04-14 11:18:57 -0700 | [diff] [blame] | 92 | static struct resource data_resource = { |
| 93 | .name = "Kernel data", |
| 94 | .start = 0, |
| 95 | .end = 0, |
| 96 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM |
| 97 | }; |
| 98 | |
| 99 | static struct resource code_resource = { |
| 100 | .name = "Kernel code", |
| 101 | .start = 0, |
| 102 | .end = 0, |
| 103 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM |
| 104 | }; |
| 105 | |
| 106 | static struct resource bss_resource = { |
| 107 | .name = "Kernel bss", |
| 108 | .start = 0, |
| 109 | .end = 0, |
| 110 | .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM |
| 111 | }; |
| 112 | |
| 113 | |
Yinghai Lu | 7dea23e | 2008-06-25 17:50:06 -0700 | [diff] [blame] | 114 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 115 | /* CPU data as detected by the assembly code in head_32.S */ |
Mathias Krause | 6415813 | 2017-02-12 22:12:08 +0100 | [diff] [blame] | 116 | struct cpuinfo_x86 new_cpu_data; |
| 117 | |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 118 | /* Common CPU data for all CPUs */ |
Mathias Krause | 6415813 | 2017-02-12 22:12:08 +0100 | [diff] [blame] | 119 | struct cpuinfo_x86 boot_cpu_data __read_mostly; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 120 | EXPORT_SYMBOL(boot_cpu_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Alexey Starikovskiy | 0c254e3 | 2008-03-27 23:55:04 +0300 | [diff] [blame] | 122 | unsigned int def_to_bigsmp; |
| 123 | |
Yinghai Lu | 7dea23e | 2008-06-25 17:50:06 -0700 | [diff] [blame] | 124 | struct apm_info apm_info; |
| 125 | EXPORT_SYMBOL(apm_info); |
| 126 | |
| 127 | #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \ |
| 128 | defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) |
| 129 | struct ist_info ist_info; |
| 130 | EXPORT_SYMBOL(ist_info); |
| 131 | #else |
| 132 | struct ist_info ist_info; |
| 133 | #endif |
| 134 | |
| 135 | #else |
Kirill A. Shutemov | 162434e | 2018-02-14 14:16:54 +0300 | [diff] [blame] | 136 | struct cpuinfo_x86 boot_cpu_data __read_mostly; |
Yinghai Lu | 7dea23e | 2008-06-25 17:50:06 -0700 | [diff] [blame] | 137 | EXPORT_SYMBOL(boot_cpu_data); |
| 138 | #endif |
| 139 | |
| 140 | |
| 141 | #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64) |
Kees Cook | 404f6aa | 2016-08-08 16:29:06 -0700 | [diff] [blame] | 142 | __visible unsigned long mmu_cr4_features __ro_after_init; |
Yinghai Lu | 7dea23e | 2008-06-25 17:50:06 -0700 | [diff] [blame] | 143 | #else |
Kees Cook | 404f6aa | 2016-08-08 16:29:06 -0700 | [diff] [blame] | 144 | __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE; |
Yinghai Lu | 7dea23e | 2008-06-25 17:50:06 -0700 | [diff] [blame] | 145 | #endif |
| 146 | |
H. Peter Anvin | 5031296 | 2009-05-07 16:54:11 -0700 | [diff] [blame] | 147 | /* Boot loader ID and version as integers, for the benefit of proc_dointvec */ |
| 148 | int bootloader_type, bootloader_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* |
| 151 | * Setup options |
| 152 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | struct screen_info screen_info; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 154 | EXPORT_SYMBOL(screen_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | struct edid_info edid_info; |
Antonino A. Daplas | 5e518d7 | 2005-09-09 13:04:34 -0700 | [diff] [blame] | 156 | EXPORT_SYMBOL_GPL(edid_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | extern int root_mountflags; |
| 159 | |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 160 | unsigned long saved_video_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 162 | #define RAMDISK_IMAGE_START_MASK 0x07FF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | #define RAMDISK_PROMPT_FLAG 0x8000 |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 164 | #define RAMDISK_LOAD_FLAG 0x4000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Alon Bar-Lev | 4e498b6 | 2007-02-12 00:54:11 -0800 | [diff] [blame] | 166 | static char __initdata command_line[COMMAND_LINE_SIZE]; |
Tim Bird | 516cbf3 | 2008-08-12 12:52:36 -0700 | [diff] [blame] | 167 | #ifdef CONFIG_CMDLINE_BOOL |
| 168 | static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; |
| 169 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) |
| 172 | struct edd edd; |
| 173 | #ifdef CONFIG_EDD_MODULE |
| 174 | EXPORT_SYMBOL(edd); |
| 175 | #endif |
| 176 | /** |
| 177 | * copy_edd() - Copy the BIOS EDD information |
| 178 | * from boot_params into a safe place. |
| 179 | * |
| 180 | */ |
Helight.Xu | 9eaa192 | 2009-11-30 18:33:51 +0800 | [diff] [blame] | 181 | static inline void __init copy_edd(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 183 | memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer, |
| 184 | sizeof(edd.mbr_signature)); |
| 185 | memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info)); |
| 186 | edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries; |
| 187 | edd.edd_info_nr = boot_params.eddbuf_entries; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | #else |
Helight.Xu | 9eaa192 | 2009-11-30 18:33:51 +0800 | [diff] [blame] | 190 | static inline void __init copy_edd(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
| 192 | } |
| 193 | #endif |
| 194 | |
H. Peter Anvin | 5368a2b | 2009-03-14 17:19:51 -0700 | [diff] [blame] | 195 | void * __init extend_brk(size_t size, size_t align) |
| 196 | { |
| 197 | size_t mask = align - 1; |
| 198 | void *ret; |
| 199 | |
| 200 | BUG_ON(_brk_start == 0); |
| 201 | BUG_ON(align & mask); |
| 202 | |
| 203 | _brk_end = (_brk_end + mask) & ~mask; |
| 204 | BUG_ON((char *)(_brk_end + size) > __brk_limit); |
| 205 | |
| 206 | ret = (void *)_brk_end; |
| 207 | _brk_end += size; |
| 208 | |
| 209 | memset(ret, 0, size); |
| 210 | |
| 211 | return ret; |
| 212 | } |
| 213 | |
Yinghai Lu | 148b209 | 2012-11-16 19:39:08 -0800 | [diff] [blame] | 214 | #ifdef CONFIG_X86_32 |
Yinghai Lu | e5f15b4 | 2011-02-18 11:30:30 +0000 | [diff] [blame] | 215 | static void __init cleanup_highmap(void) |
Yinghai Lu | f005fe1 | 2010-12-27 16:48:32 -0800 | [diff] [blame] | 216 | { |
| 217 | } |
Pekka J Enberg | 854c879 | 2009-06-22 17:39:41 +0300 | [diff] [blame] | 218 | #endif |
| 219 | |
H. Peter Anvin | 5368a2b | 2009-03-14 17:19:51 -0700 | [diff] [blame] | 220 | static void __init reserve_brk(void) |
| 221 | { |
| 222 | if (_brk_end > _brk_start) |
Alexander Duyck | fc8d782 | 2012-11-16 13:57:13 -0800 | [diff] [blame] | 223 | memblock_reserve(__pa_symbol(_brk_start), |
| 224 | _brk_end - _brk_start); |
H. Peter Anvin | 5368a2b | 2009-03-14 17:19:51 -0700 | [diff] [blame] | 225 | |
| 226 | /* Mark brk area as locked down and no longer taking any |
| 227 | new allocations */ |
| 228 | _brk_start = 0; |
| 229 | } |
| 230 | |
Borislav Petkov | 5aa3d71 | 2013-12-04 20:50:42 +0100 | [diff] [blame] | 231 | u64 relocated_ramdisk; |
| 232 | |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 233 | #ifdef CONFIG_BLK_DEV_INITRD |
| 234 | |
Yinghai Lu | a8a51a8 | 2013-01-24 12:19:56 -0800 | [diff] [blame] | 235 | static u64 __init get_ramdisk_image(void) |
| 236 | { |
| 237 | u64 ramdisk_image = boot_params.hdr.ramdisk_image; |
| 238 | |
Yinghai Lu | ee92d81 | 2013-01-28 20:16:44 -0800 | [diff] [blame] | 239 | ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; |
| 240 | |
Ronald G. Minnich | 694cfd8 | 2020-04-25 18:10:21 -0700 | [diff] [blame] | 241 | if (ramdisk_image == 0) |
| 242 | ramdisk_image = phys_initrd_start; |
| 243 | |
Yinghai Lu | a8a51a8 | 2013-01-24 12:19:56 -0800 | [diff] [blame] | 244 | return ramdisk_image; |
| 245 | } |
| 246 | static u64 __init get_ramdisk_size(void) |
| 247 | { |
| 248 | u64 ramdisk_size = boot_params.hdr.ramdisk_size; |
| 249 | |
Yinghai Lu | ee92d81 | 2013-01-28 20:16:44 -0800 | [diff] [blame] | 250 | ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; |
| 251 | |
Ronald G. Minnich | 694cfd8 | 2020-04-25 18:10:21 -0700 | [diff] [blame] | 252 | if (ramdisk_size == 0) |
| 253 | ramdisk_size = phys_initrd_size; |
| 254 | |
Yinghai Lu | a8a51a8 | 2013-01-24 12:19:56 -0800 | [diff] [blame] | 255 | return ramdisk_size; |
| 256 | } |
| 257 | |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 258 | static void __init relocate_initrd(void) |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 259 | { |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 260 | /* Assume only end is not page aligned */ |
Yinghai Lu | a8a51a8 | 2013-01-24 12:19:56 -0800 | [diff] [blame] | 261 | u64 ramdisk_image = get_ramdisk_image(); |
| 262 | u64 ramdisk_size = get_ramdisk_size(); |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 263 | u64 area_size = PAGE_ALIGN(ramdisk_size); |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 264 | |
Yinghai Lu | e8c57d4 | 2012-11-16 19:38:51 -0800 | [diff] [blame] | 265 | /* We need to move the initrd down into directly mapped mem */ |
Mike Rapoport | 3c45ee6 | 2020-10-13 16:58:12 -0700 | [diff] [blame] | 266 | relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0, |
| 267 | PFN_PHYS(max_pfn_mapped)); |
Borislav Petkov | 5aa3d71 | 2013-12-04 20:50:42 +0100 | [diff] [blame] | 268 | if (!relocated_ramdisk) |
Yinghai Lu | 3945e2c | 2008-05-25 10:00:09 -0700 | [diff] [blame] | 269 | panic("Cannot find place for new RAMDISK of size %lld\n", |
Borislav Petkov | 5aa3d71 | 2013-12-04 20:50:42 +0100 | [diff] [blame] | 270 | ramdisk_size); |
Yinghai Lu | 3945e2c | 2008-05-25 10:00:09 -0700 | [diff] [blame] | 271 | |
Borislav Petkov | 5aa3d71 | 2013-12-04 20:50:42 +0100 | [diff] [blame] | 272 | initrd_start = relocated_ramdisk + PAGE_OFFSET; |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 273 | initrd_end = initrd_start + ramdisk_size; |
Bjorn Helgaas | 365811d | 2012-05-29 15:06:29 -0700 | [diff] [blame] | 274 | printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", |
Borislav Petkov | 5aa3d71 | 2013-12-04 20:50:42 +0100 | [diff] [blame] | 275 | relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 276 | |
Mark Salter | 5dd2c4b | 2015-09-08 15:03:07 -0700 | [diff] [blame] | 277 | copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size); |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 278 | |
Bjorn Helgaas | 365811d | 2012-05-29 15:06:29 -0700 | [diff] [blame] | 279 | printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to" |
| 280 | " [mem %#010llx-%#010llx]\n", |
Yinghai Lu | ba5b14cc | 2008-05-21 18:40:18 -0700 | [diff] [blame] | 281 | ramdisk_image, ramdisk_image + ramdisk_size - 1, |
Borislav Petkov | 5aa3d71 | 2013-12-04 20:50:42 +0100 | [diff] [blame] | 282 | relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1); |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 283 | } |
Yinghai Lu | 9a27f5c | 2008-06-13 20:07:03 -0700 | [diff] [blame] | 284 | |
Yinghai Lu | 1b8c78b | 2013-01-24 12:19:55 -0800 | [diff] [blame] | 285 | static void __init early_reserve_initrd(void) |
| 286 | { |
| 287 | /* Assume only end is not page aligned */ |
Yinghai Lu | a8a51a8 | 2013-01-24 12:19:56 -0800 | [diff] [blame] | 288 | u64 ramdisk_image = get_ramdisk_image(); |
| 289 | u64 ramdisk_size = get_ramdisk_size(); |
Yinghai Lu | 1b8c78b | 2013-01-24 12:19:55 -0800 | [diff] [blame] | 290 | u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); |
| 291 | |
| 292 | if (!boot_params.hdr.type_of_loader || |
| 293 | !ramdisk_image || !ramdisk_size) |
| 294 | return; /* No initrd provided by bootloader */ |
| 295 | |
| 296 | memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); |
| 297 | } |
Mike Rapoport | 3c45ee6 | 2020-10-13 16:58:12 -0700 | [diff] [blame] | 298 | |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 299 | static void __init reserve_initrd(void) |
| 300 | { |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 301 | /* Assume only end is not page aligned */ |
Yinghai Lu | a8a51a8 | 2013-01-24 12:19:56 -0800 | [diff] [blame] | 302 | u64 ramdisk_image = get_ramdisk_image(); |
| 303 | u64 ramdisk_size = get_ramdisk_size(); |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 304 | u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 305 | |
| 306 | if (!boot_params.hdr.type_of_loader || |
| 307 | !ramdisk_image || !ramdisk_size) |
| 308 | return; /* No initrd provided by bootloader */ |
| 309 | |
| 310 | initrd_start = 0; |
| 311 | |
Bjorn Helgaas | 365811d | 2012-05-29 15:06:29 -0700 | [diff] [blame] | 312 | printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, |
| 313 | ramdisk_end - 1); |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 314 | |
Yinghai Lu | 74f2765 | 2012-11-16 19:38:53 -0800 | [diff] [blame] | 315 | if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image), |
Yinghai Lu | e8c57d4 | 2012-11-16 19:38:51 -0800 | [diff] [blame] | 316 | PFN_DOWN(ramdisk_end))) { |
| 317 | /* All are mapped, easy case */ |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 318 | initrd_start = ramdisk_image + PAGE_OFFSET; |
| 319 | initrd_end = initrd_start + ramdisk_size; |
| 320 | return; |
| 321 | } |
| 322 | |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 323 | relocate_initrd(); |
Yinghai Lu | 8c5dd8f | 2009-06-04 19:14:22 -0700 | [diff] [blame] | 324 | |
Mike Rapoport | 3ecc683 | 2021-11-05 13:43:19 -0700 | [diff] [blame^] | 325 | memblock_phys_free(ramdisk_image, ramdisk_end - ramdisk_image); |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 326 | } |
Lv Zheng | af06f8b | 2016-04-11 10:13:27 +0800 | [diff] [blame] | 327 | |
Yinghai Lu | 225c37d | 2008-06-22 02:46:58 -0700 | [diff] [blame] | 328 | #else |
Yinghai Lu | 1b8c78b | 2013-01-24 12:19:55 -0800 | [diff] [blame] | 329 | static void __init early_reserve_initrd(void) |
| 330 | { |
| 331 | } |
Yinghai Lu | eb1379c | 2008-06-25 17:49:26 -0700 | [diff] [blame] | 332 | static void __init reserve_initrd(void) |
Yinghai Lu | 225c37d | 2008-06-22 02:46:58 -0700 | [diff] [blame] | 333 | { |
| 334 | } |
H. Peter Anvin | cf8fa92 | 2008-01-30 13:32:51 +0100 | [diff] [blame] | 335 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 336 | |
Yinghai Lu | 29f784e | 2008-06-25 18:00:22 -0700 | [diff] [blame] | 337 | static void __init parse_setup_data(void) |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 338 | { |
| 339 | struct setup_data *data; |
Linn Crosetto | 30e46b5 | 2013-08-13 15:46:41 -0600 | [diff] [blame] | 340 | u64 pa_data, pa_next; |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 341 | |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 342 | pa_data = boot_params.hdr.setup_data; |
| 343 | while (pa_data) { |
WANG Chao | 7389882 | 2015-01-07 18:55:48 +0800 | [diff] [blame] | 344 | u32 data_len, data_type; |
Sebastian Andrzej Siewior | f1c2b35 | 2011-02-22 21:07:36 +0100 | [diff] [blame] | 345 | |
WANG Chao | 7389882 | 2015-01-07 18:55:48 +0800 | [diff] [blame] | 346 | data = early_memremap(pa_data, sizeof(*data)); |
Sebastian Andrzej Siewior | f1c2b35 | 2011-02-22 21:07:36 +0100 | [diff] [blame] | 347 | data_len = data->len + sizeof(struct setup_data); |
Linn Crosetto | 30e46b5 | 2013-08-13 15:46:41 -0600 | [diff] [blame] | 348 | data_type = data->type; |
| 349 | pa_next = data->next; |
Juergen Gross | 8d4a40b | 2015-02-24 10:13:28 +0100 | [diff] [blame] | 350 | early_memunmap(data, sizeof(*data)); |
Sebastian Andrzej Siewior | f1c2b35 | 2011-02-22 21:07:36 +0100 | [diff] [blame] | 351 | |
Linn Crosetto | 30e46b5 | 2013-08-13 15:46:41 -0600 | [diff] [blame] | 352 | switch (data_type) { |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 353 | case SETUP_E820_EXT: |
Ingo Molnar | 914053c | 2017-01-28 13:18:40 +0100 | [diff] [blame] | 354 | e820__memory_setup_extended(pa_data, data_len); |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 355 | break; |
Sebastian Andrzej Siewior | da6b737 | 2011-02-22 21:07:37 +0100 | [diff] [blame] | 356 | case SETUP_DTB: |
| 357 | add_dtb(pa_data); |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 358 | break; |
Dave Young | 1fec053 | 2013-12-20 18:02:19 +0800 | [diff] [blame] | 359 | case SETUP_EFI: |
| 360 | parse_efi_setup(pa_data, data_len); |
| 361 | break; |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 362 | default: |
| 363 | break; |
| 364 | } |
Linn Crosetto | 30e46b5 | 2013-08-13 15:46:41 -0600 | [diff] [blame] | 365 | pa_data = pa_next; |
Yinghai Lu | 257b0fd | 2008-06-25 17:56:22 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 369 | static void __init memblock_x86_reserve_range_setup_data(void) |
Yinghai Lu | a0a0bec | 2008-07-03 11:37:13 -0700 | [diff] [blame] | 370 | { |
| 371 | struct setup_data *data; |
| 372 | u64 pa_data; |
Yinghai Lu | a0a0bec | 2008-07-03 11:37:13 -0700 | [diff] [blame] | 373 | |
Yinghai Lu | a0a0bec | 2008-07-03 11:37:13 -0700 | [diff] [blame] | 374 | pa_data = boot_params.hdr.setup_data; |
| 375 | while (pa_data) { |
Jeremy Fitzhardinge | 88b4c14 | 2008-09-07 15:21:16 -0700 | [diff] [blame] | 376 | data = early_memremap(pa_data, sizeof(*data)); |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 377 | memblock_reserve(pa_data, sizeof(*data) + data->len); |
Daniel Kiper | b3c72fc | 2019-11-12 14:46:40 +0100 | [diff] [blame] | 378 | |
| 379 | if (data->type == SETUP_INDIRECT && |
| 380 | ((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) |
| 381 | memblock_reserve(((struct setup_indirect *)data->data)->addr, |
| 382 | ((struct setup_indirect *)data->data)->len); |
| 383 | |
Yinghai Lu | a0a0bec | 2008-07-03 11:37:13 -0700 | [diff] [blame] | 384 | pa_data = data->next; |
Juergen Gross | 8d4a40b | 2015-02-24 10:13:28 +0100 | [diff] [blame] | 385 | early_memunmap(data, sizeof(*data)); |
Yinghai Lu | a0a0bec | 2008-07-03 11:37:13 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /* |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 390 | * --------- Crashkernel reservation ------------------------------ |
| 391 | */ |
| 392 | |
Dave Young | 2965faa | 2015-09-09 15:38:55 -0700 | [diff] [blame] | 393 | #ifdef CONFIG_KEXEC_CORE |
Bernhard Walle | 32105f7 | 2008-06-26 21:54:08 +0200 | [diff] [blame] | 394 | |
Borislav Petkov | 606134f | 2015-10-19 11:17:44 +0200 | [diff] [blame] | 395 | /* 16M alignment for crash kernel regions */ |
Dave Young | 9ca5c8e | 2019-04-21 11:50:59 +0800 | [diff] [blame] | 396 | #define CRASH_ALIGN SZ_16M |
Borislav Petkov | 606134f | 2015-10-19 11:17:44 +0200 | [diff] [blame] | 397 | |
H. Peter Anvin | 7f8595b | 2010-12-16 19:20:41 -0800 | [diff] [blame] | 398 | /* |
Baoquan He | 8ff80fb | 2019-05-24 15:38:10 +0800 | [diff] [blame] | 399 | * Keep the crash kernel below this limit. |
| 400 | * |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 401 | * Earlier 32-bits kernels would limit the kernel to the low 512 MB range |
Baoquan He | 8ff80fb | 2019-05-24 15:38:10 +0800 | [diff] [blame] | 402 | * due to mapping restrictions. |
| 403 | * |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 404 | * 64-bit kdump kernels need to be restricted to be under 64 TB, which is |
Cao jin | 11a98f3 | 2019-11-18 15:00:12 +0800 | [diff] [blame] | 405 | * the upper limit of system RAM in 4-level paging mode. Since the kdump |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 406 | * jump could be from 5-level paging to 4-level paging, the jump will fail if |
| 407 | * the kernel is put above 64 TB, and during the 1st kernel bootup there's |
| 408 | * no good way to detect the paging mode of the target kernel which will be |
| 409 | * loaded for dumping. |
H. Peter Anvin | 7f8595b | 2010-12-16 19:20:41 -0800 | [diff] [blame] | 410 | */ |
| 411 | #ifdef CONFIG_X86_32 |
Dave Young | 9ca5c8e | 2019-04-21 11:50:59 +0800 | [diff] [blame] | 412 | # define CRASH_ADDR_LOW_MAX SZ_512M |
| 413 | # define CRASH_ADDR_HIGH_MAX SZ_512M |
H. Peter Anvin | 7f8595b | 2010-12-16 19:20:41 -0800 | [diff] [blame] | 414 | #else |
Dave Young | 9ca5c8e | 2019-04-21 11:50:59 +0800 | [diff] [blame] | 415 | # define CRASH_ADDR_LOW_MAX SZ_4G |
Baoquan He | 8ff80fb | 2019-05-24 15:38:10 +0800 | [diff] [blame] | 416 | # define CRASH_ADDR_HIGH_MAX SZ_64T |
H. Peter Anvin | 7f8595b | 2010-12-16 19:20:41 -0800 | [diff] [blame] | 417 | #endif |
| 418 | |
Baoquan He | eb6db83 | 2015-10-19 11:17:41 +0200 | [diff] [blame] | 419 | static int __init reserve_crashkernel_low(void) |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 420 | { |
| 421 | #ifdef CONFIG_X86_64 |
Borislav Petkov | f56d557 | 2015-10-19 11:17:45 +0200 | [diff] [blame] | 422 | unsigned long long base, low_base = 0, low_size = 0; |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 423 | unsigned long low_mem_limit; |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 424 | int ret; |
| 425 | |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 426 | low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX); |
Borislav Petkov | 97eac21 | 2015-10-19 11:17:43 +0200 | [diff] [blame] | 427 | |
Yinghai Lu | adbc742 | 2013-04-15 22:23:48 -0700 | [diff] [blame] | 428 | /* crashkernel=Y,low */ |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 429 | ret = parse_crashkernel_low(boot_command_line, low_mem_limit, &low_size, &base); |
Borislav Petkov | f56d557 | 2015-10-19 11:17:45 +0200 | [diff] [blame] | 430 | if (ret) { |
Yinghai Lu | c729de8 | 2013-04-15 22:23:45 -0700 | [diff] [blame] | 431 | /* |
Andy Shevchenko | 392e879 | 2019-06-19 17:19:55 +0300 | [diff] [blame] | 432 | * two parts from kernel/dma/swiotlb.c: |
Joerg Roedel | 94fb933 | 2015-06-10 17:49:42 +0200 | [diff] [blame] | 433 | * -swiotlb size: user-specified with swiotlb= or default. |
| 434 | * |
| 435 | * -swiotlb overflow buffer: now hardcoded to 32k. We round it |
| 436 | * to 8M for other buffers that may need to stay low too. Also |
| 437 | * make sure we allocate enough extra low memory so that we |
| 438 | * don't run out of DMA buffers for 32-bit devices. |
Yinghai Lu | c729de8 | 2013-04-15 22:23:45 -0700 | [diff] [blame] | 439 | */ |
Borislav Petkov | 97eac21 | 2015-10-19 11:17:43 +0200 | [diff] [blame] | 440 | low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); |
Yinghai Lu | c729de8 | 2013-04-15 22:23:45 -0700 | [diff] [blame] | 441 | } else { |
Yinghai Lu | adbc742 | 2013-04-15 22:23:48 -0700 | [diff] [blame] | 442 | /* passed with crashkernel=0,low ? */ |
Yinghai Lu | c729de8 | 2013-04-15 22:23:45 -0700 | [diff] [blame] | 443 | if (!low_size) |
Baoquan He | eb6db83 | 2015-10-19 11:17:41 +0200 | [diff] [blame] | 444 | return 0; |
Yinghai Lu | c729de8 | 2013-04-15 22:23:45 -0700 | [diff] [blame] | 445 | } |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 446 | |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 447 | low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 448 | if (!low_base) { |
Baoquan He | eb6db83 | 2015-10-19 11:17:41 +0200 | [diff] [blame] | 449 | pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", |
| 450 | (unsigned long)(low_size >> 20)); |
| 451 | return -ENOMEM; |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 454 | pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n", |
Borislav Petkov | 97eac21 | 2015-10-19 11:17:43 +0200 | [diff] [blame] | 455 | (unsigned long)(low_size >> 20), |
| 456 | (unsigned long)(low_base >> 20), |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 457 | (unsigned long)(low_mem_limit >> 20)); |
Borislav Petkov | 97eac21 | 2015-10-19 11:17:43 +0200 | [diff] [blame] | 458 | |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 459 | crashk_low_res.start = low_base; |
| 460 | crashk_low_res.end = low_base + low_size - 1; |
| 461 | insert_resource(&iomem_resource, &crashk_low_res); |
| 462 | #endif |
Baoquan He | eb6db83 | 2015-10-19 11:17:41 +0200 | [diff] [blame] | 463 | return 0; |
Yinghai Lu | 0212f91 | 2013-01-24 12:20:11 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Yinghai Lu | 29f784e | 2008-06-25 18:00:22 -0700 | [diff] [blame] | 466 | static void __init reserve_crashkernel(void) |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 467 | { |
Borislav Petkov | f56d557 | 2015-10-19 11:17:45 +0200 | [diff] [blame] | 468 | unsigned long long crash_size, crash_base, total_mem; |
Yinghai Lu | 55a20ee | 2013-04-15 22:23:47 -0700 | [diff] [blame] | 469 | bool high = false; |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 470 | int ret; |
| 471 | |
Dave Young | 09c71bf | 2012-03-28 14:42:47 -0700 | [diff] [blame] | 472 | total_mem = memblock_phys_mem_size(); |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 473 | |
Yinghai Lu | 55a20ee | 2013-04-15 22:23:47 -0700 | [diff] [blame] | 474 | /* crashkernel=XM */ |
Borislav Petkov | 97eac21 | 2015-10-19 11:17:43 +0200 | [diff] [blame] | 475 | ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); |
Yinghai Lu | 55a20ee | 2013-04-15 22:23:47 -0700 | [diff] [blame] | 476 | if (ret != 0 || crash_size <= 0) { |
Yinghai Lu | adbc742 | 2013-04-15 22:23:48 -0700 | [diff] [blame] | 477 | /* crashkernel=X,high */ |
Yinghai Lu | 55a20ee | 2013-04-15 22:23:47 -0700 | [diff] [blame] | 478 | ret = parse_crashkernel_high(boot_command_line, total_mem, |
Borislav Petkov | 97eac21 | 2015-10-19 11:17:43 +0200 | [diff] [blame] | 479 | &crash_size, &crash_base); |
Yinghai Lu | 55a20ee | 2013-04-15 22:23:47 -0700 | [diff] [blame] | 480 | if (ret != 0 || crash_size <= 0) |
| 481 | return; |
| 482 | high = true; |
| 483 | } |
Bernhard Walle | 32105f7 | 2008-06-26 21:54:08 +0200 | [diff] [blame] | 484 | |
Petr Tesarik | 3db3eb2 | 2018-04-25 12:08:35 +0200 | [diff] [blame] | 485 | if (xen_pv_domain()) { |
| 486 | pr_info("Ignoring crashkernel for a Xen PV domain\n"); |
| 487 | return; |
| 488 | } |
| 489 | |
Bernhard Walle | 32105f7 | 2008-06-26 21:54:08 +0200 | [diff] [blame] | 490 | /* 0 means: find the address automatically */ |
Dave Young | b9ac384 | 2019-04-22 11:19:05 +0800 | [diff] [blame] | 491 | if (!crash_base) { |
Yinghai Lu | 9f4c139 | 2010-10-05 16:05:14 -0700 | [diff] [blame] | 492 | /* |
Xunlei Pang | a8d4c82 | 2017-01-23 14:48:23 +0800 | [diff] [blame] | 493 | * Set CRASH_ADDR_LOW_MAX upper bound for crash memory, |
Dave Young | b9ac384 | 2019-04-22 11:19:05 +0800 | [diff] [blame] | 494 | * crashkernel=x,high reserves memory over 4G, also allocates |
| 495 | * 256M extra low memory for DMA buffers and swiotlb. |
| 496 | * But the extra memory is not required for all machines. |
| 497 | * So try low memory first and fall back to high memory |
| 498 | * unless "crashkernel=size[KMG],high" is specified. |
Yinghai Lu | 9f4c139 | 2010-10-05 16:05:14 -0700 | [diff] [blame] | 499 | */ |
Dave Young | b9ac384 | 2019-04-22 11:19:05 +0800 | [diff] [blame] | 500 | if (!high) |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 501 | crash_base = memblock_phys_alloc_range(crash_size, |
| 502 | CRASH_ALIGN, CRASH_ALIGN, |
| 503 | CRASH_ADDR_LOW_MAX); |
Dave Young | b9ac384 | 2019-04-22 11:19:05 +0800 | [diff] [blame] | 504 | if (!crash_base) |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 505 | crash_base = memblock_phys_alloc_range(crash_size, |
| 506 | CRASH_ALIGN, CRASH_ALIGN, |
| 507 | CRASH_ADDR_HIGH_MAX); |
Tejun Heo | 1f5026a | 2011-07-12 09:58:09 +0200 | [diff] [blame] | 508 | if (!crash_base) { |
Yinghai Lu | 4428073 | 2009-11-22 17:18:49 -0800 | [diff] [blame] | 509 | pr_info("crashkernel reservation failed - No suitable area found.\n"); |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 510 | return; |
| 511 | } |
Bernhard Walle | 32105f7 | 2008-06-26 21:54:08 +0200 | [diff] [blame] | 512 | } else { |
Yinghai Lu | 4428073 | 2009-11-22 17:18:49 -0800 | [diff] [blame] | 513 | unsigned long long start; |
| 514 | |
Mike Rapoport | 6120cdc | 2020-10-13 16:58:16 -0700 | [diff] [blame] | 515 | start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base, |
| 516 | crash_base + crash_size); |
Yinghai Lu | 4428073 | 2009-11-22 17:18:49 -0800 | [diff] [blame] | 517 | if (start != crash_base) { |
| 518 | pr_info("crashkernel reservation failed - memory is in use.\n"); |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 519 | return; |
| 520 | } |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 521 | } |
Bernhard Walle | 32105f7 | 2008-06-26 21:54:08 +0200 | [diff] [blame] | 522 | |
Baoquan He | eb6db83 | 2015-10-19 11:17:41 +0200 | [diff] [blame] | 523 | if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { |
Mike Rapoport | 3ecc683 | 2021-11-05 13:43:19 -0700 | [diff] [blame^] | 524 | memblock_phys_free(crash_base, crash_size); |
Baoquan He | eb6db83 | 2015-10-19 11:17:41 +0200 | [diff] [blame] | 525 | return; |
| 526 | } |
| 527 | |
Borislav Petkov | f56d557 | 2015-10-19 11:17:45 +0200 | [diff] [blame] | 528 | pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", |
| 529 | (unsigned long)(crash_size >> 20), |
| 530 | (unsigned long)(crash_base >> 20), |
| 531 | (unsigned long)(total_mem >> 20)); |
Bernhard Walle | 32105f7 | 2008-06-26 21:54:08 +0200 | [diff] [blame] | 532 | |
| 533 | crashk_res.start = crash_base; |
| 534 | crashk_res.end = crash_base + crash_size - 1; |
| 535 | insert_resource(&iomem_resource, &crashk_res); |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 536 | } |
| 537 | #else |
Yinghai Lu | 29f784e | 2008-06-25 18:00:22 -0700 | [diff] [blame] | 538 | static void __init reserve_crashkernel(void) |
Yinghai Lu | ccb4def | 2008-06-25 17:57:13 -0700 | [diff] [blame] | 539 | { |
| 540 | } |
| 541 | #endif |
| 542 | |
Yinghai Lu | bdba0e7 | 2008-06-25 17:58:02 -0700 | [diff] [blame] | 543 | static struct resource standard_io_resources[] = { |
| 544 | { .name = "dma1", .start = 0x00, .end = 0x1f, |
| 545 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 546 | { .name = "pic1", .start = 0x20, .end = 0x21, |
| 547 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 548 | { .name = "timer0", .start = 0x40, .end = 0x43, |
| 549 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 550 | { .name = "timer1", .start = 0x50, .end = 0x53, |
| 551 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 552 | { .name = "keyboard", .start = 0x60, .end = 0x60, |
| 553 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 554 | { .name = "keyboard", .start = 0x64, .end = 0x64, |
| 555 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 556 | { .name = "dma page reg", .start = 0x80, .end = 0x8f, |
| 557 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 558 | { .name = "pic2", .start = 0xa0, .end = 0xa1, |
| 559 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 560 | { .name = "dma2", .start = 0xc0, .end = 0xdf, |
| 561 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 562 | { .name = "fpu", .start = 0xf0, .end = 0xff, |
| 563 | .flags = IORESOURCE_BUSY | IORESOURCE_IO } |
| 564 | }; |
| 565 | |
Thomas Gleixner | 8fee697 | 2009-08-19 14:55:50 +0200 | [diff] [blame] | 566 | void __init reserve_standard_io_resources(void) |
Yinghai Lu | bdba0e7 | 2008-06-25 17:58:02 -0700 | [diff] [blame] | 567 | { |
| 568 | int i; |
| 569 | |
| 570 | /* request I/O space for devices used on all i[345]86 PCs */ |
| 571 | for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) |
| 572 | request_resource(&ioport_resource, &standard_io_resources[i]); |
| 573 | |
| 574 | } |
| 575 | |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 576 | static bool __init snb_gfx_workaround_needed(void) |
| 577 | { |
H. Peter Anvin | e43b3ce | 2013-01-13 20:56:41 -0800 | [diff] [blame] | 578 | #ifdef CONFIG_PCI |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 579 | int i; |
| 580 | u16 vendor, devid; |
H. Peter Anvin | ab3cd86 | 2013-01-13 20:36:39 -0800 | [diff] [blame] | 581 | static const __initconst u16 snb_ids[] = { |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 582 | 0x0102, |
| 583 | 0x0112, |
| 584 | 0x0122, |
| 585 | 0x0106, |
| 586 | 0x0116, |
| 587 | 0x0126, |
| 588 | 0x010a, |
| 589 | }; |
| 590 | |
| 591 | /* Assume no if something weird is going on with PCI */ |
| 592 | if (!early_pci_allowed()) |
| 593 | return false; |
| 594 | |
| 595 | vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID); |
| 596 | if (vendor != 0x8086) |
| 597 | return false; |
| 598 | |
| 599 | devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID); |
| 600 | for (i = 0; i < ARRAY_SIZE(snb_ids); i++) |
| 601 | if (devid == snb_ids[i]) |
| 602 | return true; |
H. Peter Anvin | e43b3ce | 2013-01-13 20:56:41 -0800 | [diff] [blame] | 603 | #endif |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 604 | |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * Sandy Bridge graphics has trouble with certain ranges, exclude |
| 610 | * them from allocation. |
| 611 | */ |
| 612 | static void __init trim_snb_memory(void) |
| 613 | { |
H. Peter Anvin | ab3cd86 | 2013-01-13 20:36:39 -0800 | [diff] [blame] | 614 | static const __initconst unsigned long bad_pages[] = { |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 615 | 0x20050000, |
| 616 | 0x20110000, |
| 617 | 0x20130000, |
| 618 | 0x20138000, |
| 619 | 0x40004000, |
| 620 | }; |
| 621 | int i; |
| 622 | |
| 623 | if (!snb_gfx_workaround_needed()) |
| 624 | return; |
| 625 | |
| 626 | printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); |
| 627 | |
| 628 | /* |
Mike Rapoport | c361e5d | 2021-04-13 21:08:39 +0300 | [diff] [blame] | 629 | * SandyBridge integrated graphics devices have a bug that prevents |
| 630 | * them from accessing certain memory ranges, namely anything below |
| 631 | * 1M and in the pages listed in bad_pages[] above. |
| 632 | * |
Mike Rapoport | f1d4d47 | 2021-06-01 10:53:52 +0300 | [diff] [blame] | 633 | * To avoid these pages being ever accessed by SNB gfx devices reserve |
| 634 | * bad_pages that have not already been reserved at boot time. |
| 635 | * All memory below the 1 MB mark is anyway reserved later during |
| 636 | * setup_arch(), so there is no need to reserve it here. |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 637 | */ |
Mike Rapoport | c361e5d | 2021-04-13 21:08:39 +0300 | [diff] [blame] | 638 | |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 639 | for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { |
| 640 | if (memblock_reserve(bad_pages[i], PAGE_SIZE)) |
| 641 | printk(KERN_WARNING "failed to reserve 0x%08lx\n", |
| 642 | bad_pages[i]); |
| 643 | } |
| 644 | } |
| 645 | |
Yinghai Lu | 1b5576e | 2010-01-22 11:21:04 +0800 | [diff] [blame] | 646 | static void __init trim_bios_range(void) |
| 647 | { |
| 648 | /* |
Mike Rapoport | 5c279c4 | 2021-02-04 20:12:37 +0200 | [diff] [blame] | 649 | * A special case is the first 4Kb of memory; |
| 650 | * This is a BIOS owned area, not kernel ram, but generally |
| 651 | * not listed as such in the E820 table. |
| 652 | * |
| 653 | * This typically reserves additional memory (64KiB by default) |
| 654 | * since some BIOSes are known to corrupt low memory. See the |
| 655 | * Kconfig help text for X86_RESERVE_LOW. |
| 656 | */ |
| 657 | e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); |
| 658 | |
| 659 | /* |
Cao jin | 11a98f3 | 2019-11-18 15:00:12 +0800 | [diff] [blame] | 660 | * special case: Some BIOSes report the PC BIOS |
| 661 | * area (640Kb -> 1Mb) as RAM even though it is not. |
Yinghai Lu | 1b5576e | 2010-01-22 11:21:04 +0800 | [diff] [blame] | 662 | * take them out. |
| 663 | */ |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 664 | e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1); |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 665 | |
Ingo Molnar | f9748fa | 2017-01-28 18:00:35 +0100 | [diff] [blame] | 666 | e820__update_table(e820_table); |
Yinghai Lu | 1b5576e | 2010-01-22 11:21:04 +0800 | [diff] [blame] | 667 | } |
| 668 | |
Yinghai Lu | b422a30 | 2013-01-24 12:19:45 -0800 | [diff] [blame] | 669 | /* called before trim_bios_range() to spare extra sanitize */ |
| 670 | static void __init e820_add_kernel_range(void) |
| 671 | { |
| 672 | u64 start = __pa_symbol(_text); |
| 673 | u64 size = __pa_symbol(_end) - start; |
| 674 | |
| 675 | /* |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 676 | * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and |
Yinghai Lu | b422a30 | 2013-01-24 12:19:45 -0800 | [diff] [blame] | 677 | * attempt to fix it by adding the range. We may have a confused BIOS, |
| 678 | * or the user may have used memmap=exactmap or memmap=xxM$yyM to |
| 679 | * exclude kernel range. If we really are running on top non-RAM, |
| 680 | * we will crash later anyways. |
| 681 | */ |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 682 | if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) |
Yinghai Lu | b422a30 | 2013-01-24 12:19:45 -0800 | [diff] [blame] | 683 | return; |
| 684 | |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 685 | pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n"); |
| 686 | e820__range_remove(start, size, E820_TYPE_RAM, 0); |
| 687 | e820__range_add(start, size, E820_TYPE_RAM); |
Yinghai Lu | b422a30 | 2013-01-24 12:19:45 -0800 | [diff] [blame] | 688 | } |
| 689 | |
Mike Rapoport | a799c2b | 2021-03-02 12:04:05 +0200 | [diff] [blame] | 690 | static void __init early_reserve_memory(void) |
H. Peter Anvin | 95c9608 | 2013-02-14 14:02:52 -0800 | [diff] [blame] | 691 | { |
Mike Rapoport | a799c2b | 2021-03-02 12:04:05 +0200 | [diff] [blame] | 692 | /* |
| 693 | * Reserve the memory occupied by the kernel between _text and |
| 694 | * __end_of_kernel_reserve symbols. Any kernel sections after the |
| 695 | * __end_of_kernel_reserve symbol must be explicitly reserved with a |
| 696 | * separate memblock_reserve() or they will be discarded. |
| 697 | */ |
| 698 | memblock_reserve(__pa_symbol(_text), |
| 699 | (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); |
| 700 | |
| 701 | /* |
Mike Rapoport | 4c67448 | 2021-03-02 12:04:06 +0200 | [diff] [blame] | 702 | * The first 4Kb of memory is a BIOS owned area, but generally it is |
| 703 | * not listed as such in the E820 table. |
| 704 | * |
Mike Rapoport | f1d4d47 | 2021-06-01 10:53:52 +0300 | [diff] [blame] | 705 | * Reserve the first 64K of memory since some BIOSes are known to |
| 706 | * corrupt low memory. After the real mode trampoline is allocated the |
| 707 | * rest of the memory below 640k is reserved. |
Mike Rapoport | 4c67448 | 2021-03-02 12:04:06 +0200 | [diff] [blame] | 708 | * |
| 709 | * In addition, make sure page 0 is always reserved because on |
| 710 | * systems with L1TF its contents can be leaked to user processes. |
Mike Rapoport | a799c2b | 2021-03-02 12:04:05 +0200 | [diff] [blame] | 711 | */ |
Mike Rapoport | f1d4d47 | 2021-06-01 10:53:52 +0300 | [diff] [blame] | 712 | memblock_reserve(0, SZ_64K); |
Mike Rapoport | a799c2b | 2021-03-02 12:04:05 +0200 | [diff] [blame] | 713 | |
| 714 | early_reserve_initrd(); |
| 715 | |
| 716 | if (efi_enabled(EFI_BOOT)) |
| 717 | efi_memblock_x86_reserve_range(); |
| 718 | |
| 719 | memblock_x86_reserve_range_setup_data(); |
| 720 | |
| 721 | reserve_ibft_region(); |
| 722 | reserve_bios_regions(); |
Mike Rapoport | f1d4d47 | 2021-06-01 10:53:52 +0300 | [diff] [blame] | 723 | trim_snb_memory(); |
H. Peter Anvin | 95c9608 | 2013-02-14 14:02:52 -0800 | [diff] [blame] | 724 | } |
Mike Rapoport | a799c2b | 2021-03-02 12:04:05 +0200 | [diff] [blame] | 725 | |
Jeremy Fitzhardinge | 5394f80 | 2008-09-07 01:51:32 -0700 | [diff] [blame] | 726 | /* |
Kees Cook | f32360e | 2013-10-10 17:18:17 -0700 | [diff] [blame] | 727 | * Dump out kernel offset information on panic. |
| 728 | */ |
| 729 | static int |
| 730 | dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) |
| 731 | { |
Borislav Petkov | 78cac48 | 2015-04-01 12:49:52 +0200 | [diff] [blame] | 732 | if (kaslr_enabled()) { |
| 733 | pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n", |
Jiri Kosina | 4545c89 | 2015-04-27 13:17:19 +0200 | [diff] [blame] | 734 | kaslr_offset(), |
Borislav Petkov | 78cac48 | 2015-04-01 12:49:52 +0200 | [diff] [blame] | 735 | __START_KERNEL, |
| 736 | __START_KERNEL_map, |
| 737 | MODULES_VADDR-1); |
| 738 | } else { |
| 739 | pr_emerg("Kernel Offset: disabled\n"); |
| 740 | } |
Kees Cook | f32360e | 2013-10-10 17:18:17 -0700 | [diff] [blame] | 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | * Determine if we were loaded by an EFI loader. If so, then we have also been |
| 747 | * passed the efi memmap, systab, etc., so we should use these data structures |
| 748 | * for initialization. Note, the efi init code path is determined by the |
| 749 | * global efi_enabled. This allows the same kernel image to be used on existing |
| 750 | * systems (with a traditional BIOS) as well as on EFI systems. |
| 751 | */ |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 752 | /* |
| 753 | * setup_arch - architecture-specific boot-time initializations |
| 754 | * |
| 755 | * Note: On x86_64, fixmaps are ready for use even before this is called. |
| 756 | */ |
| 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | void __init setup_arch(char **cmdline_p) |
| 759 | { |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 760 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 762 | |
| 763 | /* |
| 764 | * copy kernel address range established so far and switch |
| 765 | * to the proper swapper page table |
| 766 | */ |
| 767 | clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY, |
| 768 | initial_page_table + KERNEL_PGD_BOUNDARY, |
| 769 | KERNEL_PGD_PTRS); |
| 770 | |
| 771 | load_cr3(swapper_pg_dir); |
Bryan O'Donoghue | 2075244 | 2014-10-07 01:19:48 +0100 | [diff] [blame] | 772 | /* |
| 773 | * Note: Quark X1000 CPUs advertise PGE incorrectly and require |
| 774 | * a cr3 based tlb flush, so the following __flush_tlb_all() |
Ingo Molnar | 360db4a | 2019-11-18 16:03:39 +0100 | [diff] [blame] | 775 | * will not flush anything because the CPU quirk which clears |
Bryan O'Donoghue | 2075244 | 2014-10-07 01:19:48 +0100 | [diff] [blame] | 776 | * X86_FEATURE_PGE has not been invoked yet. Though due to the |
| 777 | * load_cr3() above the TLB has been flushed already. The |
| 778 | * quirk is invoked before subsequent calls to __flush_tlb_all() |
| 779 | * so proper operation is guaranteed. |
| 780 | */ |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 781 | __flush_tlb_all(); |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 782 | #else |
| 783 | printk(KERN_INFO "Command line: %s\n", boot_command_line); |
Kirill A. Shutemov | 162434e | 2018-02-14 14:16:54 +0300 | [diff] [blame] | 784 | boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 785 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Alok Kataria | 9863c90 | 2010-08-23 14:49:11 -0700 | [diff] [blame] | 787 | /* |
| 788 | * If we have OLPC OFW, we might end up relocating the fixmap due to |
| 789 | * reserve_top(), so do this before touching the ioremap area. |
| 790 | */ |
Andres Salomon | fd699c7 | 2010-06-18 17:46:53 -0400 | [diff] [blame] | 791 | olpc_ofw_detect(); |
| 792 | |
Thomas Gleixner | 433f892 | 2017-08-28 08:47:50 +0200 | [diff] [blame] | 793 | idt_setup_early_traps(); |
Jeremy Fitzhardinge | 9e882c9 | 2008-07-21 16:49:54 -0700 | [diff] [blame] | 794 | early_cpu_init(); |
Pavel Tatashin | 8990cac | 2018-07-19 16:55:28 -0400 | [diff] [blame] | 795 | jump_label_init(); |
Peter Zijlstra | a945c83 | 2020-08-18 15:57:51 +0200 | [diff] [blame] | 796 | static_call_init(); |
Jeremy Fitzhardinge | 1a98fd1 | 2008-06-29 20:02:44 -0700 | [diff] [blame] | 797 | early_ioremap_init(); |
| 798 | |
Andres Salomon | fd699c7 | 2010-06-18 17:46:53 -0400 | [diff] [blame] | 799 | setup_olpc_ofw_pgd(); |
| 800 | |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 801 | ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev); |
| 802 | screen_info = boot_params.screen_info; |
| 803 | edid_info = boot_params.edid_info; |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 804 | #ifdef CONFIG_X86_32 |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 805 | apm_info.bios = boot_params.apm_bios_info; |
| 806 | ist_info = boot_params.ist_info; |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 807 | #endif |
| 808 | saved_video_mode = boot_params.hdr.vid_mode; |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 809 | bootloader_type = boot_params.hdr.type_of_loader; |
H. Peter Anvin | 5031296 | 2009-05-07 16:54:11 -0700 | [diff] [blame] | 810 | if ((bootloader_type >> 4) == 0xe) { |
| 811 | bootloader_type &= 0xf; |
| 812 | bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4; |
| 813 | } |
| 814 | bootloader_version = bootloader_type & 0xf; |
| 815 | bootloader_version |= boot_params.hdr.ext_loader_ver << 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | #ifdef CONFIG_BLK_DEV_RAM |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 818 | rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | #endif |
Yinghai Lu | 7465252 | 2008-06-23 19:53:33 -0700 | [diff] [blame] | 820 | #ifdef CONFIG_EFI |
| 821 | if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, |
Daniel Kiper | 9402973 | 2014-06-30 19:53:03 +0200 | [diff] [blame] | 822 | EFI32_LOADER_SIGNATURE, 4)) { |
Matt Fleming | 3e90959 | 2014-01-15 13:21:22 +0000 | [diff] [blame] | 823 | set_bit(EFI_BOOT, &efi.flags); |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 824 | } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, |
Daniel Kiper | 9402973 | 2014-06-30 19:53:03 +0200 | [diff] [blame] | 825 | EFI64_LOADER_SIGNATURE, 4)) { |
Matt Fleming | 3e90959 | 2014-01-15 13:21:22 +0000 | [diff] [blame] | 826 | set_bit(EFI_BOOT, &efi.flags); |
| 827 | set_bit(EFI_64BIT, &efi.flags); |
Yinghai Lu | 7465252 | 2008-06-23 19:53:33 -0700 | [diff] [blame] | 828 | } |
| 829 | #endif |
| 830 | |
Thomas Gleixner | 42bbdb4 | 2009-08-20 13:04:10 +0200 | [diff] [blame] | 831 | x86_init.oem.arch_setup(); |
Huang, Ying | 2215e69 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 832 | |
Juergen Gross | 8aa83e6 | 2021-09-20 14:04:21 +0200 | [diff] [blame] | 833 | /* |
| 834 | * Do some memory reservations *before* memory is added to memblock, so |
| 835 | * memblock allocations won't overwrite it. |
| 836 | * |
| 837 | * After this point, everything still needed from the boot loader or |
| 838 | * firmware or kernel text should be early reserved or marked not RAM in |
| 839 | * e820. All other memory is free game. |
| 840 | * |
| 841 | * This call needs to happen before e820__memory_setup() which calls the |
| 842 | * xen_memory_setup() on Xen dom0 which relies on the fact that those |
| 843 | * early reservations have happened already. |
| 844 | */ |
| 845 | early_reserve_memory(); |
| 846 | |
Bjorn Helgaas | 419afdf | 2010-10-26 15:41:49 -0600 | [diff] [blame] | 847 | iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; |
Ingo Molnar | 103e206 | 2017-01-28 09:58:49 +0100 | [diff] [blame] | 848 | e820__memory_setup(); |
Yinghai Lu | 28bb223 | 2008-06-30 16:20:54 -0700 | [diff] [blame] | 849 | parse_setup_data(); |
| 850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | copy_edd(); |
| 852 | |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 853 | if (!boot_params.hdr.root_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | root_mountflags &= ~MS_RDONLY; |
Kefeng Wang | 30120d7 | 2021-07-07 18:09:03 -0700 | [diff] [blame] | 855 | setup_initial_init_mm(_text, _etext, _edata, (void *)_brk_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Linus Torvalds | 4046d6e | 2016-04-14 11:18:57 -0700 | [diff] [blame] | 857 | code_resource.start = __pa_symbol(_text); |
| 858 | code_resource.end = __pa_symbol(_etext)-1; |
Kees Cook | a329975 | 2019-10-29 14:13:50 -0700 | [diff] [blame] | 859 | rodata_resource.start = __pa_symbol(__start_rodata); |
| 860 | rodata_resource.end = __pa_symbol(__end_rodata)-1; |
| 861 | data_resource.start = __pa_symbol(_sdata); |
Linus Torvalds | 4046d6e | 2016-04-14 11:18:57 -0700 | [diff] [blame] | 862 | data_resource.end = __pa_symbol(_edata)-1; |
| 863 | bss_resource.start = __pa_symbol(__bss_start); |
| 864 | bss_resource.end = __pa_symbol(__bss_stop)-1; |
| 865 | |
Tim Bird | 516cbf3 | 2008-08-12 12:52:36 -0700 | [diff] [blame] | 866 | #ifdef CONFIG_CMDLINE_BOOL |
| 867 | #ifdef CONFIG_CMDLINE_OVERRIDE |
| 868 | strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); |
| 869 | #else |
| 870 | if (builtin_cmdline[0]) { |
| 871 | /* append boot loader cmdline to builtin */ |
| 872 | strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); |
| 873 | strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); |
| 874 | strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); |
| 875 | } |
| 876 | #endif |
| 877 | #endif |
| 878 | |
Yinghai Lu | eda6da9 | 2009-09-19 11:07:57 -0700 | [diff] [blame] | 879 | strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); |
| 880 | *cmdline_p = command_line; |
| 881 | |
Yinghai Lu | eda6da9 | 2009-09-19 11:07:57 -0700 | [diff] [blame] | 882 | /* |
Kees Cook | 4b0f3b8 | 2009-11-13 15:28:17 -0800 | [diff] [blame] | 883 | * x86_configure_nx() is called before parse_early_param() to detect |
| 884 | * whether hardware doesn't support NX (so that the early EHCI debug |
| 885 | * console setup can safely call set_fixmap()). It may then be called |
| 886 | * again from within noexec_setup() during parsing early parameters |
| 887 | * to honor the respective command line option. |
Yinghai Lu | eda6da9 | 2009-09-19 11:07:57 -0700 | [diff] [blame] | 888 | */ |
H. Peter Anvin | 4763ed4 | 2009-11-13 15:28:16 -0800 | [diff] [blame] | 889 | x86_configure_nx(); |
Yinghai Lu | eda6da9 | 2009-09-19 11:07:57 -0700 | [diff] [blame] | 890 | |
| 891 | parse_early_param(); |
| 892 | |
Reza Arbab | 39fa104d | 2016-12-12 16:42:55 -0800 | [diff] [blame] | 893 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 894 | /* |
| 895 | * Memory used by the kernel cannot be hot-removed because Linux |
| 896 | * cannot migrate the kernel pages. When memory hotplug is |
| 897 | * enabled, we should prevent memblock from allocating memory |
| 898 | * for the kernel. |
| 899 | * |
| 900 | * ACPI SRAT records all hotpluggable memory ranges. But before |
| 901 | * SRAT is parsed, we don't know about it. |
| 902 | * |
| 903 | * The kernel image is loaded into memory at very early time. We |
| 904 | * cannot prevent this anyway. So on NUMA system, we set any |
| 905 | * node the kernel resides in as un-hotpluggable. |
| 906 | * |
| 907 | * Since on modern servers, one node could have double-digit |
| 908 | * gigabytes memory, we can assume the memory around the kernel |
| 909 | * image is also un-hotpluggable. So before SRAT is parsed, just |
| 910 | * allocate memory near the kernel image to try the best to keep |
| 911 | * the kernel away from hotpluggable memory. |
| 912 | */ |
| 913 | if (movable_node_is_enabled()) |
| 914 | memblock_set_bottom_up(true); |
| 915 | #endif |
| 916 | |
Kees Cook | 4b0f3b8 | 2009-11-13 15:28:17 -0800 | [diff] [blame] | 917 | x86_report_nx(); |
Jeremy Fitzhardinge | 0ad5bce | 2008-09-11 16:42:00 -0700 | [diff] [blame] | 918 | |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 919 | if (acpi_mps_check()) { |
Ingo Molnar | 3eb11ed | 2008-06-23 22:19:22 +0200 | [diff] [blame] | 920 | #ifdef CONFIG_X86_LOCAL_APIC |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 921 | disable_apic = 1; |
| 922 | #endif |
Yinghai Lu | 988781d | 2008-07-21 11:21:43 -0700 | [diff] [blame] | 923 | setup_clear_cpu_cap(X86_FEATURE_APIC); |
Yinghai Lu | 3c999f1 | 2008-06-20 16:11:20 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Ingo Molnar | 1a12703 | 2017-01-28 22:27:28 +0100 | [diff] [blame] | 926 | e820__reserve_setup_data(); |
Ingo Molnar | 9641bda | 2017-01-28 13:37:17 +0100 | [diff] [blame] | 927 | e820__finish_early_params(); |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 928 | |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 929 | if (efi_enabled(EFI_BOOT)) |
Brian Maly | ff0c087 | 2009-03-03 21:55:31 -0500 | [diff] [blame] | 930 | efi_init(); |
| 931 | |
Robert Richter | 0fca081 | 2019-03-28 20:34:28 +0100 | [diff] [blame] | 932 | dmi_setup(); |
Yinghai Lu | 2216d19 | 2008-09-22 02:52:26 -0700 | [diff] [blame] | 933 | |
Alok Kataria | 88b094f | 2008-10-27 10:41:46 -0700 | [diff] [blame] | 934 | /* |
| 935 | * VMware detection requires dmi to be available, so this |
Robert Richter | 0fca081 | 2019-03-28 20:34:28 +0100 | [diff] [blame] | 936 | * needs to be done after dmi_setup(), for the boot CPU. |
Alok Kataria | 88b094f | 2008-10-27 10:41:46 -0700 | [diff] [blame] | 937 | */ |
Thomas Gleixner | 2d82640 | 2009-08-20 17:06:25 +0200 | [diff] [blame] | 938 | init_hypervisor_platform(); |
Alok Kataria | 88b094f | 2008-10-27 10:41:46 -0700 | [diff] [blame] | 939 | |
Pavel Tatashin | cf7a63e | 2018-07-19 16:55:38 -0400 | [diff] [blame] | 940 | tsc_early_init(); |
Thomas Gleixner | f7cf5a5 | 2009-08-19 14:43:56 +0200 | [diff] [blame] | 941 | x86_init.resources.probe_roms(); |
Yinghai Lu | 41c094f | 2008-06-16 13:03:31 -0700 | [diff] [blame] | 942 | |
Linus Torvalds | 4046d6e | 2016-04-14 11:18:57 -0700 | [diff] [blame] | 943 | /* after parse_early_param, so could debug it */ |
| 944 | insert_resource(&iomem_resource, &code_resource); |
Kees Cook | a329975 | 2019-10-29 14:13:50 -0700 | [diff] [blame] | 945 | insert_resource(&iomem_resource, &rodata_resource); |
Linus Torvalds | 4046d6e | 2016-04-14 11:18:57 -0700 | [diff] [blame] | 946 | insert_resource(&iomem_resource, &data_resource); |
| 947 | insert_resource(&iomem_resource, &bss_resource); |
| 948 | |
Yinghai Lu | b422a30 | 2013-01-24 12:19:45 -0800 | [diff] [blame] | 949 | e820_add_kernel_range(); |
Yinghai Lu | 1b5576e | 2010-01-22 11:21:04 +0800 | [diff] [blame] | 950 | trim_bios_range(); |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 951 | #ifdef CONFIG_X86_32 |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 952 | if (ppro_with_ram_bug()) { |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 953 | e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM, |
| 954 | E820_TYPE_RESERVED); |
Ingo Molnar | f9748fa | 2017-01-28 18:00:35 +0100 | [diff] [blame] | 955 | e820__update_table(e820_table); |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 956 | printk(KERN_INFO "fixed physical RAM map:\n"); |
Ingo Molnar | be0c3f0 | 2017-01-28 14:24:02 +0100 | [diff] [blame] | 957 | e820__print_table("bad_ppro"); |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 958 | } |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 959 | #else |
| 960 | early_gart_iommu_check(); |
| 961 | #endif |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 962 | |
Yinghai Lu | 7b2a0a6 | 2008-06-03 19:35:04 -0700 | [diff] [blame] | 963 | /* |
| 964 | * partially used pages are not usable - thus |
| 965 | * we are rounding upwards: |
| 966 | */ |
Ingo Molnar | 0c6fc11 | 2017-01-28 22:52:16 +0100 | [diff] [blame] | 967 | max_pfn = e820__end_of_ram_pfn(); |
Yinghai Lu | 7b2a0a6 | 2008-06-03 19:35:04 -0700 | [diff] [blame] | 968 | |
Yinghai Lu | 093af8d | 2008-01-30 13:33:32 +0100 | [diff] [blame] | 969 | /* update e820 for memory not covered by WB MTRRs */ |
| 970 | mtrr_bp_init(); |
Yinghai Lu | 2dc807b | 2008-07-08 18:56:38 -0700 | [diff] [blame] | 971 | if (mtrr_trim_uncached_memory(max_pfn)) |
Ingo Molnar | 0c6fc11 | 2017-01-28 22:52:16 +0100 | [diff] [blame] | 972 | max_pfn = e820__end_of_ram_pfn(); |
Yinghai Lu | 76c32418 | 2008-03-23 00:16:49 -0700 | [diff] [blame] | 973 | |
Igor Mammedov | 8dd3303 | 2015-12-04 14:07:05 +0100 | [diff] [blame] | 974 | max_possible_pfn = max_pfn; |
| 975 | |
Thomas Garnier | c7d2361 | 2016-08-09 10:11:04 -0700 | [diff] [blame] | 976 | /* |
Mikulas Patocka | 99c13b8 | 2017-07-04 19:04:23 -0400 | [diff] [blame] | 977 | * This call is required when the CPU does not support PAT. If |
| 978 | * mtrr_bp_init() invoked it already via pat_init() the call has no |
| 979 | * effect. |
| 980 | */ |
| 981 | init_cache_modes(); |
| 982 | |
| 983 | /* |
Thomas Garnier | c7d2361 | 2016-08-09 10:11:04 -0700 | [diff] [blame] | 984 | * Define random base addresses for memory sections after max_pfn is |
| 985 | * defined and before each memory section base is used. |
| 986 | */ |
| 987 | kernel_randomize_memory(); |
| 988 | |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 989 | #ifdef CONFIG_X86_32 |
Yinghai Lu | 4e29684 | 2008-06-24 12:18:14 -0700 | [diff] [blame] | 990 | /* max_low_pfn get updated here */ |
Yinghai Lu | 2ec65f8 | 2008-06-23 03:05:30 -0700 | [diff] [blame] | 991 | find_low_pfn_range(); |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 992 | #else |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 993 | check_x2apic(); |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 994 | |
| 995 | /* How many end-of-memory variables you have, grandma! */ |
| 996 | /* need this before calling reserve_initrd */ |
Yinghai Lu | f361a45 | 2008-07-10 20:38:26 -0700 | [diff] [blame] | 997 | if (max_pfn > (1UL<<(32 - PAGE_SHIFT))) |
Ingo Molnar | 0c6fc11 | 2017-01-28 22:52:16 +0100 | [diff] [blame] | 998 | max_low_pfn = e820__end_of_low_ram_pfn(); |
Yinghai Lu | f361a45 | 2008-07-10 20:38:26 -0700 | [diff] [blame] | 999 | else |
| 1000 | max_low_pfn = max_pfn; |
| 1001 | |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 1002 | high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; |
| 1003 | #endif |
Yinghai Lu | 2ec65f8 | 2008-06-23 03:05:30 -0700 | [diff] [blame] | 1004 | |
Yinghai Lu | 893f38d | 2009-12-10 13:07:22 -0800 | [diff] [blame] | 1005 | /* |
| 1006 | * Find and reserve possible boot-time SMP configuration: |
| 1007 | */ |
| 1008 | find_smp_config(); |
| 1009 | |
Yinghai Lu | 8d57470 | 2012-11-16 19:38:58 -0800 | [diff] [blame] | 1010 | early_alloc_pgt_buf(); |
| 1011 | |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 1012 | /* |
Ingo Molnar | 4918e22 | 2017-01-28 11:37:42 +0100 | [diff] [blame] | 1013 | * Need to conclude brk, before e820__memblock_setup() |
Cao jin | 81519f7 | 2021-03-11 16:39:19 +0800 | [diff] [blame] | 1014 | * it could use memblock_find_in_range, could overlap with |
| 1015 | * brk area. |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 1016 | */ |
| 1017 | reserve_brk(); |
| 1018 | |
Yinghai Lu | e5f15b4 | 2011-02-18 11:30:30 +0000 | [diff] [blame] | 1019 | cleanup_highmap(); |
| 1020 | |
Tang Chen | 2449f34 | 2013-08-14 11:44:04 +0800 | [diff] [blame] | 1021 | memblock_set_current_limit(ISA_END_ADDRESS); |
Ingo Molnar | 4918e22 | 2017-01-28 11:37:42 +0100 | [diff] [blame] | 1022 | e820__memblock_setup(); |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 1023 | |
Ashish Kalra | e998879 | 2020-12-10 01:25:15 +0000 | [diff] [blame] | 1024 | /* |
| 1025 | * Needs to run after memblock setup because it needs the physical |
| 1026 | * memory size. |
| 1027 | */ |
| 1028 | sev_setup_arch(); |
| 1029 | |
Dan Williams | 6950e31 | 2019-11-06 17:43:05 -0800 | [diff] [blame] | 1030 | efi_fake_memmap(); |
| 1031 | efi_find_mirror(); |
| 1032 | efi_esrt_init(); |
Lenny Szubowicz | 58c9090 | 2020-09-04 21:31:05 -0400 | [diff] [blame] | 1033 | efi_mokvar_table_init(); |
Matt Fleming | 4971531 | 2016-06-21 23:11:38 +0100 | [diff] [blame] | 1034 | |
Dan Williams | 6950e31 | 2019-11-06 17:43:05 -0800 | [diff] [blame] | 1035 | /* |
| 1036 | * The EFI specification says that boot service code won't be |
| 1037 | * called after ExitBootServices(). This is, in fact, a lie. |
| 1038 | */ |
| 1039 | efi_reserve_boot_services(); |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 1040 | |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 1041 | /* preallocate 4k for mptable mpc */ |
Ingo Molnar | 5da217c | 2017-01-28 13:46:28 +0100 | [diff] [blame] | 1042 | e820__memblock_alloc_reserved_mpc_new(); |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 1043 | |
| 1044 | #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION |
| 1045 | setup_bios_corruption_check(); |
| 1046 | #endif |
| 1047 | |
Yinghai Lu | 1005423 | 2013-01-24 12:19:54 -0800 | [diff] [blame] | 1048 | #ifdef CONFIG_X86_32 |
Bjorn Helgaas | 365811d | 2012-05-29 15:06:29 -0700 | [diff] [blame] | 1049 | printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n", |
| 1050 | (max_pfn_mapped<<PAGE_SHIFT) - 1); |
Yinghai Lu | 1005423 | 2013-01-24 12:19:54 -0800 | [diff] [blame] | 1051 | #endif |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 1052 | |
Mike Rapoport | c361e5d | 2021-04-13 21:08:39 +0300 | [diff] [blame] | 1053 | /* |
Borislav Petkov | ec35d1d | 2021-06-08 22:17:10 +0200 | [diff] [blame] | 1054 | * Find free memory for the real mode trampoline and place it there. If |
| 1055 | * there is not enough free memory under 1M, on EFI-enabled systems |
| 1056 | * there will be additional attempt to reclaim the memory for the real |
| 1057 | * mode trampoline at efi_free_boot_services(). |
Mike Rapoport | f1d4d47 | 2021-06-01 10:53:52 +0300 | [diff] [blame] | 1058 | * |
Borislav Petkov | ec35d1d | 2021-06-08 22:17:10 +0200 | [diff] [blame] | 1059 | * Unconditionally reserve the entire first 1M of RAM because BIOSes |
| 1060 | * are known to corrupt low memory and several hundred kilobytes are not |
| 1061 | * worth complex detection what memory gets clobbered. Windows does the |
| 1062 | * same thing for very similar reasons. |
| 1063 | * |
| 1064 | * Moreover, on machines with SandyBridge graphics or in setups that use |
| 1065 | * crashkernel the entire 1M is reserved anyway. |
Mike Rapoport | c361e5d | 2021-04-13 21:08:39 +0300 | [diff] [blame] | 1066 | */ |
Mike Rapoport | f1d4d47 | 2021-06-01 10:53:52 +0300 | [diff] [blame] | 1067 | reserve_real_mode(); |
Jesse Barnes | a9acc53 | 2012-11-14 20:43:31 +0000 | [diff] [blame] | 1068 | |
Yinghai Lu | 22ddfca | 2012-11-16 19:38:41 -0800 | [diff] [blame] | 1069 | init_mem_mapping(); |
Pekka J Enberg | 854c879 | 2009-06-22 17:39:41 +0300 | [diff] [blame] | 1070 | |
Thomas Gleixner | 433f892 | 2017-08-28 08:47:50 +0200 | [diff] [blame] | 1071 | idt_setup_early_pf(); |
Jarkko Sakkinen | cda846f | 2012-05-08 21:22:46 +0300 | [diff] [blame] | 1072 | |
Andy Lutomirski | 18bc7bd | 2016-08-10 02:29:14 -0700 | [diff] [blame] | 1073 | /* |
| 1074 | * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) |
| 1075 | * with the current CR4 value. This may not be necessary, but |
| 1076 | * auditing all the early-boot CR4 manipulation would be needed to |
| 1077 | * rule it out. |
Andy Lutomirski | c7ad5ad | 2017-09-10 17:48:27 -0700 | [diff] [blame] | 1078 | * |
| 1079 | * Mask off features that don't work outside long mode (just |
| 1080 | * PCIDE for now). |
Andy Lutomirski | 18bc7bd | 2016-08-10 02:29:14 -0700 | [diff] [blame] | 1081 | */ |
Andy Lutomirski | c7ad5ad | 2017-09-10 17:48:27 -0700 | [diff] [blame] | 1082 | mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE; |
Andy Lutomirski | 18bc7bd | 2016-08-10 02:29:14 -0700 | [diff] [blame] | 1083 | |
Yinghai Lu | 4ce7a86 | 2014-01-27 17:06:50 -0800 | [diff] [blame] | 1084 | memblock_set_current_limit(get_max_mapped()); |
Yinghai Lu | e7b3789 | 2008-06-25 21:51:28 -0700 | [diff] [blame] | 1085 | |
| 1086 | /* |
| 1087 | * NOTE: On x86-32, only from this point on, fixmaps are ready for use. |
| 1088 | */ |
| 1089 | |
| 1090 | #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT |
| 1091 | if (init_ohci1394_dma_early) |
Mike Travis | 162a7e7 | 2011-05-24 17:13:20 -0700 | [diff] [blame] | 1092 | init_ohci1394_dma_on_all_controllers(); |
| 1093 | #endif |
Yinghai Lu | e7b3789 | 2008-06-25 21:51:28 -0700 | [diff] [blame] | 1094 | /* Allocate bigger log buffer */ |
Yinghai Lu | 2ec65f8 | 2008-06-23 03:05:30 -0700 | [diff] [blame] | 1095 | setup_log_buf(1); |
| 1096 | |
David Howells | 9661b33 | 2017-02-06 11:22:45 +0000 | [diff] [blame] | 1097 | if (efi_enabled(EFI_BOOT)) { |
| 1098 | switch (boot_params.secure_boot) { |
| 1099 | case efi_secureboot_mode_disabled: |
| 1100 | pr_info("Secure boot disabled\n"); |
| 1101 | break; |
| 1102 | case efi_secureboot_mode_enabled: |
| 1103 | pr_info("Secure boot enabled\n"); |
| 1104 | break; |
| 1105 | default: |
| 1106 | pr_info("Secure boot could not be determined\n"); |
| 1107 | break; |
| 1108 | } |
| 1109 | } |
| 1110 | |
Yinghai Lu | 4428073 | 2009-11-22 17:18:49 -0800 | [diff] [blame] | 1111 | reserve_initrd(); |
| 1112 | |
Aleksey Makarov | da3d3f9 | 2016-06-20 13:56:10 +0300 | [diff] [blame] | 1113 | acpi_table_upgrade(); |
Rafael J. Wysocki | 6998a88 | 2021-04-13 16:01:00 +0200 | [diff] [blame] | 1114 | /* Look for ACPI tables and reserve memory occupied by them. */ |
| 1115 | acpi_boot_table_init(); |
Yinghai Lu | 1c6e550 | 2008-06-17 15:41:45 -0700 | [diff] [blame] | 1116 | |
Yinghai Lu | 1c6e550 | 2008-06-17 15:41:45 -0700 | [diff] [blame] | 1117 | vsmp_init(); |
| 1118 | |
Yinghai Lu | 1c6e550 | 2008-06-17 15:41:45 -0700 | [diff] [blame] | 1119 | io_delay_init(); |
| 1120 | |
Lukas Wunner | 630b3af | 2017-08-01 14:10:41 +0200 | [diff] [blame] | 1121 | early_platform_quirks(); |
| 1122 | |
Yinghai Lu | 20e6926 | 2013-03-01 14:51:27 -0800 | [diff] [blame] | 1123 | early_acpi_boot_init(); |
| 1124 | |
Bernhard Walle | 91467bd | 2008-07-18 19:07:53 +0200 | [diff] [blame] | 1125 | initmem_init(); |
Weijie Yang | 3c325f8 | 2014-10-24 17:00:34 +0800 | [diff] [blame] | 1126 | dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); |
Tang Chen | fa591c4 | 2013-11-12 15:08:07 -0800 | [diff] [blame] | 1127 | |
Roman Gushchin | cf11e85 | 2020-04-10 14:32:45 -0700 | [diff] [blame] | 1128 | if (boot_cpu_has(X86_FEATURE_GBPAGES)) |
| 1129 | hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); |
| 1130 | |
Tang Chen | fa591c4 | 2013-11-12 15:08:07 -0800 | [diff] [blame] | 1131 | /* |
| 1132 | * Reserve memory for crash kernel after SRAT is parsed so that it |
| 1133 | * won't consume hotpluggable memory. |
| 1134 | */ |
| 1135 | reserve_crashkernel(); |
| 1136 | |
Glauber de Oliveira Costa | 790c73f | 2008-02-15 17:52:48 -0200 | [diff] [blame] | 1137 | memblock_find_dma_reserve(); |
| 1138 | |
Boris Ostrovsky | ccb6494 | 2017-09-11 14:51:11 -0400 | [diff] [blame] | 1139 | if (!early_xdbc_setup_hardware()) |
| 1140 | early_xdbc_register_console(); |
| 1141 | |
Thomas Gleixner | 030cb6c | 2009-08-20 14:30:02 +0200 | [diff] [blame] | 1142 | x86_init.paging.pagetable_init(); |
Bernhard Kaindl | f212ec4 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 1143 | |
Andrey Ryabinin | ef7f0d6 | 2015-02-13 14:39:25 -0800 | [diff] [blame] | 1144 | kasan_init(); |
| 1145 | |
Andy Lutomirski | d2b6dc6 | 2017-05-08 17:09:10 -0700 | [diff] [blame] | 1146 | /* |
Thomas Gleixner | 945fd17 | 2018-02-28 21:14:26 +0100 | [diff] [blame] | 1147 | * Sync back kernel address range. |
| 1148 | * |
| 1149 | * FIXME: Can the later sync in setup_cpu_entry_areas() replace |
| 1150 | * this call? |
Andy Lutomirski | d2b6dc6 | 2017-05-08 17:09:10 -0700 | [diff] [blame] | 1151 | */ |
Thomas Gleixner | 945fd17 | 2018-02-28 21:14:26 +0100 | [diff] [blame] | 1152 | sync_initial_page_table(); |
Andy Lutomirski | d2b6dc6 | 2017-05-08 17:09:10 -0700 | [diff] [blame] | 1153 | |
Joseph Cihula | 3162534 | 2009-06-30 19:30:59 -0700 | [diff] [blame] | 1154 | tboot_probe(); |
| 1155 | |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 1156 | map_vsyscall(); |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 1157 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1158 | generic_apic_probe(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 1160 | early_quirks(); |
Andy Currid | d44647b | 2006-06-08 00:43:38 -0700 | [diff] [blame] | 1161 | |
Yinghai Lu | 295deae | 2008-06-23 19:55:05 -0700 | [diff] [blame] | 1162 | /* |
| 1163 | * Read APIC and some other early information from ACPI tables. |
| 1164 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | acpi_boot_init(); |
Thomas Gleixner | a906fda | 2011-02-25 16:09:31 +0100 | [diff] [blame] | 1166 | x86_dtb_init(); |
Feng Tang | efafc8b | 2009-08-14 15:23:29 -0400 | [diff] [blame] | 1167 | |
Yinghai Lu | 295deae | 2008-06-23 19:55:05 -0700 | [diff] [blame] | 1168 | /* |
| 1169 | * get boot-time SMP configuration: |
| 1170 | */ |
Baoquan He | a91bf71 | 2016-08-12 14:57:12 +0800 | [diff] [blame] | 1171 | get_smp_config(); |
Yinghai Lu | 76934ed | 2008-06-25 17:52:35 -0700 | [diff] [blame] | 1172 | |
Thomas Gleixner | 1e90a13 | 2016-10-29 13:42:42 +0200 | [diff] [blame] | 1173 | /* |
| 1174 | * Systems w/o ACPI and mptables might not have it mapped the local |
| 1175 | * APIC yet, but prefill_possible_map() might need to access it. |
| 1176 | */ |
| 1177 | init_apic_mappings(); |
| 1178 | |
Yinghai Lu | 329513a | 2008-07-02 18:54:40 -0700 | [diff] [blame] | 1179 | prefill_possible_map(); |
Yinghai Lu | 301e619 | 2008-08-19 20:50:02 -0700 | [diff] [blame] | 1180 | |
Yinghai Lu | 5f4765f | 2008-07-02 18:53:44 -0700 | [diff] [blame] | 1181 | init_cpu_to_node(); |
Jonathan Cameron | 73bf738 | 2020-09-30 22:05:43 +0800 | [diff] [blame] | 1182 | init_gi_nodes(); |
Yinghai Lu | 5f4765f | 2008-07-02 18:53:44 -0700 | [diff] [blame] | 1183 | |
Thomas Gleixner | ca1b886 | 2015-04-24 13:57:48 +0200 | [diff] [blame] | 1184 | io_apic_init_mappings(); |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 1185 | |
Juergen Gross | f361464 | 2017-11-09 14:27:38 +0100 | [diff] [blame] | 1186 | x86_init.hyper.guest_late_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Ingo Molnar | 1506c8d | 2017-01-28 22:41:14 +0100 | [diff] [blame] | 1188 | e820__reserve_resources(); |
Zhimin Gu | cc55f75 | 2018-09-21 14:26:24 +0800 | [diff] [blame] | 1189 | e820__register_nosave_regions(max_pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
Thomas Gleixner | 8fee697 | 2009-08-19 14:55:50 +0200 | [diff] [blame] | 1191 | x86_init.resources.reserve_resources(); |
Yinghai Lu | 41c094f | 2008-06-16 13:03:31 -0700 | [diff] [blame] | 1192 | |
Ingo Molnar | 2df908b | 2017-01-28 14:16:38 +0100 | [diff] [blame] | 1193 | e820__setup_pci_gap(); |
Yinghai Lu | 41c094f | 2008-06-16 13:03:31 -0700 | [diff] [blame] | 1194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | #ifdef CONFIG_VT |
| 1196 | #if defined(CONFIG_VGA_CONSOLE) |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 1197 | if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | conswitchp = &vga_con; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | #endif |
| 1200 | #endif |
Thomas Gleixner | 6f30c1a | 2009-08-20 13:19:57 +0200 | [diff] [blame] | 1201 | x86_init.oem.banner(); |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 1202 | |
Feng Tang | 6b617e2 | 2011-02-15 00:13:31 +0800 | [diff] [blame] | 1203 | x86_init.timers.wallclock_init(); |
| 1204 | |
Borislav Petkov | 9a90ed0 | 2021-05-27 11:02:26 +0200 | [diff] [blame] | 1205 | /* |
| 1206 | * This needs to run before setup_local_APIC() which soft-disables the |
| 1207 | * local APIC temporarily and that masks the thermal LVT interrupt, |
| 1208 | * leading to softlockups on machines which have configured SMI |
| 1209 | * interrupt delivery. |
| 1210 | */ |
| 1211 | therm_lvt_init(); |
| 1212 | |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 1213 | mcheck_init(); |
Jason Baron | f49aa44 | 2010-09-17 11:08:51 -0400 | [diff] [blame] | 1214 | |
John Stultz | b3c869d | 2012-09-04 12:42:27 -0400 | [diff] [blame] | 1215 | register_refined_jiffies(CLOCK_TICK_RATE); |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 1216 | |
| 1217 | #ifdef CONFIG_EFI |
Borislav Petkov | a5d90c9 | 2014-03-04 17:02:17 +0100 | [diff] [blame] | 1218 | if (efi_enabled(EFI_BOOT)) |
| 1219 | efi_apply_memmap_quirks(); |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 1220 | #endif |
Josh Poimboeuf | ee9f8fc | 2017-07-24 18:36:57 -0500 | [diff] [blame] | 1221 | |
| 1222 | unwind_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } |
Ingo Molnar | 5649b7c | 2008-09-16 09:29:09 +0200 | [diff] [blame] | 1224 | |
Ingo Molnar | 9be1b56 | 2009-02-17 23:12:48 +0100 | [diff] [blame] | 1225 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 5649b7c | 2008-09-16 09:29:09 +0200 | [diff] [blame] | 1226 | |
Thomas Gleixner | 8fee697 | 2009-08-19 14:55:50 +0200 | [diff] [blame] | 1227 | static struct resource video_ram_resource = { |
| 1228 | .name = "Video RAM area", |
| 1229 | .start = 0xa0000, |
| 1230 | .end = 0xbffff, |
| 1231 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM |
Ingo Molnar | 9be1b56 | 2009-02-17 23:12:48 +0100 | [diff] [blame] | 1232 | }; |
| 1233 | |
Thomas Gleixner | 8fee697 | 2009-08-19 14:55:50 +0200 | [diff] [blame] | 1234 | void __init i386_reserve_resources(void) |
Ingo Molnar | 9be1b56 | 2009-02-17 23:12:48 +0100 | [diff] [blame] | 1235 | { |
Thomas Gleixner | 8fee697 | 2009-08-19 14:55:50 +0200 | [diff] [blame] | 1236 | request_resource(&iomem_resource, &video_ram_resource); |
| 1237 | reserve_standard_io_resources(); |
Ingo Molnar | 9be1b56 | 2009-02-17 23:12:48 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
Ingo Molnar | 9be1b56 | 2009-02-17 23:12:48 +0100 | [diff] [blame] | 1240 | #endif /* CONFIG_X86_32 */ |
Kees Cook | f32360e | 2013-10-10 17:18:17 -0700 | [diff] [blame] | 1241 | |
| 1242 | static struct notifier_block kernel_offset_notifier = { |
| 1243 | .notifier_call = dump_kernel_offset |
| 1244 | }; |
| 1245 | |
| 1246 | static int __init register_kernel_offset_dumper(void) |
| 1247 | { |
| 1248 | atomic_notifier_chain_register(&panic_notifier_list, |
| 1249 | &kernel_offset_notifier); |
| 1250 | return 0; |
| 1251 | } |
| 1252 | __initcall(register_kernel_offset_dumper); |