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
)
32 /* Unmask CPUID levels if masked: */
33 if (c
->x86
> 6 || (c
->x86
== 6 && c
->x86_model
>= 0xd)) {
36 rdmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
38 if (misc_enable
& MSR_IA32_MISC_ENABLE_LIMIT_CPUID
) {
39 misc_enable
&= ~MSR_IA32_MISC_ENABLE_LIMIT_CPUID
;
40 wrmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
41 c
->cpuid_level
= cpuid_eax(0);
46 if ((c
->x86
== 0xf && c
->x86_model
>= 0x03) ||
47 (c
->x86
== 0x6 && c
->x86_model
>= 0x0e))
48 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
51 * Atom erratum AAE44/AAF40/AAG38/AAH41:
53 * A race condition between speculative fetches and invalidating
54 * a large page. This is worked around in microcode, but we
55 * need the microcode to have already been loaded... so if it is
56 * not, recommend a BIOS update and disable large pages.
58 if (c
->x86
== 6 && c
->x86_model
== 0x1c && c
->x86_mask
<= 2) {
61 wrmsr(MSR_IA32_UCODE_REV
, 0, 0);
63 rdmsr(MSR_IA32_UCODE_REV
, junk
, ucode
);
66 printk(KERN_WARNING
"Atom PSE erratum detected, BIOS microcode update recommended\n");
67 clear_cpu_cap(c
, X86_FEATURE_PSE
);
72 set_cpu_cap(c
, X86_FEATURE_SYSENTER32
);
74 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
75 if (c
->x86
== 15 && c
->x86_cache_alignment
== 64)
76 c
->x86_cache_alignment
= 128;
79 if (c
->x86
== 0xF && c
->x86_model
== 0x3
80 && (c
->x86_mask
== 0x3 || c
->x86_mask
== 0x4))
81 c
->x86_phys_bits
= 36;
84 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
85 * with P/T states and does not stop in deep C-states.
87 * It is also reliable across cores and sockets. (but not across
88 * cabinets - we turn it off in that case explicitly.)
90 if (c
->x86_power
& (1 << 8)) {
91 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
92 set_cpu_cap(c
, X86_FEATURE_NONSTOP_TSC
);
93 if (!check_tsc_unstable())
94 sched_clock_stable
= 1;
98 * There is a known erratum on Pentium III and Core Solo
100 * " Page with PAT set to WC while associated MTRR is UC
101 * may consolidate to UC "
102 * Because of this erratum, it is better to stick with
103 * setting WC in MTRR rather than using PAT on these CPUs.
105 * Enable PAT WC only on P4, Core 2 or later CPUs.
107 if (c
->x86
== 6 && c
->x86_model
< 15)
108 clear_cpu_cap(c
, X86_FEATURE_PAT
);
110 #ifdef CONFIG_KMEMCHECK
112 * P4s have a "fast strings" feature which causes single-
113 * stepping REP instructions to only generate a #DB on
114 * cache-line boundaries.
116 * Ingo Molnar reported a Pentium D (model 6) and a Xeon
117 * (model 2) with the same problem.
122 rdmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
124 if (misc_enable
& MSR_IA32_MISC_ENABLE_FAST_STRING
) {
125 printk(KERN_INFO
"kmemcheck: Disabling fast string operations\n");
127 misc_enable
&= ~MSR_IA32_MISC_ENABLE_FAST_STRING
;
128 wrmsrl(MSR_IA32_MISC_ENABLE
, misc_enable
);
136 * Early probe support logic for ppro memory erratum #50
138 * This is called before we do cpu ident work
141 int __cpuinit
ppro_with_ram_bug(void)
143 /* Uses data from early_cpu_detect now */
144 if (boot_cpu_data
.x86_vendor
== X86_VENDOR_INTEL
&&
145 boot_cpu_data
.x86
== 6 &&
146 boot_cpu_data
.x86_model
== 1 &&
147 boot_cpu_data
.x86_mask
< 8) {
148 printk(KERN_INFO
"Pentium Pro with Errata#50 detected. Taking evasive action.\n");
154 #ifdef CONFIG_X86_F00F_BUG
155 static void __cpuinit
trap_init_f00f_bug(void)
157 __set_fixmap(FIX_F00F_IDT
, __pa(&idt_table
), PAGE_KERNEL_RO
);
160 * Update the IDT descriptor and reload the IDT so that
161 * it uses the read-only mapped virtual address.
163 idt_descr
.address
= fix_to_virt(FIX_F00F_IDT
);
164 load_idt(&idt_descr
);
168 static void __cpuinit
intel_smp_check(struct cpuinfo_x86
*c
)
171 /* calling is from identify_secondary_cpu() ? */
172 if (c
->cpu_index
== boot_cpu_id
)
176 * Mask B, Pentium, but not Pentium MMX
179 c
->x86_mask
>= 1 && c
->x86_mask
<= 4 &&
182 * Remember we have B step Pentia with bugs
184 WARN_ONCE(1, "WARNING: SMP operation may be unreliable"
185 "with B stepping processors.\n");
190 static void __cpuinit
intel_workarounds(struct cpuinfo_x86
*c
)
192 unsigned long lo
, hi
;
194 #ifdef CONFIG_X86_F00F_BUG
196 if (!paravirt_enabled() && c
->x86
== 5) {
197 static int f00f_workaround_enabled
;
200 if (!f00f_workaround_enabled
) {
201 trap_init_f00f_bug();
202 printk(KERN_NOTICE
"Intel Pentium with F0 0F bug - workaround enabled.\n");
203 f00f_workaround_enabled
= 1;
209 * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
212 if ((c
->x86
<<8 | c
->x86_model
<<4 | c
->x86_mask
) < 0x633)
213 clear_cpu_cap(c
, X86_FEATURE_SEP
);
215 if ((c
->x86
== 15) && (c
->x86_model
== 1) && (c
->x86_mask
== 1)) {
216 rdmsr(MSR_IA32_MISC_ENABLE
, lo
, hi
);
217 if ((lo
& MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE
) == 0) {
218 printk (KERN_INFO
"CPU: C0 stepping P4 Xeon detected.\n");
219 printk (KERN_INFO
"CPU: Disabling hardware prefetching (Errata 037)\n");
220 lo
|= MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE
;
221 wrmsr(MSR_IA32_MISC_ENABLE
, lo
, hi
);
226 * See if we have a good local APIC by checking for buggy Pentia,
227 * i.e. all B steppings and the C2 stepping of P54C when using their
228 * integrated APIC (see 11AP erratum in "Pentium Processor
229 * Specification Update").
231 if (cpu_has_apic
&& (c
->x86
<<8 | c
->x86_model
<<4) == 0x520 &&
232 (c
->x86_mask
< 0x6 || c
->x86_mask
== 0xb))
233 set_cpu_cap(c
, X86_FEATURE_11AP
);
236 #ifdef CONFIG_X86_INTEL_USERCOPY
238 * Set up the preferred alignment for movsl bulk memory moves
241 case 4: /* 486: untested */
243 case 5: /* Old Pentia: untested */
245 case 6: /* PII/PIII only like movsl with 8-byte alignment */
248 case 15: /* P4 is OK down to 8-byte alignment */
254 #ifdef CONFIG_X86_NUMAQ
261 static void __cpuinit
intel_workarounds(struct cpuinfo_x86
*c
)
266 static void __cpuinit
srat_detect_node(struct cpuinfo_x86
*c
)
268 #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
270 int cpu
= smp_processor_id();
271 int apicid
= cpu_has_apic
? hard_smp_processor_id() : c
->apicid
;
273 /* Don't do the funky fallback heuristics the AMD version employs
275 node
= apicid_to_node
[apicid
];
276 if (node
== NUMA_NO_NODE
)
277 node
= first_node(node_online_map
);
278 else if (!node_online(node
)) {
279 /* reuse the value from init_cpu_to_node() */
280 node
= cpu_to_node(cpu
);
282 numa_set_node(cpu
, node
);
287 * find out the number of processor cores on the die
289 static int __cpuinit
intel_num_cpu_cores(struct cpuinfo_x86
*c
)
291 unsigned int eax
, ebx
, ecx
, edx
;
293 if (c
->cpuid_level
< 4)
296 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
297 cpuid_count(4, 0, &eax
, &ebx
, &ecx
, &edx
);
299 return (eax
>> 26) + 1;
304 static void __cpuinit
detect_vmx_virtcap(struct cpuinfo_x86
*c
)
306 /* Intel VMX MSR indicated features */
307 #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
308 #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
309 #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
310 #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
311 #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
312 #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
314 u32 vmx_msr_low
, vmx_msr_high
, msr_ctl
, msr_ctl2
;
316 clear_cpu_cap(c
, X86_FEATURE_TPR_SHADOW
);
317 clear_cpu_cap(c
, X86_FEATURE_VNMI
);
318 clear_cpu_cap(c
, X86_FEATURE_FLEXPRIORITY
);
319 clear_cpu_cap(c
, X86_FEATURE_EPT
);
320 clear_cpu_cap(c
, X86_FEATURE_VPID
);
322 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS
, vmx_msr_low
, vmx_msr_high
);
323 msr_ctl
= vmx_msr_high
| vmx_msr_low
;
324 if (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW
)
325 set_cpu_cap(c
, X86_FEATURE_TPR_SHADOW
);
326 if (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_VNMI
)
327 set_cpu_cap(c
, X86_FEATURE_VNMI
);
328 if (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS
) {
329 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2
,
330 vmx_msr_low
, vmx_msr_high
);
331 msr_ctl2
= vmx_msr_high
| vmx_msr_low
;
332 if ((msr_ctl2
& X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC
) &&
333 (msr_ctl
& X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW
))
334 set_cpu_cap(c
, X86_FEATURE_FLEXPRIORITY
);
335 if (msr_ctl2
& X86_VMX_FEATURE_PROC_CTLS2_EPT
)
336 set_cpu_cap(c
, X86_FEATURE_EPT
);
337 if (msr_ctl2
& X86_VMX_FEATURE_PROC_CTLS2_VPID
)
338 set_cpu_cap(c
, X86_FEATURE_VPID
);
342 static void __cpuinit
init_intel(struct cpuinfo_x86
*c
)
348 intel_workarounds(c
);
351 * Detect the extended topology information if available. This
352 * will reinitialise the initial_apicid which will be used
353 * in init_intel_cacheinfo()
355 detect_extended_topology(c
);
357 l2
= init_intel_cacheinfo(c
);
358 if (c
->cpuid_level
> 9) {
359 unsigned eax
= cpuid_eax(10);
360 /* Check for version and the number of counters */
361 if ((eax
& 0xff) && (((eax
>>8) & 0xff) > 1))
362 set_cpu_cap(c
, X86_FEATURE_ARCH_PERFMON
);
366 set_cpu_cap(c
, X86_FEATURE_LFENCE_RDTSC
);
369 rdmsr(MSR_IA32_MISC_ENABLE
, l1
, l2
);
371 set_cpu_cap(c
, X86_FEATURE_BTS
);
373 set_cpu_cap(c
, X86_FEATURE_PEBS
);
376 if (c
->x86
== 6 && c
->x86_model
== 29 && cpu_has_clflush
)
377 set_cpu_cap(c
, X86_FEATURE_CLFLUSH_MONITOR
);
381 c
->x86_cache_alignment
= c
->x86_clflush_size
* 2;
383 set_cpu_cap(c
, X86_FEATURE_REP_GOOD
);
386 * Names for the Pentium II/Celeron processors
387 * detectable only by also checking the cache size.
388 * Dixon is NOT a Celeron.
393 switch (c
->x86_model
) {
395 if (c
->x86_mask
== 0) {
397 p
= "Celeron (Covington)";
399 p
= "Mobile Pentium II (Dixon)";
405 p
= "Celeron (Mendocino)";
406 else if (c
->x86_mask
== 0 || c
->x86_mask
== 5)
412 p
= "Celeron (Coppermine)";
417 strcpy(c
->x86_model_id
, p
);
421 set_cpu_cap(c
, X86_FEATURE_P4
);
423 set_cpu_cap(c
, X86_FEATURE_P3
);
426 if (!cpu_has(c
, X86_FEATURE_XTOPOLOGY
)) {
428 * let's use the legacy cpuid vector 0x1 and 0x4 for topology
431 c
->x86_max_cores
= intel_num_cpu_cores(c
);
439 if (cpu_has(c
, X86_FEATURE_VMX
))
440 detect_vmx_virtcap(c
);
444 static unsigned int __cpuinit
intel_size_cache(struct cpuinfo_x86
*c
, unsigned int size
)
447 * Intel PIII Tualatin. This comes in two flavours.
448 * One has 256kb of cache, the other 512. We have no way
449 * to determine which, so we use a boottime override
450 * for the 512kb model, and assume 256 otherwise.
452 if ((c
->x86
== 6) && (c
->x86_model
== 11) && (size
== 0))
458 static const struct cpu_dev __cpuinitconst intel_cpu_dev
= {
460 .c_ident
= { "GenuineIntel" },
463 { .vendor
= X86_VENDOR_INTEL
, .family
= 4, .model_names
=
465 [0] = "486 DX-25/33",
476 { .vendor
= X86_VENDOR_INTEL
, .family
= 5, .model_names
=
478 [0] = "Pentium 60/66 A-step",
479 [1] = "Pentium 60/66",
480 [2] = "Pentium 75 - 200",
481 [3] = "OverDrive PODP5V83",
483 [7] = "Mobile Pentium 75 - 200",
484 [8] = "Mobile Pentium MMX"
487 { .vendor
= X86_VENDOR_INTEL
, .family
= 6, .model_names
=
489 [0] = "Pentium Pro A-step",
491 [3] = "Pentium II (Klamath)",
492 [4] = "Pentium II (Deschutes)",
493 [5] = "Pentium II (Deschutes)",
494 [6] = "Mobile Pentium II",
495 [7] = "Pentium III (Katmai)",
496 [8] = "Pentium III (Coppermine)",
497 [10] = "Pentium III (Cascades)",
498 [11] = "Pentium III (Tualatin)",
501 { .vendor
= X86_VENDOR_INTEL
, .family
= 15, .model_names
=
503 [0] = "Pentium 4 (Unknown)",
504 [1] = "Pentium 4 (Willamette)",
505 [2] = "Pentium 4 (Northwood)",
506 [4] = "Pentium 4 (Foster)",
507 [5] = "Pentium 4 (Foster)",
511 .c_size_cache
= intel_size_cache
,
513 .c_early_init
= early_init_intel
,
514 .c_init
= init_intel
,
515 .c_x86_vendor
= X86_VENDOR_INTEL
,
518 cpu_dev_register(intel_cpu_dev
);