blob: 4a8ac9d4ff50e9a5eb1465921ec9b4f33865c8ad [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/ptrace.h>
15#include <asm/ds.h>
Harvey Harrison73bdb732008-02-04 16:48:04 +010016#include <asm/bugs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include "cpu.h"
19
20#ifdef CONFIG_X86_LOCAL_APIC
21#include <asm/mpspec.h>
22#include <asm/apic.h>
23#include <mach_apic.h>
24#endif
25
Thomas Petazzoni03ae5762008-02-15 12:00:23 +010026static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
29 if (c->x86 == 15 && c->x86_cache_alignment == 64)
30 c->x86_cache_alignment = 128;
Andi Kleen2b16a232008-01-30 13:32:40 +010031 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
32 (c->x86 == 0x6 && c->x86_model >= 0x0e))
33 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
36/*
37 * Early probe support logic for ppro memory erratum #50
38 *
39 * This is called before we do cpu ident work
40 */
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010041
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080042int __cpuinit ppro_with_ram_bug(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 /* Uses data from early_cpu_detect now */
45 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
46 boot_cpu_data.x86 == 6 &&
47 boot_cpu_data.x86_model == 1 &&
48 boot_cpu_data.x86_mask < 8) {
49 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
50 return 1;
51 }
52 return 0;
53}
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/*
57 * P4 Xeon errata 037 workaround.
58 * Hardware prefetcher may cause stale data to be loaded into the cache.
59 */
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080060static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 unsigned long lo, hi;
63
64 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010065 rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 if ((lo & (1<<9)) == 0) {
67 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
68 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
69 lo |= (1<<9); /* Disable hw prefetching */
70 wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
71 }
72 }
73}
74
75
Andi Kleen3dd9d512005-04-16 15:25:15 -070076/*
77 * find out the number of processor cores on the die
78 */
Yinghai Luf69feff2008-09-07 17:58:58 -070079static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
Andi Kleen3dd9d512005-04-16 15:25:15 -070080{
Zachary Amsdenf2ab4462005-09-03 15:56:42 -070081 unsigned int eax, ebx, ecx, edx;
Andi Kleen3dd9d512005-04-16 15:25:15 -070082
83 if (c->cpuid_level < 4)
84 return 1;
85
Zachary Amsdenf2ab4462005-09-03 15:56:42 -070086 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
87 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
Andi Kleen3dd9d512005-04-16 15:25:15 -070088 if (eax & 0x1f)
89 return ((eax >> 26) + 1);
90 else
91 return 1;
92}
93
Sam Ravnborgd72b1b42007-10-17 18:04:33 +020094#ifdef CONFIG_X86_F00F_BUG
95static void __cpuinit trap_init_f00f_bug(void)
96{
97 __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
98
99 /*
100 * Update the IDT descriptor and reload the IDT so that
101 * it uses the read-only mapped virtual address.
102 */
103 idt_descr.address = fix_to_virt(FIX_F00F_IDT);
104 load_idt(&idt_descr);
105}
106#endif
107
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800108static void __cpuinit init_intel(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 unsigned int l2 = 0;
111 char *p = NULL;
112
Andi Kleen2b16a232008-01-30 13:32:40 +0100113 early_init_intel(c);
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#ifdef CONFIG_X86_F00F_BUG
116 /*
117 * All current models of Pentium and Pentium with MMX technology CPUs
118 * have the F0 0F bug, which lets nonprivileged users lock up the system.
119 * Note that the workaround only should be initialized once...
120 */
121 c->f00f_bug = 0;
Rusty Russell4f205fd2006-12-07 02:14:08 +0100122 if (!paravirt_enabled() && c->x86 == 5) {
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100123 static int f00f_workaround_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 c->f00f_bug = 1;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100126 if (!f00f_workaround_enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 trap_init_f00f_bug();
128 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
129 f00f_workaround_enabled = 1;
130 }
131 }
132#endif
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 l2 = init_intel_cacheinfo(c);
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100135 if (c->cpuid_level > 9) {
Venkatesh Pallipadi0080e662006-06-26 13:59:59 +0200136 unsigned eax = cpuid_eax(10);
137 /* Check for version and the number of counters */
138 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100139 set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
Venkatesh Pallipadi0080e662006-06-26 13:59:59 +0200140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
143 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100144 clear_cpu_cap(c, X86_FEATURE_SEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100146 /*
147 * Names for the Pentium II/Celeron processors
148 * detectable only by also checking the cache size.
149 * Dixon is NOT a Celeron.
150 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 if (c->x86 == 6) {
152 switch (c->x86_model) {
153 case 5:
154 if (c->x86_mask == 0) {
155 if (l2 == 0)
156 p = "Celeron (Covington)";
157 else if (l2 == 256)
158 p = "Mobile Pentium II (Dixon)";
159 }
160 break;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 case 6:
163 if (l2 == 128)
164 p = "Celeron (Mendocino)";
165 else if (c->x86_mask == 0 || c->x86_mask == 5)
166 p = "Celeron-A";
167 break;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 case 8:
170 if (l2 == 128)
171 p = "Celeron (Coppermine)";
172 break;
173 }
174 }
175
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100176 if (p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 strcpy(c->x86_model_id, p);
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100178
Suresh Siddhabbb65d22008-08-23 17:47:10 +0200179 detect_extended_topology(c);
Andi Kleen3dd9d512005-04-16 15:25:15 -0700180
Suresh Siddhabbb65d22008-08-23 17:47:10 +0200181 if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
182 /*
183 * let's use the legacy cpuid vector 0x1 and 0x4 for topology
184 * detection.
185 */
Yinghai Luf69feff2008-09-07 17:58:58 -0700186 c->x86_max_cores = intel_num_cpu_cores(c);
Suresh Siddhabbb65d22008-08-23 17:47:10 +0200187 detect_ht(c);
188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 /* Work around errata */
191 Intel_errata_workarounds(c);
192
193#ifdef CONFIG_X86_INTEL_USERCOPY
194 /*
195 * Set up the preferred alignment for movsl bulk memory moves
196 */
197 switch (c->x86) {
198 case 4: /* 486: untested */
199 break;
200 case 5: /* Old Pentia: untested */
201 break;
202 case 6: /* PII/PIII only like movsl with 8-byte alignment */
203 movsl_mask.mask = 7;
204 break;
205 case 15: /* P4 is OK down to 8-byte alignment */
206 movsl_mask.mask = 7;
207 break;
208 }
209#endif
210
Ingo Molnar6d5f7182008-01-30 13:32:38 +0100211 if (cpu_has_xmm2)
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100212 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
Yinghai Luf69feff2008-09-07 17:58:58 -0700213 if (c->x86 == 15)
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100214 set_cpu_cap(c, X86_FEATURE_P4);
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100215 if (c->x86 == 6)
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100216 set_cpu_cap(c, X86_FEATURE_P3);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100217 if (cpu_has_ds) {
218 unsigned int l1;
219 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
Stephane Eranian538f1882006-12-07 02:14:11 +0100220 if (!(l1 & (1<<11)))
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100221 set_cpu_cap(c, X86_FEATURE_BTS);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100222 if (!(l1 & (1<<12)))
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100223 set_cpu_cap(c, X86_FEATURE_PEBS);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100224 }
Markus Metzgereee3af42008-01-30 13:31:09 +0100225
226 if (cpu_has_bts)
227 ds_init_intel(c);
Yinghai Lu3d88cca2008-07-12 22:52:55 -0700228
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +0100229 /*
230 * See if we have a good local APIC by checking for buggy Pentia,
231 * i.e. all B steppings and the C2 stepping of P54C when using their
232 * integrated APIC (see 11AP erratum in "Pentium Processor
233 * Specification Update").
234 */
235 if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
236 (c->x86_mask < 0x6 || c->x86_mask == 0xb))
237 set_cpu_cap(c, X86_FEATURE_11AP);
238
Yinghai Lu3d88cca2008-07-12 22:52:55 -0700239#ifdef CONFIG_X86_NUMAQ
240 numaq_tsc_disable();
241#endif
Stephane Eranian42ed4582006-12-07 02:14:01 +0100242}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100244static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100246 /*
247 * Intel PIII Tualatin. This comes in two flavours.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 * One has 256kb of cache, the other 512. We have no way
249 * to determine which, so we use a boottime override
250 * for the 512kb model, and assume 256 otherwise.
251 */
252 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
253 size = 256;
254 return size;
255}
256
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800257static struct cpu_dev intel_cpu_dev __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 .c_vendor = "Intel",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100259 .c_ident = { "GenuineIntel" },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 .c_models = {
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100261 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
262 {
263 [0] = "486 DX-25/33",
264 [1] = "486 DX-50",
265 [2] = "486 SX",
266 [3] = "486 DX/2",
267 [4] = "486 SL",
268 [5] = "486 SX/2",
269 [7] = "486 DX/2-WB",
270 [8] = "486 DX/4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 [9] = "486 DX/4-WB"
272 }
273 },
274 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100275 {
276 [0] = "Pentium 60/66 A-step",
277 [1] = "Pentium 60/66",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 [2] = "Pentium 75 - 200",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100279 [3] = "OverDrive PODP5V83",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 [4] = "Pentium MMX",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100281 [7] = "Mobile Pentium 75 - 200",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 [8] = "Mobile Pentium MMX"
283 }
284 },
285 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 [0] = "Pentium Pro A-step",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100288 [1] = "Pentium Pro",
289 [3] = "Pentium II (Klamath)",
290 [4] = "Pentium II (Deschutes)",
291 [5] = "Pentium II (Deschutes)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 [6] = "Mobile Pentium II",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100293 [7] = "Pentium III (Katmai)",
294 [8] = "Pentium III (Coppermine)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 [10] = "Pentium III (Cascades)",
296 [11] = "Pentium III (Tualatin)",
297 }
298 },
299 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
300 {
301 [0] = "Pentium 4 (Unknown)",
302 [1] = "Pentium 4 (Willamette)",
303 [2] = "Pentium 4 (Northwood)",
304 [4] = "Pentium 4 (Foster)",
305 [5] = "Pentium 4 (Foster)",
306 }
307 },
308 },
Thomas Petazzoni03ae5762008-02-15 12:00:23 +0100309 .c_early_init = early_init_intel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 .c_init = init_intel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 .c_size_cache = intel_size_cache,
Yinghai Lu10a434f2008-09-04 21:09:45 +0200312 .c_x86_vendor = X86_VENDOR_INTEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313};
314
Yinghai Lu10a434f2008-09-04 21:09:45 +0200315cpu_dev_register(intel_cpu_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100317/* arch_initcall(intel_cpu_init); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318