setup_32.c 27 KB

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