bea6747643
Currently, there are some things that need to be set up by userspace that the kernel previously did. These include telling firmware when the I/O APIC is used, and most importantly, shutting down the system. The former is not particularly important, but for the latter I think that we could implement this using a "shutdown pipe". Essentially it will be a file that triggers an event shutting down, which would be used to notify to acpid that the kernel is requesting a shutdown.
55 lines
1.2 KiB
Rust
55 lines
1.2 KiB
Rust
use core::convert::TryFrom;
|
|
use core::mem;
|
|
use alloc::boxed::Box;
|
|
|
|
use super::sdt::Sdt;
|
|
use super::rxsdt::Rxsdt;
|
|
|
|
#[derive(Debug)]
|
|
pub struct Rsdt(&'static Sdt);
|
|
|
|
impl Rsdt {
|
|
pub fn new(sdt: &'static Sdt) -> Option<Rsdt> {
|
|
if &sdt.signature == b"RSDT" {
|
|
Some(Rsdt(sdt))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
pub fn as_slice(&self) -> &[u8] {
|
|
let length = usize::try_from(self.0.length)
|
|
.expect("expected 32-bit length to fit within usize");
|
|
|
|
unsafe {
|
|
core::slice::from_raw_parts(self.0 as *const _ as *const u8, length)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Rxsdt for Rsdt {
|
|
fn iter(&self) -> Box<dyn Iterator<Item = usize>> {
|
|
Box::new(RsdtIter {
|
|
sdt: self.0,
|
|
i: 0
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct RsdtIter {
|
|
sdt: &'static Sdt,
|
|
i: usize
|
|
}
|
|
|
|
impl Iterator for RsdtIter {
|
|
type Item = usize;
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
if self.i < self.sdt.data_len()/mem::size_of::<u32>() {
|
|
let item = unsafe { *(self.sdt.data_address() as *const u32).add(self.i) };
|
|
self.i += 1;
|
|
Some(item as usize)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|