2 * Copyright (C) 1995 Linus Torvalds
6 * This file handles the architecture-dependent parts of initialization
9 #include <linux/errno.h>
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
13 #include <linux/stddef.h>
14 #include <linux/unistd.h>
15 #include <linux/ptrace.h>
16 #include <linux/slab.h>
17 #include <linux/user.h>
18 #include <linux/screen_info.h>
19 #include <linux/ioport.h>
20 #include <linux/delay.h>
21 #include <linux/init.h>
22 #include <linux/initrd.h>
23 #include <linux/highmem.h>
24 #include <linux/bootmem.h>
25 #include <linux/module.h>
26 #include <asm/processor.h>
27 #include <linux/console.h>
28 #include <linux/seq_file.h>
29 #include <linux/crash_dump.h>
30 #include <linux/root_dev.h>
31 #include <linux/pci.h>
32 #include <asm/pci-direct.h>
33 #include <linux/efi.h>
34 #include <linux/acpi.h>
35 #include <linux/kallsyms.h>
36 #include <linux/edd.h>
37 #include <linux/iscsi_ibft.h>
38 #include <linux/mmzone.h>
39 #include <linux/kexec.h>
40 #include <linux/cpufreq.h>
41 #include <linux/dmi.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/ctype.h>
44 #include <linux/sort.h>
45 #include <linux/uaccess.h>
46 #include <linux/init_ohci1394_dma.h>
49 #include <asm/uaccess.h>
50 #include <asm/system.h>
51 #include <asm/vsyscall.h>
56 #include <video/edid.h>
60 #include <asm/mpspec.h>
61 #include <asm/mmu_context.h>
62 #include <asm/proto.h>
63 #include <asm/setup.h>
65 #include <asm/sections.h>
67 #include <asm/cacheflush.h>
70 #include <asm/topology.h>
71 #include <asm/trampoline.h>
73 #include <mach_apic.h>
74 #ifdef CONFIG_PARAVIRT
75 #include <asm/paravirt.h>
84 struct cpuinfo_x86 boot_cpu_data __read_mostly;
85 EXPORT_SYMBOL(boot_cpu_data);
87 __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
89 unsigned long mmu_cr4_features;
91 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
94 unsigned long saved_video_mode;
96 int force_mwait __cpuinitdata;
102 char dmi_alloc_data[DMI_MAX_DATA];
107 struct screen_info screen_info;
108 EXPORT_SYMBOL(screen_info);
109 struct sys_desc_table_struct {
110 unsigned short length;
111 unsigned char table[0];
114 struct edid_info edid_info;
115 EXPORT_SYMBOL_GPL(edid_info);
117 extern int root_mountflags;
119 char __initdata command_line[COMMAND_LINE_SIZE];
121 static struct resource standard_io_resources[] = {
122 { .name = "dma1", .start = 0x00, .end = 0x1f,
123 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
124 { .name = "pic1", .start = 0x20, .end = 0x21,
125 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
126 { .name = "timer0", .start = 0x40, .end = 0x43,
127 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
128 { .name = "timer1", .start = 0x50, .end = 0x53,
129 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
130 { .name = "keyboard", .start = 0x60, .end = 0x6f,
131 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
132 { .name = "dma page reg", .start = 0x80, .end = 0x8f,
133 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
134 { .name = "pic2", .start = 0xa0, .end = 0xa1,
135 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
136 { .name = "dma2", .start = 0xc0, .end = 0xdf,
137 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
138 { .name = "fpu", .start = 0xf0, .end = 0xff,
139 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
142 #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
144 static struct resource data_resource = {
145 .name = "Kernel data",
148 .flags = IORESOURCE_RAM,
150 static struct resource code_resource = {
151 .name = "Kernel code",
154 .flags = IORESOURCE_RAM,
156 static struct resource bss_resource = {
157 .name = "Kernel bss",
160 .flags = IORESOURCE_RAM,
163 static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
165 #ifdef CONFIG_PROC_VMCORE
166 /* elfcorehdr= specifies the location of elf core header
167 * stored by the crashed kernel. This option will be passed
168 * by kexec loader to the capture kernel.
170 static int __init setup_elfcorehdr(char *arg)
175 elfcorehdr_addr = memparse(arg, &end);
176 return end > arg ? 0 : -EINVAL;
178 early_param("elfcorehdr", setup_elfcorehdr);
183 contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
185 unsigned long bootmap_size, bootmap;
187 bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
188 bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
191 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
192 bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
193 e820_register_active_regions(0, start_pfn, end_pfn);
194 free_bootmem_with_active_regions(0, end_pfn);
195 early_res_to_bootmem(0, end_pfn<<PAGE_SHIFT);
196 reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
200 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
202 #ifdef CONFIG_EDD_MODULE
206 * copy_edd() - Copy the BIOS EDD information
207 * from boot_params into a safe place.
210 static inline void copy_edd(void)
212 memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
213 sizeof(edd.mbr_signature));
214 memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
215 edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
216 edd.edd_info_nr = boot_params.eddbuf_entries;
219 static inline void copy_edd(void)
225 static void __init reserve_crashkernel(void)
227 unsigned long long total_mem;
228 unsigned long long crash_size, crash_base;
231 total_mem = ((unsigned long long)max_low_pfn - min_low_pfn) << PAGE_SHIFT;
233 ret = parse_crashkernel(boot_command_line, total_mem,
234 &crash_size, &crash_base);
235 if (ret == 0 && crash_size) {
236 if (crash_base <= 0) {
237 printk(KERN_INFO "crashkernel reservation failed - "
238 "you have to specify a base address\n");
242 if (reserve_bootmem(crash_base, crash_size,
243 BOOTMEM_EXCLUSIVE) < 0) {
244 printk(KERN_INFO "crashkernel reservation failed - "
245 "memory is in use\n");
249 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
250 "for crashkernel (System RAM: %ldMB)\n",
251 (unsigned long)(crash_size >> 20),
252 (unsigned long)(crash_base >> 20),
253 (unsigned long)(total_mem >> 20));
254 crashk_res.start = crash_base;
255 crashk_res.end = crash_base + crash_size - 1;
256 insert_resource(&iomem_resource, &crashk_res);
260 static inline void __init reserve_crashkernel(void)
264 /* Overridden in paravirt.c if CONFIG_PARAVIRT */
265 void __attribute__((weak)) __init memory_setup(void)
267 machine_specific_memory_setup();
270 static void __init parse_setup_data(void)
272 struct setup_data *data;
273 unsigned long pa_data;
275 if (boot_params.hdr.version < 0x0209)
277 pa_data = boot_params.hdr.setup_data;
279 data = early_ioremap(pa_data, PAGE_SIZE);
280 switch (data->type) {
284 #ifndef CONFIG_DEBUG_BOOT_PARAMS
285 free_early(pa_data, pa_data+sizeof(*data)+data->len);
287 pa_data = data->next;
288 early_iounmap(data, PAGE_SIZE);
292 #ifdef CONFIG_PCI_MMCONFIG
293 extern void __cpuinit fam10h_check_enable_mmcfg(void);
294 extern void __init check_enable_amd_mmconf_dmi(void);
296 void __cpuinit fam10h_check_enable_mmcfg(void)
299 void __init check_enable_amd_mmconf_dmi(void)
305 * setup_arch - architecture-specific boot-time initializations
307 * Note: On x86_64, fixmaps are ready for use even before this is called.
309 void __init setup_arch(char **cmdline_p)
313 printk(KERN_INFO "Command line: %s\n", boot_command_line);
315 ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
316 screen_info = boot_params.screen_info;
317 edid_info = boot_params.edid_info;
318 saved_video_mode = boot_params.hdr.vid_mode;
319 bootloader_type = boot_params.hdr.type_of_loader;
321 #ifdef CONFIG_BLK_DEV_RAM
322 rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
323 rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
324 rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
327 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
337 if (!boot_params.hdr.root_flags)
338 root_mountflags &= ~MS_RDONLY;
339 init_mm.start_code = (unsigned long) &_text;
340 init_mm.end_code = (unsigned long) &_etext;
341 init_mm.end_data = (unsigned long) &_edata;
342 init_mm.brk = (unsigned long) &_end;
344 code_resource.start = virt_to_phys(&_text);
345 code_resource.end = virt_to_phys(&_etext)-1;
346 data_resource.start = virt_to_phys(&_etext);
347 data_resource.end = virt_to_phys(&_edata)-1;
348 bss_resource.start = virt_to_phys(&__bss_start);
349 bss_resource.end = virt_to_phys(&__bss_stop)-1;
351 early_identify_cpu(&boot_cpu_data);
353 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
354 *cmdline_p = command_line;
360 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
361 if (init_ohci1394_dma_early)
362 init_ohci1394_dma_on_all_controllers();
365 finish_e820_parsing();
367 /* after parse_early_param, so could debug it */
368 insert_resource(&iomem_resource, &code_resource);
369 insert_resource(&iomem_resource, &data_resource);
370 insert_resource(&iomem_resource, &bss_resource);
372 early_gart_iommu_check();
374 e820_register_active_regions(0, 0, -1UL);
376 * partially used pages are not usable - thus
377 * we are rounding upwards:
379 end_pfn = e820_end_of_ram();
380 /* update e820 for memory not covered by WB MTRRs */
382 if (mtrr_trim_uncached_memory(end_pfn)) {
383 e820_register_active_regions(0, 0, -1UL);
384 end_pfn = e820_end_of_ram();
387 num_physpages = end_pfn;
391 max_pfn_mapped = init_memory_mapping(0, (max_pfn_mapped << PAGE_SHIFT));
402 /* setup to use the early static init tables during kernel startup */
403 x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
404 x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
406 x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
412 * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
413 * Call this early for SRAT node setup.
415 acpi_boot_table_init();
418 /* How many end-of-memory variables you have, grandma! */
419 max_low_pfn = end_pfn;
421 high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
423 /* Remove active ranges so rediscovery with NUMA-awareness happens */
424 remove_all_active_ranges();
426 #ifdef CONFIG_ACPI_NUMA
428 * Parse SRAT to discover nodes.
434 numa_initmem_init(0, end_pfn);
436 contig_initmem_init(0, end_pfn);
439 dma32_reserve_bootmem();
441 #ifdef CONFIG_ACPI_SLEEP
443 * Reserve low memory region for sleep support.
445 acpi_reserve_bootmem();
449 efi_reserve_bootmem();
452 * Find and reserve possible boot-time SMP configuration:
455 #ifdef CONFIG_BLK_DEV_INITRD
456 if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
457 unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
458 unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
459 unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
460 unsigned long end_of_mem = end_pfn << PAGE_SHIFT;
462 if (ramdisk_end <= end_of_mem) {
464 * don't need to reserve again, already reserved early
465 * in x86_64_start_kernel, and early_res_to_bootmem
466 * convert that to reserved in bootmem
468 initrd_start = ramdisk_image + PAGE_OFFSET;
469 initrd_end = initrd_start+ramdisk_size;
471 free_bootmem(ramdisk_image, ramdisk_size);
472 printk(KERN_ERR "initrd extends beyond end of memory "
473 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
474 ramdisk_end, end_of_mem);
479 reserve_crashkernel();
481 reserve_ibft_region();
490 * Read APIC and some other early information from ACPI tables.
498 * get boot-time SMP configuration:
500 if (smp_found_config)
502 init_apic_mappings();
503 ioapic_init_mappings();
506 * We trust e820 completely. No explicit ROM probing in memory.
508 e820_reserve_resources();
509 e820_mark_nosave_regions();
511 /* request I/O space for devices used on all i[345]86 PCs */
512 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
513 request_resource(&ioport_resource, &standard_io_resources[i]);
518 #if defined(CONFIG_VGA_CONSOLE)
519 if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
520 conswitchp = &vga_con;
521 #elif defined(CONFIG_DUMMY_CONSOLE)
522 conswitchp = &dummy_con;
526 /* do this before identify_cpu for boot cpu */
527 check_enable_amd_mmconf_dmi();
530 static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
534 if (c->extended_cpuid_level < 0x80000004)
537 v = (unsigned int *) c->x86_model_id;
538 cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
539 cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
540 cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
541 c->x86_model_id[48] = 0;
546 static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
548 unsigned int n, dummy, eax, ebx, ecx, edx;
550 n = c->extended_cpuid_level;
552 if (n >= 0x80000005) {
553 cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
554 printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
555 "D cache %dK (%d bytes/line)\n",
556 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
557 c->x86_cache_size = (ecx>>24) + (edx>>24);
558 /* On K8 L1 TLB is inclusive, so don't count it */
562 if (n >= 0x80000006) {
563 cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
564 ecx = cpuid_ecx(0x80000006);
565 c->x86_cache_size = ecx >> 16;
566 c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
568 printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
569 c->x86_cache_size, ecx & 0xFF);
571 if (n >= 0x80000008) {
572 cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
573 c->x86_virt_bits = (eax >> 8) & 0xff;
574 c->x86_phys_bits = eax & 0xff;
579 static int __cpuinit nearby_node(int apicid)
583 for (i = apicid - 1; i >= 0; i--) {
584 node = apicid_to_node[i];
585 if (node != NUMA_NO_NODE && node_online(node))
588 for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
589 node = apicid_to_node[i];
590 if (node != NUMA_NO_NODE && node_online(node))
593 return first_node(node_online_map); /* Shouldn't happen */
598 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
599 * Assumes number of cores is a power of two.
601 static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
606 int cpu = smp_processor_id();
608 unsigned apicid = hard_smp_processor_id();
610 bits = c->x86_coreid_bits;
612 /* Low order bits define the core id (index of core in socket) */
613 c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
614 /* Convert the initial APIC ID into the socket ID */
615 c->phys_proc_id = c->initial_apicid >> bits;
618 node = c->phys_proc_id;
619 if (apicid_to_node[apicid] != NUMA_NO_NODE)
620 node = apicid_to_node[apicid];
621 if (!node_online(node)) {
622 /* Two possibilities here:
623 - The CPU is missing memory and no node was created.
624 In that case try picking one from a nearby CPU
625 - The APIC IDs differ from the HyperTransport node IDs
626 which the K8 northbridge parsing fills in.
627 Assume they are all increased by a constant offset,
628 but in the same order as the HT nodeids.
629 If that doesn't result in a usable node fall back to the
630 path for the previous case. */
632 int ht_nodeid = c->initial_apicid;
634 if (ht_nodeid >= 0 &&
635 apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
636 node = apicid_to_node[ht_nodeid];
637 /* Pick a nearby node */
638 if (!node_online(node))
639 node = nearby_node(apicid);
641 numa_set_node(cpu, node);
643 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
648 static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
653 /* Multi core CPU? */
654 if (c->extended_cpuid_level < 0x80000008)
657 ecx = cpuid_ecx(0x80000008);
659 c->x86_max_cores = (ecx & 0xff) + 1;
661 /* CPU telling us the core id bits shift? */
662 bits = (ecx >> 12) & 0xF;
664 /* Otherwise recompute */
666 while ((1 << bits) < c->x86_max_cores)
670 c->x86_coreid_bits = bits;
675 #define ENABLE_C1E_MASK 0x18000000
676 #define CPUID_PROCESSOR_SIGNATURE 1
677 #define CPUID_XFAM 0x0ff00000
678 #define CPUID_XFAM_K8 0x00000000
679 #define CPUID_XFAM_10H 0x00100000
680 #define CPUID_XFAM_11H 0x00200000
681 #define CPUID_XMOD 0x000f0000
682 #define CPUID_XMOD_REV_F 0x00040000
684 /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
685 static __cpuinit int amd_apic_timer_broken(void)
687 u32 lo, hi, eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
689 switch (eax & CPUID_XFAM) {
691 if ((eax & CPUID_XMOD) < CPUID_XMOD_REV_F)
695 rdmsr(MSR_K8_ENABLE_C1E, lo, hi);
696 if (lo & ENABLE_C1E_MASK)
700 /* err on the side of caution */
706 static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
708 early_init_amd_mc(c);
710 /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
711 if (c->x86_power & (1<<8))
712 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
715 static void __cpuinit init_amd(struct cpuinfo_x86 *c)
723 * Disable TLB flush filter by setting HWCR.FFDIS on K8
724 * bit 6 of msr C001_0015
726 * Errata 63 for SH-B3 steppings
727 * Errata 122 for all steppings (F+ have it disabled by default)
730 rdmsrl(MSR_K8_HWCR, value);
732 wrmsrl(MSR_K8_HWCR, value);
736 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
737 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
738 clear_cpu_cap(c, 0*32+31);
740 /* On C+ stepping K8 rep microcode works well for copy/memset */
741 level = cpuid_eax(1);
742 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
744 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
745 if (c->x86 == 0x10 || c->x86 == 0x11)
746 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
748 /* Enable workaround for FXSAVE leak */
750 set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
752 level = get_model_name(c);
756 /* Should distinguish Models here, but this is only
757 a fallback anyways. */
758 strcpy(c->x86_model_id, "Hammer");
762 display_cacheinfo(c);
764 /* Multi core CPU? */
765 if (c->extended_cpuid_level >= 0x80000008)
768 if (c->extended_cpuid_level >= 0x80000006 &&
769 (cpuid_edx(0x80000006) & 0xf000))
770 num_cache_leaves = 4;
772 num_cache_leaves = 3;
774 if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
775 set_cpu_cap(c, X86_FEATURE_K8);
777 /* MFENCE stops RDTSC speculation */
778 set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
781 fam10h_check_enable_mmcfg();
783 if (amd_apic_timer_broken())
784 disable_apic_timer = 1;
786 if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
787 unsigned long long tseg;
790 * Split up direct mapping around the TSEG SMM area.
791 * Don't do it for gbpages because there seems very little
792 * benefit in doing so.
794 if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
795 (tseg >> PMD_SHIFT) < (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
796 set_memory_4k((unsigned long)__va(tseg), 1);
800 void __cpuinit detect_ht(struct cpuinfo_x86 *c)
803 u32 eax, ebx, ecx, edx;
804 int index_msb, core_bits;
806 cpuid(1, &eax, &ebx, &ecx, &edx);
809 if (!cpu_has(c, X86_FEATURE_HT))
811 if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
814 smp_num_siblings = (ebx & 0xff0000) >> 16;
816 if (smp_num_siblings == 1) {
817 printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
818 } else if (smp_num_siblings > 1) {
820 if (smp_num_siblings > NR_CPUS) {
821 printk(KERN_WARNING "CPU: Unsupported number of "
822 "siblings %d", smp_num_siblings);
823 smp_num_siblings = 1;
827 index_msb = get_count_order(smp_num_siblings);
828 c->phys_proc_id = phys_pkg_id(index_msb);
830 smp_num_siblings = smp_num_siblings / c->x86_max_cores;
832 index_msb = get_count_order(smp_num_siblings);
834 core_bits = get_count_order(c->x86_max_cores);
836 c->cpu_core_id = phys_pkg_id(index_msb) &
837 ((1 << core_bits) - 1);
840 if ((c->x86_max_cores * smp_num_siblings) > 1) {
841 printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
843 printk(KERN_INFO "CPU: Processor Core ID: %d\n",
851 * find out the number of processor cores on the die
853 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
857 if (c->cpuid_level < 4)
860 cpuid_count(4, 0, &eax, &t, &t, &t);
863 return ((eax >> 26) + 1);
868 static void __cpuinit srat_detect_node(void)
872 int cpu = smp_processor_id();
873 int apicid = hard_smp_processor_id();
875 /* Don't do the funky fallback heuristics the AMD version employs
877 node = apicid_to_node[apicid];
878 if (node == NUMA_NO_NODE || !node_online(node))
879 node = first_node(node_online_map);
880 numa_set_node(cpu, node);
882 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
886 static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
888 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
889 (c->x86 == 0x6 && c->x86_model >= 0x0e))
890 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
893 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
898 init_intel_cacheinfo(c);
899 if (c->cpuid_level > 9) {
900 unsigned eax = cpuid_eax(10);
901 /* Check for version and the number of counters */
902 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
903 set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
908 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
910 set_cpu_cap(c, X86_FEATURE_BTS);
912 set_cpu_cap(c, X86_FEATURE_PEBS);
919 n = c->extended_cpuid_level;
920 if (n >= 0x80000008) {
921 unsigned eax = cpuid_eax(0x80000008);
922 c->x86_virt_bits = (eax >> 8) & 0xff;
923 c->x86_phys_bits = eax & 0xff;
924 /* CPUID workaround for Intel 0F34 CPU */
925 if (c->x86_vendor == X86_VENDOR_INTEL &&
926 c->x86 == 0xF && c->x86_model == 0x3 &&
928 c->x86_phys_bits = 36;
932 c->x86_cache_alignment = c->x86_clflush_size * 2;
934 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
935 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
936 c->x86_max_cores = intel_num_cpu_cores(c);
941 static void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
943 if (c->x86 == 0x6 && c->x86_model >= 0xf)
944 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
947 static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
952 n = c->extended_cpuid_level;
953 if (n >= 0x80000008) {
954 unsigned eax = cpuid_eax(0x80000008);
955 c->x86_virt_bits = (eax >> 8) & 0xff;
956 c->x86_phys_bits = eax & 0xff;
959 if (c->x86 == 0x6 && c->x86_model >= 0xf) {
960 c->x86_cache_alignment = c->x86_clflush_size * 2;
961 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
962 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
964 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
967 static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
969 char *v = c->x86_vendor_id;
971 if (!strcmp(v, "AuthenticAMD"))
972 c->x86_vendor = X86_VENDOR_AMD;
973 else if (!strcmp(v, "GenuineIntel"))
974 c->x86_vendor = X86_VENDOR_INTEL;
975 else if (!strcmp(v, "CentaurHauls"))
976 c->x86_vendor = X86_VENDOR_CENTAUR;
978 c->x86_vendor = X86_VENDOR_UNKNOWN;
981 /* Do some early cpuid on the boot CPU to get some parameter that are
982 needed before check_bugs. Everything advanced is in identify_cpu
984 static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
988 c->loops_per_jiffy = loops_per_jiffy;
989 c->x86_cache_size = -1;
990 c->x86_vendor = X86_VENDOR_UNKNOWN;
991 c->x86_model = c->x86_mask = 0; /* So far unknown... */
992 c->x86_vendor_id[0] = '\0'; /* Unset */
993 c->x86_model_id[0] = '\0'; /* Unset */
994 c->x86_clflush_size = 64;
995 c->x86_cache_alignment = c->x86_clflush_size;
996 c->x86_max_cores = 1;
997 c->x86_coreid_bits = 0;
998 c->extended_cpuid_level = 0;
999 memset(&c->x86_capability, 0, sizeof c->x86_capability);
1001 /* Get vendor name */
1002 cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
1003 (unsigned int *)&c->x86_vendor_id[0],
1004 (unsigned int *)&c->x86_vendor_id[8],
1005 (unsigned int *)&c->x86_vendor_id[4]);
1009 /* Initialize the standard set of capabilities */
1010 /* Note that the vendor-specific code below might override */
1012 /* Intel-defined flags: level 0x00000001 */
1013 if (c->cpuid_level >= 0x00000001) {
1015 cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
1016 &c->x86_capability[0]);
1017 c->x86 = (tfms >> 8) & 0xf;
1018 c->x86_model = (tfms >> 4) & 0xf;
1019 c->x86_mask = tfms & 0xf;
1021 c->x86 += (tfms >> 20) & 0xff;
1023 c->x86_model += ((tfms >> 16) & 0xF) << 4;
1024 if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
1025 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
1027 /* Have CPUID level 0 only - unheard of */
1031 c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
1033 c->phys_proc_id = c->initial_apicid;
1035 /* AMD-defined flags: level 0x80000001 */
1036 xlvl = cpuid_eax(0x80000000);
1037 c->extended_cpuid_level = xlvl;
1038 if ((xlvl & 0xffff0000) == 0x80000000) {
1039 if (xlvl >= 0x80000001) {
1040 c->x86_capability[1] = cpuid_edx(0x80000001);
1041 c->x86_capability[6] = cpuid_ecx(0x80000001);
1043 if (xlvl >= 0x80000004)
1044 get_model_name(c); /* Default name */
1047 /* Transmeta-defined flags: level 0x80860001 */
1048 xlvl = cpuid_eax(0x80860000);
1049 if ((xlvl & 0xffff0000) == 0x80860000) {
1050 /* Don't set x86_cpuid_level here for now to not confuse. */
1051 if (xlvl >= 0x80860001)
1052 c->x86_capability[2] = cpuid_edx(0x80860001);
1055 c->extended_cpuid_level = cpuid_eax(0x80000000);
1056 if (c->extended_cpuid_level >= 0x80000007)
1057 c->x86_power = cpuid_edx(0x80000007);
1060 clear_cpu_cap(c, X86_FEATURE_PAT);
1062 switch (c->x86_vendor) {
1063 case X86_VENDOR_AMD:
1065 if (c->x86 >= 0xf && c->x86 <= 0x11)
1066 set_cpu_cap(c, X86_FEATURE_PAT);
1068 case X86_VENDOR_INTEL:
1069 early_init_intel(c);
1070 if (c->x86 == 0xF || (c->x86 == 6 && c->x86_model >= 15))
1071 set_cpu_cap(c, X86_FEATURE_PAT);
1073 case X86_VENDOR_CENTAUR:
1074 early_init_centaur(c);
1081 * This does the hard work of actually picking apart the CPU stuff...
1083 void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
1087 early_identify_cpu(c);
1089 init_scattered_cpuid_features(c);
1091 c->apicid = phys_pkg_id(0);
1094 * Vendor-specific initialization. In this section we
1095 * canonicalize the feature flags, meaning if there are
1096 * features a certain CPU supports which CPUID doesn't
1097 * tell us, CPUID claiming incorrect flags, or other bugs,
1098 * we handle them here.
1100 * At the end of this section, c->x86_capability better
1101 * indicate the features this CPU genuinely supports!
1103 switch (c->x86_vendor) {
1104 case X86_VENDOR_AMD:
1108 case X86_VENDOR_INTEL:
1112 case X86_VENDOR_CENTAUR:
1116 case X86_VENDOR_UNKNOWN:
1118 display_cacheinfo(c);
1125 * On SMP, boot_cpu_data holds the common feature set between
1126 * all CPUs; so make sure that we indicate which features are
1127 * common between the CPUs. The first time this routine gets
1128 * executed, c == &boot_cpu_data.
1130 if (c != &boot_cpu_data) {
1131 /* AND the already accumulated flags with these */
1132 for (i = 0; i < NCAPINTS; i++)
1133 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
1136 /* Clear all flags overriden by options */
1137 for (i = 0; i < NCAPINTS; i++)
1138 c->x86_capability[i] &= ~cleared_cpu_caps[i];
1140 #ifdef CONFIG_X86_MCE
1143 select_idle_routine(c);
1146 numa_add_cpu(smp_processor_id());
1151 void __cpuinit identify_boot_cpu(void)
1153 identify_cpu(&boot_cpu_data);
1156 void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
1158 BUG_ON(c == &boot_cpu_data);
1163 static __init int setup_noclflush(char *arg)
1165 setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
1168 __setup("noclflush", setup_noclflush);
1170 void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
1172 if (c->x86_model_id[0])
1173 printk(KERN_CONT "%s", c->x86_model_id);
1175 if (c->x86_mask || c->cpuid_level >= 0)
1176 printk(KERN_CONT " stepping %02x\n", c->x86_mask);
1178 printk(KERN_CONT "\n");
1181 static __init int setup_disablecpuid(char *arg)
1184 if (get_option(&arg, &bit) && bit < NCAPINTS*32)
1185 setup_clear_cpu_cap(bit);
1190 __setup("clearcpuid=", setup_disablecpuid);