1 #include <linux/kernel.h>
3 #include <linux/string.h>
4 #include <linux/bitops.h>
6 #include <linux/sched.h>
7 #include <linux/thread_info.h>
8 #include <linux/module.h>
9 #include <linux/uaccess.h>
11 #include <asm/cpufeature.h>
12 #include <asm/pgtable.h>
16 #include <asm/intel-family.h>
17 #include <asm/microcode_intel.h>
20 #include <linux/topology.h>
25 #ifdef CONFIG_X86_LOCAL_APIC
26 #include <asm/mpspec.h>
31 * Early microcode releases for the Spectre v2 mitigation were broken.
32 * Information taken from;
33 * - https://newsroom.intel.com/wp-content/uploads/sites/11/2018/03/microcode-update-guidance.pdf
34 * - https://kb.vmware.com/s/article/52345
35 * - Microcode revisions observed in the wild
36 * - Release note from 20180108 microcode release
38 struct sku_microcode {
43 static const struct sku_microcode spectre_bad_microcodes[] = {
44 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0B, 0x80 },
45 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x0A, 0x80 },
46 { INTEL_FAM6_KABYLAKE_DESKTOP, 0x09, 0x80 },
47 { INTEL_FAM6_KABYLAKE_MOBILE, 0x0A, 0x80 },
48 { INTEL_FAM6_KABYLAKE_MOBILE, 0x09, 0x80 },
49 { INTEL_FAM6_SKYLAKE_X, 0x03, 0x0100013e },
50 { INTEL_FAM6_SKYLAKE_X, 0x04, 0x0200003c },
51 { INTEL_FAM6_BROADWELL_CORE, 0x04, 0x28 },
52 { INTEL_FAM6_BROADWELL_GT3E, 0x01, 0x1b },
53 { INTEL_FAM6_BROADWELL_XEON_D, 0x02, 0x14 },
54 { INTEL_FAM6_BROADWELL_XEON_D, 0x03, 0x07000011 },
55 { INTEL_FAM6_BROADWELL_X, 0x01, 0x0b000025 },
56 { INTEL_FAM6_HASWELL_ULT, 0x01, 0x21 },
57 { INTEL_FAM6_HASWELL_GT3E, 0x01, 0x18 },
58 { INTEL_FAM6_HASWELL_CORE, 0x03, 0x23 },
59 { INTEL_FAM6_HASWELL_X, 0x02, 0x3b },
60 { INTEL_FAM6_HASWELL_X, 0x04, 0x10 },
61 { INTEL_FAM6_IVYBRIDGE_X, 0x04, 0x42a },
62 /* Observed in the wild */
63 { INTEL_FAM6_SANDYBRIDGE_X, 0x06, 0x61b },
64 { INTEL_FAM6_SANDYBRIDGE_X, 0x07, 0x712 },
67 static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
72 * We know that the hypervisor lie to us on the microcode version so
73 * we may as well hope that it is running the correct version.
75 if (cpu_has(c, X86_FEATURE_HYPERVISOR))
81 for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) {
82 if (c->x86_model == spectre_bad_microcodes[i].model &&
83 c->x86_stepping == spectre_bad_microcodes[i].stepping)
84 return (c->microcode <= spectre_bad_microcodes[i].microcode);
89 static void early_init_intel(struct cpuinfo_x86 *c)
93 /* Unmask CPUID levels if masked: */
94 if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
95 if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
96 MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT) > 0) {
97 c->cpuid_level = cpuid_eax(0);
102 if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
103 (c->x86 == 0x6 && c->x86_model >= 0x0e))
104 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
106 if (c->x86 >= 6 && !cpu_has(c, X86_FEATURE_IA64))
107 c->microcode = intel_get_microcode_revision();
109 /* Now if any of them are set, check the blacklist and clear the lot */
110 if ((cpu_has(c, X86_FEATURE_SPEC_CTRL) ||
111 cpu_has(c, X86_FEATURE_INTEL_STIBP) ||
112 cpu_has(c, X86_FEATURE_IBRS) || cpu_has(c, X86_FEATURE_IBPB) ||
113 cpu_has(c, X86_FEATURE_STIBP)) && bad_spectre_microcode(c)) {
114 pr_warn("Intel Spectre v2 broken microcode detected; disabling Speculation Control\n");
115 setup_clear_cpu_cap(X86_FEATURE_IBRS);
116 setup_clear_cpu_cap(X86_FEATURE_IBPB);
117 setup_clear_cpu_cap(X86_FEATURE_STIBP);
118 setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL);
119 setup_clear_cpu_cap(X86_FEATURE_MSR_SPEC_CTRL);
120 setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
121 setup_clear_cpu_cap(X86_FEATURE_SSBD);
122 setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL_SSBD);
126 * Atom erratum AAE44/AAF40/AAG38/AAH41:
128 * A race condition between speculative fetches and invalidating
129 * a large page. This is worked around in microcode, but we
130 * need the microcode to have already been loaded... so if it is
131 * not, recommend a BIOS update and disable large pages.
133 if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_stepping <= 2 &&
134 c->microcode < 0x20e) {
135 printk(KERN_WARNING "Atom PSE erratum detected, BIOS microcode update recommended\n");
136 clear_cpu_cap(c, X86_FEATURE_PSE);
140 set_cpu_cap(c, X86_FEATURE_SYSENTER32);
142 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
143 if (c->x86 == 15 && c->x86_cache_alignment == 64)
144 c->x86_cache_alignment = 128;
147 /* CPUID workaround for 0F33/0F34 CPU */
148 if (c->x86 == 0xF && c->x86_model == 0x3
149 && (c->x86_stepping == 0x3 || c->x86_stepping == 0x4))
150 c->x86_phys_bits = 36;
153 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
154 * with P/T states and does not stop in deep C-states.
156 * It is also reliable across cores and sockets. (but not across
157 * cabinets - we turn it off in that case explicitly.)
159 if (c->x86_power & (1 << 8)) {
160 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
161 set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
162 if (!check_tsc_unstable())
163 set_sched_clock_stable();
166 /* Penwell and Cloverview have the TSC which doesn't sleep on S3 */
168 switch (c->x86_model) {
169 case 0x27: /* Penwell */
170 case 0x35: /* Cloverview */
171 case 0x4a: /* Merrifield */
172 set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC_S3);
180 * There is a known erratum on Pentium III and Core Solo
182 * " Page with PAT set to WC while associated MTRR is UC
183 * may consolidate to UC "
184 * Because of this erratum, it is better to stick with
185 * setting WC in MTRR rather than using PAT on these CPUs.
187 * Enable PAT WC only on P4, Core 2 or later CPUs.
189 if (c->x86 == 6 && c->x86_model < 15)
190 clear_cpu_cap(c, X86_FEATURE_PAT);
192 #ifdef CONFIG_KMEMCHECK
194 * P4s have a "fast strings" feature which causes single-
195 * stepping REP instructions to only generate a #DB on
196 * cache-line boundaries.
198 * Ingo Molnar reported a Pentium D (model 6) and a Xeon
199 * (model 2) with the same problem.
202 if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
203 MSR_IA32_MISC_ENABLE_FAST_STRING_BIT) > 0)
204 pr_info("kmemcheck: Disabling fast string operations\n");
208 * If fast string is not enabled in IA32_MISC_ENABLE for any reason,
209 * clear the fast string and enhanced fast string CPU capabilities.
211 if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
212 rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
213 if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) {
214 printk(KERN_INFO "Disabled fast string operations\n");
215 setup_clear_cpu_cap(X86_FEATURE_REP_GOOD);
216 setup_clear_cpu_cap(X86_FEATURE_ERMS);
221 * Intel Quark Core DevMan_001.pdf section 6.4.11
222 * "The operating system also is required to invalidate (i.e., flush)
223 * the TLB when any changes are made to any of the page table entries.
224 * The operating system must reload CR3 to cause the TLB to be flushed"
226 * As a result cpu_has_pge() in arch/x86/include/asm/tlbflush.h should
227 * be false so that __flush_tlb_all() causes CR3 insted of CR4.PGE
230 if (c->x86 == 5 && c->x86_model == 9) {
231 pr_info("Disabling PGE capability bit\n");
232 setup_clear_cpu_cap(X86_FEATURE_PGE);
238 * Early probe support logic for ppro memory erratum #50
240 * This is called before we do cpu ident work
243 int ppro_with_ram_bug(void)
245 /* Uses data from early_cpu_detect now */
246 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
247 boot_cpu_data.x86 == 6 &&
248 boot_cpu_data.x86_model == 1 &&
249 boot_cpu_data.x86_stepping < 8) {
250 pr_info("Pentium Pro with Errata#50 detected. Taking evasive action.\n");
256 static void intel_smp_check(struct cpuinfo_x86 *c)
258 /* calling is from identify_secondary_cpu() ? */
263 * Mask B, Pentium, but not Pentium MMX
266 c->x86_stepping >= 1 && c->x86_stepping <= 4 &&
269 * Remember we have B step Pentia with bugs
271 WARN_ONCE(1, "WARNING: SMP operation may be unreliable"
272 "with B stepping processors.\n");
277 static int __init forcepae_setup(char *__unused)
282 __setup("forcepae", forcepae_setup);
284 static void intel_workarounds(struct cpuinfo_x86 *c)
286 #ifdef CONFIG_X86_F00F_BUG
288 * All models of Pentium and Pentium with MMX technology CPUs
289 * have the F0 0F bug, which lets nonprivileged users lock up the
290 * system. Announce that the fault handler will be checking for it.
291 * The Quark is also family 5, but does not have the same bug.
293 clear_cpu_bug(c, X86_BUG_F00F);
294 if (!paravirt_enabled() && c->x86 == 5 && c->x86_model < 9) {
295 static int f00f_workaround_enabled;
297 set_cpu_bug(c, X86_BUG_F00F);
298 if (!f00f_workaround_enabled) {
299 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
300 f00f_workaround_enabled = 1;
306 * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
309 if ((c->x86<<8 | c->x86_model<<4 | c->x86_stepping) < 0x633)
310 clear_cpu_cap(c, X86_FEATURE_SEP);
313 * PAE CPUID issue: many Pentium M report no PAE but may have a
314 * functionally usable PAE implementation.
315 * Forcefully enable PAE if kernel parameter "forcepae" is present.
318 printk(KERN_WARNING "PAE forced!\n");
319 set_cpu_cap(c, X86_FEATURE_PAE);
320 add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_NOW_UNRELIABLE);
324 * P4 Xeon errata 037 workaround.
325 * Hardware prefetcher may cause stale data to be loaded into the cache.
327 if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_stepping == 1)) {
328 if (msr_set_bit(MSR_IA32_MISC_ENABLE,
329 MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT)
331 pr_info("CPU: C0 stepping P4 Xeon detected.\n");
332 pr_info("CPU: Disabling hardware prefetching (Errata 037)\n");
337 * See if we have a good local APIC by checking for buggy Pentia,
338 * i.e. all B steppings and the C2 stepping of P54C when using their
339 * integrated APIC (see 11AP erratum in "Pentium Processor
340 * Specification Update").
342 if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
343 (c->x86_stepping < 0x6 || c->x86_stepping == 0xb))
344 set_cpu_bug(c, X86_BUG_11AP);
347 #ifdef CONFIG_X86_INTEL_USERCOPY
349 * Set up the preferred alignment for movsl bulk memory moves
352 case 4: /* 486: untested */
354 case 5: /* Old Pentia: untested */
356 case 6: /* PII/PIII only like movsl with 8-byte alignment */
359 case 15: /* P4 is OK down to 8-byte alignment */
368 static void intel_workarounds(struct cpuinfo_x86 *c)
373 static void srat_detect_node(struct cpuinfo_x86 *c)
377 int cpu = smp_processor_id();
379 /* Don't do the funky fallback heuristics the AMD version employs
381 node = numa_cpu_node(cpu);
382 if (node == NUMA_NO_NODE || !node_online(node)) {
383 /* reuse the value from init_cpu_to_node() */
384 node = cpu_to_node(cpu);
386 numa_set_node(cpu, node);
391 * find out the number of processor cores on the die
393 static int intel_num_cpu_cores(struct cpuinfo_x86 *c)
395 unsigned int eax, ebx, ecx, edx;
397 if (c->cpuid_level < 4)
400 /* Intel has a non-standard dependency on %ecx for this CPUID level. */
401 cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
403 return (eax >> 26) + 1;
408 static void detect_vmx_virtcap(struct cpuinfo_x86 *c)
410 /* Intel VMX MSR indicated features */
411 #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
412 #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
413 #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
414 #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
415 #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
416 #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
418 u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
420 clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
421 clear_cpu_cap(c, X86_FEATURE_VNMI);
422 clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
423 clear_cpu_cap(c, X86_FEATURE_EPT);
424 clear_cpu_cap(c, X86_FEATURE_VPID);
426 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
427 msr_ctl = vmx_msr_high | vmx_msr_low;
428 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
429 set_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
430 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
431 set_cpu_cap(c, X86_FEATURE_VNMI);
432 if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
433 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
434 vmx_msr_low, vmx_msr_high);
435 msr_ctl2 = vmx_msr_high | vmx_msr_low;
436 if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
437 (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
438 set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
439 if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
440 set_cpu_cap(c, X86_FEATURE_EPT);
441 if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
442 set_cpu_cap(c, X86_FEATURE_VPID);
446 static void init_intel_energy_perf(struct cpuinfo_x86 *c)
451 * Initialize MSR_IA32_ENERGY_PERF_BIAS if not already initialized.
452 * (x86_energy_perf_policy(8) is available to change it at run-time.)
454 if (!cpu_has(c, X86_FEATURE_EPB))
457 rdmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
458 if ((epb & 0xF) != ENERGY_PERF_BIAS_PERFORMANCE)
461 pr_warn_once("ENERGY_PERF_BIAS: Set to 'normal', was 'performance'\n");
462 pr_warn_once("ENERGY_PERF_BIAS: View and update with x86_energy_perf_policy(8)\n");
463 epb = (epb & ~0xF) | ENERGY_PERF_BIAS_NORMAL;
464 wrmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
467 static void intel_bsp_resume(struct cpuinfo_x86 *c)
470 * MSR_IA32_ENERGY_PERF_BIAS is lost across suspend/resume,
471 * so reinitialize it properly like during bootup:
473 init_intel_energy_perf(c);
476 static void init_intel(struct cpuinfo_x86 *c)
482 intel_workarounds(c);
485 * Detect the extended topology information if available. This
486 * will reinitialise the initial_apicid which will be used
487 * in init_intel_cacheinfo()
489 detect_extended_topology(c);
491 if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
493 * let's use the legacy cpuid vector 0x1 and 0x4 for topology
496 c->x86_max_cores = intel_num_cpu_cores(c);
502 l2 = init_intel_cacheinfo(c);
504 /* Detect legacy cache sizes if init_intel_cacheinfo did not */
506 cpu_detect_cache_sizes(c);
507 l2 = c->x86_cache_size;
510 if (c->cpuid_level > 9) {
511 unsigned eax = cpuid_eax(10);
512 /* Check for version and the number of counters */
513 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
514 set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
518 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
520 if (boot_cpu_has(X86_FEATURE_DS)) {
522 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
524 set_cpu_cap(c, X86_FEATURE_BTS);
526 set_cpu_cap(c, X86_FEATURE_PEBS);
529 if (c->x86 == 6 && cpu_has_clflush &&
530 (c->x86_model == 29 || c->x86_model == 46 || c->x86_model == 47))
531 set_cpu_bug(c, X86_BUG_CLFLUSH_MONITOR);
535 c->x86_cache_alignment = c->x86_clflush_size * 2;
537 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
540 * Names for the Pentium II/Celeron processors
541 * detectable only by also checking the cache size.
542 * Dixon is NOT a Celeron.
547 switch (c->x86_model) {
550 p = "Celeron (Covington)";
552 p = "Mobile Pentium II (Dixon)";
557 p = "Celeron (Mendocino)";
558 else if (c->x86_stepping == 0 || c->x86_stepping == 5)
564 p = "Celeron (Coppermine)";
569 strcpy(c->x86_model_id, p);
573 set_cpu_cap(c, X86_FEATURE_P4);
575 set_cpu_cap(c, X86_FEATURE_P3);
578 /* Work around errata */
581 if (cpu_has(c, X86_FEATURE_VMX))
582 detect_vmx_virtcap(c);
584 init_intel_energy_perf(c);
586 if (tsx_ctrl_state == TSX_CTRL_ENABLE)
588 if (tsx_ctrl_state == TSX_CTRL_DISABLE)
593 static unsigned int intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
596 * Intel PIII Tualatin. This comes in two flavours.
597 * One has 256kb of cache, the other 512. We have no way
598 * to determine which, so we use a boottime override
599 * for the 512kb model, and assume 256 otherwise.
601 if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
605 * Intel Quark SoC X1000 contains a 4-way set associative
606 * 16K cache with a 16 byte cache line and 256 lines per tag
608 if ((c->x86 == 5) && (c->x86_model == 9))
614 #define TLB_INST_4K 0x01
615 #define TLB_INST_4M 0x02
616 #define TLB_INST_2M_4M 0x03
618 #define TLB_INST_ALL 0x05
619 #define TLB_INST_1G 0x06
621 #define TLB_DATA_4K 0x11
622 #define TLB_DATA_4M 0x12
623 #define TLB_DATA_2M_4M 0x13
624 #define TLB_DATA_4K_4M 0x14
626 #define TLB_DATA_1G 0x16
628 #define TLB_DATA0_4K 0x21
629 #define TLB_DATA0_4M 0x22
630 #define TLB_DATA0_2M_4M 0x23
633 #define STLB_4K_2M 0x42
635 static const struct _tlb_table intel_tlb_table[] = {
636 { 0x01, TLB_INST_4K, 32, " TLB_INST 4 KByte pages, 4-way set associative" },
637 { 0x02, TLB_INST_4M, 2, " TLB_INST 4 MByte pages, full associative" },
638 { 0x03, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way set associative" },
639 { 0x04, TLB_DATA_4M, 8, " TLB_DATA 4 MByte pages, 4-way set associative" },
640 { 0x05, TLB_DATA_4M, 32, " TLB_DATA 4 MByte pages, 4-way set associative" },
641 { 0x0b, TLB_INST_4M, 4, " TLB_INST 4 MByte pages, 4-way set associative" },
642 { 0x4f, TLB_INST_4K, 32, " TLB_INST 4 KByte pages */" },
643 { 0x50, TLB_INST_ALL, 64, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
644 { 0x51, TLB_INST_ALL, 128, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
645 { 0x52, TLB_INST_ALL, 256, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
646 { 0x55, TLB_INST_2M_4M, 7, " TLB_INST 2-MByte or 4-MByte pages, fully associative" },
647 { 0x56, TLB_DATA0_4M, 16, " TLB_DATA0 4 MByte pages, 4-way set associative" },
648 { 0x57, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, 4-way associative" },
649 { 0x59, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, fully associative" },
650 { 0x5a, TLB_DATA0_2M_4M, 32, " TLB_DATA0 2-MByte or 4 MByte pages, 4-way set associative" },
651 { 0x5b, TLB_DATA_4K_4M, 64, " TLB_DATA 4 KByte and 4 MByte pages" },
652 { 0x5c, TLB_DATA_4K_4M, 128, " TLB_DATA 4 KByte and 4 MByte pages" },
653 { 0x5d, TLB_DATA_4K_4M, 256, " TLB_DATA 4 KByte and 4 MByte pages" },
654 { 0x61, TLB_INST_4K, 48, " TLB_INST 4 KByte pages, full associative" },
655 { 0x63, TLB_DATA_1G, 4, " TLB_DATA 1 GByte pages, 4-way set associative" },
656 { 0x76, TLB_INST_2M_4M, 8, " TLB_INST 2-MByte or 4-MByte pages, fully associative" },
657 { 0xb0, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 4-way set associative" },
658 { 0xb1, TLB_INST_2M_4M, 4, " TLB_INST 2M pages, 4-way, 8 entries or 4M pages, 4-way entries" },
659 { 0xb2, TLB_INST_4K, 64, " TLB_INST 4KByte pages, 4-way set associative" },
660 { 0xb3, TLB_DATA_4K, 128, " TLB_DATA 4 KByte pages, 4-way set associative" },
661 { 0xb4, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 4-way associative" },
662 { 0xb5, TLB_INST_4K, 64, " TLB_INST 4 KByte pages, 8-way set associative" },
663 { 0xb6, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 8-way set associative" },
664 { 0xba, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way associative" },
665 { 0xc0, TLB_DATA_4K_4M, 8, " TLB_DATA 4 KByte and 4 MByte pages, 4-way associative" },
666 { 0xc1, STLB_4K_2M, 1024, " STLB 4 KByte and 2 MByte pages, 8-way associative" },
667 { 0xc2, TLB_DATA_2M_4M, 16, " DTLB 2 MByte/4MByte pages, 4-way associative" },
668 { 0xca, STLB_4K, 512, " STLB 4 KByte pages, 4-way associative" },
672 static void intel_tlb_lookup(const unsigned char desc)
678 /* look up this descriptor in the table */
679 for (k = 0; intel_tlb_table[k].descriptor != desc && \
680 intel_tlb_table[k].descriptor != 0; k++)
683 if (intel_tlb_table[k].tlb_type == 0)
686 switch (intel_tlb_table[k].tlb_type) {
688 if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
689 tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
690 if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
691 tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
694 if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
695 tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
696 if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
697 tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
698 if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
699 tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
700 if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries)
701 tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries;
702 if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
703 tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
704 if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
705 tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
708 if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
709 tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
710 if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
711 tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
712 if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
713 tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
716 if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
717 tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
720 if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
721 tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
724 if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
725 tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
726 if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
727 tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
731 if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
732 tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
736 if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
737 tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
740 case TLB_DATA0_2M_4M:
741 if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries)
742 tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries;
743 if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
744 tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
747 if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
748 tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
749 if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
750 tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
753 if (tlb_lld_1g[ENTRIES] < intel_tlb_table[k].entries)
754 tlb_lld_1g[ENTRIES] = intel_tlb_table[k].entries;
759 static void intel_detect_tlb(struct cpuinfo_x86 *c)
762 unsigned int regs[4];
763 unsigned char *desc = (unsigned char *)regs;
765 if (c->cpuid_level < 2)
768 /* Number of times to iterate */
769 n = cpuid_eax(2) & 0xFF;
771 for (i = 0 ; i < n ; i++) {
772 cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]);
774 /* If bit 31 is set, this is an unknown format */
775 for (j = 0 ; j < 3 ; j++)
776 if (regs[j] & (1 << 31))
779 /* Byte 0 is level count, not a descriptor */
780 for (j = 1 ; j < 16 ; j++)
781 intel_tlb_lookup(desc[j]);
785 static const struct cpu_dev intel_cpu_dev = {
787 .c_ident = { "GenuineIntel" },
790 { .family = 4, .model_names =
792 [0] = "486 DX-25/33",
803 { .family = 5, .model_names =
805 [0] = "Pentium 60/66 A-step",
806 [1] = "Pentium 60/66",
807 [2] = "Pentium 75 - 200",
808 [3] = "OverDrive PODP5V83",
810 [7] = "Mobile Pentium 75 - 200",
811 [8] = "Mobile Pentium MMX",
812 [9] = "Quark SoC X1000",
815 { .family = 6, .model_names =
817 [0] = "Pentium Pro A-step",
819 [3] = "Pentium II (Klamath)",
820 [4] = "Pentium II (Deschutes)",
821 [5] = "Pentium II (Deschutes)",
822 [6] = "Mobile Pentium II",
823 [7] = "Pentium III (Katmai)",
824 [8] = "Pentium III (Coppermine)",
825 [10] = "Pentium III (Cascades)",
826 [11] = "Pentium III (Tualatin)",
829 { .family = 15, .model_names =
831 [0] = "Pentium 4 (Unknown)",
832 [1] = "Pentium 4 (Willamette)",
833 [2] = "Pentium 4 (Northwood)",
834 [4] = "Pentium 4 (Foster)",
835 [5] = "Pentium 4 (Foster)",
839 .legacy_cache_size = intel_size_cache,
841 .c_detect_tlb = intel_detect_tlb,
842 .c_early_init = early_init_intel,
843 .c_init = init_intel,
844 .c_bsp_resume = intel_bsp_resume,
845 .c_x86_vendor = X86_VENDOR_INTEL,
848 cpu_dev_register(intel_cpu_dev);