[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250506050437.10264-12-darwi@linutronix.de>
Date: Tue, 6 May 2025 07:04:22 +0200
From: "Ahmed S. Darwish" <darwi@...utronix.de>
To: Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Andrew Cooper <andrew.cooper3@...rix.com>,
"H. Peter Anvin" <hpa@...or.com>,
John Ogness <john.ogness@...utronix.de>,
x86@...nel.org,
x86-cpuid@...ts.linux.dev,
LKML <linux-kernel@...r.kernel.org>,
"Ahmed S. Darwish" <darwi@...utronix.de>
Subject: [PATCH v1 11/26] x86/lib: Add CPUID(0x1) CPU family and model calculation
The x86 library code provides x86_family() and x86_model(). They take
raw CPUID(0x1) EAX register output, extract the necessary bitfields with
bitwise operations, then calculate out the CPU family and model.
In follow-up commits, the x86 code will use scanned CPUID access, along
with its auto-generated <cpuid/leaves.h> CPUID leaf data structures and
their detailed C99 bitfields.
Introduce CPU family and model calculation functions to x86/lib that take
the auto-generated 'struct leaf_0x1_0' data type. Refactor the pure CPU
family and model calculation logic into internal static functions so that
no logic is duplicated.
Signed-off-by: Ahmed S. Darwish <darwi@...utronix.de>
---
arch/x86/include/asm/cpu.h | 6 ++++++
arch/x86/lib/cpu.c | 41 ++++++++++++++++++++++----------------
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index ad235dda1ded..b5685377f583 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -7,7 +7,9 @@
#include <linux/topology.h>
#include <linux/nodemask.h>
#include <linux/percpu.h>
+
#include <asm/ibt.h>
+#include <asm/cpuid/leaves.h>
#ifndef CONFIG_SMP
#define cpu_physical_id(cpu) boot_cpu_physical_apicid
@@ -25,6 +27,10 @@ int mwait_usable(const struct cpuinfo_x86 *);
unsigned int x86_family(unsigned int sig);
unsigned int x86_model(unsigned int sig);
unsigned int x86_stepping(unsigned int sig);
+
+unsigned int cpuid_family(const struct leaf_0x1_0 *l);
+unsigned int cpuid_model(const struct leaf_0x1_0 *l);
+
#ifdef CONFIG_X86_BUS_LOCK_DETECT
extern void __init sld_setup(struct cpuinfo_x86 *c);
extern bool handle_user_split_lock(struct pt_regs *regs, long error_code);
diff --git a/arch/x86/lib/cpu.c b/arch/x86/lib/cpu.c
index 7ad68917a51e..1a6aaa76305a 100644
--- a/arch/x86/lib/cpu.c
+++ b/arch/x86/lib/cpu.c
@@ -1,36 +1,43 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/types.h>
#include <linux/export.h>
+
#include <asm/cpu.h>
+#include <asm/cpuid/leaves.h>
-unsigned int x86_family(unsigned int sig)
+static unsigned int __x86_family(unsigned int base_fam, unsigned int ext_fam)
{
- unsigned int x86;
-
- x86 = (sig >> 8) & 0xf;
+ return (base_fam == 0xf) ? base_fam + ext_fam : base_fam;
+}
- if (x86 == 0xf)
- x86 += (sig >> 20) & 0xff;
+static unsigned int
+__x86_model(unsigned int family, unsigned int base_model, unsigned int ext_model)
+{
+ return (family >= 0x6) ? base_model | ext_model << 4 : base_model;
+}
- return x86;
+unsigned int x86_family(unsigned int sig)
+{
+ return __x86_family((sig >> 8) & 0xf, (sig >> 20) & 0xff);
}
EXPORT_SYMBOL_GPL(x86_family);
-unsigned int x86_model(unsigned int sig)
+unsigned int cpuid_family(const struct leaf_0x1_0 *l)
{
- unsigned int fam, model;
-
- fam = x86_family(sig);
-
- model = (sig >> 4) & 0xf;
-
- if (fam >= 0x6)
- model += ((sig >> 16) & 0xf) << 4;
+ return __x86_family(l->base_family_id, l->ext_family);
+}
- return model;
+unsigned int x86_model(unsigned int sig)
+{
+ return __x86_model(x86_family(sig), (sig >> 4) & 0xf, (sig >> 16) & 0xf);
}
EXPORT_SYMBOL_GPL(x86_model);
+unsigned int cpuid_model(const struct leaf_0x1_0 *l)
+{
+ return __x86_model(cpuid_family(l), l->base_model, l->ext_model);
+}
+
unsigned int x86_stepping(unsigned int sig)
{
return sig & 0xf;
--
2.49.0
Powered by blists - more mailing lists