Merge master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[pandora-kernel.git] / arch / i386 / kernel / cpu / intel.c
1 #include <linux/config.h>
2 #include <linux/init.h>
3 #include <linux/kernel.h>
4
5 #include <linux/string.h>
6 #include <linux/bitops.h>
7 #include <linux/smp.h>
8 #include <linux/thread_info.h>
9 #include <linux/module.h>
10
11 #include <asm/processor.h>
12 #include <asm/msr.h>
13 #include <asm/uaccess.h>
14
15 #include "cpu.h"
16
17 #ifdef CONFIG_X86_LOCAL_APIC
18 #include <asm/mpspec.h>
19 #include <asm/apic.h>
20 #include <mach_apic.h>
21 #endif
22
23 extern int trap_init_f00f_bug(void);
24
25 #ifdef CONFIG_X86_INTEL_USERCOPY
26 /*
27  * Alignment at which movsl is preferred for bulk memory copies.
28  */
29 struct movsl_mask movsl_mask __read_mostly;
30 #endif
31
32 void __cpuinit early_intel_workaround(struct cpuinfo_x86 *c)
33 {
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  
47 int __cpuinit ppro_with_ram_bug(void)
48 {
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  */
65 static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
66 {
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
81 /*
82  * find out the number of processor cores on the die
83  */
84 static int __cpuinit num_cpu_cores(struct cpuinfo_x86 *c)
85 {
86         unsigned int eax, ebx, ecx, edx;
87
88         if (c->cpuid_level < 4)
89                 return 1;
90
91         /* Intel has a non-standard dependency on %ecx for this CPUID level. */
92         cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
93         if (eax & 0x1f)
94                 return ((eax >> 26) + 1);
95         else
96                 return 1;
97 }
98
99 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
100 {
101         unsigned int l2 = 0;
102         char *p = NULL;
103
104 #ifdef CONFIG_X86_F00F_BUG
105         /*
106          * All current models of Pentium and Pentium with MMX technology CPUs
107          * have the F0 0F bug, which lets nonprivileged users lock up the system.
108          * Note that the workaround only should be initialized once...
109          */
110         c->f00f_bug = 0;
111         if ( c->x86 == 5 ) {
112                 static int f00f_workaround_enabled = 0;
113
114                 c->f00f_bug = 1;
115                 if ( !f00f_workaround_enabled ) {
116                         trap_init_f00f_bug();
117                         printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
118                         f00f_workaround_enabled = 1;
119                 }
120         }
121 #endif
122
123         select_idle_routine(c);
124         l2 = init_intel_cacheinfo(c);
125         if (c->cpuid_level > 9 ) {
126                 unsigned eax = cpuid_eax(10);
127                 /* Check for version and the number of counters */
128                 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
129                         set_bit(X86_FEATURE_ARCH_PERFMON, c->x86_capability);
130         }
131
132         /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
133         if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
134                 clear_bit(X86_FEATURE_SEP, c->x86_capability);
135
136         /* Names for the Pentium II/Celeron processors 
137            detectable only by also checking the cache size.
138            Dixon is NOT a Celeron. */
139         if (c->x86 == 6) {
140                 switch (c->x86_model) {
141                 case 5:
142                         if (c->x86_mask == 0) {
143                                 if (l2 == 0)
144                                         p = "Celeron (Covington)";
145                                 else if (l2 == 256)
146                                         p = "Mobile Pentium II (Dixon)";
147                         }
148                         break;
149                         
150                 case 6:
151                         if (l2 == 128)
152                                 p = "Celeron (Mendocino)";
153                         else if (c->x86_mask == 0 || c->x86_mask == 5)
154                                 p = "Celeron-A";
155                         break;
156                         
157                 case 8:
158                         if (l2 == 128)
159                                 p = "Celeron (Coppermine)";
160                         break;
161                 }
162         }
163
164         if ( p )
165                 strcpy(c->x86_model_id, p);
166         
167         c->x86_max_cores = num_cpu_cores(c);
168
169         detect_ht(c);
170
171         /* Work around errata */
172         Intel_errata_workarounds(c);
173
174 #ifdef CONFIG_X86_INTEL_USERCOPY
175         /*
176          * Set up the preferred alignment for movsl bulk memory moves
177          */
178         switch (c->x86) {
179         case 4:         /* 486: untested */
180                 break;
181         case 5:         /* Old Pentia: untested */
182                 break;
183         case 6:         /* PII/PIII only like movsl with 8-byte alignment */
184                 movsl_mask.mask = 7;
185                 break;
186         case 15:        /* P4 is OK down to 8-byte alignment */
187                 movsl_mask.mask = 7;
188                 break;
189         }
190 #endif
191
192         if (c->x86 == 15)
193                 set_bit(X86_FEATURE_P4, c->x86_capability);
194         if (c->x86 == 6) 
195                 set_bit(X86_FEATURE_P3, c->x86_capability);
196         if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
197                 (c->x86 == 0x6 && c->x86_model >= 0x0e))
198                 set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
199 }
200
201
202 static unsigned int intel_size_cache(struct cpuinfo_x86 * c, unsigned int size)
203 {
204         /* Intel PIII Tualatin. This comes in two flavours.
205          * One has 256kb of cache, the other 512. We have no way
206          * to determine which, so we use a boottime override
207          * for the 512kb model, and assume 256 otherwise.
208          */
209         if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
210                 size = 256;
211         return size;
212 }
213
214 static struct cpu_dev intel_cpu_dev __cpuinitdata = {
215         .c_vendor       = "Intel",
216         .c_ident        = { "GenuineIntel" },
217         .c_models = {
218                 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names = 
219                   { 
220                           [0] = "486 DX-25/33", 
221                           [1] = "486 DX-50", 
222                           [2] = "486 SX", 
223                           [3] = "486 DX/2", 
224                           [4] = "486 SL", 
225                           [5] = "486 SX/2", 
226                           [7] = "486 DX/2-WB", 
227                           [8] = "486 DX/4", 
228                           [9] = "486 DX/4-WB"
229                   }
230                 },
231                 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
232                   { 
233                           [0] = "Pentium 60/66 A-step", 
234                           [1] = "Pentium 60/66", 
235                           [2] = "Pentium 75 - 200",
236                           [3] = "OverDrive PODP5V83", 
237                           [4] = "Pentium MMX",
238                           [7] = "Mobile Pentium 75 - 200", 
239                           [8] = "Mobile Pentium MMX"
240                   }
241                 },
242                 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
243                   { 
244                           [0] = "Pentium Pro A-step",
245                           [1] = "Pentium Pro", 
246                           [3] = "Pentium II (Klamath)", 
247                           [4] = "Pentium II (Deschutes)", 
248                           [5] = "Pentium II (Deschutes)", 
249                           [6] = "Mobile Pentium II",
250                           [7] = "Pentium III (Katmai)", 
251                           [8] = "Pentium III (Coppermine)", 
252                           [10] = "Pentium III (Cascades)",
253                           [11] = "Pentium III (Tualatin)",
254                   }
255                 },
256                 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
257                   {
258                           [0] = "Pentium 4 (Unknown)",
259                           [1] = "Pentium 4 (Willamette)",
260                           [2] = "Pentium 4 (Northwood)",
261                           [4] = "Pentium 4 (Foster)",
262                           [5] = "Pentium 4 (Foster)",
263                   }
264                 },
265         },
266         .c_init         = init_intel,
267         .c_identify     = generic_identify,
268         .c_size_cache   = intel_size_cache,
269 };
270
271 __init int intel_cpu_init(void)
272 {
273         cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
274         return 0;
275 }
276
277 #ifndef CONFIG_X86_CMPXCHG
278 unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new)
279 {
280         u8 prev;
281         unsigned long flags;
282
283         /* Poor man's cmpxchg for 386. Unsuitable for SMP */
284         local_irq_save(flags);
285         prev = *(u8 *)ptr;
286         if (prev == old)
287                 *(u8 *)ptr = new;
288         local_irq_restore(flags);
289         return prev;
290 }
291 EXPORT_SYMBOL(cmpxchg_386_u8);
292
293 unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new)
294 {
295         u16 prev;
296         unsigned long flags;
297
298         /* Poor man's cmpxchg for 386. Unsuitable for SMP */
299         local_irq_save(flags);
300         prev = *(u16 *)ptr;
301         if (prev == old)
302                 *(u16 *)ptr = new;
303         local_irq_restore(flags);
304         return prev;
305 }
306 EXPORT_SYMBOL(cmpxchg_386_u16);
307
308 unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new)
309 {
310         u32 prev;
311         unsigned long flags;
312
313         /* Poor man's cmpxchg for 386. Unsuitable for SMP */
314         local_irq_save(flags);
315         prev = *(u32 *)ptr;
316         if (prev == old)
317                 *(u32 *)ptr = new;
318         local_irq_restore(flags);
319         return prev;
320 }
321 EXPORT_SYMBOL(cmpxchg_386_u32);
322 #endif
323
324 // arch_initcall(intel_cpu_init);
325