Skip to main content

strat9_kernel/acpi/
hpet.rs

1//! Support for the HPET: High Precision Event Timer.
2//! Inspired by Theseus OS.
3
4use super::sdt::{GenericAddressStructure, Sdt};
5use zerocopy::FromBytes;
6
7pub const HPET_SIGNATURE: &[u8; 4] = b"HPET";
8
9/// The structure of the HPET ACPI table.
10#[derive(Clone, Copy, Debug, FromBytes)]
11#[repr(C, packed)]
12pub struct HpetAcpiTable {
13    pub header: Sdt,
14    pub hardware_revision_id: u8,
15    pub comparator_descriptor: u8,
16    pub pci_vendor_id: u16,
17    pub gen_addr_struct: GenericAddressStructure,
18    pub hpet_number: u8,
19    pub min_periodic_clock_tick: u16,
20    /// also called 'page_protection'
21    pub oem_attribute: u8,
22}
23
24impl HpetAcpiTable {
25    /// Finds the HPET in the given `AcpiTables` and returns a reference to it.
26    pub fn get() -> Option<&'static HpetAcpiTable> {
27        unsafe { super::find_table(HPET_SIGNATURE).map(|ptr| &*(ptr as *const HpetAcpiTable)) }
28    }
29}