ia64/xen-unstable

view linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c @ 13978:477a3bde3b61

linux: miscellaneous changes after upgrade through 2.6.17.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kfraser@localhost.localdomain
date Thu Feb 15 14:12:32 2007 +0000 (2007-02-15)
parents beab19d957de
children 7c739272bac8
line source
1 /*
2 * linux/arch/x86-64/kernel/setup.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 *
6 * Nov 2001 Dave Jones <davej@suse.de>
7 * Forked from i386 setup code.
8 */
10 /*
11 * This file handles the architecture-dependent parts of initialization
12 */
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/stddef.h>
19 #include <linux/unistd.h>
20 #include <linux/ptrace.h>
21 #include <linux/slab.h>
22 #include <linux/user.h>
23 #include <linux/a.out.h>
24 #include <linux/screen_info.h>
25 #include <linux/ioport.h>
26 #include <linux/delay.h>
27 #include <linux/init.h>
28 #include <linux/initrd.h>
29 #include <linux/highmem.h>
30 #include <linux/bootmem.h>
31 #include <linux/module.h>
32 #include <asm/processor.h>
33 #include <linux/console.h>
34 #include <linux/seq_file.h>
35 #include <linux/crash_dump.h>
36 #include <linux/root_dev.h>
37 #include <linux/pci.h>
38 #include <linux/acpi.h>
39 #include <linux/kallsyms.h>
40 #include <linux/edd.h>
41 #include <linux/mmzone.h>
42 #include <linux/kexec.h>
43 #include <linux/cpufreq.h>
44 #include <linux/dmi.h>
45 #include <linux/dma-mapping.h>
46 #include <linux/ctype.h>
48 #include <asm/mtrr.h>
49 #include <asm/uaccess.h>
50 #include <asm/system.h>
51 #include <asm/io.h>
52 #include <asm/smp.h>
53 #include <asm/msr.h>
54 #include <asm/desc.h>
55 #include <video/edid.h>
56 #include <asm/e820.h>
57 #include <asm/dma.h>
58 #include <asm/mpspec.h>
59 #include <asm/mmu_context.h>
60 #include <asm/bootsetup.h>
61 #include <asm/proto.h>
62 #include <asm/setup.h>
63 #include <asm/mach_apic.h>
64 #include <asm/numa.h>
65 #include <asm/sections.h>
66 #include <asm/dmi.h>
67 #ifdef CONFIG_XEN
68 #include <linux/percpu.h>
69 #include <xen/interface/physdev.h>
70 #include "setup_arch_pre.h"
71 #include <asm/hypervisor.h>
72 #include <xen/interface/nmi.h>
73 #include <xen/features.h>
74 #include <xen/xencons.h>
75 #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
76 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
77 #include <asm/mach-xen/setup_arch_post.h>
78 #include <xen/interface/memory.h>
80 #ifdef CONFIG_XEN
81 #include <xen/interface/kexec.h>
82 #endif
84 extern unsigned long start_pfn;
85 extern struct edid_info edid_info;
87 shared_info_t *HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
88 EXPORT_SYMBOL(HYPERVISOR_shared_info);
90 extern char hypercall_page[PAGE_SIZE];
91 EXPORT_SYMBOL(hypercall_page);
93 /* Allows setting of maximum possible memory size */
94 unsigned long xen_override_max_pfn;
96 static int xen_panic_event(struct notifier_block *, unsigned long, void *);
97 static struct notifier_block xen_panic_block = {
98 xen_panic_event, NULL, 0 /* try to go last */
99 };
101 unsigned long *phys_to_machine_mapping;
102 unsigned long *pfn_to_mfn_frame_list_list, *pfn_to_mfn_frame_list[512];
104 EXPORT_SYMBOL(phys_to_machine_mapping);
106 DEFINE_PER_CPU(multicall_entry_t, multicall_list[8]);
107 DEFINE_PER_CPU(int, nr_multicall_ents);
109 /* Raw start-of-day parameters from the hypervisor. */
110 start_info_t *xen_start_info;
111 EXPORT_SYMBOL(xen_start_info);
112 #endif
114 /*
115 * Machine setup..
116 */
118 struct cpuinfo_x86 boot_cpu_data __read_mostly;
119 EXPORT_SYMBOL(boot_cpu_data);
121 unsigned long mmu_cr4_features;
123 int acpi_disabled;
124 EXPORT_SYMBOL(acpi_disabled);
125 #ifdef CONFIG_ACPI
126 extern int __initdata acpi_ht;
127 extern acpi_interrupt_flags acpi_sci_flags;
128 int __initdata acpi_force = 0;
129 #endif
131 int acpi_numa __initdata;
133 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
134 int bootloader_type;
136 unsigned long saved_video_mode;
138 /*
139 * Early DMI memory
140 */
141 int dmi_alloc_index;
142 char dmi_alloc_data[DMI_MAX_DATA];
144 /*
145 * Setup options
146 */
147 struct screen_info screen_info;
148 EXPORT_SYMBOL(screen_info);
149 struct sys_desc_table_struct {
150 unsigned short length;
151 unsigned char table[0];
152 };
154 struct edid_info edid_info;
155 EXPORT_SYMBOL_GPL(edid_info);
156 struct e820map e820;
157 #ifdef CONFIG_XEN
158 struct e820map machine_e820;
159 #endif
161 extern int root_mountflags;
163 char command_line[COMMAND_LINE_SIZE];
165 struct resource standard_io_resources[] = {
166 { .name = "dma1", .start = 0x00, .end = 0x1f,
167 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
168 { .name = "pic1", .start = 0x20, .end = 0x21,
169 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
170 { .name = "timer0", .start = 0x40, .end = 0x43,
171 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
172 { .name = "timer1", .start = 0x50, .end = 0x53,
173 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
174 { .name = "keyboard", .start = 0x60, .end = 0x6f,
175 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
176 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
177 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
178 { .name = "pic2", .start = 0xa0, .end = 0xa1,
179 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
180 { .name = "dma2", .start = 0xc0, .end = 0xdf,
181 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
182 { .name = "fpu", .start = 0xf0, .end = 0xff,
183 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
184 };
186 #define STANDARD_IO_RESOURCES \
187 (sizeof standard_io_resources / sizeof standard_io_resources[0])
189 #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
191 struct resource data_resource = {
192 .name = "Kernel data",
193 .start = 0,
194 .end = 0,
195 .flags = IORESOURCE_RAM,
196 };
197 struct resource code_resource = {
198 .name = "Kernel code",
199 .start = 0,
200 .end = 0,
201 .flags = IORESOURCE_RAM,
202 };
204 #define IORESOURCE_ROM (IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM)
206 static struct resource system_rom_resource = {
207 .name = "System ROM",
208 .start = 0xf0000,
209 .end = 0xfffff,
210 .flags = IORESOURCE_ROM,
211 };
213 static struct resource extension_rom_resource = {
214 .name = "Extension ROM",
215 .start = 0xe0000,
216 .end = 0xeffff,
217 .flags = IORESOURCE_ROM,
218 };
220 static struct resource adapter_rom_resources[] = {
221 { .name = "Adapter ROM", .start = 0xc8000, .end = 0,
222 .flags = IORESOURCE_ROM },
223 { .name = "Adapter ROM", .start = 0, .end = 0,
224 .flags = IORESOURCE_ROM },
225 { .name = "Adapter ROM", .start = 0, .end = 0,
226 .flags = IORESOURCE_ROM },
227 { .name = "Adapter ROM", .start = 0, .end = 0,
228 .flags = IORESOURCE_ROM },
229 { .name = "Adapter ROM", .start = 0, .end = 0,
230 .flags = IORESOURCE_ROM },
231 { .name = "Adapter ROM", .start = 0, .end = 0,
232 .flags = IORESOURCE_ROM }
233 };
235 #define ADAPTER_ROM_RESOURCES \
236 (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
238 static struct resource video_rom_resource = {
239 .name = "Video ROM",
240 .start = 0xc0000,
241 .end = 0xc7fff,
242 .flags = IORESOURCE_ROM,
243 };
245 static struct resource video_ram_resource = {
246 .name = "Video RAM area",
247 .start = 0xa0000,
248 .end = 0xbffff,
249 .flags = IORESOURCE_RAM,
250 };
252 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
254 static int __init romchecksum(unsigned char *rom, unsigned long length)
255 {
256 unsigned char *p, sum = 0;
258 for (p = rom; p < rom + length; p++)
259 sum += *p;
260 return sum == 0;
261 }
263 static void __init probe_roms(void)
264 {
265 unsigned long start, length, upper;
266 unsigned char *rom;
267 int i;
269 #ifdef CONFIG_XEN
270 /* Nothing to do if not running in dom0. */
271 if (!is_initial_xendomain())
272 return;
273 #endif
275 /* video rom */
276 upper = adapter_rom_resources[0].start;
277 for (start = video_rom_resource.start; start < upper; start += 2048) {
278 rom = isa_bus_to_virt(start);
279 if (!romsignature(rom))
280 continue;
282 video_rom_resource.start = start;
284 /* 0 < length <= 0x7f * 512, historically */
285 length = rom[2] * 512;
287 /* if checksum okay, trust length byte */
288 if (length && romchecksum(rom, length))
289 video_rom_resource.end = start + length - 1;
291 request_resource(&iomem_resource, &video_rom_resource);
292 break;
293 }
295 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
296 if (start < upper)
297 start = upper;
299 /* system rom */
300 request_resource(&iomem_resource, &system_rom_resource);
301 upper = system_rom_resource.start;
303 /* check for extension rom (ignore length byte!) */
304 rom = isa_bus_to_virt(extension_rom_resource.start);
305 if (romsignature(rom)) {
306 length = extension_rom_resource.end - extension_rom_resource.start + 1;
307 if (romchecksum(rom, length)) {
308 request_resource(&iomem_resource, &extension_rom_resource);
309 upper = extension_rom_resource.start;
310 }
311 }
313 /* check for adapter roms on 2k boundaries */
314 for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
315 rom = isa_bus_to_virt(start);
316 if (!romsignature(rom))
317 continue;
319 /* 0 < length <= 0x7f * 512, historically */
320 length = rom[2] * 512;
322 /* but accept any length that fits if checksum okay */
323 if (!length || start + length > upper || !romchecksum(rom, length))
324 continue;
326 adapter_rom_resources[i].start = start;
327 adapter_rom_resources[i].end = start + length - 1;
328 request_resource(&iomem_resource, &adapter_rom_resources[i]);
330 start = adapter_rom_resources[i++].end & ~2047UL;
331 }
332 }
334 /* Check for full argument with no trailing characters */
335 static int fullarg(char *p, char *arg)
336 {
337 int l = strlen(arg);
338 return !memcmp(p, arg, l) && (p[l] == 0 || isspace(p[l]));
339 }
341 static __init void parse_cmdline_early (char ** cmdline_p)
342 {
343 char c = ' ', *to = command_line, *from = COMMAND_LINE;
344 int len = 0;
345 int userdef = 0;
347 for (;;) {
348 if (c != ' ')
349 goto next_char;
351 #ifdef CONFIG_SMP
352 /*
353 * If the BIOS enumerates physical processors before logical,
354 * maxcpus=N at enumeration-time can be used to disable HT.
355 */
356 else if (!memcmp(from, "maxcpus=", 8)) {
357 extern unsigned int maxcpus;
359 maxcpus = simple_strtoul(from + 8, NULL, 0);
360 }
361 #endif
362 #ifdef CONFIG_ACPI
363 /* "acpi=off" disables both ACPI table parsing and interpreter init */
364 if (fullarg(from,"acpi=off"))
365 disable_acpi();
367 if (fullarg(from, "acpi=force")) {
368 /* add later when we do DMI horrors: */
369 acpi_force = 1;
370 acpi_disabled = 0;
371 }
373 /* acpi=ht just means: do ACPI MADT parsing
374 at bootup, but don't enable the full ACPI interpreter */
375 if (fullarg(from, "acpi=ht")) {
376 if (!acpi_force)
377 disable_acpi();
378 acpi_ht = 1;
379 }
380 else if (fullarg(from, "pci=noacpi"))
381 acpi_disable_pci();
382 else if (fullarg(from, "acpi=noirq"))
383 acpi_noirq_set();
385 else if (fullarg(from, "acpi_sci=edge"))
386 acpi_sci_flags.trigger = 1;
387 else if (fullarg(from, "acpi_sci=level"))
388 acpi_sci_flags.trigger = 3;
389 else if (fullarg(from, "acpi_sci=high"))
390 acpi_sci_flags.polarity = 1;
391 else if (fullarg(from, "acpi_sci=low"))
392 acpi_sci_flags.polarity = 3;
394 /* acpi=strict disables out-of-spec workarounds */
395 else if (fullarg(from, "acpi=strict")) {
396 acpi_strict = 1;
397 }
398 #ifdef CONFIG_X86_IO_APIC
399 else if (fullarg(from, "acpi_skip_timer_override"))
400 acpi_skip_timer_override = 1;
401 #endif
402 #endif
404 #ifndef CONFIG_XEN
405 if (fullarg(from, "nolapic") || fullarg(from, "disableapic")) {
406 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
407 disable_apic = 1;
408 }
410 if (fullarg(from, "noapic"))
411 skip_ioapic_setup = 1;
413 if (fullarg(from,"apic")) {
414 skip_ioapic_setup = 0;
415 ioapic_force = 1;
416 }
417 #endif
419 if (!memcmp(from, "mem=", 4))
420 parse_memopt(from+4, &from);
422 if (!memcmp(from, "memmap=", 7)) {
423 /* exactmap option is for used defined memory */
424 if (!memcmp(from+7, "exactmap", 8)) {
425 #ifdef CONFIG_CRASH_DUMP
426 /* If we are doing a crash dump, we
427 * still need to know the real mem
428 * size before original memory map is
429 * reset.
430 */
431 saved_max_pfn = e820_end_of_ram();
432 #endif
433 from += 8+7;
434 end_pfn_map = 0;
435 e820.nr_map = 0;
436 userdef = 1;
437 }
438 else {
439 parse_memmapopt(from+7, &from);
440 userdef = 1;
441 }
442 }
444 #ifdef CONFIG_NUMA
445 if (!memcmp(from, "numa=", 5))
446 numa_setup(from+5);
447 #endif
449 if (!memcmp(from,"iommu=",6)) {
450 iommu_setup(from+6);
451 }
453 if (fullarg(from,"oops=panic"))
454 panic_on_oops = 1;
456 if (!memcmp(from, "noexec=", 7))
457 nonx_setup(from + 7);
459 #ifdef CONFIG_KEXEC
460 /* crashkernel=size@addr specifies the location to reserve for
461 * a crash kernel. By reserving this memory we guarantee
462 * that linux never set's it up as a DMA target.
463 * Useful for holding code to do something appropriate
464 * after a kernel panic.
465 */
466 else if (!memcmp(from, "crashkernel=", 12)) {
467 #ifndef CONFIG_XEN
468 unsigned long size, base;
469 size = memparse(from+12, &from);
470 if (*from == '@') {
471 base = memparse(from+1, &from);
472 /* FIXME: Do I want a sanity check
473 * to validate the memory range?
474 */
475 crashk_res.start = base;
476 crashk_res.end = base + size - 1;
477 }
478 #else
479 printk("Ignoring crashkernel command line, "
480 "parameter will be supplied by xen\n");
481 #endif
482 }
483 #endif
485 #ifdef CONFIG_PROC_VMCORE
486 /* elfcorehdr= specifies the location of elf core header
487 * stored by the crashed kernel. This option will be passed
488 * by kexec loader to the capture kernel.
489 */
490 else if(!memcmp(from, "elfcorehdr=", 11))
491 elfcorehdr_addr = memparse(from+11, &from);
492 #endif
494 #if defined(CONFIG_HOTPLUG_CPU) && !defined(CONFIG_XEN)
495 else if (!memcmp(from, "additional_cpus=", 16))
496 setup_additional_cpus(from+16);
497 #endif
499 next_char:
500 c = *(from++);
501 if (!c)
502 break;
503 if (COMMAND_LINE_SIZE <= ++len)
504 break;
505 *(to++) = c;
506 }
507 if (userdef) {
508 printk(KERN_INFO "user-defined physical RAM map:\n");
509 e820_print_map("user");
510 }
511 *to = '\0';
512 *cmdline_p = command_line;
513 }
515 #ifndef CONFIG_NUMA
516 static void __init
517 contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
518 {
519 unsigned long bootmap_size, bootmap;
521 bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
522 bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
523 if (bootmap == -1L)
524 panic("Cannot find bootmem map of size %ld\n",bootmap_size);
525 bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
526 #ifdef CONFIG_XEN
527 e820_bootmem_free(NODE_DATA(0), 0, xen_start_info->nr_pages<<PAGE_SHIFT);
528 #else
529 e820_bootmem_free(NODE_DATA(0), 0, end_pfn << PAGE_SHIFT);
530 #endif
531 reserve_bootmem(bootmap, bootmap_size);
532 }
533 #endif
535 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
536 struct edd edd;
537 #ifdef CONFIG_EDD_MODULE
538 EXPORT_SYMBOL(edd);
539 #endif
540 /**
541 * copy_edd() - Copy the BIOS EDD information
542 * from boot_params into a safe place.
543 *
544 */
545 static inline void copy_edd(void)
546 {
547 memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
548 memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
549 edd.mbr_signature_nr = EDD_MBR_SIG_NR;
550 edd.edd_info_nr = EDD_NR;
551 }
552 #else
553 static inline void copy_edd(void)
554 {
555 }
556 #endif
558 #ifndef CONFIG_XEN
559 #define EBDA_ADDR_POINTER 0x40E
561 unsigned __initdata ebda_addr;
562 unsigned __initdata ebda_size;
564 static void discover_ebda(void)
565 {
566 /*
567 * there is a real-mode segmented pointer pointing to the
568 * 4K EBDA area at 0x40E
569 */
570 ebda_addr = *(unsigned short *)EBDA_ADDR_POINTER;
571 ebda_addr <<= 4;
573 ebda_size = *(unsigned short *)(unsigned long)ebda_addr;
575 /* Round EBDA up to pages */
576 if (ebda_size == 0)
577 ebda_size = 1;
578 ebda_size <<= 10;
579 ebda_size = round_up(ebda_size + (ebda_addr & ~PAGE_MASK), PAGE_SIZE);
580 if (ebda_size > 64*1024)
581 ebda_size = 64*1024;
582 }
583 #else
584 #define discover_ebda() ((void)0)
585 #endif
587 void __init setup_arch(char **cmdline_p)
588 {
589 #ifdef CONFIG_XEN
590 /* Register a call for panic conditions. */
591 atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
593 ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
594 screen_info = SCREEN_INFO;
596 if (is_initial_xendomain()) {
597 /* This is drawn from a dump from vgacon:startup in
598 * standard Linux. */
599 screen_info.orig_video_mode = 3;
600 screen_info.orig_video_isVGA = 1;
601 screen_info.orig_video_lines = 25;
602 screen_info.orig_video_cols = 80;
603 screen_info.orig_video_ega_bx = 3;
604 screen_info.orig_video_points = 16;
605 screen_info.orig_y = screen_info.orig_video_lines - 1;
606 if (xen_start_info->console.dom0.info_size >=
607 sizeof(struct dom0_vga_console_info)) {
608 const struct dom0_vga_console_info *info =
609 (struct dom0_vga_console_info *)(
610 (char *)xen_start_info +
611 xen_start_info->console.dom0.info_off);
612 dom0_init_screen_info(info);
613 }
614 xen_start_info->console.domU.mfn = 0;
615 xen_start_info->console.domU.evtchn = 0;
616 } else
617 screen_info.orig_video_isVGA = 0;
619 edid_info = EDID_INFO;
620 saved_video_mode = SAVED_VIDEO_MODE;
621 bootloader_type = LOADER_TYPE;
623 #ifdef CONFIG_BLK_DEV_RAM
624 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
625 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
626 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
629 #endif
631 setup_xen_features();
633 HYPERVISOR_vm_assist(VMASST_CMD_enable,
634 VMASST_TYPE_writable_pagetables);
636 ARCH_SETUP
637 #else
638 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
639 screen_info = SCREEN_INFO;
640 edid_info = EDID_INFO;
641 saved_video_mode = SAVED_VIDEO_MODE;
642 bootloader_type = LOADER_TYPE;
644 #ifdef CONFIG_BLK_DEV_RAM
645 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
646 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
647 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
648 #endif
649 #endif /* !CONFIG_XEN */
650 setup_memory_region();
651 copy_edd();
653 if (!MOUNT_ROOT_RDONLY)
654 root_mountflags &= ~MS_RDONLY;
655 init_mm.start_code = (unsigned long) &_text;
656 init_mm.end_code = (unsigned long) &_etext;
657 init_mm.end_data = (unsigned long) &_edata;
658 init_mm.brk = (unsigned long) &_end;
660 code_resource.start = virt_to_phys(&_text);
661 code_resource.end = virt_to_phys(&_etext)-1;
662 data_resource.start = virt_to_phys(&_etext);
663 data_resource.end = virt_to_phys(&_edata)-1;
665 parse_cmdline_early(cmdline_p);
667 early_identify_cpu(&boot_cpu_data);
669 /*
670 * partially used pages are not usable - thus
671 * we are rounding upwards:
672 */
673 end_pfn = e820_end_of_ram();
674 num_physpages = end_pfn; /* for pfn_valid */
676 check_efer();
678 discover_ebda();
680 init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
682 /* dmi_scan_machine(); */
684 #ifdef CONFIG_ACPI_NUMA
685 /*
686 * Parse SRAT to discover nodes.
687 */
688 acpi_numa_init();
689 #endif
691 #ifdef CONFIG_NUMA
692 numa_initmem_init(0, end_pfn);
693 #else
694 contig_initmem_init(0, end_pfn);
695 #endif
697 /* Reserve direct mapping */
698 reserve_bootmem_generic(table_start << PAGE_SHIFT,
699 (table_end - table_start) << PAGE_SHIFT);
701 /* reserve kernel */
702 reserve_bootmem_generic(__pa_symbol(&_text),
703 __pa_symbol(&_end) - __pa_symbol(&_text));
705 #ifdef CONFIG_XEN
706 /* reserve physmap, start info and initial page tables */
707 reserve_bootmem_generic(__pa_symbol(&_end),
708 (table_start << PAGE_SHIFT) -
709 __pa_symbol(&_end));
710 #else
711 /*
712 * reserve physical page 0 - it's a special BIOS page on many boxes,
713 * enabling clean reboots, SMP operation, laptop functions.
714 */
715 reserve_bootmem_generic(0, PAGE_SIZE);
717 /* reserve ebda region */
718 if (ebda_addr)
719 reserve_bootmem_generic(ebda_addr, ebda_size);
720 #endif
722 #ifdef CONFIG_SMP
723 /*
724 * But first pinch a few for the stack/trampoline stuff
725 * FIXME: Don't need the extra page at 4K, but need to fix
726 * trampoline before removing it. (see the GDT stuff)
727 */
728 reserve_bootmem_generic(PAGE_SIZE, PAGE_SIZE);
730 /* Reserve SMP trampoline */
731 reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, PAGE_SIZE);
732 #endif
734 #ifdef CONFIG_ACPI_SLEEP
735 /*
736 * Reserve low memory region for sleep support.
737 */
738 acpi_reserve_bootmem();
739 #endif
740 #ifdef CONFIG_XEN
741 #ifdef CONFIG_BLK_DEV_INITRD
742 if (xen_start_info->mod_start) {
743 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
744 /*reserve_bootmem_generic(INITRD_START, INITRD_SIZE);*/
745 initrd_start = INITRD_START + PAGE_OFFSET;
746 initrd_end = initrd_start+INITRD_SIZE;
747 initrd_below_start_ok = 1;
748 } else {
749 printk(KERN_ERR "initrd extends beyond end of memory "
750 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
751 (unsigned long)(INITRD_START + INITRD_SIZE),
752 (unsigned long)(end_pfn << PAGE_SHIFT));
753 initrd_start = 0;
754 }
755 }
756 #endif
757 #else /* CONFIG_XEN */
758 #ifdef CONFIG_BLK_DEV_INITRD
759 if (LOADER_TYPE && INITRD_START) {
760 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
761 reserve_bootmem_generic(INITRD_START, INITRD_SIZE);
762 initrd_start =
763 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
764 initrd_end = initrd_start+INITRD_SIZE;
765 }
766 else {
767 printk(KERN_ERR "initrd extends beyond end of memory "
768 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
769 (unsigned long)(INITRD_START + INITRD_SIZE),
770 (unsigned long)(end_pfn << PAGE_SHIFT));
771 initrd_start = 0;
772 }
773 }
774 #endif
775 #endif /* !CONFIG_XEN */
776 #ifdef CONFIG_KEXEC
777 #ifdef CONFIG_XEN
778 xen_machine_kexec_setup_resources();
779 #else
780 if (crashk_res.start != crashk_res.end) {
781 reserve_bootmem_generic(crashk_res.start,
782 crashk_res.end - crashk_res.start + 1);
783 }
784 #endif
785 #endif
787 paging_init();
788 #ifdef CONFIG_X86_LOCAL_APIC
789 /*
790 * Find and reserve possible boot-time SMP configuration:
791 */
792 find_smp_config();
793 #endif
794 #ifdef CONFIG_XEN
795 {
796 int i, j, k, fpp;
798 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
799 /* Make sure we have a large enough P->M table. */
800 phys_to_machine_mapping = alloc_bootmem_pages(
801 end_pfn * sizeof(unsigned long));
802 memset(phys_to_machine_mapping, ~0,
803 end_pfn * sizeof(unsigned long));
804 memcpy(phys_to_machine_mapping,
805 (unsigned long *)xen_start_info->mfn_list,
806 xen_start_info->nr_pages * sizeof(unsigned long));
807 free_bootmem(
808 __pa(xen_start_info->mfn_list),
809 PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
810 sizeof(unsigned long))));
812 /*
813 * Initialise the list of the frames that specify the
814 * list of frames that make up the p2m table. Used by
815 * save/restore.
816 */
817 pfn_to_mfn_frame_list_list = alloc_bootmem_pages(PAGE_SIZE);
819 fpp = PAGE_SIZE/sizeof(unsigned long);
820 for (i=0, j=0, k=-1; i< end_pfn; i+=fpp, j++) {
821 if ((j % fpp) == 0) {
822 k++;
823 BUG_ON(k>=fpp);
824 pfn_to_mfn_frame_list[k] =
825 alloc_bootmem_pages(PAGE_SIZE);
826 pfn_to_mfn_frame_list_list[k] =
827 virt_to_mfn(pfn_to_mfn_frame_list[k]);
828 j=0;
829 }
830 pfn_to_mfn_frame_list[k][j] =
831 virt_to_mfn(&phys_to_machine_mapping[i]);
832 }
833 HYPERVISOR_shared_info->arch.max_pfn = end_pfn;
834 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
835 virt_to_mfn(pfn_to_mfn_frame_list_list);
836 }
838 }
840 if (!is_initial_xendomain()) {
841 acpi_disabled = 1;
842 #ifdef CONFIG_ACPI
843 acpi_ht = 0;
844 #endif
845 }
846 #endif
848 #ifndef CONFIG_XEN
849 check_ioapic();
850 #endif
852 zap_low_mappings(0);
854 /*
855 * set this early, so we dont allocate cpu0
856 * if MADT list doesnt list BSP first
857 * mpparse.c/MP_processor_info() allocates logical cpu numbers.
858 */
859 cpu_set(0, cpu_present_map);
860 #ifdef CONFIG_ACPI
861 /*
862 * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
863 * Call this early for SRAT node setup.
864 */
865 acpi_boot_table_init();
867 /*
868 * Read APIC and some other early information from ACPI tables.
869 */
870 acpi_boot_init();
871 #endif
873 init_cpu_to_node();
875 #ifdef CONFIG_X86_LOCAL_APIC
876 /*
877 * get boot-time SMP configuration:
878 */
879 if (smp_found_config)
880 get_smp_config();
881 #ifndef CONFIG_XEN
882 init_apic_mappings();
883 #endif
884 #endif
885 #if defined(CONFIG_XEN) && defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU)
886 prefill_possible_map();
887 #endif
889 /*
890 * Request address space for all standard RAM and ROM resources
891 * and also for regions reported as reserved by the e820.
892 */
893 probe_roms();
894 #ifdef CONFIG_XEN
895 if (is_initial_xendomain()) {
896 struct xen_memory_map memmap;
898 memmap.nr_entries = E820MAX;
899 set_xen_guest_handle(memmap.buffer, machine_e820.map);
901 if (HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap))
902 BUG();
903 machine_e820.nr_map = memmap.nr_entries;
905 e820_reserve_resources(machine_e820.map, machine_e820.nr_map);
906 }
907 #else
908 e820_reserve_resources(e820.map, e820.nr_map);
909 #endif
911 request_resource(&iomem_resource, &video_ram_resource);
913 {
914 unsigned i;
915 /* request I/O space for devices used on all i[345]86 PCs */
916 for (i = 0; i < STANDARD_IO_RESOURCES; i++)
917 request_resource(&ioport_resource, &standard_io_resources[i]);
918 }
920 #ifdef CONFIG_XEN
921 if (is_initial_xendomain())
922 e820_setup_gap(machine_e820.map, machine_e820.nr_map);
923 #else
924 e820_setup_gap(e820.map, e820.nr_map);
925 #endif
927 #ifdef CONFIG_XEN
928 {
929 struct physdev_set_iopl set_iopl;
931 set_iopl.iopl = 1;
932 HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
934 if (is_initial_xendomain()) {
935 #ifdef CONFIG_VT
936 #if defined(CONFIG_VGA_CONSOLE)
937 conswitchp = &vga_con;
938 #elif defined(CONFIG_DUMMY_CONSOLE)
939 conswitchp = &dummy_con;
940 #endif
941 #endif
942 } else {
943 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
944 conswitchp = &dummy_con;
945 #endif
946 }
947 }
948 xencons_early_setup();
949 #else /* CONFIG_XEN */
951 #ifdef CONFIG_VT
952 #if defined(CONFIG_VGA_CONSOLE)
953 conswitchp = &vga_con;
954 #elif defined(CONFIG_DUMMY_CONSOLE)
955 conswitchp = &dummy_con;
956 #endif
957 #endif
959 #endif /* !CONFIG_XEN */
960 }
962 #ifdef CONFIG_XEN
963 static int
964 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
965 {
966 HYPERVISOR_shutdown(SHUTDOWN_crash);
967 /* we're never actually going to get here... */
968 return NOTIFY_DONE;
969 }
970 #endif /* !CONFIG_XEN */
973 static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
974 {
975 unsigned int *v;
977 if (c->extended_cpuid_level < 0x80000004)
978 return 0;
980 v = (unsigned int *) c->x86_model_id;
981 cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
982 cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
983 cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
984 c->x86_model_id[48] = 0;
985 return 1;
986 }
989 static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
990 {
991 unsigned int n, dummy, eax, ebx, ecx, edx;
993 n = c->extended_cpuid_level;
995 if (n >= 0x80000005) {
996 cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
997 printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
998 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
999 c->x86_cache_size=(ecx>>24)+(edx>>24);
1000 /* On K8 L1 TLB is inclusive, so don't count it */
1001 c->x86_tlbsize = 0;
1004 if (n >= 0x80000006) {
1005 cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
1006 ecx = cpuid_ecx(0x80000006);
1007 c->x86_cache_size = ecx >> 16;
1008 c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
1010 printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
1011 c->x86_cache_size, ecx & 0xFF);
1014 if (n >= 0x80000007)
1015 cpuid(0x80000007, &dummy, &dummy, &dummy, &c->x86_power);
1016 if (n >= 0x80000008) {
1017 cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
1018 c->x86_virt_bits = (eax >> 8) & 0xff;
1019 c->x86_phys_bits = eax & 0xff;
1023 #ifdef CONFIG_NUMA
1024 static int nearby_node(int apicid)
1026 int i;
1027 for (i = apicid - 1; i >= 0; i--) {
1028 int node = apicid_to_node[i];
1029 if (node != NUMA_NO_NODE && node_online(node))
1030 return node;
1032 for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
1033 int node = apicid_to_node[i];
1034 if (node != NUMA_NO_NODE && node_online(node))
1035 return node;
1037 return first_node(node_online_map); /* Shouldn't happen */
1039 #endif
1041 /*
1042 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
1043 * Assumes number of cores is a power of two.
1044 */
1045 static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
1047 #ifdef CONFIG_SMP
1048 unsigned bits;
1049 #ifdef CONFIG_NUMA
1050 int cpu = smp_processor_id();
1051 int node = 0;
1052 unsigned apicid = hard_smp_processor_id();
1053 #endif
1054 unsigned ecx = cpuid_ecx(0x80000008);
1056 c->x86_max_cores = (ecx & 0xff) + 1;
1058 /* CPU telling us the core id bits shift? */
1059 bits = (ecx >> 12) & 0xF;
1061 /* Otherwise recompute */
1062 if (bits == 0) {
1063 while ((1 << bits) < c->x86_max_cores)
1064 bits++;
1067 /* Low order bits define the core id (index of core in socket) */
1068 c->cpu_core_id = c->phys_proc_id & ((1 << bits)-1);
1069 /* Convert the APIC ID into the socket ID */
1070 c->phys_proc_id = phys_pkg_id(bits);
1072 #ifdef CONFIG_NUMA
1073 node = c->phys_proc_id;
1074 if (apicid_to_node[apicid] != NUMA_NO_NODE)
1075 node = apicid_to_node[apicid];
1076 if (!node_online(node)) {
1077 /* Two possibilities here:
1078 - The CPU is missing memory and no node was created.
1079 In that case try picking one from a nearby CPU
1080 - The APIC IDs differ from the HyperTransport node IDs
1081 which the K8 northbridge parsing fills in.
1082 Assume they are all increased by a constant offset,
1083 but in the same order as the HT nodeids.
1084 If that doesn't result in a usable node fall back to the
1085 path for the previous case. */
1086 int ht_nodeid = apicid - (cpu_data[0].phys_proc_id << bits);
1087 if (ht_nodeid >= 0 &&
1088 apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
1089 node = apicid_to_node[ht_nodeid];
1090 /* Pick a nearby node */
1091 if (!node_online(node))
1092 node = nearby_node(apicid);
1094 numa_set_node(cpu, node);
1096 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
1097 #endif
1098 #endif
1101 static void __init init_amd(struct cpuinfo_x86 *c)
1103 unsigned level;
1105 #ifdef CONFIG_SMP
1106 unsigned long value;
1108 /*
1109 * Disable TLB flush filter by setting HWCR.FFDIS on K8
1110 * bit 6 of msr C001_0015
1112 * Errata 63 for SH-B3 steppings
1113 * Errata 122 for all steppings (F+ have it disabled by default)
1114 */
1115 if (c->x86 == 15) {
1116 rdmsrl(MSR_K8_HWCR, value);
1117 value |= 1 << 6;
1118 wrmsrl(MSR_K8_HWCR, value);
1120 #endif
1122 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
1123 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
1124 clear_bit(0*32+31, &c->x86_capability);
1126 /* On C+ stepping K8 rep microcode works well for copy/memset */
1127 level = cpuid_eax(1);
1128 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58))
1129 set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
1131 /* Enable workaround for FXSAVE leak */
1132 if (c->x86 >= 6)
1133 set_bit(X86_FEATURE_FXSAVE_LEAK, &c->x86_capability);
1135 level = get_model_name(c);
1136 if (!level) {
1137 switch (c->x86) {
1138 case 15:
1139 /* Should distinguish Models here, but this is only
1140 a fallback anyways. */
1141 strcpy(c->x86_model_id, "Hammer");
1142 break;
1145 display_cacheinfo(c);
1147 /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
1148 if (c->x86_power & (1<<8))
1149 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1151 /* Multi core CPU? */
1152 if (c->extended_cpuid_level >= 0x80000008)
1153 amd_detect_cmp(c);
1155 /* Fix cpuid4 emulation for more */
1156 num_cache_leaves = 3;
1159 static void __cpuinit detect_ht(struct cpuinfo_x86 *c)
1161 #ifdef CONFIG_SMP
1162 u32 eax, ebx, ecx, edx;
1163 int index_msb, core_bits;
1165 cpuid(1, &eax, &ebx, &ecx, &edx);
1168 if (!cpu_has(c, X86_FEATURE_HT))
1169 return;
1170 if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
1171 goto out;
1173 smp_num_siblings = (ebx & 0xff0000) >> 16;
1175 if (smp_num_siblings == 1) {
1176 printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
1177 } else if (smp_num_siblings > 1 ) {
1179 if (smp_num_siblings > NR_CPUS) {
1180 printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
1181 smp_num_siblings = 1;
1182 return;
1185 index_msb = get_count_order(smp_num_siblings);
1186 c->phys_proc_id = phys_pkg_id(index_msb);
1188 smp_num_siblings = smp_num_siblings / c->x86_max_cores;
1190 index_msb = get_count_order(smp_num_siblings) ;
1192 core_bits = get_count_order(c->x86_max_cores);
1194 c->cpu_core_id = phys_pkg_id(index_msb) &
1195 ((1 << core_bits) - 1);
1197 out:
1198 if ((c->x86_max_cores * smp_num_siblings) > 1) {
1199 printk(KERN_INFO "CPU: Physical Processor ID: %d\n", c->phys_proc_id);
1200 printk(KERN_INFO "CPU: Processor Core ID: %d\n", c->cpu_core_id);
1203 #endif
1206 /*
1207 * find out the number of processor cores on the die
1208 */
1209 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
1211 unsigned int eax, t;
1213 if (c->cpuid_level < 4)
1214 return 1;
1216 cpuid_count(4, 0, &eax, &t, &t, &t);
1218 if (eax & 0x1f)
1219 return ((eax >> 26) + 1);
1220 else
1221 return 1;
1224 static void srat_detect_node(void)
1226 #ifdef CONFIG_NUMA
1227 unsigned node;
1228 int cpu = smp_processor_id();
1229 int apicid = hard_smp_processor_id();
1231 /* Don't do the funky fallback heuristics the AMD version employs
1232 for now. */
1233 node = apicid_to_node[apicid];
1234 if (node == NUMA_NO_NODE)
1235 node = first_node(node_online_map);
1236 numa_set_node(cpu, node);
1238 if (acpi_numa > 0)
1239 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
1240 #endif
1243 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
1245 /* Cache sizes */
1246 unsigned n;
1248 init_intel_cacheinfo(c);
1249 if (c->cpuid_level > 9 ) {
1250 unsigned eax = cpuid_eax(10);
1251 /* Check for version and the number of counters */
1252 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
1253 set_bit(X86_FEATURE_ARCH_PERFMON, &c->x86_capability);
1256 n = c->extended_cpuid_level;
1257 if (n >= 0x80000008) {
1258 unsigned eax = cpuid_eax(0x80000008);
1259 c->x86_virt_bits = (eax >> 8) & 0xff;
1260 c->x86_phys_bits = eax & 0xff;
1261 /* CPUID workaround for Intel 0F34 CPU */
1262 if (c->x86_vendor == X86_VENDOR_INTEL &&
1263 c->x86 == 0xF && c->x86_model == 0x3 &&
1264 c->x86_mask == 0x4)
1265 c->x86_phys_bits = 36;
1268 if (c->x86 == 15)
1269 c->x86_cache_alignment = c->x86_clflush_size * 2;
1270 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
1271 (c->x86 == 0x6 && c->x86_model >= 0x0e))
1272 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1273 set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
1274 c->x86_max_cores = intel_num_cpu_cores(c);
1276 srat_detect_node();
1279 static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
1281 char *v = c->x86_vendor_id;
1283 if (!strcmp(v, "AuthenticAMD"))
1284 c->x86_vendor = X86_VENDOR_AMD;
1285 else if (!strcmp(v, "GenuineIntel"))
1286 c->x86_vendor = X86_VENDOR_INTEL;
1287 else
1288 c->x86_vendor = X86_VENDOR_UNKNOWN;
1291 struct cpu_model_info {
1292 int vendor;
1293 int family;
1294 char *model_names[16];
1295 };
1297 /* Do some early cpuid on the boot CPU to get some parameter that are
1298 needed before check_bugs. Everything advanced is in identify_cpu
1299 below. */
1300 void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
1302 u32 tfms;
1304 c->loops_per_jiffy = loops_per_jiffy;
1305 c->x86_cache_size = -1;
1306 c->x86_vendor = X86_VENDOR_UNKNOWN;
1307 c->x86_model = c->x86_mask = 0; /* So far unknown... */
1308 c->x86_vendor_id[0] = '\0'; /* Unset */
1309 c->x86_model_id[0] = '\0'; /* Unset */
1310 c->x86_clflush_size = 64;
1311 c->x86_cache_alignment = c->x86_clflush_size;
1312 c->x86_max_cores = 1;
1313 c->extended_cpuid_level = 0;
1314 memset(&c->x86_capability, 0, sizeof c->x86_capability);
1316 /* Get vendor name */
1317 cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
1318 (unsigned int *)&c->x86_vendor_id[0],
1319 (unsigned int *)&c->x86_vendor_id[8],
1320 (unsigned int *)&c->x86_vendor_id[4]);
1322 get_cpu_vendor(c);
1324 /* Initialize the standard set of capabilities */
1325 /* Note that the vendor-specific code below might override */
1327 /* Intel-defined flags: level 0x00000001 */
1328 if (c->cpuid_level >= 0x00000001) {
1329 __u32 misc;
1330 cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
1331 &c->x86_capability[0]);
1332 c->x86 = (tfms >> 8) & 0xf;
1333 c->x86_model = (tfms >> 4) & 0xf;
1334 c->x86_mask = tfms & 0xf;
1335 if (c->x86 == 0xf)
1336 c->x86 += (tfms >> 20) & 0xff;
1337 if (c->x86 >= 0x6)
1338 c->x86_model += ((tfms >> 16) & 0xF) << 4;
1339 if (c->x86_capability[0] & (1<<19))
1340 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
1341 } else {
1342 /* Have CPUID level 0 only - unheard of */
1343 c->x86 = 4;
1346 #ifdef CONFIG_SMP
1347 c->phys_proc_id = (cpuid_ebx(1) >> 24) & 0xff;
1348 #endif
1351 /*
1352 * This does the hard work of actually picking apart the CPU stuff...
1353 */
1354 void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
1356 int i;
1357 u32 xlvl;
1359 early_identify_cpu(c);
1361 /* AMD-defined flags: level 0x80000001 */
1362 xlvl = cpuid_eax(0x80000000);
1363 c->extended_cpuid_level = xlvl;
1364 if ((xlvl & 0xffff0000) == 0x80000000) {
1365 if (xlvl >= 0x80000001) {
1366 c->x86_capability[1] = cpuid_edx(0x80000001);
1367 c->x86_capability[6] = cpuid_ecx(0x80000001);
1369 if (xlvl >= 0x80000004)
1370 get_model_name(c); /* Default name */
1373 /* Transmeta-defined flags: level 0x80860001 */
1374 xlvl = cpuid_eax(0x80860000);
1375 if ((xlvl & 0xffff0000) == 0x80860000) {
1376 /* Don't set x86_cpuid_level here for now to not confuse. */
1377 if (xlvl >= 0x80860001)
1378 c->x86_capability[2] = cpuid_edx(0x80860001);
1381 c->apicid = phys_pkg_id(0);
1383 /*
1384 * Vendor-specific initialization. In this section we
1385 * canonicalize the feature flags, meaning if there are
1386 * features a certain CPU supports which CPUID doesn't
1387 * tell us, CPUID claiming incorrect flags, or other bugs,
1388 * we handle them here.
1390 * At the end of this section, c->x86_capability better
1391 * indicate the features this CPU genuinely supports!
1392 */
1393 switch (c->x86_vendor) {
1394 case X86_VENDOR_AMD:
1395 init_amd(c);
1396 break;
1398 case X86_VENDOR_INTEL:
1399 init_intel(c);
1400 break;
1402 case X86_VENDOR_UNKNOWN:
1403 default:
1404 display_cacheinfo(c);
1405 break;
1408 select_idle_routine(c);
1409 detect_ht(c);
1411 /*
1412 * On SMP, boot_cpu_data holds the common feature set between
1413 * all CPUs; so make sure that we indicate which features are
1414 * common between the CPUs. The first time this routine gets
1415 * executed, c == &boot_cpu_data.
1416 */
1417 if (c != &boot_cpu_data) {
1418 /* AND the already accumulated flags with these */
1419 for (i = 0 ; i < NCAPINTS ; i++)
1420 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
1423 #ifdef CONFIG_X86_MCE
1424 mcheck_init(c);
1425 #endif
1426 if (c == &boot_cpu_data)
1427 mtrr_bp_init();
1428 else
1429 mtrr_ap_init();
1430 #ifdef CONFIG_NUMA
1431 numa_add_cpu(smp_processor_id());
1432 #endif
1436 void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
1438 if (c->x86_model_id[0])
1439 printk("%s", c->x86_model_id);
1441 if (c->x86_mask || c->cpuid_level >= 0)
1442 printk(" stepping %02x\n", c->x86_mask);
1443 else
1444 printk("\n");
1447 /*
1448 * Get CPU information for use by the procfs.
1449 */
1451 static int show_cpuinfo(struct seq_file *m, void *v)
1453 struct cpuinfo_x86 *c = v;
1455 /*
1456 * These flag bits must match the definitions in <asm/cpufeature.h>.
1457 * NULL means this bit is undefined or reserved; either way it doesn't
1458 * have meaning as far as Linux is concerned. Note that it's important
1459 * to realize there is a difference between this table and CPUID -- if
1460 * applications want to get the raw CPUID data, they should access
1461 * /dev/cpu/<cpu_nr>/cpuid instead.
1462 */
1463 static char *x86_cap_flags[] = {
1464 /* Intel-defined */
1465 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
1466 "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
1467 "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
1468 "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
1470 /* AMD-defined */
1471 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1472 NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
1473 NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
1474 NULL, "fxsr_opt", NULL, "rdtscp", NULL, "lm", "3dnowext", "3dnow",
1476 /* Transmeta-defined */
1477 "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
1478 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1479 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1480 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1482 /* Other (Linux-defined) */
1483 "cxmmx", NULL, "cyrix_arr", "centaur_mcr", NULL,
1484 "constant_tsc", NULL, NULL,
1485 "up", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1486 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1487 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1489 /* Intel-defined (#2) */
1490 "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
1491 "tm2", NULL, "cid", NULL, NULL, "cx16", "xtpr", NULL,
1492 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1493 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1495 /* VIA/Cyrix/Centaur-defined */
1496 NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
1497 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1498 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1499 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1501 /* AMD-defined (#2) */
1502 "lahf_lm", "cmp_legacy", "svm", NULL, "cr8_legacy", NULL, NULL, NULL,
1503 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1504 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1505 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1506 };
1507 static char *x86_power_flags[] = {
1508 "ts", /* temperature sensor */
1509 "fid", /* frequency id control */
1510 "vid", /* voltage id control */
1511 "ttp", /* thermal trip */
1512 "tm",
1513 "stc",
1514 NULL,
1515 /* nothing */ /* constant_tsc - moved to flags */
1516 };
1519 #ifdef CONFIG_SMP
1520 if (!cpu_online(c-cpu_data))
1521 return 0;
1522 #endif
1524 seq_printf(m,"processor\t: %u\n"
1525 "vendor_id\t: %s\n"
1526 "cpu family\t: %d\n"
1527 "model\t\t: %d\n"
1528 "model name\t: %s\n",
1529 (unsigned)(c-cpu_data),
1530 c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
1531 c->x86,
1532 (int)c->x86_model,
1533 c->x86_model_id[0] ? c->x86_model_id : "unknown");
1535 if (c->x86_mask || c->cpuid_level >= 0)
1536 seq_printf(m, "stepping\t: %d\n", c->x86_mask);
1537 else
1538 seq_printf(m, "stepping\t: unknown\n");
1540 if (cpu_has(c,X86_FEATURE_TSC)) {
1541 unsigned int freq = cpufreq_quick_get((unsigned)(c-cpu_data));
1542 if (!freq)
1543 freq = cpu_khz;
1544 seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
1545 freq / 1000, (freq % 1000));
1548 /* Cache size */
1549 if (c->x86_cache_size >= 0)
1550 seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
1552 #ifdef CONFIG_SMP
1553 if (smp_num_siblings * c->x86_max_cores > 1) {
1554 int cpu = c - cpu_data;
1555 seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
1556 seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[cpu]));
1557 seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
1558 seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
1560 #endif
1562 seq_printf(m,
1563 "fpu\t\t: yes\n"
1564 "fpu_exception\t: yes\n"
1565 "cpuid level\t: %d\n"
1566 "wp\t\t: yes\n"
1567 "flags\t\t:",
1568 c->cpuid_level);
1571 int i;
1572 for ( i = 0 ; i < 32*NCAPINTS ; i++ )
1573 if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
1574 seq_printf(m, " %s", x86_cap_flags[i]);
1577 seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
1578 c->loops_per_jiffy/(500000/HZ),
1579 (c->loops_per_jiffy/(5000/HZ)) % 100);
1581 if (c->x86_tlbsize > 0)
1582 seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
1583 seq_printf(m, "clflush size\t: %d\n", c->x86_clflush_size);
1584 seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
1586 seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
1587 c->x86_phys_bits, c->x86_virt_bits);
1589 seq_printf(m, "power management:");
1591 unsigned i;
1592 for (i = 0; i < 32; i++)
1593 if (c->x86_power & (1 << i)) {
1594 if (i < ARRAY_SIZE(x86_power_flags) &&
1595 x86_power_flags[i])
1596 seq_printf(m, "%s%s",
1597 x86_power_flags[i][0]?" ":"",
1598 x86_power_flags[i]);
1599 else
1600 seq_printf(m, " [%d]", i);
1604 seq_printf(m, "\n\n");
1606 return 0;
1609 static void *c_start(struct seq_file *m, loff_t *pos)
1611 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
1614 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1616 ++*pos;
1617 return c_start(m, pos);
1620 static void c_stop(struct seq_file *m, void *v)
1624 struct seq_operations cpuinfo_op = {
1625 .start =c_start,
1626 .next = c_next,
1627 .stop = c_stop,
1628 .show = show_cpuinfo,
1629 };
1631 static int __init run_dmi_scan(void)
1633 dmi_scan_machine();
1634 return 0;
1636 core_initcall(run_dmi_scan);
1638 #if defined(CONFIG_INPUT_PCSPKR) || defined(CONFIG_INPUT_PCSPKR_MODULE)
1639 #include <linux/platform_device.h>
1640 static __init int add_pcspkr(void)
1642 struct platform_device *pd;
1643 int ret;
1645 pd = platform_device_alloc("pcspkr", -1);
1646 if (!pd)
1647 return -ENOMEM;
1649 ret = platform_device_add(pd);
1650 if (ret)
1651 platform_device_put(pd);
1653 return ret;
1655 device_initcall(add_pcspkr);
1656 #endif