ia64/xen-unstable

view linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c @ 14671:4a873ab4e261

[LINUX] Make sure to initialiase the xen features bitmap before first use on x86_64.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Fri Mar 30 14:13:53 2007 +0100 (2007-03-30)
parents 5dfad62b7a70
children 297d98f057e8
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 static int xen_panic_event(struct notifier_block *, unsigned long, void *);
94 static struct notifier_block xen_panic_block = {
95 xen_panic_event, NULL, 0 /* try to go last */
96 };
98 unsigned long *phys_to_machine_mapping;
99 unsigned long *pfn_to_mfn_frame_list_list, *pfn_to_mfn_frame_list[512];
101 EXPORT_SYMBOL(phys_to_machine_mapping);
103 DEFINE_PER_CPU(multicall_entry_t, multicall_list[8]);
104 DEFINE_PER_CPU(int, nr_multicall_ents);
106 /* Raw start-of-day parameters from the hypervisor. */
107 start_info_t *xen_start_info;
108 EXPORT_SYMBOL(xen_start_info);
109 #endif
111 /*
112 * Machine setup..
113 */
115 struct cpuinfo_x86 boot_cpu_data __read_mostly;
116 EXPORT_SYMBOL(boot_cpu_data);
118 unsigned long mmu_cr4_features;
120 int acpi_disabled;
121 EXPORT_SYMBOL(acpi_disabled);
122 #ifdef CONFIG_ACPI
123 extern int __initdata acpi_ht;
124 extern acpi_interrupt_flags acpi_sci_flags;
125 int __initdata acpi_force = 0;
126 #endif
128 int acpi_numa __initdata;
130 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
131 int bootloader_type;
133 unsigned long saved_video_mode;
135 /*
136 * Early DMI memory
137 */
138 int dmi_alloc_index;
139 char dmi_alloc_data[DMI_MAX_DATA];
141 /*
142 * Setup options
143 */
144 struct screen_info screen_info;
145 EXPORT_SYMBOL(screen_info);
146 struct sys_desc_table_struct {
147 unsigned short length;
148 unsigned char table[0];
149 };
151 struct edid_info edid_info;
152 EXPORT_SYMBOL_GPL(edid_info);
153 struct e820map e820;
154 #ifdef CONFIG_XEN
155 struct e820map machine_e820;
156 #endif
158 extern int root_mountflags;
160 char command_line[COMMAND_LINE_SIZE];
162 struct resource standard_io_resources[] = {
163 { .name = "dma1", .start = 0x00, .end = 0x1f,
164 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
165 { .name = "pic1", .start = 0x20, .end = 0x21,
166 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
167 { .name = "timer0", .start = 0x40, .end = 0x43,
168 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
169 { .name = "timer1", .start = 0x50, .end = 0x53,
170 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
171 { .name = "keyboard", .start = 0x60, .end = 0x6f,
172 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
173 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
174 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
175 { .name = "pic2", .start = 0xa0, .end = 0xa1,
176 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
177 { .name = "dma2", .start = 0xc0, .end = 0xdf,
178 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
179 { .name = "fpu", .start = 0xf0, .end = 0xff,
180 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
181 };
183 #define STANDARD_IO_RESOURCES \
184 (sizeof standard_io_resources / sizeof standard_io_resources[0])
186 #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
188 struct resource data_resource = {
189 .name = "Kernel data",
190 .start = 0,
191 .end = 0,
192 .flags = IORESOURCE_RAM,
193 };
194 struct resource code_resource = {
195 .name = "Kernel code",
196 .start = 0,
197 .end = 0,
198 .flags = IORESOURCE_RAM,
199 };
201 #define IORESOURCE_ROM (IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM)
203 static struct resource system_rom_resource = {
204 .name = "System ROM",
205 .start = 0xf0000,
206 .end = 0xfffff,
207 .flags = IORESOURCE_ROM,
208 };
210 static struct resource extension_rom_resource = {
211 .name = "Extension ROM",
212 .start = 0xe0000,
213 .end = 0xeffff,
214 .flags = IORESOURCE_ROM,
215 };
217 static struct resource adapter_rom_resources[] = {
218 { .name = "Adapter ROM", .start = 0xc8000, .end = 0,
219 .flags = IORESOURCE_ROM },
220 { .name = "Adapter ROM", .start = 0, .end = 0,
221 .flags = IORESOURCE_ROM },
222 { .name = "Adapter ROM", .start = 0, .end = 0,
223 .flags = IORESOURCE_ROM },
224 { .name = "Adapter ROM", .start = 0, .end = 0,
225 .flags = IORESOURCE_ROM },
226 { .name = "Adapter ROM", .start = 0, .end = 0,
227 .flags = IORESOURCE_ROM },
228 { .name = "Adapter ROM", .start = 0, .end = 0,
229 .flags = IORESOURCE_ROM }
230 };
232 #define ADAPTER_ROM_RESOURCES \
233 (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
235 static struct resource video_rom_resource = {
236 .name = "Video ROM",
237 .start = 0xc0000,
238 .end = 0xc7fff,
239 .flags = IORESOURCE_ROM,
240 };
242 static struct resource video_ram_resource = {
243 .name = "Video RAM area",
244 .start = 0xa0000,
245 .end = 0xbffff,
246 .flags = IORESOURCE_RAM,
247 };
249 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
251 static int __init romchecksum(unsigned char *rom, unsigned long length)
252 {
253 unsigned char *p, sum = 0;
255 for (p = rom; p < rom + length; p++)
256 sum += *p;
257 return sum == 0;
258 }
260 static void __init probe_roms(void)
261 {
262 unsigned long start, length, upper;
263 unsigned char *rom;
264 int i;
266 #ifdef CONFIG_XEN
267 /* Nothing to do if not running in dom0. */
268 if (!is_initial_xendomain())
269 return;
270 #endif
272 /* video rom */
273 upper = adapter_rom_resources[0].start;
274 for (start = video_rom_resource.start; start < upper; start += 2048) {
275 rom = isa_bus_to_virt(start);
276 if (!romsignature(rom))
277 continue;
279 video_rom_resource.start = start;
281 /* 0 < length <= 0x7f * 512, historically */
282 length = rom[2] * 512;
284 /* if checksum okay, trust length byte */
285 if (length && romchecksum(rom, length))
286 video_rom_resource.end = start + length - 1;
288 request_resource(&iomem_resource, &video_rom_resource);
289 break;
290 }
292 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
293 if (start < upper)
294 start = upper;
296 /* system rom */
297 request_resource(&iomem_resource, &system_rom_resource);
298 upper = system_rom_resource.start;
300 /* check for extension rom (ignore length byte!) */
301 rom = isa_bus_to_virt(extension_rom_resource.start);
302 if (romsignature(rom)) {
303 length = extension_rom_resource.end - extension_rom_resource.start + 1;
304 if (romchecksum(rom, length)) {
305 request_resource(&iomem_resource, &extension_rom_resource);
306 upper = extension_rom_resource.start;
307 }
308 }
310 /* check for adapter roms on 2k boundaries */
311 for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
312 rom = isa_bus_to_virt(start);
313 if (!romsignature(rom))
314 continue;
316 /* 0 < length <= 0x7f * 512, historically */
317 length = rom[2] * 512;
319 /* but accept any length that fits if checksum okay */
320 if (!length || start + length > upper || !romchecksum(rom, length))
321 continue;
323 adapter_rom_resources[i].start = start;
324 adapter_rom_resources[i].end = start + length - 1;
325 request_resource(&iomem_resource, &adapter_rom_resources[i]);
327 start = adapter_rom_resources[i++].end & ~2047UL;
328 }
329 }
331 /* Check for full argument with no trailing characters */
332 static int fullarg(char *p, char *arg)
333 {
334 int l = strlen(arg);
335 return !memcmp(p, arg, l) && (p[l] == 0 || isspace(p[l]));
336 }
338 static __init void parse_cmdline_early (char ** cmdline_p)
339 {
340 char c = ' ', *to = command_line, *from = COMMAND_LINE;
341 int len = 0;
342 int userdef = 0;
344 for (;;) {
345 if (c != ' ')
346 goto next_char;
348 #ifdef CONFIG_SMP
349 /*
350 * If the BIOS enumerates physical processors before logical,
351 * maxcpus=N at enumeration-time can be used to disable HT.
352 */
353 else if (!memcmp(from, "maxcpus=", 8)) {
354 extern unsigned int maxcpus;
356 maxcpus = simple_strtoul(from + 8, NULL, 0);
357 }
358 #endif
359 #ifdef CONFIG_ACPI
360 /* "acpi=off" disables both ACPI table parsing and interpreter init */
361 if (fullarg(from,"acpi=off"))
362 disable_acpi();
364 if (fullarg(from, "acpi=force")) {
365 /* add later when we do DMI horrors: */
366 acpi_force = 1;
367 acpi_disabled = 0;
368 }
370 /* acpi=ht just means: do ACPI MADT parsing
371 at bootup, but don't enable the full ACPI interpreter */
372 if (fullarg(from, "acpi=ht")) {
373 if (!acpi_force)
374 disable_acpi();
375 acpi_ht = 1;
376 }
377 else if (fullarg(from, "pci=noacpi"))
378 acpi_disable_pci();
379 else if (fullarg(from, "acpi=noirq"))
380 acpi_noirq_set();
382 else if (fullarg(from, "acpi_sci=edge"))
383 acpi_sci_flags.trigger = 1;
384 else if (fullarg(from, "acpi_sci=level"))
385 acpi_sci_flags.trigger = 3;
386 else if (fullarg(from, "acpi_sci=high"))
387 acpi_sci_flags.polarity = 1;
388 else if (fullarg(from, "acpi_sci=low"))
389 acpi_sci_flags.polarity = 3;
391 /* acpi=strict disables out-of-spec workarounds */
392 else if (fullarg(from, "acpi=strict")) {
393 acpi_strict = 1;
394 }
395 #ifdef CONFIG_X86_IO_APIC
396 else if (fullarg(from, "acpi_skip_timer_override"))
397 acpi_skip_timer_override = 1;
398 #endif
399 #endif
401 #ifndef CONFIG_XEN
402 if (fullarg(from, "nolapic") || fullarg(from, "disableapic")) {
403 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
404 disable_apic = 1;
405 }
407 if (fullarg(from, "noapic"))
408 skip_ioapic_setup = 1;
410 if (fullarg(from,"apic")) {
411 skip_ioapic_setup = 0;
412 ioapic_force = 1;
413 }
414 #endif
416 if (!memcmp(from, "mem=", 4))
417 parse_memopt(from+4, &from);
419 if (!memcmp(from, "memmap=", 7)) {
420 /* exactmap option is for used defined memory */
421 if (!memcmp(from+7, "exactmap", 8)) {
422 #ifdef CONFIG_CRASH_DUMP
423 /* If we are doing a crash dump, we
424 * still need to know the real mem
425 * size before original memory map is
426 * reset.
427 */
428 saved_max_pfn = e820_end_of_ram();
429 #endif
430 from += 8+7;
431 end_pfn_map = 0;
432 e820.nr_map = 0;
433 userdef = 1;
434 }
435 else {
436 parse_memmapopt(from+7, &from);
437 userdef = 1;
438 }
439 }
441 #ifdef CONFIG_NUMA
442 if (!memcmp(from, "numa=", 5))
443 numa_setup(from+5);
444 #endif
446 if (!memcmp(from,"iommu=",6)) {
447 iommu_setup(from+6);
448 }
450 if (fullarg(from,"oops=panic"))
451 panic_on_oops = 1;
453 if (!memcmp(from, "noexec=", 7))
454 nonx_setup(from + 7);
456 #ifdef CONFIG_KEXEC
457 /* crashkernel=size@addr specifies the location to reserve for
458 * a crash kernel. By reserving this memory we guarantee
459 * that linux never set's it up as a DMA target.
460 * Useful for holding code to do something appropriate
461 * after a kernel panic.
462 */
463 else if (!memcmp(from, "crashkernel=", 12)) {
464 #ifndef CONFIG_XEN
465 unsigned long size, base;
466 size = memparse(from+12, &from);
467 if (*from == '@') {
468 base = memparse(from+1, &from);
469 /* FIXME: Do I want a sanity check
470 * to validate the memory range?
471 */
472 crashk_res.start = base;
473 crashk_res.end = base + size - 1;
474 }
475 #else
476 printk("Ignoring crashkernel command line, "
477 "parameter will be supplied by xen\n");
478 #endif
479 }
480 #endif
482 #ifdef CONFIG_PROC_VMCORE
483 /* elfcorehdr= specifies the location of elf core header
484 * stored by the crashed kernel. This option will be passed
485 * by kexec loader to the capture kernel.
486 */
487 else if(!memcmp(from, "elfcorehdr=", 11))
488 elfcorehdr_addr = memparse(from+11, &from);
489 #endif
491 #if defined(CONFIG_HOTPLUG_CPU) && !defined(CONFIG_XEN)
492 else if (!memcmp(from, "additional_cpus=", 16))
493 setup_additional_cpus(from+16);
494 #endif
496 next_char:
497 c = *(from++);
498 if (!c)
499 break;
500 if (COMMAND_LINE_SIZE <= ++len)
501 break;
502 *(to++) = c;
503 }
504 if (userdef) {
505 printk(KERN_INFO "user-defined physical RAM map:\n");
506 e820_print_map("user");
507 }
508 *to = '\0';
509 *cmdline_p = command_line;
510 }
512 #ifndef CONFIG_NUMA
513 static void __init
514 contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
515 {
516 unsigned long bootmap_size, bootmap;
518 bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
519 bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
520 if (bootmap == -1L)
521 panic("Cannot find bootmem map of size %ld\n",bootmap_size);
522 bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
523 #ifdef CONFIG_XEN
524 e820_bootmem_free(NODE_DATA(0), 0, xen_start_info->nr_pages<<PAGE_SHIFT);
525 #else
526 e820_bootmem_free(NODE_DATA(0), 0, end_pfn << PAGE_SHIFT);
527 #endif
528 reserve_bootmem(bootmap, bootmap_size);
529 }
530 #endif
532 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
533 struct edd edd;
534 #ifdef CONFIG_EDD_MODULE
535 EXPORT_SYMBOL(edd);
536 #endif
537 /**
538 * copy_edd() - Copy the BIOS EDD information
539 * from boot_params into a safe place.
540 *
541 */
542 static inline void copy_edd(void)
543 {
544 memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
545 memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
546 edd.mbr_signature_nr = EDD_MBR_SIG_NR;
547 edd.edd_info_nr = EDD_NR;
548 }
549 #else
550 static inline void copy_edd(void)
551 {
552 }
553 #endif
555 #ifndef CONFIG_XEN
556 #define EBDA_ADDR_POINTER 0x40E
558 unsigned __initdata ebda_addr;
559 unsigned __initdata ebda_size;
561 static void discover_ebda(void)
562 {
563 /*
564 * there is a real-mode segmented pointer pointing to the
565 * 4K EBDA area at 0x40E
566 */
567 ebda_addr = *(unsigned short *)EBDA_ADDR_POINTER;
568 ebda_addr <<= 4;
570 ebda_size = *(unsigned short *)(unsigned long)ebda_addr;
572 /* Round EBDA up to pages */
573 if (ebda_size == 0)
574 ebda_size = 1;
575 ebda_size <<= 10;
576 ebda_size = round_up(ebda_size + (ebda_addr & ~PAGE_MASK), PAGE_SIZE);
577 if (ebda_size > 64*1024)
578 ebda_size = 64*1024;
579 }
580 #else
581 #define discover_ebda() ((void)0)
582 #endif
584 void __init setup_arch(char **cmdline_p)
585 {
586 #ifdef CONFIG_XEN
587 /* Register a call for panic conditions. */
588 atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
590 ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
591 screen_info = SCREEN_INFO;
593 if (is_initial_xendomain()) {
594 /* This is drawn from a dump from vgacon:startup in
595 * standard Linux. */
596 screen_info.orig_video_mode = 3;
597 screen_info.orig_video_isVGA = 1;
598 screen_info.orig_video_lines = 25;
599 screen_info.orig_video_cols = 80;
600 screen_info.orig_video_ega_bx = 3;
601 screen_info.orig_video_points = 16;
602 screen_info.orig_y = screen_info.orig_video_lines - 1;
603 if (xen_start_info->console.dom0.info_size >=
604 sizeof(struct dom0_vga_console_info)) {
605 const struct dom0_vga_console_info *info =
606 (struct dom0_vga_console_info *)(
607 (char *)xen_start_info +
608 xen_start_info->console.dom0.info_off);
609 dom0_init_screen_info(info);
610 }
611 xen_start_info->console.domU.mfn = 0;
612 xen_start_info->console.domU.evtchn = 0;
613 } else
614 screen_info.orig_video_isVGA = 0;
616 edid_info = EDID_INFO;
617 saved_video_mode = SAVED_VIDEO_MODE;
618 bootloader_type = LOADER_TYPE;
620 #ifdef CONFIG_BLK_DEV_RAM
621 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
622 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
623 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
626 #endif
628 HYPERVISOR_vm_assist(VMASST_CMD_enable,
629 VMASST_TYPE_writable_pagetables);
631 ARCH_SETUP
632 #else
633 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
634 screen_info = SCREEN_INFO;
635 edid_info = EDID_INFO;
636 saved_video_mode = SAVED_VIDEO_MODE;
637 bootloader_type = LOADER_TYPE;
639 #ifdef CONFIG_BLK_DEV_RAM
640 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
641 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
642 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
643 #endif
644 #endif /* !CONFIG_XEN */
645 setup_memory_region();
646 copy_edd();
648 if (!MOUNT_ROOT_RDONLY)
649 root_mountflags &= ~MS_RDONLY;
650 init_mm.start_code = (unsigned long) &_text;
651 init_mm.end_code = (unsigned long) &_etext;
652 init_mm.end_data = (unsigned long) &_edata;
653 init_mm.brk = (unsigned long) &_end;
655 code_resource.start = virt_to_phys(&_text);
656 code_resource.end = virt_to_phys(&_etext)-1;
657 data_resource.start = virt_to_phys(&_etext);
658 data_resource.end = virt_to_phys(&_edata)-1;
660 parse_cmdline_early(cmdline_p);
662 early_identify_cpu(&boot_cpu_data);
664 /*
665 * partially used pages are not usable - thus
666 * we are rounding upwards:
667 */
668 end_pfn = e820_end_of_ram();
669 num_physpages = end_pfn; /* for pfn_valid */
671 check_efer();
673 discover_ebda();
675 init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
677 if (is_initial_xendomain())
678 dmi_scan_machine();
680 #ifdef CONFIG_ACPI_NUMA
681 /*
682 * Parse SRAT to discover nodes.
683 */
684 acpi_numa_init();
685 #endif
687 #ifdef CONFIG_NUMA
688 numa_initmem_init(0, end_pfn);
689 #else
690 contig_initmem_init(0, end_pfn);
691 #endif
693 #ifdef CONFIG_XEN
694 /*
695 * Reserve kernel, physmap, start info, initial page tables, and
696 * direct mapping.
697 */
698 reserve_bootmem_generic(__pa_symbol(&_text),
699 (table_end << PAGE_SHIFT) - __pa_symbol(&_text));
700 #else
701 /* Reserve direct mapping */
702 reserve_bootmem_generic(table_start << PAGE_SHIFT,
703 (table_end - table_start) << PAGE_SHIFT);
705 /* reserve kernel */
706 reserve_bootmem_generic(__pa_symbol(&_text),
707 __pa_symbol(&_end) - __pa_symbol(&_text));
709 /*
710 * reserve physical page 0 - it's a special BIOS page on many boxes,
711 * enabling clean reboots, SMP operation, laptop functions.
712 */
713 reserve_bootmem_generic(0, PAGE_SIZE);
715 /* reserve ebda region */
716 if (ebda_addr)
717 reserve_bootmem_generic(ebda_addr, ebda_size);
719 #ifdef CONFIG_SMP
720 /*
721 * But first pinch a few for the stack/trampoline stuff
722 * FIXME: Don't need the extra page at 4K, but need to fix
723 * trampoline before removing it. (see the GDT stuff)
724 */
725 reserve_bootmem_generic(PAGE_SIZE, PAGE_SIZE);
727 /* Reserve SMP trampoline */
728 reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, PAGE_SIZE);
729 #endif
730 #endif
732 #ifdef CONFIG_ACPI_SLEEP
733 /*
734 * Reserve low memory region for sleep support.
735 */
736 acpi_reserve_bootmem();
737 #endif
738 #ifdef CONFIG_XEN
739 #ifdef CONFIG_BLK_DEV_INITRD
740 if (xen_start_info->mod_start) {
741 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
742 /*reserve_bootmem_generic(INITRD_START, INITRD_SIZE);*/
743 initrd_start = INITRD_START + PAGE_OFFSET;
744 initrd_end = initrd_start+INITRD_SIZE;
745 initrd_below_start_ok = 1;
746 } else {
747 printk(KERN_ERR "initrd extends beyond end of memory "
748 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
749 (unsigned long)(INITRD_START + INITRD_SIZE),
750 (unsigned long)(end_pfn << PAGE_SHIFT));
751 initrd_start = 0;
752 }
753 }
754 #endif
755 #else /* CONFIG_XEN */
756 #ifdef CONFIG_BLK_DEV_INITRD
757 if (LOADER_TYPE && INITRD_START) {
758 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
759 reserve_bootmem_generic(INITRD_START, INITRD_SIZE);
760 initrd_start =
761 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
762 initrd_end = initrd_start+INITRD_SIZE;
763 }
764 else {
765 printk(KERN_ERR "initrd extends beyond end of memory "
766 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
767 (unsigned long)(INITRD_START + INITRD_SIZE),
768 (unsigned long)(end_pfn << PAGE_SHIFT));
769 initrd_start = 0;
770 }
771 }
772 #endif
773 #endif /* !CONFIG_XEN */
774 #ifdef CONFIG_KEXEC
775 #ifdef CONFIG_XEN
776 xen_machine_kexec_setup_resources();
777 #else
778 if (crashk_res.start != crashk_res.end) {
779 reserve_bootmem_generic(crashk_res.start,
780 crashk_res.end - crashk_res.start + 1);
781 }
782 #endif
783 #endif
785 paging_init();
786 #ifdef CONFIG_X86_LOCAL_APIC
787 /*
788 * Find and reserve possible boot-time SMP configuration:
789 */
790 find_smp_config();
791 #endif
792 #ifdef CONFIG_XEN
793 {
794 int i, j, k, fpp;
796 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
797 /* Make sure we have a large enough P->M table. */
798 phys_to_machine_mapping = alloc_bootmem_pages(
799 end_pfn * sizeof(unsigned long));
800 memset(phys_to_machine_mapping, ~0,
801 end_pfn * sizeof(unsigned long));
802 memcpy(phys_to_machine_mapping,
803 (unsigned long *)xen_start_info->mfn_list,
804 xen_start_info->nr_pages * sizeof(unsigned long));
805 free_bootmem(
806 __pa(xen_start_info->mfn_list),
807 PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
808 sizeof(unsigned long))));
810 /*
811 * Initialise the list of the frames that specify the
812 * list of frames that make up the p2m table. Used by
813 * save/restore.
814 */
815 pfn_to_mfn_frame_list_list = alloc_bootmem_pages(PAGE_SIZE);
817 fpp = PAGE_SIZE/sizeof(unsigned long);
818 for (i=0, j=0, k=-1; i< end_pfn; i+=fpp, j++) {
819 if ((j % fpp) == 0) {
820 k++;
821 BUG_ON(k>=fpp);
822 pfn_to_mfn_frame_list[k] =
823 alloc_bootmem_pages(PAGE_SIZE);
824 pfn_to_mfn_frame_list_list[k] =
825 virt_to_mfn(pfn_to_mfn_frame_list[k]);
826 j=0;
827 }
828 pfn_to_mfn_frame_list[k][j] =
829 virt_to_mfn(&phys_to_machine_mapping[i]);
830 }
831 HYPERVISOR_shared_info->arch.max_pfn = end_pfn;
832 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
833 virt_to_mfn(pfn_to_mfn_frame_list_list);
834 }
836 }
838 if (!is_initial_xendomain()) {
839 acpi_disabled = 1;
840 #ifdef CONFIG_ACPI
841 acpi_ht = 0;
842 #endif
843 }
844 #endif
846 #ifndef CONFIG_XEN
847 check_ioapic();
848 #endif
850 zap_low_mappings(0);
852 /*
853 * set this early, so we dont allocate cpu0
854 * if MADT list doesnt list BSP first
855 * mpparse.c/MP_processor_info() allocates logical cpu numbers.
856 */
857 cpu_set(0, cpu_present_map);
858 #ifdef CONFIG_ACPI
859 /*
860 * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
861 * Call this early for SRAT node setup.
862 */
863 acpi_boot_table_init();
865 /*
866 * Read APIC and some other early information from ACPI tables.
867 */
868 acpi_boot_init();
869 #endif
871 init_cpu_to_node();
873 #ifdef CONFIG_X86_LOCAL_APIC
874 /*
875 * get boot-time SMP configuration:
876 */
877 if (smp_found_config)
878 get_smp_config();
879 #ifndef CONFIG_XEN
880 init_apic_mappings();
881 #endif
882 #endif
883 #if defined(CONFIG_XEN) && defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU)
884 prefill_possible_map();
885 #endif
887 /*
888 * Request address space for all standard RAM and ROM resources
889 * and also for regions reported as reserved by the e820.
890 */
891 probe_roms();
892 #ifdef CONFIG_XEN
893 if (is_initial_xendomain()) {
894 struct xen_memory_map memmap;
896 memmap.nr_entries = E820MAX;
897 set_xen_guest_handle(memmap.buffer, machine_e820.map);
899 if (HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap))
900 BUG();
901 machine_e820.nr_map = memmap.nr_entries;
903 e820_reserve_resources(machine_e820.map, machine_e820.nr_map);
904 }
905 #else
906 e820_reserve_resources(e820.map, e820.nr_map);
907 #endif
909 request_resource(&iomem_resource, &video_ram_resource);
911 {
912 unsigned i;
913 /* request I/O space for devices used on all i[345]86 PCs */
914 for (i = 0; i < STANDARD_IO_RESOURCES; i++)
915 request_resource(&ioport_resource, &standard_io_resources[i]);
916 }
918 #ifdef CONFIG_XEN
919 if (is_initial_xendomain())
920 e820_setup_gap(machine_e820.map, machine_e820.nr_map);
921 #else
922 e820_setup_gap(e820.map, e820.nr_map);
923 #endif
925 #ifdef CONFIG_XEN
926 {
927 struct physdev_set_iopl set_iopl;
929 set_iopl.iopl = 1;
930 HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
932 if (is_initial_xendomain()) {
933 #ifdef CONFIG_VT
934 #if defined(CONFIG_VGA_CONSOLE)
935 conswitchp = &vga_con;
936 #elif defined(CONFIG_DUMMY_CONSOLE)
937 conswitchp = &dummy_con;
938 #endif
939 #endif
940 } else {
941 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
942 conswitchp = &dummy_con;
943 #endif
944 }
945 }
946 xencons_early_setup();
947 #else /* CONFIG_XEN */
949 #ifdef CONFIG_VT
950 #if defined(CONFIG_VGA_CONSOLE)
951 conswitchp = &vga_con;
952 #elif defined(CONFIG_DUMMY_CONSOLE)
953 conswitchp = &dummy_con;
954 #endif
955 #endif
957 #endif /* !CONFIG_XEN */
958 }
960 #ifdef CONFIG_XEN
961 static int
962 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
963 {
964 HYPERVISOR_shutdown(SHUTDOWN_crash);
965 /* we're never actually going to get here... */
966 return NOTIFY_DONE;
967 }
968 #endif /* !CONFIG_XEN */
971 static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
972 {
973 unsigned int *v;
975 if (c->extended_cpuid_level < 0x80000004)
976 return 0;
978 v = (unsigned int *) c->x86_model_id;
979 cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
980 cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
981 cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
982 c->x86_model_id[48] = 0;
983 return 1;
984 }
987 static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
988 {
989 unsigned int n, dummy, eax, ebx, ecx, edx;
991 n = c->extended_cpuid_level;
993 if (n >= 0x80000005) {
994 cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
995 printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
996 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
997 c->x86_cache_size=(ecx>>24)+(edx>>24);
998 /* On K8 L1 TLB is inclusive, so don't count it */
999 c->x86_tlbsize = 0;
1002 if (n >= 0x80000006) {
1003 cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
1004 ecx = cpuid_ecx(0x80000006);
1005 c->x86_cache_size = ecx >> 16;
1006 c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
1008 printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
1009 c->x86_cache_size, ecx & 0xFF);
1012 if (n >= 0x80000007)
1013 cpuid(0x80000007, &dummy, &dummy, &dummy, &c->x86_power);
1014 if (n >= 0x80000008) {
1015 cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
1016 c->x86_virt_bits = (eax >> 8) & 0xff;
1017 c->x86_phys_bits = eax & 0xff;
1021 #ifdef CONFIG_NUMA
1022 static int nearby_node(int apicid)
1024 int i;
1025 for (i = apicid - 1; i >= 0; i--) {
1026 int node = apicid_to_node[i];
1027 if (node != NUMA_NO_NODE && node_online(node))
1028 return node;
1030 for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
1031 int node = apicid_to_node[i];
1032 if (node != NUMA_NO_NODE && node_online(node))
1033 return node;
1035 return first_node(node_online_map); /* Shouldn't happen */
1037 #endif
1039 /*
1040 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
1041 * Assumes number of cores is a power of two.
1042 */
1043 static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
1045 #ifdef CONFIG_SMP
1046 unsigned bits;
1047 #ifdef CONFIG_NUMA
1048 int cpu = smp_processor_id();
1049 int node = 0;
1050 unsigned apicid = hard_smp_processor_id();
1051 #endif
1052 unsigned ecx = cpuid_ecx(0x80000008);
1054 c->x86_max_cores = (ecx & 0xff) + 1;
1056 /* CPU telling us the core id bits shift? */
1057 bits = (ecx >> 12) & 0xF;
1059 /* Otherwise recompute */
1060 if (bits == 0) {
1061 while ((1 << bits) < c->x86_max_cores)
1062 bits++;
1065 /* Low order bits define the core id (index of core in socket) */
1066 c->cpu_core_id = c->phys_proc_id & ((1 << bits)-1);
1067 /* Convert the APIC ID into the socket ID */
1068 c->phys_proc_id = phys_pkg_id(bits);
1070 #ifdef CONFIG_NUMA
1071 node = c->phys_proc_id;
1072 if (apicid_to_node[apicid] != NUMA_NO_NODE)
1073 node = apicid_to_node[apicid];
1074 if (!node_online(node)) {
1075 /* Two possibilities here:
1076 - The CPU is missing memory and no node was created.
1077 In that case try picking one from a nearby CPU
1078 - The APIC IDs differ from the HyperTransport node IDs
1079 which the K8 northbridge parsing fills in.
1080 Assume they are all increased by a constant offset,
1081 but in the same order as the HT nodeids.
1082 If that doesn't result in a usable node fall back to the
1083 path for the previous case. */
1084 int ht_nodeid = apicid - (cpu_data[0].phys_proc_id << bits);
1085 if (ht_nodeid >= 0 &&
1086 apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
1087 node = apicid_to_node[ht_nodeid];
1088 /* Pick a nearby node */
1089 if (!node_online(node))
1090 node = nearby_node(apicid);
1092 numa_set_node(cpu, node);
1094 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
1095 #endif
1096 #endif
1099 static void __init init_amd(struct cpuinfo_x86 *c)
1101 unsigned level;
1103 #ifdef CONFIG_SMP
1104 unsigned long value;
1106 /*
1107 * Disable TLB flush filter by setting HWCR.FFDIS on K8
1108 * bit 6 of msr C001_0015
1110 * Errata 63 for SH-B3 steppings
1111 * Errata 122 for all steppings (F+ have it disabled by default)
1112 */
1113 if (c->x86 == 15) {
1114 rdmsrl(MSR_K8_HWCR, value);
1115 value |= 1 << 6;
1116 wrmsrl(MSR_K8_HWCR, value);
1118 #endif
1120 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
1121 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
1122 clear_bit(0*32+31, &c->x86_capability);
1124 /* On C+ stepping K8 rep microcode works well for copy/memset */
1125 level = cpuid_eax(1);
1126 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58))
1127 set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
1129 /* Enable workaround for FXSAVE leak */
1130 if (c->x86 >= 6)
1131 set_bit(X86_FEATURE_FXSAVE_LEAK, &c->x86_capability);
1133 level = get_model_name(c);
1134 if (!level) {
1135 switch (c->x86) {
1136 case 15:
1137 /* Should distinguish Models here, but this is only
1138 a fallback anyways. */
1139 strcpy(c->x86_model_id, "Hammer");
1140 break;
1143 display_cacheinfo(c);
1145 /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
1146 if (c->x86_power & (1<<8))
1147 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1149 /* Multi core CPU? */
1150 if (c->extended_cpuid_level >= 0x80000008)
1151 amd_detect_cmp(c);
1153 /* Fix cpuid4 emulation for more */
1154 num_cache_leaves = 3;
1157 static void __cpuinit detect_ht(struct cpuinfo_x86 *c)
1159 #ifdef CONFIG_SMP
1160 u32 eax, ebx, ecx, edx;
1161 int index_msb, core_bits;
1163 cpuid(1, &eax, &ebx, &ecx, &edx);
1166 if (!cpu_has(c, X86_FEATURE_HT))
1167 return;
1168 if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
1169 goto out;
1171 smp_num_siblings = (ebx & 0xff0000) >> 16;
1173 if (smp_num_siblings == 1) {
1174 printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
1175 } else if (smp_num_siblings > 1 ) {
1177 if (smp_num_siblings > NR_CPUS) {
1178 printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
1179 smp_num_siblings = 1;
1180 return;
1183 index_msb = get_count_order(smp_num_siblings);
1184 c->phys_proc_id = phys_pkg_id(index_msb);
1186 smp_num_siblings = smp_num_siblings / c->x86_max_cores;
1188 index_msb = get_count_order(smp_num_siblings) ;
1190 core_bits = get_count_order(c->x86_max_cores);
1192 c->cpu_core_id = phys_pkg_id(index_msb) &
1193 ((1 << core_bits) - 1);
1195 out:
1196 if ((c->x86_max_cores * smp_num_siblings) > 1) {
1197 printk(KERN_INFO "CPU: Physical Processor ID: %d\n", c->phys_proc_id);
1198 printk(KERN_INFO "CPU: Processor Core ID: %d\n", c->cpu_core_id);
1201 #endif
1204 /*
1205 * find out the number of processor cores on the die
1206 */
1207 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
1209 unsigned int eax, t;
1211 if (c->cpuid_level < 4)
1212 return 1;
1214 cpuid_count(4, 0, &eax, &t, &t, &t);
1216 if (eax & 0x1f)
1217 return ((eax >> 26) + 1);
1218 else
1219 return 1;
1222 static void srat_detect_node(void)
1224 #ifdef CONFIG_NUMA
1225 unsigned node;
1226 int cpu = smp_processor_id();
1227 int apicid = hard_smp_processor_id();
1229 /* Don't do the funky fallback heuristics the AMD version employs
1230 for now. */
1231 node = apicid_to_node[apicid];
1232 if (node == NUMA_NO_NODE)
1233 node = first_node(node_online_map);
1234 numa_set_node(cpu, node);
1236 if (acpi_numa > 0)
1237 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
1238 #endif
1241 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
1243 /* Cache sizes */
1244 unsigned n;
1246 init_intel_cacheinfo(c);
1247 if (c->cpuid_level > 9 ) {
1248 unsigned eax = cpuid_eax(10);
1249 /* Check for version and the number of counters */
1250 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
1251 set_bit(X86_FEATURE_ARCH_PERFMON, &c->x86_capability);
1254 n = c->extended_cpuid_level;
1255 if (n >= 0x80000008) {
1256 unsigned eax = cpuid_eax(0x80000008);
1257 c->x86_virt_bits = (eax >> 8) & 0xff;
1258 c->x86_phys_bits = eax & 0xff;
1259 /* CPUID workaround for Intel 0F34 CPU */
1260 if (c->x86_vendor == X86_VENDOR_INTEL &&
1261 c->x86 == 0xF && c->x86_model == 0x3 &&
1262 c->x86_mask == 0x4)
1263 c->x86_phys_bits = 36;
1266 if (c->x86 == 15)
1267 c->x86_cache_alignment = c->x86_clflush_size * 2;
1268 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
1269 (c->x86 == 0x6 && c->x86_model >= 0x0e))
1270 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1271 set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
1272 c->x86_max_cores = intel_num_cpu_cores(c);
1274 srat_detect_node();
1277 static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
1279 char *v = c->x86_vendor_id;
1281 if (!strcmp(v, "AuthenticAMD"))
1282 c->x86_vendor = X86_VENDOR_AMD;
1283 else if (!strcmp(v, "GenuineIntel"))
1284 c->x86_vendor = X86_VENDOR_INTEL;
1285 else
1286 c->x86_vendor = X86_VENDOR_UNKNOWN;
1289 struct cpu_model_info {
1290 int vendor;
1291 int family;
1292 char *model_names[16];
1293 };
1295 /* Do some early cpuid on the boot CPU to get some parameter that are
1296 needed before check_bugs. Everything advanced is in identify_cpu
1297 below. */
1298 void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
1300 u32 tfms;
1302 c->loops_per_jiffy = loops_per_jiffy;
1303 c->x86_cache_size = -1;
1304 c->x86_vendor = X86_VENDOR_UNKNOWN;
1305 c->x86_model = c->x86_mask = 0; /* So far unknown... */
1306 c->x86_vendor_id[0] = '\0'; /* Unset */
1307 c->x86_model_id[0] = '\0'; /* Unset */
1308 c->x86_clflush_size = 64;
1309 c->x86_cache_alignment = c->x86_clflush_size;
1310 c->x86_max_cores = 1;
1311 c->extended_cpuid_level = 0;
1312 memset(&c->x86_capability, 0, sizeof c->x86_capability);
1314 /* Get vendor name */
1315 cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
1316 (unsigned int *)&c->x86_vendor_id[0],
1317 (unsigned int *)&c->x86_vendor_id[8],
1318 (unsigned int *)&c->x86_vendor_id[4]);
1320 get_cpu_vendor(c);
1322 /* Initialize the standard set of capabilities */
1323 /* Note that the vendor-specific code below might override */
1325 /* Intel-defined flags: level 0x00000001 */
1326 if (c->cpuid_level >= 0x00000001) {
1327 __u32 misc;
1328 cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
1329 &c->x86_capability[0]);
1330 c->x86 = (tfms >> 8) & 0xf;
1331 c->x86_model = (tfms >> 4) & 0xf;
1332 c->x86_mask = tfms & 0xf;
1333 if (c->x86 == 0xf)
1334 c->x86 += (tfms >> 20) & 0xff;
1335 if (c->x86 >= 0x6)
1336 c->x86_model += ((tfms >> 16) & 0xF) << 4;
1337 if (c->x86_capability[0] & (1<<19))
1338 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
1339 } else {
1340 /* Have CPUID level 0 only - unheard of */
1341 c->x86 = 4;
1344 #ifdef CONFIG_SMP
1345 c->phys_proc_id = (cpuid_ebx(1) >> 24) & 0xff;
1346 #endif
1349 /*
1350 * This does the hard work of actually picking apart the CPU stuff...
1351 */
1352 void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
1354 int i;
1355 u32 xlvl;
1357 early_identify_cpu(c);
1359 /* AMD-defined flags: level 0x80000001 */
1360 xlvl = cpuid_eax(0x80000000);
1361 c->extended_cpuid_level = xlvl;
1362 if ((xlvl & 0xffff0000) == 0x80000000) {
1363 if (xlvl >= 0x80000001) {
1364 c->x86_capability[1] = cpuid_edx(0x80000001);
1365 c->x86_capability[6] = cpuid_ecx(0x80000001);
1367 if (xlvl >= 0x80000004)
1368 get_model_name(c); /* Default name */
1371 /* Transmeta-defined flags: level 0x80860001 */
1372 xlvl = cpuid_eax(0x80860000);
1373 if ((xlvl & 0xffff0000) == 0x80860000) {
1374 /* Don't set x86_cpuid_level here for now to not confuse. */
1375 if (xlvl >= 0x80860001)
1376 c->x86_capability[2] = cpuid_edx(0x80860001);
1379 c->apicid = phys_pkg_id(0);
1381 /*
1382 * Vendor-specific initialization. In this section we
1383 * canonicalize the feature flags, meaning if there are
1384 * features a certain CPU supports which CPUID doesn't
1385 * tell us, CPUID claiming incorrect flags, or other bugs,
1386 * we handle them here.
1388 * At the end of this section, c->x86_capability better
1389 * indicate the features this CPU genuinely supports!
1390 */
1391 switch (c->x86_vendor) {
1392 case X86_VENDOR_AMD:
1393 init_amd(c);
1394 break;
1396 case X86_VENDOR_INTEL:
1397 init_intel(c);
1398 break;
1400 case X86_VENDOR_UNKNOWN:
1401 default:
1402 display_cacheinfo(c);
1403 break;
1406 select_idle_routine(c);
1407 detect_ht(c);
1409 /*
1410 * On SMP, boot_cpu_data holds the common feature set between
1411 * all CPUs; so make sure that we indicate which features are
1412 * common between the CPUs. The first time this routine gets
1413 * executed, c == &boot_cpu_data.
1414 */
1415 if (c != &boot_cpu_data) {
1416 /* AND the already accumulated flags with these */
1417 for (i = 0 ; i < NCAPINTS ; i++)
1418 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
1421 #ifdef CONFIG_X86_MCE
1422 mcheck_init(c);
1423 #endif
1424 if (c == &boot_cpu_data)
1425 mtrr_bp_init();
1426 else
1427 mtrr_ap_init();
1428 #ifdef CONFIG_NUMA
1429 numa_add_cpu(smp_processor_id());
1430 #endif
1434 void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
1436 if (c->x86_model_id[0])
1437 printk("%s", c->x86_model_id);
1439 if (c->x86_mask || c->cpuid_level >= 0)
1440 printk(" stepping %02x\n", c->x86_mask);
1441 else
1442 printk("\n");
1445 /*
1446 * Get CPU information for use by the procfs.
1447 */
1449 static int show_cpuinfo(struct seq_file *m, void *v)
1451 struct cpuinfo_x86 *c = v;
1453 /*
1454 * These flag bits must match the definitions in <asm/cpufeature.h>.
1455 * NULL means this bit is undefined or reserved; either way it doesn't
1456 * have meaning as far as Linux is concerned. Note that it's important
1457 * to realize there is a difference between this table and CPUID -- if
1458 * applications want to get the raw CPUID data, they should access
1459 * /dev/cpu/<cpu_nr>/cpuid instead.
1460 */
1461 static char *x86_cap_flags[] = {
1462 /* Intel-defined */
1463 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
1464 "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
1465 "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
1466 "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
1468 /* AMD-defined */
1469 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1470 NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
1471 NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
1472 NULL, "fxsr_opt", NULL, "rdtscp", NULL, "lm", "3dnowext", "3dnow",
1474 /* Transmeta-defined */
1475 "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
1476 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1477 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1478 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1480 /* Other (Linux-defined) */
1481 "cxmmx", NULL, "cyrix_arr", "centaur_mcr", NULL,
1482 "constant_tsc", NULL, NULL,
1483 "up", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1484 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1485 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1487 /* Intel-defined (#2) */
1488 "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
1489 "tm2", NULL, "cid", NULL, NULL, "cx16", "xtpr", NULL,
1490 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1491 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1493 /* VIA/Cyrix/Centaur-defined */
1494 NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
1495 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1496 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1497 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1499 /* AMD-defined (#2) */
1500 "lahf_lm", "cmp_legacy", "svm", NULL, "cr8_legacy", NULL, NULL, NULL,
1501 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1502 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1503 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1504 };
1505 static char *x86_power_flags[] = {
1506 "ts", /* temperature sensor */
1507 "fid", /* frequency id control */
1508 "vid", /* voltage id control */
1509 "ttp", /* thermal trip */
1510 "tm",
1511 "stc",
1512 NULL,
1513 /* nothing */ /* constant_tsc - moved to flags */
1514 };
1517 #ifdef CONFIG_SMP
1518 if (!cpu_online(c-cpu_data))
1519 return 0;
1520 #endif
1522 seq_printf(m,"processor\t: %u\n"
1523 "vendor_id\t: %s\n"
1524 "cpu family\t: %d\n"
1525 "model\t\t: %d\n"
1526 "model name\t: %s\n",
1527 (unsigned)(c-cpu_data),
1528 c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
1529 c->x86,
1530 (int)c->x86_model,
1531 c->x86_model_id[0] ? c->x86_model_id : "unknown");
1533 if (c->x86_mask || c->cpuid_level >= 0)
1534 seq_printf(m, "stepping\t: %d\n", c->x86_mask);
1535 else
1536 seq_printf(m, "stepping\t: unknown\n");
1538 if (cpu_has(c,X86_FEATURE_TSC)) {
1539 unsigned int freq = cpufreq_quick_get((unsigned)(c-cpu_data));
1540 if (!freq)
1541 freq = cpu_khz;
1542 seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
1543 freq / 1000, (freq % 1000));
1546 /* Cache size */
1547 if (c->x86_cache_size >= 0)
1548 seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
1550 #ifdef CONFIG_SMP
1551 if (smp_num_siblings * c->x86_max_cores > 1) {
1552 int cpu = c - cpu_data;
1553 seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
1554 seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[cpu]));
1555 seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
1556 seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
1558 #endif
1560 seq_printf(m,
1561 "fpu\t\t: yes\n"
1562 "fpu_exception\t: yes\n"
1563 "cpuid level\t: %d\n"
1564 "wp\t\t: yes\n"
1565 "flags\t\t:",
1566 c->cpuid_level);
1569 int i;
1570 for ( i = 0 ; i < 32*NCAPINTS ; i++ )
1571 if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
1572 seq_printf(m, " %s", x86_cap_flags[i]);
1575 seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
1576 c->loops_per_jiffy/(500000/HZ),
1577 (c->loops_per_jiffy/(5000/HZ)) % 100);
1579 if (c->x86_tlbsize > 0)
1580 seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
1581 seq_printf(m, "clflush size\t: %d\n", c->x86_clflush_size);
1582 seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
1584 seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
1585 c->x86_phys_bits, c->x86_virt_bits);
1587 seq_printf(m, "power management:");
1589 unsigned i;
1590 for (i = 0; i < 32; i++)
1591 if (c->x86_power & (1 << i)) {
1592 if (i < ARRAY_SIZE(x86_power_flags) &&
1593 x86_power_flags[i])
1594 seq_printf(m, "%s%s",
1595 x86_power_flags[i][0]?" ":"",
1596 x86_power_flags[i]);
1597 else
1598 seq_printf(m, " [%d]", i);
1602 seq_printf(m, "\n\n");
1604 return 0;
1607 static void *c_start(struct seq_file *m, loff_t *pos)
1609 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
1612 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1614 ++*pos;
1615 return c_start(m, pos);
1618 static void c_stop(struct seq_file *m, void *v)
1622 struct seq_operations cpuinfo_op = {
1623 .start =c_start,
1624 .next = c_next,
1625 .stop = c_stop,
1626 .show = show_cpuinfo,
1627 };
1629 #if defined(CONFIG_INPUT_PCSPKR) || defined(CONFIG_INPUT_PCSPKR_MODULE)
1630 #include <linux/platform_device.h>
1631 static __init int add_pcspkr(void)
1633 struct platform_device *pd;
1634 int ret;
1636 if (!is_initial_xendomain())
1637 return 0;
1639 pd = platform_device_alloc("pcspkr", -1);
1640 if (!pd)
1641 return -ENOMEM;
1643 ret = platform_device_add(pd);
1644 if (ret)
1645 platform_device_put(pd);
1647 return ret;
1649 device_initcall(add_pcspkr);
1650 #endif