Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/cpu: Unify CPU family, model, stepping calculation

Add generic functions which calc family, model and stepping from
the CPUID_1.EAX leaf and stick them into the library we have.

Rename those which do call CPUID with the prefix "x86_cpuid" as
suggested by Paolo Bonzini.

No functionality change.

Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1448273546-2567-2-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Borislav Petkov and committed by
Ingo Molnar
99f925ce 1ec21837

+61 -57
+3
arch/x86/include/asm/cpu.h
··· 36 36 37 37 int mwait_usable(const struct cpuinfo_x86 *); 38 38 39 + unsigned int x86_family(unsigned int sig); 40 + unsigned int x86_model(unsigned int sig); 41 + unsigned int x86_stepping(unsigned int sig); 39 42 #endif /* _ASM_X86_CPU_H */
+7 -32
arch/x86/include/asm/microcode.h
··· 1 1 #ifndef _ASM_X86_MICROCODE_H 2 2 #define _ASM_X86_MICROCODE_H 3 3 4 + #include <asm/cpu.h> 4 5 #include <linux/earlycpio.h> 5 6 6 7 #define native_rdmsr(msr, val1, val2) \ ··· 96 95 97 96 /* 98 97 * In early loading microcode phase on BSP, boot_cpu_data is not set up yet. 99 - * x86_vendor() gets vendor id for BSP. 98 + * x86_cpuid_vendor() gets vendor id for BSP. 100 99 * 101 100 * In 32 bit AP case, accessing boot_cpu_data needs linear address. To simplify 102 - * coding, we still use x86_vendor() to get vendor id for AP. 101 + * coding, we still use x86_cpuid_vendor() to get vendor id for AP. 103 102 * 104 - * x86_vendor() gets vendor information directly from CPUID. 103 + * x86_cpuid_vendor() gets vendor information directly from CPUID. 105 104 */ 106 - static inline int x86_vendor(void) 105 + static inline int x86_cpuid_vendor(void) 107 106 { 108 107 u32 eax = 0x00000000; 109 108 u32 ebx, ecx = 0, edx; ··· 119 118 return X86_VENDOR_UNKNOWN; 120 119 } 121 120 122 - static inline unsigned int __x86_family(unsigned int sig) 123 - { 124 - unsigned int x86; 125 - 126 - x86 = (sig >> 8) & 0xf; 127 - 128 - if (x86 == 0xf) 129 - x86 += (sig >> 20) & 0xff; 130 - 131 - return x86; 132 - } 133 - 134 - static inline unsigned int x86_family(void) 121 + static inline unsigned int x86_cpuid_family(void) 135 122 { 136 123 u32 eax = 0x00000001; 137 124 u32 ebx, ecx = 0, edx; 138 125 139 126 native_cpuid(&eax, &ebx, &ecx, &edx); 140 127 141 - return __x86_family(eax); 142 - } 143 - 144 - static inline unsigned int x86_model(unsigned int sig) 145 - { 146 - unsigned int x86, model; 147 - 148 - x86 = __x86_family(sig); 149 - 150 - model = (sig >> 4) & 0xf; 151 - 152 - if (x86 == 0x6 || x86 == 0xf) 153 - model += ((sig >> 16) & 0xf) << 4; 154 - 155 - return model; 128 + return x86_family(eax); 156 129 } 157 130 158 131 #ifdef CONFIG_MICROCODE
+3 -8
arch/x86/kernel/cpu/common.c
··· 581 581 u32 junk, tfms, cap0, misc; 582 582 583 583 cpuid(0x00000001, &tfms, &misc, &junk, &cap0); 584 - c->x86 = (tfms >> 8) & 0xf; 585 - c->x86_model = (tfms >> 4) & 0xf; 586 - c->x86_mask = tfms & 0xf; 587 - 588 - if (c->x86 == 0xf) 589 - c->x86 += (tfms >> 20) & 0xff; 590 - if (c->x86 >= 0x6) 591 - c->x86_model += ((tfms >> 16) & 0xf) << 4; 584 + c->x86 = x86_family(tfms); 585 + c->x86_model = x86_model(tfms); 586 + c->x86_mask = x86_stepping(tfms); 592 587 593 588 if (cap0 & (1<<19)) { 594 589 c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
+6 -6
arch/x86/kernel/cpu/microcode/core.c
··· 129 129 if (!have_cpuid_p()) 130 130 return; 131 131 132 - vendor = x86_vendor(); 133 - family = x86_family(); 132 + vendor = x86_cpuid_vendor(); 133 + family = x86_cpuid_family(); 134 134 135 135 switch (vendor) { 136 136 case X86_VENDOR_INTEL: ··· 165 165 if (!have_cpuid_p()) 166 166 return; 167 167 168 - vendor = x86_vendor(); 169 - family = x86_family(); 168 + vendor = x86_cpuid_vendor(); 169 + family = x86_cpuid_family(); 170 170 171 171 switch (vendor) { 172 172 case X86_VENDOR_INTEL: ··· 206 206 { 207 207 int vendor, family; 208 208 209 - vendor = x86_vendor(); 210 - family = x86_family(); 209 + vendor = x86_cpuid_vendor(); 210 + family = x86_cpuid_family(); 211 211 212 212 switch (vendor) { 213 213 case X86_VENDOR_INTEL:
+6 -10
arch/x86/kernel/cpu/microcode/intel.c
··· 145 145 int ext_sigcount, i; 146 146 struct extended_signature *ext_sig; 147 147 148 - fam = __x86_family(sig); 148 + fam = x86_family(sig); 149 149 model = x86_model(sig); 150 150 151 - fam_ucode = __x86_family(mc_header->sig); 151 + fam_ucode = x86_family(mc_header->sig); 152 152 model_ucode = x86_model(mc_header->sig); 153 153 154 154 if (fam == fam_ucode && model == model_ucode) ··· 163 163 ext_sigcount = ext_header->count; 164 164 165 165 for (i = 0; i < ext_sigcount; i++) { 166 - fam_ucode = __x86_family(ext_sig->sig); 166 + fam_ucode = x86_family(ext_sig->sig); 167 167 model_ucode = x86_model(ext_sig->sig); 168 168 169 169 if (fam == fam_ucode && model == model_ucode) ··· 365 365 native_cpuid(&eax, &ebx, &ecx, &edx); 366 366 csig.sig = eax; 367 367 368 - family = __x86_family(csig.sig); 368 + family = x86_family(csig.sig); 369 369 model = x86_model(csig.sig); 370 370 371 371 if ((model >= 5) || (family > 6)) { ··· 521 521 { 522 522 #ifdef CONFIG_X86_64 523 523 unsigned int eax = 0x00000001, ebx, ecx = 0, edx; 524 - unsigned int family, model, stepping; 525 524 char name[30]; 526 525 527 526 native_cpuid(&eax, &ebx, &ecx, &edx); 528 527 529 - family = __x86_family(eax); 530 - model = x86_model(eax); 531 - stepping = eax & 0xf; 532 - 533 - sprintf(name, "intel-ucode/%02x-%02x-%02x", family, model, stepping); 528 + sprintf(name, "intel-ucode/%02x-%02x-%02x", 529 + x86_family(eax), x86_model(eax), x86_stepping(eax)); 534 530 535 531 return get_builtin_firmware(cp, name); 536 532 #else
+1 -1
arch/x86/lib/Makefile
··· 16 16 17 17 obj-$(CONFIG_SMP) += msr-smp.o cache-smp.o 18 18 19 - lib-y := delay.o misc.o cmdline.o 19 + lib-y := delay.o misc.o cmdline.o cpu.o 20 20 lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o 21 21 lib-y += memcpy_$(BITS).o 22 22 lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
+35
arch/x86/lib/cpu.c
··· 1 + #include <linux/module.h> 2 + 3 + unsigned int x86_family(unsigned int sig) 4 + { 5 + unsigned int x86; 6 + 7 + x86 = (sig >> 8) & 0xf; 8 + 9 + if (x86 == 0xf) 10 + x86 += (sig >> 20) & 0xff; 11 + 12 + return x86; 13 + } 14 + EXPORT_SYMBOL_GPL(x86_family); 15 + 16 + unsigned int x86_model(unsigned int sig) 17 + { 18 + unsigned int fam, model; 19 + 20 + fam = x86_family(sig); 21 + 22 + model = (sig >> 4) & 0xf; 23 + 24 + if (fam >= 0x6) 25 + model += ((sig >> 16) & 0xf) << 4; 26 + 27 + return model; 28 + } 29 + EXPORT_SYMBOL_GPL(x86_model); 30 + 31 + unsigned int x86_stepping(unsigned int sig) 32 + { 33 + return sig & 0xf; 34 + } 35 + EXPORT_SYMBOL_GPL(x86_stepping);