diff options
author | Borislav Petkov <bp@suse.de> | 2015-11-23 05:12:21 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-11-24 03:15:54 -0500 |
commit | 99f925ce927e4ac313d9af8bd1bf55796e2cdcb1 (patch) | |
tree | 51a3708791496f4d60f895e6f07a628a8f7a68e3 | |
parent | 1ec218373b8ebda821aec00bb156a9c94fad9cd4 (diff) |
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>
-rw-r--r-- | arch/x86/include/asm/cpu.h | 3 | ||||
-rw-r--r-- | arch/x86/include/asm/microcode.h | 39 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/common.c | 11 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/microcode/core.c | 12 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/microcode/intel.c | 16 | ||||
-rw-r--r-- | arch/x86/lib/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/lib/cpu.c | 35 |
7 files changed, 61 insertions, 57 deletions
diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index bf2caa1dedc5..678637ad7476 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h | |||
@@ -36,4 +36,7 @@ extern int _debug_hotplug_cpu(int cpu, int action); | |||
36 | 36 | ||
37 | int mwait_usable(const struct cpuinfo_x86 *); | 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 | #endif /* _ASM_X86_CPU_H */ | 42 | #endif /* _ASM_X86_CPU_H */ |
diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h index 34e62b1dcfce..1e1b07a5a738 100644 --- a/arch/x86/include/asm/microcode.h +++ b/arch/x86/include/asm/microcode.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _ASM_X86_MICROCODE_H | 1 | #ifndef _ASM_X86_MICROCODE_H |
2 | #define _ASM_X86_MICROCODE_H | 2 | #define _ASM_X86_MICROCODE_H |
3 | 3 | ||
4 | #include <asm/cpu.h> | ||
4 | #include <linux/earlycpio.h> | 5 | #include <linux/earlycpio.h> |
5 | 6 | ||
6 | #define native_rdmsr(msr, val1, val2) \ | 7 | #define native_rdmsr(msr, val1, val2) \ |
@@ -95,14 +96,14 @@ static inline void __exit exit_amd_microcode(void) {} | |||
95 | 96 | ||
96 | /* | 97 | /* |
97 | * In early loading microcode phase on BSP, boot_cpu_data is not set up yet. | 98 | * In early loading microcode phase on BSP, boot_cpu_data is not set up yet. |
98 | * x86_vendor() gets vendor id for BSP. | 99 | * x86_cpuid_vendor() gets vendor id for BSP. |
99 | * | 100 | * |
100 | * In 32 bit AP case, accessing boot_cpu_data needs linear address. To simplify | 101 | * In 32 bit AP case, accessing boot_cpu_data needs linear address. To simplify |
101 | * coding, we still use x86_vendor() to get vendor id for AP. | 102 | * coding, we still use x86_cpuid_vendor() to get vendor id for AP. |
102 | * | 103 | * |
103 | * x86_vendor() gets vendor information directly from CPUID. | 104 | * x86_cpuid_vendor() gets vendor information directly from CPUID. |
104 | */ | 105 | */ |
105 | static inline int x86_vendor(void) | 106 | static inline int x86_cpuid_vendor(void) |
106 | { | 107 | { |
107 | u32 eax = 0x00000000; | 108 | u32 eax = 0x00000000; |
108 | u32 ebx, ecx = 0, edx; | 109 | u32 ebx, ecx = 0, edx; |
@@ -118,40 +119,14 @@ static inline int x86_vendor(void) | |||
118 | return X86_VENDOR_UNKNOWN; | 119 | return X86_VENDOR_UNKNOWN; |
119 | } | 120 | } |
120 | 121 | ||
121 | static inline unsigned int __x86_family(unsigned int sig) | 122 | static inline unsigned int x86_cpuid_family(void) |
122 | { | ||
123 | unsigned int x86; | ||
124 | |||
125 | x86 = (sig >> 8) & 0xf; | ||
126 | |||
127 | if (x86 == 0xf) | ||
128 | x86 += (sig >> 20) & 0xff; | ||
129 | |||
130 | return x86; | ||
131 | } | ||
132 | |||
133 | static inline unsigned int x86_family(void) | ||
134 | { | 123 | { |
135 | u32 eax = 0x00000001; | 124 | u32 eax = 0x00000001; |
136 | u32 ebx, ecx = 0, edx; | 125 | u32 ebx, ecx = 0, edx; |
137 | 126 | ||
138 | native_cpuid(&eax, &ebx, &ecx, &edx); | 127 | native_cpuid(&eax, &ebx, &ecx, &edx); |
139 | 128 | ||
140 | return __x86_family(eax); | 129 | return x86_family(eax); |
141 | } | ||
142 | |||
143 | static inline unsigned int x86_model(unsigned int sig) | ||
144 | { | ||
145 | unsigned int x86, model; | ||
146 | |||
147 | x86 = __x86_family(sig); | ||
148 | |||
149 | model = (sig >> 4) & 0xf; | ||
150 | |||
151 | if (x86 == 0x6 || x86 == 0xf) | ||
152 | model += ((sig >> 16) & 0xf) << 4; | ||
153 | |||
154 | return model; | ||
155 | } | 130 | } |
156 | 131 | ||
157 | #ifdef CONFIG_MICROCODE | 132 | #ifdef CONFIG_MICROCODE |
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index c2b7522cbf35..0bed416f8c40 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -581,14 +581,9 @@ void cpu_detect(struct cpuinfo_x86 *c) | |||
581 | u32 junk, tfms, cap0, misc; | 581 | u32 junk, tfms, cap0, misc; |
582 | 582 | ||
583 | cpuid(0x00000001, &tfms, &misc, &junk, &cap0); | 583 | cpuid(0x00000001, &tfms, &misc, &junk, &cap0); |
584 | c->x86 = (tfms >> 8) & 0xf; | 584 | c->x86 = x86_family(tfms); |
585 | c->x86_model = (tfms >> 4) & 0xf; | 585 | c->x86_model = x86_model(tfms); |
586 | c->x86_mask = tfms & 0xf; | 586 | c->x86_mask = x86_stepping(tfms); |
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; | ||
592 | 587 | ||
593 | if (cap0 & (1<<19)) { | 588 | if (cap0 & (1<<19)) { |
594 | c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; | 589 | c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; |
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 7fc27f1cca58..3aaffb601c91 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c | |||
@@ -129,8 +129,8 @@ void __init load_ucode_bsp(void) | |||
129 | if (!have_cpuid_p()) | 129 | if (!have_cpuid_p()) |
130 | return; | 130 | return; |
131 | 131 | ||
132 | vendor = x86_vendor(); | 132 | vendor = x86_cpuid_vendor(); |
133 | family = x86_family(); | 133 | family = x86_cpuid_family(); |
134 | 134 | ||
135 | switch (vendor) { | 135 | switch (vendor) { |
136 | case X86_VENDOR_INTEL: | 136 | case X86_VENDOR_INTEL: |
@@ -165,8 +165,8 @@ void load_ucode_ap(void) | |||
165 | if (!have_cpuid_p()) | 165 | if (!have_cpuid_p()) |
166 | return; | 166 | return; |
167 | 167 | ||
168 | vendor = x86_vendor(); | 168 | vendor = x86_cpuid_vendor(); |
169 | family = x86_family(); | 169 | family = x86_cpuid_family(); |
170 | 170 | ||
171 | switch (vendor) { | 171 | switch (vendor) { |
172 | case X86_VENDOR_INTEL: | 172 | case X86_VENDOR_INTEL: |
@@ -206,8 +206,8 @@ void reload_early_microcode(void) | |||
206 | { | 206 | { |
207 | int vendor, family; | 207 | int vendor, family; |
208 | 208 | ||
209 | vendor = x86_vendor(); | 209 | vendor = x86_cpuid_vendor(); |
210 | family = x86_family(); | 210 | family = x86_cpuid_family(); |
211 | 211 | ||
212 | switch (vendor) { | 212 | switch (vendor) { |
213 | case X86_VENDOR_INTEL: | 213 | case X86_VENDOR_INTEL: |
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c index ce47402eb2f9..ee81c544ee0d 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c | |||
@@ -145,10 +145,10 @@ matching_model_microcode(struct microcode_header_intel *mc_header, | |||
145 | int ext_sigcount, i; | 145 | int ext_sigcount, i; |
146 | struct extended_signature *ext_sig; | 146 | struct extended_signature *ext_sig; |
147 | 147 | ||
148 | fam = __x86_family(sig); | 148 | fam = x86_family(sig); |
149 | model = x86_model(sig); | 149 | model = x86_model(sig); |
150 | 150 | ||
151 | fam_ucode = __x86_family(mc_header->sig); | 151 | fam_ucode = x86_family(mc_header->sig); |
152 | model_ucode = x86_model(mc_header->sig); | 152 | model_ucode = x86_model(mc_header->sig); |
153 | 153 | ||
154 | if (fam == fam_ucode && model == model_ucode) | 154 | if (fam == fam_ucode && model == model_ucode) |
@@ -163,7 +163,7 @@ matching_model_microcode(struct microcode_header_intel *mc_header, | |||
163 | ext_sigcount = ext_header->count; | 163 | ext_sigcount = ext_header->count; |
164 | 164 | ||
165 | for (i = 0; i < ext_sigcount; i++) { | 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 | model_ucode = x86_model(ext_sig->sig); | 167 | model_ucode = x86_model(ext_sig->sig); |
168 | 168 | ||
169 | if (fam == fam_ucode && model == model_ucode) | 169 | if (fam == fam_ucode && model == model_ucode) |
@@ -365,7 +365,7 @@ static int collect_cpu_info_early(struct ucode_cpu_info *uci) | |||
365 | native_cpuid(&eax, &ebx, &ecx, &edx); | 365 | native_cpuid(&eax, &ebx, &ecx, &edx); |
366 | csig.sig = eax; | 366 | csig.sig = eax; |
367 | 367 | ||
368 | family = __x86_family(csig.sig); | 368 | family = x86_family(csig.sig); |
369 | model = x86_model(csig.sig); | 369 | model = x86_model(csig.sig); |
370 | 370 | ||
371 | if ((model >= 5) || (family > 6)) { | 371 | if ((model >= 5) || (family > 6)) { |
@@ -521,16 +521,12 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp) | |||
521 | { | 521 | { |
522 | #ifdef CONFIG_X86_64 | 522 | #ifdef CONFIG_X86_64 |
523 | unsigned int eax = 0x00000001, ebx, ecx = 0, edx; | 523 | unsigned int eax = 0x00000001, ebx, ecx = 0, edx; |
524 | unsigned int family, model, stepping; | ||
525 | char name[30]; | 524 | char name[30]; |
526 | 525 | ||
527 | native_cpuid(&eax, &ebx, &ecx, &edx); | 526 | native_cpuid(&eax, &ebx, &ecx, &edx); |
528 | 527 | ||
529 | family = __x86_family(eax); | 528 | sprintf(name, "intel-ucode/%02x-%02x-%02x", |
530 | model = x86_model(eax); | 529 | x86_family(eax), x86_model(eax), x86_stepping(eax)); |
531 | stepping = eax & 0xf; | ||
532 | |||
533 | sprintf(name, "intel-ucode/%02x-%02x-%02x", family, model, stepping); | ||
534 | 530 | ||
535 | return get_builtin_firmware(cp, name); | 531 | return get_builtin_firmware(cp, name); |
536 | #else | 532 | #else |
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index f2587888d987..a501fa25da41 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile | |||
@@ -16,7 +16,7 @@ clean-files := inat-tables.c | |||
16 | 16 | ||
17 | obj-$(CONFIG_SMP) += msr-smp.o cache-smp.o | 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 | lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o | 20 | lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o |
21 | lib-y += memcpy_$(BITS).o | 21 | lib-y += memcpy_$(BITS).o |
22 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | 22 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o |
diff --git a/arch/x86/lib/cpu.c b/arch/x86/lib/cpu.c new file mode 100644 index 000000000000..aa417a97511c --- /dev/null +++ b/arch/x86/lib/cpu.c | |||
@@ -0,0 +1,35 @@ | |||
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); | ||