setup_32.c 21 KB

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