forked from AbleOS/ableos
68 lines
1.9 KiB
Rust
68 lines
1.9 KiB
Rust
use {
|
|
crate::{
|
|
arch::{pci, x86_64::cpuid},
|
|
device_tree::DeviceTree,
|
|
kmain::DEVICE_TREE,
|
|
},
|
|
limine::SmpRequest,
|
|
xml::XMLElement,
|
|
};
|
|
|
|
fn collect_cpu_info(device_tree: &mut DeviceTree) {
|
|
use crate::alloc::string::ToString;
|
|
|
|
static SMP: SmpRequest = SmpRequest::new(0);
|
|
let smp_response = SMP.get_response().get().unwrap();
|
|
|
|
let mut cpu = XMLElement::new("cpu");
|
|
|
|
// Get the amount of cores on the CPU
|
|
let core_count = smp_response.cpu_count.to_string();
|
|
cpu.set_attribute("core count", core_count);
|
|
for x in 0..smp_response.cpu_count {
|
|
let core_name = alloc::format!("core_{}", x);
|
|
let core = XMLElement::new(core_name);
|
|
cpu.set_child(core);
|
|
}
|
|
|
|
let cpu_info = cpuid::master().unwrap();
|
|
|
|
let brand_string = cpu_info.brand_string().unwrap_or("Unknown").to_string();
|
|
cpu.set_attribute("brand string", brand_string);
|
|
|
|
cpu.set_attribute("speed", "unknown");
|
|
|
|
// Get CPU features and add them to the device tree entry.
|
|
let mut cpu_features = XMLElement::new("CPU Features");
|
|
for (feature_key, feature_enabled) in cpu_info.features() {
|
|
cpu_features.set_attribute(feature_key, feature_enabled.to_string());
|
|
}
|
|
cpu.set_child(cpu_features);
|
|
|
|
// CPU temperature
|
|
if cpu_info.digital_temperature_sensor() {
|
|
let mut temperature_child = XMLElement::new("Temperature");
|
|
|
|
temperature_child.set_attribute("degrees", "Unknown");
|
|
cpu.set_child(temperature_child);
|
|
}
|
|
|
|
// Add CPU to device tree
|
|
let cpus = device_tree.devices.get_mut("CPUs").unwrap();
|
|
cpus.push(cpu);
|
|
}
|
|
|
|
pub fn collect_device_info() {
|
|
// Lock device tree
|
|
unsafe {
|
|
DEVICE_TREE.force_unlock();
|
|
}
|
|
let device_tree = &mut DEVICE_TREE.lock();
|
|
|
|
// Generate device tree from PCI enumeration.
|
|
pci::init(device_tree);
|
|
|
|
// Collect CPU info and add it to the device tree
|
|
collect_cpu_info(device_tree);
|
|
}
|