acpica_bindings/interface/handler/mod.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//! The [`AcpiHandler`] trait, which is the interface with which ACPICA calls OS functions.
mod bindings;
mod handler_trait;
pub use handler_trait::AcpiHandler;
use alloc::ffi::CString;
use crate::{
bindings::functions::{
AcpiDebugTrace, AcpiEnterSleepState, AcpiEnterSleepStatePrep, AcpiGetTimer,
},
AcpicaOperation,
};
use super::status::AcpiError;
impl<const TI: bool, const TL: bool, const E: bool, const I: bool> AcpicaOperation<TI, TL, E, I> {
/// Rust binding to the ACPICA `AcpiDebugTrace` function.
///
/// # Panics
/// * If the OS interface has not been set up using [`register_interface`]
/// * If `name` contains null bytes, including at the end.
///
/// TODO: Find enums for layer, level, and flags
///
/// [`register_interface`]: super::register_interface
pub fn debug_trace(
&self,
name: &str,
level: u32,
layer: u32,
flags: u32,
) -> Result<(), AcpiError> {
let ffi_name = CString::new(name).expect("name should not contain null bytes");
// SAFETY: The passed pointer is valid as it was taken from a CString
unsafe { AcpiDebugTrace(ffi_name.as_ptr(), level, layer, flags).as_result() }
}
}
// TODO: check what level of initialization these really need
impl AcpicaOperation<true, true, true, true> {
/// TODO: docs
pub unsafe fn enter_sleep_state_prep(&mut self, state: u8) -> Result<(), AcpiError> {
// SAFETY: TODO
unsafe { AcpiEnterSleepStatePrep(state).as_result() }
}
/// TODO: docs
pub unsafe fn enter_sleep_state(&mut self, state: u8) -> Result<(), AcpiError> {
// SAFETY: TODO
unsafe { AcpiEnterSleepState(state).as_result() }
}
/// TODO: docs
pub fn get_timer(&mut self) -> u32 {
let mut x = 0;
// SAFETY: TODO
unsafe { AcpiGetTimer(&mut x).as_result().unwrap() }
x
}
}