setup.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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/module.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 <video/edid.h>
  68. #include <asm/mtrr.h>
  69. #include <asm/apic.h>
  70. #include <asm/realmode.h>
  71. #include <asm/e820.h>
  72. #include <asm/mpspec.h>
  73. #include <asm/setup.h>
  74. #include <asm/efi.h>
  75. #include <asm/timer.h>
  76. #include <asm/i8259.h>
  77. #include <asm/sections.h>
  78. #include <asm/dmi.h>
  79. #include <asm/io_apic.h>
  80. #include <asm/ist.h>
  81. #include <asm/setup_arch.h>
  82. #include <asm/bios_ebda.h>
  83. #include <asm/cacheflush.h>
  84. #include <asm/processor.h>
  85. #include <asm/bugs.h>
  86. #include <asm/vsyscall.h>
  87. #include <asm/cpu.h>
  88. #include <asm/desc.h>
  89. #include <asm/dma.h>
  90. #include <asm/iommu.h>
  91. #include <asm/gart.h>
  92. #include <asm/mmu_context.h>
  93. #include <asm/proto.h>
  94. #include <asm/paravirt.h>
  95. #include <asm/hypervisor.h>
  96. #include <asm/olpc_ofw.h>
  97. #include <asm/percpu.h>
  98. #include <asm/topology.h>
  99. #include <asm/apicdef.h>
  100. #include <asm/amd_nb.h>
  101. #include <asm/mce.h>
  102. #include <asm/alternative.h>
  103. #include <asm/prom.h>
  104. /*
  105. * max_low_pfn_mapped: highest direct mapped pfn under 4GB
  106. * max_pfn_mapped: highest direct mapped pfn over 4GB
  107. *
  108. * The direct mapping only covers E820_RAM regions, so the ranges and gaps are
  109. * represented by pfn_mapped
  110. */
  111. unsigned long max_low_pfn_mapped;
  112. unsigned long max_pfn_mapped;
  113. #ifdef CONFIG_DMI
  114. RESERVE_BRK(dmi_alloc, 65536);
  115. #endif
  116. static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
  117. unsigned long _brk_end = (unsigned long)__brk_base;
  118. #ifdef CONFIG_X86_64
  119. int default_cpu_present_to_apicid(int mps_cpu)
  120. {
  121. return __default_cpu_present_to_apicid(mps_cpu);
  122. }
  123. int default_check_phys_apicid_present(int phys_apicid)
  124. {
  125. return __default_check_phys_apicid_present(phys_apicid);
  126. }
  127. #endif
  128. struct boot_params boot_params;
  129. /*
  130. * Machine setup..
  131. */
  132. static struct resource data_resource = {
  133. .name = "Kernel data",
  134. .start = 0,
  135. .end = 0,
  136. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  137. };
  138. static struct resource code_resource = {
  139. .name = "Kernel code",
  140. .start = 0,
  141. .end = 0,
  142. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  143. };
  144. static struct resource bss_resource = {
  145. .name = "Kernel bss",
  146. .start = 0,
  147. .end = 0,
  148. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  149. };
  150. #ifdef CONFIG_X86_32
  151. /* cpu data as detected by the assembly code in head.S */
  152. struct cpuinfo_x86 new_cpu_data __cpuinitdata = {
  153. .wp_works_ok = -1,
  154. .fdiv_bug = -1,
  155. };
  156. /* common cpu data for all cpus */
  157. struct cpuinfo_x86 boot_cpu_data __read_mostly = {
  158. .wp_works_ok = -1,
  159. .fdiv_bug = -1,
  160. };
  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. unsigned long mmu_cr4_features;
  184. #else
  185. unsigned long mmu_cr4_features = 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. #ifdef CONFIG_BLK_DEV_INITRD
  256. static u64 __init get_ramdisk_image(void)
  257. {
  258. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  259. ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
  260. return ramdisk_image;
  261. }
  262. static u64 __init get_ramdisk_size(void)
  263. {
  264. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  265. ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
  266. return ramdisk_size;
  267. }
  268. #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
  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. u64 ramdisk_here;
  276. unsigned long slop, clen, mapaddr;
  277. char *p, *q;
  278. /* We need to move the initrd down into directly mapped mem */
  279. ramdisk_here = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
  280. area_size, PAGE_SIZE);
  281. if (!ramdisk_here)
  282. panic("Cannot find place for new RAMDISK of size %lld\n",
  283. ramdisk_size);
  284. /* Note: this includes all the mem currently occupied by
  285. the initrd, we rely on that fact to keep the data intact. */
  286. memblock_reserve(ramdisk_here, area_size);
  287. initrd_start = ramdisk_here + PAGE_OFFSET;
  288. initrd_end = initrd_start + ramdisk_size;
  289. printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
  290. ramdisk_here, ramdisk_here + ramdisk_size - 1);
  291. q = (char *)initrd_start;
  292. /* Copy the initrd */
  293. while (ramdisk_size) {
  294. slop = ramdisk_image & ~PAGE_MASK;
  295. clen = ramdisk_size;
  296. if (clen > MAX_MAP_CHUNK-slop)
  297. clen = MAX_MAP_CHUNK-slop;
  298. mapaddr = ramdisk_image & PAGE_MASK;
  299. p = early_memremap(mapaddr, clen+slop);
  300. memcpy(q, p+slop, clen);
  301. early_iounmap(p, clen+slop);
  302. q += clen;
  303. ramdisk_image += clen;
  304. ramdisk_size -= clen;
  305. }
  306. ramdisk_image = get_ramdisk_image();
  307. ramdisk_size = get_ramdisk_size();
  308. printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
  309. " [mem %#010llx-%#010llx]\n",
  310. ramdisk_image, ramdisk_image + ramdisk_size - 1,
  311. ramdisk_here, ramdisk_here + ramdisk_size - 1);
  312. }
  313. static void __init early_reserve_initrd(void)
  314. {
  315. /* Assume only end is not page aligned */
  316. u64 ramdisk_image = get_ramdisk_image();
  317. u64 ramdisk_size = get_ramdisk_size();
  318. u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
  319. if (!boot_params.hdr.type_of_loader ||
  320. !ramdisk_image || !ramdisk_size)
  321. return; /* No initrd provided by bootloader */
  322. memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
  323. }
  324. static void __init reserve_initrd(void)
  325. {
  326. /* Assume only end is not page aligned */
  327. u64 ramdisk_image = get_ramdisk_image();
  328. u64 ramdisk_size = get_ramdisk_size();
  329. u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
  330. u64 mapped_size;
  331. if (!boot_params.hdr.type_of_loader ||
  332. !ramdisk_image || !ramdisk_size)
  333. return; /* No initrd provided by bootloader */
  334. initrd_start = 0;
  335. mapped_size = memblock_mem_size(max_pfn_mapped);
  336. if (ramdisk_size >= (mapped_size>>1))
  337. panic("initrd too large to handle, "
  338. "disabling initrd (%lld needed, %lld available)\n",
  339. ramdisk_size, mapped_size>>1);
  340. printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
  341. ramdisk_end - 1);
  342. if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image),
  343. PFN_DOWN(ramdisk_end))) {
  344. /* All are mapped, easy case */
  345. initrd_start = ramdisk_image + PAGE_OFFSET;
  346. initrd_end = initrd_start + ramdisk_size;
  347. return;
  348. }
  349. relocate_initrd();
  350. memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
  351. }
  352. #else
  353. static void __init early_reserve_initrd(void)
  354. {
  355. }
  356. static void __init reserve_initrd(void)
  357. {
  358. }
  359. #endif /* CONFIG_BLK_DEV_INITRD */
  360. static void __init parse_setup_data(void)
  361. {
  362. struct setup_data *data;
  363. u64 pa_data;
  364. pa_data = boot_params.hdr.setup_data;
  365. while (pa_data) {
  366. u32 data_len, map_len;
  367. map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
  368. (u64)sizeof(struct setup_data));
  369. data = early_memremap(pa_data, map_len);
  370. data_len = data->len + sizeof(struct setup_data);
  371. if (data_len > map_len) {
  372. early_iounmap(data, map_len);
  373. data = early_memremap(pa_data, data_len);
  374. map_len = data_len;
  375. }
  376. switch (data->type) {
  377. case SETUP_E820_EXT:
  378. parse_e820_ext(data);
  379. break;
  380. case SETUP_DTB:
  381. add_dtb(pa_data);
  382. break;
  383. default:
  384. break;
  385. }
  386. pa_data = data->next;
  387. early_iounmap(data, map_len);
  388. }
  389. }
  390. static void __init e820_reserve_setup_data(void)
  391. {
  392. struct setup_data *data;
  393. u64 pa_data;
  394. int found = 0;
  395. pa_data = boot_params.hdr.setup_data;
  396. while (pa_data) {
  397. data = early_memremap(pa_data, sizeof(*data));
  398. e820_update_range(pa_data, sizeof(*data)+data->len,
  399. E820_RAM, E820_RESERVED_KERN);
  400. found = 1;
  401. pa_data = data->next;
  402. early_iounmap(data, sizeof(*data));
  403. }
  404. if (!found)
  405. return;
  406. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  407. memcpy(&e820_saved, &e820, sizeof(struct e820map));
  408. printk(KERN_INFO "extended physical RAM map:\n");
  409. e820_print_map("reserve setup_data");
  410. }
  411. static void __init memblock_x86_reserve_range_setup_data(void)
  412. {
  413. struct setup_data *data;
  414. u64 pa_data;
  415. pa_data = boot_params.hdr.setup_data;
  416. while (pa_data) {
  417. data = early_memremap(pa_data, sizeof(*data));
  418. memblock_reserve(pa_data, sizeof(*data) + data->len);
  419. pa_data = data->next;
  420. early_iounmap(data, sizeof(*data));
  421. }
  422. }
  423. /*
  424. * --------- Crashkernel reservation ------------------------------
  425. */
  426. #ifdef CONFIG_KEXEC
  427. /*
  428. * Keep the crash kernel below this limit. On 32 bits earlier kernels
  429. * would limit the kernel to the low 512 MiB due to mapping restrictions.
  430. * On 64bit, old kexec-tools need to under 896MiB.
  431. */
  432. #ifdef CONFIG_X86_32
  433. # define CRASH_KERNEL_ADDR_LOW_MAX (512 << 20)
  434. # define CRASH_KERNEL_ADDR_HIGH_MAX (512 << 20)
  435. #else
  436. # define CRASH_KERNEL_ADDR_LOW_MAX (896UL<<20)
  437. # define CRASH_KERNEL_ADDR_HIGH_MAX MAXMEM
  438. #endif
  439. static void __init reserve_crashkernel_low(void)
  440. {
  441. #ifdef CONFIG_X86_64
  442. const unsigned long long alignment = 16<<20; /* 16M */
  443. unsigned long long low_base = 0, low_size = 0;
  444. unsigned long total_low_mem;
  445. unsigned long long base;
  446. bool auto_set = false;
  447. int ret;
  448. total_low_mem = memblock_mem_size(1UL<<(32-PAGE_SHIFT));
  449. /* crashkernel=Y,low */
  450. ret = parse_crashkernel_low(boot_command_line, total_low_mem,
  451. &low_size, &base);
  452. if (ret != 0) {
  453. /*
  454. * two parts from lib/swiotlb.c:
  455. * swiotlb size: user specified with swiotlb= or default.
  456. * swiotlb overflow buffer: now is hardcoded to 32k.
  457. * We round it to 8M for other buffers that
  458. * may need to stay low too.
  459. */
  460. low_size = swiotlb_size_or_default() + (8UL<<20);
  461. auto_set = true;
  462. } else {
  463. /* passed with crashkernel=0,low ? */
  464. if (!low_size)
  465. return;
  466. }
  467. low_base = memblock_find_in_range(low_size, (1ULL<<32),
  468. low_size, alignment);
  469. if (!low_base) {
  470. if (!auto_set)
  471. pr_info("crashkernel low reservation failed - No suitable area found.\n");
  472. return;
  473. }
  474. memblock_reserve(low_base, low_size);
  475. pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n",
  476. (unsigned long)(low_size >> 20),
  477. (unsigned long)(low_base >> 20),
  478. (unsigned long)(total_low_mem >> 20));
  479. crashk_low_res.start = low_base;
  480. crashk_low_res.end = low_base + low_size - 1;
  481. insert_resource(&iomem_resource, &crashk_low_res);
  482. #endif
  483. }
  484. static void __init reserve_crashkernel(void)
  485. {
  486. const unsigned long long alignment = 16<<20; /* 16M */
  487. unsigned long long total_mem;
  488. unsigned long long crash_size, crash_base;
  489. bool high = false;
  490. int ret;
  491. total_mem = memblock_phys_mem_size();
  492. /* crashkernel=XM */
  493. ret = parse_crashkernel(boot_command_line, total_mem,
  494. &crash_size, &crash_base);
  495. if (ret != 0 || crash_size <= 0) {
  496. /* crashkernel=X,high */
  497. ret = parse_crashkernel_high(boot_command_line, total_mem,
  498. &crash_size, &crash_base);
  499. if (ret != 0 || crash_size <= 0)
  500. return;
  501. high = true;
  502. }
  503. /* 0 means: find the address automatically */
  504. if (crash_base <= 0) {
  505. /*
  506. * kexec want bzImage is below CRASH_KERNEL_ADDR_MAX
  507. */
  508. crash_base = memblock_find_in_range(alignment,
  509. high ? CRASH_KERNEL_ADDR_HIGH_MAX :
  510. CRASH_KERNEL_ADDR_LOW_MAX,
  511. crash_size, alignment);
  512. if (!crash_base) {
  513. pr_info("crashkernel reservation failed - No suitable area found.\n");
  514. return;
  515. }
  516. } else {
  517. unsigned long long start;
  518. start = memblock_find_in_range(crash_base,
  519. crash_base + crash_size, crash_size, 1<<20);
  520. if (start != crash_base) {
  521. pr_info("crashkernel reservation failed - memory is in use.\n");
  522. return;
  523. }
  524. }
  525. memblock_reserve(crash_base, crash_size);
  526. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  527. "for crashkernel (System RAM: %ldMB)\n",
  528. (unsigned long)(crash_size >> 20),
  529. (unsigned long)(crash_base >> 20),
  530. (unsigned long)(total_mem >> 20));
  531. crashk_res.start = crash_base;
  532. crashk_res.end = crash_base + crash_size - 1;
  533. insert_resource(&iomem_resource, &crashk_res);
  534. if (crash_base >= (1ULL<<32))
  535. reserve_crashkernel_low();
  536. }
  537. #else
  538. static void __init reserve_crashkernel(void)
  539. {
  540. }
  541. #endif
  542. static struct resource standard_io_resources[] = {
  543. { .name = "dma1", .start = 0x00, .end = 0x1f,
  544. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  545. { .name = "pic1", .start = 0x20, .end = 0x21,
  546. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  547. { .name = "timer0", .start = 0x40, .end = 0x43,
  548. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  549. { .name = "timer1", .start = 0x50, .end = 0x53,
  550. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  551. { .name = "keyboard", .start = 0x60, .end = 0x60,
  552. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  553. { .name = "keyboard", .start = 0x64, .end = 0x64,
  554. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  555. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  556. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  557. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  558. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  559. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  560. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  561. { .name = "fpu", .start = 0xf0, .end = 0xff,
  562. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  563. };
  564. void __init reserve_standard_io_resources(void)
  565. {
  566. int i;
  567. /* request I/O space for devices used on all i[345]86 PCs */
  568. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  569. request_resource(&ioport_resource, &standard_io_resources[i]);
  570. }
  571. static __init void reserve_ibft_region(void)
  572. {
  573. unsigned long addr, size = 0;
  574. addr = find_ibft_region(&size);
  575. if (size)
  576. memblock_reserve(addr, size);
  577. }
  578. static bool __init snb_gfx_workaround_needed(void)
  579. {
  580. #ifdef CONFIG_PCI
  581. int i;
  582. u16 vendor, devid;
  583. static const __initconst u16 snb_ids[] = {
  584. 0x0102,
  585. 0x0112,
  586. 0x0122,
  587. 0x0106,
  588. 0x0116,
  589. 0x0126,
  590. 0x010a,
  591. };
  592. /* Assume no if something weird is going on with PCI */
  593. if (!early_pci_allowed())
  594. return false;
  595. vendor = read_pci_config_16(0, 2, 0, PCI_VENDOR_ID);
  596. if (vendor != 0x8086)
  597. return false;
  598. devid = read_pci_config_16(0, 2, 0, PCI_DEVICE_ID);
  599. for (i = 0; i < ARRAY_SIZE(snb_ids); i++)
  600. if (devid == snb_ids[i])
  601. return true;
  602. #endif
  603. return false;
  604. }
  605. /*
  606. * Sandy Bridge graphics has trouble with certain ranges, exclude
  607. * them from allocation.
  608. */
  609. static void __init trim_snb_memory(void)
  610. {
  611. static const __initconst unsigned long bad_pages[] = {
  612. 0x20050000,
  613. 0x20110000,
  614. 0x20130000,
  615. 0x20138000,
  616. 0x40004000,
  617. };
  618. int i;
  619. if (!snb_gfx_workaround_needed())
  620. return;
  621. printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n");
  622. /*
  623. * Reserve all memory below the 1 MB mark that has not
  624. * already been reserved.
  625. */
  626. memblock_reserve(0, 1<<20);
  627. for (i = 0; i < ARRAY_SIZE(bad_pages); i++) {
  628. if (memblock_reserve(bad_pages[i], PAGE_SIZE))
  629. printk(KERN_WARNING "failed to reserve 0x%08lx\n",
  630. bad_pages[i]);
  631. }
  632. }
  633. /*
  634. * Here we put platform-specific memory range workarounds, i.e.
  635. * memory known to be corrupt or otherwise in need to be reserved on
  636. * specific platforms.
  637. *
  638. * If this gets used more widely it could use a real dispatch mechanism.
  639. */
  640. static void __init trim_platform_memory_ranges(void)
  641. {
  642. trim_snb_memory();
  643. }
  644. static void __init trim_bios_range(void)
  645. {
  646. /*
  647. * A special case is the first 4Kb of memory;
  648. * This is a BIOS owned area, not kernel ram, but generally
  649. * not listed as such in the E820 table.
  650. *
  651. * This typically reserves additional memory (64KiB by default)
  652. * since some BIOSes are known to corrupt low memory. See the
  653. * Kconfig help text for X86_RESERVE_LOW.
  654. */
  655. e820_update_range(0, PAGE_SIZE, E820_RAM, E820_RESERVED);
  656. /*
  657. * special case: Some BIOSen report the PC BIOS
  658. * area (640->1Mb) as ram even though it is not.
  659. * take them out.
  660. */
  661. e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
  662. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  663. }
  664. /* called before trim_bios_range() to spare extra sanitize */
  665. static void __init e820_add_kernel_range(void)
  666. {
  667. u64 start = __pa_symbol(_text);
  668. u64 size = __pa_symbol(_end) - start;
  669. /*
  670. * Complain if .text .data and .bss are not marked as E820_RAM and
  671. * attempt to fix it by adding the range. We may have a confused BIOS,
  672. * or the user may have used memmap=exactmap or memmap=xxM$yyM to
  673. * exclude kernel range. If we really are running on top non-RAM,
  674. * we will crash later anyways.
  675. */
  676. if (e820_all_mapped(start, start + size, E820_RAM))
  677. return;
  678. pr_warn(".text .data .bss are not marked as E820_RAM!\n");
  679. e820_remove_range(start, size, E820_RAM, 0);
  680. e820_add_region(start, size, E820_RAM);
  681. }
  682. static unsigned reserve_low = CONFIG_X86_RESERVE_LOW << 10;
  683. static int __init parse_reservelow(char *p)
  684. {
  685. unsigned long long size;
  686. if (!p)
  687. return -EINVAL;
  688. size = memparse(p, &p);
  689. if (size < 4096)
  690. size = 4096;
  691. if (size > 640*1024)
  692. size = 640*1024;
  693. reserve_low = size;
  694. return 0;
  695. }
  696. early_param("reservelow", parse_reservelow);
  697. static void __init trim_low_memory_range(void)
  698. {
  699. memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE));
  700. }
  701. /*
  702. * Determine if we were loaded by an EFI loader. If so, then we have also been
  703. * passed the efi memmap, systab, etc., so we should use these data structures
  704. * for initialization. Note, the efi init code path is determined by the
  705. * global efi_enabled. This allows the same kernel image to be used on existing
  706. * systems (with a traditional BIOS) as well as on EFI systems.
  707. */
  708. /*
  709. * setup_arch - architecture-specific boot-time initializations
  710. *
  711. * Note: On x86_64, fixmaps are ready for use even before this is called.
  712. */
  713. void __init setup_arch(char **cmdline_p)
  714. {
  715. memblock_reserve(__pa_symbol(_text),
  716. (unsigned long)__bss_stop - (unsigned long)_text);
  717. early_reserve_initrd();
  718. /*
  719. * At this point everything still needed from the boot loader
  720. * or BIOS or kernel text should be early reserved or marked not
  721. * RAM in e820. All other memory is free game.
  722. */
  723. #ifdef CONFIG_X86_32
  724. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  725. visws_early_detect();
  726. /*
  727. * copy kernel address range established so far and switch
  728. * to the proper swapper page table
  729. */
  730. clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  731. initial_page_table + KERNEL_PGD_BOUNDARY,
  732. KERNEL_PGD_PTRS);
  733. load_cr3(swapper_pg_dir);
  734. __flush_tlb_all();
  735. #else
  736. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  737. #endif
  738. /*
  739. * If we have OLPC OFW, we might end up relocating the fixmap due to
  740. * reserve_top(), so do this before touching the ioremap area.
  741. */
  742. olpc_ofw_detect();
  743. early_trap_init();
  744. early_cpu_init();
  745. early_ioremap_init();
  746. setup_olpc_ofw_pgd();
  747. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  748. screen_info = boot_params.screen_info;
  749. edid_info = boot_params.edid_info;
  750. #ifdef CONFIG_X86_32
  751. apm_info.bios = boot_params.apm_bios_info;
  752. ist_info = boot_params.ist_info;
  753. if (boot_params.sys_desc_table.length != 0) {
  754. machine_id = boot_params.sys_desc_table.table[0];
  755. machine_submodel_id = boot_params.sys_desc_table.table[1];
  756. BIOS_revision = boot_params.sys_desc_table.table[2];
  757. }
  758. #endif
  759. saved_video_mode = boot_params.hdr.vid_mode;
  760. bootloader_type = boot_params.hdr.type_of_loader;
  761. if ((bootloader_type >> 4) == 0xe) {
  762. bootloader_type &= 0xf;
  763. bootloader_type |= (boot_params.hdr.ext_loader_type+0x10) << 4;
  764. }
  765. bootloader_version = bootloader_type & 0xf;
  766. bootloader_version |= boot_params.hdr.ext_loader_ver << 4;
  767. #ifdef CONFIG_BLK_DEV_RAM
  768. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  769. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  770. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  771. #endif
  772. #ifdef CONFIG_EFI
  773. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  774. "EL32", 4)) {
  775. set_bit(EFI_BOOT, &x86_efi_facility);
  776. } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  777. "EL64", 4)) {
  778. set_bit(EFI_BOOT, &x86_efi_facility);
  779. set_bit(EFI_64BIT, &x86_efi_facility);
  780. }
  781. if (efi_enabled(EFI_BOOT))
  782. efi_memblock_x86_reserve_range();
  783. #endif
  784. x86_init.oem.arch_setup();
  785. iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
  786. setup_memory_map();
  787. parse_setup_data();
  788. /* update the e820_saved too */
  789. e820_reserve_setup_data();
  790. copy_edd();
  791. if (!boot_params.hdr.root_flags)
  792. root_mountflags &= ~MS_RDONLY;
  793. init_mm.start_code = (unsigned long) _text;
  794. init_mm.end_code = (unsigned long) _etext;
  795. init_mm.end_data = (unsigned long) _edata;
  796. init_mm.brk = _brk_end;
  797. code_resource.start = __pa_symbol(_text);
  798. code_resource.end = __pa_symbol(_etext)-1;
  799. data_resource.start = __pa_symbol(_etext);
  800. data_resource.end = __pa_symbol(_edata)-1;
  801. bss_resource.start = __pa_symbol(__bss_start);
  802. bss_resource.end = __pa_symbol(__bss_stop)-1;
  803. #ifdef CONFIG_CMDLINE_BOOL
  804. #ifdef CONFIG_CMDLINE_OVERRIDE
  805. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  806. #else
  807. if (builtin_cmdline[0]) {
  808. /* append boot loader cmdline to builtin */
  809. strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
  810. strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  811. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  812. }
  813. #endif
  814. #endif
  815. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  816. *cmdline_p = command_line;
  817. /*
  818. * x86_configure_nx() is called before parse_early_param() to detect
  819. * whether hardware doesn't support NX (so that the early EHCI debug
  820. * console setup can safely call set_fixmap()). It may then be called
  821. * again from within noexec_setup() during parsing early parameters
  822. * to honor the respective command line option.
  823. */
  824. x86_configure_nx();
  825. parse_early_param();
  826. x86_report_nx();
  827. /* after early param, so could get panic from serial */
  828. memblock_x86_reserve_range_setup_data();
  829. if (acpi_mps_check()) {
  830. #ifdef CONFIG_X86_LOCAL_APIC
  831. disable_apic = 1;
  832. #endif
  833. setup_clear_cpu_cap(X86_FEATURE_APIC);
  834. }
  835. #ifdef CONFIG_PCI
  836. if (pci_early_dump_regs)
  837. early_dump_pci_devices();
  838. #endif
  839. finish_e820_parsing();
  840. if (efi_enabled(EFI_BOOT))
  841. efi_init();
  842. dmi_scan_machine();
  843. /*
  844. * VMware detection requires dmi to be available, so this
  845. * needs to be done after dmi_scan_machine, for the BP.
  846. */
  847. init_hypervisor_platform();
  848. x86_init.resources.probe_roms();
  849. /* after parse_early_param, so could debug it */
  850. insert_resource(&iomem_resource, &code_resource);
  851. insert_resource(&iomem_resource, &data_resource);
  852. insert_resource(&iomem_resource, &bss_resource);
  853. e820_add_kernel_range();
  854. trim_bios_range();
  855. #ifdef CONFIG_X86_32
  856. if (ppro_with_ram_bug()) {
  857. e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
  858. E820_RESERVED);
  859. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  860. printk(KERN_INFO "fixed physical RAM map:\n");
  861. e820_print_map("bad_ppro");
  862. }
  863. #else
  864. early_gart_iommu_check();
  865. #endif
  866. /*
  867. * partially used pages are not usable - thus
  868. * we are rounding upwards:
  869. */
  870. max_pfn = e820_end_of_ram_pfn();
  871. /* update e820 for memory not covered by WB MTRRs */
  872. mtrr_bp_init();
  873. if (mtrr_trim_uncached_memory(max_pfn))
  874. max_pfn = e820_end_of_ram_pfn();
  875. #ifdef CONFIG_X86_32
  876. /* max_low_pfn get updated here */
  877. find_low_pfn_range();
  878. #else
  879. num_physpages = max_pfn;
  880. check_x2apic();
  881. /* How many end-of-memory variables you have, grandma! */
  882. /* need this before calling reserve_initrd */
  883. if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
  884. max_low_pfn = e820_end_of_low_ram_pfn();
  885. else
  886. max_low_pfn = max_pfn;
  887. high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
  888. #endif
  889. /*
  890. * Find and reserve possible boot-time SMP configuration:
  891. */
  892. find_smp_config();
  893. reserve_ibft_region();
  894. early_alloc_pgt_buf();
  895. /*
  896. * Need to conclude brk, before memblock_x86_fill()
  897. * it could use memblock_find_in_range, could overlap with
  898. * brk area.
  899. */
  900. reserve_brk();
  901. cleanup_highmap();
  902. memblock.current_limit = ISA_END_ADDRESS;
  903. memblock_x86_fill();
  904. /*
  905. * The EFI specification says that boot service code won't be called
  906. * after ExitBootServices(). This is, in fact, a lie.
  907. */
  908. if (efi_enabled(EFI_MEMMAP))
  909. efi_reserve_boot_services();
  910. /* preallocate 4k for mptable mpc */
  911. early_reserve_e820_mpc_new();
  912. #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
  913. setup_bios_corruption_check();
  914. #endif
  915. #ifdef CONFIG_X86_32
  916. printk(KERN_DEBUG "initial memory mapped: [mem 0x00000000-%#010lx]\n",
  917. (max_pfn_mapped<<PAGE_SHIFT) - 1);
  918. #endif
  919. reserve_real_mode();
  920. trim_platform_memory_ranges();
  921. trim_low_memory_range();
  922. init_mem_mapping();
  923. early_trap_pf_init();
  924. setup_real_mode();
  925. memblock.current_limit = get_max_mapped();
  926. dma_contiguous_reserve(0);
  927. /*
  928. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  929. */
  930. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  931. if (init_ohci1394_dma_early)
  932. init_ohci1394_dma_on_all_controllers();
  933. #endif
  934. /* Allocate bigger log buffer */
  935. setup_log_buf(1);
  936. reserve_initrd();
  937. #if defined(CONFIG_ACPI) && defined(CONFIG_BLK_DEV_INITRD)
  938. acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);
  939. #endif
  940. reserve_crashkernel();
  941. vsmp_init();
  942. io_delay_init();
  943. /*
  944. * Parse the ACPI tables for possible boot-time SMP configuration.
  945. */
  946. acpi_boot_table_init();
  947. early_acpi_boot_init();
  948. initmem_init();
  949. memblock_find_dma_reserve();
  950. #ifdef CONFIG_KVM_GUEST
  951. kvmclock_init();
  952. #endif
  953. x86_init.paging.pagetable_init();
  954. if (boot_cpu_data.cpuid_level >= 0) {
  955. /* A CPU has %cr4 if and only if it has CPUID */
  956. mmu_cr4_features = read_cr4();
  957. if (trampoline_cr4_features)
  958. *trampoline_cr4_features = mmu_cr4_features;
  959. }
  960. #ifdef CONFIG_X86_32
  961. /* sync back kernel address range */
  962. clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
  963. swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  964. KERNEL_PGD_PTRS);
  965. #endif
  966. tboot_probe();
  967. #ifdef CONFIG_X86_64
  968. map_vsyscall();
  969. #endif
  970. generic_apic_probe();
  971. early_quirks();
  972. /*
  973. * Read APIC and some other early information from ACPI tables.
  974. */
  975. acpi_boot_init();
  976. sfi_init();
  977. x86_dtb_init();
  978. /*
  979. * get boot-time SMP configuration:
  980. */
  981. if (smp_found_config)
  982. get_smp_config();
  983. prefill_possible_map();
  984. init_cpu_to_node();
  985. init_apic_mappings();
  986. if (x86_io_apic_ops.init)
  987. x86_io_apic_ops.init();
  988. kvm_guest_init();
  989. e820_reserve_resources();
  990. e820_mark_nosave_regions(max_low_pfn);
  991. x86_init.resources.reserve_resources();
  992. e820_setup_gap();
  993. #ifdef CONFIG_VT
  994. #if defined(CONFIG_VGA_CONSOLE)
  995. if (!efi_enabled(EFI_BOOT) || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  996. conswitchp = &vga_con;
  997. #elif defined(CONFIG_DUMMY_CONSOLE)
  998. conswitchp = &dummy_con;
  999. #endif
  1000. #endif
  1001. x86_init.oem.banner();
  1002. x86_init.timers.wallclock_init();
  1003. mcheck_init();
  1004. arch_init_ideal_nops();
  1005. register_refined_jiffies(CLOCK_TICK_RATE);
  1006. #ifdef CONFIG_EFI
  1007. /* Once setup is done above, unmap the EFI memory map on
  1008. * mismatched firmware/kernel archtectures since there is no
  1009. * support for runtime services.
  1010. */
  1011. if (efi_enabled(EFI_BOOT) && !efi_is_native()) {
  1012. pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n");
  1013. efi_unmap_memmap();
  1014. }
  1015. #endif
  1016. }
  1017. #ifdef CONFIG_X86_32
  1018. static struct resource video_ram_resource = {
  1019. .name = "Video RAM area",
  1020. .start = 0xa0000,
  1021. .end = 0xbffff,
  1022. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  1023. };
  1024. void __init i386_reserve_resources(void)
  1025. {
  1026. request_resource(&iomem_resource, &video_ram_resource);
  1027. reserve_standard_io_resources();
  1028. }
  1029. #endif /* CONFIG_X86_32 */