Skip to main content

strat9_kernel/acpi/
dmar.rs

1//! Definitions for the DMAR, the Direct Memory Access (DMA) Remapping ACPI table.
2//! Inspired by Theseus OS.
3
4use super::sdt::Sdt;
5use zerocopy::FromBytes;
6
7pub const DMAR_SIGNATURE: &[u8; 4] = b"DMAR";
8
9#[derive(Clone, Copy, Debug, FromBytes)]
10#[repr(C, packed)]
11struct DmarReporting {
12    header: Sdt,
13    host_address_width: u8,
14    flags: u8,
15    _reserved: [u8; 10],
16}
17
18pub struct Dmar {
19    table: &'static DmarReporting,
20}
21
22impl Dmar {
23    /// Performs the get operation.
24    pub fn get() -> Option<Self> {
25        unsafe {
26            super::find_table(DMAR_SIGNATURE).map(|ptr| Dmar {
27                table: &*(ptr as *const DmarReporting),
28            })
29        }
30    }
31
32    /// Performs the host address width operation.
33    pub fn host_address_width(&self) -> u8 {
34        self.table.host_address_width + 1
35    }
36
37    /// Performs the flags operation.
38    pub fn flags(&self) -> u8 {
39        self.table.flags
40    }
41}