setup_32.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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/crash_dump.h>
  44. #include <linux/dmi.h>
  45. #include <linux/pfn.h>
  46. #include <linux/pci.h>
  47. #include <linux/init_ohci1394_dma.h>
  48. #include <linux/kvm_para.h>
  49. #include <video/edid.h>
  50. #include <asm/mtrr.h>
  51. #include <asm/apic.h>
  52. #include <asm/e820.h>
  53. #include <asm/mpspec.h>
  54. #include <asm/mmzone.h>
  55. #include <asm/setup.h>
  56. #include <asm/arch_hooks.h>
  57. #include <asm/sections.h>
  58. #include <asm/io_apic.h>
  59. #include <asm/ist.h>
  60. #include <asm/io.h>
  61. #include <asm/vmi.h>
  62. #include <setup_arch.h>
  63. #include <asm/bios_ebda.h>
  64. #include <asm/cacheflush.h>
  65. #include <asm/processor.h>
  66. #include <asm/efi.h>
  67. /* This value is set up by the early boot code to point to the value
  68. immediately after the boot time page tables. It contains a *physical*
  69. address, and must not be in the .bss segment! */
  70. unsigned long init_pg_tables_start __initdata = ~0UL;
  71. unsigned long init_pg_tables_end __initdata = ~0UL;
  72. /*
  73. * Machine setup..
  74. */
  75. static struct resource data_resource = {
  76. .name = "Kernel data",
  77. .start = 0,
  78. .end = 0,
  79. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  80. };
  81. static struct resource code_resource = {
  82. .name = "Kernel code",
  83. .start = 0,
  84. .end = 0,
  85. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  86. };
  87. static struct resource bss_resource = {
  88. .name = "Kernel bss",
  89. .start = 0,
  90. .end = 0,
  91. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  92. };
  93. static struct resource video_ram_resource = {
  94. .name = "Video RAM area",
  95. .start = 0xa0000,
  96. .end = 0xbffff,
  97. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  98. };
  99. static struct resource standard_io_resources[] = { {
  100. .name = "dma1",
  101. .start = 0x0000,
  102. .end = 0x001f,
  103. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  104. }, {
  105. .name = "pic1",
  106. .start = 0x0020,
  107. .end = 0x0021,
  108. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  109. }, {
  110. .name = "timer0",
  111. .start = 0x0040,
  112. .end = 0x0043,
  113. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  114. }, {
  115. .name = "timer1",
  116. .start = 0x0050,
  117. .end = 0x0053,
  118. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  119. }, {
  120. .name = "keyboard",
  121. .start = 0x0060,
  122. .end = 0x0060,
  123. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  124. }, {
  125. .name = "keyboard",
  126. .start = 0x0064,
  127. .end = 0x0064,
  128. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  129. }, {
  130. .name = "dma page reg",
  131. .start = 0x0080,
  132. .end = 0x008f,
  133. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  134. }, {
  135. .name = "pic2",
  136. .start = 0x00a0,
  137. .end = 0x00a1,
  138. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  139. }, {
  140. .name = "dma2",
  141. .start = 0x00c0,
  142. .end = 0x00df,
  143. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  144. }, {
  145. .name = "fpu",
  146. .start = 0x00f0,
  147. .end = 0x00ff,
  148. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  149. } };
  150. /* cpu data as detected by the assembly code in head.S */
  151. struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  152. /* common cpu data for all cpus */
  153. struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  154. EXPORT_SYMBOL(boot_cpu_data);
  155. unsigned int def_to_bigsmp;
  156. #ifndef CONFIG_X86_PAE
  157. unsigned long mmu_cr4_features;
  158. #else
  159. unsigned long mmu_cr4_features = X86_CR4_PAE;
  160. #endif
  161. /* for MCA, but anyone else can use it if they want */
  162. unsigned int machine_id;
  163. unsigned int machine_submodel_id;
  164. unsigned int BIOS_revision;
  165. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  166. int bootloader_type;
  167. /* user-defined highmem size */
  168. static unsigned int highmem_pages = -1;
  169. /*
  170. * Setup options
  171. */
  172. struct screen_info screen_info;
  173. EXPORT_SYMBOL(screen_info);
  174. struct apm_info apm_info;
  175. EXPORT_SYMBOL(apm_info);
  176. struct edid_info edid_info;
  177. EXPORT_SYMBOL_GPL(edid_info);
  178. struct ist_info ist_info;
  179. #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
  180. defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
  181. EXPORT_SYMBOL(ist_info);
  182. #endif
  183. extern void early_cpu_init(void);
  184. extern int root_mountflags;
  185. unsigned long saved_video_mode;
  186. #define RAMDISK_IMAGE_START_MASK 0x07FF
  187. #define RAMDISK_PROMPT_FLAG 0x8000
  188. #define RAMDISK_LOAD_FLAG 0x4000
  189. static char __initdata command_line[COMMAND_LINE_SIZE];
  190. #ifndef CONFIG_DEBUG_BOOT_PARAMS
  191. struct boot_params __initdata boot_params;
  192. #else
  193. struct boot_params boot_params;
  194. #endif
  195. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  196. struct edd edd;
  197. #ifdef CONFIG_EDD_MODULE
  198. EXPORT_SYMBOL(edd);
  199. #endif
  200. /**
  201. * copy_edd() - Copy the BIOS EDD information
  202. * from boot_params into a safe place.
  203. *
  204. */
  205. static inline void copy_edd(void)
  206. {
  207. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  208. sizeof(edd.mbr_signature));
  209. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  210. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  211. edd.edd_info_nr = boot_params.eddbuf_entries;
  212. }
  213. #else
  214. static inline void copy_edd(void)
  215. {
  216. }
  217. #endif
  218. #ifdef CONFIG_PROC_VMCORE
  219. /* elfcorehdr= specifies the location of elf core header
  220. * stored by the crashed kernel.
  221. */
  222. static int __init parse_elfcorehdr(char *arg)
  223. {
  224. if (!arg)
  225. return -EINVAL;
  226. elfcorehdr_addr = memparse(arg, &arg);
  227. return 0;
  228. }
  229. early_param("elfcorehdr", parse_elfcorehdr);
  230. #endif /* CONFIG_PROC_VMCORE */
  231. /*
  232. * highmem=size forces highmem to be exactly 'size' bytes.
  233. * This works even on boxes that have no highmem otherwise.
  234. * This also works to reduce highmem size on bigger boxes.
  235. */
  236. static int __init parse_highmem(char *arg)
  237. {
  238. if (!arg)
  239. return -EINVAL;
  240. highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
  241. return 0;
  242. }
  243. early_param("highmem", parse_highmem);
  244. /*
  245. * vmalloc=size forces the vmalloc area to be exactly 'size'
  246. * bytes. This can be used to increase (or decrease) the
  247. * vmalloc area - the default is 128m.
  248. */
  249. static int __init parse_vmalloc(char *arg)
  250. {
  251. if (!arg)
  252. return -EINVAL;
  253. __VMALLOC_RESERVE = memparse(arg, &arg);
  254. return 0;
  255. }
  256. early_param("vmalloc", parse_vmalloc);
  257. /*
  258. * reservetop=size reserves a hole at the top of the kernel address space which
  259. * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
  260. * so relocating the fixmap can be done before paging initialization.
  261. */
  262. static int __init parse_reservetop(char *arg)
  263. {
  264. unsigned long address;
  265. if (!arg)
  266. return -EINVAL;
  267. address = memparse(arg, &arg);
  268. reserve_top_address(address);
  269. return 0;
  270. }
  271. early_param("reservetop", parse_reservetop);
  272. /*
  273. * Determine low and high memory ranges:
  274. */
  275. unsigned long __init find_max_low_pfn(void)
  276. {
  277. unsigned long max_low_pfn;
  278. max_low_pfn = max_pfn;
  279. if (max_low_pfn > MAXMEM_PFN) {
  280. if (highmem_pages == -1)
  281. highmem_pages = max_pfn - MAXMEM_PFN;
  282. if (highmem_pages + MAXMEM_PFN < max_pfn)
  283. max_pfn = MAXMEM_PFN + highmem_pages;
  284. if (highmem_pages + MAXMEM_PFN > max_pfn) {
  285. printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
  286. highmem_pages = 0;
  287. }
  288. max_low_pfn = MAXMEM_PFN;
  289. #ifndef CONFIG_HIGHMEM
  290. /* Maximum memory usable is what is directly addressable */
  291. printk(KERN_WARNING "Warning only %ldMB will be used.\n",
  292. MAXMEM>>20);
  293. if (max_pfn > MAX_NONPAE_PFN)
  294. printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
  295. else
  296. printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
  297. max_pfn = MAXMEM_PFN;
  298. #else /* !CONFIG_HIGHMEM */
  299. #ifndef CONFIG_HIGHMEM64G
  300. if (max_pfn > MAX_NONPAE_PFN) {
  301. max_pfn = MAX_NONPAE_PFN;
  302. printk(KERN_WARNING "Warning only 4GB will be used.\n");
  303. printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
  304. }
  305. #endif /* !CONFIG_HIGHMEM64G */
  306. #endif /* !CONFIG_HIGHMEM */
  307. } else {
  308. if (highmem_pages == -1)
  309. highmem_pages = 0;
  310. #ifdef CONFIG_HIGHMEM
  311. if (highmem_pages >= max_pfn) {
  312. printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
  313. highmem_pages = 0;
  314. }
  315. if (highmem_pages) {
  316. if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
  317. printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
  318. highmem_pages = 0;
  319. }
  320. max_low_pfn -= highmem_pages;
  321. }
  322. #else
  323. if (highmem_pages)
  324. printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
  325. #endif
  326. }
  327. return max_low_pfn;
  328. }
  329. #ifndef CONFIG_NEED_MULTIPLE_NODES
  330. static void __init setup_bootmem_allocator(void);
  331. static unsigned long __init setup_memory(void)
  332. {
  333. /*
  334. * partially used pages are not usable - thus
  335. * we are rounding upwards:
  336. */
  337. min_low_pfn = PFN_UP(init_pg_tables_end);
  338. max_low_pfn = find_max_low_pfn();
  339. #ifdef CONFIG_HIGHMEM
  340. highstart_pfn = highend_pfn = max_pfn;
  341. if (max_pfn > max_low_pfn) {
  342. highstart_pfn = max_low_pfn;
  343. }
  344. memory_present(0, 0, highend_pfn);
  345. printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
  346. pages_to_mb(highend_pfn - highstart_pfn));
  347. num_physpages = highend_pfn;
  348. high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
  349. #else
  350. memory_present(0, 0, max_low_pfn);
  351. num_physpages = max_low_pfn;
  352. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
  353. #endif
  354. #ifdef CONFIG_FLATMEM
  355. max_mapnr = num_physpages;
  356. #endif
  357. printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
  358. pages_to_mb(max_low_pfn));
  359. setup_bootmem_allocator();
  360. return max_low_pfn;
  361. }
  362. static void __init zone_sizes_init(void)
  363. {
  364. unsigned long max_zone_pfns[MAX_NR_ZONES];
  365. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  366. max_zone_pfns[ZONE_DMA] =
  367. virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  368. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  369. remove_all_active_ranges();
  370. #ifdef CONFIG_HIGHMEM
  371. max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
  372. e820_register_active_regions(0, 0, highend_pfn);
  373. #else
  374. e820_register_active_regions(0, 0, max_low_pfn);
  375. #endif
  376. free_area_init_nodes(max_zone_pfns);
  377. }
  378. #else
  379. extern unsigned long __init setup_memory(void);
  380. extern void zone_sizes_init(void);
  381. #endif /* !CONFIG_NEED_MULTIPLE_NODES */
  382. static inline unsigned long long get_total_mem(void)
  383. {
  384. unsigned long long total;
  385. total = max_low_pfn - min_low_pfn;
  386. #ifdef CONFIG_HIGHMEM
  387. total += highend_pfn - highstart_pfn;
  388. #endif
  389. return total << PAGE_SHIFT;
  390. }
  391. #ifdef CONFIG_KEXEC
  392. static void __init reserve_crashkernel(void)
  393. {
  394. unsigned long long total_mem;
  395. unsigned long long crash_size, crash_base;
  396. int ret;
  397. total_mem = get_total_mem();
  398. ret = parse_crashkernel(boot_command_line, total_mem,
  399. &crash_size, &crash_base);
  400. if (ret == 0 && crash_size > 0) {
  401. if (crash_base <= 0) {
  402. printk(KERN_INFO "crashkernel reservation failed - "
  403. "you have to specify a base address\n");
  404. return;
  405. }
  406. if (reserve_bootmem_generic(crash_base, crash_size,
  407. BOOTMEM_EXCLUSIVE) < 0) {
  408. printk(KERN_INFO "crashkernel reservation failed - "
  409. "memory is in use\n");
  410. return;
  411. }
  412. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  413. "for crashkernel (System RAM: %ldMB)\n",
  414. (unsigned long)(crash_size >> 20),
  415. (unsigned long)(crash_base >> 20),
  416. (unsigned long)(total_mem >> 20));
  417. crashk_res.start = crash_base;
  418. crashk_res.end = crash_base + crash_size - 1;
  419. insert_resource(&iomem_resource, &crashk_res);
  420. }
  421. }
  422. #else
  423. static inline void __init reserve_crashkernel(void)
  424. {}
  425. #endif
  426. #ifdef CONFIG_BLK_DEV_INITRD
  427. static bool do_relocate_initrd = false;
  428. static void __init reserve_initrd(void)
  429. {
  430. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  431. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  432. u64 ramdisk_end = ramdisk_image + ramdisk_size;
  433. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  434. u64 ramdisk_here;
  435. if (!boot_params.hdr.type_of_loader ||
  436. !ramdisk_image || !ramdisk_size)
  437. return; /* No initrd provided by bootloader */
  438. initrd_start = 0;
  439. if (ramdisk_size >= end_of_lowmem/2) {
  440. free_early(ramdisk_image, ramdisk_end);
  441. printk(KERN_ERR "initrd too large to handle, "
  442. "disabling initrd\n");
  443. return;
  444. }
  445. printk(KERN_INFO "old RAMDISK: %08llx - %08llx\n", ramdisk_image,
  446. ramdisk_end);
  447. if (ramdisk_end <= end_of_lowmem) {
  448. /* All in lowmem, easy case */
  449. /*
  450. * don't need to reserve again, already reserved early
  451. * in i386_start_kernel
  452. */
  453. initrd_start = ramdisk_image + PAGE_OFFSET;
  454. initrd_end = initrd_start+ramdisk_size;
  455. return;
  456. }
  457. /* We need to move the initrd down into lowmem */
  458. ramdisk_here = find_e820_area(min_low_pfn<<PAGE_SHIFT,
  459. end_of_lowmem, ramdisk_size,
  460. PAGE_SIZE);
  461. if (ramdisk_here == -1ULL)
  462. panic("Cannot find place for new RAMDISK of size %lld\n",
  463. ramdisk_size);
  464. /* Note: this includes all the lowmem currently occupied by
  465. the initrd, we rely on that fact to keep the data intact. */
  466. reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
  467. "NEW RAMDISK");
  468. initrd_start = ramdisk_here + PAGE_OFFSET;
  469. initrd_end = initrd_start + ramdisk_size;
  470. printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
  471. ramdisk_here, ramdisk_here + ramdisk_size);
  472. do_relocate_initrd = true;
  473. }
  474. #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
  475. static void __init relocate_initrd(void)
  476. {
  477. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  478. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  479. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  480. u64 ramdisk_here;
  481. unsigned long slop, clen, mapaddr;
  482. char *p, *q;
  483. if (!do_relocate_initrd)
  484. return;
  485. ramdisk_here = initrd_start - PAGE_OFFSET;
  486. q = (char *)initrd_start;
  487. /* Copy any lowmem portion of the initrd */
  488. if (ramdisk_image < end_of_lowmem) {
  489. clen = end_of_lowmem - ramdisk_image;
  490. p = (char *)__va(ramdisk_image);
  491. memcpy(q, p, clen);
  492. q += clen;
  493. /* need to free these low pages...*/
  494. printk(KERN_INFO "Freeing old partial RAMDISK %08llx-%08llx\n",
  495. ramdisk_image, ramdisk_image + clen - 1);
  496. free_bootmem(ramdisk_image, clen);
  497. ramdisk_image += clen;
  498. ramdisk_size -= clen;
  499. }
  500. /* Copy the highmem portion of the initrd */
  501. while (ramdisk_size) {
  502. slop = ramdisk_image & ~PAGE_MASK;
  503. clen = ramdisk_size;
  504. if (clen > MAX_MAP_CHUNK-slop)
  505. clen = MAX_MAP_CHUNK-slop;
  506. mapaddr = ramdisk_image & PAGE_MASK;
  507. p = early_ioremap(mapaddr, clen+slop);
  508. memcpy(q, p+slop, clen);
  509. early_iounmap(p, clen+slop);
  510. q += clen;
  511. ramdisk_image += clen;
  512. ramdisk_size -= clen;
  513. }
  514. /* high pages is not converted by early_res_to_bootmem */
  515. ramdisk_image = boot_params.hdr.ramdisk_image;
  516. ramdisk_size = boot_params.hdr.ramdisk_size;
  517. printk(KERN_INFO "Copied RAMDISK from %016llx - %016llx to %08llx - %08llx\n",
  518. ramdisk_image, ramdisk_image + ramdisk_size - 1,
  519. ramdisk_here, ramdisk_here + ramdisk_size - 1);
  520. /* need to free that, otherwise init highmem will reserve it again */
  521. free_early(ramdisk_image, ramdisk_image+ramdisk_size);
  522. }
  523. #endif /* CONFIG_BLK_DEV_INITRD */
  524. void __init setup_bootmem_allocator(void)
  525. {
  526. int i;
  527. unsigned long bootmap_size, bootmap;
  528. /*
  529. * Initialize the boot-time allocator (with low memory only):
  530. */
  531. bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
  532. bootmap = find_e820_area(min_low_pfn<<PAGE_SHIFT,
  533. max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
  534. PAGE_SIZE);
  535. if (bootmap == -1L)
  536. panic("Cannot find bootmem map of size %ld\n", bootmap_size);
  537. reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
  538. #ifdef CONFIG_BLK_DEV_INITRD
  539. reserve_initrd();
  540. #endif
  541. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, max_low_pfn);
  542. printk(KERN_INFO " mapped low ram: 0 - %08lx\n",
  543. max_pfn_mapped<<PAGE_SHIFT);
  544. printk(KERN_INFO " low ram: %08lx - %08lx\n",
  545. min_low_pfn<<PAGE_SHIFT, max_low_pfn<<PAGE_SHIFT);
  546. printk(KERN_INFO " bootmap %08lx - %08lx\n",
  547. bootmap, bootmap + bootmap_size);
  548. for_each_online_node(i)
  549. free_bootmem_with_active_regions(i, max_low_pfn);
  550. early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
  551. #ifdef CONFIG_ACPI_SLEEP
  552. /*
  553. * Reserve low memory region for sleep support.
  554. */
  555. acpi_reserve_bootmem();
  556. #endif
  557. #ifdef CONFIG_X86_FIND_SMP_CONFIG
  558. /*
  559. * Find and reserve possible boot-time SMP configuration:
  560. */
  561. find_smp_config();
  562. #endif
  563. reserve_crashkernel();
  564. reserve_ibft_region();
  565. }
  566. /*
  567. * The node 0 pgdat is initialized before all of these because
  568. * it's needed for bootmem. node>0 pgdats have their virtual
  569. * space allocated before the pagetables are in place to access
  570. * them, so they can't be cleared then.
  571. *
  572. * This should all compile down to nothing when NUMA is off.
  573. */
  574. static void __init remapped_pgdat_init(void)
  575. {
  576. int nid;
  577. for_each_online_node(nid) {
  578. if (nid != 0)
  579. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  580. }
  581. }
  582. #ifdef CONFIG_MCA
  583. static void set_mca_bus(int x)
  584. {
  585. MCA_bus = x;
  586. }
  587. #else
  588. static void set_mca_bus(int x) { }
  589. #endif
  590. #ifdef CONFIG_NUMA
  591. /*
  592. * In the golden day, when everything among i386 and x86_64 will be
  593. * integrated, this will not live here
  594. */
  595. void *x86_cpu_to_node_map_early_ptr;
  596. int x86_cpu_to_node_map_init[NR_CPUS] = {
  597. [0 ... NR_CPUS-1] = NUMA_NO_NODE
  598. };
  599. DEFINE_PER_CPU(int, x86_cpu_to_node_map) = NUMA_NO_NODE;
  600. #endif
  601. static void probe_roms(void);
  602. /*
  603. * Determine if we were loaded by an EFI loader. If so, then we have also been
  604. * passed the efi memmap, systab, etc., so we should use these data structures
  605. * for initialization. Note, the efi init code path is determined by the
  606. * global efi_enabled. This allows the same kernel image to be used on existing
  607. * systems (with a traditional BIOS) as well as on EFI systems.
  608. */
  609. void __init setup_arch(char **cmdline_p)
  610. {
  611. int i;
  612. unsigned long max_low_pfn;
  613. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  614. pre_setup_arch_hook();
  615. early_cpu_init();
  616. early_ioremap_init();
  617. reserve_setup_data();
  618. #ifdef CONFIG_EFI
  619. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  620. "EL32", 4)) {
  621. efi_enabled = 1;
  622. efi_reserve_early();
  623. }
  624. #endif
  625. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  626. screen_info = boot_params.screen_info;
  627. edid_info = boot_params.edid_info;
  628. apm_info.bios = boot_params.apm_bios_info;
  629. ist_info = boot_params.ist_info;
  630. saved_video_mode = boot_params.hdr.vid_mode;
  631. if( boot_params.sys_desc_table.length != 0 ) {
  632. set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
  633. machine_id = boot_params.sys_desc_table.table[0];
  634. machine_submodel_id = boot_params.sys_desc_table.table[1];
  635. BIOS_revision = boot_params.sys_desc_table.table[2];
  636. }
  637. bootloader_type = boot_params.hdr.type_of_loader;
  638. #ifdef CONFIG_BLK_DEV_RAM
  639. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  640. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  641. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  642. #endif
  643. ARCH_SETUP
  644. setup_memory_map();
  645. copy_edd();
  646. if (!boot_params.hdr.root_flags)
  647. root_mountflags &= ~MS_RDONLY;
  648. init_mm.start_code = (unsigned long) _text;
  649. init_mm.end_code = (unsigned long) _etext;
  650. init_mm.end_data = (unsigned long) _edata;
  651. init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
  652. code_resource.start = virt_to_phys(_text);
  653. code_resource.end = virt_to_phys(_etext)-1;
  654. data_resource.start = virt_to_phys(_etext);
  655. data_resource.end = virt_to_phys(_edata)-1;
  656. bss_resource.start = virt_to_phys(&__bss_start);
  657. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  658. parse_setup_data();
  659. parse_early_param();
  660. finish_e820_parsing();
  661. probe_roms();
  662. /* after parse_early_param, so could debug it */
  663. insert_resource(&iomem_resource, &code_resource);
  664. insert_resource(&iomem_resource, &data_resource);
  665. insert_resource(&iomem_resource, &bss_resource);
  666. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  667. *cmdline_p = command_line;
  668. if (efi_enabled)
  669. efi_init();
  670. e820_register_active_regions(0, 0, -1UL);
  671. /*
  672. * partially used pages are not usable - thus
  673. * we are rounding upwards:
  674. */
  675. max_pfn = e820_end_of_ram();
  676. /* preallocate 4k for mptable mpc */
  677. early_reserve_e820_mpc_new();
  678. /* update e820 for memory not covered by WB MTRRs */
  679. mtrr_bp_init();
  680. if (mtrr_trim_uncached_memory(max_pfn)) {
  681. remove_all_active_ranges();
  682. e820_register_active_regions(0, 0, -1UL);
  683. max_pfn = e820_end_of_ram();
  684. }
  685. max_low_pfn = setup_memory();
  686. #ifdef CONFIG_KVM_CLOCK
  687. kvmclock_init();
  688. #endif
  689. #ifdef CONFIG_VMI
  690. /*
  691. * Must be after max_low_pfn is determined, and before kernel
  692. * pagetables are setup.
  693. */
  694. vmi_init();
  695. #endif
  696. kvm_guest_init();
  697. /*
  698. * NOTE: before this point _nobody_ is allowed to allocate
  699. * any memory using the bootmem allocator. Although the
  700. * allocator is now initialised only the first 8Mb of the kernel
  701. * virtual address space has been mapped. All allocations before
  702. * paging_init() has completed must use the alloc_bootmem_low_pages()
  703. * variant (which allocates DMA'able memory) and care must be taken
  704. * not to exceed the 8Mb limit.
  705. */
  706. paging_init();
  707. /*
  708. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  709. */
  710. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  711. if (init_ohci1394_dma_early)
  712. init_ohci1394_dma_on_all_controllers();
  713. #endif
  714. /*
  715. * NOTE: at this point the bootmem allocator is fully available.
  716. */
  717. #ifdef CONFIG_BLK_DEV_INITRD
  718. relocate_initrd();
  719. #endif
  720. remapped_pgdat_init();
  721. sparse_init();
  722. zone_sizes_init();
  723. paravirt_post_allocator_init();
  724. dmi_scan_machine();
  725. io_delay_init();
  726. #ifdef CONFIG_X86_SMP
  727. /*
  728. * setup to use the early static init tables during kernel startup
  729. * X86_SMP will exclude sub-arches that don't deal well with it.
  730. */
  731. x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
  732. x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
  733. #ifdef CONFIG_NUMA
  734. x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
  735. #endif
  736. #endif
  737. #ifdef CONFIG_X86_GENERICARCH
  738. generic_apic_probe();
  739. #endif
  740. #ifdef CONFIG_ACPI
  741. /*
  742. * Parse the ACPI tables for possible boot-time SMP configuration.
  743. */
  744. acpi_boot_table_init();
  745. #endif
  746. early_quirks();
  747. #ifdef CONFIG_ACPI
  748. acpi_boot_init();
  749. #endif
  750. #if defined(CONFIG_X86_MPPARSE) || defined(CONFIG_X86_VISWS)
  751. if (smp_found_config)
  752. get_smp_config();
  753. #endif
  754. #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
  755. if (def_to_bigsmp)
  756. printk(KERN_WARNING "More than 8 CPUs detected and "
  757. "CONFIG_X86_PC cannot handle it.\nUse "
  758. "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
  759. #endif
  760. e820_reserve_resources();
  761. e820_mark_nosave_regions(max_low_pfn);
  762. request_resource(&iomem_resource, &video_ram_resource);
  763. /* request I/O space for devices used on all i[345]86 PCs */
  764. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  765. request_resource(&ioport_resource, &standard_io_resources[i]);
  766. e820_setup_gap();
  767. #ifdef CONFIG_VT
  768. #if defined(CONFIG_VGA_CONSOLE)
  769. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  770. conswitchp = &vga_con;
  771. #elif defined(CONFIG_DUMMY_CONSOLE)
  772. conswitchp = &dummy_con;
  773. #endif
  774. #endif
  775. }
  776. static struct resource system_rom_resource = {
  777. .name = "System ROM",
  778. .start = 0xf0000,
  779. .end = 0xfffff,
  780. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  781. };
  782. static struct resource extension_rom_resource = {
  783. .name = "Extension ROM",
  784. .start = 0xe0000,
  785. .end = 0xeffff,
  786. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  787. };
  788. static struct resource adapter_rom_resources[] = { {
  789. .name = "Adapter ROM",
  790. .start = 0xc8000,
  791. .end = 0,
  792. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  793. }, {
  794. .name = "Adapter ROM",
  795. .start = 0,
  796. .end = 0,
  797. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  798. }, {
  799. .name = "Adapter ROM",
  800. .start = 0,
  801. .end = 0,
  802. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  803. }, {
  804. .name = "Adapter ROM",
  805. .start = 0,
  806. .end = 0,
  807. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  808. }, {
  809. .name = "Adapter ROM",
  810. .start = 0,
  811. .end = 0,
  812. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  813. }, {
  814. .name = "Adapter ROM",
  815. .start = 0,
  816. .end = 0,
  817. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  818. } };
  819. static struct resource video_rom_resource = {
  820. .name = "Video ROM",
  821. .start = 0xc0000,
  822. .end = 0xc7fff,
  823. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  824. };
  825. #define ROMSIGNATURE 0xaa55
  826. static int __init romsignature(const unsigned char *rom)
  827. {
  828. const unsigned short * const ptr = (const unsigned short *)rom;
  829. unsigned short sig;
  830. return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
  831. }
  832. static int __init romchecksum(const unsigned char *rom, unsigned long length)
  833. {
  834. unsigned char sum, c;
  835. for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
  836. sum += c;
  837. return !length && !sum;
  838. }
  839. static void __init probe_roms(void)
  840. {
  841. const unsigned char *rom;
  842. unsigned long start, length, upper;
  843. unsigned char c;
  844. int i;
  845. /* video rom */
  846. upper = adapter_rom_resources[0].start;
  847. for (start = video_rom_resource.start; start < upper; start += 2048) {
  848. rom = isa_bus_to_virt(start);
  849. if (!romsignature(rom))
  850. continue;
  851. video_rom_resource.start = start;
  852. if (probe_kernel_address(rom + 2, c) != 0)
  853. continue;
  854. /* 0 < length <= 0x7f * 512, historically */
  855. length = c * 512;
  856. /* if checksum okay, trust length byte */
  857. if (length && romchecksum(rom, length))
  858. video_rom_resource.end = start + length - 1;
  859. request_resource(&iomem_resource, &video_rom_resource);
  860. break;
  861. }
  862. start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
  863. if (start < upper)
  864. start = upper;
  865. /* system rom */
  866. request_resource(&iomem_resource, &system_rom_resource);
  867. upper = system_rom_resource.start;
  868. /* check for extension rom (ignore length byte!) */
  869. rom = isa_bus_to_virt(extension_rom_resource.start);
  870. if (romsignature(rom)) {
  871. length = extension_rom_resource.end - extension_rom_resource.start + 1;
  872. if (romchecksum(rom, length)) {
  873. request_resource(&iomem_resource, &extension_rom_resource);
  874. upper = extension_rom_resource.start;
  875. }
  876. }
  877. /* check for adapter roms on 2k boundaries */
  878. for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
  879. rom = isa_bus_to_virt(start);
  880. if (!romsignature(rom))
  881. continue;
  882. if (probe_kernel_address(rom + 2, c) != 0)
  883. continue;
  884. /* 0 < length <= 0x7f * 512, historically */
  885. length = c * 512;
  886. /* but accept any length that fits if checksum okay */
  887. if (!length || start + length > upper || !romchecksum(rom, length))
  888. continue;
  889. adapter_rom_resources[i].start = start;
  890. adapter_rom_resources[i].end = start + length - 1;
  891. request_resource(&iomem_resource, &adapter_rom_resources[i]);
  892. start = adapter_rom_resources[i++].end & ~2047UL;
  893. }
  894. }