]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/kernel/cpu/intel.c
Merge branch 'x86/pebs' into x86/unify-cpu-detect
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / cpu / intel.c
1 #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>
8 #include <linux/module.h>
9
10 #include <asm/processor.h>
11 #include <asm/pgtable.h>
12 #include <asm/msr.h>
13 #include <asm/uaccess.h>
14 #include <asm/ptrace.h>
15 #include <asm/ds.h>
16 #include <asm/bugs.h>
17
18 #include "cpu.h"
19
20 #ifdef CONFIG_X86_LOCAL_APIC
21 #include <asm/mpspec.h>
22 #include <asm/apic.h>
23 #include <mach_apic.h>
24 #endif
25
26 static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
27 {
28         /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
29         if (c->x86 == 15 && c->x86_cache_alignment == 64)
30                 c->x86_cache_alignment = 128;
31         if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
32                 (c->x86 == 0x6 && c->x86_model >= 0x0e))
33                 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
34 }
35
36 /*
37  *      Early probe support logic for ppro memory erratum #50
38  *
39  *      This is called before we do cpu ident work
40  */
41
42 int __cpuinit ppro_with_ram_bug(void)
43 {
44         /* Uses data from early_cpu_detect now */
45         if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
46             boot_cpu_data.x86 == 6 &&
47             boot_cpu_data.x86_model == 1 &&
48             boot_cpu_data.x86_mask < 8) {
49                 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
50                 return 1;
51         }
52         return 0;
53 }
54
55
56 /*
57  * P4 Xeon errata 037 workaround.
58  * Hardware prefetcher may cause stale data to be loaded into the cache.
59  */
60 static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
61 {
62         unsigned long lo, hi;
63
64         if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
65                 rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
66                 if ((lo & (1<<9)) == 0) {
67                         printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
68                         printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
69                         lo |= (1<<9);   /* Disable hw prefetching */
70                         wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
71                 }
72         }
73 }
74
75
76 /*
77  * find out the number of processor cores on the die
78  */
79 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
80 {
81         unsigned int eax, ebx, ecx, edx;
82
83         if (c->cpuid_level < 4)
84                 return 1;
85
86         /* Intel has a non-standard dependency on %ecx for this CPUID level. */
87         cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
88         if (eax & 0x1f)
89                 return ((eax >> 26) + 1);
90         else
91                 return 1;
92 }
93
94 #ifdef CONFIG_X86_F00F_BUG
95 static void __cpuinit trap_init_f00f_bug(void)
96 {
97         __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
98
99         /*
100          * Update the IDT descriptor and reload the IDT so that
101          * it uses the read-only mapped virtual address.
102          */
103         idt_descr.address = fix_to_virt(FIX_F00F_IDT);
104         load_idt(&idt_descr);
105 }
106 #endif
107
108 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
109 {
110         unsigned int l2 = 0;
111         char *p = NULL;
112
113         early_init_intel(c);
114
115 #ifdef CONFIG_X86_F00F_BUG
116         /*
117          * All current models of Pentium and Pentium with MMX technology CPUs
118          * have the F0 0F bug, which lets nonprivileged users lock up the system.
119          * Note that the workaround only should be initialized once...
120          */
121         c->f00f_bug = 0;
122         if (!paravirt_enabled() && c->x86 == 5) {
123                 static int f00f_workaround_enabled;
124
125                 c->f00f_bug = 1;
126                 if (!f00f_workaround_enabled) {
127                         trap_init_f00f_bug();
128                         printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
129                         f00f_workaround_enabled = 1;
130                 }
131         }
132 #endif
133
134         l2 = init_intel_cacheinfo(c);
135         if (c->cpuid_level > 9) {
136                 unsigned eax = cpuid_eax(10);
137                 /* Check for version and the number of counters */
138                 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
139                         set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
140         }
141
142         /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
143         if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
144                 clear_cpu_cap(c, X86_FEATURE_SEP);
145
146         /*
147          * Names for the Pentium II/Celeron processors
148          * detectable only by also checking the cache size.
149          * Dixon is NOT a Celeron.
150          */
151         if (c->x86 == 6) {
152                 switch (c->x86_model) {
153                 case 5:
154                         if (c->x86_mask == 0) {
155                                 if (l2 == 0)
156                                         p = "Celeron (Covington)";
157                                 else if (l2 == 256)
158                                         p = "Mobile Pentium II (Dixon)";
159                         }
160                         break;
161
162                 case 6:
163                         if (l2 == 128)
164                                 p = "Celeron (Mendocino)";
165                         else if (c->x86_mask == 0 || c->x86_mask == 5)
166                                 p = "Celeron-A";
167                         break;
168
169                 case 8:
170                         if (l2 == 128)
171                                 p = "Celeron (Coppermine)";
172                         break;
173                 }
174         }
175
176         if (p)
177                 strcpy(c->x86_model_id, p);
178
179         detect_extended_topology(c);
180
181         if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
182                 /*
183                  * let's use the legacy cpuid vector 0x1 and 0x4 for topology
184                  * detection.
185                  */
186                 c->x86_max_cores = intel_num_cpu_cores(c);
187                 detect_ht(c);
188         }
189
190         /* Work around errata */
191         Intel_errata_workarounds(c);
192
193 #ifdef CONFIG_X86_INTEL_USERCOPY
194         /*
195          * Set up the preferred alignment for movsl bulk memory moves
196          */
197         switch (c->x86) {
198         case 4:         /* 486: untested */
199                 break;
200         case 5:         /* Old Pentia: untested */
201                 break;
202         case 6:         /* PII/PIII only like movsl with 8-byte alignment */
203                 movsl_mask.mask = 7;
204                 break;
205         case 15:        /* P4 is OK down to 8-byte alignment */
206                 movsl_mask.mask = 7;
207                 break;
208         }
209 #endif
210
211         if (cpu_has_xmm2)
212                 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
213         if (c->x86 == 15)
214                 set_cpu_cap(c, X86_FEATURE_P4);
215         if (c->x86 == 6)
216                 set_cpu_cap(c, X86_FEATURE_P3);
217         if (cpu_has_ds) {
218                 unsigned int l1;
219                 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
220                 if (!(l1 & (1<<11)))
221                         set_cpu_cap(c, X86_FEATURE_BTS);
222                 if (!(l1 & (1<<12)))
223                         set_cpu_cap(c, X86_FEATURE_PEBS);
224                 ds_init_intel(c);
225         }
226
227         if (cpu_has_bts)
228                 ptrace_bts_init_intel(c);
229
230         /*
231          * See if we have a good local APIC by checking for buggy Pentia,
232          * i.e. all B steppings and the C2 stepping of P54C when using their
233          * integrated APIC (see 11AP erratum in "Pentium Processor
234          * Specification Update").
235          */
236         if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
237             (c->x86_mask < 0x6 || c->x86_mask == 0xb))
238                 set_cpu_cap(c, X86_FEATURE_11AP);
239
240 #ifdef CONFIG_X86_NUMAQ
241         numaq_tsc_disable();
242 #endif
243 }
244
245 static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
246 {
247         /*
248          * Intel PIII Tualatin. This comes in two flavours.
249          * One has 256kb of cache, the other 512. We have no way
250          * to determine which, so we use a boottime override
251          * for the 512kb model, and assume 256 otherwise.
252          */
253         if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
254                 size = 256;
255         return size;
256 }
257
258 static struct cpu_dev intel_cpu_dev __cpuinitdata = {
259         .c_vendor       = "Intel",
260         .c_ident        = { "GenuineIntel" },
261         .c_models = {
262                 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
263                   {
264                           [0] = "486 DX-25/33",
265                           [1] = "486 DX-50",
266                           [2] = "486 SX",
267                           [3] = "486 DX/2",
268                           [4] = "486 SL",
269                           [5] = "486 SX/2",
270                           [7] = "486 DX/2-WB",
271                           [8] = "486 DX/4",
272                           [9] = "486 DX/4-WB"
273                   }
274                 },
275                 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
276                   {
277                           [0] = "Pentium 60/66 A-step",
278                           [1] = "Pentium 60/66",
279                           [2] = "Pentium 75 - 200",
280                           [3] = "OverDrive PODP5V83",
281                           [4] = "Pentium MMX",
282                           [7] = "Mobile Pentium 75 - 200",
283                           [8] = "Mobile Pentium MMX"
284                   }
285                 },
286                 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
287                   {
288                           [0] = "Pentium Pro A-step",
289                           [1] = "Pentium Pro",
290                           [3] = "Pentium II (Klamath)",
291                           [4] = "Pentium II (Deschutes)",
292                           [5] = "Pentium II (Deschutes)",
293                           [6] = "Mobile Pentium II",
294                           [7] = "Pentium III (Katmai)",
295                           [8] = "Pentium III (Coppermine)",
296                           [10] = "Pentium III (Cascades)",
297                           [11] = "Pentium III (Tualatin)",
298                   }
299                 },
300                 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
301                   {
302                           [0] = "Pentium 4 (Unknown)",
303                           [1] = "Pentium 4 (Willamette)",
304                           [2] = "Pentium 4 (Northwood)",
305                           [4] = "Pentium 4 (Foster)",
306                           [5] = "Pentium 4 (Foster)",
307                   }
308                 },
309         },
310         .c_early_init   = early_init_intel,
311         .c_init         = init_intel,
312         .c_size_cache   = intel_size_cache,
313         .c_x86_vendor   = X86_VENDOR_INTEL,
314 };
315
316 cpu_dev_register(intel_cpu_dev);
317
318 /* arch_initcall(intel_cpu_init); */
319