setup_32.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  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. /* This value is set up by the early boot code to point to the value
  67. immediately after the boot time page tables. It contains a *physical*
  68. address, and must not be in the .bss segment! */
  69. unsigned long init_pg_tables_end __initdata = ~0UL;
  70. /*
  71. * Machine setup..
  72. */
  73. static struct resource data_resource = {
  74. .name = "Kernel data",
  75. .start = 0,
  76. .end = 0,
  77. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  78. };
  79. static struct resource code_resource = {
  80. .name = "Kernel code",
  81. .start = 0,
  82. .end = 0,
  83. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  84. };
  85. static struct resource bss_resource = {
  86. .name = "Kernel bss",
  87. .start = 0,
  88. .end = 0,
  89. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  90. };
  91. static struct resource video_ram_resource = {
  92. .name = "Video RAM area",
  93. .start = 0xa0000,
  94. .end = 0xbffff,
  95. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  96. };
  97. static struct resource standard_io_resources[] = { {
  98. .name = "dma1",
  99. .start = 0x0000,
  100. .end = 0x001f,
  101. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  102. }, {
  103. .name = "pic1",
  104. .start = 0x0020,
  105. .end = 0x0021,
  106. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  107. }, {
  108. .name = "timer0",
  109. .start = 0x0040,
  110. .end = 0x0043,
  111. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  112. }, {
  113. .name = "timer1",
  114. .start = 0x0050,
  115. .end = 0x0053,
  116. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  117. }, {
  118. .name = "keyboard",
  119. .start = 0x0060,
  120. .end = 0x0060,
  121. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  122. }, {
  123. .name = "keyboard",
  124. .start = 0x0064,
  125. .end = 0x0064,
  126. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  127. }, {
  128. .name = "dma page reg",
  129. .start = 0x0080,
  130. .end = 0x008f,
  131. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  132. }, {
  133. .name = "pic2",
  134. .start = 0x00a0,
  135. .end = 0x00a1,
  136. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  137. }, {
  138. .name = "dma2",
  139. .start = 0x00c0,
  140. .end = 0x00df,
  141. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  142. }, {
  143. .name = "fpu",
  144. .start = 0x00f0,
  145. .end = 0x00ff,
  146. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  147. } };
  148. /* cpu data as detected by the assembly code in head.S */
  149. struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  150. /* common cpu data for all cpus */
  151. struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  152. EXPORT_SYMBOL(boot_cpu_data);
  153. unsigned int def_to_bigsmp;
  154. #ifndef CONFIG_X86_PAE
  155. unsigned long mmu_cr4_features;
  156. #else
  157. unsigned long mmu_cr4_features = X86_CR4_PAE;
  158. #endif
  159. /* for MCA, but anyone else can use it if they want */
  160. unsigned int machine_id;
  161. unsigned int machine_submodel_id;
  162. unsigned int BIOS_revision;
  163. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  164. int bootloader_type;
  165. /* user-defined highmem size */
  166. static unsigned int highmem_pages = -1;
  167. /*
  168. * Setup options
  169. */
  170. struct screen_info screen_info;
  171. EXPORT_SYMBOL(screen_info);
  172. struct apm_info apm_info;
  173. EXPORT_SYMBOL(apm_info);
  174. struct edid_info edid_info;
  175. EXPORT_SYMBOL_GPL(edid_info);
  176. struct ist_info ist_info;
  177. #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
  178. defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
  179. EXPORT_SYMBOL(ist_info);
  180. #endif
  181. extern void early_cpu_init(void);
  182. extern int root_mountflags;
  183. unsigned long saved_video_mode;
  184. #define RAMDISK_IMAGE_START_MASK 0x07FF
  185. #define RAMDISK_PROMPT_FLAG 0x8000
  186. #define RAMDISK_LOAD_FLAG 0x4000
  187. static char __initdata command_line[COMMAND_LINE_SIZE];
  188. #ifndef CONFIG_DEBUG_BOOT_PARAMS
  189. struct boot_params __initdata boot_params;
  190. #else
  191. struct boot_params boot_params;
  192. #endif
  193. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  194. struct edd edd;
  195. #ifdef CONFIG_EDD_MODULE
  196. EXPORT_SYMBOL(edd);
  197. #endif
  198. /**
  199. * copy_edd() - Copy the BIOS EDD information
  200. * from boot_params into a safe place.
  201. *
  202. */
  203. static inline void copy_edd(void)
  204. {
  205. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  206. sizeof(edd.mbr_signature));
  207. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  208. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  209. edd.edd_info_nr = boot_params.eddbuf_entries;
  210. }
  211. #else
  212. static inline void copy_edd(void)
  213. {
  214. }
  215. #endif
  216. int __initdata user_defined_memmap;
  217. /*
  218. * "mem=nopentium" disables the 4MB page tables.
  219. * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
  220. * to <mem>, overriding the bios size.
  221. * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
  222. * <start> to <start>+<mem>, overriding the bios size.
  223. *
  224. * HPA tells me bootloaders need to parse mem=, so no new
  225. * option should be mem= [also see Documentation/i386/boot.txt]
  226. */
  227. static int __init parse_mem(char *arg)
  228. {
  229. if (!arg)
  230. return -EINVAL;
  231. if (strcmp(arg, "nopentium") == 0) {
  232. setup_clear_cpu_cap(X86_FEATURE_PSE);
  233. } else {
  234. /* If the user specifies memory size, we
  235. * limit the BIOS-provided memory map to
  236. * that size. exactmap can be used to specify
  237. * the exact map. mem=number can be used to
  238. * trim the existing memory map.
  239. */
  240. unsigned long long mem_size;
  241. mem_size = memparse(arg, &arg);
  242. limit_regions(mem_size);
  243. user_defined_memmap = 1;
  244. }
  245. return 0;
  246. }
  247. early_param("mem", parse_mem);
  248. #ifdef CONFIG_PROC_VMCORE
  249. /* elfcorehdr= specifies the location of elf core header
  250. * stored by the crashed kernel.
  251. */
  252. static int __init parse_elfcorehdr(char *arg)
  253. {
  254. if (!arg)
  255. return -EINVAL;
  256. elfcorehdr_addr = memparse(arg, &arg);
  257. return 0;
  258. }
  259. early_param("elfcorehdr", parse_elfcorehdr);
  260. #endif /* CONFIG_PROC_VMCORE */
  261. /*
  262. * highmem=size forces highmem to be exactly 'size' bytes.
  263. * This works even on boxes that have no highmem otherwise.
  264. * This also works to reduce highmem size on bigger boxes.
  265. */
  266. static int __init parse_highmem(char *arg)
  267. {
  268. if (!arg)
  269. return -EINVAL;
  270. highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
  271. return 0;
  272. }
  273. early_param("highmem", parse_highmem);
  274. /*
  275. * vmalloc=size forces the vmalloc area to be exactly 'size'
  276. * bytes. This can be used to increase (or decrease) the
  277. * vmalloc area - the default is 128m.
  278. */
  279. static int __init parse_vmalloc(char *arg)
  280. {
  281. if (!arg)
  282. return -EINVAL;
  283. __VMALLOC_RESERVE = memparse(arg, &arg);
  284. return 0;
  285. }
  286. early_param("vmalloc", parse_vmalloc);
  287. /*
  288. * reservetop=size reserves a hole at the top of the kernel address space which
  289. * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
  290. * so relocating the fixmap can be done before paging initialization.
  291. */
  292. static int __init parse_reservetop(char *arg)
  293. {
  294. unsigned long address;
  295. if (!arg)
  296. return -EINVAL;
  297. address = memparse(arg, &arg);
  298. reserve_top_address(address);
  299. return 0;
  300. }
  301. early_param("reservetop", parse_reservetop);
  302. /*
  303. * Determine low and high memory ranges:
  304. */
  305. unsigned long __init find_max_low_pfn(void)
  306. {
  307. unsigned long max_low_pfn;
  308. max_low_pfn = max_pfn;
  309. if (max_low_pfn > MAXMEM_PFN) {
  310. if (highmem_pages == -1)
  311. highmem_pages = max_pfn - MAXMEM_PFN;
  312. if (highmem_pages + MAXMEM_PFN < max_pfn)
  313. max_pfn = MAXMEM_PFN + highmem_pages;
  314. if (highmem_pages + MAXMEM_PFN > max_pfn) {
  315. printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
  316. highmem_pages = 0;
  317. }
  318. max_low_pfn = MAXMEM_PFN;
  319. #ifndef CONFIG_HIGHMEM
  320. /* Maximum memory usable is what is directly addressable */
  321. printk(KERN_WARNING "Warning only %ldMB will be used.\n",
  322. MAXMEM>>20);
  323. if (max_pfn > MAX_NONPAE_PFN)
  324. printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
  325. else
  326. printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
  327. max_pfn = MAXMEM_PFN;
  328. #else /* !CONFIG_HIGHMEM */
  329. #ifndef CONFIG_HIGHMEM64G
  330. if (max_pfn > MAX_NONPAE_PFN) {
  331. max_pfn = MAX_NONPAE_PFN;
  332. printk(KERN_WARNING "Warning only 4GB will be used.\n");
  333. printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
  334. }
  335. #endif /* !CONFIG_HIGHMEM64G */
  336. #endif /* !CONFIG_HIGHMEM */
  337. } else {
  338. if (highmem_pages == -1)
  339. highmem_pages = 0;
  340. #ifdef CONFIG_HIGHMEM
  341. if (highmem_pages >= max_pfn) {
  342. printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
  343. highmem_pages = 0;
  344. }
  345. if (highmem_pages) {
  346. if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
  347. printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
  348. highmem_pages = 0;
  349. }
  350. max_low_pfn -= highmem_pages;
  351. }
  352. #else
  353. if (highmem_pages)
  354. printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
  355. #endif
  356. }
  357. return max_low_pfn;
  358. }
  359. #define BIOS_LOWMEM_KILOBYTES 0x413
  360. /*
  361. * The BIOS places the EBDA/XBDA at the top of conventional
  362. * memory, and usually decreases the reported amount of
  363. * conventional memory (int 0x12) too. This also contains a
  364. * workaround for Dell systems that neglect to reserve EBDA.
  365. * The same workaround also avoids a problem with the AMD768MPX
  366. * chipset: reserve a page before VGA to prevent PCI prefetch
  367. * into it (errata #56). Usually the page is reserved anyways,
  368. * unless you have no PS/2 mouse plugged in.
  369. */
  370. static void __init reserve_ebda_region(void)
  371. {
  372. unsigned int lowmem, ebda_addr;
  373. /* To determine the position of the EBDA and the */
  374. /* end of conventional memory, we need to look at */
  375. /* the BIOS data area. In a paravirtual environment */
  376. /* that area is absent. We'll just have to assume */
  377. /* that the paravirt case can handle memory setup */
  378. /* correctly, without our help. */
  379. if (paravirt_enabled())
  380. return;
  381. /* end of low (conventional) memory */
  382. lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
  383. lowmem <<= 10;
  384. /* start of EBDA area */
  385. ebda_addr = get_bios_ebda();
  386. /* Fixup: bios puts an EBDA in the top 64K segment */
  387. /* of conventional memory, but does not adjust lowmem. */
  388. if ((lowmem - ebda_addr) <= 0x10000)
  389. lowmem = ebda_addr;
  390. /* Fixup: bios does not report an EBDA at all. */
  391. /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
  392. if ((ebda_addr == 0) && (lowmem >= 0x9f000))
  393. lowmem = 0x9f000;
  394. /* Paranoia: should never happen, but... */
  395. if ((lowmem == 0) || (lowmem >= 0x100000))
  396. lowmem = 0x9f000;
  397. /* reserve all memory between lowmem and the 1MB mark */
  398. reserve_bootmem(lowmem, 0x100000 - lowmem, BOOTMEM_DEFAULT);
  399. }
  400. #ifndef CONFIG_NEED_MULTIPLE_NODES
  401. static void __init setup_bootmem_allocator(void);
  402. static unsigned long __init setup_memory(void)
  403. {
  404. /*
  405. * partially used pages are not usable - thus
  406. * we are rounding upwards:
  407. */
  408. min_low_pfn = PFN_UP(init_pg_tables_end);
  409. max_low_pfn = find_max_low_pfn();
  410. #ifdef CONFIG_HIGHMEM
  411. highstart_pfn = highend_pfn = max_pfn;
  412. if (max_pfn > max_low_pfn) {
  413. highstart_pfn = max_low_pfn;
  414. }
  415. printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
  416. pages_to_mb(highend_pfn - highstart_pfn));
  417. num_physpages = highend_pfn;
  418. high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
  419. #else
  420. num_physpages = max_low_pfn;
  421. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
  422. #endif
  423. #ifdef CONFIG_FLATMEM
  424. max_mapnr = num_physpages;
  425. #endif
  426. printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
  427. pages_to_mb(max_low_pfn));
  428. setup_bootmem_allocator();
  429. return max_low_pfn;
  430. }
  431. static void __init zone_sizes_init(void)
  432. {
  433. unsigned long max_zone_pfns[MAX_NR_ZONES];
  434. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  435. max_zone_pfns[ZONE_DMA] =
  436. virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  437. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  438. #ifdef CONFIG_HIGHMEM
  439. max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
  440. add_active_range(0, 0, highend_pfn);
  441. #else
  442. add_active_range(0, 0, max_low_pfn);
  443. #endif
  444. free_area_init_nodes(max_zone_pfns);
  445. }
  446. #else
  447. extern unsigned long __init setup_memory(void);
  448. extern void zone_sizes_init(void);
  449. #endif /* !CONFIG_NEED_MULTIPLE_NODES */
  450. static inline unsigned long long get_total_mem(void)
  451. {
  452. unsigned long long total;
  453. total = max_low_pfn - min_low_pfn;
  454. #ifdef CONFIG_HIGHMEM
  455. total += highend_pfn - highstart_pfn;
  456. #endif
  457. return total << PAGE_SHIFT;
  458. }
  459. #ifdef CONFIG_KEXEC
  460. static void __init reserve_crashkernel(void)
  461. {
  462. unsigned long long total_mem;
  463. unsigned long long crash_size, crash_base;
  464. int ret;
  465. total_mem = get_total_mem();
  466. ret = parse_crashkernel(boot_command_line, total_mem,
  467. &crash_size, &crash_base);
  468. if (ret == 0 && crash_size > 0) {
  469. if (crash_base > 0) {
  470. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  471. "for crashkernel (System RAM: %ldMB)\n",
  472. (unsigned long)(crash_size >> 20),
  473. (unsigned long)(crash_base >> 20),
  474. (unsigned long)(total_mem >> 20));
  475. if (reserve_bootmem(crash_base, crash_size,
  476. BOOTMEM_EXCLUSIVE) < 0) {
  477. printk(KERN_INFO "crashkernel reservation "
  478. "failed - memory is in use\n");
  479. return;
  480. }
  481. crashk_res.start = crash_base;
  482. crashk_res.end = crash_base + crash_size - 1;
  483. } else
  484. printk(KERN_INFO "crashkernel reservation failed - "
  485. "you have to specify a base address\n");
  486. }
  487. }
  488. #else
  489. static inline void __init reserve_crashkernel(void)
  490. {}
  491. #endif
  492. #ifdef CONFIG_BLK_DEV_INITRD
  493. static bool do_relocate_initrd = false;
  494. static void __init reserve_initrd(void)
  495. {
  496. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  497. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  498. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  499. unsigned long end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  500. unsigned long ramdisk_here;
  501. initrd_start = 0;
  502. if (!boot_params.hdr.type_of_loader ||
  503. !ramdisk_image || !ramdisk_size)
  504. return; /* No initrd provided by bootloader */
  505. if (ramdisk_end < ramdisk_image) {
  506. printk(KERN_ERR "initrd wraps around end of memory, "
  507. "disabling initrd\n");
  508. return;
  509. }
  510. if (ramdisk_size >= end_of_lowmem/2) {
  511. printk(KERN_ERR "initrd too large to handle, "
  512. "disabling initrd\n");
  513. return;
  514. }
  515. if (ramdisk_end <= end_of_lowmem) {
  516. /* All in lowmem, easy case */
  517. reserve_bootmem(ramdisk_image, ramdisk_size, BOOTMEM_DEFAULT);
  518. initrd_start = ramdisk_image + PAGE_OFFSET;
  519. initrd_end = initrd_start+ramdisk_size;
  520. return;
  521. }
  522. /* We need to move the initrd down into lowmem */
  523. ramdisk_here = (end_of_lowmem - ramdisk_size) & PAGE_MASK;
  524. /* Note: this includes all the lowmem currently occupied by
  525. the initrd, we rely on that fact to keep the data intact. */
  526. reserve_bootmem(ramdisk_here, ramdisk_size, BOOTMEM_DEFAULT);
  527. initrd_start = ramdisk_here + PAGE_OFFSET;
  528. initrd_end = initrd_start + ramdisk_size;
  529. do_relocate_initrd = true;
  530. }
  531. #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
  532. static void __init relocate_initrd(void)
  533. {
  534. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  535. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  536. unsigned long end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  537. unsigned long ramdisk_here;
  538. unsigned long slop, clen, mapaddr;
  539. char *p, *q;
  540. if (!do_relocate_initrd)
  541. return;
  542. ramdisk_here = initrd_start - PAGE_OFFSET;
  543. q = (char *)initrd_start;
  544. /* Copy any lowmem portion of the initrd */
  545. if (ramdisk_image < end_of_lowmem) {
  546. clen = end_of_lowmem - ramdisk_image;
  547. p = (char *)__va(ramdisk_image);
  548. memcpy(q, p, clen);
  549. q += clen;
  550. ramdisk_image += clen;
  551. ramdisk_size -= clen;
  552. }
  553. /* Copy the highmem portion of the initrd */
  554. while (ramdisk_size) {
  555. slop = ramdisk_image & ~PAGE_MASK;
  556. clen = ramdisk_size;
  557. if (clen > MAX_MAP_CHUNK-slop)
  558. clen = MAX_MAP_CHUNK-slop;
  559. mapaddr = ramdisk_image & PAGE_MASK;
  560. p = early_ioremap(mapaddr, clen+slop);
  561. memcpy(q, p+slop, clen);
  562. early_iounmap(p, clen+slop);
  563. q += clen;
  564. ramdisk_image += clen;
  565. ramdisk_size -= clen;
  566. }
  567. }
  568. #endif /* CONFIG_BLK_DEV_INITRD */
  569. void __init setup_bootmem_allocator(void)
  570. {
  571. unsigned long bootmap_size;
  572. /*
  573. * Initialize the boot-time allocator (with low memory only):
  574. */
  575. bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
  576. register_bootmem_low_pages(max_low_pfn);
  577. /*
  578. * Reserve the bootmem bitmap itself as well. We do this in two
  579. * steps (first step was init_bootmem()) because this catches
  580. * the (very unlikely) case of us accidentally initializing the
  581. * bootmem allocator with an invalid RAM area.
  582. */
  583. reserve_bootmem(__pa_symbol(_text), (PFN_PHYS(min_low_pfn) +
  584. bootmap_size + PAGE_SIZE-1) - __pa_symbol(_text),
  585. BOOTMEM_DEFAULT);
  586. /*
  587. * reserve physical page 0 - it's a special BIOS page on many boxes,
  588. * enabling clean reboots, SMP operation, laptop functions.
  589. */
  590. reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT);
  591. /* reserve EBDA region */
  592. reserve_ebda_region();
  593. #ifdef CONFIG_SMP
  594. /*
  595. * But first pinch a few for the stack/trampoline stuff
  596. * FIXME: Don't need the extra page at 4K, but need to fix
  597. * trampoline before removing it. (see the GDT stuff)
  598. */
  599. reserve_bootmem(PAGE_SIZE, PAGE_SIZE, BOOTMEM_DEFAULT);
  600. #endif
  601. #ifdef CONFIG_ACPI_SLEEP
  602. /*
  603. * Reserve low memory region for sleep support.
  604. */
  605. acpi_reserve_bootmem();
  606. #endif
  607. #ifdef CONFIG_X86_FIND_SMP_CONFIG
  608. /*
  609. * Find and reserve possible boot-time SMP configuration:
  610. */
  611. find_smp_config();
  612. #endif
  613. #ifdef CONFIG_BLK_DEV_INITRD
  614. reserve_initrd();
  615. #endif
  616. numa_kva_reserve();
  617. reserve_crashkernel();
  618. reserve_ibft_region();
  619. }
  620. /*
  621. * The node 0 pgdat is initialized before all of these because
  622. * it's needed for bootmem. node>0 pgdats have their virtual
  623. * space allocated before the pagetables are in place to access
  624. * them, so they can't be cleared then.
  625. *
  626. * This should all compile down to nothing when NUMA is off.
  627. */
  628. static void __init remapped_pgdat_init(void)
  629. {
  630. int nid;
  631. for_each_online_node(nid) {
  632. if (nid != 0)
  633. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  634. }
  635. }
  636. #ifdef CONFIG_MCA
  637. static void set_mca_bus(int x)
  638. {
  639. MCA_bus = x;
  640. }
  641. #else
  642. static void set_mca_bus(int x) { }
  643. #endif
  644. /* Overridden in paravirt.c if CONFIG_PARAVIRT */
  645. char * __init __attribute__((weak)) memory_setup(void)
  646. {
  647. return machine_specific_memory_setup();
  648. }
  649. #ifdef CONFIG_NUMA
  650. /*
  651. * In the golden day, when everything among i386 and x86_64 will be
  652. * integrated, this will not live here
  653. */
  654. void *x86_cpu_to_node_map_early_ptr;
  655. int x86_cpu_to_node_map_init[NR_CPUS] = {
  656. [0 ... NR_CPUS-1] = NUMA_NO_NODE
  657. };
  658. DEFINE_PER_CPU(int, x86_cpu_to_node_map) = NUMA_NO_NODE;
  659. #endif
  660. /*
  661. * Determine if we were loaded by an EFI loader. If so, then we have also been
  662. * passed the efi memmap, systab, etc., so we should use these data structures
  663. * for initialization. Note, the efi init code path is determined by the
  664. * global efi_enabled. This allows the same kernel image to be used on existing
  665. * systems (with a traditional BIOS) as well as on EFI systems.
  666. */
  667. void __init setup_arch(char **cmdline_p)
  668. {
  669. unsigned long max_low_pfn;
  670. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  671. pre_setup_arch_hook();
  672. early_cpu_init();
  673. early_ioremap_init();
  674. #ifdef CONFIG_EFI
  675. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  676. "EL32", 4))
  677. efi_enabled = 1;
  678. #endif
  679. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  680. screen_info = boot_params.screen_info;
  681. edid_info = boot_params.edid_info;
  682. apm_info.bios = boot_params.apm_bios_info;
  683. ist_info = boot_params.ist_info;
  684. saved_video_mode = boot_params.hdr.vid_mode;
  685. if( boot_params.sys_desc_table.length != 0 ) {
  686. set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
  687. machine_id = boot_params.sys_desc_table.table[0];
  688. machine_submodel_id = boot_params.sys_desc_table.table[1];
  689. BIOS_revision = boot_params.sys_desc_table.table[2];
  690. }
  691. bootloader_type = boot_params.hdr.type_of_loader;
  692. #ifdef CONFIG_BLK_DEV_RAM
  693. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  694. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  695. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  696. #endif
  697. ARCH_SETUP
  698. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  699. print_memory_map(memory_setup());
  700. copy_edd();
  701. if (!boot_params.hdr.root_flags)
  702. root_mountflags &= ~MS_RDONLY;
  703. init_mm.start_code = (unsigned long) _text;
  704. init_mm.end_code = (unsigned long) _etext;
  705. init_mm.end_data = (unsigned long) _edata;
  706. init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
  707. code_resource.start = virt_to_phys(_text);
  708. code_resource.end = virt_to_phys(_etext)-1;
  709. data_resource.start = virt_to_phys(_etext);
  710. data_resource.end = virt_to_phys(_edata)-1;
  711. bss_resource.start = virt_to_phys(&__bss_start);
  712. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  713. parse_early_param();
  714. if (user_defined_memmap) {
  715. printk(KERN_INFO "user-defined physical RAM map:\n");
  716. print_memory_map("user");
  717. }
  718. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  719. *cmdline_p = command_line;
  720. if (efi_enabled)
  721. efi_init();
  722. /* update e820 for memory not covered by WB MTRRs */
  723. propagate_e820_map();
  724. mtrr_bp_init();
  725. if (mtrr_trim_uncached_memory(max_pfn))
  726. propagate_e820_map();
  727. max_low_pfn = setup_memory();
  728. #ifdef CONFIG_KVM_CLOCK
  729. kvmclock_init();
  730. #endif
  731. #ifdef CONFIG_VMI
  732. /*
  733. * Must be after max_low_pfn is determined, and before kernel
  734. * pagetables are setup.
  735. */
  736. vmi_init();
  737. #endif
  738. kvm_guest_init();
  739. /*
  740. * NOTE: before this point _nobody_ is allowed to allocate
  741. * any memory using the bootmem allocator. Although the
  742. * allocator is now initialised only the first 8Mb of the kernel
  743. * virtual address space has been mapped. All allocations before
  744. * paging_init() has completed must use the alloc_bootmem_low_pages()
  745. * variant (which allocates DMA'able memory) and care must be taken
  746. * not to exceed the 8Mb limit.
  747. */
  748. #ifdef CONFIG_SMP
  749. smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
  750. #endif
  751. paging_init();
  752. /*
  753. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  754. */
  755. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  756. if (init_ohci1394_dma_early)
  757. init_ohci1394_dma_on_all_controllers();
  758. #endif
  759. remapped_pgdat_init();
  760. sparse_init();
  761. zone_sizes_init();
  762. /*
  763. * NOTE: at this point the bootmem allocator is fully available.
  764. */
  765. #ifdef CONFIG_BLK_DEV_INITRD
  766. relocate_initrd();
  767. #endif
  768. paravirt_post_allocator_init();
  769. dmi_scan_machine();
  770. io_delay_init();
  771. #ifdef CONFIG_X86_SMP
  772. /*
  773. * setup to use the early static init tables during kernel startup
  774. * X86_SMP will exclude sub-arches that don't deal well with it.
  775. */
  776. x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
  777. x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
  778. #ifdef CONFIG_NUMA
  779. x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
  780. #endif
  781. #endif
  782. #ifdef CONFIG_X86_GENERICARCH
  783. generic_apic_probe();
  784. #endif
  785. #ifdef CONFIG_ACPI
  786. /*
  787. * Parse the ACPI tables for possible boot-time SMP configuration.
  788. */
  789. acpi_boot_table_init();
  790. #endif
  791. early_quirks();
  792. #ifdef CONFIG_ACPI
  793. acpi_boot_init();
  794. #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
  795. if (def_to_bigsmp)
  796. printk(KERN_WARNING "More than 8 CPUs detected and "
  797. "CONFIG_X86_PC cannot handle it.\nUse "
  798. "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
  799. #endif
  800. #endif
  801. #ifdef CONFIG_X86_LOCAL_APIC
  802. if (smp_found_config)
  803. get_smp_config();
  804. #endif
  805. e820_register_memory();
  806. e820_mark_nosave_regions();
  807. #ifdef CONFIG_VT
  808. #if defined(CONFIG_VGA_CONSOLE)
  809. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  810. conswitchp = &vga_con;
  811. #elif defined(CONFIG_DUMMY_CONSOLE)
  812. conswitchp = &dummy_con;
  813. #endif
  814. #endif
  815. }
  816. /*
  817. * Request address space for all standard resources
  818. *
  819. * This is called just before pcibios_init(), which is also a
  820. * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
  821. */
  822. static int __init request_standard_resources(void)
  823. {
  824. int i;
  825. printk(KERN_INFO "Setting up standard PCI resources\n");
  826. init_iomem_resources(&code_resource, &data_resource, &bss_resource);
  827. request_resource(&iomem_resource, &video_ram_resource);
  828. /* request I/O space for devices used on all i[345]86 PCs */
  829. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  830. request_resource(&ioport_resource, &standard_io_resources[i]);
  831. return 0;
  832. }
  833. subsys_initcall(request_standard_resources);