Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/kernel.h> |
2 | ||
3 | #include <linux/string.h> | |
4 | #include <linux/bitops.h> | |
5 | #include <linux/smp.h> | |
83ce4009 | 6 | #include <linux/sched.h> |
1da177e4 | 7 | #include <linux/thread_info.h> |
53e86b91 | 8 | #include <linux/module.h> |
8bdbd962 | 9 | #include <linux/uaccess.h> |
1da177e4 | 10 | |
cd4d09ec | 11 | #include <asm/cpufeature.h> |
d72b1b4f | 12 | #include <asm/pgtable.h> |
1da177e4 | 13 | #include <asm/msr.h> |
73bdb73f | 14 | #include <asm/bugs.h> |
1f442d70 | 15 | #include <asm/cpu.h> |
08e237fa | 16 | #include <asm/intel-family.h> |
1da177e4 | 17 | |
185f3b9d | 18 | #ifdef CONFIG_X86_64 |
8bdbd962 | 19 | #include <linux/topology.h> |
185f3b9d YL |
20 | #endif |
21 | ||
1da177e4 LT |
22 | #include "cpu.h" |
23 | ||
24 | #ifdef CONFIG_X86_LOCAL_APIC | |
25 | #include <asm/mpspec.h> | |
26 | #include <asm/apic.h> | |
1da177e4 LT |
27 | #endif |
28 | ||
0f6ff2bc DH |
29 | /* |
30 | * Just in case our CPU detection goes bad, or you have a weird system, | |
31 | * allow a way to override the automatic disabling of MPX. | |
32 | */ | |
33 | static int forcempx; | |
34 | ||
35 | static int __init forcempx_setup(char *__unused) | |
36 | { | |
37 | forcempx = 1; | |
38 | ||
39 | return 1; | |
40 | } | |
41 | __setup("intel-skd-046-workaround=disable", forcempx_setup); | |
42 | ||
43 | void check_mpx_erratum(struct cpuinfo_x86 *c) | |
44 | { | |
45 | if (forcempx) | |
46 | return; | |
47 | /* | |
48 | * Turn off the MPX feature on CPUs where SMEP is not | |
49 | * available or disabled. | |
50 | * | |
51 | * Works around Intel Erratum SKD046: "Branch Instructions | |
52 | * May Initialize MPX Bound Registers Incorrectly". | |
53 | * | |
54 | * This might falsely disable MPX on systems without | |
55 | * SMEP, like Atom processors without SMEP. But there | |
56 | * is no such hardware known at the moment. | |
57 | */ | |
58 | if (cpu_has(c, X86_FEATURE_MPX) && !cpu_has(c, X86_FEATURE_SMEP)) { | |
59 | setup_clear_cpu_cap(X86_FEATURE_MPX); | |
60 | pr_warn("x86/mpx: Disabling MPX since SMEP not present\n"); | |
61 | } | |
62 | } | |
63 | ||
148f9bb8 | 64 | static void early_init_intel(struct cpuinfo_x86 *c) |
1da177e4 | 65 | { |
161ec53c FY |
66 | u64 misc_enable; |
67 | ||
99fb4d34 | 68 | /* Unmask CPUID levels if masked: */ |
30a0fb94 | 69 | if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) { |
0b131be8 PA |
70 | if (msr_clear_bit(MSR_IA32_MISC_ENABLE, |
71 | MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT) > 0) { | |
99fb4d34 | 72 | c->cpuid_level = cpuid_eax(0); |
d900329e | 73 | get_cpu_cap(c); |
99fb4d34 | 74 | } |
066941bd PA |
75 | } |
76 | ||
2b16a235 AK |
77 | if ((c->x86 == 0xf && c->x86_model >= 0x03) || |
78 | (c->x86 == 0x6 && c->x86_model >= 0x0e)) | |
79 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); | |
185f3b9d | 80 | |
506ed6b5 AK |
81 | if (c->x86 >= 6 && !cpu_has(c, X86_FEATURE_IA64)) { |
82 | unsigned lower_word; | |
83 | ||
84 | wrmsr(MSR_IA32_UCODE_REV, 0, 0); | |
85 | /* Required by the SDM */ | |
86 | sync_core(); | |
87 | rdmsr(MSR_IA32_UCODE_REV, lower_word, c->microcode); | |
88 | } | |
89 | ||
7a0fc404 PA |
90 | /* |
91 | * Atom erratum AAE44/AAF40/AAG38/AAH41: | |
92 | * | |
93 | * A race condition between speculative fetches and invalidating | |
94 | * a large page. This is worked around in microcode, but we | |
95 | * need the microcode to have already been loaded... so if it is | |
96 | * not, recommend a BIOS update and disable large pages. | |
97 | */ | |
30963c0a AK |
98 | if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_mask <= 2 && |
99 | c->microcode < 0x20e) { | |
1b74dde7 | 100 | pr_warn("Atom PSE erratum detected, BIOS microcode update recommended\n"); |
30963c0a | 101 | clear_cpu_cap(c, X86_FEATURE_PSE); |
7a0fc404 PA |
102 | } |
103 | ||
185f3b9d YL |
104 | #ifdef CONFIG_X86_64 |
105 | set_cpu_cap(c, X86_FEATURE_SYSENTER32); | |
106 | #else | |
107 | /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */ | |
108 | if (c->x86 == 15 && c->x86_cache_alignment == 64) | |
109 | c->x86_cache_alignment = 128; | |
110 | #endif | |
40fb1715 | 111 | |
13c6c532 JB |
112 | /* CPUID workaround for 0F33/0F34 CPU */ |
113 | if (c->x86 == 0xF && c->x86_model == 0x3 | |
114 | && (c->x86_mask == 0x3 || c->x86_mask == 0x4)) | |
115 | c->x86_phys_bits = 36; | |
116 | ||
40fb1715 VP |
117 | /* |
118 | * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate | |
83ce4009 IM |
119 | * with P/T states and does not stop in deep C-states. |
120 | * | |
121 | * It is also reliable across cores and sockets. (but not across | |
122 | * cabinets - we turn it off in that case explicitly.) | |
40fb1715 VP |
123 | */ |
124 | if (c->x86_power & (1 << 8)) { | |
125 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); | |
126 | set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); | |
14be1f74 | 127 | if (!check_tsc_unstable()) |
35af99e6 | 128 | set_sched_clock_stable(); |
40fb1715 VP |
129 | } |
130 | ||
c54fdbb2 FT |
131 | /* Penwell and Cloverview have the TSC which doesn't sleep on S3 */ |
132 | if (c->x86 == 6) { | |
133 | switch (c->x86_model) { | |
134 | case 0x27: /* Penwell */ | |
135 | case 0x35: /* Cloverview */ | |
354dbaa7 | 136 | case 0x4a: /* Merrifield */ |
c54fdbb2 FT |
137 | set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC_S3); |
138 | break; | |
139 | default: | |
140 | break; | |
141 | } | |
142 | } | |
143 | ||
75a04811 PA |
144 | /* |
145 | * There is a known erratum on Pentium III and Core Solo | |
146 | * and Core Duo CPUs. | |
147 | * " Page with PAT set to WC while associated MTRR is UC | |
148 | * may consolidate to UC " | |
149 | * Because of this erratum, it is better to stick with | |
150 | * setting WC in MTRR rather than using PAT on these CPUs. | |
151 | * | |
152 | * Enable PAT WC only on P4, Core 2 or later CPUs. | |
153 | */ | |
154 | if (c->x86 == 6 && c->x86_model < 15) | |
155 | clear_cpu_cap(c, X86_FEATURE_PAT); | |
f8561296 VN |
156 | |
157 | #ifdef CONFIG_KMEMCHECK | |
158 | /* | |
159 | * P4s have a "fast strings" feature which causes single- | |
160 | * stepping REP instructions to only generate a #DB on | |
161 | * cache-line boundaries. | |
162 | * | |
163 | * Ingo Molnar reported a Pentium D (model 6) and a Xeon | |
164 | * (model 2) with the same problem. | |
165 | */ | |
c0a639ad | 166 | if (c->x86 == 15) |
0b131be8 PA |
167 | if (msr_clear_bit(MSR_IA32_MISC_ENABLE, |
168 | MSR_IA32_MISC_ENABLE_FAST_STRING_BIT) > 0) | |
c0a639ad | 169 | pr_info("kmemcheck: Disabling fast string operations\n"); |
f8561296 | 170 | #endif |
161ec53c FY |
171 | |
172 | /* | |
173 | * If fast string is not enabled in IA32_MISC_ENABLE for any reason, | |
174 | * clear the fast string and enhanced fast string CPU capabilities. | |
175 | */ | |
176 | if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) { | |
177 | rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); | |
178 | if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) { | |
1b74dde7 | 179 | pr_info("Disabled fast string operations\n"); |
161ec53c FY |
180 | setup_clear_cpu_cap(X86_FEATURE_REP_GOOD); |
181 | setup_clear_cpu_cap(X86_FEATURE_ERMS); | |
182 | } | |
183 | } | |
ee1b5b16 BD |
184 | |
185 | /* | |
186 | * Intel Quark Core DevMan_001.pdf section 6.4.11 | |
187 | * "The operating system also is required to invalidate (i.e., flush) | |
188 | * the TLB when any changes are made to any of the page table entries. | |
189 | * The operating system must reload CR3 to cause the TLB to be flushed" | |
190 | * | |
c109bf95 BP |
191 | * As a result, boot_cpu_has(X86_FEATURE_PGE) in arch/x86/include/asm/tlbflush.h |
192 | * should be false so that __flush_tlb_all() causes CR3 insted of CR4.PGE | |
193 | * to be modified. | |
ee1b5b16 BD |
194 | */ |
195 | if (c->x86 == 5 && c->x86_model == 9) { | |
196 | pr_info("Disabling PGE capability bit\n"); | |
197 | setup_clear_cpu_cap(X86_FEATURE_PGE); | |
198 | } | |
1f12e32f TG |
199 | |
200 | if (c->cpuid_level >= 0x00000001) { | |
201 | u32 eax, ebx, ecx, edx; | |
202 | ||
203 | cpuid(0x00000001, &eax, &ebx, &ecx, &edx); | |
204 | /* | |
205 | * If HTT (EDX[28]) is set EBX[16:23] contain the number of | |
206 | * apicids which are reserved per package. Store the resulting | |
207 | * shift value for the package management code. | |
208 | */ | |
209 | if (edx & (1U << 28)) | |
210 | c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff); | |
211 | } | |
0f6ff2bc DH |
212 | |
213 | check_mpx_erratum(c); | |
1da177e4 LT |
214 | } |
215 | ||
185f3b9d | 216 | #ifdef CONFIG_X86_32 |
1da177e4 LT |
217 | /* |
218 | * Early probe support logic for ppro memory erratum #50 | |
219 | * | |
220 | * This is called before we do cpu ident work | |
221 | */ | |
65eb6b43 | 222 | |
148f9bb8 | 223 | int ppro_with_ram_bug(void) |
1da177e4 LT |
224 | { |
225 | /* Uses data from early_cpu_detect now */ | |
226 | if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && | |
227 | boot_cpu_data.x86 == 6 && | |
228 | boot_cpu_data.x86_model == 1 && | |
229 | boot_cpu_data.x86_mask < 8) { | |
1b74dde7 | 230 | pr_info("Pentium Pro with Errata#50 detected. Taking evasive action.\n"); |
1da177e4 LT |
231 | return 1; |
232 | } | |
233 | return 0; | |
234 | } | |
65eb6b43 | 235 | |
148f9bb8 | 236 | static void intel_smp_check(struct cpuinfo_x86 *c) |
1f442d70 | 237 | { |
1f442d70 | 238 | /* calling is from identify_secondary_cpu() ? */ |
f6e9456c | 239 | if (!c->cpu_index) |
1f442d70 YL |
240 | return; |
241 | ||
242 | /* | |
243 | * Mask B, Pentium, but not Pentium MMX | |
244 | */ | |
245 | if (c->x86 == 5 && | |
246 | c->x86_mask >= 1 && c->x86_mask <= 4 && | |
247 | c->x86_model <= 3) { | |
248 | /* | |
249 | * Remember we have B step Pentia with bugs | |
250 | */ | |
251 | WARN_ONCE(1, "WARNING: SMP operation may be unreliable" | |
252 | "with B stepping processors.\n"); | |
253 | } | |
1f442d70 YL |
254 | } |
255 | ||
69f2366c CB |
256 | static int forcepae; |
257 | static int __init forcepae_setup(char *__unused) | |
258 | { | |
259 | forcepae = 1; | |
260 | return 1; | |
261 | } | |
262 | __setup("forcepae", forcepae_setup); | |
263 | ||
148f9bb8 | 264 | static void intel_workarounds(struct cpuinfo_x86 *c) |
1da177e4 | 265 | { |
4052704d YL |
266 | #ifdef CONFIG_X86_F00F_BUG |
267 | /* | |
d4e1a0af | 268 | * All models of Pentium and Pentium with MMX technology CPUs |
8bdbd962 | 269 | * have the F0 0F bug, which lets nonprivileged users lock up the |
4eefbe79 | 270 | * system. Announce that the fault handler will be checking for it. |
d4e1a0af | 271 | * The Quark is also family 5, but does not have the same bug. |
4052704d | 272 | */ |
e2604b49 | 273 | clear_cpu_bug(c, X86_BUG_F00F); |
fa392794 | 274 | if (c->x86 == 5 && c->x86_model < 9) { |
4052704d YL |
275 | static int f00f_workaround_enabled; |
276 | ||
e2604b49 | 277 | set_cpu_bug(c, X86_BUG_F00F); |
4052704d | 278 | if (!f00f_workaround_enabled) { |
1b74dde7 | 279 | pr_notice("Intel Pentium with F0 0F bug - workaround enabled.\n"); |
4052704d YL |
280 | f00f_workaround_enabled = 1; |
281 | } | |
282 | } | |
283 | #endif | |
284 | ||
285 | /* | |
286 | * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until | |
287 | * model 3 mask 3 | |
288 | */ | |
289 | if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633) | |
290 | clear_cpu_cap(c, X86_FEATURE_SEP); | |
291 | ||
69f2366c CB |
292 | /* |
293 | * PAE CPUID issue: many Pentium M report no PAE but may have a | |
294 | * functionally usable PAE implementation. | |
295 | * Forcefully enable PAE if kernel parameter "forcepae" is present. | |
296 | */ | |
297 | if (forcepae) { | |
1b74dde7 | 298 | pr_warn("PAE forced!\n"); |
69f2366c CB |
299 | set_cpu_cap(c, X86_FEATURE_PAE); |
300 | add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_NOW_UNRELIABLE); | |
301 | } | |
302 | ||
4052704d | 303 | /* |
f0133acc | 304 | * P4 Xeon erratum 037 workaround. |
4052704d YL |
305 | * Hardware prefetcher may cause stale data to be loaded into the cache. |
306 | */ | |
1da177e4 | 307 | if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) { |
0b131be8 | 308 | if (msr_set_bit(MSR_IA32_MISC_ENABLE, |
f0133acc | 309 | MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT) > 0) { |
c0a639ad | 310 | pr_info("CPU: C0 stepping P4 Xeon detected.\n"); |
f0133acc | 311 | pr_info("CPU: Disabling hardware prefetching (Erratum 037)\n"); |
1da177e4 LT |
312 | } |
313 | } | |
1da177e4 | 314 | |
4052704d YL |
315 | /* |
316 | * See if we have a good local APIC by checking for buggy Pentia, | |
317 | * i.e. all B steppings and the C2 stepping of P54C when using their | |
318 | * integrated APIC (see 11AP erratum in "Pentium Processor | |
319 | * Specification Update"). | |
320 | */ | |
93984fbd | 321 | if (boot_cpu_has(X86_FEATURE_APIC) && (c->x86<<8 | c->x86_model<<4) == 0x520 && |
4052704d | 322 | (c->x86_mask < 0x6 || c->x86_mask == 0xb)) |
9b13a93d | 323 | set_cpu_bug(c, X86_BUG_11AP); |
185f3b9d | 324 | |
185f3b9d | 325 | |
4052704d | 326 | #ifdef CONFIG_X86_INTEL_USERCOPY |
185f3b9d | 327 | /* |
4052704d | 328 | * Set up the preferred alignment for movsl bulk memory moves |
185f3b9d | 329 | */ |
4052704d YL |
330 | switch (c->x86) { |
331 | case 4: /* 486: untested */ | |
332 | break; | |
333 | case 5: /* Old Pentia: untested */ | |
334 | break; | |
335 | case 6: /* PII/PIII only like movsl with 8-byte alignment */ | |
336 | movsl_mask.mask = 7; | |
337 | break; | |
338 | case 15: /* P4 is OK down to 8-byte alignment */ | |
339 | movsl_mask.mask = 7; | |
340 | break; | |
341 | } | |
185f3b9d | 342 | #endif |
4052704d | 343 | |
1f442d70 | 344 | intel_smp_check(c); |
4052704d YL |
345 | } |
346 | #else | |
148f9bb8 | 347 | static void intel_workarounds(struct cpuinfo_x86 *c) |
4052704d YL |
348 | { |
349 | } | |
185f3b9d YL |
350 | #endif |
351 | ||
148f9bb8 | 352 | static void srat_detect_node(struct cpuinfo_x86 *c) |
185f3b9d | 353 | { |
645a7919 | 354 | #ifdef CONFIG_NUMA |
185f3b9d YL |
355 | unsigned node; |
356 | int cpu = smp_processor_id(); | |
185f3b9d YL |
357 | |
358 | /* Don't do the funky fallback heuristics the AMD version employs | |
359 | for now. */ | |
bbc9e2f4 | 360 | node = numa_cpu_node(cpu); |
50f2d7f6 | 361 | if (node == NUMA_NO_NODE || !node_online(node)) { |
d9c2d5ac YL |
362 | /* reuse the value from init_cpu_to_node() */ |
363 | node = cpu_to_node(cpu); | |
364 | } | |
185f3b9d | 365 | numa_set_node(cpu, node); |
185f3b9d YL |
366 | #endif |
367 | } | |
368 | ||
3dd9d514 AK |
369 | /* |
370 | * find out the number of processor cores on the die | |
371 | */ | |
148f9bb8 | 372 | static int intel_num_cpu_cores(struct cpuinfo_x86 *c) |
3dd9d514 | 373 | { |
f2ab4461 | 374 | unsigned int eax, ebx, ecx, edx; |
3dd9d514 | 375 | |
8d415ee2 | 376 | if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4) |
3dd9d514 AK |
377 | return 1; |
378 | ||
f2ab4461 ZA |
379 | /* Intel has a non-standard dependency on %ecx for this CPUID level. */ |
380 | cpuid_count(4, 0, &eax, &ebx, &ecx, &edx); | |
3dd9d514 | 381 | if (eax & 0x1f) |
8bdbd962 | 382 | return (eax >> 26) + 1; |
3dd9d514 AK |
383 | else |
384 | return 1; | |
385 | } | |
386 | ||
148f9bb8 | 387 | static void detect_vmx_virtcap(struct cpuinfo_x86 *c) |
e38e05a8 SY |
388 | { |
389 | /* Intel VMX MSR indicated features */ | |
390 | #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000 | |
391 | #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000 | |
392 | #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000 | |
393 | #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001 | |
394 | #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002 | |
395 | #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020 | |
396 | ||
397 | u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2; | |
398 | ||
399 | clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW); | |
400 | clear_cpu_cap(c, X86_FEATURE_VNMI); | |
401 | clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY); | |
402 | clear_cpu_cap(c, X86_FEATURE_EPT); | |
403 | clear_cpu_cap(c, X86_FEATURE_VPID); | |
404 | ||
405 | rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high); | |
406 | msr_ctl = vmx_msr_high | vmx_msr_low; | |
407 | if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW) | |
408 | set_cpu_cap(c, X86_FEATURE_TPR_SHADOW); | |
409 | if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI) | |
410 | set_cpu_cap(c, X86_FEATURE_VNMI); | |
411 | if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) { | |
412 | rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2, | |
413 | vmx_msr_low, vmx_msr_high); | |
414 | msr_ctl2 = vmx_msr_high | vmx_msr_low; | |
415 | if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) && | |
416 | (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)) | |
417 | set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY); | |
418 | if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT) | |
419 | set_cpu_cap(c, X86_FEATURE_EPT); | |
420 | if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID) | |
421 | set_cpu_cap(c, X86_FEATURE_VPID); | |
422 | } | |
423 | } | |
424 | ||
b51ef52d LA |
425 | static void init_intel_energy_perf(struct cpuinfo_x86 *c) |
426 | { | |
427 | u64 epb; | |
428 | ||
429 | /* | |
430 | * Initialize MSR_IA32_ENERGY_PERF_BIAS if not already initialized. | |
431 | * (x86_energy_perf_policy(8) is available to change it at run-time.) | |
432 | */ | |
433 | if (!cpu_has(c, X86_FEATURE_EPB)) | |
434 | return; | |
435 | ||
436 | rdmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb); | |
437 | if ((epb & 0xF) != ENERGY_PERF_BIAS_PERFORMANCE) | |
438 | return; | |
439 | ||
440 | pr_warn_once("ENERGY_PERF_BIAS: Set to 'normal', was 'performance'\n"); | |
441 | pr_warn_once("ENERGY_PERF_BIAS: View and update with x86_energy_perf_policy(8)\n"); | |
442 | epb = (epb & ~0xF) | ENERGY_PERF_BIAS_NORMAL; | |
443 | wrmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb); | |
444 | } | |
445 | ||
446 | static void intel_bsp_resume(struct cpuinfo_x86 *c) | |
447 | { | |
448 | /* | |
449 | * MSR_IA32_ENERGY_PERF_BIAS is lost across suspend/resume, | |
450 | * so reinitialize it properly like during bootup: | |
451 | */ | |
452 | init_intel_energy_perf(c); | |
453 | } | |
454 | ||
148f9bb8 | 455 | static void init_intel(struct cpuinfo_x86 *c) |
1da177e4 LT |
456 | { |
457 | unsigned int l2 = 0; | |
1da177e4 | 458 | |
2b16a235 AK |
459 | early_init_intel(c); |
460 | ||
4052704d | 461 | intel_workarounds(c); |
1da177e4 | 462 | |
345077cd SS |
463 | /* |
464 | * Detect the extended topology information if available. This | |
465 | * will reinitialise the initial_apicid which will be used | |
466 | * in init_intel_cacheinfo() | |
467 | */ | |
468 | detect_extended_topology(c); | |
469 | ||
2a226155 PZ |
470 | if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) { |
471 | /* | |
472 | * let's use the legacy cpuid vector 0x1 and 0x4 for topology | |
473 | * detection. | |
474 | */ | |
475 | c->x86_max_cores = intel_num_cpu_cores(c); | |
476 | #ifdef CONFIG_X86_32 | |
477 | detect_ht(c); | |
478 | #endif | |
479 | } | |
480 | ||
1da177e4 | 481 | l2 = init_intel_cacheinfo(c); |
aece118e BD |
482 | |
483 | /* Detect legacy cache sizes if init_intel_cacheinfo did not */ | |
484 | if (l2 == 0) { | |
485 | cpu_detect_cache_sizes(c); | |
486 | l2 = c->x86_cache_size; | |
487 | } | |
488 | ||
65eb6b43 | 489 | if (c->cpuid_level > 9) { |
0080e667 VP |
490 | unsigned eax = cpuid_eax(10); |
491 | /* Check for version and the number of counters */ | |
492 | if ((eax & 0xff) && (((eax>>8) & 0xff) > 1)) | |
d0e95ebd | 493 | set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); |
0080e667 | 494 | } |
1da177e4 | 495 | |
054efb64 | 496 | if (cpu_has(c, X86_FEATURE_XMM2)) |
4052704d | 497 | set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC); |
362f924b BP |
498 | |
499 | if (boot_cpu_has(X86_FEATURE_DS)) { | |
4052704d YL |
500 | unsigned int l1; |
501 | rdmsr(MSR_IA32_MISC_ENABLE, l1, l2); | |
502 | if (!(l1 & (1<<11))) | |
503 | set_cpu_cap(c, X86_FEATURE_BTS); | |
504 | if (!(l1 & (1<<12))) | |
505 | set_cpu_cap(c, X86_FEATURE_PEBS); | |
4052704d | 506 | } |
1da177e4 | 507 | |
906bf7fd | 508 | if (c->x86 == 6 && boot_cpu_has(X86_FEATURE_CLFLUSH) && |
40e2d7f9 | 509 | (c->x86_model == 29 || c->x86_model == 46 || c->x86_model == 47)) |
9b13a93d | 510 | set_cpu_bug(c, X86_BUG_CLFLUSH_MONITOR); |
e736ad54 | 511 | |
08e237fa PZ |
512 | if (c->x86 == 6 && boot_cpu_has(X86_FEATURE_MWAIT) && |
513 | ((c->x86_model == INTEL_FAM6_ATOM_GOLDMONT))) | |
514 | set_cpu_bug(c, X86_BUG_MONITOR); | |
515 | ||
4052704d YL |
516 | #ifdef CONFIG_X86_64 |
517 | if (c->x86 == 15) | |
518 | c->x86_cache_alignment = c->x86_clflush_size * 2; | |
519 | if (c->x86 == 6) | |
520 | set_cpu_cap(c, X86_FEATURE_REP_GOOD); | |
521 | #else | |
65eb6b43 PC |
522 | /* |
523 | * Names for the Pentium II/Celeron processors | |
524 | * detectable only by also checking the cache size. | |
525 | * Dixon is NOT a Celeron. | |
526 | */ | |
1da177e4 | 527 | if (c->x86 == 6) { |
4052704d YL |
528 | char *p = NULL; |
529 | ||
1da177e4 LT |
530 | switch (c->x86_model) { |
531 | case 5: | |
865be7a8 OZ |
532 | if (l2 == 0) |
533 | p = "Celeron (Covington)"; | |
534 | else if (l2 == 256) | |
535 | p = "Mobile Pentium II (Dixon)"; | |
1da177e4 | 536 | break; |
65eb6b43 | 537 | |
1da177e4 LT |
538 | case 6: |
539 | if (l2 == 128) | |
540 | p = "Celeron (Mendocino)"; | |
541 | else if (c->x86_mask == 0 || c->x86_mask == 5) | |
542 | p = "Celeron-A"; | |
543 | break; | |
65eb6b43 | 544 | |
1da177e4 LT |
545 | case 8: |
546 | if (l2 == 128) | |
547 | p = "Celeron (Coppermine)"; | |
548 | break; | |
549 | } | |
1da177e4 | 550 | |
4052704d YL |
551 | if (p) |
552 | strcpy(c->x86_model_id, p); | |
1da177e4 | 553 | } |
1da177e4 | 554 | |
185f3b9d YL |
555 | if (c->x86 == 15) |
556 | set_cpu_cap(c, X86_FEATURE_P4); | |
557 | if (c->x86 == 6) | |
558 | set_cpu_cap(c, X86_FEATURE_P3); | |
f4166c54 | 559 | #endif |
185f3b9d | 560 | |
185f3b9d | 561 | /* Work around errata */ |
2759c328 | 562 | srat_detect_node(c); |
e38e05a8 SY |
563 | |
564 | if (cpu_has(c, X86_FEATURE_VMX)) | |
565 | detect_vmx_virtcap(c); | |
abe48b10 | 566 | |
b51ef52d | 567 | init_intel_energy_perf(c); |
42ed458a | 568 | } |
1da177e4 | 569 | |
185f3b9d | 570 | #ifdef CONFIG_X86_32 |
148f9bb8 | 571 | static unsigned int intel_size_cache(struct cpuinfo_x86 *c, unsigned int size) |
1da177e4 | 572 | { |
65eb6b43 PC |
573 | /* |
574 | * Intel PIII Tualatin. This comes in two flavours. | |
1da177e4 LT |
575 | * One has 256kb of cache, the other 512. We have no way |
576 | * to determine which, so we use a boottime override | |
577 | * for the 512kb model, and assume 256 otherwise. | |
578 | */ | |
579 | if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0)) | |
580 | size = 256; | |
aece118e BD |
581 | |
582 | /* | |
583 | * Intel Quark SoC X1000 contains a 4-way set associative | |
584 | * 16K cache with a 16 byte cache line and 256 lines per tag | |
585 | */ | |
586 | if ((c->x86 == 5) && (c->x86_model == 9)) | |
587 | size = 16; | |
1da177e4 LT |
588 | return size; |
589 | } | |
185f3b9d | 590 | #endif |
1da177e4 | 591 | |
e0ba94f1 AS |
592 | #define TLB_INST_4K 0x01 |
593 | #define TLB_INST_4M 0x02 | |
594 | #define TLB_INST_2M_4M 0x03 | |
595 | ||
596 | #define TLB_INST_ALL 0x05 | |
597 | #define TLB_INST_1G 0x06 | |
598 | ||
599 | #define TLB_DATA_4K 0x11 | |
600 | #define TLB_DATA_4M 0x12 | |
601 | #define TLB_DATA_2M_4M 0x13 | |
602 | #define TLB_DATA_4K_4M 0x14 | |
603 | ||
604 | #define TLB_DATA_1G 0x16 | |
605 | ||
606 | #define TLB_DATA0_4K 0x21 | |
607 | #define TLB_DATA0_4M 0x22 | |
608 | #define TLB_DATA0_2M_4M 0x23 | |
609 | ||
610 | #define STLB_4K 0x41 | |
dd360393 | 611 | #define STLB_4K_2M 0x42 |
e0ba94f1 | 612 | |
148f9bb8 | 613 | static const struct _tlb_table intel_tlb_table[] = { |
e0ba94f1 AS |
614 | { 0x01, TLB_INST_4K, 32, " TLB_INST 4 KByte pages, 4-way set associative" }, |
615 | { 0x02, TLB_INST_4M, 2, " TLB_INST 4 MByte pages, full associative" }, | |
616 | { 0x03, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way set associative" }, | |
617 | { 0x04, TLB_DATA_4M, 8, " TLB_DATA 4 MByte pages, 4-way set associative" }, | |
618 | { 0x05, TLB_DATA_4M, 32, " TLB_DATA 4 MByte pages, 4-way set associative" }, | |
619 | { 0x0b, TLB_INST_4M, 4, " TLB_INST 4 MByte pages, 4-way set associative" }, | |
620 | { 0x4f, TLB_INST_4K, 32, " TLB_INST 4 KByte pages */" }, | |
621 | { 0x50, TLB_INST_ALL, 64, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" }, | |
622 | { 0x51, TLB_INST_ALL, 128, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" }, | |
623 | { 0x52, TLB_INST_ALL, 256, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" }, | |
624 | { 0x55, TLB_INST_2M_4M, 7, " TLB_INST 2-MByte or 4-MByte pages, fully associative" }, | |
625 | { 0x56, TLB_DATA0_4M, 16, " TLB_DATA0 4 MByte pages, 4-way set associative" }, | |
626 | { 0x57, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, 4-way associative" }, | |
627 | { 0x59, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, fully associative" }, | |
628 | { 0x5a, TLB_DATA0_2M_4M, 32, " TLB_DATA0 2-MByte or 4 MByte pages, 4-way set associative" }, | |
629 | { 0x5b, TLB_DATA_4K_4M, 64, " TLB_DATA 4 KByte and 4 MByte pages" }, | |
630 | { 0x5c, TLB_DATA_4K_4M, 128, " TLB_DATA 4 KByte and 4 MByte pages" }, | |
631 | { 0x5d, TLB_DATA_4K_4M, 256, " TLB_DATA 4 KByte and 4 MByte pages" }, | |
dd360393 KS |
632 | { 0x61, TLB_INST_4K, 48, " TLB_INST 4 KByte pages, full associative" }, |
633 | { 0x63, TLB_DATA_1G, 4, " TLB_DATA 1 GByte pages, 4-way set associative" }, | |
634 | { 0x76, TLB_INST_2M_4M, 8, " TLB_INST 2-MByte or 4-MByte pages, fully associative" }, | |
e0ba94f1 AS |
635 | { 0xb0, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 4-way set associative" }, |
636 | { 0xb1, TLB_INST_2M_4M, 4, " TLB_INST 2M pages, 4-way, 8 entries or 4M pages, 4-way entries" }, | |
637 | { 0xb2, TLB_INST_4K, 64, " TLB_INST 4KByte pages, 4-way set associative" }, | |
638 | { 0xb3, TLB_DATA_4K, 128, " TLB_DATA 4 KByte pages, 4-way set associative" }, | |
639 | { 0xb4, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 4-way associative" }, | |
a927792c YG |
640 | { 0xb5, TLB_INST_4K, 64, " TLB_INST 4 KByte pages, 8-way set associative" }, |
641 | { 0xb6, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 8-way set associative" }, | |
e0ba94f1 AS |
642 | { 0xba, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way associative" }, |
643 | { 0xc0, TLB_DATA_4K_4M, 8, " TLB_DATA 4 KByte and 4 MByte pages, 4-way associative" }, | |
dd360393 KS |
644 | { 0xc1, STLB_4K_2M, 1024, " STLB 4 KByte and 2 MByte pages, 8-way associative" }, |
645 | { 0xc2, TLB_DATA_2M_4M, 16, " DTLB 2 MByte/4MByte pages, 4-way associative" }, | |
e0ba94f1 AS |
646 | { 0xca, STLB_4K, 512, " STLB 4 KByte pages, 4-way associative" }, |
647 | { 0x00, 0, 0 } | |
648 | }; | |
649 | ||
148f9bb8 | 650 | static void intel_tlb_lookup(const unsigned char desc) |
e0ba94f1 AS |
651 | { |
652 | unsigned char k; | |
653 | if (desc == 0) | |
654 | return; | |
655 | ||
656 | /* look up this descriptor in the table */ | |
657 | for (k = 0; intel_tlb_table[k].descriptor != desc && \ | |
658 | intel_tlb_table[k].descriptor != 0; k++) | |
659 | ; | |
660 | ||
661 | if (intel_tlb_table[k].tlb_type == 0) | |
662 | return; | |
663 | ||
664 | switch (intel_tlb_table[k].tlb_type) { | |
665 | case STLB_4K: | |
666 | if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) | |
667 | tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries; | |
668 | if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) | |
669 | tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries; | |
670 | break; | |
dd360393 KS |
671 | case STLB_4K_2M: |
672 | if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) | |
673 | tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries; | |
674 | if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) | |
675 | tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries; | |
676 | if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries) | |
677 | tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries; | |
678 | if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries) | |
679 | tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries; | |
680 | if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) | |
681 | tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries; | |
682 | if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) | |
683 | tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries; | |
684 | break; | |
e0ba94f1 AS |
685 | case TLB_INST_ALL: |
686 | if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) | |
687 | tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries; | |
688 | if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries) | |
689 | tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries; | |
690 | if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) | |
691 | tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries; | |
692 | break; | |
693 | case TLB_INST_4K: | |
694 | if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) | |
695 | tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries; | |
696 | break; | |
697 | case TLB_INST_4M: | |
698 | if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) | |
699 | tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries; | |
700 | break; | |
701 | case TLB_INST_2M_4M: | |
702 | if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries) | |
703 | tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries; | |
704 | if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) | |
705 | tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries; | |
706 | break; | |
707 | case TLB_DATA_4K: | |
708 | case TLB_DATA0_4K: | |
709 | if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) | |
710 | tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries; | |
711 | break; | |
712 | case TLB_DATA_4M: | |
713 | case TLB_DATA0_4M: | |
714 | if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) | |
715 | tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries; | |
716 | break; | |
717 | case TLB_DATA_2M_4M: | |
718 | case TLB_DATA0_2M_4M: | |
719 | if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries) | |
720 | tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries; | |
721 | if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) | |
722 | tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries; | |
723 | break; | |
724 | case TLB_DATA_4K_4M: | |
725 | if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) | |
726 | tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries; | |
727 | if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) | |
728 | tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries; | |
729 | break; | |
dd360393 KS |
730 | case TLB_DATA_1G: |
731 | if (tlb_lld_1g[ENTRIES] < intel_tlb_table[k].entries) | |
732 | tlb_lld_1g[ENTRIES] = intel_tlb_table[k].entries; | |
e0ba94f1 AS |
733 | break; |
734 | } | |
735 | } | |
736 | ||
148f9bb8 | 737 | static void intel_detect_tlb(struct cpuinfo_x86 *c) |
e0ba94f1 AS |
738 | { |
739 | int i, j, n; | |
740 | unsigned int regs[4]; | |
741 | unsigned char *desc = (unsigned char *)regs; | |
5b556332 BP |
742 | |
743 | if (c->cpuid_level < 2) | |
744 | return; | |
745 | ||
e0ba94f1 AS |
746 | /* Number of times to iterate */ |
747 | n = cpuid_eax(2) & 0xFF; | |
748 | ||
749 | for (i = 0 ; i < n ; i++) { | |
750 | cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]); | |
751 | ||
752 | /* If bit 31 is set, this is an unknown format */ | |
753 | for (j = 0 ; j < 3 ; j++) | |
754 | if (regs[j] & (1 << 31)) | |
755 | regs[j] = 0; | |
756 | ||
757 | /* Byte 0 is level count, not a descriptor */ | |
758 | for (j = 1 ; j < 16 ; j++) | |
759 | intel_tlb_lookup(desc[j]); | |
760 | } | |
761 | } | |
762 | ||
148f9bb8 | 763 | static const struct cpu_dev intel_cpu_dev = { |
1da177e4 | 764 | .c_vendor = "Intel", |
65eb6b43 | 765 | .c_ident = { "GenuineIntel" }, |
185f3b9d | 766 | #ifdef CONFIG_X86_32 |
09dc68d9 JB |
767 | .legacy_models = { |
768 | { .family = 4, .model_names = | |
65eb6b43 PC |
769 | { |
770 | [0] = "486 DX-25/33", | |
771 | [1] = "486 DX-50", | |
772 | [2] = "486 SX", | |
773 | [3] = "486 DX/2", | |
774 | [4] = "486 SL", | |
775 | [5] = "486 SX/2", | |
776 | [7] = "486 DX/2-WB", | |
777 | [8] = "486 DX/4", | |
1da177e4 LT |
778 | [9] = "486 DX/4-WB" |
779 | } | |
780 | }, | |
09dc68d9 | 781 | { .family = 5, .model_names = |
65eb6b43 PC |
782 | { |
783 | [0] = "Pentium 60/66 A-step", | |
784 | [1] = "Pentium 60/66", | |
1da177e4 | 785 | [2] = "Pentium 75 - 200", |
65eb6b43 | 786 | [3] = "OverDrive PODP5V83", |
1da177e4 | 787 | [4] = "Pentium MMX", |
65eb6b43 | 788 | [7] = "Mobile Pentium 75 - 200", |
aece118e BD |
789 | [8] = "Mobile Pentium MMX", |
790 | [9] = "Quark SoC X1000", | |
1da177e4 LT |
791 | } |
792 | }, | |
09dc68d9 | 793 | { .family = 6, .model_names = |
65eb6b43 | 794 | { |
1da177e4 | 795 | [0] = "Pentium Pro A-step", |
65eb6b43 PC |
796 | [1] = "Pentium Pro", |
797 | [3] = "Pentium II (Klamath)", | |
798 | [4] = "Pentium II (Deschutes)", | |
799 | [5] = "Pentium II (Deschutes)", | |
1da177e4 | 800 | [6] = "Mobile Pentium II", |
65eb6b43 PC |
801 | [7] = "Pentium III (Katmai)", |
802 | [8] = "Pentium III (Coppermine)", | |
1da177e4 LT |
803 | [10] = "Pentium III (Cascades)", |
804 | [11] = "Pentium III (Tualatin)", | |
805 | } | |
806 | }, | |
09dc68d9 | 807 | { .family = 15, .model_names = |
1da177e4 LT |
808 | { |
809 | [0] = "Pentium 4 (Unknown)", | |
810 | [1] = "Pentium 4 (Willamette)", | |
811 | [2] = "Pentium 4 (Northwood)", | |
812 | [4] = "Pentium 4 (Foster)", | |
813 | [5] = "Pentium 4 (Foster)", | |
814 | } | |
815 | }, | |
816 | }, | |
09dc68d9 | 817 | .legacy_cache_size = intel_size_cache, |
185f3b9d | 818 | #endif |
e0ba94f1 | 819 | .c_detect_tlb = intel_detect_tlb, |
03ae5768 | 820 | .c_early_init = early_init_intel, |
1da177e4 | 821 | .c_init = init_intel, |
b51ef52d | 822 | .c_bsp_resume = intel_bsp_resume, |
10a434fc | 823 | .c_x86_vendor = X86_VENDOR_INTEL, |
1da177e4 LT |
824 | }; |
825 | ||
10a434fc | 826 | cpu_dev_register(intel_cpu_dev); |
1da177e4 | 827 |