setup.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. *
  4. * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
  5. *
  6. * Memory region support
  7. * David Parsons <orc@pell.chi.il.us>, July-August 1999
  8. *
  9. * Added E820 sanitization routine (removes overlapping memory regions);
  10. * Brian Moyle <bmoyle@mvista.com>, February 2001
  11. *
  12. * Moved CPU detection code to cpu/${cpu}.c
  13. * Patrick Mochel <mochel@osdl.org>, March 2002
  14. *
  15. * Provisions for empty E820 memory regions (reported by certain BIOSes).
  16. * Alex Achenbach <xela@slit.de>, December 2002.
  17. *
  18. */
  19. /*
  20. * This file handles the architecture-dependent parts of initialization
  21. */
  22. #include <linux/sched.h>
  23. #include <linux/mm.h>
  24. #include <linux/mmzone.h>
  25. #include <linux/screen_info.h>
  26. #include <linux/ioport.h>
  27. #include <linux/acpi.h>
  28. #include <linux/sfi.h>
  29. #include <linux/apm_bios.h>
  30. #include <linux/initrd.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/memblock.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/console.h>
  35. #include <linux/root_dev.h>
  36. #include <linux/highmem.h>
  37. #include <linux/export.h>
  38. #include <linux/efi.h>
  39. #include <linux/init.h>
  40. #include <linux/edd.h>
  41. #include <linux/iscsi_ibft.h>
  42. #include <linux/nodemask.h>
  43. #include <linux/kexec.h>
  44. #include <linux/dmi.h>
  45. #include <linux/pfn.h>
  46. #include <linux/pci.h>
  47. #include <asm/pci-direct.h>
  48. #include <linux/init_ohci1394_dma.h>
  49. #include <linux/kvm_para.h>
  50. #include <linux/dma-contiguous.h>
  51. #include <linux/errno.h>
  52. #include <linux/kernel.h>
  53. #include <linux/stddef.h>
  54. #include <linux/unistd.h>
  55. #include <linux/ptrace.h>
  56. #include <linux/user.h>
  57. #include <linux/delay.h>
  58. #include <linux/kallsyms.h>
  59. #include <linux/cpufreq.h>
  60. #include <linux/dma-mapping.h>
  61. #include <linux/ctype.h>
  62. #include <linux/uaccess.h>
  63. #include <linux/percpu.h>
  64. #include <linux/crash_dump.h>
  65. #include <linux/tboot.h>
  66. #include <linux/jiffies.h>
  67. #include <linux/mem_encrypt.h>
  68. #include <linux/usb/xhci-dbgp.h>
  69. #include <video/edid.h>
  70. #include <asm/mtrr.h>
  71. #include <asm/apic.h>
  72. #include <asm/realmode.h>
  73. #include <asm/e820/api.h>
  74. #include <asm/mpspec.h>
  75. #include <asm/setup.h>
  76. #include <asm/efi.h>
  77. #include <asm/timer.h>
  78. #include <asm/i8259.h>
  79. #include <asm/sections.h>
  80. #include <asm/io_apic.h>
  81. #include <asm/ist.h>
  82. #include <asm/setup_arch.h>
  83. #include <asm/bios_ebda.h>
  84. #include <asm/cacheflush.h>
  85. #include <asm/processor.h>
  86. #include <asm/bugs.h>
  87. #include <asm/kasan.h>
  88. #include <asm/vsyscall.h>
  89. #include <asm/cpu.h>
  90. #include <asm/desc.h>
  91. #include <asm/dma.h>
  92. #include <asm/iommu.h>
  93. #include <asm/gart.h>
  94. #include <asm/mmu_context.h>
  95. #include <asm/proto.h>
  96. #include <asm/paravirt.h>
  97. #include <asm/hypervisor.h>
  98. #include <asm/olpc_ofw.h>
  99. #include <asm/percpu.h>
  100. #include <asm/topology.h>
  101. #include <asm/apicdef.h>
  102. #include <asm/amd_nb.h>
  103. #include <asm/mce.h>
  104. #include <asm/alternative.h>
  105. #include <asm/prom.h>
  106. #include <asm/microcode.h>
  107. #include <asm/mmu_context.h>
  108. #include <asm/kaslr.h>
  109. #include <asm/unwind.h>
  110. /*
  111. * max_low_pfn_mapped: highest direct mapped pfn under 4GB
  112. * max_pfn_mapped: highest direct mapped pfn over 4GB
  113. *
  114. * The direct mapping only covers E820_TYPE_RAM regions, so the ranges and gaps are
  115. * represented by pfn_mapped
  116. */
  117. unsigned long max_low_pfn_mapped;
  118. unsigned long max_pfn_mapped;
  119. #ifdef CONFIG_DMI
  120. RESERVE_BRK(dmi_alloc, 65536);
  121. #endif
  122. static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
  123. unsigned long _brk_end = (unsigned long)__brk_base;
  124. #ifdef CONFIG_X86_64
  125. int default_cpu_present_to_apicid(int mps_cpu)
  126. {
  127. return __default_cpu_present_to_apicid(mps_cpu);
  128. }
  129. int default_check_phys_apicid_present(int phys_apicid)
  130. {
  131. return __default_check_phys_apicid_present(phys_apicid);
  132. }
  133. #endif
  134. struct boot_params boot_params;
  135. /*
  136. * Machine setup..
  137. */
  138. static struct resource data_resource = {
  139. .name = "Kernel data",
  140. .start = 0,
  141. .end = 0,
  142. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  143. };
  144. static struct resource code_resource = {
  145. .name = "Kernel code",
  146. .start = 0,
  147. .end = 0,
  148. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  149. };
  150. static struct resource bss_resource = {
  151. .name = "Kernel bss",
  152. .start = 0,
  153. .end = 0,
  154. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  155. };
  156. #ifdef CONFIG_X86_32
  157. /* cpu data as detected by the assembly code in head_32.S */
  158. struct cpuinfo_x86 new_cpu_data;
  159. /* common cpu data for all cpus */
  160. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  161. EXPORT_SYMBOL(boot_cpu_data);
  162. unsigned int def_to_bigsmp;
  163. /* for MCA, but anyone else can use it if they want */
  164. unsigned int machine_id;
  165. unsigned int machine_submodel_id;
  166. unsigned int BIOS_revision;
  167. struct apm_info apm_info;
  168. EXPORT_SYMBOL(apm_info);
  169. #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
  170. defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
  171. struct ist_info ist_info;
  172. EXPORT_SYMBOL(ist_info);
  173. #else
  174. struct ist_info ist_info;
  175. #endif
  176. #else
  177. struct cpuinfo_x86 boot_cpu_data __read_mostly = {
  178. .x86_phys_bits = MAX_PHYSMEM_BITS,
  179. };
  180. EXPORT_SYMBOL(boot_cpu_data);
  181. #endif
  182. #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
  183. __visible unsigned long mmu_cr4_features __ro_after_init;
  184. #else
  185. __visible unsigned long mmu_cr4_features __ro_after_init = X86_CR4_PAE;
  186. #endif
  187. /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
  188. int bootloader_type, bootloader_version;
  189. /*
  190. * Setup options
  191. */
  192. struct screen_info screen_info;
  193. EXPORT_SYMBOL(screen_info);
  194. struct edid_info edid_info;
  195. EXPORT_SYMBOL_GPL(edid_info);
  196. extern int root_mountflags;
  197. unsigned long saved_video_mode;
  198. #define RAMDISK_IMAGE_START_MASK 0x07FF
  199. #define RAMDISK_PROMPT_FLAG 0x8000
  200. #define RAMDISK_LOAD_FLAG 0x4000
  201. static char __initdata command_line[COMMAND_LINE_SIZE];
  202. #ifdef CONFIG_CMDLINE_BOOL
  203. static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  204. #endif
  205. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  206. struct edd edd;
  207. #ifdef CONFIG_EDD_MODULE
  208. EXPORT_SYMBOL(edd);
  209. #endif
  210. /**
  211. * copy_edd() - Copy the BIOS EDD information
  212. * from boot_params into a safe place.
  213. *
  214. */
  215. static inline void __init copy_edd(void)
  216. {
  217. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  218. sizeof(edd.mbr_signature));
  219. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  220. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  221. edd.edd_info_nr = boot_params.eddbuf_entries;
  222. }
  223. #else
  224. static inline void __init copy_edd(void)
  225. {
  226. }
  227. #endif
  228. void * __init extend_brk(size_t size, size_t align)
  229. {
  230. size_t mask = align - 1;
  231. void *ret;
  232. BUG_ON(_brk_start == 0);
  233. BUG_ON(align & mask);
  234. _brk_end = (_brk_end + mask) & ~mask;
  235. BUG_ON((char *)(_brk_end + size) > __brk_limit);
  236. ret = (void *)_brk_end;
  237. _brk_end += size;
  238. memset(ret, 0, size);
  239. return ret;
  240. }
  241. #ifdef CONFIG_X86_32
  242. static void __init cleanup_highmap(void)
  243. {
  244. }
  245. #endif
  246. static void __init reserve_brk(void)
  247. {
  248. if (_brk_end > _brk_start)
  249. memblock_reserve(__pa_symbol(_brk_start),
  250. _brk_end - _brk_start);
  251. /* Mark brk area as locked down and no longer taking any
  252. new allocations */
  253. _brk_start = 0;
  254. }
  255. u64 relocated_ramdisk;
  256. #ifdef CONFIG_BLK_DEV_INITRD
  257. static u64 __init get_ramdisk_image(void)
  258. {
  259. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  260. ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
  261. return ramdisk_image;
  262. }
  263. static u64 __init get_ramdisk_size(void)
  264. {
  265. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  266. ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
  267. return ramdisk_size;
  268. }
  269. static void __init relocate_initrd(void)
  270. {
  271. /* Assume only end is not page aligned */
  272. u64 ramdisk_image = get_ramdisk_image();
  273. u64 ramdisk_size = get_ramdisk_size();
  274. u64 area_size = PAGE_ALIGN(ramdisk_size);
  275. /* We need to move the initrd down into directly mapped mem */
  276. relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
  277. area_size, PAGE_SIZE);
  278. if (!relocated_ramdisk)
  279. panic("Cannot find place for new RAMDISK of size %lld\n",
  280. ramdisk_size);
  281. /* Note: this includes all the mem currently occupied by
  282. the initrd, we rely on that fact to keep the data intact. */
  283. memblock_reserve(relocated_ramdisk, area_size);
  284. initrd_start = relocated_ramdisk + PAGE_OFFSET;
  285. initrd_end = initrd_start + ramdisk_size;
  286. printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
  287. relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
  288. copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
  289. printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
  290. " [mem %#010llx-%#010llx]\n",
  291. ramdisk_image, ramdisk_image + ramdisk_size - 1,
  292. relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
  293. }
  294. static void __init early_reserve_initrd(void)
  295. {
  296. /* Assume only end is not page aligned */
  297. u64 ramdisk_image = get_ramdisk_image();
  298. u64 ramdisk_size = get_ramdisk_size();
  299. u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
  300. if (!boot_params.hdr.type_of_loader ||
  301. !ramdisk_image || !ramdisk_size)
  302. return; /* No initrd provided by bootloader */
  303. memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
  304. }
  305. static void __init reserve_initrd(void)
  306. {
  307. /* Assume only end is not page aligned */
  308. u64 ramdisk_image = get_ramdisk_image();
  309. u64 ramdisk_size = get_ramdisk_size();
  310. u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
  311. u64 mapped_size;
  312. if (!boot_params.hdr.type_of_loader ||
  313. !ramdisk_image || !ramdisk_size)
  314. return; /* No initrd provided by bootloader */
  315. /*
  316. * If SME is active, this memory will be marked encrypted by the
  317. * kernel when it is accessed (including relocation). However, the
  318. * ramdisk image was loaded decrypted by the bootloader, so make
  319. * sure that it is encrypted before accessing it. For SEV the
  320. * ramdisk will already be encrypted, so only do this for SME.
  321. */
  322. if (sme_active())
  323. sme_early_encrypt(ramdisk_image, ramdisk_end - ramdisk_image);
  324. initrd_start = 0;
  325. mapped_size = memblock_mem_size(max_pfn_mapped);
  326. if (ramdisk_size >= (mapped_size>>1))
  327. panic("initrd too large to handle, "
  328. "disabling initrd (%lld needed, %lld available)\n",
  329. ramdisk_size, mapped_size>>1);
  330. printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
  331. ramdisk_end - 1);
  332. if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image),
  333. PFN_DOWN(ramdisk_end))) {
  334. /* All are mapped, easy case */
  335. initrd_start = ramdisk_image + PAGE_OFFSET;
  336. initrd_end = initrd_start + ramdisk_size;
  337. return;
  338. }
  339. relocate_initrd();
  340. memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
  341. }
  342. #else
  343. static void __init early_reserve_initrd(void)
  344. {
  345. }
  346. static void __init reserve_initrd(void)
  347. {
  348. }
  349. #endif /* CONFIG_BLK_DEV_INITRD */
  350. static void __init parse_setup_data(void)
  351. {
  352. struct setup_data *data;
  353. u64 pa_data, pa_next;
  354. pa_data = boot_params.hdr.setup_data;
  355. while (pa_data) {
  356. u32 data_len, data_type;
  357. data = early_memremap(pa_data, sizeof(*data));
  358. data_len = data->len + sizeof(struct setup_data);
  359. data_type = data->type;
  360. pa_next = data->next;
  361. early_memunmap(data, sizeof(*data));
  362. switch (data_type) {
  363. case SETUP_E820_EXT:
  364. e820__memory_setup_extended(pa_data, data_len);
  365. break;
  366. case SETUP_DTB:
  367. add_dtb(pa_data);
  368. break;
  369. case SETUP_EFI:
  370. parse_efi_setup(pa_data, data_len);
  371. break;
  372. default:
  373. break;
  374. }
  375. pa_data = pa_next;
  376. }
  377. }
  378. static void __init memblock_x86_reserve_range_setup_data(void)
  379. {
  380. struct setup_data *data;
  381. u64 pa_data;
  382. pa_data = boot_params.hdr.setup_data;
  383. while (pa_data) {
  384. data = early_memremap(pa_data, sizeof(*data));
  385. memblock_reserve(pa_data, sizeof(*data) + data->len);
  386. pa_data = data->next;
  387. early_memunmap(data, sizeof(*data));
  388. }
  389. }
  390. /*
  391. * --------- Crashkernel reservation ------------------------------
  392. */
  393. #ifdef CONFIG_KEXEC_CORE
  394. /* 16M alignment for crash kernel regions */
  395. #define CRASH_ALIGN (16 << 20)
  396. /*
  397. * Keep the crash kernel below this limit. On 32 bits earlier kernels
  398. * would limit the kernel to the low 512 MiB due to mapping restrictions.
  399. * On 64bit, old kexec-tools need to under 896MiB.
  400. */
  401. #ifdef CONFIG_X86_32
  402. # define CRASH_ADDR_LOW_MAX (512 << 20)
  403. # define CRASH_ADDR_HIGH_MAX (512 << 20)
  404. #else
  405. # define CRASH_ADDR_LOW_MAX (896UL << 20)
  406. # define CRASH_ADDR_HIGH_MAX MAXMEM
  407. #endif
  408. static int __init reserve_crashkernel_low(void)
  409. {
  410. #ifdef CONFIG_X86_64
  411. unsigned long long base, low_base = 0, low_size = 0;
  412. unsigned long total_low_mem;
  413. int ret;
  414. total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT));
  415. /* crashkernel=Y,low */
  416. ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base);
  417. if (ret) {
  418. /*
  419. * two parts from lib/swiotlb.c:
  420. * -swiotlb size: user-specified with swiotlb= or default.
  421. *
  422. * -swiotlb overflow buffer: now hardcoded to 32k. We round it
  423. * to 8M for other buffers that may need to stay low too. Also
  424. * make sure we allocate enough extra low memory so that we
  425. * don't run out of DMA buffers for 32-bit devices.
  426. */
  427. low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20);
  428. } else {
  429. /* passed with crashkernel=0,low ? */
  430. if (!low_size)
  431. return 0;
  432. }
  433. low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN);
  434. if (!low_base) {
  435. pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n",
  436. (unsigned long)(low_size >> 20));
  437. return -ENOMEM;
  438. }
  439. ret = memblock_reserve(low_base, low_size);
  440. if (ret) {
  441. pr_err("%s: Error reserving crashkernel low memblock.\n", __func__);
  442. return ret;
  443. }
  444. pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n",
  445. (unsigned long)(low_size >> 20),
  446. (unsigned long)(low_base >> 20),
  447. (unsigned long)(total_low_mem >> 20));
  448. crashk_low_res.start = low_base;
  449. crashk_low_res.end = low_base + low_size - 1;
  450. insert_resource(&iomem_resource, &crashk_low_res);
  451. #endif
  452. return 0;
  453. }
  454. static void __init reserve_crashkernel(void)
  455. {
  456. unsigned long long crash_size, crash_base, total_mem;
  457. bool high = false;
  458. int ret;
  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. /* 0 means: find the address automatically */
  471. if (crash_base <= 0) {
  472. /*
  473. * Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
  474. * as old kexec-tools loads bzImage below that, unless
  475. * "crashkernel=size[KMG],high" is specified.
  476. */
  477. crash_base = memblock_find_in_range(CRASH_ALIGN,
  478. high ? CRASH_ADDR_HIGH_MAX
  479. : CRASH_ADDR_LOW_MAX,
  480. crash_size, CRASH_ALIGN);
  481. if (!crash_base) {
  482. pr_info("crashkernel reservation failed - No suitable area found.\n");
  483. return;
  484. }
  485. } else {
  486. unsigned long long start;
  487. start = memblock_find_in_range(crash_base,
  488. crash_base + crash_size,
  489. crash_size, 1 << 20);
  490. if (start != crash_base) {
  491. pr_info("crashkernel reservation failed - memory is in use.\n");
  492. return;
  493. }
  494. }
  495. ret = memblock_reserve(crash_base, crash_size);
  496. if (ret) {
  497. pr_err("%s: Error reserving crashkernel memblock.\n", __func__);
  498. return;
  499. }
  500. if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) {
  501. memblock_free(crash_base, crash_size);
  502. return;
  503. }
  504. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n",
  505. (unsigned long)(crash_size >> 20),
  506. (unsigned long)(crash_base >> 20),
  507. (unsigned long)(total_mem >> 20));
  508. crashk_res.start = crash_base;
  509. crashk_res.end = crash_base + crash_size - 1;
  510. insert_resource(&iomem_resource, &crashk_res);
  511. }
  512. #else
  513. static void __init reserve_crashkernel(void)
  514. {
  515. }
  516. #endif
  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 __init void reserve_ibft_region(void)
  547. {
  548. unsigned long addr, size = 0;
  549. addr = find_ibft_region(&size);
  550. if (size)
  551. memblock_reserve(addr, size);
  552. }
  553. static bool __init snb_gfx_workaround_needed(void)
  554. {
  555. #ifdef CONFIG_PCI
  556. int i;
  557. u16 vendor, devid;
  558. static const __initconst u16 snb_ids[] = {
  559. 0x0102,
  560. 0x0112,
  561. 0x0122,
  562. 0x0106,
  563. 0x0116,
  564. 0x0126,
  565. 0x010a,
  566. };
  567. /* Assume no if something weird is going on with PCI */
  568. if (!early_pci_allowed())
  569. return false;
  570. vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID);
  571. if (vendor != 0x8086)
  572. return false;
  573. devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID);
  574. for (i = 0; i < ARRAY_SIZE(snb_ids); i++)
  575. if (devid == snb_ids[i])
  576. return true;
  577. #endif
  578. return false;
  579. }
  580. /*
  581. * Sandy Bridge graphics has trouble with certain ranges, exclude
  582. * them from allocation.
  583. */
  584. static void __init trim_snb_memory(void)
  585. {
  586. static const __initconst unsigned long bad_pages[] = {
  587. 0x20050000,
  588. 0x20110000,
  589. 0x20130000,
  590. 0x20138000,
  591. 0x40004000,
  592. };
  593. int i;
  594. if (!snb_gfx_workaround_needed())
  595. return;
  596. printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n");
  597. /*
  598. * Reserve all memory below the 1 MB mark that has not
  599. * already been reserved.
  600. */
  601. memblock_reserve(0, 1<<20);
  602. for (i = 0; i < ARRAY_SIZE(bad_pages); i++) {
  603. if (memblock_reserve(bad_pages[i], PAGE_SIZE))
  604. printk(KERN_WARNING "failed to reserve 0x%08lx\n",
  605. bad_pages[i]);
  606. }
  607. }
  608. /*
  609. * Here we put platform-specific memory range workarounds, i.e.
  610. * memory known to be corrupt or otherwise in need to be reserved on
  611. * specific platforms.
  612. *
  613. * If this gets used more widely it could use a real dispatch mechanism.
  614. */
  615. static void __init trim_platform_memory_ranges(void)
  616. {
  617. trim_snb_memory();
  618. }
  619. static void __init trim_bios_range(void)
  620. {
  621. /*
  622. * A special case is the first 4Kb of memory;
  623. * This is a BIOS owned area, not kernel ram, but generally
  624. * not listed as such in the E820 table.
  625. *
  626. * This typically reserves additional memory (64KiB by default)
  627. * since some BIOSes are known to corrupt low memory. See the
  628. * Kconfig help text for X86_RESERVE_LOW.
  629. */
  630. e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
  631. /*
  632. * special case: Some BIOSen report the PC BIOS
  633. * area (640->1Mb) as ram even though it is not.
  634. * take them out.
  635. */
  636. e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1);
  637. e820__update_table(e820_table);
  638. }
  639. /* called before trim_bios_range() to spare extra sanitize */
  640. static void __init e820_add_kernel_range(void)
  641. {
  642. u64 start = __pa_symbol(_text);
  643. u64 size = __pa_symbol(_end) - start;
  644. /*
  645. * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and
  646. * attempt to fix it by adding the range. We may have a confused BIOS,
  647. * or the user may have used memmap=exactmap or memmap=xxM$yyM to
  648. * exclude kernel range. If we really are running on top non-RAM,
  649. * we will crash later anyways.
  650. */
  651. if (e820__mapped_all(start, start + size, E820_TYPE_RAM))
  652. return;
  653. pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n");
  654. e820__range_remove(start, size, E820_TYPE_RAM, 0);
  655. e820__range_add(start, size, E820_TYPE_RAM);
  656. }
  657. static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
  658. static int __init parse_reservelow(char *p)
  659. {
  660. unsigned long long size;
  661. if (!p)
  662. return -EINVAL;
  663. size = memparse(p, &p);
  664. if (size < 4096)
  665. size = 4096;
  666. if (size > 640*1024)
  667. size = 640*1024;
  668. reserve_low = size;
  669. return 0;
  670. }
  671. early_param("reservelow", parse_reservelow);
  672. static void __init trim_low_memory_range(void)
  673. {
  674. memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE));
  675. }
  676. /*
  677. * Dump out kernel offset information on panic.
  678. */
  679. static int
  680. dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
  681. {
  682. if (kaslr_enabled()) {
  683. pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
  684. kaslr_offset(),
  685. __START_KERNEL,
  686. __START_KERNEL_map,
  687. MODULES_VADDR-1);
  688. } else {
  689. pr_emerg("Kernel Offset: disabled\n");
  690. }
  691. return 0;
  692. }
  693. static void __init simple_udelay_calibration(void)
  694. {
  695. unsigned int tsc_khz, cpu_khz;
  696. unsigned long lpj;
  697. if (!boot_cpu_has(X86_FEATURE_TSC))
  698. return;
  699. cpu_khz = x86_platform.calibrate_cpu();
  700. tsc_khz = x86_platform.calibrate_tsc();
  701. tsc_khz = tsc_khz ? : cpu_khz;
  702. if (!tsc_khz)
  703. return;
  704. lpj = tsc_khz * 1000;
  705. do_div(lpj, HZ);
  706. loops_per_jiffy = lpj;
  707. }
  708. /*
  709. * Determine if we were loaded by an EFI loader. If so, then we have also been
  710. * passed the efi memmap, systab, etc., so we should use these data structures
  711. * for initialization. Note, the efi init code path is determined by the
  712. * global efi_enabled. This allows the same kernel image to be used on existing
  713. * systems (with a traditional BIOS) as well as on EFI systems.
  714. */
  715. /*
  716. * setup_arch - architecture-specific boot-time initializations
  717. *
  718. * Note: On x86_64, fixmaps are ready for use even before this is called.
  719. */
  720. void __init setup_arch(char **cmdline_p)
  721. {
  722. memblock_reserve(__pa_symbol(_text),
  723. (unsigned long)__bss_stop - (unsigned long)_text);
  724. early_reserve_initrd();
  725. /*
  726. * At this point everything still needed from the boot loader
  727. * or BIOS or kernel text should be early reserved or marked not
  728. * RAM in e820. All other memory is free game.
  729. */
  730. #ifdef CONFIG_X86_32
  731. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  732. /*
  733. * copy kernel address range established so far and switch
  734. * to the proper swapper page table
  735. */
  736. clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  737. initial_page_table + KERNEL_PGD_BOUNDARY,
  738. KERNEL_PGD_PTRS);
  739. load_cr3(swapper_pg_dir);
  740. /*
  741. * Note: Quark X1000 CPUs advertise PGE incorrectly and require
  742. * a cr3 based tlb flush, so the following __flush_tlb_all()
  743. * will not flush anything because the cpu quirk which clears
  744. * X86_FEATURE_PGE has not been invoked yet. Though due to the
  745. * load_cr3() above the TLB has been flushed already. The
  746. * quirk is invoked before subsequent calls to __flush_tlb_all()
  747. * so proper operation is guaranteed.
  748. */
  749. __flush_tlb_all();
  750. #else
  751. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  752. #endif
  753. /*
  754. * If we have OLPC OFW, we might end up relocating the fixmap due to
  755. * reserve_top(), so do this before touching the ioremap area.
  756. */
  757. olpc_ofw_detect();
  758. idt_setup_early_traps();
  759. early_cpu_init();
  760. early_ioremap_init();
  761. setup_olpc_ofw_pgd();
  762. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  763. screen_info = boot_params.screen_info;
  764. edid_info = boot_params.edid_info;
  765. #ifdef CONFIG_X86_32
  766. apm_info.bios = boot_params.apm_bios_info;
  767. ist_info = boot_params.ist_info;
  768. #endif
  769. saved_video_mode = boot_params.hdr.vid_mode;
  770. bootloader_type = boot_params.hdr.type_of_loader;
  771. if ((bootloader_type >> 4) == 0xe) {
  772. bootloader_type &= 0xf;
  773. bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4;
  774. }
  775. bootloader_version = bootloader_type & 0xf;
  776. bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
  777. #ifdef CONFIG_BLK_DEV_RAM
  778. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  779. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  780. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  781. #endif
  782. #ifdef CONFIG_EFI
  783. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  784. EFI32_LOADER_SIGNATURE, 4)) {
  785. set_bit(EFI_BOOT, &efi.flags);
  786. } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  787. EFI64_LOADER_SIGNATURE, 4)) {
  788. set_bit(EFI_BOOT, &efi.flags);
  789. set_bit(EFI_64BIT, &efi.flags);
  790. }
  791. if (efi_enabled(EFI_BOOT))
  792. efi_memblock_x86_reserve_range();
  793. #endif
  794. x86_init.oem.arch_setup();
  795. iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
  796. e820__memory_setup();
  797. parse_setup_data();
  798. copy_edd();
  799. if (!boot_params.hdr.root_flags)
  800. root_mountflags &= ~MS_RDONLY;
  801. init_mm.start_code = (unsigned long) _text;
  802. init_mm.end_code = (unsigned long) _etext;
  803. init_mm.end_data = (unsigned long) _edata;
  804. init_mm.brk = _brk_end;
  805. mpx_mm_init(&init_mm);
  806. code_resource.start = __pa_symbol(_text);
  807. code_resource.end = __pa_symbol(_etext)-1;
  808. data_resource.start = __pa_symbol(_etext);
  809. data_resource.end = __pa_symbol(_edata)-1;
  810. bss_resource.start = __pa_symbol(__bss_start);
  811. bss_resource.end = __pa_symbol(__bss_stop)-1;
  812. #ifdef CONFIG_CMDLINE_BOOL
  813. #ifdef CONFIG_CMDLINE_OVERRIDE
  814. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  815. #else
  816. if (builtin_cmdline[0]) {
  817. /* append boot loader cmdline to builtin */
  818. strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
  819. strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  820. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  821. }
  822. #endif
  823. #endif
  824. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  825. *cmdline_p = command_line;
  826. /*
  827. * x86_configure_nx() is called before parse_early_param() to detect
  828. * whether hardware doesn't support NX (so that the early EHCI debug
  829. * console setup can safely call set_fixmap()). It may then be called
  830. * again from within noexec_setup() during parsing early parameters
  831. * to honor the respective command line option.
  832. */
  833. x86_configure_nx();
  834. parse_early_param();
  835. #ifdef CONFIG_MEMORY_HOTPLUG
  836. /*
  837. * Memory used by the kernel cannot be hot-removed because Linux
  838. * cannot migrate the kernel pages. When memory hotplug is
  839. * enabled, we should prevent memblock from allocating memory
  840. * for the kernel.
  841. *
  842. * ACPI SRAT records all hotpluggable memory ranges. But before
  843. * SRAT is parsed, we don't know about it.
  844. *
  845. * The kernel image is loaded into memory at very early time. We
  846. * cannot prevent this anyway. So on NUMA system, we set any
  847. * node the kernel resides in as un-hotpluggable.
  848. *
  849. * Since on modern servers, one node could have double-digit
  850. * gigabytes memory, we can assume the memory around the kernel
  851. * image is also un-hotpluggable. So before SRAT is parsed, just
  852. * allocate memory near the kernel image to try the best to keep
  853. * the kernel away from hotpluggable memory.
  854. */
  855. if (movable_node_is_enabled())
  856. memblock_set_bottom_up(true);
  857. #endif
  858. x86_report_nx();
  859. /* after early param, so could get panic from serial */
  860. memblock_x86_reserve_range_setup_data();
  861. if (acpi_mps_check()) {
  862. #ifdef CONFIG_X86_LOCAL_APIC
  863. disable_apic = 1;
  864. #endif
  865. setup_clear_cpu_cap(X86_FEATURE_APIC);
  866. }
  867. #ifdef CONFIG_PCI
  868. if (pci_early_dump_regs)
  869. early_dump_pci_devices();
  870. #endif
  871. e820__reserve_setup_data();
  872. e820__finish_early_params();
  873. if (efi_enabled(EFI_BOOT))
  874. efi_init();
  875. dmi_scan_machine();
  876. dmi_memdev_walk();
  877. dmi_set_dump_stack_arch_desc();
  878. /*
  879. * VMware detection requires dmi to be available, so this
  880. * needs to be done after dmi_scan_machine(), for the boot CPU.
  881. */
  882. init_hypervisor_platform();
  883. simple_udelay_calibration();
  884. x86_init.resources.probe_roms();
  885. /* after parse_early_param, so could debug it */
  886. insert_resource(&iomem_resource, &code_resource);
  887. insert_resource(&iomem_resource, &data_resource);
  888. insert_resource(&iomem_resource, &bss_resource);
  889. e820_add_kernel_range();
  890. trim_bios_range();
  891. #ifdef CONFIG_X86_32
  892. if (ppro_with_ram_bug()) {
  893. e820__range_update(0x70000000ULL, 0x40000ULL, E820_TYPE_RAM,
  894. E820_TYPE_RESERVED);
  895. e820__update_table(e820_table);
  896. printk(KERN_INFO "fixed physical RAM map:\n");
  897. e820__print_table("bad_ppro");
  898. }
  899. #else
  900. early_gart_iommu_check();
  901. #endif
  902. /*
  903. * partially used pages are not usable - thus
  904. * we are rounding upwards:
  905. */
  906. max_pfn = e820__end_of_ram_pfn();
  907. /* update e820 for memory not covered by WB MTRRs */
  908. mtrr_bp_init();
  909. if (mtrr_trim_uncached_memory(max_pfn))
  910. max_pfn = e820__end_of_ram_pfn();
  911. max_possible_pfn = max_pfn;
  912. /*
  913. * This call is required when the CPU does not support PAT. If
  914. * mtrr_bp_init() invoked it already via pat_init() the call has no
  915. * effect.
  916. */
  917. init_cache_modes();
  918. /*
  919. * Define random base addresses for memory sections after max_pfn is
  920. * defined and before each memory section base is used.
  921. */
  922. kernel_randomize_memory();
  923. #ifdef CONFIG_X86_32
  924. /* max_low_pfn get updated here */
  925. find_low_pfn_range();
  926. #else
  927. check_x2apic();
  928. /* How many end-of-memory variables you have, grandma! */
  929. /* need this before calling reserve_initrd */
  930. if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
  931. max_low_pfn = e820__end_of_low_ram_pfn();
  932. else
  933. max_low_pfn = max_pfn;
  934. high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
  935. #endif
  936. /*
  937. * Find and reserve possible boot-time SMP configuration:
  938. */
  939. find_smp_config();
  940. reserve_ibft_region();
  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. if (!early_xdbc_setup_hardware())
  952. early_xdbc_register_console();
  953. reserve_bios_regions();
  954. if (efi_enabled(EFI_MEMMAP)) {
  955. efi_fake_memmap();
  956. efi_find_mirror();
  957. efi_esrt_init();
  958. /*
  959. * The EFI specification says that boot service code won't be
  960. * called after ExitBootServices(). This is, in fact, a lie.
  961. */
  962. efi_reserve_boot_services();
  963. }
  964. /* preallocate 4k for mptable mpc */
  965. e820__memblock_alloc_reserved_mpc_new();
  966. #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
  967. setup_bios_corruption_check();
  968. #endif
  969. #ifdef CONFIG_X86_32
  970. printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n",
  971. (max_pfn_mapped<<PAGE_SHIFT) - 1);
  972. #endif
  973. reserve_real_mode();
  974. trim_platform_memory_ranges();
  975. trim_low_memory_range();
  976. init_mem_mapping();
  977. idt_setup_early_pf();
  978. /*
  979. * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features)
  980. * with the current CR4 value. This may not be necessary, but
  981. * auditing all the early-boot CR4 manipulation would be needed to
  982. * rule it out.
  983. *
  984. * Mask off features that don't work outside long mode (just
  985. * PCIDE for now).
  986. */
  987. mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE;
  988. memblock_set_current_limit(get_max_mapped());
  989. /*
  990. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  991. */
  992. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  993. if (init_ohci1394_dma_early)
  994. init_ohci1394_dma_on_all_controllers();
  995. #endif
  996. /* Allocate bigger log buffer */
  997. setup_log_buf(1);
  998. if (efi_enabled(EFI_BOOT)) {
  999. switch (boot_params.secure_boot) {
  1000. case efi_secureboot_mode_disabled:
  1001. pr_info("Secure boot disabled\n");
  1002. break;
  1003. case efi_secureboot_mode_enabled:
  1004. pr_info("Secure boot enabled\n");
  1005. break;
  1006. default:
  1007. pr_info("Secure boot could not be determined\n");
  1008. break;
  1009. }
  1010. }
  1011. reserve_initrd();
  1012. acpi_table_upgrade();
  1013. vsmp_init();
  1014. io_delay_init();
  1015. early_platform_quirks();
  1016. /*
  1017. * Parse the ACPI tables for possible boot-time SMP configuration.
  1018. */
  1019. acpi_boot_table_init();
  1020. early_acpi_boot_init();
  1021. initmem_init();
  1022. dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT);
  1023. /*
  1024. * Reserve memory for crash kernel after SRAT is parsed so that it
  1025. * won't consume hotpluggable memory.
  1026. */
  1027. reserve_crashkernel();
  1028. memblock_find_dma_reserve();
  1029. #ifdef CONFIG_KVM_GUEST
  1030. kvmclock_init();
  1031. #endif
  1032. x86_init.paging.pagetable_init();
  1033. kasan_init();
  1034. #ifdef CONFIG_X86_32
  1035. /* sync back kernel address range */
  1036. clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
  1037. swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  1038. KERNEL_PGD_PTRS);
  1039. /*
  1040. * sync back low identity map too. It is used for example
  1041. * in the 32-bit EFI stub.
  1042. */
  1043. clone_pgd_range(initial_page_table,
  1044. swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  1045. min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
  1046. #endif
  1047. tboot_probe();
  1048. map_vsyscall();
  1049. generic_apic_probe();
  1050. early_quirks();
  1051. /*
  1052. * Read APIC and some other early information from ACPI tables.
  1053. */
  1054. acpi_boot_init();
  1055. sfi_init();
  1056. x86_dtb_init();
  1057. /*
  1058. * get boot-time SMP configuration:
  1059. */
  1060. get_smp_config();
  1061. /*
  1062. * Systems w/o ACPI and mptables might not have it mapped the local
  1063. * APIC yet, but prefill_possible_map() might need to access it.
  1064. */
  1065. init_apic_mappings();
  1066. prefill_possible_map();
  1067. init_cpu_to_node();
  1068. io_apic_init_mappings();
  1069. x86_init.hyper.guest_late_init();
  1070. e820__reserve_resources();
  1071. e820__register_nosave_regions(max_low_pfn);
  1072. x86_init.resources.reserve_resources();
  1073. e820__setup_pci_gap();
  1074. #ifdef CONFIG_VT
  1075. #if defined(CONFIG_VGA_CONSOLE)
  1076. if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  1077. conswitchp = &vga_con;
  1078. #elif defined(CONFIG_DUMMY_CONSOLE)
  1079. conswitchp = &dummy_con;
  1080. #endif
  1081. #endif
  1082. x86_init.oem.banner();
  1083. x86_init.timers.wallclock_init();
  1084. mcheck_init();
  1085. arch_init_ideal_nops();
  1086. register_refined_jiffies(CLOCK_TICK_RATE);
  1087. #ifdef CONFIG_EFI
  1088. if (efi_enabled(EFI_BOOT))
  1089. efi_apply_memmap_quirks();
  1090. #endif
  1091. unwind_init();
  1092. }
  1093. #ifdef CONFIG_X86_32
  1094. static struct resource video_ram_resource = {
  1095. .name = "Video RAM area",
  1096. .start = 0xa0000,
  1097. .end = 0xbffff,
  1098. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  1099. };
  1100. void __init i386_reserve_resources(void)
  1101. {
  1102. request_resource(&iomem_resource, &video_ram_resource);
  1103. reserve_standard_io_resources();
  1104. }
  1105. #endif /* CONFIG_X86_32 */
  1106. static struct notifier_block kernel_offset_notifier = {
  1107. .notifier_call = dump_kernel_offset
  1108. };
  1109. static int __init register_kernel_offset_dumper(void)
  1110. {
  1111. atomic_notifier_chain_register(&panic_notifier_list,
  1112. &kernel_offset_notifier);
  1113. return 0;
  1114. }
  1115. __initcall(register_kernel_offset_dumper);
  1116. void arch_show_smap(struct seq_file *m, struct vm_area_struct *vma)
  1117. {
  1118. if (!boot_cpu_has(X86_FEATURE_OSPKE))
  1119. return;
  1120. seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma));
  1121. }