blob: cbffa2a25a1334e53a7e65f637da6e647d182aba [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#ifdef CONFIG_X86_INTEL_USERCOPY
27/*
28 * Alignment at which movsl is preferred for bulk memory copies.
29 */
Christoph Lameter6c036522005-07-07 17:56:59 -070030struct movsl_mask movsl_mask __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#endif
32
Thomas Petazzoni03ae5762008-02-15 12:00:23 +010033static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
36 if (c->x86 == 15 && c->x86_cache_alignment == 64)
37 c->x86_cache_alignment = 128;
Andi Kleen2b16a232008-01-30 13:32:40 +010038 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
39 (c->x86 == 0x6 && c->x86_model >= 0x0e))
40 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
43/*
44 * Early probe support logic for ppro memory erratum #50
45 *
46 * This is called before we do cpu ident work
47 */
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010048
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080049int __cpuinit ppro_with_ram_bug(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
51 /* Uses data from early_cpu_detect now */
52 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
53 boot_cpu_data.x86 == 6 &&
54 boot_cpu_data.x86_model == 1 &&
55 boot_cpu_data.x86_mask < 8) {
56 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
57 return 1;
58 }
59 return 0;
60}
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/*
64 * P4 Xeon errata 037 workaround.
65 * Hardware prefetcher may cause stale data to be loaded into the cache.
66 */
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080067static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 unsigned long lo, hi;
70
71 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +010072 rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if ((lo & (1<<9)) == 0) {
74 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
75 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
76 lo |= (1<<9); /* Disable hw prefetching */
77 wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
78 }
79 }
80}
81
82
Andi Kleen3dd9d512005-04-16 15:25:15 -070083/*
84 * find out the number of processor cores on the die
85 */
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080086static int __cpuinit num_cpu_cores(struct cpuinfo_x86 *c)
Andi Kleen3dd9d512005-04-16 15:25:15 -070087{
Zachary Amsdenf2ab4462005-09-03 15:56:42 -070088 unsigned int eax, ebx, ecx, edx;
Andi Kleen3dd9d512005-04-16 15:25:15 -070089
90 if (c->cpuid_level < 4)
91 return 1;
92
Zachary Amsdenf2ab4462005-09-03 15:56:42 -070093 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
94 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
Andi Kleen3dd9d512005-04-16 15:25:15 -070095 if (eax & 0x1f)
96 return ((eax >> 26) + 1);
97 else
98 return 1;
99}
100
Sam Ravnborgd72b1b42007-10-17 18:04:33 +0200101#ifdef CONFIG_X86_F00F_BUG
102static void __cpuinit trap_init_f00f_bug(void)
103{
104 __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
105
106 /*
107 * Update the IDT descriptor and reload the IDT so that
108 * it uses the read-only mapped virtual address.
109 */
110 idt_descr.address = fix_to_virt(FIX_F00F_IDT);
111 load_idt(&idt_descr);
112}
113#endif
114
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800115static void __cpuinit init_intel(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 unsigned int l2 = 0;
118 char *p = NULL;
119
Andi Kleen2b16a232008-01-30 13:32:40 +0100120 early_init_intel(c);
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#ifdef CONFIG_X86_F00F_BUG
123 /*
124 * All current models of Pentium and Pentium with MMX technology CPUs
125 * have the F0 0F bug, which lets nonprivileged users lock up the system.
126 * Note that the workaround only should be initialized once...
127 */
128 c->f00f_bug = 0;
Rusty Russell4f205fd2006-12-07 02:14:08 +0100129 if (!paravirt_enabled() && c->x86 == 5) {
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100130 static int f00f_workaround_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 c->f00f_bug = 1;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100133 if (!f00f_workaround_enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 trap_init_f00f_bug();
135 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
136 f00f_workaround_enabled = 1;
137 }
138 }
139#endif
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 l2 = init_intel_cacheinfo(c);
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100142 if (c->cpuid_level > 9) {
Venkatesh Pallipadi0080e662006-06-26 13:59:59 +0200143 unsigned eax = cpuid_eax(10);
144 /* Check for version and the number of counters */
145 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100146 set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
Venkatesh Pallipadi0080e662006-06-26 13:59:59 +0200147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
150 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100151 clear_cpu_cap(c, X86_FEATURE_SEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100153 /*
154 * Names for the Pentium II/Celeron processors
155 * detectable only by also checking the cache size.
156 * Dixon is NOT a Celeron.
157 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 if (c->x86 == 6) {
159 switch (c->x86_model) {
160 case 5:
161 if (c->x86_mask == 0) {
162 if (l2 == 0)
163 p = "Celeron (Covington)";
164 else if (l2 == 256)
165 p = "Mobile Pentium II (Dixon)";
166 }
167 break;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 case 6:
170 if (l2 == 128)
171 p = "Celeron (Mendocino)";
172 else if (c->x86_mask == 0 || c->x86_mask == 5)
173 p = "Celeron-A";
174 break;
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 case 8:
177 if (l2 == 128)
178 p = "Celeron (Coppermine)";
179 break;
180 }
181 }
182
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100183 if (p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 strcpy(c->x86_model_id, p);
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100185
Siddha, Suresh B94605ef2005-11-05 17:25:54 +0100186 c->x86_max_cores = num_cpu_cores(c);
Andi Kleen3dd9d512005-04-16 15:25:15 -0700187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 detect_ht(c);
189
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);
Andi Kleen3aefbe02007-05-02 19:27:20 +0200213 if (c->x86 == 15) {
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100214 set_cpu_cap(c, X86_FEATURE_P4);
Andi Kleen3aefbe02007-05-02 19:27:20 +0200215 }
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100216 if (c->x86 == 6)
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100217 set_cpu_cap(c, X86_FEATURE_P3);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100218 if (cpu_has_ds) {
219 unsigned int l1;
220 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
Stephane Eranian538f1882006-12-07 02:14:11 +0100221 if (!(l1 & (1<<11)))
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100222 set_cpu_cap(c, X86_FEATURE_BTS);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100223 if (!(l1 & (1<<12)))
Ingo Molnard0e95eb2008-02-26 08:52:33 +0100224 set_cpu_cap(c, X86_FEATURE_PEBS);
Markus Metzger93fa7632008-04-08 11:01:58 +0200225 ds_init_intel(c);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100226 }
Markus Metzgereee3af42008-01-30 13:31:09 +0100227
228 if (cpu_has_bts)
Markus Metzger93fa7632008-04-08 11:01:58 +0200229 ptrace_bts_init_intel(c);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100230}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100232static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100234 /*
235 * Intel PIII Tualatin. This comes in two flavours.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 * One has 256kb of cache, the other 512. We have no way
237 * to determine which, so we use a boottime override
238 * for the 512kb model, and assume 256 otherwise.
239 */
240 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
241 size = 256;
242 return size;
243}
244
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800245static struct cpu_dev intel_cpu_dev __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .c_vendor = "Intel",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100247 .c_ident = { "GenuineIntel" },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 .c_models = {
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100249 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
250 {
251 [0] = "486 DX-25/33",
252 [1] = "486 DX-50",
253 [2] = "486 SX",
254 [3] = "486 DX/2",
255 [4] = "486 SL",
256 [5] = "486 SX/2",
257 [7] = "486 DX/2-WB",
258 [8] = "486 DX/4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 [9] = "486 DX/4-WB"
260 }
261 },
262 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100263 {
264 [0] = "Pentium 60/66 A-step",
265 [1] = "Pentium 60/66",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 [2] = "Pentium 75 - 200",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100267 [3] = "OverDrive PODP5V83",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 [4] = "Pentium MMX",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100269 [7] = "Mobile Pentium 75 - 200",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 [8] = "Mobile Pentium MMX"
271 }
272 },
273 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100274 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 [0] = "Pentium Pro A-step",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100276 [1] = "Pentium Pro",
277 [3] = "Pentium II (Klamath)",
278 [4] = "Pentium II (Deschutes)",
279 [5] = "Pentium II (Deschutes)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 [6] = "Mobile Pentium II",
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100281 [7] = "Pentium III (Katmai)",
282 [8] = "Pentium III (Coppermine)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 [10] = "Pentium III (Cascades)",
284 [11] = "Pentium III (Tualatin)",
285 }
286 },
287 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
288 {
289 [0] = "Pentium 4 (Unknown)",
290 [1] = "Pentium 4 (Willamette)",
291 [2] = "Pentium 4 (Northwood)",
292 [4] = "Pentium 4 (Foster)",
293 [5] = "Pentium 4 (Foster)",
294 }
295 },
296 },
Thomas Petazzoni03ae5762008-02-15 12:00:23 +0100297 .c_early_init = early_init_intel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 .c_init = init_intel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 .c_size_cache = intel_size_cache,
300};
301
Thomas Petazzoni03ae5762008-02-15 12:00:23 +0100302cpu_vendor_dev_register(X86_VENDOR_INTEL, &intel_cpu_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Nick Piggin53e86b92005-11-13 16:07:23 -0800304#ifndef CONFIG_X86_CMPXCHG
305unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new)
306{
307 u8 prev;
308 unsigned long flags;
309
310 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
311 local_irq_save(flags);
312 prev = *(u8 *)ptr;
313 if (prev == old)
314 *(u8 *)ptr = new;
315 local_irq_restore(flags);
316 return prev;
317}
318EXPORT_SYMBOL(cmpxchg_386_u8);
319
320unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new)
321{
322 u16 prev;
323 unsigned long flags;
324
325 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
326 local_irq_save(flags);
327 prev = *(u16 *)ptr;
328 if (prev == old)
329 *(u16 *)ptr = new;
330 local_irq_restore(flags);
331 return prev;
332}
333EXPORT_SYMBOL(cmpxchg_386_u16);
334
335unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new)
336{
337 u32 prev;
338 unsigned long flags;
339
340 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
341 local_irq_save(flags);
342 prev = *(u32 *)ptr;
343 if (prev == old)
344 *(u32 *)ptr = new;
345 local_irq_restore(flags);
346 return prev;
347}
348EXPORT_SYMBOL(cmpxchg_386_u32);
349#endif
350
Mathieu Desnoyers2c0b8a72008-01-30 13:30:47 +0100351#ifndef CONFIG_X86_CMPXCHG64
352unsigned long long cmpxchg_486_u64(volatile void *ptr, u64 old, u64 new)
353{
354 u64 prev;
355 unsigned long flags;
356
357 /* Poor man's cmpxchg8b for 386 and 486. Unsuitable for SMP */
358 local_irq_save(flags);
359 prev = *(u64 *)ptr;
360 if (prev == old)
361 *(u64 *)ptr = new;
362 local_irq_restore(flags);
363 return prev;
364}
365EXPORT_SYMBOL(cmpxchg_486_u64);
366#endif
367
Paolo Ciarrocchi65eb6b42008-02-22 23:09:42 +0100368/* arch_initcall(intel_cpu_init); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369