blob: 0a4abdb61ae4e3a89fd8ed5dbda1f0dd37279e24 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include "cpu.h"
18
19#ifdef CONFIG_X86_LOCAL_APIC
20#include <asm/mpspec.h>
21#include <asm/apic.h>
22#include <mach_apic.h>
23#endif
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#ifdef CONFIG_X86_INTEL_USERCOPY
26/*
27 * Alignment at which movsl is preferred for bulk memory copies.
28 */
Christoph Lameter6c036522005-07-07 17:56:59 -070029struct movsl_mask movsl_mask __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#endif
31
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080032void __cpuinit early_intel_workaround(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 if (c->x86_vendor != X86_VENDOR_INTEL)
35 return;
36 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
37 if (c->x86 == 15 && c->x86_cache_alignment == 64)
38 c->x86_cache_alignment = 128;
39}
40
41/*
42 * Early probe support logic for ppro memory erratum #50
43 *
44 * This is called before we do cpu ident work
45 */
46
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080047int __cpuinit ppro_with_ram_bug(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
49 /* Uses data from early_cpu_detect now */
50 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
51 boot_cpu_data.x86 == 6 &&
52 boot_cpu_data.x86_model == 1 &&
53 boot_cpu_data.x86_mask < 8) {
54 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
55 return 1;
56 }
57 return 0;
58}
59
60
61/*
62 * P4 Xeon errata 037 workaround.
63 * Hardware prefetcher may cause stale data to be loaded into the cache.
64 */
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080065static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 unsigned long lo, hi;
68
69 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
70 rdmsr (MSR_IA32_MISC_ENABLE, lo, hi);
71 if ((lo & (1<<9)) == 0) {
72 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
73 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
74 lo |= (1<<9); /* Disable hw prefetching */
75 wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
76 }
77 }
78}
79
80
Andi Kleen3dd9d512005-04-16 15:25:15 -070081/*
82 * find out the number of processor cores on the die
83 */
Chuck Ebbert3bc9b762006-03-23 02:59:33 -080084static int __cpuinit num_cpu_cores(struct cpuinfo_x86 *c)
Andi Kleen3dd9d512005-04-16 15:25:15 -070085{
Zachary Amsdenf2ab4462005-09-03 15:56:42 -070086 unsigned int eax, ebx, ecx, edx;
Andi Kleen3dd9d512005-04-16 15:25:15 -070087
88 if (c->cpuid_level < 4)
89 return 1;
90
Zachary Amsdenf2ab4462005-09-03 15:56:42 -070091 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
92 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
Andi Kleen3dd9d512005-04-16 15:25:15 -070093 if (eax & 0x1f)
94 return ((eax >> 26) + 1);
95 else
96 return 1;
97}
98
Sam Ravnborgd72b1b42007-10-17 18:04:33 +020099#ifdef CONFIG_X86_F00F_BUG
100static void __cpuinit trap_init_f00f_bug(void)
101{
102 __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
103
104 /*
105 * Update the IDT descriptor and reload the IDT so that
106 * it uses the read-only mapped virtual address.
107 */
108 idt_descr.address = fix_to_virt(FIX_F00F_IDT);
109 load_idt(&idt_descr);
110}
111#endif
112
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800113static void __cpuinit init_intel(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 unsigned int l2 = 0;
116 char *p = NULL;
117
118#ifdef CONFIG_X86_F00F_BUG
119 /*
120 * All current models of Pentium and Pentium with MMX technology CPUs
121 * have the F0 0F bug, which lets nonprivileged users lock up the system.
122 * Note that the workaround only should be initialized once...
123 */
124 c->f00f_bug = 0;
Rusty Russell4f205fd2006-12-07 02:14:08 +0100125 if (!paravirt_enabled() && c->x86 == 5) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 static int f00f_workaround_enabled = 0;
127
128 c->f00f_bug = 1;
129 if ( !f00f_workaround_enabled ) {
130 trap_init_f00f_bug();
131 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
132 f00f_workaround_enabled = 1;
133 }
134 }
135#endif
136
137 select_idle_routine(c);
138 l2 = init_intel_cacheinfo(c);
Venkatesh Pallipadi0080e662006-06-26 13:59:59 +0200139 if (c->cpuid_level > 9 ) {
140 unsigned eax = cpuid_eax(10);
141 /* Check for version and the number of counters */
142 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
143 set_bit(X86_FEATURE_ARCH_PERFMON, c->x86_capability);
144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
147 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
148 clear_bit(X86_FEATURE_SEP, c->x86_capability);
149
150 /* Names for the Pentium II/Celeron processors
151 detectable only by also checking the cache size.
152 Dixon is NOT a Celeron. */
153 if (c->x86 == 6) {
154 switch (c->x86_model) {
155 case 5:
156 if (c->x86_mask == 0) {
157 if (l2 == 0)
158 p = "Celeron (Covington)";
159 else if (l2 == 256)
160 p = "Mobile Pentium II (Dixon)";
161 }
162 break;
163
164 case 6:
165 if (l2 == 128)
166 p = "Celeron (Mendocino)";
167 else if (c->x86_mask == 0 || c->x86_mask == 5)
168 p = "Celeron-A";
169 break;
170
171 case 8:
172 if (l2 == 128)
173 p = "Celeron (Coppermine)";
174 break;
175 }
176 }
177
178 if ( p )
179 strcpy(c->x86_model_id, p);
180
Siddha, Suresh B94605ef2005-11-05 17:25:54 +0100181 c->x86_max_cores = num_cpu_cores(c);
Andi Kleen3dd9d512005-04-16 15:25:15 -0700182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 detect_ht(c);
184
185 /* Work around errata */
186 Intel_errata_workarounds(c);
187
188#ifdef CONFIG_X86_INTEL_USERCOPY
189 /*
190 * Set up the preferred alignment for movsl bulk memory moves
191 */
192 switch (c->x86) {
193 case 4: /* 486: untested */
194 break;
195 case 5: /* Old Pentia: untested */
196 break;
197 case 6: /* PII/PIII only like movsl with 8-byte alignment */
198 movsl_mask.mask = 7;
199 break;
200 case 15: /* P4 is OK down to 8-byte alignment */
201 movsl_mask.mask = 7;
202 break;
203 }
204#endif
205
Andi Kleen707fa8e2008-01-30 13:32:37 +0100206 if (cpu_has_xmm)
207 set_bit(X86_FEATURE_LFENCE_RDTSC, c->x86_capability);
Andi Kleen3aefbe02007-05-02 19:27:20 +0200208 if (c->x86 == 15) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 set_bit(X86_FEATURE_P4, c->x86_capability);
Andi Kleen3aefbe02007-05-02 19:27:20 +0200210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (c->x86 == 6)
212 set_bit(X86_FEATURE_P3, c->x86_capability);
Andi Kleen39b3a792006-01-11 22:42:45 +0100213 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
214 (c->x86 == 0x6 && c->x86_model >= 0x0e))
215 set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
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)))
221 set_bit(X86_FEATURE_BTS, c->x86_capability);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100222 if (!(l1 & (1<<12)))
223 set_bit(X86_FEATURE_PEBS, c->x86_capability);
224 }
Markus Metzgereee3af42008-01-30 13:31:09 +0100225
226 if (cpu_has_bts)
227 ds_init_intel(c);
Stephane Eranian42ed4582006-12-07 02:14:01 +0100228}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Magnus Damme9dff0e2006-09-26 10:52:36 +0200230static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 * c, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 /* Intel PIII Tualatin. This comes in two flavours.
233 * One has 256kb of cache, the other 512. We have no way
234 * to determine which, so we use a boottime override
235 * for the 512kb model, and assume 256 otherwise.
236 */
237 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
238 size = 256;
239 return size;
240}
241
Chuck Ebbert3bc9b762006-03-23 02:59:33 -0800242static struct cpu_dev intel_cpu_dev __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 .c_vendor = "Intel",
244 .c_ident = { "GenuineIntel" },
245 .c_models = {
246 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
247 {
248 [0] = "486 DX-25/33",
249 [1] = "486 DX-50",
250 [2] = "486 SX",
251 [3] = "486 DX/2",
252 [4] = "486 SL",
253 [5] = "486 SX/2",
254 [7] = "486 DX/2-WB",
255 [8] = "486 DX/4",
256 [9] = "486 DX/4-WB"
257 }
258 },
259 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
260 {
261 [0] = "Pentium 60/66 A-step",
262 [1] = "Pentium 60/66",
263 [2] = "Pentium 75 - 200",
264 [3] = "OverDrive PODP5V83",
265 [4] = "Pentium MMX",
266 [7] = "Mobile Pentium 75 - 200",
267 [8] = "Mobile Pentium MMX"
268 }
269 },
270 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
271 {
272 [0] = "Pentium Pro A-step",
273 [1] = "Pentium Pro",
274 [3] = "Pentium II (Klamath)",
275 [4] = "Pentium II (Deschutes)",
276 [5] = "Pentium II (Deschutes)",
277 [6] = "Mobile Pentium II",
278 [7] = "Pentium III (Katmai)",
279 [8] = "Pentium III (Coppermine)",
280 [10] = "Pentium III (Cascades)",
281 [11] = "Pentium III (Tualatin)",
282 }
283 },
284 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
285 {
286 [0] = "Pentium 4 (Unknown)",
287 [1] = "Pentium 4 (Willamette)",
288 [2] = "Pentium 4 (Northwood)",
289 [4] = "Pentium 4 (Foster)",
290 [5] = "Pentium 4 (Foster)",
291 }
292 },
293 },
294 .c_init = init_intel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 .c_size_cache = intel_size_cache,
296};
297
298__init int intel_cpu_init(void)
299{
300 cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
301 return 0;
302}
303
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368// arch_initcall(intel_cpu_init);
369