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