[PATCH v1 06/12] tools/x86/kcpuid: Extend CPUID index mask macro

From: Ahmed S. Darwish
Date: Thu Mar 06 2025 - 15:52:13 EST


Extend the CPUID index mask macro from 0x80000000 to 0xffff0000. This
accommodates the Centaur-specific indices (0x80860000+) which will be
later added.

Note that this also automatically sets CPUID_FUNCTION_MASK to 0x0000ffff,
which is the actual correct value. Use it instead of the 0xffff literal
where appropriate.

Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
---
tools/arch/x86/kcpuid/kcpuid.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 6f6a394486af..6a4c845bc1de 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -70,7 +70,7 @@ enum range_index {
RANGE_EXT = 0x80000000, /* Extended */
};

-#define CPUID_INDEX_MASK 0x80000000
+#define CPUID_INDEX_MASK 0xffff0000
#define CPUID_FUNCTION_MASK (~CPUID_INDEX_MASK)

struct cpuid_range {
@@ -174,7 +174,7 @@ static bool cpuid_store(struct cpuid_range *range, u32 f, int subleaf,
* Cut off vendor-prefix from CPUID function as we're using it as an
* index into ->funcs.
*/
- func = &range->funcs[f & 0xffff];
+ func = &range->funcs[f & CPUID_FUNCTION_MASK];

if (!func->leafs) {
func->leafs = malloc(sizeof(struct subleaf));
@@ -236,7 +236,7 @@ void setup_cpuid_range(struct cpuid_range *range)

cpuid(&eax, &ebx, &ecx, &edx);
max_func = eax;
- idx_func = (max_func & 0xffff) + 1;
+ idx_func = (max_func & CPUID_FUNCTION_MASK) + 1;

range->funcs = malloc(sizeof(struct cpuid_func) * idx_func);
if (!range->funcs)
@@ -546,7 +546,7 @@ static inline struct cpuid_func *index_to_func(u32 index)
if (!range)
return NULL;

- func_idx = index & 0xffff;
+ func_idx = index & CPUID_FUNCTION_MASK;
if ((func_idx + 1) > (u32)range->nr) {
warnx("Invalid input index (0x%x)", index);
return NULL;
--
2.48.1