Skip to content

Commit 1469c6a

Browse files
lai_host: sleep and I/O functions
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 6f324b0 commit 1469c6a

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/aero_kernel/src/drivers/lai.rs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
use alloc::sync::Arc;
2+
13
use crate::acpi::fadt;
24
use crate::acpi::get_acpi_table;
35

46
use crate::mem::paging::PhysAddr;
57

8+
use crate::userland::scheduler;
9+
use crate::utils::io;
10+
611
struct LaiHost;
712

813
impl lai::Host for LaiHost {
@@ -25,16 +30,55 @@ impl lai::Host for LaiHost {
2530
}
2631
.unwrap_or(core::ptr::null())
2732
}
33+
34+
fn sleep(&self, ms: u64) {
35+
scheduler::get_scheduler()
36+
.inner
37+
.sleep(Some(ms as usize * 1_000_000))
38+
.expect("lai: unexpected signal during sleep")
39+
}
40+
41+
// Port I/O functions:
42+
#[inline]
43+
fn outb(&self, port: u16, value: u8) {
44+
unsafe { io::outb(port, value) }
45+
}
46+
47+
#[inline]
48+
fn outw(&self, port: u16, value: u16) {
49+
unsafe { io::outw(port, value) }
50+
}
51+
52+
#[inline]
53+
fn outd(&self, port: u16, value: u32) {
54+
unsafe { io::outl(port, value) }
55+
}
56+
57+
#[inline]
58+
fn inb(&self, port: u16) -> u8 {
59+
unsafe { io::inb(port) }
60+
}
61+
62+
#[inline]
63+
fn inw(&self, port: u16) -> u16 {
64+
unsafe { io::inw(port) }
65+
}
66+
67+
#[inline]
68+
fn ind(&self, port: u16) -> u32 {
69+
unsafe { io::inl(port) }
70+
}
2871
}
2972

3073
pub fn init_lai() {
31-
let lai_host = box LaiHost;
74+
let lai_host = Arc::new(LaiHost);
3275
lai::init(lai_host);
3376

34-
unsafe {
35-
lai::lai_set_acpi_revision(get_acpi_table().revision() as _);
36-
lai::lai_create_namespace();
37-
}
77+
lai::set_acpi_revision(get_acpi_table().revision() as _);
78+
lai::create_namespace();
79+
80+
lai::enable_acpi(1);
81+
lai::enter_sleep(5);
3882
}
3983

4084
crate::module_init!(init_lai);

src/aero_kernel/src/utils/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub unsafe fn outw(port: u16, value: u16) {
9393
}
9494

9595
/// Wrapper function to the `outl` assembly instruction used to do the
96-
/// low level port output.
96+
/// 32-bit low level port output.
9797
#[inline]
9898
pub unsafe fn outl(port: u16, value: u32) {
9999
asm!(

0 commit comments

Comments
 (0)