Skip to main content

strat9_kernel/acpi/
waet.rs

1//! Definitions for WAET, the Windows ACPI Emulated devices Table.
2//! Inspired by Theseus OS.
3
4use super::sdt::Sdt;
5use zerocopy::FromBytes;
6
7pub const WAET_SIGNATURE: &[u8; 4] = b"WAET";
8
9/// The Windows ACPI Emulated devices Table (WAET) allows virtualized OSes
10/// to avoid workarounds for errata on physical devices.
11#[repr(C, packed)]
12#[derive(Clone, Copy, Debug, FromBytes)]
13pub struct Waet {
14    pub header: Sdt,
15    pub emulated_device_flags: u32,
16}
17
18impl Waet {
19    /// Finds the WAET in the given `AcpiTables` and returns a reference to it.
20    pub fn get() -> Option<&'static Waet> {
21        unsafe { super::find_table(WAET_SIGNATURE).map(|ptr| &*(ptr as *const Waet)) }
22    }
23
24    /// Returns whether the RTC has been enhanced not to require
25    /// acknowledgment after it asserts an interrupt.
26    pub fn rtc_good(&self) -> bool {
27        const RTC_GOOD: u32 = 1 << 0;
28        self.emulated_device_flags & RTC_GOOD == RTC_GOOD
29    }
30
31    /// Returns whether the ACPI PM timer has been enhanced not to require
32    /// multiple reads.
33    pub fn acpi_pm_timer_good(&self) -> bool {
34        const ACPI_PM_TIMER_GOOD: u32 = 1 << 1;
35        self.emulated_device_flags & ACPI_PM_TIMER_GOOD == ACPI_PM_TIMER_GOOD
36    }
37}