[PATCH v5 31/35] x86/cacheinfo: Use parsed CPUID(0x80000006)
"Ahmed S. Darwish" <[email protected]> Fri, 5 Sep 2025 14:15:11 +0200
| Newsgroups | dev.linux.lists.x86-cpuid,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
For the AMD cacheinfo logic, use parsed CPUID(0x80000006) access instead of a direct CPUID query. Beside the CPUID parser centralization benefits, this allows using the auto-generated <asm/cpuid/leaf_types.h> data types, and their full C99 bitfields, instead of doing ugly bitwise operations on CPUID register output. For testing L3 cache availability, just check if CPUID(0x80000006) EDX l3_assoc output is not zero. Per AMD manuals, an L3 associativity of zero implies the absence of an L3 cache on the CPU. Since cpuid_amd_hygon_has_l3_cache() is now using the CPUID parser API, move its definition under the header file section: "Convenience leaf specific functions (using parsed CPUID data)" Signed-off-by: Ahmed S. Darwish <[email protected]> --- arch/x86/include/asm/cpuid/api.h | 18 +++++++++--------- arch/x86/kernel/amd_nb.c | 3 ++- arch/x86/kernel/cpu/cacheinfo.c | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/api.h index 2989a0c83ab0..c8efbd013504 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -213,15 +213,6 @@ static inline u32 cpuid_base_hypervisor(const char *sig, u32 leaves) return 0; } -/* - * CPUID(0x80000006) parsing: - */ - -static inline bool cpuid_amd_hygon_has_l3_cache(void) -{ - return cpuid_edx(0x80000006); -} - /* * 'struct cpuid_leaves' accessors (without sanity checks): * @@ -538,6 +529,15 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) _ptr < &((union leaf_0x2_regs *)(_regs))->desc[16] && (_desc = &cpuid_0x2_table[*_ptr]);\ _ptr++) +/* + * CPUID(0x80000006) + */ + +static inline bool cpuid_amd_hygon_has_l3_cache(struct cpuinfo_x86 *c) +{ + return cpuid_leaf(c, 0x80000006)->l3_assoc; +} + /* * CPUID parser exported APIs: */ diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index c1acead6227a..04a1965f10fe 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -16,6 +16,7 @@ #include <asm/amd/nb.h> #include <asm/cpuid/api.h> +#include <asm/processor.h> static u32 *flush_words; @@ -93,7 +94,7 @@ static int amd_cache_northbridges(void) if (amd_gart_present()) amd_northbridges.flags |= AMD_NB_GART; - if (!cpuid_amd_hygon_has_l3_cache()) + if (!cpuid_amd_hygon_has_l3_cache(&boot_cpu_data)) return 0; /* diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index 7033baa94276..c5c6b0740e0d 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -235,7 +235,7 @@ static unsigned int get_cache_id(u32 apicid, const struct _cpuid4_info *id4) void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) { - if (!cpuid_amd_hygon_has_l3_cache()) + if (!cpuid_amd_hygon_has_l3_cache(c)) return; if (c->x86 < 0x17) { @@ -262,7 +262,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) { - if (!cpuid_amd_hygon_has_l3_cache()) + if (!cpuid_amd_hygon_has_l3_cache(c)) return; /* @@ -278,7 +278,7 @@ void init_amd_cacheinfo(struct cpuinfo_x86 *c) ci->num_leaves = boot_cpu_has(X86_FEATURE_TOPOEXT) ? cpuid_subleaf_count(c, 0x8000001d) : - cpuid_leaf(c, 0x80000006)->l3_assoc ? 4 : 3; + cpuid_amd_hygon_has_l3_cache(c) ? 4 : 3; } void init_hygon_cacheinfo(struct cpuinfo_x86 *c) -- 2.50.1