setup.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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/apm_bios.h>
  29. #include <linux/initrd.h>
  30. #include <linux/bootmem.h>
  31. #include <linux/seq_file.h>
  32. #include <linux/console.h>
  33. #include <linux/mca.h>
  34. #include <linux/root_dev.h>
  35. #include <linux/highmem.h>
  36. #include <linux/module.h>
  37. #include <linux/efi.h>
  38. #include <linux/init.h>
  39. #include <linux/edd.h>
  40. #include <linux/iscsi_ibft.h>
  41. #include <linux/nodemask.h>
  42. #include <linux/kexec.h>
  43. #include <linux/dmi.h>
  44. #include <linux/pfn.h>
  45. #include <linux/pci.h>
  46. #include <asm/pci-direct.h>
  47. #include <linux/init_ohci1394_dma.h>
  48. #include <linux/kvm_para.h>
  49. #include <linux/errno.h>
  50. #include <linux/kernel.h>
  51. #include <linux/stddef.h>
  52. #include <linux/unistd.h>
  53. #include <linux/ptrace.h>
  54. #include <linux/slab.h>
  55. #include <linux/user.h>
  56. #include <linux/delay.h>
  57. #include <linux/kallsyms.h>
  58. #include <linux/cpufreq.h>
  59. #include <linux/dma-mapping.h>
  60. #include <linux/ctype.h>
  61. #include <linux/uaccess.h>
  62. #include <linux/percpu.h>
  63. #include <linux/crash_dump.h>
  64. #include <video/edid.h>
  65. #include <asm/mtrr.h>
  66. #include <asm/apic.h>
  67. #include <asm/e820.h>
  68. #include <asm/mpspec.h>
  69. #include <asm/setup.h>
  70. #include <asm/efi.h>
  71. #include <asm/timer.h>
  72. #include <asm/i8259.h>
  73. #include <asm/sections.h>
  74. #include <asm/dmi.h>
  75. #include <asm/io_apic.h>
  76. #include <asm/ist.h>
  77. #include <asm/vmi.h>
  78. #include <asm/setup_arch.h>
  79. #include <asm/bios_ebda.h>
  80. #include <asm/cacheflush.h>
  81. #include <asm/processor.h>
  82. #include <asm/bugs.h>
  83. #include <asm/system.h>
  84. #include <asm/vsyscall.h>
  85. #include <asm/cpu.h>
  86. #include <asm/desc.h>
  87. #include <asm/dma.h>
  88. #include <asm/iommu.h>
  89. #include <asm/gart.h>
  90. #include <asm/mmu_context.h>
  91. #include <asm/proto.h>
  92. #include <asm/paravirt.h>
  93. #include <asm/hypervisor.h>
  94. #include <asm/percpu.h>
  95. #include <asm/topology.h>
  96. #include <asm/apicdef.h>
  97. #ifdef CONFIG_X86_64
  98. #include <asm/numa_64.h>
  99. #endif
  100. #ifndef ARCH_SETUP
  101. #define ARCH_SETUP
  102. #endif
  103. unsigned int boot_cpu_id __read_mostly;
  104. static __initdata unsigned long _brk_start = (unsigned long)__brk_base;
  105. unsigned long _brk_end = (unsigned long)__brk_base;
  106. #ifdef CONFIG_X86_64
  107. int default_cpu_present_to_apicid(int mps_cpu)
  108. {
  109. return __default_cpu_present_to_apicid(mps_cpu);
  110. }
  111. int default_check_phys_apicid_present(int boot_cpu_physical_apicid)
  112. {
  113. return __default_check_phys_apicid_present(boot_cpu_physical_apicid);
  114. }
  115. #endif
  116. #ifndef CONFIG_DEBUG_BOOT_PARAMS
  117. struct boot_params __initdata boot_params;
  118. #else
  119. struct boot_params boot_params;
  120. #endif
  121. /*
  122. * Machine setup..
  123. */
  124. static struct resource data_resource = {
  125. .name = "Kernel data",
  126. .start = 0,
  127. .end = 0,
  128. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  129. };
  130. static struct resource code_resource = {
  131. .name = "Kernel code",
  132. .start = 0,
  133. .end = 0,
  134. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  135. };
  136. static struct resource bss_resource = {
  137. .name = "Kernel bss",
  138. .start = 0,
  139. .end = 0,
  140. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  141. };
  142. #ifdef CONFIG_X86_32
  143. /* This value is set up by the early boot code to point to the value
  144. immediately after the boot time page tables. It contains a *physical*
  145. address, and must not be in the .bss segment! */
  146. unsigned long init_pg_tables_start __initdata = ~0UL;
  147. unsigned long init_pg_tables_end __initdata = ~0UL;
  148. static struct resource video_ram_resource = {
  149. .name = "Video RAM area",
  150. .start = 0xa0000,
  151. .end = 0xbffff,
  152. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  153. };
  154. /* cpu data as detected by the assembly code in head.S */
  155. struct cpuinfo_x86 new_cpu_data __cpuinitdata = {0, 0, 0, 0, -1, 1, 0, 0, -1};
  156. /* common cpu data for all cpus */
  157. struct cpuinfo_x86 boot_cpu_data __read_mostly = {0, 0, 0, 0, -1, 1, 0, 0, -1};
  158. EXPORT_SYMBOL(boot_cpu_data);
  159. static void set_mca_bus(int x)
  160. {
  161. #ifdef CONFIG_MCA
  162. MCA_bus = x;
  163. #endif
  164. }
  165. unsigned int def_to_bigsmp;
  166. /* for MCA, but anyone else can use it if they want */
  167. unsigned int machine_id;
  168. unsigned int machine_submodel_id;
  169. unsigned int BIOS_revision;
  170. struct apm_info apm_info;
  171. EXPORT_SYMBOL(apm_info);
  172. #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
  173. defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
  174. struct ist_info ist_info;
  175. EXPORT_SYMBOL(ist_info);
  176. #else
  177. struct ist_info ist_info;
  178. #endif
  179. #else
  180. struct cpuinfo_x86 boot_cpu_data __read_mostly = {
  181. .x86_phys_bits = MAX_PHYSMEM_BITS,
  182. };
  183. EXPORT_SYMBOL(boot_cpu_data);
  184. #endif
  185. #if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
  186. unsigned long mmu_cr4_features;
  187. #else
  188. unsigned long mmu_cr4_features = X86_CR4_PAE;
  189. #endif
  190. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  191. int bootloader_type;
  192. /*
  193. * Early DMI memory
  194. */
  195. int dmi_alloc_index;
  196. char dmi_alloc_data[DMI_MAX_DATA];
  197. /*
  198. * Setup options
  199. */
  200. struct screen_info screen_info;
  201. EXPORT_SYMBOL(screen_info);
  202. struct edid_info edid_info;
  203. EXPORT_SYMBOL_GPL(edid_info);
  204. extern int root_mountflags;
  205. unsigned long saved_video_mode;
  206. #define RAMDISK_IMAGE_START_MASK 0x07FF
  207. #define RAMDISK_PROMPT_FLAG 0x8000
  208. #define RAMDISK_LOAD_FLAG 0x4000
  209. static char __initdata command_line[COMMAND_LINE_SIZE];
  210. #ifdef CONFIG_CMDLINE_BOOL
  211. static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  212. #endif
  213. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  214. struct edd edd;
  215. #ifdef CONFIG_EDD_MODULE
  216. EXPORT_SYMBOL(edd);
  217. #endif
  218. /**
  219. * copy_edd() - Copy the BIOS EDD information
  220. * from boot_params into a safe place.
  221. *
  222. */
  223. static inline void copy_edd(void)
  224. {
  225. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  226. sizeof(edd.mbr_signature));
  227. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  228. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  229. edd.edd_info_nr = boot_params.eddbuf_entries;
  230. }
  231. #else
  232. static inline void copy_edd(void)
  233. {
  234. }
  235. #endif
  236. #ifdef CONFIG_BLK_DEV_INITRD
  237. #ifdef CONFIG_X86_32
  238. #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
  239. static void __init relocate_initrd(void)
  240. {
  241. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  242. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  243. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  244. u64 ramdisk_here;
  245. unsigned long slop, clen, mapaddr;
  246. char *p, *q;
  247. /* We need to move the initrd down into lowmem */
  248. ramdisk_here = find_e820_area(0, end_of_lowmem, ramdisk_size,
  249. PAGE_SIZE);
  250. if (ramdisk_here == -1ULL)
  251. panic("Cannot find place for new RAMDISK of size %lld\n",
  252. ramdisk_size);
  253. /* Note: this includes all the lowmem currently occupied by
  254. the initrd, we rely on that fact to keep the data intact. */
  255. reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
  256. "NEW RAMDISK");
  257. initrd_start = ramdisk_here + PAGE_OFFSET;
  258. initrd_end = initrd_start + ramdisk_size;
  259. printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
  260. ramdisk_here, ramdisk_here + ramdisk_size);
  261. q = (char *)initrd_start;
  262. /* Copy any lowmem portion of the initrd */
  263. if (ramdisk_image < end_of_lowmem) {
  264. clen = end_of_lowmem - ramdisk_image;
  265. p = (char *)__va(ramdisk_image);
  266. memcpy(q, p, clen);
  267. q += clen;
  268. ramdisk_image += clen;
  269. ramdisk_size -= clen;
  270. }
  271. /* Copy the highmem portion of the initrd */
  272. while (ramdisk_size) {
  273. slop = ramdisk_image & ~PAGE_MASK;
  274. clen = ramdisk_size;
  275. if (clen > MAX_MAP_CHUNK-slop)
  276. clen = MAX_MAP_CHUNK-slop;
  277. mapaddr = ramdisk_image & PAGE_MASK;
  278. p = early_memremap(mapaddr, clen+slop);
  279. memcpy(q, p+slop, clen);
  280. early_iounmap(p, clen+slop);
  281. q += clen;
  282. ramdisk_image += clen;
  283. ramdisk_size -= clen;
  284. }
  285. /* high pages is not converted by early_res_to_bootmem */
  286. ramdisk_image = boot_params.hdr.ramdisk_image;
  287. ramdisk_size = boot_params.hdr.ramdisk_size;
  288. printk(KERN_INFO "Move RAMDISK from %016llx - %016llx to"
  289. " %08llx - %08llx\n",
  290. ramdisk_image, ramdisk_image + ramdisk_size - 1,
  291. ramdisk_here, ramdisk_here + ramdisk_size - 1);
  292. }
  293. #endif
  294. void * __init extend_brk(size_t size, size_t align)
  295. {
  296. size_t mask = align - 1;
  297. void *ret;
  298. BUG_ON(_brk_start == 0);
  299. BUG_ON(align & mask);
  300. _brk_end = (_brk_end + mask) & ~mask;
  301. BUG_ON((char *)(_brk_end + size) > __brk_limit);
  302. ret = (void *)_brk_end;
  303. _brk_end += size;
  304. memset(ret, 0, size);
  305. return ret;
  306. }
  307. static void __init reserve_brk(void)
  308. {
  309. if (_brk_end > _brk_start)
  310. reserve_early(__pa(_brk_start), __pa(_brk_end), "BRK");
  311. /* Mark brk area as locked down and no longer taking any new allocations */
  312. _brk_start = 0;
  313. }
  314. static void __init reserve_initrd(void)
  315. {
  316. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  317. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  318. u64 ramdisk_end = ramdisk_image + ramdisk_size;
  319. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  320. if (!boot_params.hdr.type_of_loader ||
  321. !ramdisk_image || !ramdisk_size)
  322. return; /* No initrd provided by bootloader */
  323. initrd_start = 0;
  324. if (ramdisk_size >= (end_of_lowmem>>1)) {
  325. free_early(ramdisk_image, ramdisk_end);
  326. printk(KERN_ERR "initrd too large to handle, "
  327. "disabling initrd\n");
  328. return;
  329. }
  330. printk(KERN_INFO "RAMDISK: %08llx - %08llx\n", ramdisk_image,
  331. ramdisk_end);
  332. if (ramdisk_end <= end_of_lowmem) {
  333. /* All in lowmem, easy case */
  334. /*
  335. * don't need to reserve again, already reserved early
  336. * in i386_start_kernel
  337. */
  338. initrd_start = ramdisk_image + PAGE_OFFSET;
  339. initrd_end = initrd_start + ramdisk_size;
  340. return;
  341. }
  342. #ifdef CONFIG_X86_32
  343. relocate_initrd();
  344. #else
  345. printk(KERN_ERR "initrd extends beyond end of memory "
  346. "(0x%08llx > 0x%08llx)\ndisabling initrd\n",
  347. ramdisk_end, end_of_lowmem);
  348. initrd_start = 0;
  349. #endif
  350. free_early(ramdisk_image, ramdisk_end);
  351. }
  352. #else
  353. static void __init reserve_initrd(void)
  354. {
  355. }
  356. #endif /* CONFIG_BLK_DEV_INITRD */
  357. static void __init parse_setup_data(void)
  358. {
  359. struct setup_data *data;
  360. u64 pa_data;
  361. if (boot_params.hdr.version < 0x0209)
  362. return;
  363. pa_data = boot_params.hdr.setup_data;
  364. while (pa_data) {
  365. data = early_memremap(pa_data, PAGE_SIZE);
  366. switch (data->type) {
  367. case SETUP_E820_EXT:
  368. parse_e820_ext(data, pa_data);
  369. break;
  370. default:
  371. break;
  372. }
  373. pa_data = data->next;
  374. early_iounmap(data, PAGE_SIZE);
  375. }
  376. }
  377. static void __init e820_reserve_setup_data(void)
  378. {
  379. struct setup_data *data;
  380. u64 pa_data;
  381. int found = 0;
  382. if (boot_params.hdr.version < 0x0209)
  383. return;
  384. pa_data = boot_params.hdr.setup_data;
  385. while (pa_data) {
  386. data = early_memremap(pa_data, sizeof(*data));
  387. e820_update_range(pa_data, sizeof(*data)+data->len,
  388. E820_RAM, E820_RESERVED_KERN);
  389. found = 1;
  390. pa_data = data->next;
  391. early_iounmap(data, sizeof(*data));
  392. }
  393. if (!found)
  394. return;
  395. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  396. memcpy(&e820_saved, &e820, sizeof(struct e820map));
  397. printk(KERN_INFO "extended physical RAM map:\n");
  398. e820_print_map("reserve setup_data");
  399. }
  400. static void __init reserve_early_setup_data(void)
  401. {
  402. struct setup_data *data;
  403. u64 pa_data;
  404. char buf[32];
  405. if (boot_params.hdr.version < 0x0209)
  406. return;
  407. pa_data = boot_params.hdr.setup_data;
  408. while (pa_data) {
  409. data = early_memremap(pa_data, sizeof(*data));
  410. sprintf(buf, "setup data %x", data->type);
  411. reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
  412. pa_data = data->next;
  413. early_iounmap(data, sizeof(*data));
  414. }
  415. }
  416. /*
  417. * --------- Crashkernel reservation ------------------------------
  418. */
  419. #ifdef CONFIG_KEXEC
  420. /**
  421. * Reserve @size bytes of crashkernel memory at any suitable offset.
  422. *
  423. * @size: Size of the crashkernel memory to reserve.
  424. * Returns the base address on success, and -1ULL on failure.
  425. */
  426. static
  427. unsigned long long __init find_and_reserve_crashkernel(unsigned long long size)
  428. {
  429. const unsigned long long alignment = 16<<20; /* 16M */
  430. unsigned long long start = 0LL;
  431. while (1) {
  432. int ret;
  433. start = find_e820_area(start, ULONG_MAX, size, alignment);
  434. if (start == -1ULL)
  435. return start;
  436. /* try to reserve it */
  437. ret = reserve_bootmem_generic(start, size, BOOTMEM_EXCLUSIVE);
  438. if (ret >= 0)
  439. return start;
  440. start += alignment;
  441. }
  442. }
  443. static inline unsigned long long get_total_mem(void)
  444. {
  445. unsigned long long total;
  446. total = max_low_pfn - min_low_pfn;
  447. #ifdef CONFIG_HIGHMEM
  448. total += highend_pfn - highstart_pfn;
  449. #endif
  450. return total << PAGE_SHIFT;
  451. }
  452. static void __init reserve_crashkernel(void)
  453. {
  454. unsigned long long total_mem;
  455. unsigned long long crash_size, crash_base;
  456. int ret;
  457. total_mem = get_total_mem();
  458. ret = parse_crashkernel(boot_command_line, total_mem,
  459. &crash_size, &crash_base);
  460. if (ret != 0 || crash_size <= 0)
  461. return;
  462. /* 0 means: find the address automatically */
  463. if (crash_base <= 0) {
  464. crash_base = find_and_reserve_crashkernel(crash_size);
  465. if (crash_base == -1ULL) {
  466. pr_info("crashkernel reservation failed. "
  467. "No suitable area found.\n");
  468. return;
  469. }
  470. } else {
  471. ret = reserve_bootmem_generic(crash_base, crash_size,
  472. BOOTMEM_EXCLUSIVE);
  473. if (ret < 0) {
  474. pr_info("crashkernel reservation failed - "
  475. "memory is in use\n");
  476. return;
  477. }
  478. }
  479. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  480. "for crashkernel (System RAM: %ldMB)\n",
  481. (unsigned long)(crash_size >> 20),
  482. (unsigned long)(crash_base >> 20),
  483. (unsigned long)(total_mem >> 20));
  484. crashk_res.start = crash_base;
  485. crashk_res.end = crash_base + crash_size - 1;
  486. insert_resource(&iomem_resource, &crashk_res);
  487. }
  488. #else
  489. static void __init reserve_crashkernel(void)
  490. {
  491. }
  492. #endif
  493. static struct resource standard_io_resources[] = {
  494. { .name = "dma1", .start = 0x00, .end = 0x1f,
  495. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  496. { .name = "pic1", .start = 0x20, .end = 0x21,
  497. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  498. { .name = "timer0", .start = 0x40, .end = 0x43,
  499. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  500. { .name = "timer1", .start = 0x50, .end = 0x53,
  501. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  502. { .name = "keyboard", .start = 0x60, .end = 0x60,
  503. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  504. { .name = "keyboard", .start = 0x64, .end = 0x64,
  505. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  506. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  507. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  508. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  509. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  510. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  511. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  512. { .name = "fpu", .start = 0xf0, .end = 0xff,
  513. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  514. };
  515. static void __init reserve_standard_io_resources(void)
  516. {
  517. int i;
  518. /* request I/O space for devices used on all i[345]86 PCs */
  519. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  520. request_resource(&ioport_resource, &standard_io_resources[i]);
  521. }
  522. /*
  523. * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
  524. * is_kdump_kernel() to determine if we are booting after a panic. Hence
  525. * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
  526. */
  527. #ifdef CONFIG_CRASH_DUMP
  528. /* elfcorehdr= specifies the location of elf core header
  529. * stored by the crashed kernel. This option will be passed
  530. * by kexec loader to the capture kernel.
  531. */
  532. static int __init setup_elfcorehdr(char *arg)
  533. {
  534. char *end;
  535. if (!arg)
  536. return -EINVAL;
  537. elfcorehdr_addr = memparse(arg, &end);
  538. return end > arg ? 0 : -EINVAL;
  539. }
  540. early_param("elfcorehdr", setup_elfcorehdr);
  541. #endif
  542. static struct x86_quirks default_x86_quirks __initdata;
  543. struct x86_quirks *x86_quirks __initdata = &default_x86_quirks;
  544. #ifdef CONFIG_X86_RESERVE_LOW_64K
  545. static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
  546. {
  547. printk(KERN_NOTICE
  548. "%s detected: BIOS may corrupt low RAM, working around it.\n",
  549. d->ident);
  550. e820_update_range(0, 0x10000, E820_RAM, E820_RESERVED);
  551. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  552. return 0;
  553. }
  554. #endif
  555. /* List of systems that have known low memory corruption BIOS problems */
  556. static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
  557. #ifdef CONFIG_X86_RESERVE_LOW_64K
  558. {
  559. .callback = dmi_low_memory_corruption,
  560. .ident = "AMI BIOS",
  561. .matches = {
  562. DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
  563. },
  564. },
  565. {
  566. .callback = dmi_low_memory_corruption,
  567. .ident = "Phoenix BIOS",
  568. .matches = {
  569. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies"),
  570. },
  571. },
  572. #endif
  573. {}
  574. };
  575. /*
  576. * Determine if we were loaded by an EFI loader. If so, then we have also been
  577. * passed the efi memmap, systab, etc., so we should use these data structures
  578. * for initialization. Note, the efi init code path is determined by the
  579. * global efi_enabled. This allows the same kernel image to be used on existing
  580. * systems (with a traditional BIOS) as well as on EFI systems.
  581. */
  582. /*
  583. * setup_arch - architecture-specific boot-time initializations
  584. *
  585. * Note: On x86_64, fixmaps are ready for use even before this is called.
  586. */
  587. void __init setup_arch(char **cmdline_p)
  588. {
  589. #ifdef CONFIG_X86_32
  590. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  591. visws_early_detect();
  592. #else
  593. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  594. #endif
  595. /* VMI may relocate the fixmap; do this before touching ioremap area */
  596. vmi_init();
  597. early_cpu_init();
  598. early_ioremap_init();
  599. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  600. screen_info = boot_params.screen_info;
  601. edid_info = boot_params.edid_info;
  602. #ifdef CONFIG_X86_32
  603. apm_info.bios = boot_params.apm_bios_info;
  604. ist_info = boot_params.ist_info;
  605. if (boot_params.sys_desc_table.length != 0) {
  606. set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
  607. machine_id = boot_params.sys_desc_table.table[0];
  608. machine_submodel_id = boot_params.sys_desc_table.table[1];
  609. BIOS_revision = boot_params.sys_desc_table.table[2];
  610. }
  611. #endif
  612. saved_video_mode = boot_params.hdr.vid_mode;
  613. bootloader_type = boot_params.hdr.type_of_loader;
  614. #ifdef CONFIG_BLK_DEV_RAM
  615. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  616. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  617. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  618. #endif
  619. #ifdef CONFIG_EFI
  620. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  621. #ifdef CONFIG_X86_32
  622. "EL32",
  623. #else
  624. "EL64",
  625. #endif
  626. 4)) {
  627. efi_enabled = 1;
  628. efi_reserve_early();
  629. }
  630. #endif
  631. ARCH_SETUP
  632. setup_memory_map();
  633. parse_setup_data();
  634. /* update the e820_saved too */
  635. e820_reserve_setup_data();
  636. copy_edd();
  637. if (!boot_params.hdr.root_flags)
  638. root_mountflags &= ~MS_RDONLY;
  639. init_mm.start_code = (unsigned long) _text;
  640. init_mm.end_code = (unsigned long) _etext;
  641. init_mm.end_data = (unsigned long) _edata;
  642. init_mm.brk = _brk_end;
  643. code_resource.start = virt_to_phys(_text);
  644. code_resource.end = virt_to_phys(_etext)-1;
  645. data_resource.start = virt_to_phys(_etext);
  646. data_resource.end = virt_to_phys(_edata)-1;
  647. bss_resource.start = virt_to_phys(&__bss_start);
  648. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  649. #ifdef CONFIG_CMDLINE_BOOL
  650. #ifdef CONFIG_CMDLINE_OVERRIDE
  651. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  652. #else
  653. if (builtin_cmdline[0]) {
  654. /* append boot loader cmdline to builtin */
  655. strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
  656. strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  657. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  658. }
  659. #endif
  660. #endif
  661. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  662. *cmdline_p = command_line;
  663. parse_early_param();
  664. #ifdef CONFIG_X86_64
  665. check_efer();
  666. #endif
  667. /* Must be before kernel pagetables are setup */
  668. vmi_activate();
  669. /* after early param, so could get panic from serial */
  670. reserve_early_setup_data();
  671. if (acpi_mps_check()) {
  672. #ifdef CONFIG_X86_LOCAL_APIC
  673. disable_apic = 1;
  674. #endif
  675. setup_clear_cpu_cap(X86_FEATURE_APIC);
  676. }
  677. #ifdef CONFIG_PCI
  678. if (pci_early_dump_regs)
  679. early_dump_pci_devices();
  680. #endif
  681. finish_e820_parsing();
  682. if (efi_enabled)
  683. efi_init();
  684. dmi_scan_machine();
  685. dmi_check_system(bad_bios_dmi_table);
  686. /*
  687. * VMware detection requires dmi to be available, so this
  688. * needs to be done after dmi_scan_machine, for the BP.
  689. */
  690. init_hypervisor(&boot_cpu_data);
  691. #ifdef CONFIG_X86_32
  692. probe_roms();
  693. #endif
  694. /* after parse_early_param, so could debug it */
  695. insert_resource(&iomem_resource, &code_resource);
  696. insert_resource(&iomem_resource, &data_resource);
  697. insert_resource(&iomem_resource, &bss_resource);
  698. #ifdef CONFIG_X86_32
  699. if (ppro_with_ram_bug()) {
  700. e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
  701. E820_RESERVED);
  702. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  703. printk(KERN_INFO "fixed physical RAM map:\n");
  704. e820_print_map("bad_ppro");
  705. }
  706. #else
  707. early_gart_iommu_check();
  708. #endif
  709. /*
  710. * partially used pages are not usable - thus
  711. * we are rounding upwards:
  712. */
  713. max_pfn = e820_end_of_ram_pfn();
  714. /* preallocate 4k for mptable mpc */
  715. early_reserve_e820_mpc_new();
  716. /* update e820 for memory not covered by WB MTRRs */
  717. mtrr_bp_init();
  718. if (mtrr_trim_uncached_memory(max_pfn))
  719. max_pfn = e820_end_of_ram_pfn();
  720. #ifdef CONFIG_X86_32
  721. /* max_low_pfn get updated here */
  722. find_low_pfn_range();
  723. #else
  724. num_physpages = max_pfn;
  725. check_x2apic();
  726. /* How many end-of-memory variables you have, grandma! */
  727. /* need this before calling reserve_initrd */
  728. if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
  729. max_low_pfn = e820_end_of_low_ram_pfn();
  730. else
  731. max_low_pfn = max_pfn;
  732. high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
  733. #endif
  734. #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
  735. setup_bios_corruption_check();
  736. #endif
  737. reserve_brk();
  738. /* max_pfn_mapped is updated here */
  739. max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT);
  740. max_pfn_mapped = max_low_pfn_mapped;
  741. #ifdef CONFIG_X86_64
  742. if (max_pfn > max_low_pfn) {
  743. max_pfn_mapped = init_memory_mapping(1UL<<32,
  744. max_pfn<<PAGE_SHIFT);
  745. /* can we preseve max_low_pfn ?*/
  746. max_low_pfn = max_pfn;
  747. }
  748. #endif
  749. /*
  750. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  751. */
  752. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  753. if (init_ohci1394_dma_early)
  754. init_ohci1394_dma_on_all_controllers();
  755. #endif
  756. reserve_initrd();
  757. vsmp_init();
  758. io_delay_init();
  759. /*
  760. * Parse the ACPI tables for possible boot-time SMP configuration.
  761. */
  762. acpi_boot_table_init();
  763. early_acpi_boot_init();
  764. #ifdef CONFIG_ACPI_NUMA
  765. /*
  766. * Parse SRAT to discover nodes.
  767. */
  768. acpi_numa_init();
  769. #endif
  770. initmem_init(0, max_pfn);
  771. #ifdef CONFIG_ACPI_SLEEP
  772. /*
  773. * Reserve low memory region for sleep support.
  774. */
  775. acpi_reserve_bootmem();
  776. #endif
  777. /*
  778. * Find and reserve possible boot-time SMP configuration:
  779. */
  780. find_smp_config();
  781. reserve_crashkernel();
  782. #ifdef CONFIG_X86_64
  783. /*
  784. * dma32_reserve_bootmem() allocates bootmem which may conflict
  785. * with the crashkernel command line, so do that after
  786. * reserve_crashkernel()
  787. */
  788. dma32_reserve_bootmem();
  789. #endif
  790. reserve_ibft_region();
  791. #ifdef CONFIG_KVM_CLOCK
  792. kvmclock_init();
  793. #endif
  794. paravirt_pagetable_setup_start(swapper_pg_dir);
  795. paging_init();
  796. paravirt_pagetable_setup_done(swapper_pg_dir);
  797. paravirt_post_allocator_init();
  798. #ifdef CONFIG_X86_64
  799. map_vsyscall();
  800. #endif
  801. generic_apic_probe();
  802. early_quirks();
  803. /*
  804. * Read APIC and some other early information from ACPI tables.
  805. */
  806. acpi_boot_init();
  807. #if defined(CONFIG_X86_MPPARSE) || defined(CONFIG_X86_VISWS)
  808. /*
  809. * get boot-time SMP configuration:
  810. */
  811. if (smp_found_config)
  812. get_smp_config();
  813. #endif
  814. prefill_possible_map();
  815. #ifdef CONFIG_X86_64
  816. init_cpu_to_node();
  817. #endif
  818. init_apic_mappings();
  819. ioapic_init_mappings();
  820. /* need to wait for io_apic is mapped */
  821. probe_nr_irqs_gsi();
  822. kvm_guest_init();
  823. e820_reserve_resources();
  824. e820_mark_nosave_regions(max_low_pfn);
  825. #ifdef CONFIG_X86_32
  826. request_resource(&iomem_resource, &video_ram_resource);
  827. #endif
  828. reserve_standard_io_resources();
  829. e820_setup_gap();
  830. #ifdef CONFIG_VT
  831. #if defined(CONFIG_VGA_CONSOLE)
  832. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  833. conswitchp = &vga_con;
  834. #elif defined(CONFIG_DUMMY_CONSOLE)
  835. conswitchp = &dummy_con;
  836. #endif
  837. #endif
  838. }
  839. #ifdef CONFIG_X86_32
  840. /**
  841. * x86_quirk_pre_intr_init - initialisation prior to setting up interrupt vectors
  842. *
  843. * Description:
  844. * Perform any necessary interrupt initialisation prior to setting up
  845. * the "ordinary" interrupt call gates. For legacy reasons, the ISA
  846. * interrupts should be initialised here if the machine emulates a PC
  847. * in any way.
  848. **/
  849. void __init x86_quirk_pre_intr_init(void)
  850. {
  851. if (x86_quirks->arch_pre_intr_init) {
  852. if (x86_quirks->arch_pre_intr_init())
  853. return;
  854. }
  855. init_ISA_irqs();
  856. }
  857. /**
  858. * x86_quirk_intr_init - post gate setup interrupt initialisation
  859. *
  860. * Description:
  861. * Fill in any interrupts that may have been left out by the general
  862. * init_IRQ() routine. interrupts having to do with the machine rather
  863. * than the devices on the I/O bus (like APIC interrupts in intel MP
  864. * systems) are started here.
  865. **/
  866. void __init x86_quirk_intr_init(void)
  867. {
  868. if (x86_quirks->arch_intr_init) {
  869. if (x86_quirks->arch_intr_init())
  870. return;
  871. }
  872. }
  873. /**
  874. * x86_quirk_trap_init - initialise system specific traps
  875. *
  876. * Description:
  877. * Called as the final act of trap_init(). Used in VISWS to initialise
  878. * the various board specific APIC traps.
  879. **/
  880. void __init x86_quirk_trap_init(void)
  881. {
  882. if (x86_quirks->arch_trap_init) {
  883. if (x86_quirks->arch_trap_init())
  884. return;
  885. }
  886. }
  887. static struct irqaction irq0 = {
  888. .handler = timer_interrupt,
  889. .flags = IRQF_DISABLED | IRQF_NOBALANCING | IRQF_IRQPOLL | IRQF_TIMER,
  890. .mask = CPU_MASK_NONE,
  891. .name = "timer"
  892. };
  893. /**
  894. * x86_quirk_pre_time_init - do any specific initialisations before.
  895. *
  896. **/
  897. void __init x86_quirk_pre_time_init(void)
  898. {
  899. if (x86_quirks->arch_pre_time_init)
  900. x86_quirks->arch_pre_time_init();
  901. }
  902. /**
  903. * x86_quirk_time_init - do any specific initialisations for the system timer.
  904. *
  905. * Description:
  906. * Must plug the system timer interrupt source at HZ into the IRQ listed
  907. * in irq_vectors.h:TIMER_IRQ
  908. **/
  909. void __init x86_quirk_time_init(void)
  910. {
  911. if (x86_quirks->arch_time_init) {
  912. /*
  913. * A nonzero return code does not mean failure, it means
  914. * that the architecture quirk does not want any
  915. * generic (timer) setup to be performed after this:
  916. */
  917. if (x86_quirks->arch_time_init())
  918. return;
  919. }
  920. irq0.mask = cpumask_of_cpu(0);
  921. setup_irq(0, &irq0);
  922. }
  923. #endif /* CONFIG_X86_32 */