use std::ops::{Deref, DerefMut}; use common::io::Mmio; // TODO: Only wrap with Mmio where there are hardware-registers. (Some of these structs seem to be // ring buffer entries, which are not to be treated the same way). pub struct DrhdPage { virt: *mut Drhd, } impl DrhdPage { pub fn map(base_phys: usize) -> syscall::Result { assert_eq!( base_phys % crate::acpi::PAGE_SIZE, 0, "DRHD registers must be page-aligned" ); // TODO: Uncachable? Can reads have side-effects? let virt = unsafe { common::physmap( base_phys, crate::acpi::PAGE_SIZE, common::Prot::RO, common::MemoryType::default(), )? } as *mut Drhd; Ok(Self { virt }) } } impl Deref for DrhdPage { type Target = Drhd; fn deref(&self) -> &Self::Target { unsafe { &*self.virt } } } impl DerefMut for DrhdPage { fn deref_mut(&mut self) -> &mut Self::Target { unsafe { &mut *self.virt } } } impl Drop for DrhdPage { fn drop(&mut self) { unsafe { let _ = libredox::call::munmap(self.virt.cast(), crate::acpi::PAGE_SIZE); } } } #[repr(C, packed)] pub struct DrhdFault { pub sts: Mmio, pub ctrl: Mmio, pub data: Mmio, pub addr: [Mmio; 2], _rsv: [Mmio; 2], pub log: Mmio, } #[repr(C, packed)] pub struct DrhdProtectedMemory { pub en: Mmio, pub low_base: Mmio, pub low_limit: Mmio, pub high_base: Mmio, pub high_limit: Mmio, } #[repr(C, packed)] pub struct DrhdInvalidation { pub queue_head: Mmio, pub queue_tail: Mmio, pub queue_addr: Mmio, _rsv: Mmio, pub cmpl_sts: Mmio, pub cmpl_ctrl: Mmio, pub cmpl_data: Mmio, pub cmpl_addr: [Mmio; 2], } #[repr(C, packed)] pub struct DrhdPageRequest { pub queue_head: Mmio, pub queue_tail: Mmio, pub queue_addr: Mmio, _rsv: Mmio, pub sts: Mmio, pub ctrl: Mmio, pub data: Mmio, pub addr: [Mmio; 2], } #[repr(C, packed)] pub struct DrhdMtrrVariable { pub base: Mmio, pub mask: Mmio, } #[repr(C, packed)] pub struct DrhdMtrr { pub cap: Mmio, pub def_type: Mmio, pub fixed: [Mmio; 11], pub variable: [DrhdMtrrVariable; 10], } #[repr(C, packed)] pub struct Drhd { pub version: Mmio, _rsv: Mmio, pub cap: Mmio, pub ext_cap: Mmio, pub gl_cmd: Mmio, pub gl_sts: Mmio, pub root_table: Mmio, pub ctx_cmd: Mmio, _rsv1: Mmio, pub fault: DrhdFault, _rsv2: Mmio, pub pm: DrhdProtectedMemory, pub invl: DrhdInvalidation, _rsv3: Mmio, pub intr_table: Mmio, pub page_req: DrhdPageRequest, pub mtrr: DrhdMtrr, }