setup_32.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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/dmi.h>
  59. #include <asm/io_apic.h>
  60. #include <asm/ist.h>
  61. #include <asm/io.h>
  62. #include <asm/vmi.h>
  63. #include <setup_arch.h>
  64. #include <asm/bios_ebda.h>
  65. #include <asm/cacheflush.h>
  66. #include <asm/processor.h>
  67. #include <asm/efi.h>
  68. #include <asm/bugs.h>
  69. /* This value is set up by the early boot code to point to the value
  70. immediately after the boot time page tables. It contains a *physical*
  71. address, and must not be in the .bss segment! */
  72. unsigned long init_pg_tables_start __initdata = ~0UL;
  73. unsigned long init_pg_tables_end __initdata = ~0UL;
  74. /*
  75. * Machine setup..
  76. */
  77. static struct resource data_resource = {
  78. .name = "Kernel data",
  79. .start = 0,
  80. .end = 0,
  81. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  82. };
  83. static struct resource code_resource = {
  84. .name = "Kernel code",
  85. .start = 0,
  86. .end = 0,
  87. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  88. };
  89. static struct resource bss_resource = {
  90. .name = "Kernel bss",
  91. .start = 0,
  92. .end = 0,
  93. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  94. };
  95. static struct resource video_ram_resource = {
  96. .name = "Video RAM area",
  97. .start = 0xa0000,
  98. .end = 0xbffff,
  99. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  100. };
  101. static struct resource standard_io_resources[] = { {
  102. .name = "dma1",
  103. .start = 0x0000,
  104. .end = 0x001f,
  105. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  106. }, {
  107. .name = "pic1",
  108. .start = 0x0020,
  109. .end = 0x0021,
  110. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  111. }, {
  112. .name = "timer0",
  113. .start = 0x0040,
  114. .end = 0x0043,
  115. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  116. }, {
  117. .name = "timer1",
  118. .start = 0x0050,
  119. .end = 0x0053,
  120. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  121. }, {
  122. .name = "keyboard",
  123. .start = 0x0060,
  124. .end = 0x0060,
  125. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  126. }, {
  127. .name = "keyboard",
  128. .start = 0x0064,
  129. .end = 0x0064,
  130. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  131. }, {
  132. .name = "dma page reg",
  133. .start = 0x0080,
  134. .end = 0x008f,
  135. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  136. }, {
  137. .name = "pic2",
  138. .start = 0x00a0,
  139. .end = 0x00a1,
  140. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  141. }, {
  142. .name = "dma2",
  143. .start = 0x00c0,
  144. .end = 0x00df,
  145. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  146. }, {
  147. .name = "fpu",
  148. .start = 0x00f0,
  149. .end = 0x00ff,
  150. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  151. } };
  152. /* cpu data as detected by the assembly code in head.S */
  153. struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  154. /* common cpu data for all cpus */
  155. struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  156. EXPORT_SYMBOL(boot_cpu_data);
  157. unsigned int def_to_bigsmp;
  158. #ifndef CONFIG_X86_PAE
  159. unsigned long mmu_cr4_features;
  160. #else
  161. unsigned long mmu_cr4_features = X86_CR4_PAE;
  162. #endif
  163. /* for MCA, but anyone else can use it if they want */
  164. unsigned int machine_id;
  165. unsigned int machine_submodel_id;
  166. unsigned int BIOS_revision;
  167. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  168. int bootloader_type;
  169. /* user-defined highmem size */
  170. static unsigned int highmem_pages = -1;
  171. /*
  172. * Early DMI memory
  173. */
  174. int dmi_alloc_index;
  175. char dmi_alloc_data[DMI_MAX_DATA];
  176. /*
  177. * Setup options
  178. */
  179. struct screen_info screen_info;
  180. EXPORT_SYMBOL(screen_info);
  181. struct apm_info apm_info;
  182. EXPORT_SYMBOL(apm_info);
  183. struct edid_info edid_info;
  184. EXPORT_SYMBOL_GPL(edid_info);
  185. struct ist_info ist_info;
  186. #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
  187. defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
  188. EXPORT_SYMBOL(ist_info);
  189. #endif
  190. extern void early_cpu_init(void);
  191. extern int root_mountflags;
  192. unsigned long saved_video_mode;
  193. #define RAMDISK_IMAGE_START_MASK 0x07FF
  194. #define RAMDISK_PROMPT_FLAG 0x8000
  195. #define RAMDISK_LOAD_FLAG 0x4000
  196. static char __initdata command_line[COMMAND_LINE_SIZE];
  197. #ifndef CONFIG_DEBUG_BOOT_PARAMS
  198. struct boot_params __initdata boot_params;
  199. #else
  200. struct boot_params boot_params;
  201. #endif
  202. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  203. struct edd edd;
  204. #ifdef CONFIG_EDD_MODULE
  205. EXPORT_SYMBOL(edd);
  206. #endif
  207. /**
  208. * copy_edd() - Copy the BIOS EDD information
  209. * from boot_params into a safe place.
  210. *
  211. */
  212. static inline void copy_edd(void)
  213. {
  214. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  215. sizeof(edd.mbr_signature));
  216. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  217. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  218. edd.edd_info_nr = boot_params.eddbuf_entries;
  219. }
  220. #else
  221. static inline void copy_edd(void)
  222. {
  223. }
  224. #endif
  225. #ifdef CONFIG_PROC_VMCORE
  226. /* elfcorehdr= specifies the location of elf core header
  227. * stored by the crashed kernel.
  228. */
  229. static int __init parse_elfcorehdr(char *arg)
  230. {
  231. if (!arg)
  232. return -EINVAL;
  233. elfcorehdr_addr = memparse(arg, &arg);
  234. return 0;
  235. }
  236. early_param("elfcorehdr", parse_elfcorehdr);
  237. #endif /* CONFIG_PROC_VMCORE */
  238. /*
  239. * highmem=size forces highmem to be exactly 'size' bytes.
  240. * This works even on boxes that have no highmem otherwise.
  241. * This also works to reduce highmem size on bigger boxes.
  242. */
  243. static int __init parse_highmem(char *arg)
  244. {
  245. if (!arg)
  246. return -EINVAL;
  247. highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
  248. return 0;
  249. }
  250. early_param("highmem", parse_highmem);
  251. /*
  252. * vmalloc=size forces the vmalloc area to be exactly 'size'
  253. * bytes. This can be used to increase (or decrease) the
  254. * vmalloc area - the default is 128m.
  255. */
  256. static int __init parse_vmalloc(char *arg)
  257. {
  258. if (!arg)
  259. return -EINVAL;
  260. __VMALLOC_RESERVE = memparse(arg, &arg);
  261. return 0;
  262. }
  263. early_param("vmalloc", parse_vmalloc);
  264. /*
  265. * reservetop=size reserves a hole at the top of the kernel address space which
  266. * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
  267. * so relocating the fixmap can be done before paging initialization.
  268. */
  269. static int __init parse_reservetop(char *arg)
  270. {
  271. unsigned long address;
  272. if (!arg)
  273. return -EINVAL;
  274. address = memparse(arg, &arg);
  275. reserve_top_address(address);
  276. return 0;
  277. }
  278. early_param("reservetop", parse_reservetop);
  279. /*
  280. * Determine low and high memory ranges:
  281. */
  282. unsigned long __init find_max_low_pfn(void)
  283. {
  284. unsigned long max_low_pfn;
  285. max_low_pfn = max_pfn;
  286. if (max_low_pfn > MAXMEM_PFN) {
  287. if (highmem_pages == -1)
  288. highmem_pages = max_pfn - MAXMEM_PFN;
  289. if (highmem_pages + MAXMEM_PFN < max_pfn)
  290. max_pfn = MAXMEM_PFN + highmem_pages;
  291. if (highmem_pages + MAXMEM_PFN > max_pfn) {
  292. printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
  293. highmem_pages = 0;
  294. }
  295. max_low_pfn = MAXMEM_PFN;
  296. #ifndef CONFIG_HIGHMEM
  297. /* Maximum memory usable is what is directly addressable */
  298. printk(KERN_WARNING "Warning only %ldMB will be used.\n",
  299. MAXMEM>>20);
  300. if (max_pfn > MAX_NONPAE_PFN)
  301. printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
  302. else
  303. printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
  304. max_pfn = MAXMEM_PFN;
  305. #else /* !CONFIG_HIGHMEM */
  306. #ifndef CONFIG_HIGHMEM64G
  307. if (max_pfn > MAX_NONPAE_PFN) {
  308. max_pfn = MAX_NONPAE_PFN;
  309. printk(KERN_WARNING "Warning only 4GB will be used.\n");
  310. printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
  311. }
  312. #endif /* !CONFIG_HIGHMEM64G */
  313. #endif /* !CONFIG_HIGHMEM */
  314. } else {
  315. if (highmem_pages == -1)
  316. highmem_pages = 0;
  317. #ifdef CONFIG_HIGHMEM
  318. if (highmem_pages >= max_pfn) {
  319. printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
  320. highmem_pages = 0;
  321. }
  322. if (highmem_pages) {
  323. if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
  324. printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
  325. highmem_pages = 0;
  326. }
  327. max_low_pfn -= highmem_pages;
  328. }
  329. #else
  330. if (highmem_pages)
  331. printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
  332. #endif
  333. }
  334. return max_low_pfn;
  335. }
  336. #ifndef CONFIG_NEED_MULTIPLE_NODES
  337. static void __init setup_bootmem_allocator(void);
  338. static unsigned long __init setup_memory(void)
  339. {
  340. /*
  341. * partially used pages are not usable - thus
  342. * we are rounding upwards:
  343. */
  344. min_low_pfn = PFN_UP(init_pg_tables_end);
  345. max_low_pfn = find_max_low_pfn();
  346. #ifdef CONFIG_HIGHMEM
  347. highstart_pfn = highend_pfn = max_pfn;
  348. if (max_pfn > max_low_pfn) {
  349. highstart_pfn = max_low_pfn;
  350. }
  351. memory_present(0, 0, highend_pfn);
  352. printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
  353. pages_to_mb(highend_pfn - highstart_pfn));
  354. num_physpages = highend_pfn;
  355. high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
  356. #else
  357. memory_present(0, 0, max_low_pfn);
  358. num_physpages = max_low_pfn;
  359. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
  360. #endif
  361. #ifdef CONFIG_FLATMEM
  362. max_mapnr = num_physpages;
  363. #endif
  364. printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
  365. pages_to_mb(max_low_pfn));
  366. setup_bootmem_allocator();
  367. return max_low_pfn;
  368. }
  369. static void __init zone_sizes_init(void)
  370. {
  371. unsigned long max_zone_pfns[MAX_NR_ZONES];
  372. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  373. max_zone_pfns[ZONE_DMA] =
  374. virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  375. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  376. remove_all_active_ranges();
  377. #ifdef CONFIG_HIGHMEM
  378. max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
  379. e820_register_active_regions(0, 0, highend_pfn);
  380. #else
  381. e820_register_active_regions(0, 0, max_low_pfn);
  382. #endif
  383. free_area_init_nodes(max_zone_pfns);
  384. }
  385. #else
  386. extern unsigned long __init setup_memory(void);
  387. extern void zone_sizes_init(void);
  388. #endif /* !CONFIG_NEED_MULTIPLE_NODES */
  389. #ifdef CONFIG_BLK_DEV_INITRD
  390. static bool do_relocate_initrd = false;
  391. static void __init reserve_initrd(void)
  392. {
  393. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  394. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  395. u64 ramdisk_end = ramdisk_image + ramdisk_size;
  396. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  397. u64 ramdisk_here;
  398. if (!boot_params.hdr.type_of_loader ||
  399. !ramdisk_image || !ramdisk_size)
  400. return; /* No initrd provided by bootloader */
  401. initrd_start = 0;
  402. if (ramdisk_size >= end_of_lowmem/2) {
  403. free_early(ramdisk_image, ramdisk_end);
  404. printk(KERN_ERR "initrd too large to handle, "
  405. "disabling initrd\n");
  406. return;
  407. }
  408. printk(KERN_INFO "old RAMDISK: %08llx - %08llx\n", ramdisk_image,
  409. ramdisk_end);
  410. if (ramdisk_end <= end_of_lowmem) {
  411. /* All in lowmem, easy case */
  412. /*
  413. * don't need to reserve again, already reserved early
  414. * in i386_start_kernel
  415. */
  416. initrd_start = ramdisk_image + PAGE_OFFSET;
  417. initrd_end = initrd_start+ramdisk_size;
  418. return;
  419. }
  420. /* We need to move the initrd down into lowmem */
  421. ramdisk_here = find_e820_area(min_low_pfn<<PAGE_SHIFT,
  422. end_of_lowmem, ramdisk_size,
  423. PAGE_SIZE);
  424. if (ramdisk_here == -1ULL)
  425. panic("Cannot find place for new RAMDISK of size %lld\n",
  426. ramdisk_size);
  427. /* Note: this includes all the lowmem currently occupied by
  428. the initrd, we rely on that fact to keep the data intact. */
  429. reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
  430. "NEW RAMDISK");
  431. initrd_start = ramdisk_here + PAGE_OFFSET;
  432. initrd_end = initrd_start + ramdisk_size;
  433. printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
  434. ramdisk_here, ramdisk_here + ramdisk_size);
  435. do_relocate_initrd = true;
  436. }
  437. #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
  438. static void __init relocate_initrd(void)
  439. {
  440. u64 ramdisk_image = boot_params.hdr.ramdisk_image;
  441. u64 ramdisk_size = boot_params.hdr.ramdisk_size;
  442. u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
  443. u64 ramdisk_here;
  444. unsigned long slop, clen, mapaddr;
  445. char *p, *q;
  446. if (!do_relocate_initrd)
  447. return;
  448. ramdisk_here = initrd_start - PAGE_OFFSET;
  449. q = (char *)initrd_start;
  450. /* Copy any lowmem portion of the initrd */
  451. if (ramdisk_image < end_of_lowmem) {
  452. clen = end_of_lowmem - ramdisk_image;
  453. p = (char *)__va(ramdisk_image);
  454. memcpy(q, p, clen);
  455. q += clen;
  456. /* need to free these low pages...*/
  457. printk(KERN_INFO "Freeing old partial RAMDISK %08llx-%08llx\n",
  458. ramdisk_image, ramdisk_image + clen - 1);
  459. free_bootmem(ramdisk_image, clen);
  460. ramdisk_image += clen;
  461. ramdisk_size -= clen;
  462. }
  463. /* Copy the highmem portion of the initrd */
  464. while (ramdisk_size) {
  465. slop = ramdisk_image & ~PAGE_MASK;
  466. clen = ramdisk_size;
  467. if (clen > MAX_MAP_CHUNK-slop)
  468. clen = MAX_MAP_CHUNK-slop;
  469. mapaddr = ramdisk_image & PAGE_MASK;
  470. p = early_ioremap(mapaddr, clen+slop);
  471. memcpy(q, p+slop, clen);
  472. early_iounmap(p, clen+slop);
  473. q += clen;
  474. ramdisk_image += clen;
  475. ramdisk_size -= clen;
  476. }
  477. /* high pages is not converted by early_res_to_bootmem */
  478. ramdisk_image = boot_params.hdr.ramdisk_image;
  479. ramdisk_size = boot_params.hdr.ramdisk_size;
  480. printk(KERN_INFO "Copied RAMDISK from %016llx - %016llx to %08llx - %08llx\n",
  481. ramdisk_image, ramdisk_image + ramdisk_size - 1,
  482. ramdisk_here, ramdisk_here + ramdisk_size - 1);
  483. /* need to free that, otherwise init highmem will reserve it again */
  484. free_early(ramdisk_image, ramdisk_image+ramdisk_size);
  485. }
  486. #endif /* CONFIG_BLK_DEV_INITRD */
  487. void __init setup_bootmem_allocator(void)
  488. {
  489. int i;
  490. unsigned long bootmap_size, bootmap;
  491. /*
  492. * Initialize the boot-time allocator (with low memory only):
  493. */
  494. bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
  495. bootmap = find_e820_area(min_low_pfn<<PAGE_SHIFT,
  496. max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
  497. PAGE_SIZE);
  498. if (bootmap == -1L)
  499. panic("Cannot find bootmem map of size %ld\n", bootmap_size);
  500. reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
  501. #ifdef CONFIG_BLK_DEV_INITRD
  502. reserve_initrd();
  503. #endif
  504. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, max_low_pfn);
  505. printk(KERN_INFO " mapped low ram: 0 - %08lx\n",
  506. max_pfn_mapped<<PAGE_SHIFT);
  507. printk(KERN_INFO " low ram: %08lx - %08lx\n",
  508. min_low_pfn<<PAGE_SHIFT, max_low_pfn<<PAGE_SHIFT);
  509. printk(KERN_INFO " bootmap %08lx - %08lx\n",
  510. bootmap, bootmap + bootmap_size);
  511. for_each_online_node(i)
  512. free_bootmem_with_active_regions(i, max_low_pfn);
  513. early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
  514. }
  515. /*
  516. * The node 0 pgdat is initialized before all of these because
  517. * it's needed for bootmem. node>0 pgdats have their virtual
  518. * space allocated before the pagetables are in place to access
  519. * them, so they can't be cleared then.
  520. *
  521. * This should all compile down to nothing when NUMA is off.
  522. */
  523. static void __init remapped_pgdat_init(void)
  524. {
  525. int nid;
  526. for_each_online_node(nid) {
  527. if (nid != 0)
  528. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  529. }
  530. }
  531. #ifdef CONFIG_MCA
  532. static void set_mca_bus(int x)
  533. {
  534. MCA_bus = x;
  535. }
  536. #else
  537. static void set_mca_bus(int x) { }
  538. #endif
  539. static void probe_roms(void);
  540. /*
  541. * Determine if we were loaded by an EFI loader. If so, then we have also been
  542. * passed the efi memmap, systab, etc., so we should use these data structures
  543. * for initialization. Note, the efi init code path is determined by the
  544. * global efi_enabled. This allows the same kernel image to be used on existing
  545. * systems (with a traditional BIOS) as well as on EFI systems.
  546. */
  547. void __init setup_arch(char **cmdline_p)
  548. {
  549. int i;
  550. unsigned long max_low_pfn;
  551. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  552. pre_setup_arch_hook();
  553. early_cpu_init();
  554. early_ioremap_init();
  555. reserve_setup_data();
  556. #ifdef CONFIG_EFI
  557. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  558. "EL32", 4)) {
  559. efi_enabled = 1;
  560. efi_reserve_early();
  561. }
  562. #endif
  563. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  564. screen_info = boot_params.screen_info;
  565. edid_info = boot_params.edid_info;
  566. apm_info.bios = boot_params.apm_bios_info;
  567. ist_info = boot_params.ist_info;
  568. saved_video_mode = boot_params.hdr.vid_mode;
  569. if( boot_params.sys_desc_table.length != 0 ) {
  570. set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
  571. machine_id = boot_params.sys_desc_table.table[0];
  572. machine_submodel_id = boot_params.sys_desc_table.table[1];
  573. BIOS_revision = boot_params.sys_desc_table.table[2];
  574. }
  575. bootloader_type = boot_params.hdr.type_of_loader;
  576. #ifdef CONFIG_BLK_DEV_RAM
  577. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  578. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  579. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  580. #endif
  581. ARCH_SETUP
  582. setup_memory_map();
  583. copy_edd();
  584. if (!boot_params.hdr.root_flags)
  585. root_mountflags &= ~MS_RDONLY;
  586. init_mm.start_code = (unsigned long) _text;
  587. init_mm.end_code = (unsigned long) _etext;
  588. init_mm.end_data = (unsigned long) _edata;
  589. init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
  590. code_resource.start = virt_to_phys(_text);
  591. code_resource.end = virt_to_phys(_etext)-1;
  592. data_resource.start = virt_to_phys(_etext);
  593. data_resource.end = virt_to_phys(_edata)-1;
  594. bss_resource.start = virt_to_phys(&__bss_start);
  595. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  596. parse_setup_data();
  597. parse_early_param();
  598. finish_e820_parsing();
  599. probe_roms();
  600. /* after parse_early_param, so could debug it */
  601. insert_resource(&iomem_resource, &code_resource);
  602. insert_resource(&iomem_resource, &data_resource);
  603. insert_resource(&iomem_resource, &bss_resource);
  604. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  605. *cmdline_p = command_line;
  606. if (efi_enabled)
  607. efi_init();
  608. if (ppro_with_ram_bug()) {
  609. e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
  610. E820_RESERVED);
  611. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  612. printk(KERN_INFO "fixed physical RAM map:\n");
  613. e820_print_map("bad_ppro");
  614. }
  615. e820_register_active_regions(0, 0, -1UL);
  616. /*
  617. * partially used pages are not usable - thus
  618. * we are rounding upwards:
  619. */
  620. max_pfn = e820_end_of_ram();
  621. /* preallocate 4k for mptable mpc */
  622. early_reserve_e820_mpc_new();
  623. /* update e820 for memory not covered by WB MTRRs */
  624. mtrr_bp_init();
  625. if (mtrr_trim_uncached_memory(max_pfn)) {
  626. remove_all_active_ranges();
  627. e820_register_active_regions(0, 0, -1UL);
  628. max_pfn = e820_end_of_ram();
  629. }
  630. dmi_scan_machine();
  631. io_delay_init();
  632. #ifdef CONFIG_ACPI
  633. /*
  634. * Parse the ACPI tables for possible boot-time SMP configuration.
  635. */
  636. acpi_boot_table_init();
  637. #endif
  638. #ifdef CONFIG_ACPI_NUMA
  639. /*
  640. * Parse SRAT to discover nodes.
  641. */
  642. acpi_numa_init();
  643. #endif
  644. max_low_pfn = setup_memory();
  645. #ifdef CONFIG_ACPI_SLEEP
  646. /*
  647. * Reserve low memory region for sleep support.
  648. */
  649. acpi_reserve_bootmem();
  650. #endif
  651. #ifdef CONFIG_X86_FIND_SMP_CONFIG
  652. /*
  653. * Find and reserve possible boot-time SMP configuration:
  654. */
  655. find_smp_config();
  656. #endif
  657. reserve_crashkernel();
  658. reserve_ibft_region();
  659. #ifdef CONFIG_KVM_CLOCK
  660. kvmclock_init();
  661. #endif
  662. #ifdef CONFIG_VMI
  663. /*
  664. * Must be after max_low_pfn is determined, and before kernel
  665. * pagetables are setup.
  666. */
  667. vmi_init();
  668. #endif
  669. kvm_guest_init();
  670. /*
  671. * NOTE: before this point _nobody_ is allowed to allocate
  672. * any memory using the bootmem allocator. Although the
  673. * allocator is now initialised only the first 8Mb of the kernel
  674. * virtual address space has been mapped. All allocations before
  675. * paging_init() has completed must use the alloc_bootmem_low_pages()
  676. * variant (which allocates DMA'able memory) and care must be taken
  677. * not to exceed the 8Mb limit.
  678. */
  679. paging_init();
  680. /*
  681. * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
  682. */
  683. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  684. if (init_ohci1394_dma_early)
  685. init_ohci1394_dma_on_all_controllers();
  686. #endif
  687. /*
  688. * NOTE: at this point the bootmem allocator is fully available.
  689. */
  690. #ifdef CONFIG_BLK_DEV_INITRD
  691. relocate_initrd();
  692. #endif
  693. remapped_pgdat_init();
  694. sparse_init();
  695. zone_sizes_init();
  696. paravirt_post_allocator_init();
  697. #ifdef CONFIG_X86_GENERICARCH
  698. generic_apic_probe();
  699. #endif
  700. early_quirks();
  701. #ifdef CONFIG_ACPI
  702. acpi_boot_init();
  703. #endif
  704. #if defined(CONFIG_X86_MPPARSE) || defined(CONFIG_X86_VISWS)
  705. if (smp_found_config)
  706. get_smp_config();
  707. #endif
  708. #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
  709. if (def_to_bigsmp)
  710. printk(KERN_WARNING "More than 8 CPUs detected and "
  711. "CONFIG_X86_PC cannot handle it.\nUse "
  712. "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
  713. #endif
  714. e820_reserve_resources();
  715. e820_mark_nosave_regions(max_low_pfn);
  716. request_resource(&iomem_resource, &video_ram_resource);
  717. /* request I/O space for devices used on all i[345]86 PCs */
  718. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  719. request_resource(&ioport_resource, &standard_io_resources[i]);
  720. e820_setup_gap();
  721. #ifdef CONFIG_VT
  722. #if defined(CONFIG_VGA_CONSOLE)
  723. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  724. conswitchp = &vga_con;
  725. #elif defined(CONFIG_DUMMY_CONSOLE)
  726. conswitchp = &dummy_con;
  727. #endif
  728. #endif
  729. }
  730. static struct resource system_rom_resource = {
  731. .name = "System ROM",
  732. .start = 0xf0000,
  733. .end = 0xfffff,
  734. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  735. };
  736. static struct resource extension_rom_resource = {
  737. .name = "Extension ROM",
  738. .start = 0xe0000,
  739. .end = 0xeffff,
  740. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  741. };
  742. static struct resource adapter_rom_resources[] = { {
  743. .name = "Adapter ROM",
  744. .start = 0xc8000,
  745. .end = 0,
  746. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  747. }, {
  748. .name = "Adapter ROM",
  749. .start = 0,
  750. .end = 0,
  751. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  752. }, {
  753. .name = "Adapter ROM",
  754. .start = 0,
  755. .end = 0,
  756. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  757. }, {
  758. .name = "Adapter ROM",
  759. .start = 0,
  760. .end = 0,
  761. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  762. }, {
  763. .name = "Adapter ROM",
  764. .start = 0,
  765. .end = 0,
  766. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  767. }, {
  768. .name = "Adapter ROM",
  769. .start = 0,
  770. .end = 0,
  771. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  772. } };
  773. static struct resource video_rom_resource = {
  774. .name = "Video ROM",
  775. .start = 0xc0000,
  776. .end = 0xc7fff,
  777. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  778. };
  779. #define ROMSIGNATURE 0xaa55
  780. static int __init romsignature(const unsigned char *rom)
  781. {
  782. const unsigned short * const ptr = (const unsigned short *)rom;
  783. unsigned short sig;
  784. return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
  785. }
  786. static int __init romchecksum(const unsigned char *rom, unsigned long length)
  787. {
  788. unsigned char sum, c;
  789. for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
  790. sum += c;
  791. return !length && !sum;
  792. }
  793. static void __init probe_roms(void)
  794. {
  795. const unsigned char *rom;
  796. unsigned long start, length, upper;
  797. unsigned char c;
  798. int i;
  799. /* video rom */
  800. upper = adapter_rom_resources[0].start;
  801. for (start = video_rom_resource.start; start < upper; start += 2048) {
  802. rom = isa_bus_to_virt(start);
  803. if (!romsignature(rom))
  804. continue;
  805. video_rom_resource.start = start;
  806. if (probe_kernel_address(rom + 2, c) != 0)
  807. continue;
  808. /* 0 < length <= 0x7f * 512, historically */
  809. length = c * 512;
  810. /* if checksum okay, trust length byte */
  811. if (length && romchecksum(rom, length))
  812. video_rom_resource.end = start + length - 1;
  813. request_resource(&iomem_resource, &video_rom_resource);
  814. break;
  815. }
  816. start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
  817. if (start < upper)
  818. start = upper;
  819. /* system rom */
  820. request_resource(&iomem_resource, &system_rom_resource);
  821. upper = system_rom_resource.start;
  822. /* check for extension rom (ignore length byte!) */
  823. rom = isa_bus_to_virt(extension_rom_resource.start);
  824. if (romsignature(rom)) {
  825. length = extension_rom_resource.end - extension_rom_resource.start + 1;
  826. if (romchecksum(rom, length)) {
  827. request_resource(&iomem_resource, &extension_rom_resource);
  828. upper = extension_rom_resource.start;
  829. }
  830. }
  831. /* check for adapter roms on 2k boundaries */
  832. for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
  833. rom = isa_bus_to_virt(start);
  834. if (!romsignature(rom))
  835. continue;
  836. if (probe_kernel_address(rom + 2, c) != 0)
  837. continue;
  838. /* 0 < length <= 0x7f * 512, historically */
  839. length = c * 512;
  840. /* but accept any length that fits if checksum okay */
  841. if (!length || start + length > upper || !romchecksum(rom, length))
  842. continue;
  843. adapter_rom_resources[i].start = start;
  844. adapter_rom_resources[i].end = start + length - 1;
  845. request_resource(&iomem_resource, &adapter_rom_resources[i]);
  846. start = adapter_rom_resources[i++].end & ~2047UL;
  847. }
  848. }