spi/amd64: cpu: Get processor model + family ID
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <mu/cpu.h>
|
||||
#include <lib/printf.h>
|
||||
#include <machine/cpuid.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define pr_trace(fmt, ...) \
|
||||
@@ -24,18 +25,50 @@ extern void md_cpu_init(void);
|
||||
* processor on early startup
|
||||
*/
|
||||
static void
|
||||
cpu_print_info(void)
|
||||
cpu_print_info(struct cpu_info *ci)
|
||||
{
|
||||
static bool once = false;
|
||||
struct mcb *mcb;
|
||||
|
||||
if (once) {
|
||||
if (once || ci == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcb = &ci->mcb;
|
||||
pr_trace("pg.nx : yes\n");
|
||||
pr_trace("cpu.model : %x\n", mcb->model_id);
|
||||
pr_trace("cpu.family : %x\n", mcb->family_id);
|
||||
once = true;
|
||||
}
|
||||
|
||||
static void
|
||||
cpu_get_info(struct cpu_info *ci)
|
||||
{
|
||||
struct mcb *mcb;
|
||||
uint32_t eax, unused;
|
||||
uint8_t model_low, model_high;
|
||||
uint8_t family_low, family_high;
|
||||
|
||||
if (ci == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcb = &ci->mcb;
|
||||
|
||||
/* Get processor info and feature bits */
|
||||
__cpuid(0x01, eax, unused, unused, unused);
|
||||
|
||||
/* Obtain the model ID */
|
||||
model_low = (eax >> 4) & 0xF;
|
||||
model_high = (eax >> 16) & 0xF;
|
||||
mcb->model_id = (model_high << 4) | model_low;
|
||||
|
||||
/* Obtain the family ID */
|
||||
family_low = (eax >> 8) & 0xF;
|
||||
family_high = (eax >> 20) & 0xFF;
|
||||
mcb->family_id = (family_high << 4) | family_low;
|
||||
}
|
||||
|
||||
void
|
||||
mu_cpu_preinit(struct cpu_info *ci)
|
||||
{
|
||||
@@ -49,6 +82,9 @@ mu_cpu_preinit(struct cpu_info *ci)
|
||||
/* Initialize control registers and such */
|
||||
md_cpu_init();
|
||||
|
||||
/* Obtain some processor information */
|
||||
cpu_get_info(ci);
|
||||
|
||||
/* Log out some information */
|
||||
cpu_print_info();
|
||||
cpu_print_info(ci);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Mirocom Laboratories
|
||||
* All rights reserved.
|
||||
*
|
||||
* The following sources are CONFIDENTIAL and PROPRIETARY
|
||||
* property of Mirocom Laboratories. Unauthorized copying,
|
||||
* use, distribution or modification of this file, in whole
|
||||
* and in part, is strictly prohibited without the prior written
|
||||
* consent from Mirocom Laboratories.
|
||||
*/
|
||||
|
||||
#ifndef _MACHINE_MCB_H_
|
||||
#define _MACHINE_MCB_H_ 1
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* The machine core block contains MD processor
|
||||
* specific information
|
||||
*
|
||||
* @model_id: Processor model ID
|
||||
* @family_id: Processor family ID
|
||||
*/
|
||||
struct mcb {
|
||||
uint8_t model_id;
|
||||
uint16_t family_id : 12;
|
||||
};
|
||||
|
||||
#endif /* !_MACHINE_MCB_H_ */
|
||||
@@ -13,14 +13,17 @@
|
||||
#define _MU_CPU_H_ 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/mcb.h> /* shared */
|
||||
|
||||
/*
|
||||
* MI processor specific information
|
||||
*
|
||||
* @id: Processor ID
|
||||
* @mcb: Machine core block
|
||||
*/
|
||||
struct cpu_info {
|
||||
uint8_t id;
|
||||
struct mcb mcb;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user