1 #include <linux/init.h>
2 #include <linux/kernel.h>
4 #include <linux/string.h>
5 #include <linux/bitops.h>
7 #include <linux/thread_info.h>
8 #include <linux/module.h>
10 #include <asm/processor.h>
11 #include <asm/pgtable.h>
13 #include <asm/uaccess.h>
18 #include <asm/topology.h>
19 #include <asm/numa_64.h>
24 #ifdef CONFIG_X86_LOCAL_APIC
25 #include <asm/mpspec.h>
29 static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
31 /* Unmask CPUID levels if masked: */
32 if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
35 rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
37 if (misc_enable & MSR_IA32_MISC_ENABLE_LIMIT_CPUID) {
38 misc_enable &= ~MSR_IA32_MISC_ENABLE_LIMIT_CPUID;
39 wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
40 c->cpuid_level = cpuid_eax(0);
44 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
45 (c->x86 == 0x6 && c->x86_model >= 0x0e))
46 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
49 set_cpu_cap(c, X86_FEATURE_SYSENTER32);
51 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
52 if (c->x86 == 15 && c->x86_cache_alignment == 64)
53 c->x86_cache_alignment = 128;
57 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
58 * with P/T states and does not stop in deep C-states
60 if (c->x86_power & (1 << 8)) {
61 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
62 set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
66 * There is a known erratum on Pentium III and Core Solo
68 * " Page with PAT set to WC while associated MTRR is UC
69 * may consolidate to UC "
70 * Because of this erratum, it is better to stick with
71 * setting WC in MTRR rather than using PAT on these CPUs.
73 * Enable PAT WC only on P4, Core 2 or later CPUs.
75 if (c->x86 == 6 && c->x86_model < 15)
76 clear_cpu_cap(c, X86_FEATURE_PAT);
81 * Early probe support logic for ppro memory erratum #50
83 * This is called before we do cpu ident work
86 int __cpuinit ppro_with_ram_bug(void)
88 /* Uses data from early_cpu_detect now */
89 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
90 boot_cpu_data.x86 == 6 &&
91 boot_cpu_data.x86_model == 1 &&
92 boot_cpu_data.x86_mask < 8) {
93 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
99 #ifdef CONFIG_X86_F00F_BUG
100 static void __cpuinit trap_init_f00f_bug(void)
102 __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
105 * Update the IDT descriptor and reload the IDT so that
106 * it uses the read-only mapped virtual address.
108 idt_descr.address = fix_to_virt(FIX_F00F_IDT);
109 load_idt(&idt_descr);
113 static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
115 unsigned long lo, hi;
117 #ifdef CONFIG_X86_F00F_BUG
119 * All current models of Pentium and Pentium with MMX technology CPUs
120 * have the F0 0F bug, which lets nonprivileged users lock up the system.
121 * Note that the workaround only should be initialized once...
124 if (!paravirt_enabled() && c->x86 == 5) {
125 static int f00f_workaround_enabled;
128 if (!f00f_workaround_enabled) {
129 trap_init_f00f_bug();
130 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
131 f00f_workaround_enabled = 1;
137 * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
140 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
141 clear_cpu_cap(c, X86_FEATURE_SEP);
144 * P4 Xeon errata 037 workaround.
145 * Hardware prefetcher may cause stale data to be loaded into the cache.
147 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
148 rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
149 if ((lo & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE) == 0) {
150 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
151 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
152 lo |= MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE;
153 wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
158 * See if we have a good local APIC by checking for buggy Pentia,
159 * i.e. all B steppings and the C2 stepping of P54C when using their
160 * integrated APIC (see 11AP erratum in "Pentium Processor
161 * Specification Update").
163 if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
164 (c->x86_mask < 0x6 || c->x86_mask == 0xb))
165 set_cpu_cap(c, X86_FEATURE_11AP);
168 #ifdef CONFIG_X86_INTEL_USERCOPY
170 * Set up the preferred alignment for movsl bulk memory moves
173 case 4: /* 486: untested */
175 case 5: /* Old Pentia: untested */
177 case 6: /* PII/PIII only like movsl with 8-byte alignment */
180 case 15: /* P4 is OK down to 8-byte alignment */
186 #ifdef CONFIG_X86_NUMAQ
191 static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
196 static void __cpuinit srat_detect_node(void)
198 #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
200 int cpu = smp_processor_id();
201 int apicid = hard_smp_processor_id();
203 /* Don't do the funky fallback heuristics the AMD version employs
205 node = apicid_to_node[apicid];
206 if (node == NUMA_NO_NODE || !node_online(node))
207 node = first_node(node_online_map);
208 numa_set_node(cpu, node);
210 printk(KERN_INFO "CPU %d/0x%x -> Node %d\n", cpu, apicid, node);
215 * find out the number of processor cores on the die
217 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
219 unsigned int eax, ebx, ecx, edx;
221 if (c->cpuid_level < 4)
224 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
225 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
227 return ((eax >> 26) + 1);
232 static void __cpuinit detect_vmx_virtcap(struct cpuinfo_x86 *c)
234 /* Intel VMX MSR indicated features */
235 #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
236 #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
237 #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
238 #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
239 #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
240 #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
242 u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
244 clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
245 clear_cpu_cap(c, X86_FEATURE_VNMI);
246 clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
247 clear_cpu_cap(c, X86_FEATURE_EPT);
248 clear_cpu_cap(c, X86_FEATURE_VPID);
250 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
251 msr_ctl = vmx_msr_high | vmx_msr_low;
252 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
253 set_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
254 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
255 set_cpu_cap(c, X86_FEATURE_VNMI);
256 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
257 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
258 vmx_msr_low, vmx_msr_high);
259 msr_ctl2 = vmx_msr_high | vmx_msr_low;
260 if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
261 (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
262 set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
263 if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
264 set_cpu_cap(c, X86_FEATURE_EPT);
265 if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
266 set_cpu_cap(c, X86_FEATURE_VPID);
270 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
276 intel_workarounds(c);
279 * Detect the extended topology information if available. This
280 * will reinitialise the initial_apicid which will be used
281 * in init_intel_cacheinfo()
283 detect_extended_topology(c);
285 l2 = init_intel_cacheinfo(c);
286 if (c->cpuid_level > 9) {
287 unsigned eax = cpuid_eax(10);
288 /* Check for version and the number of counters */
289 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
290 set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
294 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
297 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
299 set_cpu_cap(c, X86_FEATURE_BTS);
301 set_cpu_cap(c, X86_FEATURE_PEBS);
305 if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush)
306 set_cpu_cap(c, X86_FEATURE_CLFLUSH_MONITOR);
310 c->x86_cache_alignment = c->x86_clflush_size * 2;
312 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
315 * Names for the Pentium II/Celeron processors
316 * detectable only by also checking the cache size.
317 * Dixon is NOT a Celeron.
322 switch (c->x86_model) {
324 if (c->x86_mask == 0) {
326 p = "Celeron (Covington)";
328 p = "Mobile Pentium II (Dixon)";
334 p = "Celeron (Mendocino)";
335 else if (c->x86_mask == 0 || c->x86_mask == 5)
341 p = "Celeron (Coppermine)";
346 strcpy(c->x86_model_id, p);
350 set_cpu_cap(c, X86_FEATURE_P4);
352 set_cpu_cap(c, X86_FEATURE_P3);
355 if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
357 * let's use the legacy cpuid vector 0x1 and 0x4 for topology
360 c->x86_max_cores = intel_num_cpu_cores(c);
366 /* Work around errata */
369 if (cpu_has(c, X86_FEATURE_VMX))
370 detect_vmx_virtcap(c);
374 static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
377 * Intel PIII Tualatin. This comes in two flavours.
378 * One has 256kb of cache, the other 512. We have no way
379 * to determine which, so we use a boottime override
380 * for the 512kb model, and assume 256 otherwise.
382 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
388 static struct cpu_dev intel_cpu_dev __cpuinitdata = {
390 .c_ident = { "GenuineIntel" },
393 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
395 [0] = "486 DX-25/33",
406 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
408 [0] = "Pentium 60/66 A-step",
409 [1] = "Pentium 60/66",
410 [2] = "Pentium 75 - 200",
411 [3] = "OverDrive PODP5V83",
413 [7] = "Mobile Pentium 75 - 200",
414 [8] = "Mobile Pentium MMX"
417 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
419 [0] = "Pentium Pro A-step",
421 [3] = "Pentium II (Klamath)",
422 [4] = "Pentium II (Deschutes)",
423 [5] = "Pentium II (Deschutes)",
424 [6] = "Mobile Pentium II",
425 [7] = "Pentium III (Katmai)",
426 [8] = "Pentium III (Coppermine)",
427 [10] = "Pentium III (Cascades)",
428 [11] = "Pentium III (Tualatin)",
431 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
433 [0] = "Pentium 4 (Unknown)",
434 [1] = "Pentium 4 (Willamette)",
435 [2] = "Pentium 4 (Northwood)",
436 [4] = "Pentium 4 (Foster)",
437 [5] = "Pentium 4 (Foster)",
441 .c_size_cache = intel_size_cache,
443 .c_early_init = early_init_intel,
444 .c_init = init_intel,
445 .c_x86_vendor = X86_VENDOR_INTEL,
448 cpu_dev_register(intel_cpu_dev);