From 0c60258f5d68b382ce3169ae72f6321402f2393d Mon Sep 17 00:00:00 2001 From: Joursoir Date: Tue, 25 Apr 2023 17:24:57 +0400 Subject: refactor CPUID detection code to use a struct --- cpui-drv.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/cpui-drv.c b/cpui-drv.c index bcb6dba..445dc10 100644 --- a/cpui-drv.c +++ b/cpui-drv.c @@ -2,24 +2,35 @@ #include -static int __init cpui_init(void) +struct cpui_info { + uint32_t cpuid_max; + char vendor_string[13]; +}; + +static struct cpui_info __cpu; + +static void detect_cpu(struct cpui_info *cpu) { - char id_str[13]; - uint32_t eax = 0, ebx, ecx, edx; + /* Get CPU Vendor ID String */ + cpuid(0x00, (unsigned int *)&cpu->cpuid_max, + (unsigned int *)&cpu->vendor_string[0], + (unsigned int *)&cpu->vendor_string[8], + (unsigned int *)&cpu->vendor_string[4]); + cpu->vendor_string[12] = '\0'; +} +static int __init cpui_init(void) +{ if (!have_cpuid_p()) { pr_err("CPUID instruction is NOT supported. Aborting.\n"); return 1; } - - cpuid(0, &eax, &ebx, &ecx, &edx); pr_info("CPUID instruction is supported.\n"); - pr_info("Maximum Input Value for Basic CPUID Information = %d\n", eax); - memcpy(&(id_str[0]), &ebx, 4); - memcpy(&(id_str[4]), &edx, 4); - memcpy(&(id_str[8]), &ecx, 4); - id_str[12] = '\0'; - pr_info("Identity string = %s\n", id_str); + + memset(&__cpu, 0, sizeof(__cpu)); + detect_cpu(&__cpu); + pr_info("Maximum Input Value for Basic CPUID Information = %d\n", __cpu.cpuid_max); + pr_info("Identity string = %s\n", __cpu.vendor_string); return 0; } -- cgit v1.2.3-18-g5258