gila/src/kernel/device/mod.rs

64 lines
1.7 KiB
Rust

// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later
mod acpi;
use fdt::*;
use lazy_static::lazy_static;
use limine::response::{DeviceTreeBlobResponse, RsdpResponse};
use raw_cpuid::native_cpuid::CpuIdReaderNative;
use raw_cpuid::*;
use crate::boot::{DTB_REQUEST, RSDP_REQUEST};
use crate::log::{LOGGER, LogLevel};
use crate::{format, log_info, log_trace, log_warning};
pub fn log_cpuid() {
let cpuid: CpuId<CpuIdReaderNative> = CpuId::with_cpuid_reader(CpuIdReaderNative);
log_trace!(
"Device: CPU vendor: {}",
cpuid.get_processor_brand_string().unwrap().as_str()
)
}
lazy_static! {
pub static ref DTB: Option<&'static DeviceTreeBlobResponse> = match DTB_REQUEST.get_response() {
Some(resp) => {
log_info!("Device: Got DTB pointer");
Some(resp)
}
None => {
log_warning!("Device: Did not get DTB pointer");
None
}
};
pub static ref RSDP: Option<&'static RsdpResponse> = match RSDP_REQUEST.get_response() {
Some(resp) => {
log_info!("Device: Got RSDP pointer");
Some(resp)
}
None => {
log_warning!("Device: Did not get RSDP pointer, ACPI unavailable");
None
}
};
}
// Just to check
pub fn init_statics() {
let _ = DTB.is_some();
let _ = RSDP.is_some();
}
#[allow(dead_code)]
pub fn device_tree_parsed() -> Option<Fdt<'static>> {
if let Some(ok_dtb) = *DTB
&& let Ok(ok_parsed_dt) = unsafe { fdt::Fdt::from_ptr(ok_dtb.dtb_ptr() as *const u8) }
{
log_trace!("Device: Parsed device tree");
Some(ok_parsed_dt)
} else {
None
}
}