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