1 #include <linux/init.h>
2 #include <linux/kernel.h>
4 #include <linux/string.h>
5 #include <linux/bitops.h>
7 #include <linux/thread_info.h>
8 #include <linux/module.h>
10 #include <asm/processor.h>
11 #include <asm/pgtable.h>
13 #include <asm/uaccess.h>
14 #include <asm/ptrace.h>
20 #ifdef CONFIG_X86_LOCAL_APIC
21 #include <asm/mpspec.h>
23 #include <mach_apic.h>
26 #ifdef CONFIG_X86_INTEL_USERCOPY
28 * Alignment at which movsl is preferred for bulk memory copies.
30 struct movsl_mask movsl_mask __read_mostly;
33 static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
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 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
39 (c->x86 == 0x6 && c->x86_model >= 0x0e))
40 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
44 * Early probe support logic for ppro memory erratum #50
46 * This is called before we do cpu ident work
49 int __cpuinit ppro_with_ram_bug(void)
51 /* Uses data from early_cpu_detect now */
52 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
53 boot_cpu_data.x86 == 6 &&
54 boot_cpu_data.x86_model == 1 &&
55 boot_cpu_data.x86_mask < 8) {
56 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
64 * P4 Xeon errata 037 workaround.
65 * Hardware prefetcher may cause stale data to be loaded into the cache.
67 static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
71 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
72 rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
73 if ((lo & (1<<9)) == 0) {
74 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
75 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
76 lo |= (1<<9); /* Disable hw prefetching */
77 wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
84 * find out the number of processor cores on the die
86 static int __cpuinit num_cpu_cores(struct cpuinfo_x86 *c)
88 unsigned int eax, ebx, ecx, edx;
90 if (c->cpuid_level < 4)
93 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
94 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
96 return ((eax >> 26) + 1);
101 #ifdef CONFIG_X86_F00F_BUG
102 static void __cpuinit trap_init_f00f_bug(void)
104 __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
107 * Update the IDT descriptor and reload the IDT so that
108 * it uses the read-only mapped virtual address.
110 idt_descr.address = fix_to_virt(FIX_F00F_IDT);
111 load_idt(&idt_descr);
115 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
122 #ifdef CONFIG_X86_F00F_BUG
124 * All current models of Pentium and Pentium with MMX technology CPUs
125 * have the F0 0F bug, which lets nonprivileged users lock up the system.
126 * Note that the workaround only should be initialized once...
129 if (!paravirt_enabled() && c->x86 == 5) {
130 static int f00f_workaround_enabled;
133 if (!f00f_workaround_enabled) {
134 trap_init_f00f_bug();
135 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
136 f00f_workaround_enabled = 1;
141 l2 = init_intel_cacheinfo(c);
142 if (c->cpuid_level > 9) {
143 unsigned eax = cpuid_eax(10);
144 /* Check for version and the number of counters */
145 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
146 set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
149 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
150 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
151 clear_cpu_cap(c, X86_FEATURE_SEP);
154 * Names for the Pentium II/Celeron processors
155 * detectable only by also checking the cache size.
156 * Dixon is NOT a Celeron.
159 switch (c->x86_model) {
161 if (c->x86_mask == 0) {
163 p = "Celeron (Covington)";
165 p = "Mobile Pentium II (Dixon)";
171 p = "Celeron (Mendocino)";
172 else if (c->x86_mask == 0 || c->x86_mask == 5)
178 p = "Celeron (Coppermine)";
184 strcpy(c->x86_model_id, p);
186 c->x86_max_cores = num_cpu_cores(c);
190 /* Work around errata */
191 Intel_errata_workarounds(c);
193 #ifdef CONFIG_X86_INTEL_USERCOPY
195 * Set up the preferred alignment for movsl bulk memory moves
198 case 4: /* 486: untested */
200 case 5: /* Old Pentia: untested */
202 case 6: /* PII/PIII only like movsl with 8-byte alignment */
205 case 15: /* P4 is OK down to 8-byte alignment */
212 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
214 set_cpu_cap(c, X86_FEATURE_P4);
217 set_cpu_cap(c, X86_FEATURE_P3);
220 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
222 set_cpu_cap(c, X86_FEATURE_BTS);
224 set_cpu_cap(c, X86_FEATURE_PEBS);
230 #ifdef CONFIG_X86_NUMAQ
235 static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
238 * Intel PIII Tualatin. This comes in two flavours.
239 * One has 256kb of cache, the other 512. We have no way
240 * to determine which, so we use a boottime override
241 * for the 512kb model, and assume 256 otherwise.
243 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
248 static struct cpu_dev intel_cpu_dev __cpuinitdata = {
250 .c_ident = { "GenuineIntel" },
252 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
254 [0] = "486 DX-25/33",
265 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
267 [0] = "Pentium 60/66 A-step",
268 [1] = "Pentium 60/66",
269 [2] = "Pentium 75 - 200",
270 [3] = "OverDrive PODP5V83",
272 [7] = "Mobile Pentium 75 - 200",
273 [8] = "Mobile Pentium MMX"
276 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
278 [0] = "Pentium Pro A-step",
280 [3] = "Pentium II (Klamath)",
281 [4] = "Pentium II (Deschutes)",
282 [5] = "Pentium II (Deschutes)",
283 [6] = "Mobile Pentium II",
284 [7] = "Pentium III (Katmai)",
285 [8] = "Pentium III (Coppermine)",
286 [10] = "Pentium III (Cascades)",
287 [11] = "Pentium III (Tualatin)",
290 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
292 [0] = "Pentium 4 (Unknown)",
293 [1] = "Pentium 4 (Willamette)",
294 [2] = "Pentium 4 (Northwood)",
295 [4] = "Pentium 4 (Foster)",
296 [5] = "Pentium 4 (Foster)",
300 .c_early_init = early_init_intel,
301 .c_init = init_intel,
302 .c_size_cache = intel_size_cache,
305 cpu_vendor_dev_register(X86_VENDOR_INTEL, &intel_cpu_dev);
307 #ifndef CONFIG_X86_CMPXCHG
308 unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new)
313 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
314 local_irq_save(flags);
318 local_irq_restore(flags);
321 EXPORT_SYMBOL(cmpxchg_386_u8);
323 unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new)
328 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
329 local_irq_save(flags);
333 local_irq_restore(flags);
336 EXPORT_SYMBOL(cmpxchg_386_u16);
338 unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new)
343 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
344 local_irq_save(flags);
348 local_irq_restore(flags);
351 EXPORT_SYMBOL(cmpxchg_386_u32);
354 #ifndef CONFIG_X86_CMPXCHG64
355 unsigned long long cmpxchg_486_u64(volatile void *ptr, u64 old, u64 new)
360 /* Poor man's cmpxchg8b for 386 and 486. Unsuitable for SMP */
361 local_irq_save(flags);
365 local_irq_restore(flags);
368 EXPORT_SYMBOL(cmpxchg_486_u64);
371 /* arch_initcall(intel_cpu_init); */