setup_32.c 25 KB

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