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 /arch/x86/include | |
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>
Diffstat (limited to 'arch/x86/include')
-rw-r--r-- | arch/x86/include/asm/cpu.h | 3 | ||||
-rw-r--r-- | arch/x86/include/asm/microcode.h | 39 |
2 files changed, 10 insertions, 32 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 |