blob: cd413d9a021801e821acf68f4085bdaf3e61f935 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/init.h>
2#include <linux/kernel.h>
3
4#include <linux/string.h>
5#include <linux/bitops.h>
6#include <linux/smp.h>
7#include <linux/thread_info.h>
Nick Piggin53e86b92005-11-13 16:07:23 -08008#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <asm/processor.h>
Sam Ravnborgd72b1b42007-10-17 18:04:33 +020011#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/msr.h>
13#include <asm/uaccess.h>
Markus Metzgereee3af42008-01-30 13:31:09 +010014#include <asm/ds.h>
Harvey Harrison73bdb732008-02-04 16:48:04 +010015#include <asm/bugs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Yinghai Lu185f3b92008-09-09 16:40:35 -070017#ifdef CONFIG_X86_64
18#include <asm/topology.h>
19#include <asm/numa_64.h>
20#endif
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "cpu.h"
23
24#ifdef CONFIG_X86_LOCAL_APIC
25#include <asm/mpspec.h>
26#include <asm/apic.h>
27#include <mach_apic.h>
28#endif
29
Thomas Petazzoni03ae5762008-02-15 12:00:23 +010030static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Andi Kleen2b16a232008-01-30 13:32:40 +010032 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
33 (c->x86 == 0x6 && c->x86_model >= 0x0e))
34 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
Yinghai Lu185f3b92008-09-09 16:40:35 -070035
36#ifdef CONFIG_X86_64
37 set_cpu_cap(c, X86_FEATURE_SYSENTER32);
38#else
39 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
40 if (c->x86 == 15 && c->x86_cache_alignment == 64)
41 c->x86_cache_alignment = 128;
42#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Yinghai Lu185f3b92008-09-09 16:40:35 -070045#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/*
47 * Early probe support logic for ppro memory erratum #50
48 *
49 * This is called before we do cpu ident work
50 */
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010051
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080052int __cpuinit ppro_with_ram_bug(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 /* Uses data from early_cpu_detect now */
55 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
56 boot_cpu_data.x86 == 6 &&
57 boot_cpu_data.x86_model == 1 &&
58 boot_cpu_data.x86_mask < 8) {
59 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
60 return 1;
61 }
62 return 0;
63}
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010064
Yinghai Lu185f3b92008-09-09 16:40:35 -070065#ifdef CONFIG_X86_F00F_BUG
66static void __cpuinit trap_init_f00f_bug(void)
67{
68 __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
69
70 /*
71 * Update the IDT descriptor and reload the IDT so that
72 * it uses the read-only mapped virtual address.
73 */
74 idt_descr.address = fix_to_virt(FIX_F00F_IDT);
75 load_idt(&idt_descr);
76}
77#endif
Yinghai Lu40527042008-09-09 16:40:38 -070078
79static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
80{
81 unsigned long lo, hi;
82
83#ifdef CONFIG_X86_F00F_BUG
84 /*
85 * All current models of Pentium and Pentium with MMX technology CPUs
86 * have the F0 0F bug, which lets nonprivileged users lock up the system.
87 * Note that the workaround only should be initialized once...
88 */
89 c->f00f_bug = 0;
90 if (!paravirt_enabled() && c->x86 == 5) {
91 static int f00f_workaround_enabled;
92
93 c->f00f_bug = 1;
94 if (!f00f_workaround_enabled) {
95 trap_init_f00f_bug();
96 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
97 f00f_workaround_enabled = 1;
98 }
99 }
100#endif
101
102 /*
103 * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
104 * model 3 mask 3
105 */
106 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
107 clear_cpu_cap(c, X86_FEATURE_SEP);
108
109 /*
110 * P4 Xeon errata 037 workaround.
111 * Hardware prefetcher may cause stale data to be loaded into the cache.
112 */
113 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
114 rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
115 if ((lo & (1<<9)) == 0) {
116 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
117 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
118 lo |= (1<<9); /* Disable hw prefetching */
119 wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
120 }
121 }
122
123 /*
124 * See if we have a good local APIC by checking for buggy Pentia,
125 * i.e. all B steppings and the C2 stepping of P54C when using their
126 * integrated APIC (see 11AP erratum in "Pentium Processor
127 * Specification Update").
128 */
129 if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
130 (c->x86_mask < 0x6 || c->x86_mask == 0xb))
131 set_cpu_cap(c, X86_FEATURE_11AP);
132
133
134#ifdef CONFIG_X86_INTEL_USERCOPY
135 /*
136 * Set up the preferred alignment for movsl bulk memory moves
137 */
138 switch (c->x86) {
139 case 4: /* 486: untested */
140 break;
141 case 5: /* Old Pentia: untested */
142 break;
143 case 6: /* PII/PIII only like movsl with 8-byte alignment */
144 movsl_mask.mask = 7;
145 break;
146 case 15: /* P4 is OK down to 8-byte alignment */
147 movsl_mask.mask = 7;
148 break;
149 }
150#endif
151
152#ifdef CONFIG_X86_NUMAQ
153 numaq_tsc_disable();
154#endif
155}
156#else
157static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
158{
159}
Yinghai Lu185f3b92008-09-09 16:40:35 -0700160#endif
161
162static void __cpuinit srat_detect_node(void)
163{
164#if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
165 unsigned node;
166 int cpu = smp_processor_id();
167 int apicid = hard_smp_processor_id();
168
169 /* Don't do the funky fallback heuristics the AMD version employs
170 for now. */
171 node = apicid_to_node[apicid];
172 if (node == NUMA_NO_NODE || !node_online(node))
173 node = first_node(node_online_map);
174 numa_set_node(cpu, node);
175
Yinghai Lu823b2592008-09-10 21:56:46 -0700176 printk(KERN_INFO "CPU %d/0x%x -> Node %d\n", cpu, apicid, node);
Yinghai Lu185f3b92008-09-09 16:40:35 -0700177#endif
178}
179
Andi Kleen3dd9d512005-04-16 15:25:15 -0700180/*
181 * find out the number of processor cores on the die
182 */
Yinghai Luf69feff2008-09-07 17:58:58 -0700183static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
Andi Kleen3dd9d512005-04-16 15:25:15 -0700184{
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700185 unsigned int eax, ebx, ecx, edx;
Andi Kleen3dd9d512005-04-16 15:25:15 -0700186
187 if (c->cpuid_level < 4)
188 return 1;
189
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700190 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
191 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
Andi Kleen3dd9d512005-04-16 15:25:15 -0700192 if (eax & 0x1f)
193 return ((eax >> 26) + 1);
194 else
195 return 1;
196}
197
Sheng Yange38e05a2008-09-10 18:53:34 +0800198static void __cpuinit detect_vmx_virtcap(struct cpuinfo_x86 *c)
199{
200 /* Intel VMX MSR indicated features */
201#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
202#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
203#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
204#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
205#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
206#define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
207
208 u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
209
210 clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
211 clear_cpu_cap(c, X86_FEATURE_VNMI);
212 clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
213 clear_cpu_cap(c, X86_FEATURE_EPT);
214 clear_cpu_cap(c, X86_FEATURE_VPID);
215
216 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
217 msr_ctl = vmx_msr_high | vmx_msr_low;
218 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
219 set_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
220 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
221 set_cpu_cap(c, X86_FEATURE_VNMI);
222 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
223 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
224 vmx_msr_low, vmx_msr_high);
225 msr_ctl2 = vmx_msr_high | vmx_msr_low;
226 if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
227 (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
228 set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
229 if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
230 set_cpu_cap(c, X86_FEATURE_EPT);
231 if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
232 set_cpu_cap(c, X86_FEATURE_VPID);
233 }
234}
235
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800236static void __cpuinit init_intel(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 unsigned int l2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Andi Kleen2b16a232008-01-30 13:32:40 +0100240 early_init_intel(c);
241
Yinghai Lu40527042008-09-09 16:40:38 -0700242 intel_workarounds(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 l2 = init_intel_cacheinfo(c);
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100245 if (c->cpuid_level > 9) {
Venkatesh Pallipadi0080e662006-06-26 13:59:59 +0200246 unsigned eax = cpuid_eax(10);
247 /* Check for version and the number of counters */
248 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100249 set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
Venkatesh Pallipadi0080e662006-06-26 13:59:59 +0200250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Yinghai Lu40527042008-09-09 16:40:38 -0700252 if (cpu_has_xmm2)
253 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
254 if (cpu_has_ds) {
255 unsigned int l1;
256 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
257 if (!(l1 & (1<<11)))
258 set_cpu_cap(c, X86_FEATURE_BTS);
259 if (!(l1 & (1<<12)))
260 set_cpu_cap(c, X86_FEATURE_PEBS);
261 ds_init_intel(c);
262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Yinghai Lu40527042008-09-09 16:40:38 -0700264#ifdef CONFIG_X86_64
265 if (c->x86 == 15)
266 c->x86_cache_alignment = c->x86_clflush_size * 2;
267 if (c->x86 == 6)
268 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
269#else
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100270 /*
271 * Names for the Pentium II/Celeron processors
272 * detectable only by also checking the cache size.
273 * Dixon is NOT a Celeron.
274 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (c->x86 == 6) {
Yinghai Lu40527042008-09-09 16:40:38 -0700276 char *p = NULL;
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 switch (c->x86_model) {
279 case 5:
280 if (c->x86_mask == 0) {
281 if (l2 == 0)
282 p = "Celeron (Covington)";
283 else if (l2 == 256)
284 p = "Mobile Pentium II (Dixon)";
285 }
286 break;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 case 6:
289 if (l2 == 128)
290 p = "Celeron (Mendocino)";
291 else if (c->x86_mask == 0 || c->x86_mask == 5)
292 p = "Celeron-A";
293 break;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 case 8:
296 if (l2 == 128)
297 p = "Celeron (Coppermine)";
298 break;
299 }
Yinghai Lu40527042008-09-09 16:40:38 -0700300
301 if (p)
302 strcpy(c->x86_model_id, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
Yinghai Lu185f3b92008-09-09 16:40:35 -0700305 if (c->x86 == 15)
306 set_cpu_cap(c, X86_FEATURE_P4);
307 if (c->x86 == 6)
308 set_cpu_cap(c, X86_FEATURE_P3);
Markus Metzgerf4166c52008-11-09 14:29:21 +0100309#endif
Yinghai Lu185f3b92008-09-09 16:40:35 -0700310
Yinghai Lu185f3b92008-09-09 16:40:35 -0700311 detect_extended_topology(c);
312 if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
313 /*
314 * let's use the legacy cpuid vector 0x1 and 0x4 for topology
315 * detection.
316 */
317 c->x86_max_cores = intel_num_cpu_cores(c);
318#ifdef CONFIG_X86_32
319 detect_ht(c);
320#endif
321 }
322
323 /* Work around errata */
324 srat_detect_node();
Sheng Yange38e05a2008-09-10 18:53:34 +0800325
326 if (cpu_has(c, X86_FEATURE_VMX))
327 detect_vmx_virtcap(c);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100328}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Yinghai Lu185f3b92008-09-09 16:40:35 -0700330#ifdef CONFIG_X86_32
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100331static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100333 /*
334 * Intel PIII Tualatin. This comes in two flavours.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 * One has 256kb of cache, the other 512. We have no way
336 * to determine which, so we use a boottime override
337 * for the 512kb model, and assume 256 otherwise.
338 */
339 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
340 size = 256;
341 return size;
342}
Yinghai Lu185f3b92008-09-09 16:40:35 -0700343#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800345static struct cpu_dev intel_cpu_dev __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 .c_vendor = "Intel",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100347 .c_ident = { "GenuineIntel" },
Yinghai Lu185f3b92008-09-09 16:40:35 -0700348#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 .c_models = {
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100350 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
351 {
352 [0] = "486 DX-25/33",
353 [1] = "486 DX-50",
354 [2] = "486 SX",
355 [3] = "486 DX/2",
356 [4] = "486 SL",
357 [5] = "486 SX/2",
358 [7] = "486 DX/2-WB",
359 [8] = "486 DX/4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 [9] = "486 DX/4-WB"
361 }
362 },
363 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100364 {
365 [0] = "Pentium 60/66 A-step",
366 [1] = "Pentium 60/66",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 [2] = "Pentium 75 - 200",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100368 [3] = "OverDrive PODP5V83",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 [4] = "Pentium MMX",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100370 [7] = "Mobile Pentium 75 - 200",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 [8] = "Mobile Pentium MMX"
372 }
373 },
374 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 [0] = "Pentium Pro A-step",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100377 [1] = "Pentium Pro",
378 [3] = "Pentium II (Klamath)",
379 [4] = "Pentium II (Deschutes)",
380 [5] = "Pentium II (Deschutes)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 [6] = "Mobile Pentium II",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100382 [7] = "Pentium III (Katmai)",
383 [8] = "Pentium III (Coppermine)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 [10] = "Pentium III (Cascades)",
385 [11] = "Pentium III (Tualatin)",
386 }
387 },
388 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
389 {
390 [0] = "Pentium 4 (Unknown)",
391 [1] = "Pentium 4 (Willamette)",
392 [2] = "Pentium 4 (Northwood)",
393 [4] = "Pentium 4 (Foster)",
394 [5] = "Pentium 4 (Foster)",
395 }
396 },
397 },
Yinghai Lu185f3b92008-09-09 16:40:35 -0700398 .c_size_cache = intel_size_cache,
399#endif
Thomas Petazzoni03ae5762008-02-15 12:00:23 +0100400 .c_early_init = early_init_intel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 .c_init = init_intel,
Yinghai Lu10a434f2008-09-04 21:09:45 +0200402 .c_x86_vendor = X86_VENDOR_INTEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403};
404
Yinghai Lu10a434f2008-09-04 21:09:45 +0200405cpu_dev_register(intel_cpu_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406