ia64/linux-2.6.18-xen.hg

view arch/x86_64/kernel/setup-xen.c @ 871:9cbcc9008446

xen/x86: don't initialize cpu_data[]'s apicid field on generic code

Afaict, this is not only redundant with the intialization done in
drivers/xen/core/smpboot.c, but actually results - at least for
secondary CPUs - in the Xen-specific value written to be later
overwritten with whatever the generic code determines (with no
guarantee that the two values are identical).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu May 14 10:09:15 2009 +0100 (2009-05-14)
parents 1c928f28914a
children baeb818cd2dc
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/firmware.h>
75 #include <xen/xencons.h>
76 #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
77 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
78 #include <asm/mach-xen/setup_arch_post.h>
79 #include <xen/interface/memory.h>
81 #ifdef CONFIG_XEN
82 #include <xen/interface/kexec.h>
83 #endif
85 extern unsigned long start_pfn;
86 extern struct edid_info edid_info;
88 shared_info_t *HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
89 EXPORT_SYMBOL(HYPERVISOR_shared_info);
91 extern char hypercall_page[PAGE_SIZE];
92 EXPORT_SYMBOL(hypercall_page);
94 static int xen_panic_event(struct notifier_block *, unsigned long, void *);
95 static struct notifier_block xen_panic_block = {
96 xen_panic_event, NULL, 0 /* try to go last */
97 };
99 unsigned long *phys_to_machine_mapping;
100 unsigned long *pfn_to_mfn_frame_list_list, *pfn_to_mfn_frame_list[512];
102 EXPORT_SYMBOL(phys_to_machine_mapping);
104 DEFINE_PER_CPU(multicall_entry_t, multicall_list[8]);
105 DEFINE_PER_CPU(int, nr_multicall_ents);
107 /* Raw start-of-day parameters from the hypervisor. */
108 start_info_t *xen_start_info;
109 EXPORT_SYMBOL(xen_start_info);
110 #endif
112 /*
113 * Machine setup..
114 */
116 struct cpuinfo_x86 boot_cpu_data __read_mostly;
117 EXPORT_SYMBOL(boot_cpu_data);
119 unsigned long mmu_cr4_features;
121 int acpi_disabled;
122 EXPORT_SYMBOL(acpi_disabled);
123 #ifdef CONFIG_ACPI
124 extern int __initdata acpi_ht;
125 extern acpi_interrupt_flags acpi_sci_flags;
126 int __initdata acpi_force = 0;
127 #endif
129 int acpi_numa __initdata;
131 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
132 int bootloader_type;
134 unsigned long saved_video_mode;
136 /*
137 * Early DMI memory
138 */
139 int dmi_alloc_index;
140 char dmi_alloc_data[DMI_MAX_DATA];
142 /*
143 * Setup options
144 */
145 struct screen_info screen_info;
146 EXPORT_SYMBOL(screen_info);
147 struct sys_desc_table_struct {
148 unsigned short length;
149 unsigned char table[0];
150 };
152 struct edid_info edid_info;
153 EXPORT_SYMBOL_GPL(edid_info);
154 struct e820map e820;
155 #ifdef CONFIG_XEN
156 struct e820map machine_e820;
157 #endif
159 extern int root_mountflags;
161 char command_line[COMMAND_LINE_SIZE];
163 struct resource standard_io_resources[] = {
164 { .name = "dma1", .start = 0x00, .end = 0x1f,
165 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
166 { .name = "pic1", .start = 0x20, .end = 0x21,
167 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
168 { .name = "timer0", .start = 0x40, .end = 0x43,
169 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
170 { .name = "timer1", .start = 0x50, .end = 0x53,
171 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
172 { .name = "keyboard", .start = 0x60, .end = 0x60,
173 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
174 { .name = "keyboard", .start = 0x64, .end = 0x64,
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 #ifndef CONFIG_XEN
541 /**
542 * copy_edd() - Copy the BIOS EDD information
543 * from boot_params into a safe place.
544 *
545 */
546 static inline void copy_edd(void)
547 {
548 memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
549 memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
550 edd.mbr_signature_nr = EDD_MBR_SIG_NR;
551 edd.edd_info_nr = EDD_NR;
552 }
553 #endif
554 #else
555 static inline void copy_edd(void)
556 {
557 }
558 #endif
560 #ifndef CONFIG_XEN
561 #define EBDA_ADDR_POINTER 0x40E
563 unsigned __initdata ebda_addr;
564 unsigned __initdata ebda_size;
566 static void discover_ebda(void)
567 {
568 /*
569 * there is a real-mode segmented pointer pointing to the
570 * 4K EBDA area at 0x40E
571 */
572 ebda_addr = *(unsigned short *)EBDA_ADDR_POINTER;
573 ebda_addr <<= 4;
575 ebda_size = *(unsigned short *)(unsigned long)ebda_addr;
577 /* Round EBDA up to pages */
578 if (ebda_size == 0)
579 ebda_size = 1;
580 ebda_size <<= 10;
581 ebda_size = round_up(ebda_size + (ebda_addr & ~PAGE_MASK), PAGE_SIZE);
582 if (ebda_size > 64*1024)
583 ebda_size = 64*1024;
584 }
585 #else
586 #define discover_ebda() ((void)0)
587 #endif
589 void __init setup_arch(char **cmdline_p)
590 {
591 #ifdef CONFIG_XEN
592 /* Register a call for panic conditions. */
593 atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
595 ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
596 screen_info = SCREEN_INFO;
598 if (is_initial_xendomain()) {
599 const struct dom0_vga_console_info *info =
600 (void *)((char *)xen_start_info +
601 xen_start_info->console.dom0.info_off);
603 dom0_init_screen_info(info,
604 xen_start_info->console.dom0.info_size);
605 xen_start_info->console.domU.mfn = 0;
606 xen_start_info->console.domU.evtchn = 0;
607 } else
608 screen_info.orig_video_isVGA = 0;
610 copy_edid();
612 WARN_ON(HYPERVISOR_vm_assist(VMASST_CMD_enable,
613 VMASST_TYPE_writable_pagetables));
615 ARCH_SETUP
616 #else
617 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
618 screen_info = SCREEN_INFO;
619 edid_info = EDID_INFO;
620 #endif /* !CONFIG_XEN */
621 saved_video_mode = SAVED_VIDEO_MODE;
622 bootloader_type = LOADER_TYPE;
624 #ifdef CONFIG_BLK_DEV_RAM
625 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
626 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
627 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
628 #endif
629 setup_memory_region();
630 copy_edd();
632 if (!MOUNT_ROOT_RDONLY)
633 root_mountflags &= ~MS_RDONLY;
634 init_mm.start_code = (unsigned long) &_text;
635 init_mm.end_code = (unsigned long) &_etext;
636 init_mm.end_data = (unsigned long) &_edata;
637 init_mm.brk = (unsigned long) &_end;
639 code_resource.start = virt_to_phys(&_text);
640 code_resource.end = virt_to_phys(&_etext)-1;
641 data_resource.start = virt_to_phys(&_etext);
642 data_resource.end = virt_to_phys(&_edata)-1;
644 parse_cmdline_early(cmdline_p);
646 early_identify_cpu(&boot_cpu_data);
648 /*
649 * partially used pages are not usable - thus
650 * we are rounding upwards:
651 */
652 end_pfn = e820_end_of_ram();
653 num_physpages = end_pfn; /* for pfn_valid */
655 check_efer();
657 discover_ebda();
659 init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
661 if (is_initial_xendomain())
662 dmi_scan_machine();
664 #ifdef CONFIG_ACPI_NUMA
665 /*
666 * Parse SRAT to discover nodes.
667 */
668 acpi_numa_init();
669 #endif
671 #ifdef CONFIG_NUMA
672 numa_initmem_init(0, end_pfn);
673 #else
674 contig_initmem_init(0, end_pfn);
675 #endif
677 #ifdef CONFIG_XEN
678 /*
679 * Reserve kernel, physmap, start info, initial page tables, and
680 * direct mapping.
681 */
682 reserve_bootmem_generic(__pa_symbol(&_text),
683 (table_end << PAGE_SHIFT) - __pa_symbol(&_text));
684 #else
685 /* Reserve direct mapping */
686 reserve_bootmem_generic(table_start << PAGE_SHIFT,
687 (table_end - table_start) << PAGE_SHIFT);
689 /* reserve kernel */
690 reserve_bootmem_generic(__pa_symbol(&_text),
691 __pa_symbol(&_end) - __pa_symbol(&_text));
693 /*
694 * reserve physical page 0 - it's a special BIOS page on many boxes,
695 * enabling clean reboots, SMP operation, laptop functions.
696 */
697 reserve_bootmem_generic(0, PAGE_SIZE);
699 /* reserve ebda region */
700 if (ebda_addr)
701 reserve_bootmem_generic(ebda_addr, ebda_size);
703 #ifdef CONFIG_SMP
704 /*
705 * But first pinch a few for the stack/trampoline stuff
706 * FIXME: Don't need the extra page at 4K, but need to fix
707 * trampoline before removing it. (see the GDT stuff)
708 */
709 reserve_bootmem_generic(PAGE_SIZE, PAGE_SIZE);
711 /* Reserve SMP trampoline */
712 reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, PAGE_SIZE);
713 #endif
714 #endif
716 #ifdef CONFIG_ACPI_SLEEP
717 /*
718 * Reserve low memory region for sleep support.
719 */
720 acpi_reserve_bootmem();
721 #endif
722 #ifdef CONFIG_XEN
723 #ifdef CONFIG_BLK_DEV_INITRD
724 if (xen_start_info->mod_start) {
725 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
726 /*reserve_bootmem_generic(INITRD_START, INITRD_SIZE);*/
727 initrd_start = INITRD_START + PAGE_OFFSET;
728 initrd_end = initrd_start+INITRD_SIZE;
729 initrd_below_start_ok = 1;
730 } else {
731 printk(KERN_ERR "initrd extends beyond end of memory "
732 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
733 (unsigned long)(INITRD_START + INITRD_SIZE),
734 (unsigned long)(end_pfn << PAGE_SHIFT));
735 initrd_start = 0;
736 }
737 }
738 #endif
739 #else /* CONFIG_XEN */
740 #ifdef CONFIG_BLK_DEV_INITRD
741 if (LOADER_TYPE && INITRD_START) {
742 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
743 reserve_bootmem_generic(INITRD_START, INITRD_SIZE);
744 initrd_start =
745 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
746 initrd_end = initrd_start+INITRD_SIZE;
747 }
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 #endif /* !CONFIG_XEN */
758 #ifdef CONFIG_KEXEC
759 #ifdef CONFIG_XEN
760 xen_machine_kexec_setup_resources();
761 #else
762 if (crashk_res.start != crashk_res.end) {
763 reserve_bootmem_generic(crashk_res.start,
764 crashk_res.end - crashk_res.start + 1);
765 }
766 #endif
767 #endif
769 paging_init();
770 #ifdef CONFIG_X86_LOCAL_APIC
771 /*
772 * Find and reserve possible boot-time SMP configuration:
773 */
774 find_smp_config();
775 #endif
776 #ifdef CONFIG_XEN
777 {
778 int i, j, k, fpp;
779 unsigned long p2m_pages;
781 p2m_pages = end_pfn;
782 if (xen_start_info->nr_pages > end_pfn) {
783 /*
784 * the end_pfn was shrunk (probably by mem= or highmem=
785 * kernel parameter); shrink reservation with the HV
786 */
787 struct xen_memory_reservation reservation = {
788 .address_bits = 0,
789 .extent_order = 0,
790 .domid = DOMID_SELF
791 };
792 unsigned int difference;
793 int ret;
795 difference = xen_start_info->nr_pages - end_pfn;
797 set_xen_guest_handle(reservation.extent_start,
798 ((unsigned long *)xen_start_info->mfn_list) + end_pfn);
799 reservation.nr_extents = difference;
800 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
801 &reservation);
802 BUG_ON (ret != difference);
803 }
804 else if (end_pfn > xen_start_info->nr_pages)
805 p2m_pages = xen_start_info->nr_pages;
807 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
808 /* Make sure we have a large enough P->M table. */
809 phys_to_machine_mapping = alloc_bootmem_pages(
810 end_pfn * sizeof(unsigned long));
811 memset(phys_to_machine_mapping, ~0,
812 end_pfn * sizeof(unsigned long));
813 memcpy(phys_to_machine_mapping,
814 (unsigned long *)xen_start_info->mfn_list,
815 p2m_pages * sizeof(unsigned long));
816 free_bootmem(
817 __pa(xen_start_info->mfn_list),
818 PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
819 sizeof(unsigned long))));
821 /*
822 * Initialise the list of the frames that specify the
823 * list of frames that make up the p2m table. Used by
824 * save/restore.
825 */
826 pfn_to_mfn_frame_list_list = alloc_bootmem_pages(PAGE_SIZE);
828 fpp = PAGE_SIZE/sizeof(unsigned long);
829 for (i=0, j=0, k=-1; i< end_pfn; i+=fpp, j++) {
830 if ((j % fpp) == 0) {
831 k++;
832 BUG_ON(k>=fpp);
833 pfn_to_mfn_frame_list[k] =
834 alloc_bootmem_pages(PAGE_SIZE);
835 pfn_to_mfn_frame_list_list[k] =
836 virt_to_mfn(pfn_to_mfn_frame_list[k]);
837 j=0;
838 }
839 pfn_to_mfn_frame_list[k][j] =
840 virt_to_mfn(&phys_to_machine_mapping[i]);
841 }
842 HYPERVISOR_shared_info->arch.max_pfn = end_pfn;
843 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
844 virt_to_mfn(pfn_to_mfn_frame_list_list);
845 }
847 /* Mark all ISA DMA channels in-use - using them wouldn't work. */
848 for (i = 0; i < MAX_DMA_CHANNELS; ++i)
849 if (i != 4 && request_dma(i, "xen") != 0)
850 BUG();
851 }
853 if (!is_initial_xendomain()) {
854 acpi_disabled = 1;
855 #ifdef CONFIG_ACPI
856 acpi_ht = 0;
857 #endif
858 }
859 #endif
861 #ifndef CONFIG_XEN
862 check_ioapic();
863 #endif
865 zap_low_mappings(0);
867 /*
868 * set this early, so we dont allocate cpu0
869 * if MADT list doesnt list BSP first
870 * mpparse.c/MP_processor_info() allocates logical cpu numbers.
871 */
872 cpu_set(0, cpu_present_map);
873 #ifdef CONFIG_ACPI
874 /*
875 * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
876 * Call this early for SRAT node setup.
877 */
878 acpi_boot_table_init();
880 /*
881 * Read APIC and some other early information from ACPI tables.
882 */
883 acpi_boot_init();
884 #endif
886 init_cpu_to_node();
888 #ifdef CONFIG_X86_LOCAL_APIC
889 /*
890 * get boot-time SMP configuration:
891 */
892 if (smp_found_config)
893 get_smp_config();
894 #ifndef CONFIG_XEN
895 init_apic_mappings();
896 #endif
897 #endif
898 #if defined(CONFIG_XEN) && defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU)
899 prefill_possible_map();
900 #endif
902 /*
903 * Request address space for all standard RAM and ROM resources
904 * and also for regions reported as reserved by the e820.
905 */
906 probe_roms();
907 #ifdef CONFIG_XEN
908 if (is_initial_xendomain())
909 e820_reserve_resources(machine_e820.map, machine_e820.nr_map);
910 #else
911 e820_reserve_resources(e820.map, e820.nr_map);
912 #endif
914 request_resource(&iomem_resource, &video_ram_resource);
916 {
917 unsigned i;
918 /* request I/O space for devices used on all i[345]86 PCs */
919 for (i = 0; i < STANDARD_IO_RESOURCES; i++)
920 request_resource(&ioport_resource, &standard_io_resources[i]);
921 }
923 #ifdef CONFIG_XEN
924 if (is_initial_xendomain())
925 e820_setup_gap(machine_e820.map, machine_e820.nr_map);
926 #else
927 e820_setup_gap(e820.map, e820.nr_map);
928 #endif
930 #ifdef CONFIG_XEN
931 {
932 struct physdev_set_iopl set_iopl;
934 set_iopl.iopl = 1;
935 WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl));
937 if (is_initial_xendomain()) {
938 #ifdef CONFIG_VT
939 #if defined(CONFIG_VGA_CONSOLE)
940 conswitchp = &vga_con;
941 #elif defined(CONFIG_DUMMY_CONSOLE)
942 conswitchp = &dummy_con;
943 #endif
944 #endif
945 } else {
946 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
947 conswitchp = &dummy_con;
948 #endif
949 }
950 }
951 #else /* CONFIG_XEN */
953 #ifdef CONFIG_VT
954 #if defined(CONFIG_VGA_CONSOLE)
955 conswitchp = &vga_con;
956 #elif defined(CONFIG_DUMMY_CONSOLE)
957 conswitchp = &dummy_con;
958 #endif
959 #endif
961 #endif /* !CONFIG_XEN */
962 }
964 #ifdef CONFIG_XEN
965 static int
966 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
967 {
968 HYPERVISOR_shutdown(SHUTDOWN_crash);
969 /* we're never actually going to get here... */
970 return NOTIFY_DONE;
971 }
972 #endif /* !CONFIG_XEN */
975 static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
976 {
977 unsigned int *v;
979 if (c->extended_cpuid_level < 0x80000004)
980 return 0;
982 v = (unsigned int *) c->x86_model_id;
983 cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
984 cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
985 cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
986 c->x86_model_id[48] = 0;
987 return 1;
988 }
991 static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
992 {
993 unsigned int n, dummy, eax, ebx, ecx, edx;
995 n = c->extended_cpuid_level;
997 if (n >= 0x80000005) {
998 cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
999 printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
1000 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
1001 c->x86_cache_size=(ecx>>24)+(edx>>24);
1002 /* On K8 L1 TLB is inclusive, so don't count it */
1003 c->x86_tlbsize = 0;
1006 if (n >= 0x80000006) {
1007 cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
1008 ecx = cpuid_ecx(0x80000006);
1009 c->x86_cache_size = ecx >> 16;
1010 c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
1012 printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
1013 c->x86_cache_size, ecx & 0xFF);
1016 if (n >= 0x80000007)
1017 cpuid(0x80000007, &dummy, &dummy, &dummy, &c->x86_power);
1018 if (n >= 0x80000008) {
1019 cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
1020 c->x86_virt_bits = (eax >> 8) & 0xff;
1021 c->x86_phys_bits = eax & 0xff;
1025 #ifdef CONFIG_NUMA
1026 static int nearby_node(int apicid)
1028 int i;
1029 for (i = apicid - 1; i >= 0; i--) {
1030 int node = apicid_to_node[i];
1031 if (node != NUMA_NO_NODE && node_online(node))
1032 return node;
1034 for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
1035 int node = apicid_to_node[i];
1036 if (node != NUMA_NO_NODE && node_online(node))
1037 return node;
1039 return first_node(node_online_map); /* Shouldn't happen */
1041 #endif
1043 /*
1044 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
1045 * Assumes number of cores is a power of two.
1046 */
1047 static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
1049 #ifdef CONFIG_SMP
1050 unsigned bits;
1051 #ifdef CONFIG_NUMA
1052 int cpu = smp_processor_id();
1053 int node = 0;
1054 unsigned apicid = hard_smp_processor_id();
1055 #endif
1056 unsigned ecx = cpuid_ecx(0x80000008);
1058 c->x86_max_cores = (ecx & 0xff) + 1;
1060 /* CPU telling us the core id bits shift? */
1061 bits = (ecx >> 12) & 0xF;
1063 /* Otherwise recompute */
1064 if (bits == 0) {
1065 while ((1 << bits) < c->x86_max_cores)
1066 bits++;
1069 /* Low order bits define the core id (index of core in socket) */
1070 c->cpu_core_id = c->phys_proc_id & ((1 << bits)-1);
1071 /* Convert the APIC ID into the socket ID */
1072 c->phys_proc_id = phys_pkg_id(bits);
1074 #ifdef CONFIG_NUMA
1075 node = c->phys_proc_id;
1076 if (apicid_to_node[apicid] != NUMA_NO_NODE)
1077 node = apicid_to_node[apicid];
1078 if (!node_online(node)) {
1079 /* Two possibilities here:
1080 - The CPU is missing memory and no node was created.
1081 In that case try picking one from a nearby CPU
1082 - The APIC IDs differ from the HyperTransport node IDs
1083 which the K8 northbridge parsing fills in.
1084 Assume they are all increased by a constant offset,
1085 but in the same order as the HT nodeids.
1086 If that doesn't result in a usable node fall back to the
1087 path for the previous case. */
1088 int ht_nodeid = apicid - (cpu_data[0].phys_proc_id << bits);
1089 if (ht_nodeid >= 0 &&
1090 apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
1091 node = apicid_to_node[ht_nodeid];
1092 /* Pick a nearby node */
1093 if (!node_online(node))
1094 node = nearby_node(apicid);
1096 numa_set_node(cpu, node);
1098 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
1099 #endif
1100 #endif
1103 static void __init init_amd(struct cpuinfo_x86 *c)
1105 unsigned level;
1107 #ifdef CONFIG_SMP
1108 unsigned long value;
1110 /*
1111 * Disable TLB flush filter by setting HWCR.FFDIS on K8
1112 * bit 6 of msr C001_0015
1114 * Errata 63 for SH-B3 steppings
1115 * Errata 122 for all steppings (F+ have it disabled by default)
1116 */
1117 if (c->x86 == 15) {
1118 rdmsrl(MSR_K8_HWCR, value);
1119 value |= 1 << 6;
1120 wrmsrl(MSR_K8_HWCR, value);
1122 #endif
1124 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
1125 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
1126 clear_bit(0*32+31, &c->x86_capability);
1128 /* On C+ stepping K8 rep microcode works well for copy/memset */
1129 level = cpuid_eax(1);
1130 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58))
1131 set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
1133 /* Enable workaround for FXSAVE leak */
1134 if (c->x86 >= 6)
1135 set_bit(X86_FEATURE_FXSAVE_LEAK, &c->x86_capability);
1137 level = get_model_name(c);
1138 if (!level) {
1139 switch (c->x86) {
1140 case 15:
1141 /* Should distinguish Models here, but this is only
1142 a fallback anyways. */
1143 strcpy(c->x86_model_id, "Hammer");
1144 break;
1147 display_cacheinfo(c);
1149 /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
1150 if (c->x86_power & (1<<8))
1151 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1153 /* Multi core CPU? */
1154 if (c->extended_cpuid_level >= 0x80000008)
1155 amd_detect_cmp(c);
1157 /* Fix cpuid4 emulation for more */
1158 num_cache_leaves = 3;
1161 static void __cpuinit detect_ht(struct cpuinfo_x86 *c)
1163 #ifdef CONFIG_SMP
1164 u32 eax, ebx, ecx, edx;
1165 int index_msb, core_bits;
1167 cpuid(1, &eax, &ebx, &ecx, &edx);
1170 if (!cpu_has(c, X86_FEATURE_HT))
1171 return;
1172 if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
1173 goto out;
1175 smp_num_siblings = (ebx & 0xff0000) >> 16;
1177 if (smp_num_siblings == 1) {
1178 printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
1179 } else if (smp_num_siblings > 1 ) {
1181 if (smp_num_siblings > NR_CPUS) {
1182 printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
1183 smp_num_siblings = 1;
1184 return;
1187 index_msb = get_count_order(smp_num_siblings);
1188 c->phys_proc_id = phys_pkg_id(index_msb);
1190 smp_num_siblings = smp_num_siblings / c->x86_max_cores;
1192 index_msb = get_count_order(smp_num_siblings) ;
1194 core_bits = get_count_order(c->x86_max_cores);
1196 c->cpu_core_id = phys_pkg_id(index_msb) &
1197 ((1 << core_bits) - 1);
1199 out:
1200 if ((c->x86_max_cores * smp_num_siblings) > 1) {
1201 printk(KERN_INFO "CPU: Physical Processor ID: %d\n", c->phys_proc_id);
1202 printk(KERN_INFO "CPU: Processor Core ID: %d\n", c->cpu_core_id);
1205 #endif
1208 /*
1209 * find out the number of processor cores on the die
1210 */
1211 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
1213 unsigned int eax, t;
1215 if (c->cpuid_level < 4)
1216 return 1;
1218 cpuid_count(4, 0, &eax, &t, &t, &t);
1220 if (eax & 0x1f)
1221 return ((eax >> 26) + 1);
1222 else
1223 return 1;
1226 static void srat_detect_node(void)
1228 #ifdef CONFIG_NUMA
1229 unsigned node;
1230 int cpu = smp_processor_id();
1231 int apicid = hard_smp_processor_id();
1233 /* Don't do the funky fallback heuristics the AMD version employs
1234 for now. */
1235 node = apicid_to_node[apicid];
1236 if (node == NUMA_NO_NODE)
1237 node = first_node(node_online_map);
1238 numa_set_node(cpu, node);
1240 if (acpi_numa > 0)
1241 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
1242 #endif
1245 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
1247 /* Cache sizes */
1248 unsigned n;
1250 init_intel_cacheinfo(c);
1251 if (c->cpuid_level > 9 ) {
1252 unsigned eax = cpuid_eax(10);
1253 /* Check for version and the number of counters */
1254 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
1255 set_bit(X86_FEATURE_ARCH_PERFMON, &c->x86_capability);
1258 n = c->extended_cpuid_level;
1259 if (n >= 0x80000008) {
1260 unsigned eax = cpuid_eax(0x80000008);
1261 c->x86_virt_bits = (eax >> 8) & 0xff;
1262 c->x86_phys_bits = eax & 0xff;
1263 /* CPUID workaround for Intel 0F34 CPU */
1264 if (c->x86_vendor == X86_VENDOR_INTEL &&
1265 c->x86 == 0xF && c->x86_model == 0x3 &&
1266 c->x86_mask == 0x4)
1267 c->x86_phys_bits = 36;
1270 if (c->x86 == 15)
1271 c->x86_cache_alignment = c->x86_clflush_size * 2;
1272 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
1273 (c->x86 == 0x6 && c->x86_model >= 0x0e))
1274 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1275 set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
1276 c->x86_max_cores = intel_num_cpu_cores(c);
1278 srat_detect_node();
1281 static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
1283 char *v = c->x86_vendor_id;
1285 if (!strcmp(v, "AuthenticAMD"))
1286 c->x86_vendor = X86_VENDOR_AMD;
1287 else if (!strcmp(v, "GenuineIntel"))
1288 c->x86_vendor = X86_VENDOR_INTEL;
1289 else
1290 c->x86_vendor = X86_VENDOR_UNKNOWN;
1293 struct cpu_model_info {
1294 int vendor;
1295 int family;
1296 char *model_names[16];
1297 };
1299 /* Do some early cpuid on the boot CPU to get some parameter that are
1300 needed before check_bugs. Everything advanced is in identify_cpu
1301 below. */
1302 void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
1304 u32 tfms;
1306 c->loops_per_jiffy = loops_per_jiffy;
1307 c->x86_cache_size = -1;
1308 c->x86_vendor = X86_VENDOR_UNKNOWN;
1309 c->x86_model = c->x86_mask = 0; /* So far unknown... */
1310 c->x86_vendor_id[0] = '\0'; /* Unset */
1311 c->x86_model_id[0] = '\0'; /* Unset */
1312 c->x86_clflush_size = 64;
1313 c->x86_cache_alignment = c->x86_clflush_size;
1314 c->x86_max_cores = 1;
1315 c->extended_cpuid_level = 0;
1316 memset(&c->x86_capability, 0, sizeof c->x86_capability);
1318 /* Get vendor name */
1319 cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
1320 (unsigned int *)&c->x86_vendor_id[0],
1321 (unsigned int *)&c->x86_vendor_id[8],
1322 (unsigned int *)&c->x86_vendor_id[4]);
1324 get_cpu_vendor(c);
1326 /* Initialize the standard set of capabilities */
1327 /* Note that the vendor-specific code below might override */
1329 /* Intel-defined flags: level 0x00000001 */
1330 if (c->cpuid_level >= 0x00000001) {
1331 __u32 misc;
1332 cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
1333 &c->x86_capability[0]);
1334 c->x86 = (tfms >> 8) & 0xf;
1335 c->x86_model = (tfms >> 4) & 0xf;
1336 c->x86_mask = tfms & 0xf;
1337 if (c->x86 == 0xf)
1338 c->x86 += (tfms >> 20) & 0xff;
1339 if (c->x86 >= 0x6)
1340 c->x86_model += ((tfms >> 16) & 0xF) << 4;
1341 if (c->x86_capability[0] & (1<<19))
1342 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
1343 } else {
1344 /* Have CPUID level 0 only - unheard of */
1345 c->x86 = 4;
1348 #ifdef CONFIG_SMP
1349 c->phys_proc_id = (cpuid_ebx(1) >> 24) & 0xff;
1350 #endif
1353 /*
1354 * This does the hard work of actually picking apart the CPU stuff...
1355 */
1356 void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
1358 int i;
1359 u32 xlvl;
1361 early_identify_cpu(c);
1363 /* AMD-defined flags: level 0x80000001 */
1364 xlvl = cpuid_eax(0x80000000);
1365 c->extended_cpuid_level = xlvl;
1366 if ((xlvl & 0xffff0000) == 0x80000000) {
1367 if (xlvl >= 0x80000001) {
1368 c->x86_capability[1] = cpuid_edx(0x80000001);
1369 c->x86_capability[6] = cpuid_ecx(0x80000001);
1371 if (xlvl >= 0x80000004)
1372 get_model_name(c); /* Default name */
1375 /* Transmeta-defined flags: level 0x80860001 */
1376 xlvl = cpuid_eax(0x80860000);
1377 if ((xlvl & 0xffff0000) == 0x80860000) {
1378 /* Don't set x86_cpuid_level here for now to not confuse. */
1379 if (xlvl >= 0x80860001)
1380 c->x86_capability[2] = cpuid_edx(0x80860001);
1383 #ifndef CONFIG_XEN
1384 c->apicid = phys_pkg_id(0);
1385 #endif
1387 /*
1388 * Vendor-specific initialization. In this section we
1389 * canonicalize the feature flags, meaning if there are
1390 * features a certain CPU supports which CPUID doesn't
1391 * tell us, CPUID claiming incorrect flags, or other bugs,
1392 * we handle them here.
1394 * At the end of this section, c->x86_capability better
1395 * indicate the features this CPU genuinely supports!
1396 */
1397 switch (c->x86_vendor) {
1398 case X86_VENDOR_AMD:
1399 init_amd(c);
1400 break;
1402 case X86_VENDOR_INTEL:
1403 init_intel(c);
1404 break;
1406 case X86_VENDOR_UNKNOWN:
1407 default:
1408 display_cacheinfo(c);
1409 break;
1412 select_idle_routine(c);
1413 detect_ht(c);
1415 /*
1416 * On SMP, boot_cpu_data holds the common feature set between
1417 * all CPUs; so make sure that we indicate which features are
1418 * common between the CPUs. The first time this routine gets
1419 * executed, c == &boot_cpu_data.
1420 */
1421 if (c != &boot_cpu_data) {
1422 /* AND the already accumulated flags with these */
1423 for (i = 0 ; i < NCAPINTS ; i++)
1424 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
1427 #ifdef CONFIG_X86_MCE
1428 mcheck_init(c);
1429 #endif
1430 if (c == &boot_cpu_data)
1431 mtrr_bp_init();
1432 else
1433 mtrr_ap_init();
1434 #ifdef CONFIG_NUMA
1435 numa_add_cpu(smp_processor_id());
1436 #endif
1440 void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
1442 if (c->x86_model_id[0])
1443 printk("%s", c->x86_model_id);
1445 if (c->x86_mask || c->cpuid_level >= 0)
1446 printk(" stepping %02x\n", c->x86_mask);
1447 else
1448 printk("\n");
1451 /*
1452 * Get CPU information for use by the procfs.
1453 */
1455 static int show_cpuinfo(struct seq_file *m, void *v)
1457 struct cpuinfo_x86 *c = v;
1459 /*
1460 * These flag bits must match the definitions in <asm/cpufeature.h>.
1461 * NULL means this bit is undefined or reserved; either way it doesn't
1462 * have meaning as far as Linux is concerned. Note that it's important
1463 * to realize there is a difference between this table and CPUID -- if
1464 * applications want to get the raw CPUID data, they should access
1465 * /dev/cpu/<cpu_nr>/cpuid instead.
1466 */
1467 static char *x86_cap_flags[] = {
1468 /* Intel-defined */
1469 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
1470 "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
1471 "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
1472 "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
1474 /* AMD-defined */
1475 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1476 NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
1477 NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
1478 NULL, "fxsr_opt", NULL, "rdtscp", NULL, "lm", "3dnowext", "3dnow",
1480 /* Transmeta-defined */
1481 "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
1482 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1483 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1484 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1486 /* Other (Linux-defined) */
1487 "cxmmx", NULL, "cyrix_arr", "centaur_mcr", NULL,
1488 "constant_tsc", NULL, NULL,
1489 "up", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1490 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1491 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1493 /* Intel-defined (#2) */
1494 "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
1495 "tm2", NULL, "cid", NULL, NULL, "cx16", "xtpr", NULL,
1496 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1497 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1499 /* VIA/Cyrix/Centaur-defined */
1500 NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
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,
1505 /* AMD-defined (#2) */
1506 "lahf_lm", "cmp_legacy", "svm", NULL, "cr8_legacy", NULL, NULL, NULL,
1507 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1508 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1509 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1510 };
1511 static char *x86_power_flags[] = {
1512 "ts", /* temperature sensor */
1513 "fid", /* frequency id control */
1514 "vid", /* voltage id control */
1515 "ttp", /* thermal trip */
1516 "tm",
1517 "stc",
1518 NULL,
1519 /* nothing */ /* constant_tsc - moved to flags */
1520 };
1523 #ifdef CONFIG_SMP
1524 if (!cpu_online(c-cpu_data))
1525 return 0;
1526 #endif
1528 seq_printf(m,"processor\t: %u\n"
1529 "vendor_id\t: %s\n"
1530 "cpu family\t: %d\n"
1531 "model\t\t: %d\n"
1532 "model name\t: %s\n",
1533 (unsigned)(c-cpu_data),
1534 c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
1535 c->x86,
1536 (int)c->x86_model,
1537 c->x86_model_id[0] ? c->x86_model_id : "unknown");
1539 if (c->x86_mask || c->cpuid_level >= 0)
1540 seq_printf(m, "stepping\t: %d\n", c->x86_mask);
1541 else
1542 seq_printf(m, "stepping\t: unknown\n");
1544 if (cpu_has(c,X86_FEATURE_TSC)) {
1545 unsigned int freq = cpufreq_quick_get((unsigned)(c-cpu_data));
1546 if (!freq)
1547 freq = cpu_khz;
1548 seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
1549 freq / 1000, (freq % 1000));
1552 /* Cache size */
1553 if (c->x86_cache_size >= 0)
1554 seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
1556 #ifdef CONFIG_SMP
1557 if (smp_num_siblings * c->x86_max_cores > 1) {
1558 int cpu = c - cpu_data;
1559 seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
1560 seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[cpu]));
1561 seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
1562 seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
1564 #endif
1566 seq_printf(m,
1567 "fpu\t\t: yes\n"
1568 "fpu_exception\t: yes\n"
1569 "cpuid level\t: %d\n"
1570 "wp\t\t: yes\n"
1571 "flags\t\t:",
1572 c->cpuid_level);
1575 int i;
1576 for ( i = 0 ; i < 32*NCAPINTS ; i++ )
1577 if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
1578 seq_printf(m, " %s", x86_cap_flags[i]);
1581 seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
1582 c->loops_per_jiffy/(500000/HZ),
1583 (c->loops_per_jiffy/(5000/HZ)) % 100);
1585 if (c->x86_tlbsize > 0)
1586 seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
1587 seq_printf(m, "clflush size\t: %d\n", c->x86_clflush_size);
1588 seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
1590 seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
1591 c->x86_phys_bits, c->x86_virt_bits);
1593 seq_printf(m, "power management:");
1595 unsigned i;
1596 for (i = 0; i < 32; i++)
1597 if (c->x86_power & (1 << i)) {
1598 if (i < ARRAY_SIZE(x86_power_flags) &&
1599 x86_power_flags[i])
1600 seq_printf(m, "%s%s",
1601 x86_power_flags[i][0]?" ":"",
1602 x86_power_flags[i]);
1603 else
1604 seq_printf(m, " [%d]", i);
1608 seq_printf(m, "\n\n");
1610 return 0;
1613 static void *c_start(struct seq_file *m, loff_t *pos)
1615 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
1618 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1620 ++*pos;
1621 return c_start(m, pos);
1624 static void c_stop(struct seq_file *m, void *v)
1628 struct seq_operations cpuinfo_op = {
1629 .start =c_start,
1630 .next = c_next,
1631 .stop = c_stop,
1632 .show = show_cpuinfo,
1633 };
1635 #if defined(CONFIG_INPUT_PCSPKR) || defined(CONFIG_INPUT_PCSPKR_MODULE)
1636 #include <linux/platform_device.h>
1637 static __init int add_pcspkr(void)
1639 struct platform_device *pd;
1640 int ret;
1642 if (!is_initial_xendomain())
1643 return 0;
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