forked from theseus-os/Theseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the WAET ACPI table (theseus-os#1050)
* Currently not used, but fully working. * Can be used to optimize RTC and ACPI PM timer usage.
- Loading branch information
1 parent
810e12f
commit 1be62d4
Showing
7 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "waet" | ||
version = "0.1.0" | ||
authors = ["Kevin Boos <kevinaboos@gmail.com>"] | ||
description = "Support for ACPI WAET" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
zerocopy = "0.5.0" | ||
|
||
[dependencies.memory] | ||
path = "../../memory" | ||
|
||
[dependencies.sdt] | ||
path = "../sdt" | ||
|
||
[dependencies.acpi_table] | ||
path = "../acpi_table" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//! Definitions for WAET, the Windows ACPI Emulated devices Table. | ||
|
||
#![no_std] | ||
|
||
use memory::PhysicalAddress; | ||
use sdt::Sdt; | ||
use acpi_table::{AcpiSignature, AcpiTables}; | ||
use zerocopy::FromBytes; | ||
|
||
|
||
pub const WAET_SIGNATURE: &[u8; 4] = b"WAET"; | ||
|
||
|
||
/// The handler for parsing the WAET table and adding it to the ACPI tables list. | ||
pub fn handle( | ||
acpi_tables: &mut AcpiTables, | ||
signature: AcpiSignature, | ||
_length: usize, | ||
phys_addr: PhysicalAddress | ||
) -> Result<(), &'static str> { | ||
acpi_tables.add_table_location(signature, phys_addr, None) | ||
} | ||
|
||
|
||
/// The Windows ACPI Emulated devices Table (WAET) allows virtualized OSes | ||
/// to avoid workarounds for errata on physical devices. | ||
/// | ||
/// <https://download.microsoft.com/download/7/E/7/7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2/WAET.docx> | ||
#[repr(C, packed)] | ||
#[derive(Clone, Copy, Debug, FromBytes)] | ||
pub struct Waet { | ||
pub header: Sdt, | ||
pub emulated_device_flags: u32, | ||
} | ||
const _: () = assert!(core::mem::size_of::<Waet>() == 40); | ||
const _: () = assert!(core::mem::align_of::<Waet>() == 1); | ||
|
||
impl Waet { | ||
/// Finds the WAET in the given `AcpiTables` and returns a reference to it. | ||
pub fn get(acpi_tables: &AcpiTables) -> Option<&Waet> { | ||
acpi_tables.table(WAET_SIGNATURE).ok() | ||
} | ||
|
||
/// Returns whether the RTC has been enhanced not to require | ||
/// acknowledgment after it asserts an interrupt. | ||
/// | ||
/// If this returns `true`, an interrupt handler can bypass | ||
/// reading the RTC register to unlatch the pending interrupt. | ||
pub fn rtc_good(&self) -> bool { | ||
const RTC_GOOD: u32 = 1 << 0; | ||
self.emulated_device_flags & RTC_GOOD == RTC_GOOD | ||
} | ||
|
||
/// Returns whether the ACPI PM timer has been enhanced not to require | ||
/// multiple reads. | ||
/// | ||
/// If this returns `true`, only a single read of the ACPI PM timer is | ||
/// necessary to obtain a reliable value from it. | ||
pub fn acpi_pm_timer_good(&self) -> bool { | ||
const ACPI_PM_TIMER_GOOD: u32 = 1 << 1; | ||
self.emulated_device_flags & ACPI_PM_TIMER_GOOD == ACPI_PM_TIMER_GOOD | ||
} | ||
} |