[v2 3/9] x86/cpu: determining x86 vendor early

From: Pavel Tatashin
Date: Fri Mar 24 2017 - 11:25:57 EST


In order to support early time stamps we must know the vendor id of the
chip early in boot. This patch implements it by getting vendor string from
cpuid, and comparing it against the known to Linux x86 vendors.

Signed-off-by: Pavel Tatashin <pasha.tatashin@xxxxxxxxxx>
---
arch/x86/include/asm/processor.h | 1 +
arch/x86/kernel/cpu/common.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index f385eca..a4128d1 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -184,6 +184,7 @@ enum cpuid_regs_idx {

extern void cpu_detect(struct cpuinfo_x86 *c);

+int get_x86_vendor_early(void);
extern void early_cpu_init(void);
extern void identify_boot_cpu(void);
extern void identify_secondary_cpu(struct cpuinfo_x86 *);
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 58094a1..9c02851 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -847,6 +847,42 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
fpu__init_system(c);
}

+/*
+ * Returns x86_vendor early, before other platform data structures being
+ * initialized.
+ */
+int get_x86_vendor_early(void)
+{
+ int x86_vendor = X86_VENDOR_UNKNOWN;
+ const struct cpu_dev *const *cdev;
+ char vendor_str[16];
+ int count = 0;
+
+ cpuid(0, (unsigned int *)&vendor_str[12],
+ (unsigned int *)&vendor_str[0],
+ (unsigned int *)&vendor_str[8],
+ (unsigned int *)&vendor_str[4]);
+ vendor_str[12] = '\0';
+
+ for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) {
+ const struct cpu_dev *cpudev = *cdev;
+ const char *str1 = cpudev->c_ident[0];
+ const char *str2 = cpudev->c_ident[1];
+
+ if (count == X86_VENDOR_NUM)
+ break;
+
+ if ((!strcmp(vendor_str, str1)) ||
+ (str2 && !strcmp(vendor_str, str2))) {
+ x86_vendor = cpudev->c_x86_vendor;
+ break;
+ }
+ count++;
+ }
+
+ return x86_vendor;
+}
+
void __init early_cpu_init(void)
{
const struct cpu_dev *const *cdev;
--
1.8.3.1