setup.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 1995 Linus Torvalds
  4. *
  5. * This file contains the setup_arch() code, which handles the architecture-dependent
  6. * parts of early kernel initialization.
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/console.h>
  10. #include <linux/crash_dump.h>
  11. #include <linux/dma-map-ops.h>
  12. #include <linux/dmi.h>
  13. #include <linux/efi.h>
  14. #include <linux/ima.h>
  15. #include <linux/init_ohci1394_dma.h>
  16. #include <linux/initrd.h>
  17. #include <linux/iscsi_ibft.h>
  18. #include <linux/memblock.h>
  19. #include <linux/panic_notifier.h>
  20. #include <linux/pci.h>
  21. #include <linux/root_dev.h>
  22. #include <linux/hugetlb.h>
  23. #include <linux/tboot.h>
  24. #include <linux/usb/xhci-dbgp.h>
  25. #include <linux/static_call.h>
  26. #include <linux/swiotlb.h>
  27. #include <linux/random.h>
  28. #include <uapi/linux/mount.h>
  29. #include <xen/xen.h>
  30. #include <asm/apic.h>
  31. #include <asm/numa.h>
  32. #include <asm/bios_ebda.h>
  33. #include <asm/bugs.h>
  34. #include <asm/cpu.h>
  35. #include <asm/efi.h>
  36. #include <asm/gart.h>
  37. #include <asm/hypervisor.h>
  38. #include <asm/io_apic.h>
  39. #include <asm/kasan.h>
  40. #include <asm/kaslr.h>
  41. #include <asm/mce.h>
  42. #include <asm/memtype.h>
  43. #include <asm/mtrr.h>
  44. #include <asm/realmode.h>
  45. #include <asm/olpc_ofw.h>
  46. #include <asm/pci-direct.h>
  47. #include <asm/prom.h>
  48. #include <asm/proto.h>
  49. #include <asm/thermal.h>
  50. #include <asm/unwind.h>
  51. #include <asm/vsyscall.h>
  52. #include <linux/vmalloc.h>
  53. /*
  54. * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
  55. * max_pfn_mapped: highest directly mapped pfn > 4 GB
  56. *
  57. * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are
  58. * represented by pfn_mapped[].
  59. */
  60. unsigned long max_low_pfn_mapped;
  61. unsigned long max_pfn_mapped;
  62. #ifdef CONFIG_DMI
  63. RESERVE_BRK(dmi_alloc, 65536);
  64. #endif
  65. unsigned long _brk_start = (unsigned long)__brk_base;
  66. unsigned long _brk_end = (unsigned long)__brk_base;
  67. struct boot_params boot_params;
  68. /*
  69. * These are the four main kernel memory regions, we put them into
  70. * the resource tree so that kdump tools and other debugging tools
  71. * recover it:
  72. */
  73. static struct resource rodata_resource = {
  74. .name = "Kernel rodata",
  75. .start = 0,
  76. .end = 0,
  77. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  78. };
  79. static struct resource data_resource = {
  80. .name = "Kernel data",
  81. .start = 0,
  82. .end = 0,
  83. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  84. };
  85. static struct resource code_resource = {
  86. .name = "Kernel code",
  87. .start = 0,
  88. .end = 0,
  89. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  90. };
  91. static struct resource bss_resource = {
  92. .name = "Kernel bss",
  93. .start = 0,
  94. .end = 0,
  95. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  96. };
  97. #ifdef CONFIG_X86_32
  98. /* CPU data as detected by the assembly code in head_32.S */
  99. struct cpuinfo_x86 new_cpu_data;
  100. /* Common CPU data for all CPUs */
  101. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  102. EXPORT_SYMBOL(boot_cpu_data);
  103. unsigned int def_to_bigsmp;
  104. struct apm_info apm_info;
  105. EXPORT_SYMBOL(apm_info);
  106. #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
  107. defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
  108. struct ist_info ist_info;
  109. EXPORT_SYMBOL(ist_info);
  110. #else
  111. struct ist_info ist_info;
  112. #endif
  113. #else
  114. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  115. EXPORT_SYMBOL(boot_cpu_data);
  116. #endif
  117. #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
  118. __visible unsigned long mmu_cr4_features __ro_after_init;
  119. #else
  120. __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE;
  121. #endif
  122. #ifdef CONFIG_IMA
  123. static phys_addr_t ima_kexec_buffer_phys;
  124. static size_t ima_kexec_buffer_size;
  125. #endif
  126. /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
  127. int bootloader_type, bootloader_version;
  128. /*
  129. * Setup options
  130. */
  131. struct screen_info screen_info;
  132. EXPORT_SYMBOL(screen_info);
  133. struct edid_info edid_info;
  134. EXPORT_SYMBOL_GPL(edid_info);
  135. extern int root_mountflags;
  136. unsigned long saved_video_mode;
  137. #define RAMDISK_IMAGE_START_MASK 0x07FF
  138. #define RAMDISK_PROMPT_FLAG 0x8000
  139. #define RAMDISK_LOAD_FLAG 0x4000
  140. static char __initdata command_line[COMMAND_LINE_SIZE];
  141. #ifdef CONFIG_CMDLINE_BOOL
  142. static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  143. #endif
  144. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  145. struct edd edd;
  146. #ifdef CONFIG_EDD_MODULE
  147. EXPORT_SYMBOL(edd);
  148. #endif
  149. /**
  150. * copy_edd() - Copy the BIOS EDD information
  151. * from boot_params into a safe place.
  152. *
  153. */
  154. static inline void __init copy_edd(void)
  155. {
  156. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  157. sizeof(edd.mbr_signature));
  158. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  159. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  160. edd.edd_info_nr = boot_params.eddbuf_entries;
  161. }
  162. #else
  163. static inline void __init copy_edd(void)
  164. {
  165. }
  166. #endif
  167. void * __init extend_brk(size_t size, size_t align)
  168. {
  169. size_t mask = align - 1;
  170. void *ret;
  171. BUG_ON(_brk_start == 0);
  172. BUG_ON(align & mask);
  173. _brk_end = (_brk_end + mask) & ~mask;
  174. BUG_ON((char *)(_brk_end + size) > __brk_limit);
  175. ret = (void *)_brk_end;
  176. _brk_end += size;
  177. memset(ret, 0, size);
  178. return ret;
  179. }
  180. #ifdef CONFIG_X86_32
  181. static void __init cleanup_highmap(void)
  182. {
  183. }
  184. #endif
  185. static void __init reserve_brk(void)
  186. {
  187. if (_brk_end > _brk_start)
  188. memblock_reserve(__pa_symbol(_brk_start),
  189. _brk_end - _brk_start);
  190. /* Mark brk area as locked down and no longer taking any
  191. new allocations */
  192. _brk_start = 0;
  193. }
  194. u64 relocated_ramdisk;
  195. #ifdef CONFIG_BLK_DEV_INITRD
  196. static u64 __init get_ramdisk_image(void)
  197. {
  198. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  199. ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
  200. if (ramdisk_image == 0)
  201. ramdisk_image = phys_initrd_start;
  202. return ramdisk_image;
  203. }
  204. static u64 __init get_ramdisk_size(void)
  205. {
  206. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  207. ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
  208. if (ramdisk_size == 0)
  209. ramdisk_size = phys_initrd_size;
  210. return ramdisk_size;
  211. }
  212. static void __init relocate_initrd(void)
  213. {
  214. /* Assume only end is not page aligned */
  215. u64 ramdisk_image = get_ramdisk_image();
  216. u64 ramdisk_size = get_ramdisk_size();
  217. u64 area_size = PAGE_ALIGN(ramdisk_size);
  218. /* We need to move the initrd down into directly mapped mem */
  219. relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
  220. PFN_PHYS(max_pfn_mapped));
  221. if (!relocated_ramdisk)
  222. panic("Cannot find place for new RAMDISK of size %lld\n",
  223. ramdisk_size);
  224. initrd_start = relocated_ramdisk + PAGE_OFFSET;
  225. initrd_end = initrd_start + ramdisk_size;
  226. printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
  227. relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
  228. copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
  229. printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
  230. " [mem %#010llx-%#010llx]\n",
  231. ramdisk_image, ramdisk_image + ramdisk_size - 1,
  232. relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
  233. }
  234. static void __init early_reserve_initrd(void)
  235. {
  236. /* Assume only end is not page aligned */
  237. u64 ramdisk_image = get_ramdisk_image();
  238. u64 ramdisk_size = get_ramdisk_size();
  239. u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
  240. if (!boot_params.hdr.type_of_loader ||
  241. !ramdisk_image || !ramdisk_size)
  242. return; /* No initrd provided by bootloader */
  243. memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
  244. }
  245. static void __init reserve_initrd(void)
  246. {
  247. /* Assume only end is not page aligned */
  248. u64 ramdisk_image = get_ramdisk_image();
  249. u64 ramdisk_size = get_ramdisk_size();
  250. u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
  251. if (!boot_params.hdr.type_of_loader ||
  252. !ramdisk_image || !ramdisk_size)
  253. return; /* No initrd provided by bootloader */
  254. initrd_start = 0;
  255. printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
  256. ramdisk_end - 1);
  257. if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image),
  258. PFN_DOWN(ramdisk_end))) {
  259. /* All are mapped, easy case */
  260. initrd_start = ramdisk_image + PAGE_OFFSET;
  261. initrd_end = initrd_start + ramdisk_size;
  262. return;
  263. }
  264. relocate_initrd();
  265. memblock_phys_free(ramdisk_image, ramdisk_end - ramdisk_image);
  266. }
  267. #else
  268. static void __init early_reserve_initrd(void)
  269. {
  270. }
  271. static void __init reserve_initrd(void)
  272. {
  273. }
  274. #endif /* CONFIG_BLK_DEV_INITRD */
  275. static void __init add_early_ima_buffer(u64 phys_addr)
  276. {
  277. #ifdef CONFIG_IMA
  278. struct ima_setup_data *data;
  279. data = early_memremap(phys_addr + sizeof(struct setup_data), sizeof(*data));
  280. if (!data) {
  281. pr_warn("setup: failed to memremap ima_setup_data entry\n");
  282. return;
  283. }
  284. if (data->size) {
  285. memblock_reserve(data->addr, data->size);
  286. ima_kexec_buffer_phys = data->addr;
  287. ima_kexec_buffer_size = data->size;
  288. }
  289. early_memunmap(data, sizeof(*data));
  290. #else
  291. pr_warn("Passed IMA kexec data, but CONFIG_IMA not set. Ignoring.\n");
  292. #endif
  293. }
  294. #if defined(CONFIG_HAVE_IMA_KEXEC) && !defined(CONFIG_OF_FLATTREE)
  295. int __init ima_free_kexec_buffer(void)
  296. {
  297. if (!ima_kexec_buffer_size)
  298. return -ENOENT;
  299. memblock_free_late(ima_kexec_buffer_phys,
  300. ima_kexec_buffer_size);
  301. ima_kexec_buffer_phys = 0;
  302. ima_kexec_buffer_size = 0;
  303. return 0;
  304. }
  305. int __init ima_get_kexec_buffer(void **addr, size_t *size)
  306. {
  307. if (!ima_kexec_buffer_size)
  308. return -ENOENT;
  309. *addr = __va(ima_kexec_buffer_phys);
  310. *size = ima_kexec_buffer_size;
  311. return 0;
  312. }
  313. #endif
  314. static void __init parse_setup_data(void)
  315. {
  316. struct setup_data *data;
  317. u64 pa_data, pa_next;
  318. pa_data = boot_params.hdr.setup_data;
  319. while (pa_data) {
  320. u32 data_len, data_type;
  321. data = early_memremap(pa_data, sizeof(*data));
  322. data_len = data->len + sizeof(struct setup_data);
  323. data_type = data->type;
  324. pa_next = data->next;
  325. early_memunmap(data, sizeof(*data));
  326. switch (data_type) {
  327. case SETUP_E820_EXT:
  328. e820__memory_setup_extended(pa_data, data_len);
  329. break;
  330. case SETUP_DTB:
  331. add_dtb(pa_data);
  332. break;
  333. case SETUP_EFI:
  334. parse_efi_setup(pa_data, data_len);
  335. break;
  336. case SETUP_IMA:
  337. add_early_ima_buffer(pa_data);
  338. break;
  339. case SETUP_RNG_SEED:
  340. data = early_memremap(pa_data, data_len);
  341. add_bootloader_randomness(data->data, data->len);
  342. /* Zero seed for forward secrecy. */
  343. memzero_explicit(data->data, data->len);
  344. /* Zero length in case we find ourselves back here by accident. */
  345. memzero_explicit(&data->len, sizeof(data->len));
  346. early_memunmap(data, data_len);
  347. break;
  348. default:
  349. break;
  350. }
  351. pa_data = pa_next;
  352. }
  353. }
  354. static void __init memblock_x86_reserve_range_setup_data(void)
  355. {
  356. struct setup_indirect *indirect;
  357. struct setup_data *data;
  358. u64 pa_data, pa_next;
  359. u32 len;
  360. pa_data = boot_params.hdr.setup_data;
  361. while (pa_data) {
  362. data = early_memremap(pa_data, sizeof(*data));
  363. if (!data) {
  364. pr_warn("setup: failed to memremap setup_data entry\n");
  365. return;
  366. }
  367. len = sizeof(*data);
  368. pa_next = data->next;
  369. memblock_reserve(pa_data, sizeof(*data) + data->len);
  370. if (data->type == SETUP_INDIRECT) {
  371. len += data->len;
  372. early_memunmap(data, sizeof(*data));
  373. data = early_memremap(pa_data, len);
  374. if (!data) {
  375. pr_warn("setup: failed to memremap indirect setup_data\n");
  376. return;
  377. }
  378. indirect = (struct setup_indirect *)data->data;
  379. if (indirect->type != SETUP_INDIRECT)
  380. memblock_reserve(indirect->addr, indirect->len);
  381. }
  382. pa_data = pa_next;
  383. early_memunmap(data, len);
  384. }
  385. }
  386. /*
  387. * --------- Crashkernel reservation ------------------------------
  388. */
  389. /* 16M alignment for crash kernel regions */
  390. #define CRASH_ALIGN SZ_16M
  391. /*
  392. * Keep the crash kernel below this limit.
  393. *
  394. * Earlier 32-bits kernels would limit the kernel to the low 512 MB range
  395. * due to mapping restrictions.
  396. *
  397. * 64-bit kdump kernels need to be restricted to be under 64 TB, which is
  398. * the upper limit of system RAM in 4-level paging mode. Since the kdump
  399. * jump could be from 5-level paging to 4-level paging, the jump will fail if
  400. * the kernel is put above 64 TB, and during the 1st kernel bootup there's
  401. * no good way to detect the paging mode of the target kernel which will be
  402. * loaded for dumping.
  403. */
  404. #ifdef CONFIG_X86_32
  405. # define CRASH_ADDR_LOW_MAX SZ_512M
  406. # define CRASH_ADDR_HIGH_MAX SZ_512M
  407. #else
  408. # define CRASH_ADDR_LOW_MAX SZ_4G
  409. # define CRASH_ADDR_HIGH_MAX SZ_64T
  410. #endif
  411. static int __init reserve_crashkernel_low(void)
  412. {
  413. #ifdef CONFIG_X86_64
  414. unsigned long long base, low_base = 0, low_size = 0;
  415. unsigned long low_mem_limit;
  416. int ret;
  417. low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX);
  418. /* crashkernel=Y,low */
  419. ret = parse_crashkernel_low(boot_command_line, low_mem_limit, &low_size, &base);
  420. if (ret) {
  421. /*
  422. * two parts from kernel/dma/swiotlb.c:
  423. * -swiotlb size: user-specified with swiotlb= or default.
  424. *
  425. * -swiotlb overflow buffer: now hardcoded to 32k. We round it
  426. * to 8M for other buffers that may need to stay low too. Also
  427. * make sure we allocate enough extra low memory so that we
  428. * don't run out of DMA buffers for 32-bit devices.
  429. */
  430. low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20);
  431. } else {
  432. /* passed with crashkernel=0,low ? */
  433. if (!low_size)
  434. return 0;
  435. }
  436. low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX);
  437. if (!low_base) {
  438. pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n",
  439. (unsigned long)(low_size >> 20));
  440. return -ENOMEM;
  441. }
  442. pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n",
  443. (unsigned long)(low_size >> 20),
  444. (unsigned long)(low_base >> 20),
  445. (unsigned long)(low_mem_limit >> 20));
  446. crashk_low_res.start = low_base;
  447. crashk_low_res.end = low_base + low_size - 1;
  448. insert_resource(&iomem_resource, &crashk_low_res);
  449. #endif
  450. return 0;
  451. }
  452. static void __init reserve_crashkernel(void)
  453. {
  454. unsigned long long crash_size, crash_base, total_mem;
  455. bool high = false;
  456. int ret;
  457. if (!IS_ENABLED(CONFIG_KEXEC_CORE))
  458. return;
  459. total_mem = memblock_phys_mem_size();
  460. /* crashkernel=XM */
  461. ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base);
  462. if (ret != 0 || crash_size <= 0) {
  463. /* crashkernel=X,high */
  464. ret = parse_crashkernel_high(boot_command_line, total_mem,
  465. &crash_size, &crash_base);
  466. if (ret != 0 || crash_size <= 0)
  467. return;
  468. high = true;
  469. }
  470. if (xen_pv_domain()) {
  471. pr_info("Ignoring crashkernel for a Xen PV domain\n");
  472. return;
  473. }
  474. /* 0 means: find the address automatically */
  475. if (!crash_base) {
  476. /*
  477. * Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
  478. * crashkernel=x,high reserves memory over 4G, also allocates
  479. * 256M extra low memory for DMA buffers and swiotlb.
  480. * But the extra memory is not required for all machines.
  481. * So try low memory first and fall back to high memory
  482. * unless "crashkernel=size[KMG],high" is specified.
  483. */
  484. if (!high)
  485. crash_base = memblock_phys_alloc_range(crash_size,
  486. CRASH_ALIGN, CRASH_ALIGN,
  487. CRASH_ADDR_LOW_MAX);
  488. if (!crash_base)
  489. crash_base = memblock_phys_alloc_range(crash_size,
  490. CRASH_ALIGN, CRASH_ALIGN,
  491. CRASH_ADDR_HIGH_MAX);
  492. if (!crash_base) {
  493. pr_info("crashkernel reservation failed - No suitable area found.\n");
  494. return;
  495. }
  496. } else {
  497. unsigned long long start;
  498. start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base,
  499. crash_base + crash_size);
  500. if (start != crash_base) {
  501. pr_info("crashkernel reservation failed - memory is in use.\n");
  502. return;
  503. }
  504. }
  505. if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) {
  506. memblock_phys_free(crash_base, crash_size);
  507. return;
  508. }
  509. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n",
  510. (unsigned long)(crash_size >> 20),
  511. (unsigned long)(crash_base >> 20),
  512. (unsigned long)(total_mem >> 20));
  513. crashk_res.start = crash_base;
  514. crashk_res.end = crash_base + crash_size - 1;
  515. insert_resource(&iomem_resource, &crashk_res);
  516. }
  517. static struct resource standard_io_resources[] = {
  518. { .name = "dma1", .start = 0x00, .end = 0x1f,
  519. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  520. { .name = "pic1", .start = 0x20, .end = 0x21,
  521. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  522. { .name = "timer0", .start = 0x40, .end = 0x43,
  523. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  524. { .name = "timer1", .start = 0x50, .end = 0x53,
  525. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  526. { .name = "keyboard", .start = 0x60, .end = 0x60,
  527. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  528. { .name = "keyboard", .start = 0x64, .end = 0x64,
  529. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  530. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  531. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  532. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  533. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  534. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  535. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  536. { .name = "fpu", .start = 0xf0, .end = 0xff,
  537. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  538. };
  539. void __init reserve_standard_io_resources(void)
  540. {
  541. int i;
  542. /* request I/O space for devices used on all i[345]86 PCs */
  543. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  544. request_resource(&ioport_resource, &standard_io_resources[i]);
  545. }
  546. static bool __init snb_gfx_workaround_needed(void)
  547. {
  548. #ifdef CONFIG_PCI
  549. int i;
  550. u16 vendor, devid;
  551. static const __initconst u16 snb_ids[] = {
  552. 0x0102,
  553. 0x0112,
  554. 0x0122,
  555. 0x0106,
  556. 0x0116,
  557. 0x0126,
  558. 0x010a,
  559. };
  560. /* Assume no if something weird is going on with PCI */
  561. if (!early_pci_allowed())
  562. return false;
  563. vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID);
  564. if (vendor != 0x8086)
  565. return false;
  566. devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID);
  567. for (i = 0; i < ARRAY_SIZE(snb_ids); i++)
  568. if (devid == snb_ids[i])
  569. return true;
  570. #endif
  571. return false;
  572. }
  573. /*
  574. * Sandy Bridge graphics has trouble with certain ranges, exclude
  575. * them from allocation.
  576. */
  577. static void __init trim_snb_memory(void)
  578. {
  579. static const __initconst unsigned long bad_pages[] = {
  580. 0x20050000,
  581. 0x20110000,
  582. 0x20130000,
  583. 0x20138000,
  584. 0x40004000,
  585. };
  586. int i;
  587. if (!snb_gfx_workaround_needed())
  588. return;
  589. printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n");
  590. /*
  591. * SandyBridge integrated graphics devices have a bug that prevents
  592. * them from accessing certain memory ranges, namely anything below
  593. * 1M and in the pages listed in bad_pages[] above.
  594. *
  595. * To avoid these pages being ever accessed by SNB gfx devices reserve
  596. * bad_pages that have not already been reserved at boot time.
  597. * All memory below the 1 MB mark is anyway reserved later during
  598. * setup_arch(), so there is no need to reserve it here.
  599. */
  600. for (i = 0; i < ARRAY_SIZE(bad_pages); i++) {
  601. if (memblock_reserve(bad_pages[i], PAGE_SIZE))
  602. printk(KERN_WARNING "failed to reserve 0x%08lx\n",
  603. bad_pages[i]);
  604. }
  605. }
  606. static void __init trim_bios_range(void)
  607. {
  608. /*
  609. * A special case is the first 4Kb of memory;
  610. * This is a BIOS owned area, not kernel ram, but generally
  611. * not listed as such in the E820 table.
  612. *
  613. * This typically reserves additional memory (64KiB by default)
  614. * since some BIOSes are known to corrupt low memory. See the
  615. * Kconfig help text for X86_RESERVE_LOW.
  616. */
  617. e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
  618. /*
  619. * special case: Some BIOSes report the PC BIOS
  620. * area (640Kb -> 1Mb) as RAM even though it is not.
  621. * take them out.
  622. */
  623. e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1);
  624. e820__update_table(e820_table);
  625. }
  626. /* called before trim_bios_range() to spare extra sanitize */
  627. static void __init e820_add_kernel_range(void)
  628. {
  629. u64 start = __pa_symbol(_text);
  630. u64 size = __pa_symbol(_end) - start;
  631. /*
  632. * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and
  633. * attempt to fix it by adding the range. We may have a confused BIOS,
  634. * or the user may have used memmap=exactmap or memmap=xxM$yyM to
  635. * exclude kernel range. If we really are running on top non-RAM,
  636. * we will crash later anyways.
  637. */
  638. if (e820__mapped_all(start, start + size, E820_TYPE_RAM))
  639. return;
  640. pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n");
  641. e820__range_remove(start, size, E820_TYPE_RAM, 0);
  642. e820__range_add(start, size, E820_TYPE_RAM);
  643. }
  644. static void __init early_reserve_memory(void)
  645. {
  646. /*
  647. * Reserve the memory occupied by the kernel between _text and
  648. * __end_of_kernel_reserve symbols. Any kernel sections after the
  649. * __end_of_kernel_reserve symbol must be explicitly reserved with a
  650. * separate memblock_reserve() or they will be discarded.
  651. */
  652. memblock_reserve(__pa_symbol(_text),
  653. (unsigned long)__end_of_kernel_reserve - (unsigned long)_text);
  654. /*
  655. * The first 4Kb of memory is a BIOS owned area, but generally it is
  656. * not listed as such in the E820 table.
  657. *
  658. * Reserve the first 64K of memory since some BIOSes are known to
  659. * corrupt low memory. After the real mode trampoline is allocated the
  660. * rest of the memory below 640k is reserved.
  661. *
  662. * In addition, make sure page 0 is always reserved because on
  663. * systems with L1TF its contents can be leaked to user processes.
  664. */
  665. memblock_reserve(0, SZ_64K);
  666. early_reserve_initrd();
  667. memblock_x86_reserve_range_setup_data();
  668. reserve_ibft_region();
  669. reserve_bios_regions();
  670. trim_snb_memory();
  671. }
  672. /*
  673. * Dump out kernel offset information on panic.
  674. */
  675. static int
  676. dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
  677. {
  678. if (kaslr_enabled()) {
  679. pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
  680. kaslr_offset(),
  681. __START_KERNEL,
  682. __START_KERNEL_map,
  683. MODULES_VADDR-1);
  684. } else {
  685. pr_emerg("Kernel Offset: disabled\n");
  686. }
  687. return 0;
  688. }
  689. void x86_configure_nx(void)
  690. {
  691. if (boot_cpu_has(X86_FEATURE_NX))
  692. __supported_pte_mask |= _PAGE_NX;
  693. else
  694. __supported_pte_mask &= ~_PAGE_NX;
  695. }
  696. static void __init x86_report_nx(void)
  697. {
  698. if (!boot_cpu_has(X86_FEATURE_NX)) {
  699. printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
  700. "missing in CPU!\n");
  701. } else {
  702. #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  703. printk(KERN_INFO "NX (Execute Disable) protection: active\n");
  704. #else
  705. /* 32bit non-PAE kernel, NX cannot be used */
  706. printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
  707. "cannot be enabled: non-PAE kernel!\n");
  708. #endif
  709. }
  710. }
  711. /*
  712. * 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
  714. * for initialization. Note, the efi init code path is determined by the
  715. * global efi_enabled. This allows the same kernel image to be used on existing
  716. * systems (with a traditional BIOS) as well as on EFI systems.
  717. */
  718. /*
  719. * setup_arch - architecture-specific boot-time initializations
  720. *
  721. * Note: On x86_64, fixmaps are ready for use even before this is called.
  722. */
  723. void __init setup_arch(char **cmdline_p)
  724. {
  725. #ifdef CONFIG_X86_32
  726. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  727. /*
  728. * copy kernel address range established so far and switch
  729. * to the proper swapper page table
  730. */
  731. clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  732. initial_page_table + KERNEL_PGD_BOUNDARY,
  733. KERNEL_PGD_PTRS);
  734. load_cr3(swapper_pg_dir);
  735. /*
  736. * Note: Quark X1000 CPUs advertise PGE incorrectly and require
  737. * a cr3 based tlb flush, so the following __flush_tlb_all()
  738. * will not flush anything because the CPU quirk which clears
  739. * X86_FEATURE_PGE has not been invoked yet. Though due to the
  740. * load_cr3() above the TLB has been flushed already. The
  741. * quirk is invoked before subsequent calls to __flush_tlb_all()
  742. * so proper operation is guaranteed.
  743. */
  744. __flush_tlb_all();
  745. #else
  746. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  747. boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS;
  748. #endif
  749. /*
  750. * If we have OLPC OFW, we might end up relocating the fixmap due to
  751. * reserve_top(), so do this before touching the ioremap area.
  752. */
  753. olpc_ofw_detect();
  754. idt_setup_early_traps();
  755. early_cpu_init();
  756. jump_label_init();
  757. static_call_init();
  758. early_ioremap_init();
  759. setup_olpc_ofw_pgd();
  760. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  761. screen_info = boot_params.screen_info;
  762. edid_info = boot_params.edid_info;
  763. #ifdef CONFIG_X86_32
  764. apm_info.bios = boot_params.apm_bios_info;
  765. ist_info = boot_params.ist_info;
  766. #endif
  767. saved_video_mode = boot_params.hdr.vid_mode;
  768. bootloader_type = boot_params.hdr.type_of_loader;
  769. if ((bootloader_type >> 4) == 0xe) {
  770. bootloader_type &= 0xf;
  771. bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4;
  772. }
  773. bootloader_version = bootloader_type & 0xf;
  774. bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
  775. #ifdef CONFIG_BLK_DEV_RAM
  776. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  777. #endif
  778. #ifdef CONFIG_EFI
  779. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  780. EFI32_LOADER_SIGNATURE, 4)) {
  781. set_bit(EFI_BOOT, &efi.flags);
  782. } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  783. EFI64_LOADER_SIGNATURE, 4)) {
  784. set_bit(EFI_BOOT, &efi.flags);
  785. set_bit(EFI_64BIT, &efi.flags);
  786. }
  787. #endif
  788. x86_init.oem.arch_setup();
  789. /*
  790. * Do some memory reservations *before* memory is added to memblock, so
  791. * memblock allocations won't overwrite it.
  792. *
  793. * After this point, everything still needed from the boot loader or
  794. * firmware or kernel text should be early reserved or marked not RAM in
  795. * e820. All other memory is free game.
  796. *
  797. * This call needs to happen before e820__memory_setup() which calls the
  798. * xen_memory_setup() on Xen dom0 which relies on the fact that those
  799. * early reservations have happened already.
  800. */
  801. early_reserve_memory();
  802. iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
  803. e820__memory_setup();
  804. parse_setup_data();
  805. copy_edd();
  806. if (!boot_params.hdr.root_flags)
  807. root_mountflags &= ~MS_RDONLY;
  808. setup_initial_init_mm(_text, _etext, _edata, (void *)_brk_end);
  809. code_resource.start = __pa_symbol(_text);
  810. code_resource.end = __pa_symbol(_etext)-1;
  811. rodata_resource.start = __pa_symbol(__start_rodata);
  812. rodata_resource.end = __pa_symbol(__end_rodata)-1;
  813. data_resource.start = __pa_symbol(_sdata);
  814. data_resource.end = __pa_symbol(_edata)-1;
  815. bss_resource.start = __pa_symbol(__bss_start);
  816. bss_resource.end = __pa_symbol(__bss_stop)-1;
  817. #ifdef CONFIG_CMDLINE_BOOL
  818. #ifdef CONFIG_CMDLINE_OVERRIDE
  819. strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  820. #else
  821. if (builtin_cmdline[0]) {
  822. /* append boot loader cmdline to builtin */
  823. strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
  824. strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  825. strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  826. }
  827. #endif
  828. #endif
  829. strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  830. *cmdline_p = command_line;
  831. /*
  832. * x86_configure_nx() is called before parse_early_param() to detect
  833. * whether hardware doesn't support NX (so that the early EHCI debug
  834. * console setup can safely call set_fixmap()).
  835. */
  836. x86_configure_nx();
  837. parse_early_param();
  838. if (efi_enabled(EFI_BOOT))
  839. efi_memblock_x86_reserve_range();
  840. #ifdef CONFIG_MEMORY_HOTPLUG
  841. /*
  842. * Memory used by the kernel cannot be hot-removed because Linux
  843. * cannot migrate the kernel pages. When memory hotplug is
  844. * enabled, we should prevent memblock from allocating memory
  845. * for the kernel.
  846. *
  847. * ACPI SRAT records all hotpluggable memory ranges. But before
  848. * SRAT is parsed, we don't know about it.
  849. *
  850. * The kernel image is loaded into memory at very early time. We
  851. * cannot prevent this anyway. So on NUMA system, we set any
  852. * node the kernel resides in as un-hotpluggable.
  853. *
  854. * Since on modern servers, one node could have double-digit
  855. * gigabytes memory, we can assume the memory around the kernel
  856. * image is also un-hotpluggable. So before SRAT is parsed, just
  857. * allocate memory near the kernel image to try the best to keep
  858. * the kernel away from hotpluggable memory.
  859. */
  860. if (movable_node_is_enabled())
  861. memblock_set_bottom_up(true);
  862. #endif
  863. x86_report_nx();
  864. if (acpi_mps_check()) {
  865. #ifdef CONFIG_X86_LOCAL_APIC
  866. disable_apic = 1;
  867. #endif
  868. setup_clear_cpu_cap(X86_FEATURE_APIC);
  869. }
  870. e820__reserve_setup_data();
  871. e820__finish_early_params();
  872. if (efi_enabled(EFI_BOOT))
  873. efi_init();
  874. dmi_setup();
  875. /*
  876. * VMware detection requires dmi to be available, so this
  877. * needs to be done after dmi_setup(), for the boot CPU.
  878. */
  879. init_hypervisor_platform();
  880. tsc_early_init();
  881. x86_init.resources.probe_roms();
  882. /* after parse_early_param, so could debug it */
  883. insert_resource(&iomem_resource, &code_resource);
  884. insert_resource(&iomem_resource, &rodata_resource);
  885. insert_resource(&iomem_resource, &data_resource);
  886. insert_resource(&iomem_resource, &bss_resource);
  887. e820_add_kernel_range();
  888. trim_bios_range();
  889. #ifdef CONFIG_X86_32
  890. if (ppro_with_ram_bug()) {
  891. e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM,
  892. E820_TYPE_RESERVED);
  893. e820__update_table(e820_table);
  894. printk(KERN_INFO "fixed physical RAM map:\n");
  895. e820__print_table("bad_ppro");
  896. }
  897. #else
  898. early_gart_iommu_check();
  899. #endif
  900. /*
  901. * partially used pages are not usable - thus
  902. * we are rounding upwards:
  903. */
  904. max_pfn = e820__end_of_ram_pfn();
  905. /* update e820 for memory not covered by WB MTRRs */
  906. if (IS_ENABLED(CONFIG_MTRR))
  907. mtrr_bp_init();
  908. else
  909. pat_disable("PAT support disabled because CONFIG_MTRR is disabled in the kernel.");
  910. if (mtrr_trim_uncached_memory(max_pfn))
  911. max_pfn = e820__end_of_ram_pfn();
  912. max_possible_pfn = max_pfn;
  913. /*
  914. * This call is required when the CPU does not support PAT. If
  915. * mtrr_bp_init() invoked it already via pat_init() the call has no
  916. * effect.
  917. */
  918. init_cache_modes();
  919. /*
  920. * Define random base addresses for memory sections after max_pfn is
  921. * defined and before each memory section base is used.
  922. */
  923. kernel_randomize_memory();
  924. #ifdef CONFIG_X86_32
  925. /* max_low_pfn get updated here */
  926. find_low_pfn_range();
  927. #else
  928. check_x2apic();
  929. /* How many end-of-memory variables you have, grandma! */
  930. /* need this before calling reserve_initrd */
  931. if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
  932. max_low_pfn = e820__end_of_low_ram_pfn();
  933. else
  934. max_low_pfn = max_pfn;
  935. high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
  936. #endif
  937. /*
  938. * Find and reserve possible boot-time SMP configuration:
  939. */
  940. find_smp_config();
  941. early_alloc_pgt_buf();
  942. /*
  943. * Need to conclude brk, before e820__memblock_setup()
  944. * it could use memblock_find_in_range, could overlap with
  945. * brk area.
  946. */
  947. reserve_brk();
  948. cleanup_highmap();
  949. memblock_set_current_limit(ISA_END_ADDRESS);
  950. e820__memblock_setup();
  951. /*
  952. * Needs to run after memblock setup because it needs the physical
  953. * memory size.
  954. */
  955. sev_setup_arch();
  956. efi_fake_memmap();
  957. efi_find_mirror();
  958. efi_esrt_init();
  959. efi_mokvar_table_init();
  960. /*
  961. * The EFI specification says that boot service code won't be
  962. * called after ExitBootServices(). This is, in fact, a lie.
  963. */
  964. efi_reserve_boot_services();
  965. /* preallocate 4k for mptable mpc */
  966. e820__memblock_alloc_reserved_mpc_new();
  967. #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
  968. setup_bios_corruption_check();
  969. #endif
  970. #ifdef CONFIG_X86_32
  971. printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n",
  972. (max_pfn_mapped<<PAGE_SHIFT) - 1);
  973. #endif
  974. /*
  975. * Find free memory for the real mode trampoline and place it there. If
  976. * there is not enough free memory under 1M, on EFI-enabled systems
  977. * there will be additional attempt to reclaim the memory for the real
  978. * mode trampoline at efi_free_boot_services().
  979. *
  980. * Unconditionally reserve the entire first 1M of RAM because BIOSes
  981. * are known to corrupt low memory and several hundred kilobytes are not
  982. * worth complex detection what memory gets clobbered. Windows does the
  983. * same thing for very similar reasons.
  984. *
  985. * Moreover, on machines with SandyBridge graphics or in setups that use
  986. * crashkernel the entire 1M is reserved anyway.
  987. */
  988. x86_platform.realmode_reserve();
  989. init_mem_mapping();
  990. idt_setup_early_pf();
  991. /*
  992. * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features)
  993. * with the current CR4 value. This may not be necessary, but
  994. * auditing all the early-boot CR4 manipulation would be needed to
  995. * rule it out.
  996. *
  997. * Mask off features that don't work outside long mode (just
  998. * PCIDE for now).
  999. */
  1000. mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE;
  1001. memblock_set_current_limit(get_max_mapped());
  1002. /*
  1003. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  1004. */
  1005. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  1006. if (init_ohci1394_dma_early)
  1007. init_ohci1394_dma_on_all_controllers();
  1008. #endif
  1009. /* Allocate bigger log buffer */
  1010. setup_log_buf(1);
  1011. if (efi_enabled(EFI_BOOT)) {
  1012. switch (boot_params.secure_boot) {
  1013. case efi_secureboot_mode_disabled:
  1014. pr_info("Secure boot disabled\n");
  1015. break;
  1016. case efi_secureboot_mode_enabled:
  1017. pr_info("Secure boot enabled\n");
  1018. break;
  1019. default:
  1020. pr_info("Secure boot could not be determined\n");
  1021. break;
  1022. }
  1023. }
  1024. reserve_initrd();
  1025. acpi_table_upgrade();
  1026. /* Look for ACPI tables and reserve memory occupied by them. */
  1027. acpi_boot_table_init();
  1028. vsmp_init();
  1029. io_delay_init();
  1030. early_platform_quirks();
  1031. early_acpi_boot_init();
  1032. initmem_init();
  1033. dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT);
  1034. if (boot_cpu_has(X86_FEATURE_GBPAGES))
  1035. hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT);
  1036. /*
  1037. * Reserve memory for crash kernel after SRAT is parsed so that it
  1038. * won't consume hotpluggable memory.
  1039. */
  1040. reserve_crashkernel();
  1041. memblock_find_dma_reserve();
  1042. if (!early_xdbc_setup_hardware())
  1043. early_xdbc_register_console();
  1044. x86_init.paging.pagetable_init();
  1045. kasan_init();
  1046. /*
  1047. * Sync back kernel address range.
  1048. *
  1049. * FIXME: Can the later sync in setup_cpu_entry_areas() replace
  1050. * this call?
  1051. */
  1052. sync_initial_page_table();
  1053. tboot_probe();
  1054. map_vsyscall();
  1055. generic_apic_probe();
  1056. early_quirks();
  1057. /*
  1058. * Read APIC and some other early information from ACPI tables.
  1059. */
  1060. acpi_boot_init();
  1061. x86_dtb_init();
  1062. /*
  1063. * get boot-time SMP configuration:
  1064. */
  1065. get_smp_config();
  1066. /*
  1067. * Systems w/o ACPI and mptables might not have it mapped the local
  1068. * APIC yet, but prefill_possible_map() might need to access it.
  1069. */
  1070. init_apic_mappings();
  1071. prefill_possible_map();
  1072. init_cpu_to_node();
  1073. init_gi_nodes();
  1074. io_apic_init_mappings();
  1075. x86_init.hyper.guest_late_init();
  1076. e820__reserve_resources();
  1077. e820__register_nosave_regions(max_pfn);
  1078. x86_init.resources.reserve_resources();
  1079. e820__setup_pci_gap();
  1080. #ifdef CONFIG_VT
  1081. #if defined(CONFIG_VGA_CONSOLE)
  1082. if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  1083. conswitchp = &vga_con;
  1084. #endif
  1085. #endif
  1086. x86_init.oem.banner();
  1087. x86_init.timers.wallclock_init();
  1088. /*
  1089. * This needs to run before setup_local_APIC() which soft-disables the
  1090. * local APIC temporarily and that masks the thermal LVT interrupt,
  1091. * leading to softlockups on machines which have configured SMI
  1092. * interrupt delivery.
  1093. */
  1094. therm_lvt_init();
  1095. mcheck_init();
  1096. register_refined_jiffies(CLOCK_TICK_RATE);
  1097. #ifdef CONFIG_EFI
  1098. if (efi_enabled(EFI_BOOT))
  1099. efi_apply_memmap_quirks();
  1100. #endif
  1101. unwind_init();
  1102. }
  1103. #ifdef CONFIG_X86_32
  1104. static struct resource video_ram_resource = {
  1105. .name = "Video RAM area",
  1106. .start = 0xa0000,
  1107. .end = 0xbffff,
  1108. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  1109. };
  1110. void __init i386_reserve_resources(void)
  1111. {
  1112. request_resource(&iomem_resource, &video_ram_resource);
  1113. reserve_standard_io_resources();
  1114. }
  1115. #endif /* CONFIG_X86_32 */
  1116. static struct notifier_block kernel_offset_notifier = {
  1117. .notifier_call = dump_kernel_offset
  1118. };
  1119. static int __init register_kernel_offset_dumper(void)
  1120. {
  1121. atomic_notifier_chain_register(&panic_notifier_list,
  1122. &kernel_offset_notifier);
  1123. return 0;
  1124. }
  1125. __initcall(register_kernel_offset_dumper);