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>
12 #include <asm/uaccess.h>
16 #ifdef CONFIG_X86_LOCAL_APIC
17 #include <asm/mpspec.h>
19 #include <mach_apic.h>
22 extern int trap_init_f00f_bug(void);
24 #ifdef CONFIG_X86_INTEL_USERCOPY
26 * Alignment at which movsl is preferred for bulk memory copies.
28 struct movsl_mask movsl_mask __read_mostly;
31 void __cpuinit early_intel_workaround(struct cpuinfo_x86 *c)
33 if (c->x86_vendor != X86_VENDOR_INTEL)
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;
41 * Early probe support logic for ppro memory erratum #50
43 * This is called before we do cpu ident work
46 int __cpuinit ppro_with_ram_bug(void)
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");
61 * P4 Xeon errata 037 workaround.
62 * Hardware prefetcher may cause stale data to be loaded into the cache.
64 static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
68 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
69 rdmsr (MSR_IA32_MISC_ENABLE, lo, hi);
70 if ((lo & (1<<9)) == 0) {
71 printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
72 printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
73 lo |= (1<<9); /* Disable hw prefetching */
74 wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
81 * find out the number of processor cores on the die
83 static int __cpuinit num_cpu_cores(struct cpuinfo_x86 *c)
85 unsigned int eax, ebx, ecx, edx;
87 if (c->cpuid_level < 4)
90 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
91 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
93 return ((eax >> 26) + 1);
98 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
103 #ifdef CONFIG_X86_F00F_BUG
105 * All current models of Pentium and Pentium with MMX technology CPUs
106 * have the F0 0F bug, which lets nonprivileged users lock up the system.
107 * Note that the workaround only should be initialized once...
110 if (!paravirt_enabled() && c->x86 == 5) {
111 static int f00f_workaround_enabled = 0;
114 if ( !f00f_workaround_enabled ) {
115 trap_init_f00f_bug();
116 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
117 f00f_workaround_enabled = 1;
122 select_idle_routine(c);
123 l2 = init_intel_cacheinfo(c);
124 if (c->cpuid_level > 9 ) {
125 unsigned eax = cpuid_eax(10);
126 /* Check for version and the number of counters */
127 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
128 set_bit(X86_FEATURE_ARCH_PERFMON, c->x86_capability);
131 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
132 if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
133 clear_bit(X86_FEATURE_SEP, c->x86_capability);
135 /* Names for the Pentium II/Celeron processors
136 detectable only by also checking the cache size.
137 Dixon is NOT a Celeron. */
139 switch (c->x86_model) {
141 if (c->x86_mask == 0) {
143 p = "Celeron (Covington)";
145 p = "Mobile Pentium II (Dixon)";
151 p = "Celeron (Mendocino)";
152 else if (c->x86_mask == 0 || c->x86_mask == 5)
158 p = "Celeron (Coppermine)";
164 strcpy(c->x86_model_id, p);
166 c->x86_max_cores = num_cpu_cores(c);
170 /* Work around errata */
171 Intel_errata_workarounds(c);
173 #ifdef CONFIG_X86_INTEL_USERCOPY
175 * Set up the preferred alignment for movsl bulk memory moves
178 case 4: /* 486: untested */
180 case 5: /* Old Pentia: untested */
182 case 6: /* PII/PIII only like movsl with 8-byte alignment */
185 case 15: /* P4 is OK down to 8-byte alignment */
192 set_bit(X86_FEATURE_P4, c->x86_capability);
193 set_bit(X86_FEATURE_SYNC_RDTSC, c->x86_capability);
196 set_bit(X86_FEATURE_P3, c->x86_capability);
197 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
198 (c->x86 == 0x6 && c->x86_model >= 0x0e))
199 set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
203 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
205 set_bit(X86_FEATURE_BTS, c->x86_capability);
207 set_bit(X86_FEATURE_PEBS, c->x86_capability);
211 static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 * c, unsigned int size)
213 /* Intel PIII Tualatin. This comes in two flavours.
214 * One has 256kb of cache, the other 512. We have no way
215 * to determine which, so we use a boottime override
216 * for the 512kb model, and assume 256 otherwise.
218 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
223 static struct cpu_dev intel_cpu_dev __cpuinitdata = {
225 .c_ident = { "GenuineIntel" },
227 { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
229 [0] = "486 DX-25/33",
240 { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
242 [0] = "Pentium 60/66 A-step",
243 [1] = "Pentium 60/66",
244 [2] = "Pentium 75 - 200",
245 [3] = "OverDrive PODP5V83",
247 [7] = "Mobile Pentium 75 - 200",
248 [8] = "Mobile Pentium MMX"
251 { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
253 [0] = "Pentium Pro A-step",
255 [3] = "Pentium II (Klamath)",
256 [4] = "Pentium II (Deschutes)",
257 [5] = "Pentium II (Deschutes)",
258 [6] = "Mobile Pentium II",
259 [7] = "Pentium III (Katmai)",
260 [8] = "Pentium III (Coppermine)",
261 [10] = "Pentium III (Cascades)",
262 [11] = "Pentium III (Tualatin)",
265 { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
267 [0] = "Pentium 4 (Unknown)",
268 [1] = "Pentium 4 (Willamette)",
269 [2] = "Pentium 4 (Northwood)",
270 [4] = "Pentium 4 (Foster)",
271 [5] = "Pentium 4 (Foster)",
275 .c_init = init_intel,
276 .c_size_cache = intel_size_cache,
279 __init int intel_cpu_init(void)
281 cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
285 #ifndef CONFIG_X86_CMPXCHG
286 unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new)
291 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
292 local_irq_save(flags);
296 local_irq_restore(flags);
299 EXPORT_SYMBOL(cmpxchg_386_u8);
301 unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new)
306 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
307 local_irq_save(flags);
311 local_irq_restore(flags);
314 EXPORT_SYMBOL(cmpxchg_386_u16);
316 unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new)
321 /* Poor man's cmpxchg for 386. Unsuitable for SMP */
322 local_irq_save(flags);
326 local_irq_restore(flags);
329 EXPORT_SYMBOL(cmpxchg_386_u32);
332 // arch_initcall(intel_cpu_init);