From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753207AbdCVUUe (ORCPT ); Wed, 22 Mar 2017 16:20:34 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:41059 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751744AbdCVUS7 (ORCPT ); Wed, 22 Mar 2017 16:18:59 -0400 From: Pavel Tatashin To: x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tglx@linutronix.de, hpa@zytor.com Subject: [v1 3/9] x86/cpu: determining x86 vendor early Date: Wed, 22 Mar 2017 16:24:19 -0400 Message-Id: <1490214265-899964-4-git-send-email-pasha.tatashin@oracle.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1490214265-899964-1-git-send-email-pasha.tatashin@oracle.com> References: <1490214265-899964-1-git-send-email-pasha.tatashin@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/include/asm/processor.h | 1 + arch/x86/kernel/cpu/common.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-) 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.7.1