Skip to content

Commit 44327d4

Browse files
aml: subsystem
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 8adba95 commit 44327d4

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

src/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aero_kernel/src/acpi/aml.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use alloc::sync::Arc;
2+
use spin::Once;
3+
4+
/// ## Reference
5+
/// * [ACPI Sleeping States](https://uefi.org/specs/ACPI/6.4/16_Waking_and_Sleeping/sleeping-states.html)
6+
#[repr(u8)]
7+
pub enum SleepState {
8+
S5 = 5,
9+
}
10+
11+
pub trait AmlSubsystem: Send + Sync {
12+
fn enter_state(&self, state: SleepState);
13+
}
14+
15+
static AML_SUBSYSTEM: Once<Arc<dyn AmlSubsystem>> = Once::new();
16+
17+
pub fn get_subsystem() -> Arc<dyn AmlSubsystem> {
18+
AML_SUBSYSTEM.get().unwrap().clone()
19+
}
20+
21+
pub fn init(subsystem: Arc<dyn AmlSubsystem>) {
22+
assert!(
23+
AML_SUBSYSTEM.get().is_none(),
24+
"aml: subsystem already initialized"
25+
);
26+
27+
AML_SUBSYSTEM.call_once(|| subsystem);
28+
log::debug!("aml: subsystem initialized");
29+
}

src/aero_kernel/src/acpi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::{
3131

3232
use self::{hpet::Hpet, madt::Madt, mcfg::Mcfg, sdt::Sdt};
3333

34+
pub mod aml;
3435
pub mod fadt;
3536
pub mod hpet;
3637
pub mod madt;

src/aero_kernel/src/drivers/lai.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::sync::Arc;
22

3+
use crate::acpi::aml;
34
use crate::acpi::fadt;
45
use crate::acpi::get_acpi_table;
56

@@ -98,6 +99,14 @@ impl lai::Host for LaiHost {
9899
}
99100
}
100101

102+
struct LaiSubsystem;
103+
104+
impl aml::AmlSubsystem for LaiSubsystem {
105+
fn enter_state(&self, state: aml::SleepState) {
106+
lai::enter_sleep(state as u8)
107+
}
108+
}
109+
101110
pub fn init_lai() {
102111
let lai_host = Arc::new(LaiHost);
103112
lai::init(lai_host);
@@ -106,6 +115,9 @@ pub fn init_lai() {
106115
lai::create_namespace();
107116

108117
lai::enable_acpi(1);
118+
119+
let subsystem = Arc::new(LaiSubsystem);
120+
aml::init(subsystem);
109121
}
110122

111123
crate::module_init!(init_lai);

src/aero_kernel/src/syscall/process.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use aero_syscall::{AeroSyscallError, MMapFlags, MMapProt, SysInfo, Utsname};
2222
use alloc::string::String;
2323
use spin::{Mutex, Once};
2424

25+
use crate::acpi::aml;
2526
use crate::fs;
2627
use crate::fs::Path;
2728

@@ -311,7 +312,7 @@ pub fn shutdown() -> ! {
311312
fs::cache::clear_dir_cache();
312313

313314
let _guard = IrqGuard::new();
314-
lai::enter_sleep(5);
315+
aml::get_subsystem().enter_state(aml::SleepState::S5);
315316

316317
unreachable!("aml: failed to shutdown (enter state S5)")
317318
}

0 commit comments

Comments
 (0)