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.

Dependency Surface

Detected Declarations

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

Implementation Notes