setup_32.c 22 KB

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