Files
Ahmed S. Darwish 21834b541d x86/lib: Add CPUID(0x1) family and model calculation
The x86 library provides x86_family() and x86_model().  They take raw
CPUID register output and calculate the CPU family and model from it.

In follow-up work, the x86 subsystem will use APIs which access
previously-parsed CPUID leafs structure instead of doing direct CPUID queries.
These new APIs force using the auto generated leaf data types at
<asm/cpuid/leaf_types.h>.

Introduce x86 family and model calculation functions that take these
auto-generated data types.  Refactor the original code so that no logic is
duplicated.

  [ bp: Massage commit message, unbreak too long line. ]

Signed-off-by: Ahmed S. Darwish <[email protected]>
Signed-off-by: Borislav Petkov (AMD) <[email protected]>
Link: https://patch.msgid.link/[email protected]
2026-07-31 13:57:04 -07:00

52 lines
1.1 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
#include <linux/types.h>
#include <linux/export.h>
#include <asm/cpu.h>
#include <asm/cpuid/leaf_types.h>
static unsigned int __x86_family(unsigned int base_fam, unsigned int ext_fam)
{
if (base_fam == 0xf)
base_fam += ext_fam;
return base_fam;
}
static unsigned int __x86_model(unsigned int family, unsigned int base_model,
unsigned int ext_model)
{
if (family >= 0x6)
base_model |= ext_model << 4;
return base_model;
}
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)
{
return __x86_model(x86_family(sig), (sig >> 4) & 0xf, (sig >> 16) & 0xf);
}
EXPORT_SYMBOL_GPL(x86_model);
unsigned int x86_stepping(unsigned int sig)
{
return sig & 0xf;
}
EXPORT_SYMBOL_GPL(x86_stepping);
unsigned int cpuid_family(const struct leaf_0x1_0 *l)
{
return __x86_family(l->base_family_id, l->ext_family);
}
unsigned int cpuid_model(const struct leaf_0x1_0 *l)
{
return __x86_model(cpuid_family(l), l->base_model, l->ext_model);
}