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