1 #include <linux/init.h>
2 #include <linux/kernel.h>
4 #include <linux/string.h>
5 #include <linux/bitops.h>
7 #include <linux/sched.h>
8 #include <linux/thread_info.h>
9 #include <linux/module.h>
10 #include <linux/uaccess.h>
12 #include <asm/processor.h>
13 #include <asm/pgtable.h>
19 #include <linux/topology.h>
20 #include <asm/numa_64.h>
25 #ifdef CONFIG_X86_LOCAL_APIC
26 #include <asm/mpspec.h>
30 static void __cpuinit
early_init_intel(struct cpuinfo_x86
*c
)
33 bool allow_fast_string
= true;
35 /* Unmask CPUID levels if masked: */
36 if (c
->x86
> 6 || (c
->x86
== 6 && c
->x86_model
>= 0xd)) {
37 rdmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
39 if (misc_enable
& MSR_IA32_MISC_ENABLE_LIMIT_CPUID
) {
40 misc_enable
&= ~MSR_IA32_MISC_ENABLE_LIMIT_CPUID
;
41 wrmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
42 c
->cpuid_level
= cpuid_eax(0);
47 if ((c
->x86
== 0xf && c
->x86_model
>= 0x03) ||
48 (c
->x86
== 0x6 && c
->x86_model
>= 0x0e))
49 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
51 if (c
->x86
>= 6 && !cpu_has(c
, X86_FEATURE_IA64
)) {
54 wrmsr(MSR_IA32_UCODE_REV
, 0, 0);
55 /* Required by the SDM */
57 rdmsr(MSR_IA32_UCODE_REV
, lower_word
, c
->microcode
);
61 * Atom erratum AAE44/AAF40/AAG38/AAH41:
63 * A race condition between speculative fetches and invalidating
64 * a large page. This is worked around in microcode, but we
65 * need the microcode to have already been loaded... so if it is
66 * not, recommend a BIOS update and disable large pages.
68 if (c
->x86
== 6 && c
->x86_model
== 0x1c && c
->x86_mask
<= 2 &&
69 c
->microcode
< 0x20e) {
70 printk(KERN_WARNING
"Atom PSE erratum detected, BIOS microcode update recommended\n");
71 clear_cpu_cap(c
, X86_FEATURE_PSE
);
75 set_cpu_cap(c
, X86_FEATURE_SYSENTER32
);
77 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
78 if (c
->x86
== 15 && c
->x86_cache_alignment
== 64)
79 c
->x86_cache_alignment
= 128;
82 /* CPUID workaround for 0F33/0F34 CPU */
83 if (c
->x86
== 0xF && c
->x86_model
== 0x3
84 && (c
->x86_mask
== 0x3 || c
->x86_mask
== 0x4))
85 c
->x86_phys_bits
= 36;
88 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
89 * with P/T states and does not stop in deep C-states.
91 * It is also reliable across cores and sockets. (but not across
92 * cabinets - we turn it off in that case explicitly.)
94 if (c
->x86_power
& (1 << 8)) {
95 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
96 set_cpu_cap(c
, X86_FEATURE_NONSTOP_TSC
);
97 if (!check_tsc_unstable())
98 sched_clock_stable
= 1;
102 * There is a known erratum on Pentium III and Core Solo
104 * " Page with PAT set to WC while associated MTRR is UC
105 * may consolidate to UC "
106 * Because of this erratum, it is better to stick with
107 * setting WC in MTRR rather than using PAT on these CPUs.
109 * Enable PAT WC only on P4, Core 2 or later CPUs.
111 if (c
->x86
== 6 && c
->x86_model
< 15)
112 clear_cpu_cap(c
, X86_FEATURE_PAT
);
114 #ifdef CONFIG_KMEMCHECK
116 * P4s have a "fast strings" feature which causes single-
117 * stepping REP instructions to only generate a #DB on
118 * cache-line boundaries.
120 * Ingo Molnar reported a Pentium D (model 6) and a Xeon
121 * (model 2) with the same problem.
124 allow_fast_string
= false;
126 rdmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
127 if (misc_enable
& MSR_IA32_MISC_ENABLE_FAST_STRING
) {
128 printk_once(KERN_INFO
"kmemcheck: Disabling fast string operations\n");
130 misc_enable
&= ~MSR_IA32_MISC_ENABLE_FAST_STRING
;
131 wrmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
137 * If BIOS didn't enable fast string operation, try to enable
138 * it ourselves. If that fails, then clear the fast string
139 * and enhanced fast string CPU capabilities.
141 if (c
->x86
> 6 || (c
->x86
== 6 && c
->x86_model
>= 0xd)) {
142 rdmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
144 if (allow_fast_string
&&
145 !(misc_enable
& MSR_IA32_MISC_ENABLE_FAST_STRING
)) {
146 misc_enable
|= MSR_IA32_MISC_ENABLE_FAST_STRING
;
147 wrmsr_safe(MSR_IA32_MISC_ENABLE
, (u32
)misc_enable
,
148 (u32
)(misc_enable
>> 32));
150 /* Re-read to make sure it stuck. */
151 rdmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
153 if (misc_enable
& MSR_IA32_MISC_ENABLE_FAST_STRING
)
154 printk_once(KERN_INFO FW_WARN
"IA32_MISC_ENABLE.FAST_STRING_ENABLE was not set\n");
157 if (!(misc_enable
& MSR_IA32_MISC_ENABLE_FAST_STRING
)) {
158 if (allow_fast_string
)
159 printk_once(KERN_INFO
"Failed to enable fast string operations\n");
160 setup_clear_cpu_cap(X86_FEATURE_REP_GOOD
);
161 setup_clear_cpu_cap(X86_FEATURE_ERMS
);
168 * Early probe support logic for ppro memory erratum #50
170 * This is called before we do cpu ident work
173 int __cpuinit
ppro_with_ram_bug(void)
175 /* Uses data from early_cpu_detect now */
176 if (boot_cpu_data
.x86_vendor
== X86_VENDOR_INTEL
&&
177 boot_cpu_data
.x86
== 6 &&
178 boot_cpu_data
.x86_model
== 1 &&
179 boot_cpu_data
.x86_mask
< 8) {
180 printk(KERN_INFO
"Pentium Pro with Errata#50 detected. Taking evasive action.\n");
186 #ifdef CONFIG_X86_F00F_BUG
187 static void __cpuinit
trap_init_f00f_bug(void)
189 __set_fixmap(FIX_F00F_IDT
, __pa(&idt_table
), PAGE_KERNEL_RO
);
192 * Update the IDT descriptor and reload the IDT so that
193 * it uses the read-only mapped virtual address.
195 idt_descr
.address
= fix_to_virt(FIX_F00F_IDT
);
196 load_idt(&idt_descr
);
200 static void __cpuinit
intel_smp_check(struct cpuinfo_x86
*c
)
202 /* calling is from identify_secondary_cpu() ? */
207 * Mask B, Pentium, but not Pentium MMX
210 c
->x86_mask
>= 1 && c
->x86_mask
<= 4 &&
213 * Remember we have B step Pentia with bugs
215 WARN_ONCE(1, "WARNING: SMP operation may be unreliable"
216 "with B stepping processors.\n");
220 static void __cpuinit
intel_workarounds(struct cpuinfo_x86
*c
)
222 unsigned long lo
, hi
;
224 #ifdef CONFIG_X86_F00F_BUG
226 * All current models of Pentium and Pentium with MMX technology CPUs
227 * have the F0 0F bug, which lets nonprivileged users lock up the
229 * Note that the workaround only should be initialized once...
232 if (!paravirt_enabled() && c
->x86
== 5) {
233 static int f00f_workaround_enabled
;
236 if (!f00f_workaround_enabled
) {
237 trap_init_f00f_bug();
238 printk(KERN_NOTICE
"Intel Pentium with F0 0F bug - workaround enabled.\n");
239 f00f_workaround_enabled
= 1;
245 * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
248 if ((c
->x86
<<8 | c
->x86_model
<<4 | c
->x86_mask
) < 0x633)
249 clear_cpu_cap(c
, X86_FEATURE_SEP
);
252 * P4 Xeon errata 037 workaround.
253 * Hardware prefetcher may cause stale data to be loaded into the cache.
255 if ((c
->x86
== 15) && (c
->x86_model
== 1) && (c
->x86_mask
== 1)) {
256 rdmsr(MSR_IA32_MISC_ENABLE
, lo
, hi
);
257 if ((lo
& MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE
) == 0) {
258 printk (KERN_INFO
"CPU: C0 stepping P4 Xeon detected.\n");
259 printk (KERN_INFO
"CPU: Disabling hardware prefetching (Errata 037)\n");
260 lo
|= MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE
;
261 wrmsr(MSR_IA32_MISC_ENABLE
, lo
, hi
);
266 * See if we have a good local APIC by checking for buggy Pentia,
267 * i.e. all B steppings and the C2 stepping of P54C when using their
268 * integrated APIC (see 11AP erratum in "Pentium Processor
269 * Specification Update").
271 if (cpu_has_apic
&& (c
->x86
<<8 | c
->x86_model
<<4) == 0x520 &&
272 (c
->x86_mask
< 0x6 || c
->x86_mask
== 0xb))
273 set_cpu_cap(c
, X86_FEATURE_11AP
);
276 #ifdef CONFIG_X86_INTEL_USERCOPY
278 * Set up the preferred alignment for movsl bulk memory moves
281 case 4: /* 486: untested */
283 case 5: /* Old Pentia: untested */
285 case 6: /* PII/PIII only like movsl with 8-byte alignment */
288 case 15: /* P4 is OK down to 8-byte alignment */
294 #ifdef CONFIG_X86_NUMAQ
301 static void __cpuinit
intel_workarounds(struct cpuinfo_x86
*c
)
306 static void __cpuinit
srat_detect_node(struct cpuinfo_x86
*c
)
310 int cpu
= smp_processor_id();
312 /* Don't do the funky fallback heuristics the AMD version employs
314 node
= numa_cpu_node(cpu
);
315 if (node
== NUMA_NO_NODE
|| !node_online(node
)) {
316 /* reuse the value from init_cpu_to_node() */
317 node
= cpu_to_node(cpu
);
319 numa_set_node(cpu
, node
);
324 * find out the number of processor cores on the die
326 static int __cpuinit
intel_num_cpu_cores(struct cpuinfo_x86
*c
)
328 unsigned int eax
, ebx
, ecx
, edx
;
330 if (c
->cpuid_level
< 4)
333 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
334 cpuid_count(4, 0, &eax
, &ebx
, &ecx
, &edx
);
336 return (eax
>> 26) + 1;
341 static void __cpuinit
detect_vmx_virtcap(struct cpuinfo_x86
*c
)
343 /* Intel VMX MSR indicated features */
344 #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
345 #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
346 #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
347 #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
348 #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
349 #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
351 u32 vmx_msr_low
, vmx_msr_high
, msr_ctl
, msr_ctl2
;
353 clear_cpu_cap(c
, X86_FEATURE_TPR_SHADOW
);
354 clear_cpu_cap(c
, X86_FEATURE_VNMI
);
355 clear_cpu_cap(c
, X86_FEATURE_FLEXPRIORITY
);
356 clear_cpu_cap(c
, X86_FEATURE_EPT
);
357 clear_cpu_cap(c
, X86_FEATURE_VPID
);
359 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS
, vmx_msr_low
, vmx_msr_high
);
360 msr_ctl
= vmx_msr_high
| vmx_msr_low
;
361 if (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW
)
362 set_cpu_cap(c
, X86_FEATURE_TPR_SHADOW
);
363 if (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_VNMI
)
364 set_cpu_cap(c
, X86_FEATURE_VNMI
);
365 if (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS
) {
366 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2
,
367 vmx_msr_low
, vmx_msr_high
);
368 msr_ctl2
= vmx_msr_high
| vmx_msr_low
;
369 if ((msr_ctl2
& X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC
) &&
370 (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW
))
371 set_cpu_cap(c
, X86_FEATURE_FLEXPRIORITY
);
372 if (msr_ctl2
& X86_VMX_FEATURE_PROC_CTLS2_EPT
)
373 set_cpu_cap(c
, X86_FEATURE_EPT
);
374 if (msr_ctl2
& X86_VMX_FEATURE_PROC_CTLS2_VPID
)
375 set_cpu_cap(c
, X86_FEATURE_VPID
);
379 static void __cpuinit
init_intel(struct cpuinfo_x86
*c
)
385 intel_workarounds(c
);
388 * Detect the extended topology information if available. This
389 * will reinitialise the initial_apicid which will be used
390 * in init_intel_cacheinfo()
392 detect_extended_topology(c
);
394 l2
= init_intel_cacheinfo(c
);
395 if (c
->cpuid_level
> 9) {
396 unsigned eax
= cpuid_eax(10);
397 /* Check for version and the number of counters */
398 if ((eax
& 0xff) && (((eax
>>8) & 0xff) > 1))
399 set_cpu_cap(c
, X86_FEATURE_ARCH_PERFMON
);
403 set_cpu_cap(c
, X86_FEATURE_LFENCE_RDTSC
);
406 rdmsr(MSR_IA32_MISC_ENABLE
, l1
, l2
);
408 set_cpu_cap(c
, X86_FEATURE_BTS
);
410 set_cpu_cap(c
, X86_FEATURE_PEBS
);
413 if (c
->x86
== 6 && c
->x86_model
== 29 && cpu_has_clflush
)
414 set_cpu_cap(c
, X86_FEATURE_CLFLUSH_MONITOR
);
418 c
->x86_cache_alignment
= c
->x86_clflush_size
* 2;
420 set_cpu_cap(c
, X86_FEATURE_REP_GOOD
);
423 * Names for the Pentium II/Celeron processors
424 * detectable only by also checking the cache size.
425 * Dixon is NOT a Celeron.
430 switch (c
->x86_model
) {
433 p
= "Celeron (Covington)";
435 p
= "Mobile Pentium II (Dixon)";
440 p
= "Celeron (Mendocino)";
441 else if (c
->x86_mask
== 0 || c
->x86_mask
== 5)
447 p
= "Celeron (Coppermine)";
452 strcpy(c
->x86_model_id
, p
);
456 set_cpu_cap(c
, X86_FEATURE_P4
);
458 set_cpu_cap(c
, X86_FEATURE_P3
);
461 if (!cpu_has(c
, X86_FEATURE_XTOPOLOGY
)) {
463 * let's use the legacy cpuid vector 0x1 and 0x4 for topology
466 c
->x86_max_cores
= intel_num_cpu_cores(c
);
472 /* Work around errata */
475 if (cpu_has(c
, X86_FEATURE_VMX
))
476 detect_vmx_virtcap(c
);
479 * Initialize MSR_IA32_ENERGY_PERF_BIAS if BIOS did not.
480 * x86_energy_perf_policy(8) is available to change it at run-time
482 if (cpu_has(c
, X86_FEATURE_EPB
)) {
485 rdmsrl(MSR_IA32_ENERGY_PERF_BIAS
, epb
);
486 if ((epb
& 0xF) == ENERGY_PERF_BIAS_PERFORMANCE
) {
487 printk_once(KERN_WARNING
"ENERGY_PERF_BIAS:"
488 " Set to 'normal', was 'performance'\n"
489 "ENERGY_PERF_BIAS: View and update with"
490 " x86_energy_perf_policy(8)\n");
491 epb
= (epb
& ~0xF) | ENERGY_PERF_BIAS_NORMAL
;
492 wrmsrl(MSR_IA32_ENERGY_PERF_BIAS
, epb
);
496 /* Enable monitor/mwait if BIOS didn't do it for us. */
497 if (!cpu_has(c
, X86_FEATURE_MWAIT
) && cpu_has(c
, X86_FEATURE_XMM3
)
498 && c
->x86
>= 6 && !(c
->x86
== 6 && c
->x86_model
< 0x1c)
499 && !(c
->x86
== 0xf && c
->x86_model
< 3)) {
501 rdmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
502 misc_enable
|= MSR_IA32_MISC_ENABLE_MWAIT
;
505 * Some non-SSE3 cpus will #GP. We check for that,
506 * but it can't hurt to be safe.
508 wrmsr_safe(MSR_IA32_MISC_ENABLE
, (u32
)misc_enable
,
509 (u32
)(misc_enable
>> 32));
511 /* Re-read monitor capability. */
512 if (cpuid_ecx(1) & 0x8) {
513 set_cpu_cap(c
, X86_FEATURE_MWAIT
);
515 printk(KERN_WARNING FW_WARN
"IA32_MISC_ENABLE.ENABLE_MONITOR_FSM was not set\n");
521 static unsigned int __cpuinit
intel_size_cache(struct cpuinfo_x86
*c
, unsigned int size
)
524 * Intel PIII Tualatin. This comes in two flavours.
525 * One has 256kb of cache, the other 512. We have no way
526 * to determine which, so we use a boottime override
527 * for the 512kb model, and assume 256 otherwise.
529 if ((c
->x86
== 6) && (c
->x86_model
== 11) && (size
== 0))
535 static const struct cpu_dev __cpuinitconst intel_cpu_dev
= {
537 .c_ident
= { "GenuineIntel" },
540 { .vendor
= X86_VENDOR_INTEL
, .family
= 4, .model_names
=
542 [0] = "486 DX-25/33",
553 { .vendor
= X86_VENDOR_INTEL
, .family
= 5, .model_names
=
555 [0] = "Pentium 60/66 A-step",
556 [1] = "Pentium 60/66",
557 [2] = "Pentium 75 - 200",
558 [3] = "OverDrive PODP5V83",
560 [7] = "Mobile Pentium 75 - 200",
561 [8] = "Mobile Pentium MMX"
564 { .vendor
= X86_VENDOR_INTEL
, .family
= 6, .model_names
=
566 [0] = "Pentium Pro A-step",
568 [3] = "Pentium II (Klamath)",
569 [4] = "Pentium II (Deschutes)",
570 [5] = "Pentium II (Deschutes)",
571 [6] = "Mobile Pentium II",
572 [7] = "Pentium III (Katmai)",
573 [8] = "Pentium III (Coppermine)",
574 [10] = "Pentium III (Cascades)",
575 [11] = "Pentium III (Tualatin)",
578 { .vendor
= X86_VENDOR_INTEL
, .family
= 15, .model_names
=
580 [0] = "Pentium 4 (Unknown)",
581 [1] = "Pentium 4 (Willamette)",
582 [2] = "Pentium 4 (Northwood)",
583 [4] = "Pentium 4 (Foster)",
584 [5] = "Pentium 4 (Foster)",
588 .c_size_cache
= intel_size_cache
,
590 .c_early_init
= early_init_intel
,
591 .c_init
= init_intel
,
592 .c_x86_vendor
= X86_VENDOR_INTEL
,
595 cpu_dev_register(intel_cpu_dev
);