tools/arch/x86/kcpuid/kcpuid.c
Source file repositories/reference/linux-study-clean/tools/arch/x86/kcpuid/kcpuid.c
File Facts
- System
- Linux kernel
- Corpus path
tools/arch/x86/kcpuid/kcpuid.c- Extension
.c- Size
- 15334 bytes
- Lines
- 669
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
cpuid.herr.hgetopt.hstdbool.hstdio.hstdlib.hstring.h
Detected Declarations
struct bits_descstruct reg_descstruct subleafstruct cpuid_funcstruct cpuid_rangeenum cpuid_regenum range_indexfunction for_each_valid_cpuid_rangefunction has_subleafsfunction leaf_print_rawfunction cpuid_storefunction raw_dump_rangefunction setup_cpuid_rangefunction for_each_valid_cpu_rangefunction parse_linefunction parse_textfunction show_regfunction show_reg_headerfunction show_leaffunction show_funcfunction show_rangefunction show_infofunction usagefunction parse_optionsfunction main
Annotated Snippet
struct bits_desc {
/* start and end bits */
int start, end;
/* 0 or 1 for 1-bit flag */
int value;
char simp[32];
char detail[256];
};
/* descriptor info for eax/ebx/ecx/edx */
struct reg_desc {
/* number of valid entries */
int nr;
struct bits_desc descs[32];
};
enum cpuid_reg {
R_EAX = 0,
R_EBX,
R_ECX,
R_EDX,
NR_REGS
};
static const char * const reg_names[] = {
"EAX", "EBX", "ECX", "EDX",
};
struct subleaf {
u32 index;
u32 sub;
u32 output[NR_REGS];
struct reg_desc info[NR_REGS];
};
/* Represent one leaf (basic or extended) */
struct cpuid_func {
/*
* Array of subleafs for this func, if there is no subleafs
* then the leafs[0] is the main leaf
*/
struct subleaf *leafs;
int nr;
};
enum range_index {
RANGE_STD = 0, /* Standard */
RANGE_EXT = 0x80000000, /* Extended */
RANGE_TSM = 0x80860000, /* Transmeta */
RANGE_CTR = 0xc0000000, /* Centaur/Zhaoxin */
};
#define CPUID_INDEX_MASK 0xffff0000
#define CPUID_FUNCTION_MASK (~CPUID_INDEX_MASK)
struct cpuid_range {
/* array of main leafs */
struct cpuid_func *funcs;
/* number of valid leafs */
int nr;
enum range_index index;
};
static struct cpuid_range ranges[] = {
{ .index = RANGE_STD, },
{ .index = RANGE_EXT, },
{ .index = RANGE_TSM, },
{ .index = RANGE_CTR, },
};
static char *range_to_str(struct cpuid_range *range)
{
switch (range->index) {
case RANGE_STD: return "Standard";
case RANGE_EXT: return "Extended";
case RANGE_TSM: return "Transmeta";
case RANGE_CTR: return "Centaur";
default: return NULL;
}
}
#define __for_each_cpuid_range(range, __condition) \
for (unsigned int i = 0; \
i < ARRAY_SIZE(ranges) && ((range) = &ranges[i]) && (__condition); \
i++)
#define for_each_valid_cpuid_range(range) __for_each_cpuid_range(range, (range)->nr != 0)
#define for_each_cpuid_range(range) __for_each_cpuid_range(range, true)
struct cpuid_range *index_to_cpuid_range(u32 index)
Annotation
- Immediate include surface: `cpuid.h`, `err.h`, `getopt.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`.
- Detected declarations: `struct bits_desc`, `struct reg_desc`, `struct subleaf`, `struct cpuid_func`, `struct cpuid_range`, `enum cpuid_reg`, `enum range_index`, `function for_each_valid_cpuid_range`, `function has_subleafs`, `function leaf_print_raw`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.