setup_32.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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 "Reserving %ldMB of memory at %ldMB "
  403. "for crashkernel (System RAM: %ldMB)\n",
  404. (unsigned long)(crash_size >> 20),
  405. (unsigned long)(crash_base >> 20),
  406. (unsigned long)(total_mem >> 20));
  407. if (reserve_bootmem(crash_base, crash_size,
  408. BOOTMEM_EXCLUSIVE) < 0) {
  409. printk(KERN_INFO "crashkernel reservation "
  410. "failed - memory is in use\n");
  411. return;
  412. }
  413. crashk_res.start = crash_base;
  414. crashk_res.end = crash_base + crash_size - 1;
  415. } else
  416. printk(KERN_INFO "crashkernel reservation failed - "
  417. "you have to specify a base address\n");
  418. }
  419. }
  420. #else
  421. static inline void __init reserve_crashkernel(void)
  422. {}
  423. #endif
  424. #ifdef CONFIG_BLK_DEV_INITRD
  425. static bool do_relocate_initrd = false;
  426. static void __init reserve_initrd(void)
  427. {
  428. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  429. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  430. u64 ramdisk_end = ramdisk_image + ramdisk_size;
  431. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  432. u64 ramdisk_here;
  433. if (!boot_params.hdr.type_of_loader ||
  434. !ramdisk_image || !ramdisk_size)
  435. return; /* No initrd provided by bootloader */
  436. initrd_start = 0;
  437. if (ramdisk_size >= end_of_lowmem/2) {
  438. free_early(ramdisk_image, ramdisk_end);
  439. printk(KERN_ERR "initrd too large to handle, "
  440. "disabling initrd\n");
  441. return;
  442. }
  443. printk(KERN_INFO "old RAMDISK: %08llx - %08llx\n", ramdisk_image,
  444. ramdisk_end);
  445. if (ramdisk_end <= end_of_lowmem) {
  446. /* All in lowmem, easy case */
  447. /*
  448. * don't need to reserve again, already reserved early
  449. * in i386_start_kernel
  450. */
  451. initrd_start = ramdisk_image + PAGE_OFFSET;
  452. initrd_end = initrd_start+ramdisk_size;
  453. return;
  454. }
  455. /* We need to move the initrd down into lowmem */
  456. ramdisk_here = find_e820_area(min_low_pfn<<PAGE_SHIFT,
  457. end_of_lowmem, ramdisk_size,
  458. PAGE_SIZE);
  459. if (ramdisk_here == -1ULL)
  460. panic("Cannot find place for new RAMDISK of size %lld\n",
  461. ramdisk_size);
  462. /* Note: this includes all the lowmem currently occupied by
  463. the initrd, we rely on that fact to keep the data intact. */
  464. reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
  465. "NEW RAMDISK");
  466. initrd_start = ramdisk_here + PAGE_OFFSET;
  467. initrd_end = initrd_start + ramdisk_size;
  468. printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
  469. ramdisk_here, ramdisk_here + ramdisk_size);
  470. do_relocate_initrd = true;
  471. }
  472. #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
  473. static void __init relocate_initrd(void)
  474. {
  475. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  476. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  477. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  478. u64 ramdisk_here;
  479. unsigned long slop, clen, mapaddr;
  480. char *p, *q;
  481. if (!do_relocate_initrd)
  482. return;
  483. ramdisk_here = initrd_start - PAGE_OFFSET;
  484. q = (char *)initrd_start;
  485. /* Copy any lowmem portion of the initrd */
  486. if (ramdisk_image < end_of_lowmem) {
  487. clen = end_of_lowmem - ramdisk_image;
  488. p = (char *)__va(ramdisk_image);
  489. memcpy(q, p, clen);
  490. q += clen;
  491. /* need to free these low pages...*/
  492. printk(KERN_INFO "Freeing old partial RAMDISK %08llx-%08llx\n",
  493. ramdisk_image, ramdisk_image + clen - 1);
  494. free_bootmem(ramdisk_image, clen);
  495. ramdisk_image += clen;
  496. ramdisk_size -= clen;
  497. }
  498. /* Copy the highmem portion of the initrd */
  499. while (ramdisk_size) {
  500. slop = ramdisk_image & ~PAGE_MASK;
  501. clen = ramdisk_size;
  502. if (clen > MAX_MAP_CHUNK-slop)
  503. clen = MAX_MAP_CHUNK-slop;
  504. mapaddr = ramdisk_image & PAGE_MASK;
  505. p = early_ioremap(mapaddr, clen+slop);
  506. memcpy(q, p+slop, clen);
  507. early_iounmap(p, clen+slop);
  508. q += clen;
  509. ramdisk_image += clen;
  510. ramdisk_size -= clen;
  511. }
  512. /* high pages is not converted by early_res_to_bootmem */
  513. ramdisk_image = boot_params.hdr.ramdisk_image;
  514. ramdisk_size = boot_params.hdr.ramdisk_size;
  515. printk(KERN_INFO "Copied RAMDISK from %016llx - %016llx to %08llx - %08llx\n",
  516. ramdisk_image, ramdisk_image + ramdisk_size - 1,
  517. ramdisk_here, ramdisk_here + ramdisk_size - 1);
  518. /* need to free that, otherwise init highmem will reserve it again */
  519. free_early(ramdisk_image, ramdisk_image+ramdisk_size);
  520. }
  521. #endif /* CONFIG_BLK_DEV_INITRD */
  522. void __init setup_bootmem_allocator(void)
  523. {
  524. int i;
  525. unsigned long bootmap_size, bootmap;
  526. /*
  527. * Initialize the boot-time allocator (with low memory only):
  528. */
  529. bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
  530. bootmap = find_e820_area(min_low_pfn<<PAGE_SHIFT,
  531. max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
  532. PAGE_SIZE);
  533. if (bootmap == -1L)
  534. panic("Cannot find bootmem map of size %ld\n", bootmap_size);
  535. reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
  536. #ifdef CONFIG_BLK_DEV_INITRD
  537. reserve_initrd();
  538. #endif
  539. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, max_low_pfn);
  540. printk(KERN_INFO " mapped low ram: 0 - %08lx\n",
  541. max_pfn_mapped<<PAGE_SHIFT);
  542. printk(KERN_INFO " low ram: %08lx - %08lx\n",
  543. min_low_pfn<<PAGE_SHIFT, max_low_pfn<<PAGE_SHIFT);
  544. printk(KERN_INFO " bootmap %08lx - %08lx\n",
  545. bootmap, bootmap + bootmap_size);
  546. for_each_online_node(i)
  547. free_bootmem_with_active_regions(i, max_low_pfn);
  548. early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
  549. #ifdef CONFIG_ACPI_SLEEP
  550. /*
  551. * Reserve low memory region for sleep support.
  552. */
  553. acpi_reserve_bootmem();
  554. #endif
  555. #ifdef CONFIG_X86_FIND_SMP_CONFIG
  556. /*
  557. * Find and reserve possible boot-time SMP configuration:
  558. */
  559. find_smp_config();
  560. #endif
  561. reserve_crashkernel();
  562. reserve_ibft_region();
  563. }
  564. /*
  565. * The node 0 pgdat is initialized before all of these because
  566. * it's needed for bootmem. node>0 pgdats have their virtual
  567. * space allocated before the pagetables are in place to access
  568. * them, so they can't be cleared then.
  569. *
  570. * This should all compile down to nothing when NUMA is off.
  571. */
  572. static void __init remapped_pgdat_init(void)
  573. {
  574. int nid;
  575. for_each_online_node(nid) {
  576. if (nid != 0)
  577. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  578. }
  579. }
  580. #ifdef CONFIG_MCA
  581. static void set_mca_bus(int x)
  582. {
  583. MCA_bus = x;
  584. }
  585. #else
  586. static void set_mca_bus(int x) { }
  587. #endif
  588. #ifdef CONFIG_NUMA
  589. /*
  590. * In the golden day, when everything among i386 and x86_64 will be
  591. * integrated, this will not live here
  592. */
  593. void *x86_cpu_to_node_map_early_ptr;
  594. int x86_cpu_to_node_map_init[NR_CPUS] = {
  595. [0 ... NR_CPUS-1] = NUMA_NO_NODE
  596. };
  597. DEFINE_PER_CPU(int, x86_cpu_to_node_map) = NUMA_NO_NODE;
  598. #endif
  599. /*
  600. * Determine if we were loaded by an EFI loader. If so, then we have also been
  601. * passed the efi memmap, systab, etc., so we should use these data structures
  602. * for initialization. Note, the efi init code path is determined by the
  603. * global efi_enabled. This allows the same kernel image to be used on existing
  604. * systems (with a traditional BIOS) as well as on EFI systems.
  605. */
  606. void __init setup_arch(char **cmdline_p)
  607. {
  608. unsigned long max_low_pfn;
  609. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  610. pre_setup_arch_hook();
  611. early_cpu_init();
  612. early_ioremap_init();
  613. reserve_setup_data();
  614. #ifdef CONFIG_EFI
  615. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  616. "EL32", 4)) {
  617. efi_enabled = 1;
  618. efi_reserve_early();
  619. }
  620. #endif
  621. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  622. screen_info = boot_params.screen_info;
  623. edid_info = boot_params.edid_info;
  624. apm_info.bios = boot_params.apm_bios_info;
  625. ist_info = boot_params.ist_info;
  626. saved_video_mode = boot_params.hdr.vid_mode;
  627. if( boot_params.sys_desc_table.length != 0 ) {
  628. set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
  629. machine_id = boot_params.sys_desc_table.table[0];
  630. machine_submodel_id = boot_params.sys_desc_table.table[1];
  631. BIOS_revision = boot_params.sys_desc_table.table[2];
  632. }
  633. bootloader_type = boot_params.hdr.type_of_loader;
  634. #ifdef CONFIG_BLK_DEV_RAM
  635. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  636. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  637. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  638. #endif
  639. ARCH_SETUP
  640. setup_memory_map();
  641. copy_edd();
  642. if (!boot_params.hdr.root_flags)
  643. root_mountflags &= ~MS_RDONLY;
  644. init_mm.start_code = (unsigned long) _text;
  645. init_mm.end_code = (unsigned long) _etext;
  646. init_mm.end_data = (unsigned long) _edata;
  647. init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
  648. code_resource.start = virt_to_phys(_text);
  649. code_resource.end = virt_to_phys(_etext)-1;
  650. data_resource.start = virt_to_phys(_etext);
  651. data_resource.end = virt_to_phys(_edata)-1;
  652. bss_resource.start = virt_to_phys(&__bss_start);
  653. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  654. parse_setup_data();
  655. parse_early_param();
  656. finish_e820_parsing();
  657. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  658. *cmdline_p = command_line;
  659. if (efi_enabled)
  660. efi_init();
  661. e820_register_active_regions(0, 0, -1UL);
  662. /*
  663. * partially used pages are not usable - thus
  664. * we are rounding upwards:
  665. */
  666. max_pfn = e820_end_of_ram();
  667. /* preallocate 4k for mptable mpc */
  668. early_reserve_e820_mpc_new();
  669. /* update e820 for memory not covered by WB MTRRs */
  670. mtrr_bp_init();
  671. if (mtrr_trim_uncached_memory(max_pfn)) {
  672. remove_all_active_ranges();
  673. e820_register_active_regions(0, 0, -1UL);
  674. max_pfn = e820_end_of_ram();
  675. }
  676. max_low_pfn = setup_memory();
  677. #ifdef CONFIG_KVM_CLOCK
  678. kvmclock_init();
  679. #endif
  680. #ifdef CONFIG_VMI
  681. /*
  682. * Must be after max_low_pfn is determined, and before kernel
  683. * pagetables are setup.
  684. */
  685. vmi_init();
  686. #endif
  687. kvm_guest_init();
  688. /*
  689. * NOTE: before this point _nobody_ is allowed to allocate
  690. * any memory using the bootmem allocator. Although the
  691. * allocator is now initialised only the first 8Mb of the kernel
  692. * virtual address space has been mapped. All allocations before
  693. * paging_init() has completed must use the alloc_bootmem_low_pages()
  694. * variant (which allocates DMA'able memory) and care must be taken
  695. * not to exceed the 8Mb limit.
  696. */
  697. paging_init();
  698. /*
  699. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  700. */
  701. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  702. if (init_ohci1394_dma_early)
  703. init_ohci1394_dma_on_all_controllers();
  704. #endif
  705. /*
  706. * NOTE: at this point the bootmem allocator is fully available.
  707. */
  708. #ifdef CONFIG_BLK_DEV_INITRD
  709. relocate_initrd();
  710. #endif
  711. remapped_pgdat_init();
  712. sparse_init();
  713. zone_sizes_init();
  714. paravirt_post_allocator_init();
  715. dmi_scan_machine();
  716. io_delay_init();
  717. #ifdef CONFIG_X86_SMP
  718. /*
  719. * setup to use the early static init tables during kernel startup
  720. * X86_SMP will exclude sub-arches that don't deal well with it.
  721. */
  722. x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
  723. x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
  724. #ifdef CONFIG_NUMA
  725. x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
  726. #endif
  727. #endif
  728. #ifdef CONFIG_X86_GENERICARCH
  729. generic_apic_probe();
  730. #endif
  731. #ifdef CONFIG_ACPI
  732. /*
  733. * Parse the ACPI tables for possible boot-time SMP configuration.
  734. */
  735. acpi_boot_table_init();
  736. #endif
  737. early_quirks();
  738. #ifdef CONFIG_ACPI
  739. acpi_boot_init();
  740. #endif
  741. #if defined(CONFIG_X86_MPPARSE) || defined(CONFIG_X86_VISWS)
  742. if (smp_found_config)
  743. get_smp_config();
  744. #endif
  745. #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
  746. if (def_to_bigsmp)
  747. printk(KERN_WARNING "More than 8 CPUs detected and "
  748. "CONFIG_X86_PC cannot handle it.\nUse "
  749. "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
  750. #endif
  751. e820_setup_gap();
  752. e820_mark_nosave_regions(max_low_pfn);
  753. #ifdef CONFIG_VT
  754. #if defined(CONFIG_VGA_CONSOLE)
  755. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  756. conswitchp = &vga_con;
  757. #elif defined(CONFIG_DUMMY_CONSOLE)
  758. conswitchp = &dummy_con;
  759. #endif
  760. #endif
  761. }
  762. /*
  763. * Request address space for all standard resources
  764. *
  765. * This is called just before pcibios_init(), which is also a
  766. * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
  767. */
  768. static int __init request_standard_resources(void)
  769. {
  770. int i;
  771. printk(KERN_INFO "Setting up standard PCI resources\n");
  772. init_iomem_resources(&code_resource, &data_resource, &bss_resource);
  773. request_resource(&iomem_resource, &video_ram_resource);
  774. /* request I/O space for devices used on all i[345]86 PCs */
  775. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  776. request_resource(&ioport_resource, &standard_io_resources[i]);
  777. return 0;
  778. }
  779. subsys_initcall(request_standard_resources);