Initialize ACPI module at boot time (#583)

This commit is contained in:
Vincent Ollivier 2024-02-24 10:09:20 +01:00 committed by GitHub
parent e06d068f9f
commit aff91aefcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 15 deletions

View File

@ -34,6 +34,7 @@ pub fn init(boot_info: &'static BootInfo) {
log!("MOROS v{}", v);
sys::mem::init(boot_info);
sys::acpi::init(); // Require MEM
sys::cpu::init();
sys::pci::init(); // Require MEM
sys::net::init(); // Require PCI

View File

@ -8,23 +8,19 @@ use core::ptr::NonNull;
use x86_64::instructions::port::Port;
use x86_64::PhysAddr;
fn read_addr<T>(addr: usize) -> T where T: Copy {
let virtual_address = sys::mem::phys_to_virt(PhysAddr::new(addr as u64));
unsafe { *virtual_address.as_ptr::<T>() }
}
static mut PM1A_CNT_BLK: u32 = 0;
static mut SLP_TYPA: u16 = 0;
static SLP_LEN: u16 = 1 << 13;
pub fn shutdown() {
let mut pm1a_control_block = 0;
let mut slp_typa = 0;
let slp_len = 1 << 13;
log!("ACPI Shutdown");
pub fn init() {
let res = unsafe { AcpiTables::search_for_rsdp_bios(MorosAcpiHandler) };
match res {
Ok(acpi) => {
if let Ok(fadt) = acpi.find_table::<acpi::fadt::Fadt>() {
if let Ok(block) = fadt.pm1a_control_block() {
pm1a_control_block = block.address as u32;
unsafe {
PM1A_CNT_BLK = block.address as u32;
}
}
}
if let Ok(dsdt) = &acpi.dsdt() {
@ -41,7 +37,9 @@ pub fn shutdown() {
let res = aml.namespace.get_by_path(&name);
if let Ok(AmlValue::Package(s5)) = res {
if let AmlValue::Integer(value) = s5[0] {
slp_typa = value as u16;
unsafe {
SLP_TYPA = value as u16;
}
}
}
} else {
@ -49,7 +47,9 @@ pub fn shutdown() {
// FIXME: AML parsing works on QEMU and Bochs but not
// on VirtualBox at the moment, so we use the following
// hardcoded value:
slp_typa = (5 & 7) << 10;
unsafe {
SLP_TYPA = (5 & 7) << 10;
}
}
} else {
debug!("ACPI: Could not find DSDT in BIOS");
@ -59,10 +59,13 @@ pub fn shutdown() {
debug!("ACPI: Could not find RDSP in BIOS");
}
};
}
let mut port: Port<u16> = Port::new(pm1a_control_block as u16);
pub fn shutdown() {
log!("ACPI Shutdown");
unsafe {
port.write(slp_typa | slp_len);
let mut port: Port<u16> = Port::new(PM1A_CNT_BLK as u16);
port.write(SLP_TYPA | SLP_LEN);
}
}
@ -149,3 +152,8 @@ impl Handler for MorosAmlHandler {
unimplemented!()
}
}
fn read_addr<T>(addr: usize) -> T where T: Copy {
let virtual_address = sys::mem::phys_to_virt(PhysAddr::new(addr as u64));
unsafe { *virtual_address.as_ptr::<T>() }
}