setup_32.c 23 KB

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