diff options
author | Joursoir <chat@joursoir.net> | 2023-04-25 17:24:57 +0400 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2023-04-26 13:57:56 +0400 |
commit | 0c60258f5d68b382ce3169ae72f6321402f2393d (patch) | |
tree | 69739e5c4ebd0993dc367e7a06306fe7755cc2cf | |
parent | 21cbc15a690e7c82d778de3eff973084f4198b4e (diff) | |
download | cpui-drv-0c60258f5d68b382ce3169ae72f6321402f2393d.tar.gz cpui-drv-0c60258f5d68b382ce3169ae72f6321402f2393d.tar.bz2 cpui-drv-0c60258f5d68b382ce3169ae72f6321402f2393d.zip |
refactor CPUID detection code to use a struct
-rw-r--r-- | cpui-drv.c | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -2,24 +2,35 @@ #include <linux/module.h> -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; } |