direct-io.hg

view linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c @ 11389:11626efd003c

[LINUX] /proc/iomem should not be initialised from pseudophysical e820 map.
This is because it should only contain real I/O memory address ranges,
otherwise we can get false conflicts between a real I/O range and a
'pseudophysical' RAM range, causing drivers to fail to work in a domU.
Also prevent kernel code/data being requested as iomem resources --
they are not contiguous in 'io memory' space so this would not make
sense.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Aug 31 03:05:40 2006 +0100 (2006-08-31)
parents dc883b5e906e
children d8bceca5f07d
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 *
9 * $Id$
10 */
12 /*
13 * This file handles the architecture-dependent parts of initialization
14 */
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/stddef.h>
21 #include <linux/unistd.h>
22 #include <linux/ptrace.h>
23 #include <linux/slab.h>
24 #include <linux/user.h>
25 #include <linux/a.out.h>
26 #include <linux/tty.h>
27 #include <linux/ioport.h>
28 #include <linux/delay.h>
29 #include <linux/config.h>
30 #include <linux/init.h>
31 #include <linux/initrd.h>
32 #include <linux/highmem.h>
33 #include <linux/bootmem.h>
34 #include <linux/module.h>
35 #include <asm/processor.h>
36 #include <linux/console.h>
37 #include <linux/seq_file.h>
38 #include <linux/crash_dump.h>
39 #include <linux/root_dev.h>
40 #include <linux/pci.h>
41 #include <linux/acpi.h>
42 #include <linux/kallsyms.h>
43 #include <linux/edd.h>
44 #include <linux/mmzone.h>
45 #include <linux/kexec.h>
46 #include <linux/cpufreq.h>
47 #include <linux/dmi.h>
48 #include <linux/dma-mapping.h>
50 #include <asm/mtrr.h>
51 #include <asm/uaccess.h>
52 #include <asm/system.h>
53 #include <asm/io.h>
54 #include <asm/smp.h>
55 #include <asm/msr.h>
56 #include <asm/desc.h>
57 #include <video/edid.h>
58 #include <asm/e820.h>
59 #include <asm/dma.h>
60 #include <asm/mpspec.h>
61 #include <asm/mmu_context.h>
62 #include <asm/bootsetup.h>
63 #include <asm/proto.h>
64 #include <asm/setup.h>
65 #include <asm/mach_apic.h>
66 #include <asm/numa.h>
67 #include <asm/swiotlb.h>
68 #include <asm/sections.h>
69 #include <asm/gart-mapping.h>
70 #ifdef CONFIG_XEN
71 #include <linux/percpu.h>
72 #include <xen/interface/physdev.h>
73 #include "setup_arch_pre.h"
74 #include <asm/hypervisor.h>
75 #include <xen/interface/nmi.h>
76 #include <xen/features.h>
77 #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
78 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
79 #include <asm/mach-xen/setup_arch_post.h>
80 #include <xen/interface/memory.h>
82 extern unsigned long start_pfn;
83 extern struct edid_info edid_info;
85 shared_info_t *HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
86 EXPORT_SYMBOL(HYPERVISOR_shared_info);
88 extern char hypercall_page[PAGE_SIZE];
89 EXPORT_SYMBOL(hypercall_page);
91 /* Allows setting of maximum possible memory size */
92 unsigned long xen_override_max_pfn;
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;
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 * Setup options
137 */
138 struct screen_info screen_info;
139 struct sys_desc_table_struct {
140 unsigned short length;
141 unsigned char table[0];
142 };
144 struct edid_info edid_info;
145 struct e820map e820;
147 extern int root_mountflags;
149 char command_line[COMMAND_LINE_SIZE];
151 struct resource standard_io_resources[] = {
152 { .name = "dma1", .start = 0x00, .end = 0x1f,
153 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
154 { .name = "pic1", .start = 0x20, .end = 0x21,
155 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
156 { .name = "timer0", .start = 0x40, .end = 0x43,
157 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
158 { .name = "timer1", .start = 0x50, .end = 0x53,
159 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
160 { .name = "keyboard", .start = 0x60, .end = 0x6f,
161 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
162 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
163 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
164 { .name = "pic2", .start = 0xa0, .end = 0xa1,
165 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
166 { .name = "dma2", .start = 0xc0, .end = 0xdf,
167 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
168 { .name = "fpu", .start = 0xf0, .end = 0xff,
169 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
170 };
172 #define STANDARD_IO_RESOURCES \
173 (sizeof standard_io_resources / sizeof standard_io_resources[0])
175 #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
177 struct resource data_resource = {
178 .name = "Kernel data",
179 .start = 0,
180 .end = 0,
181 .flags = IORESOURCE_RAM,
182 };
183 struct resource code_resource = {
184 .name = "Kernel code",
185 .start = 0,
186 .end = 0,
187 .flags = IORESOURCE_RAM,
188 };
190 #define IORESOURCE_ROM (IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM)
192 static struct resource system_rom_resource = {
193 .name = "System ROM",
194 .start = 0xf0000,
195 .end = 0xfffff,
196 .flags = IORESOURCE_ROM,
197 };
199 static struct resource extension_rom_resource = {
200 .name = "Extension ROM",
201 .start = 0xe0000,
202 .end = 0xeffff,
203 .flags = IORESOURCE_ROM,
204 };
206 static struct resource adapter_rom_resources[] = {
207 { .name = "Adapter ROM", .start = 0xc8000, .end = 0,
208 .flags = IORESOURCE_ROM },
209 { .name = "Adapter ROM", .start = 0, .end = 0,
210 .flags = IORESOURCE_ROM },
211 { .name = "Adapter ROM", .start = 0, .end = 0,
212 .flags = IORESOURCE_ROM },
213 { .name = "Adapter ROM", .start = 0, .end = 0,
214 .flags = IORESOURCE_ROM },
215 { .name = "Adapter ROM", .start = 0, .end = 0,
216 .flags = IORESOURCE_ROM },
217 { .name = "Adapter ROM", .start = 0, .end = 0,
218 .flags = IORESOURCE_ROM }
219 };
221 #define ADAPTER_ROM_RESOURCES \
222 (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
224 static struct resource video_rom_resource = {
225 .name = "Video ROM",
226 .start = 0xc0000,
227 .end = 0xc7fff,
228 .flags = IORESOURCE_ROM,
229 };
231 static struct resource video_ram_resource = {
232 .name = "Video RAM area",
233 .start = 0xa0000,
234 .end = 0xbffff,
235 .flags = IORESOURCE_RAM,
236 };
238 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
240 static int __init romchecksum(unsigned char *rom, unsigned long length)
241 {
242 unsigned char *p, sum = 0;
244 for (p = rom; p < rom + length; p++)
245 sum += *p;
246 return sum == 0;
247 }
249 static void __init probe_roms(void)
250 {
251 unsigned long start, length, upper;
252 unsigned char *rom;
253 int i;
255 #ifdef CONFIG_XEN
256 /* Nothing to do if not running in dom0. */
257 if (!is_initial_xendomain())
258 return;
259 #endif
261 /* video rom */
262 upper = adapter_rom_resources[0].start;
263 for (start = video_rom_resource.start; start < upper; start += 2048) {
264 rom = isa_bus_to_virt(start);
265 if (!romsignature(rom))
266 continue;
268 video_rom_resource.start = start;
270 /* 0 < length <= 0x7f * 512, historically */
271 length = rom[2] * 512;
273 /* if checksum okay, trust length byte */
274 if (length && romchecksum(rom, length))
275 video_rom_resource.end = start + length - 1;
277 request_resource(&iomem_resource, &video_rom_resource);
278 break;
279 }
281 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
282 if (start < upper)
283 start = upper;
285 /* system rom */
286 request_resource(&iomem_resource, &system_rom_resource);
287 upper = system_rom_resource.start;
289 /* check for extension rom (ignore length byte!) */
290 rom = isa_bus_to_virt(extension_rom_resource.start);
291 if (romsignature(rom)) {
292 length = extension_rom_resource.end - extension_rom_resource.start + 1;
293 if (romchecksum(rom, length)) {
294 request_resource(&iomem_resource, &extension_rom_resource);
295 upper = extension_rom_resource.start;
296 }
297 }
299 /* check for adapter roms on 2k boundaries */
300 for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
301 rom = isa_bus_to_virt(start);
302 if (!romsignature(rom))
303 continue;
305 /* 0 < length <= 0x7f * 512, historically */
306 length = rom[2] * 512;
308 /* but accept any length that fits if checksum okay */
309 if (!length || start + length > upper || !romchecksum(rom, length))
310 continue;
312 adapter_rom_resources[i].start = start;
313 adapter_rom_resources[i].end = start + length - 1;
314 request_resource(&iomem_resource, &adapter_rom_resources[i]);
316 start = adapter_rom_resources[i++].end & ~2047UL;
317 }
318 }
320 static __init void parse_cmdline_early (char ** cmdline_p)
321 {
322 char c = ' ', *to = command_line, *from = COMMAND_LINE;
323 int len = 0;
324 int userdef = 0;
326 for (;;) {
327 if (c != ' ')
328 goto next_char;
330 #ifdef CONFIG_SMP
331 /*
332 * If the BIOS enumerates physical processors before logical,
333 * maxcpus=N at enumeration-time can be used to disable HT.
334 */
335 else if (!memcmp(from, "maxcpus=", 8)) {
336 extern unsigned int maxcpus;
338 maxcpus = simple_strtoul(from + 8, NULL, 0);
339 }
340 #endif
341 #ifdef CONFIG_ACPI
342 /* "acpi=off" disables both ACPI table parsing and interpreter init */
343 if (!memcmp(from, "acpi=off", 8))
344 disable_acpi();
346 if (!memcmp(from, "acpi=force", 10)) {
347 /* add later when we do DMI horrors: */
348 acpi_force = 1;
349 acpi_disabled = 0;
350 }
352 /* acpi=ht just means: do ACPI MADT parsing
353 at bootup, but don't enable the full ACPI interpreter */
354 if (!memcmp(from, "acpi=ht", 7)) {
355 if (!acpi_force)
356 disable_acpi();
357 acpi_ht = 1;
358 }
359 else if (!memcmp(from, "pci=noacpi", 10))
360 acpi_disable_pci();
361 else if (!memcmp(from, "acpi=noirq", 10))
362 acpi_noirq_set();
364 else if (!memcmp(from, "acpi_sci=edge", 13))
365 acpi_sci_flags.trigger = 1;
366 else if (!memcmp(from, "acpi_sci=level", 14))
367 acpi_sci_flags.trigger = 3;
368 else if (!memcmp(from, "acpi_sci=high", 13))
369 acpi_sci_flags.polarity = 1;
370 else if (!memcmp(from, "acpi_sci=low", 12))
371 acpi_sci_flags.polarity = 3;
373 /* acpi=strict disables out-of-spec workarounds */
374 else if (!memcmp(from, "acpi=strict", 11)) {
375 acpi_strict = 1;
376 }
377 #ifdef CONFIG_X86_IO_APIC
378 else if (!memcmp(from, "acpi_skip_timer_override", 24))
379 acpi_skip_timer_override = 1;
380 #endif
381 #endif
383 #ifndef CONFIG_XEN
384 if (!memcmp(from, "nolapic", 7) ||
385 !memcmp(from, "disableapic", 11))
386 disable_apic = 1;
388 /* Don't confuse with noapictimer */
389 if (!memcmp(from, "noapic", 6) &&
390 (from[6] == ' ' || from[6] == 0))
391 skip_ioapic_setup = 1;
393 /* Make sure to not confuse with apic= */
394 if (!memcmp(from, "apic", 4) &&
395 (from[4] == ' ' || from[4] == 0)) {
396 skip_ioapic_setup = 0;
397 ioapic_force = 1;
398 }
399 #endif
401 if (!memcmp(from, "mem=", 4))
402 parse_memopt(from+4, &from);
404 if (!memcmp(from, "memmap=", 7)) {
405 /* exactmap option is for used defined memory */
406 if (!memcmp(from+7, "exactmap", 8)) {
407 #ifdef CONFIG_CRASH_DUMP
408 /* If we are doing a crash dump, we
409 * still need to know the real mem
410 * size before original memory map is
411 * reset.
412 */
413 saved_max_pfn = e820_end_of_ram();
414 #endif
415 from += 8+7;
416 end_pfn_map = 0;
417 e820.nr_map = 0;
418 userdef = 1;
419 }
420 else {
421 parse_memmapopt(from+7, &from);
422 userdef = 1;
423 }
424 }
426 #ifdef CONFIG_NUMA
427 if (!memcmp(from, "numa=", 5))
428 numa_setup(from+5);
429 #endif
431 if (!memcmp(from,"iommu=",6)) {
432 iommu_setup(from+6);
433 }
435 if (!memcmp(from,"oops=panic", 10))
436 panic_on_oops = 1;
438 if (!memcmp(from, "noexec=", 7))
439 nonx_setup(from + 7);
441 #ifdef CONFIG_KEXEC
442 /* crashkernel=size@addr specifies the location to reserve for
443 * a crash kernel. By reserving this memory we guarantee
444 * that linux never set's it up as a DMA target.
445 * Useful for holding code to do something appropriate
446 * after a kernel panic.
447 */
448 else if (!memcmp(from, "crashkernel=", 12)) {
449 unsigned long size, base;
450 size = memparse(from+12, &from);
451 if (*from == '@') {
452 base = memparse(from+1, &from);
453 /* FIXME: Do I want a sanity check
454 * to validate the memory range?
455 */
456 crashk_res.start = base;
457 crashk_res.end = base + size - 1;
458 }
459 }
460 #endif
462 #ifdef CONFIG_PROC_VMCORE
463 /* elfcorehdr= specifies the location of elf core header
464 * stored by the crashed kernel. This option will be passed
465 * by kexec loader to the capture kernel.
466 */
467 else if(!memcmp(from, "elfcorehdr=", 11))
468 elfcorehdr_addr = memparse(from+11, &from);
469 #endif
471 #if defined(CONFIG_HOTPLUG_CPU) && !defined(CONFIG_XEN)
472 else if (!memcmp(from, "additional_cpus=", 16))
473 setup_additional_cpus(from+16);
474 #endif
476 next_char:
477 c = *(from++);
478 if (!c)
479 break;
480 if (COMMAND_LINE_SIZE <= ++len)
481 break;
482 *(to++) = c;
483 }
484 if (userdef) {
485 printk(KERN_INFO "user-defined physical RAM map:\n");
486 e820_print_map("user");
487 }
488 *to = '\0';
489 *cmdline_p = command_line;
490 }
492 #ifndef CONFIG_NUMA
493 static void __init
494 contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
495 {
496 unsigned long bootmap_size, bootmap;
498 bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
499 bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
500 if (bootmap == -1L)
501 panic("Cannot find bootmem map of size %ld\n",bootmap_size);
502 bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
503 #ifdef CONFIG_XEN
504 e820_bootmem_free(NODE_DATA(0), 0, xen_start_info->nr_pages<<PAGE_SHIFT);
505 #else
506 e820_bootmem_free(NODE_DATA(0), 0, end_pfn << PAGE_SHIFT);
507 #endif
508 reserve_bootmem(bootmap, bootmap_size);
509 }
510 #endif
512 /* Use inline assembly to define this because the nops are defined
513 as inline assembly strings in the include files and we cannot
514 get them easily into strings. */
515 asm("\t.data\nk8nops: "
516 K8_NOP1 K8_NOP2 K8_NOP3 K8_NOP4 K8_NOP5 K8_NOP6
517 K8_NOP7 K8_NOP8);
519 extern unsigned char k8nops[];
520 static unsigned char *k8_nops[ASM_NOP_MAX+1] = {
521 NULL,
522 k8nops,
523 k8nops + 1,
524 k8nops + 1 + 2,
525 k8nops + 1 + 2 + 3,
526 k8nops + 1 + 2 + 3 + 4,
527 k8nops + 1 + 2 + 3 + 4 + 5,
528 k8nops + 1 + 2 + 3 + 4 + 5 + 6,
529 k8nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
530 };
532 extern char __vsyscall_0;
534 /* Replace instructions with better alternatives for this CPU type.
536 This runs before SMP is initialized to avoid SMP problems with
537 self modifying code. This implies that assymetric systems where
538 APs have less capabilities than the boot processor are not handled.
539 In this case boot with "noreplacement". */
540 void apply_alternatives(void *start, void *end)
541 {
542 struct alt_instr *a;
543 int diff, i, k;
544 for (a = start; (void *)a < end; a++) {
545 u8 *instr;
547 if (!boot_cpu_has(a->cpuid))
548 continue;
550 BUG_ON(a->replacementlen > a->instrlen);
551 instr = a->instr;
552 /* vsyscall code is not mapped yet. resolve it manually. */
553 if (instr >= (u8 *)VSYSCALL_START && instr < (u8*)VSYSCALL_END)
554 instr -= VSYSCALL_START - (unsigned long)&__vsyscall_0;
555 __inline_memcpy(instr, a->replacement, a->replacementlen);
556 diff = a->instrlen - a->replacementlen;
558 /* Pad the rest with nops */
559 for (i = a->replacementlen; diff > 0; diff -= k, i += k) {
560 k = diff;
561 if (k > ASM_NOP_MAX)
562 k = ASM_NOP_MAX;
563 __inline_memcpy(instr + i, k8_nops[k], k);
564 }
565 }
566 }
568 static int no_replacement __initdata = 0;
570 void __init alternative_instructions(void)
571 {
572 extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
573 if (no_replacement)
574 return;
575 apply_alternatives(__alt_instructions, __alt_instructions_end);
576 }
578 static int __init noreplacement_setup(char *s)
579 {
580 no_replacement = 1;
581 return 0;
582 }
584 __setup("noreplacement", noreplacement_setup);
586 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
587 struct edd edd;
588 #ifdef CONFIG_EDD_MODULE
589 EXPORT_SYMBOL(edd);
590 #endif
591 /**
592 * copy_edd() - Copy the BIOS EDD information
593 * from boot_params into a safe place.
594 *
595 */
596 static inline void copy_edd(void)
597 {
598 memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
599 memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
600 edd.mbr_signature_nr = EDD_MBR_SIG_NR;
601 edd.edd_info_nr = EDD_NR;
602 }
603 #else
604 static inline void copy_edd(void)
605 {
606 }
607 #endif
609 #ifndef CONFIG_XEN
610 #define EBDA_ADDR_POINTER 0x40E
611 static void __init reserve_ebda_region(void)
612 {
613 unsigned int addr;
614 /**
615 * there is a real-mode segmented pointer pointing to the
616 * 4K EBDA area at 0x40E
617 */
618 addr = *(unsigned short *)phys_to_virt(EBDA_ADDR_POINTER);
619 addr <<= 4;
620 if (addr)
621 reserve_bootmem_generic(addr, PAGE_SIZE);
622 }
623 #endif
625 void __init setup_arch(char **cmdline_p)
626 {
627 unsigned long kernel_end;
628 struct e820entry *machine_e820;
629 struct xen_memory_map memmap;
631 #ifdef CONFIG_XEN
632 /* Register a call for panic conditions. */
633 notifier_chain_register(&panic_notifier_list, &xen_panic_block);
635 ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
636 kernel_end = 0; /* dummy */
637 screen_info = SCREEN_INFO;
639 if (is_initial_xendomain()) {
640 /* This is drawn from a dump from vgacon:startup in
641 * standard Linux. */
642 screen_info.orig_video_mode = 3;
643 screen_info.orig_video_isVGA = 1;
644 screen_info.orig_video_lines = 25;
645 screen_info.orig_video_cols = 80;
646 screen_info.orig_video_ega_bx = 3;
647 screen_info.orig_video_points = 16;
648 if (xen_start_info->console.dom0.info_size >=
649 sizeof(struct dom0_vga_console_info)) {
650 const struct dom0_vga_console_info *info =
651 (struct dom0_vga_console_info *)(
652 (char *)xen_start_info +
653 xen_start_info->console.dom0.info_off);
654 screen_info.orig_video_mode = info->txt_mode;
655 screen_info.orig_video_isVGA = info->video_type;
656 screen_info.orig_video_lines = info->video_height;
657 screen_info.orig_video_cols = info->video_width;
658 screen_info.orig_video_points = info->txt_points;
659 screen_info.lfb_width = info->video_width;
660 screen_info.lfb_height = info->video_height;
661 screen_info.lfb_depth = info->lfb_depth;
662 screen_info.lfb_base = info->lfb_base;
663 screen_info.lfb_size = info->lfb_size;
664 screen_info.lfb_linelength = info->lfb_linelen;
665 screen_info.red_size = info->red_size;
666 screen_info.red_pos = info->red_pos;
667 screen_info.green_size = info->green_size;
668 screen_info.green_pos = info->green_pos;
669 screen_info.blue_size = info->blue_size;
670 screen_info.blue_pos = info->blue_pos;
671 screen_info.rsvd_size = info->rsvd_size;
672 screen_info.rsvd_pos = info->rsvd_pos;
673 }
674 screen_info.orig_y = screen_info.orig_video_lines - 1;
675 xen_start_info->console.domU.mfn = 0;
676 xen_start_info->console.domU.evtchn = 0;
677 } else
678 screen_info.orig_video_isVGA = 0;
680 edid_info = EDID_INFO;
681 saved_video_mode = SAVED_VIDEO_MODE;
682 bootloader_type = LOADER_TYPE;
684 #ifdef CONFIG_BLK_DEV_RAM
685 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
686 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
687 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
690 #endif
692 setup_xen_features();
694 HYPERVISOR_vm_assist(VMASST_CMD_enable,
695 VMASST_TYPE_writable_pagetables);
697 ARCH_SETUP
698 #else
699 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
700 screen_info = SCREEN_INFO;
701 edid_info = EDID_INFO;
702 saved_video_mode = SAVED_VIDEO_MODE;
703 bootloader_type = LOADER_TYPE;
705 #ifdef CONFIG_BLK_DEV_RAM
706 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
707 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
708 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
709 #endif
710 #endif /* !CONFIG_XEN */
711 setup_memory_region();
712 copy_edd();
714 if (!MOUNT_ROOT_RDONLY)
715 root_mountflags &= ~MS_RDONLY;
716 init_mm.start_code = (unsigned long) &_text;
717 init_mm.end_code = (unsigned long) &_etext;
718 init_mm.end_data = (unsigned long) &_edata;
719 init_mm.brk = (unsigned long) &_end;
721 code_resource.start = virt_to_phys(&_text);
722 code_resource.end = virt_to_phys(&_etext)-1;
723 data_resource.start = virt_to_phys(&_etext);
724 data_resource.end = virt_to_phys(&_edata)-1;
726 parse_cmdline_early(cmdline_p);
728 early_identify_cpu(&boot_cpu_data);
730 /*
731 * partially used pages are not usable - thus
732 * we are rounding upwards:
733 */
734 end_pfn = e820_end_of_ram();
736 check_efer();
738 init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
740 #ifdef CONFIG_ACPI_NUMA
741 /*
742 * Parse SRAT to discover nodes.
743 */
744 acpi_numa_init();
745 #endif
747 #ifdef CONFIG_NUMA
748 numa_initmem_init(0, end_pfn);
749 #else
750 contig_initmem_init(0, end_pfn);
751 #endif
753 /* Reserve direct mapping */
754 reserve_bootmem_generic(table_start << PAGE_SHIFT,
755 (table_end - table_start) << PAGE_SHIFT);
757 /* reserve kernel */
758 kernel_end = round_up(__pa_symbol(&_end),PAGE_SIZE);
759 reserve_bootmem_generic(HIGH_MEMORY, kernel_end - HIGH_MEMORY);
761 #ifdef CONFIG_XEN
762 /* reserve physmap, start info and initial page tables */
763 reserve_bootmem(kernel_end, (table_start<<PAGE_SHIFT)-kernel_end);
764 #else
765 /*
766 * reserve physical page 0 - it's a special BIOS page on many boxes,
767 * enabling clean reboots, SMP operation, laptop functions.
768 */
769 reserve_bootmem_generic(0, PAGE_SIZE);
771 /* reserve ebda region */
772 reserve_ebda_region();
773 #endif
775 #ifdef CONFIG_SMP
776 /*
777 * But first pinch a few for the stack/trampoline stuff
778 * FIXME: Don't need the extra page at 4K, but need to fix
779 * trampoline before removing it. (see the GDT stuff)
780 */
781 reserve_bootmem_generic(PAGE_SIZE, PAGE_SIZE);
783 /* Reserve SMP trampoline */
784 reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, PAGE_SIZE);
785 #endif
787 #ifdef CONFIG_ACPI_SLEEP
788 /*
789 * Reserve low memory region for sleep support.
790 */
791 acpi_reserve_bootmem();
792 #endif
793 #ifdef CONFIG_XEN
794 #ifdef CONFIG_BLK_DEV_INITRD
795 if (xen_start_info->mod_start) {
796 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
797 /*reserve_bootmem_generic(INITRD_START, INITRD_SIZE);*/
798 initrd_start = INITRD_START + PAGE_OFFSET;
799 initrd_end = initrd_start+INITRD_SIZE;
800 initrd_below_start_ok = 1;
801 } else {
802 printk(KERN_ERR "initrd extends beyond end of memory "
803 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
804 (unsigned long)(INITRD_START + INITRD_SIZE),
805 (unsigned long)(end_pfn << PAGE_SHIFT));
806 initrd_start = 0;
807 }
808 }
809 #endif
810 #else /* CONFIG_XEN */
811 #ifdef CONFIG_BLK_DEV_INITRD
812 if (LOADER_TYPE && INITRD_START) {
813 if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
814 reserve_bootmem_generic(INITRD_START, INITRD_SIZE);
815 initrd_start =
816 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
817 initrd_end = initrd_start+INITRD_SIZE;
818 }
819 else {
820 printk(KERN_ERR "initrd extends beyond end of memory "
821 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
822 (unsigned long)(INITRD_START + INITRD_SIZE),
823 (unsigned long)(end_pfn << PAGE_SHIFT));
824 initrd_start = 0;
825 }
826 }
827 #endif
828 #endif /* !CONFIG_XEN */
829 #ifdef CONFIG_KEXEC
830 if (crashk_res.start != crashk_res.end) {
831 reserve_bootmem(crashk_res.start,
832 crashk_res.end - crashk_res.start + 1);
833 }
834 #endif
836 paging_init();
837 #ifdef CONFIG_X86_LOCAL_APIC
838 /*
839 * Find and reserve possible boot-time SMP configuration:
840 */
841 find_smp_config();
842 #endif
843 #ifdef CONFIG_XEN
844 {
845 int i, j, k, fpp;
847 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
848 /* Make sure we have a large enough P->M table. */
849 phys_to_machine_mapping = alloc_bootmem_pages(
850 end_pfn * sizeof(unsigned long));
851 memset(phys_to_machine_mapping, ~0,
852 end_pfn * sizeof(unsigned long));
853 memcpy(phys_to_machine_mapping,
854 (unsigned long *)xen_start_info->mfn_list,
855 xen_start_info->nr_pages * sizeof(unsigned long));
856 free_bootmem(
857 __pa(xen_start_info->mfn_list),
858 PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
859 sizeof(unsigned long))));
861 /*
862 * Initialise the list of the frames that specify the
863 * list of frames that make up the p2m table. Used by
864 * save/restore.
865 */
866 pfn_to_mfn_frame_list_list = alloc_bootmem_pages(PAGE_SIZE);
867 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
868 virt_to_mfn(pfn_to_mfn_frame_list_list);
870 fpp = PAGE_SIZE/sizeof(unsigned long);
871 for (i=0, j=0, k=-1; i< end_pfn; i+=fpp, j++) {
872 if ((j % fpp) == 0) {
873 k++;
874 BUG_ON(k>=fpp);
875 pfn_to_mfn_frame_list[k] =
876 alloc_bootmem_pages(PAGE_SIZE);
877 pfn_to_mfn_frame_list_list[k] =
878 virt_to_mfn(pfn_to_mfn_frame_list[k]);
879 j=0;
880 }
881 pfn_to_mfn_frame_list[k][j] =
882 virt_to_mfn(&phys_to_machine_mapping[i]);
883 }
884 HYPERVISOR_shared_info->arch.max_pfn = end_pfn;
885 }
887 }
889 if (!is_initial_xendomain()) {
890 acpi_disabled = 1;
891 #ifdef CONFIG_ACPI
892 acpi_ht = 0;
893 #endif
894 }
895 #endif
897 #ifndef CONFIG_XEN
898 check_ioapic();
899 #endif
901 zap_low_mappings(0);
903 #ifdef CONFIG_ACPI
904 /*
905 * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
906 * Call this early for SRAT node setup.
907 */
908 acpi_boot_table_init();
910 /*
911 * Read APIC and some other early information from ACPI tables.
912 */
913 acpi_boot_init();
914 #endif
916 init_cpu_to_node();
918 #ifdef CONFIG_X86_LOCAL_APIC
919 /*
920 * get boot-time SMP configuration:
921 */
922 if (smp_found_config)
923 get_smp_config();
924 #ifndef CONFIG_XEN
925 init_apic_mappings();
926 #endif
927 #endif
928 #if defined(CONFIG_XEN) && defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU)
929 prefill_possible_map();
930 #endif
932 /*
933 * Request address space for all standard RAM and ROM resources
934 * and also for regions reported as reserved by the e820.
935 */
936 probe_roms();
937 #ifdef CONFIG_XEN
938 if (is_initial_xendomain()) {
939 machine_e820 = alloc_bootmem_low_pages(PAGE_SIZE);
941 memmap.nr_entries = E820MAX;
942 set_xen_guest_handle(memmap.buffer, machine_e820);
944 BUG_ON(HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap));
946 e820_reserve_resources(machine_e820, memmap.nr_entries);
947 }
948 #else
949 e820_reserve_resources(e820.map, e820.nr_map);
950 #endif
952 request_resource(&iomem_resource, &video_ram_resource);
954 {
955 unsigned i;
956 /* request I/O space for devices used on all i[345]86 PCs */
957 for (i = 0; i < STANDARD_IO_RESOURCES; i++)
958 request_resource(&ioport_resource, &standard_io_resources[i]);
959 }
961 #ifdef CONFIG_XEN
962 if (is_initial_xendomain()) {
963 e820_setup_gap(machine_e820, memmap.nr_entries);
964 free_bootmem(__pa(machine_e820), PAGE_SIZE);
965 }
966 #else
967 e820_setup_gap(e820.map, e820.nr_map);
968 #endif
970 #ifdef CONFIG_GART_IOMMU
971 iommu_hole_init();
972 #endif
974 #ifdef CONFIG_XEN
975 {
976 struct physdev_set_iopl set_iopl;
978 set_iopl.iopl = 1;
979 HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
981 if (is_initial_xendomain()) {
982 #ifdef CONFIG_VT
983 #if defined(CONFIG_VGA_CONSOLE)
984 conswitchp = &vga_con;
985 #elif defined(CONFIG_DUMMY_CONSOLE)
986 conswitchp = &dummy_con;
987 #endif
988 #endif
989 } else {
990 extern int console_use_vt;
991 console_use_vt = 0;
992 }
993 }
994 #else /* CONFIG_XEN */
996 #ifdef CONFIG_VT
997 #if defined(CONFIG_VGA_CONSOLE)
998 conswitchp = &vga_con;
999 #elif defined(CONFIG_DUMMY_CONSOLE)
1000 conswitchp = &dummy_con;
1001 #endif
1002 #endif
1004 #endif /* !CONFIG_XEN */
1007 #ifdef CONFIG_XEN
1008 static int
1009 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
1011 HYPERVISOR_shutdown(SHUTDOWN_crash);
1012 /* we're never actually going to get here... */
1013 return NOTIFY_DONE;
1015 #endif /* !CONFIG_XEN */
1018 static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
1020 unsigned int *v;
1022 if (c->extended_cpuid_level < 0x80000004)
1023 return 0;
1025 v = (unsigned int *) c->x86_model_id;
1026 cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
1027 cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
1028 cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
1029 c->x86_model_id[48] = 0;
1030 return 1;
1034 static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
1036 unsigned int n, dummy, eax, ebx, ecx, edx;
1038 n = c->extended_cpuid_level;
1040 if (n >= 0x80000005) {
1041 cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
1042 printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
1043 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
1044 c->x86_cache_size=(ecx>>24)+(edx>>24);
1045 /* On K8 L1 TLB is inclusive, so don't count it */
1046 c->x86_tlbsize = 0;
1049 if (n >= 0x80000006) {
1050 cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
1051 ecx = cpuid_ecx(0x80000006);
1052 c->x86_cache_size = ecx >> 16;
1053 c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
1055 printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
1056 c->x86_cache_size, ecx & 0xFF);
1059 if (n >= 0x80000007)
1060 cpuid(0x80000007, &dummy, &dummy, &dummy, &c->x86_power);
1061 if (n >= 0x80000008) {
1062 cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
1063 c->x86_virt_bits = (eax >> 8) & 0xff;
1064 c->x86_phys_bits = eax & 0xff;
1068 #ifdef CONFIG_NUMA
1069 static int nearby_node(int apicid)
1071 int i;
1072 for (i = apicid - 1; i >= 0; i--) {
1073 int node = apicid_to_node[i];
1074 if (node != NUMA_NO_NODE && node_online(node))
1075 return node;
1077 for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
1078 int node = apicid_to_node[i];
1079 if (node != NUMA_NO_NODE && node_online(node))
1080 return node;
1082 return first_node(node_online_map); /* Shouldn't happen */
1084 #endif
1086 /*
1087 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
1088 * Assumes number of cores is a power of two.
1089 */
1090 static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
1092 #ifdef CONFIG_SMP
1093 int cpu = smp_processor_id();
1094 unsigned bits;
1095 #ifdef CONFIG_NUMA
1096 int node = 0;
1097 unsigned apicid = phys_proc_id[cpu];
1098 #endif
1100 bits = 0;
1101 while ((1 << bits) < c->x86_max_cores)
1102 bits++;
1104 /* Low order bits define the core id (index of core in socket) */
1105 cpu_core_id[cpu] = phys_proc_id[cpu] & ((1 << bits)-1);
1106 /* Convert the APIC ID into the socket ID */
1107 phys_proc_id[cpu] >>= bits;
1109 #ifdef CONFIG_NUMA
1110 node = phys_proc_id[cpu];
1111 if (apicid_to_node[apicid] != NUMA_NO_NODE)
1112 node = apicid_to_node[apicid];
1113 if (!node_online(node)) {
1114 /* Two possibilities here:
1115 - The CPU is missing memory and no node was created.
1116 In that case try picking one from a nearby CPU
1117 - The APIC IDs differ from the HyperTransport node IDs
1118 which the K8 northbridge parsing fills in.
1119 Assume they are all increased by a constant offset,
1120 but in the same order as the HT nodeids.
1121 If that doesn't result in a usable node fall back to the
1122 path for the previous case. */
1123 int ht_nodeid = apicid - (phys_proc_id[0] << bits);
1124 if (ht_nodeid >= 0 &&
1125 apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
1126 node = apicid_to_node[ht_nodeid];
1127 /* Pick a nearby node */
1128 if (!node_online(node))
1129 node = nearby_node(apicid);
1131 numa_set_node(cpu, node);
1133 printk(KERN_INFO "CPU %d(%d) -> Node %d -> Core %d\n",
1134 cpu, c->x86_max_cores, node, cpu_core_id[cpu]);
1135 #endif
1136 #endif
1139 static int __init init_amd(struct cpuinfo_x86 *c)
1141 int r;
1142 unsigned level;
1144 #ifdef CONFIG_SMP
1145 unsigned long value;
1147 /*
1148 * Disable TLB flush filter by setting HWCR.FFDIS on K8
1149 * bit 6 of msr C001_0015
1151 * Errata 63 for SH-B3 steppings
1152 * Errata 122 for all steppings (F+ have it disabled by default)
1153 */
1154 if (c->x86 == 15) {
1155 rdmsrl(MSR_K8_HWCR, value);
1156 value |= 1 << 6;
1157 wrmsrl(MSR_K8_HWCR, value);
1159 #endif
1161 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
1162 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
1163 clear_bit(0*32+31, &c->x86_capability);
1165 /* On C+ stepping K8 rep microcode works well for copy/memset */
1166 level = cpuid_eax(1);
1167 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58))
1168 set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
1170 /* Enable workaround for FXSAVE leak */
1171 if (c->x86 >= 6)
1172 set_bit(X86_FEATURE_FXSAVE_LEAK, &c->x86_capability);
1174 r = get_model_name(c);
1175 if (!r) {
1176 switch (c->x86) {
1177 case 15:
1178 /* Should distinguish Models here, but this is only
1179 a fallback anyways. */
1180 strcpy(c->x86_model_id, "Hammer");
1181 break;
1184 display_cacheinfo(c);
1186 /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
1187 if (c->x86_power & (1<<8))
1188 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1190 if (c->extended_cpuid_level >= 0x80000008) {
1191 c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
1192 if (c->x86_max_cores & (c->x86_max_cores - 1))
1193 c->x86_max_cores = 1;
1195 amd_detect_cmp(c);
1198 return r;
1201 static void __cpuinit detect_ht(struct cpuinfo_x86 *c)
1203 #ifdef CONFIG_SMP
1204 u32 eax, ebx, ecx, edx;
1205 int index_msb, core_bits;
1206 int cpu = smp_processor_id();
1208 cpuid(1, &eax, &ebx, &ecx, &edx);
1210 c->apicid = phys_pkg_id(0);
1212 if (!cpu_has(c, X86_FEATURE_HT) || cpu_has(c, X86_FEATURE_CMP_LEGACY))
1213 return;
1215 smp_num_siblings = (ebx & 0xff0000) >> 16;
1217 if (smp_num_siblings == 1) {
1218 printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
1219 } else if (smp_num_siblings > 1 ) {
1221 if (smp_num_siblings > NR_CPUS) {
1222 printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
1223 smp_num_siblings = 1;
1224 return;
1227 index_msb = get_count_order(smp_num_siblings);
1228 phys_proc_id[cpu] = phys_pkg_id(index_msb);
1230 printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
1231 phys_proc_id[cpu]);
1233 smp_num_siblings = smp_num_siblings / c->x86_max_cores;
1235 index_msb = get_count_order(smp_num_siblings) ;
1237 core_bits = get_count_order(c->x86_max_cores);
1239 cpu_core_id[cpu] = phys_pkg_id(index_msb) &
1240 ((1 << core_bits) - 1);
1242 if (c->x86_max_cores > 1)
1243 printk(KERN_INFO "CPU: Processor Core ID: %d\n",
1244 cpu_core_id[cpu]);
1246 #endif
1249 /*
1250 * find out the number of processor cores on the die
1251 */
1252 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
1254 unsigned int eax;
1256 if (c->cpuid_level < 4)
1257 return 1;
1259 __asm__("cpuid"
1260 : "=a" (eax)
1261 : "0" (4), "c" (0)
1262 : "bx", "dx");
1264 if (eax & 0x1f)
1265 return ((eax >> 26) + 1);
1266 else
1267 return 1;
1270 static void srat_detect_node(void)
1272 #ifdef CONFIG_NUMA
1273 unsigned node;
1274 int cpu = smp_processor_id();
1276 /* Don't do the funky fallback heuristics the AMD version employs
1277 for now. */
1278 node = apicid_to_node[hard_smp_processor_id()];
1279 if (node == NUMA_NO_NODE)
1280 node = 0;
1281 numa_set_node(cpu, node);
1283 if (acpi_numa > 0)
1284 printk(KERN_INFO "CPU %d -> Node %d\n", cpu, node);
1285 #endif
1288 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
1290 /* Cache sizes */
1291 unsigned n;
1293 init_intel_cacheinfo(c);
1294 n = c->extended_cpuid_level;
1295 if (n >= 0x80000008) {
1296 unsigned eax = cpuid_eax(0x80000008);
1297 c->x86_virt_bits = (eax >> 8) & 0xff;
1298 c->x86_phys_bits = eax & 0xff;
1299 /* CPUID workaround for Intel 0F34 CPU */
1300 if (c->x86_vendor == X86_VENDOR_INTEL &&
1301 c->x86 == 0xF && c->x86_model == 0x3 &&
1302 c->x86_mask == 0x4)
1303 c->x86_phys_bits = 36;
1306 if (c->x86 == 15)
1307 c->x86_cache_alignment = c->x86_clflush_size * 2;
1308 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
1309 (c->x86 == 0x6 && c->x86_model >= 0x0e))
1310 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1311 set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
1312 c->x86_max_cores = intel_num_cpu_cores(c);
1314 srat_detect_node();
1317 static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
1319 char *v = c->x86_vendor_id;
1321 if (!strcmp(v, "AuthenticAMD"))
1322 c->x86_vendor = X86_VENDOR_AMD;
1323 else if (!strcmp(v, "GenuineIntel"))
1324 c->x86_vendor = X86_VENDOR_INTEL;
1325 else
1326 c->x86_vendor = X86_VENDOR_UNKNOWN;
1329 struct cpu_model_info {
1330 int vendor;
1331 int family;
1332 char *model_names[16];
1333 };
1335 /* Do some early cpuid on the boot CPU to get some parameter that are
1336 needed before check_bugs. Everything advanced is in identify_cpu
1337 below. */
1338 void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
1340 u32 tfms;
1342 c->loops_per_jiffy = loops_per_jiffy;
1343 c->x86_cache_size = -1;
1344 c->x86_vendor = X86_VENDOR_UNKNOWN;
1345 c->x86_model = c->x86_mask = 0; /* So far unknown... */
1346 c->x86_vendor_id[0] = '\0'; /* Unset */
1347 c->x86_model_id[0] = '\0'; /* Unset */
1348 c->x86_clflush_size = 64;
1349 c->x86_cache_alignment = c->x86_clflush_size;
1350 c->x86_max_cores = 1;
1351 c->extended_cpuid_level = 0;
1352 memset(&c->x86_capability, 0, sizeof c->x86_capability);
1354 /* Get vendor name */
1355 cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
1356 (unsigned int *)&c->x86_vendor_id[0],
1357 (unsigned int *)&c->x86_vendor_id[8],
1358 (unsigned int *)&c->x86_vendor_id[4]);
1360 get_cpu_vendor(c);
1362 /* Initialize the standard set of capabilities */
1363 /* Note that the vendor-specific code below might override */
1365 /* Intel-defined flags: level 0x00000001 */
1366 if (c->cpuid_level >= 0x00000001) {
1367 __u32 misc;
1368 cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
1369 &c->x86_capability[0]);
1370 c->x86 = (tfms >> 8) & 0xf;
1371 c->x86_model = (tfms >> 4) & 0xf;
1372 c->x86_mask = tfms & 0xf;
1373 if (c->x86 == 0xf)
1374 c->x86 += (tfms >> 20) & 0xff;
1375 if (c->x86 >= 0x6)
1376 c->x86_model += ((tfms >> 16) & 0xF) << 4;
1377 if (c->x86_capability[0] & (1<<19))
1378 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
1379 } else {
1380 /* Have CPUID level 0 only - unheard of */
1381 c->x86 = 4;
1384 #ifdef CONFIG_SMP
1385 phys_proc_id[smp_processor_id()] = (cpuid_ebx(1) >> 24) & 0xff;
1386 #endif
1389 /*
1390 * This does the hard work of actually picking apart the CPU stuff...
1391 */
1392 void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
1394 int i;
1395 u32 xlvl;
1397 early_identify_cpu(c);
1399 /* AMD-defined flags: level 0x80000001 */
1400 xlvl = cpuid_eax(0x80000000);
1401 c->extended_cpuid_level = xlvl;
1402 if ((xlvl & 0xffff0000) == 0x80000000) {
1403 if (xlvl >= 0x80000001) {
1404 c->x86_capability[1] = cpuid_edx(0x80000001);
1405 c->x86_capability[6] = cpuid_ecx(0x80000001);
1407 if (xlvl >= 0x80000004)
1408 get_model_name(c); /* Default name */
1411 /* Transmeta-defined flags: level 0x80860001 */
1412 xlvl = cpuid_eax(0x80860000);
1413 if ((xlvl & 0xffff0000) == 0x80860000) {
1414 /* Don't set x86_cpuid_level here for now to not confuse. */
1415 if (xlvl >= 0x80860001)
1416 c->x86_capability[2] = cpuid_edx(0x80860001);
1419 /*
1420 * Vendor-specific initialization. In this section we
1421 * canonicalize the feature flags, meaning if there are
1422 * features a certain CPU supports which CPUID doesn't
1423 * tell us, CPUID claiming incorrect flags, or other bugs,
1424 * we handle them here.
1426 * At the end of this section, c->x86_capability better
1427 * indicate the features this CPU genuinely supports!
1428 */
1429 switch (c->x86_vendor) {
1430 case X86_VENDOR_AMD:
1431 init_amd(c);
1432 break;
1434 case X86_VENDOR_INTEL:
1435 init_intel(c);
1436 break;
1438 case X86_VENDOR_UNKNOWN:
1439 default:
1440 display_cacheinfo(c);
1441 break;
1444 select_idle_routine(c);
1445 detect_ht(c);
1447 /*
1448 * On SMP, boot_cpu_data holds the common feature set between
1449 * all CPUs; so make sure that we indicate which features are
1450 * common between the CPUs. The first time this routine gets
1451 * executed, c == &boot_cpu_data.
1452 */
1453 if (c != &boot_cpu_data) {
1454 /* AND the already accumulated flags with these */
1455 for (i = 0 ; i < NCAPINTS ; i++)
1456 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
1459 #ifdef CONFIG_X86_MCE
1460 mcheck_init(c);
1461 #endif
1462 if (c == &boot_cpu_data)
1463 mtrr_bp_init();
1464 else
1465 mtrr_ap_init();
1466 #ifdef CONFIG_NUMA
1467 numa_add_cpu(smp_processor_id());
1468 #endif
1472 void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
1474 if (c->x86_model_id[0])
1475 printk("%s", c->x86_model_id);
1477 if (c->x86_mask || c->cpuid_level >= 0)
1478 printk(" stepping %02x\n", c->x86_mask);
1479 else
1480 printk("\n");
1483 /*
1484 * Get CPU information for use by the procfs.
1485 */
1487 static int show_cpuinfo(struct seq_file *m, void *v)
1489 struct cpuinfo_x86 *c = v;
1491 /*
1492 * These flag bits must match the definitions in <asm/cpufeature.h>.
1493 * NULL means this bit is undefined or reserved; either way it doesn't
1494 * have meaning as far as Linux is concerned. Note that it's important
1495 * to realize there is a difference between this table and CPUID -- if
1496 * applications want to get the raw CPUID data, they should access
1497 * /dev/cpu/<cpu_nr>/cpuid instead.
1498 */
1499 static char *x86_cap_flags[] = {
1500 /* Intel-defined */
1501 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
1502 "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
1503 "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
1504 "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
1506 /* AMD-defined */
1507 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1508 NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
1509 NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
1510 NULL, "fxsr_opt", "rdtscp", NULL, NULL, "lm", "3dnowext", "3dnow",
1512 /* Transmeta-defined */
1513 "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
1514 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1515 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1516 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1518 /* Other (Linux-defined) */
1519 "cxmmx", NULL, "cyrix_arr", "centaur_mcr", NULL,
1520 "constant_tsc", NULL, NULL,
1521 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1522 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1523 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1525 /* Intel-defined (#2) */
1526 "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", NULL, "est",
1527 "tm2", NULL, "cid", NULL, NULL, "cx16", "xtpr", NULL,
1528 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1529 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1531 /* VIA/Cyrix/Centaur-defined */
1532 NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
1533 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1534 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1535 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1537 /* AMD-defined (#2) */
1538 "lahf_lm", "cmp_legacy", "svm", NULL, "cr8_legacy", NULL, NULL, NULL,
1539 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1540 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1541 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1542 };
1543 static char *x86_power_flags[] = {
1544 "ts", /* temperature sensor */
1545 "fid", /* frequency id control */
1546 "vid", /* voltage id control */
1547 "ttp", /* thermal trip */
1548 "tm",
1549 "stc",
1550 NULL,
1551 /* nothing */ /* constant_tsc - moved to flags */
1552 };
1555 #ifdef CONFIG_SMP
1556 if (!cpu_online(c-cpu_data))
1557 return 0;
1558 #endif
1560 seq_printf(m,"processor\t: %u\n"
1561 "vendor_id\t: %s\n"
1562 "cpu family\t: %d\n"
1563 "model\t\t: %d\n"
1564 "model name\t: %s\n",
1565 (unsigned)(c-cpu_data),
1566 c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
1567 c->x86,
1568 (int)c->x86_model,
1569 c->x86_model_id[0] ? c->x86_model_id : "unknown");
1571 if (c->x86_mask || c->cpuid_level >= 0)
1572 seq_printf(m, "stepping\t: %d\n", c->x86_mask);
1573 else
1574 seq_printf(m, "stepping\t: unknown\n");
1576 if (cpu_has(c,X86_FEATURE_TSC)) {
1577 unsigned int freq = cpufreq_quick_get((unsigned)(c-cpu_data));
1578 if (!freq)
1579 freq = cpu_khz;
1580 seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
1581 freq / 1000, (freq % 1000));
1584 /* Cache size */
1585 if (c->x86_cache_size >= 0)
1586 seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
1588 #ifdef CONFIG_SMP
1589 if (smp_num_siblings * c->x86_max_cores > 1) {
1590 int cpu = c - cpu_data;
1591 seq_printf(m, "physical id\t: %d\n", phys_proc_id[cpu]);
1592 seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[cpu]));
1593 seq_printf(m, "core id\t\t: %d\n", cpu_core_id[cpu]);
1594 seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
1596 #endif
1598 seq_printf(m,
1599 "fpu\t\t: yes\n"
1600 "fpu_exception\t: yes\n"
1601 "cpuid level\t: %d\n"
1602 "wp\t\t: yes\n"
1603 "flags\t\t:",
1604 c->cpuid_level);
1607 int i;
1608 for ( i = 0 ; i < 32*NCAPINTS ; i++ )
1609 if ( test_bit(i, &c->x86_capability) &&
1610 x86_cap_flags[i] != NULL )
1611 seq_printf(m, " %s", x86_cap_flags[i]);
1614 seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
1615 c->loops_per_jiffy/(500000/HZ),
1616 (c->loops_per_jiffy/(5000/HZ)) % 100);
1618 if (c->x86_tlbsize > 0)
1619 seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
1620 seq_printf(m, "clflush size\t: %d\n", c->x86_clflush_size);
1621 seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
1623 seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
1624 c->x86_phys_bits, c->x86_virt_bits);
1626 seq_printf(m, "power management:");
1628 unsigned i;
1629 for (i = 0; i < 32; i++)
1630 if (c->x86_power & (1 << i)) {
1631 if (i < ARRAY_SIZE(x86_power_flags) &&
1632 x86_power_flags[i])
1633 seq_printf(m, "%s%s",
1634 x86_power_flags[i][0]?" ":"",
1635 x86_power_flags[i]);
1636 else
1637 seq_printf(m, " [%d]", i);
1641 seq_printf(m, "\n\n");
1643 return 0;
1646 static void *c_start(struct seq_file *m, loff_t *pos)
1648 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
1651 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1653 ++*pos;
1654 return c_start(m, pos);
1657 static void c_stop(struct seq_file *m, void *v)
1661 struct seq_operations cpuinfo_op = {
1662 .start =c_start,
1663 .next = c_next,
1664 .stop = c_stop,
1665 .show = show_cpuinfo,
1666 };
1668 static int __init run_dmi_scan(void)
1670 dmi_scan_machine();
1671 return 0;
1673 core_initcall(run_dmi_scan);