ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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
10 #include <asm/processor.h>
11 #include <asm/msr.h>
12 #include <asm/uaccess.h>
13
14 #include "cpu.h"
15
16 #ifdef CONFIG_X86_LOCAL_APIC
17 #include <asm/mpspec.h>
18 #include <asm/apic.h>
19 #include <mach_apic.h>
20 #endif
21
22 extern int trap_init_f00f_bug(void);
23
24 #ifdef CONFIG_X86_INTEL_USERCOPY
25 /*
26  * Alignment at which movsl is preferred for bulk memory copies.
27  */
28 struct movsl_mask movsl_mask;
29 #endif
30
31 /*
32  *      Early probe support logic for ppro memory erratum #50
33  *
34  *      This is called before we do cpu ident work
35  */
36  
37 int __init ppro_with_ram_bug(void)
38 {
39         char vendor_id[16];
40         int ident;
41
42         /* Must have CPUID */
43         if(!have_cpuid_p())
44                 return 0;
45         if(cpuid_eax(0)<1)
46                 return 0;
47         
48         /* Must be Intel */
49         cpuid(0, &ident, 
50                 (int *)&vendor_id[0],
51                 (int *)&vendor_id[8],
52                 (int *)&vendor_id[4]);
53         
54         if(memcmp(vendor_id, "IntelInside", 12))
55                 return 0;
56         
57         ident = cpuid_eax(1);
58
59         /* Model 6 */
60
61         if(((ident>>8)&15)!=6)
62                 return 0;
63         
64         /* Pentium Pro */
65
66         if(((ident>>4)&15)!=1)
67                 return 0;
68         
69         if((ident&15) < 8)
70         {
71                 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
72                 return 1;
73         }
74         printk(KERN_INFO "Your Pentium Pro seems ok.\n");
75         return 0;
76 }
77         
78 #define LVL_1_INST      1
79 #define LVL_1_DATA      2
80 #define LVL_2           3
81 #define LVL_3           4
82 #define LVL_TRACE       5
83
84 struct _cache_table
85 {
86         unsigned char descriptor;
87         char cache_type;
88         short size;
89 };
90
91 /* all the cache descriptor types we care about (no TLB or trace cache entries) */
92 static struct _cache_table cache_table[] __initdata =
93 {
94         { 0x06, LVL_1_INST, 8 },
95         { 0x08, LVL_1_INST, 16 },
96         { 0x0a, LVL_1_DATA, 8 },
97         { 0x0c, LVL_1_DATA, 16 },
98         { 0x22, LVL_3,      512 },
99         { 0x23, LVL_3,      1024 },
100         { 0x25, LVL_3,      2048 },
101         { 0x29, LVL_3,      4096 },
102         { 0x2c, LVL_1_DATA, 32 },
103         { 0x30, LVL_1_INST, 32 },
104         { 0x39, LVL_2,      128 },
105         { 0x3b, LVL_2,      128 },
106         { 0x3c, LVL_2,      256 },
107         { 0x41, LVL_2,      128 },
108         { 0x42, LVL_2,      256 },
109         { 0x43, LVL_2,      512 },
110         { 0x44, LVL_2,      1024 },
111         { 0x45, LVL_2,      2048 },
112         { 0x66, LVL_1_DATA, 8 },
113         { 0x67, LVL_1_DATA, 16 },
114         { 0x68, LVL_1_DATA, 32 },
115         { 0x70, LVL_TRACE,  12 },
116         { 0x71, LVL_TRACE,  16 },
117         { 0x72, LVL_TRACE,  32 },
118         { 0x79, LVL_2,      128 },
119         { 0x7a, LVL_2,      256 },
120         { 0x7b, LVL_2,      512 },
121         { 0x7c, LVL_2,      1024 },
122         { 0x82, LVL_2,      256 },
123         { 0x83, LVL_2,      512 },
124         { 0x84, LVL_2,      1024 },
125         { 0x85, LVL_2,      2048 },
126         { 0x86, LVL_2,      512 },
127         { 0x87, LVL_2,      1024 },
128         { 0x00, 0, 0}
129 };
130
131 /*
132  * P4 Xeon errata 037 workaround.
133  * Hardware prefetcher may cause stale data to be loaded into the cache.
134  */
135 static void __init Intel_errata_workarounds(struct cpuinfo_x86 *c)
136 {
137         unsigned long lo, hi;
138
139         if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
140                 rdmsr (MSR_IA32_MISC_ENABLE, lo, hi);
141                 if ((lo & (1<<9)) == 0) {
142                         printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
143                         printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
144                         lo |= (1<<9);   /* Disable hw prefetching */
145                         wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
146                 }
147         }
148 }
149
150
151 static void __init init_intel(struct cpuinfo_x86 *c)
152 {
153         char *p = NULL;
154         unsigned int trace = 0, l1i = 0, l1d = 0, l2 = 0, l3 = 0; /* Cache sizes */
155
156 #ifdef CONFIG_X86_F00F_BUG
157         /*
158          * All current models of Pentium and Pentium with MMX technology CPUs
159          * have the F0 0F bug, which lets nonprivileged users lock up the system.
160          * Note that the workaround only should be initialized once...
161          */
162         c->f00f_bug = 0;
163         if ( c->x86 == 5 ) {
164                 static int f00f_workaround_enabled = 0;
165
166                 c->f00f_bug = 1;
167                 if ( !f00f_workaround_enabled ) {
168                         trap_init_f00f_bug();
169                         printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
170                         f00f_workaround_enabled = 1;
171                 }
172         }
173 #endif
174
175         select_idle_routine(c);
176         if (c->cpuid_level > 1) {
177                 /* supports eax=2  call */
178                 int i, j, n;
179                 int regs[4];
180                 unsigned char *dp = (unsigned char *)regs;
181
182                 /* Number of times to iterate */
183                 n = cpuid_eax(2) & 0xFF;
184
185                 for ( i = 0 ; i < n ; i++ ) {
186                         cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
187                         
188                         /* If bit 31 is set, this is an unknown format */
189                         for ( j = 0 ; j < 3 ; j++ ) {
190                                 if ( regs[j] < 0 ) regs[j] = 0;
191                         }
192
193                         /* Byte 0 is level count, not a descriptor */
194                         for ( j = 1 ; j < 16 ; j++ ) {
195                                 unsigned char des = dp[j];
196                                 unsigned char k = 0;
197
198                                 /* look up this descriptor in the table */
199                                 while (cache_table[k].descriptor != 0)
200                                 {
201                                         if (cache_table[k].descriptor == des) {
202                                                 switch (cache_table[k].cache_type) {
203                                                 case LVL_1_INST:
204                                                         l1i += cache_table[k].size;
205                                                         break;
206                                                 case LVL_1_DATA:
207                                                         l1d += cache_table[k].size;
208                                                         break;
209                                                 case LVL_2:
210                                                         l2 += cache_table[k].size;
211                                                         break;
212                                                 case LVL_3:
213                                                         l3 += cache_table[k].size;
214                                                         break;
215                                                 case LVL_TRACE:
216                                                         trace += cache_table[k].size;
217                                                         break;
218                                                 }
219
220                                                 break;
221                                         }
222
223                                         k++;
224                                 }
225                         }
226                 }
227
228                 if ( trace )
229                         printk (KERN_INFO "CPU: Trace cache: %dK uops", trace);
230                 else if ( l1i )
231                         printk (KERN_INFO "CPU: L1 I cache: %dK", l1i);
232                 if ( l1d )
233                         printk(", L1 D cache: %dK\n", l1d);
234                 else
235                         printk("\n");
236                 if ( l2 )
237                         printk(KERN_INFO "CPU: L2 cache: %dK\n", l2);
238                 if ( l3 )
239                         printk(KERN_INFO "CPU: L3 cache: %dK\n", l3);
240
241                 /*
242                  * This assumes the L3 cache is shared; it typically lives in
243                  * the northbridge.  The L1 caches are included by the L2
244                  * cache, and so should not be included for the purpose of
245                  * SMP switching weights.
246                  */
247                 c->x86_cache_size = l2 ? l2 : (l1i+l1d);
248         }
249
250         /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
251         if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
252                 clear_bit(X86_FEATURE_SEP, c->x86_capability);
253
254         /* Names for the Pentium II/Celeron processors 
255            detectable only by also checking the cache size.
256            Dixon is NOT a Celeron. */
257         if (c->x86 == 6) {
258                 switch (c->x86_model) {
259                 case 5:
260                         if (c->x86_mask == 0) {
261                                 if (l2 == 0)
262                                         p = "Celeron (Covington)";
263                                 else if (l2 == 256)
264                                         p = "Mobile Pentium II (Dixon)";
265                         }
266                         break;
267                         
268                 case 6:
269                         if (l2 == 128)
270                                 p = "Celeron (Mendocino)";
271                         else if (c->x86_mask == 0 || c->x86_mask == 5)
272                                 p = "Celeron-A";
273                         break;
274                         
275                 case 8:
276                         if (l2 == 128)
277                                 p = "Celeron (Coppermine)";
278                         break;
279                 }
280         }
281
282         if ( p )
283                 strcpy(c->x86_model_id, p);
284         
285 #ifdef CONFIG_X86_HT
286         if (cpu_has(c, X86_FEATURE_HT)) {
287                 extern  int phys_proc_id[NR_CPUS];
288                 
289                 u32     eax, ebx, ecx, edx;
290                 int     index_lsb, index_msb, tmp;
291                 int     cpu = smp_processor_id();
292
293                 cpuid(1, &eax, &ebx, &ecx, &edx);
294                 smp_num_siblings = (ebx & 0xff0000) >> 16;
295
296                 if (smp_num_siblings == 1) {
297                         printk(KERN_INFO  "CPU: Hyper-Threading is disabled\n");
298                 } else if (smp_num_siblings > 1 ) {
299                         index_lsb = 0;
300                         index_msb = 31;
301
302                         if (smp_num_siblings > NR_CPUS) {
303                                 printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
304                                 smp_num_siblings = 1;
305                                 goto too_many_siblings;
306                         }
307                         tmp = smp_num_siblings;
308                         while ((tmp & 1) == 0) {
309                                 tmp >>=1 ;
310                                 index_lsb++;
311                         }
312                         tmp = smp_num_siblings;
313                         while ((tmp & 0x80000000 ) == 0) {
314                                 tmp <<=1 ;
315                                 index_msb--;
316                         }
317                         if (index_lsb != index_msb )
318                                 index_msb++;
319                         phys_proc_id[cpu] = phys_pkg_id((ebx >> 24) & 0xFF, index_msb);
320
321                         printk(KERN_INFO  "CPU: Physical Processor ID: %d\n",
322                                phys_proc_id[cpu]);
323                 }
324
325         }
326 too_many_siblings:
327
328 #endif
329
330         /* Work around errata */
331         Intel_errata_workarounds(c);
332
333 #ifdef CONFIG_X86_INTEL_USERCOPY
334         /*
335          * Set up the preferred alignment for movsl bulk memory moves
336          */
337         switch (c->x86) {
338         case 4:         /* 486: untested */
339                 break;
340         case 5:         /* Old Pentia: untested */
341                 break;
342         case 6:         /* PII/PIII only like movsl with 8-byte alignment */
343                 movsl_mask.mask = 7;
344                 break;
345         case 15:        /* P4 is OK down to 8-byte alignment */
346                 movsl_mask.mask = 7;
347                 break;
348         }
349 #endif
350
351         if (c->x86 == 15) 
352                 set_bit(X86_FEATURE_P4, c->x86_capability);
353         if (c->x86 == 6) 
354                 set_bit(X86_FEATURE_P3, c->x86_capability);
355 }
356
357
358 static unsigned int intel_size_cache(struct cpuinfo_x86 * c, unsigned int size)
359 {
360         /* Intel PIII Tualatin. This comes in two flavours.
361          * One has 256kb of cache, the other 512. We have no way
362          * to determine which, so we use a boottime override
363          * for the 512kb model, and assume 256 otherwise.
364          */
365         if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
366                 size = 256;
367         return size;
368 }
369
370 static struct cpu_dev intel_cpu_dev __initdata = {
371         .c_vendor       = "Intel",
372         .c_ident        = { "GenuineIntel" },
373         .c_models = {
374                 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names = 
375                   { 
376                           [0] = "486 DX-25/33", 
377                           [1] = "486 DX-50", 
378                           [2] = "486 SX", 
379                           [3] = "486 DX/2", 
380                           [4] = "486 SL", 
381                           [5] = "486 SX/2", 
382                           [7] = "486 DX/2-WB", 
383                           [8] = "486 DX/4", 
384                           [9] = "486 DX/4-WB"
385                   }
386                 },
387                 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
388                   { 
389                           [0] = "Pentium 60/66 A-step", 
390                           [1] = "Pentium 60/66", 
391                           [2] = "Pentium 75 - 200",
392                           [3] = "OverDrive PODP5V83", 
393                           [4] = "Pentium MMX",
394                           [7] = "Mobile Pentium 75 - 200", 
395                           [8] = "Mobile Pentium MMX"
396                   }
397                 },
398                 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
399                   { 
400                           [0] = "Pentium Pro A-step",
401                           [1] = "Pentium Pro", 
402                           [3] = "Pentium II (Klamath)", 
403                           [4] = "Pentium II (Deschutes)", 
404                           [5] = "Pentium II (Deschutes)", 
405                           [6] = "Mobile Pentium II",
406                           [7] = "Pentium III (Katmai)", 
407                           [8] = "Pentium III (Coppermine)", 
408                           [10] = "Pentium III (Cascades)",
409                           [11] = "Pentium III (Tualatin)",
410                   }
411                 },
412                 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
413                   {
414                           [0] = "Pentium 4 (Unknown)",
415                           [1] = "Pentium 4 (Willamette)",
416                           [2] = "Pentium 4 (Northwood)",
417                           [4] = "Pentium 4 (Foster)",
418                           [5] = "Pentium 4 (Foster)",
419                   }
420                 },
421         },
422         .c_init         = init_intel,
423         .c_identify     = generic_identify,
424         .c_size_cache   = intel_size_cache,
425 };
426
427 __init int intel_cpu_init(void)
428 {
429         cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
430         return 0;
431 }
432
433 // arch_initcall(intel_cpu_init);
434