diff options
| -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;  }  | 
