From 25dc44b34803037a61d211165b42abc675a78943 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 26 Oct 2016 17:23:20 -0600 Subject: [PATCH] Add DMAR device definition --- arch/x86_64/src/acpi/dmar/drhd.rs | 77 +++++++++++++++++++ arch/x86_64/src/acpi/{dmar.rs => dmar/mod.rs} | 12 +++ arch/x86_64/src/acpi/mod.rs | 15 +++- schemes/tcpd/src/main.rs | 1 - 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 arch/x86_64/src/acpi/dmar/drhd.rs rename arch/x86_64/src/acpi/{dmar.rs => dmar/mod.rs} (91%) diff --git a/arch/x86_64/src/acpi/dmar/drhd.rs b/arch/x86_64/src/acpi/dmar/drhd.rs new file mode 100644 index 0000000..494917e --- /dev/null +++ b/arch/x86_64/src/acpi/dmar/drhd.rs @@ -0,0 +1,77 @@ +#[repr(packed)] +pub struct DrhdFault { + pub sts: u32, + pub ctrl: u32, + pub data: u32, + pub addr: [u32; 2], + _rsv: [u64; 2], + pub log: u64, +} + +#[repr(packed)] +pub struct DrhdProtectedMemory { + pub en: u32, + pub low_base: u32, + pub low_limit: u32, + pub high_base: u64, + pub high_limit: u64, +} + +#[repr(packed)] +pub struct DrhdInvalidation { + pub queue_head: u64, + pub queue_tail: u64, + pub queue_addr: u64, + _rsv: u32, + pub cmpl_sts: u32, + pub cmpl_ctrl: u32, + pub cmpl_data: u32, + pub cmpl_addr: [u32; 2], +} + +#[repr(packed)] +pub struct DrhdPageRequest { + pub queue_head: u64, + pub queue_tail: u64, + pub queue_addr: u64, + _rsv: u32, + pub sts: u32, + pub ctrl: u32, + pub data: u32, + pub addr: [u32; 2], +} + +#[repr(packed)] +pub struct DrhdMtrrVariable { + pub base: u64, + pub mask: u64, +} + +#[repr(packed)] +pub struct DrhdMtrr { + pub cap: u64, + pub def_type: u64, + pub fixed: [u64; 11], + pub variable: [DrhdMtrrVariable; 10], +} + +#[repr(packed)] +pub struct Drhd { + pub version: u32, + _rsv: u32, + pub cap: u64, + pub ext_cap: u64, + pub gl_cmd: u32, + pub gl_sts: u32, + pub root_table: u64, + pub ctx_cmd: u64, + _rsv1: u32, + pub fault: DrhdFault, + _rsv2: u32, + pub pm: DrhdProtectedMemory, + pub invl: DrhdInvalidation, + _rsv3: u64, + pub intr_table: u64, + pub page_req: DrhdPageRequest, + pub mtrr: DrhdMtrr, +} diff --git a/arch/x86_64/src/acpi/dmar.rs b/arch/x86_64/src/acpi/dmar/mod.rs similarity index 91% rename from arch/x86_64/src/acpi/dmar.rs rename to arch/x86_64/src/acpi/dmar/mod.rs index 99dff90..d13184f 100644 --- a/arch/x86_64/src/acpi/dmar.rs +++ b/arch/x86_64/src/acpi/dmar/mod.rs @@ -1,6 +1,11 @@ use core::mem; use super::sdt::Sdt; +use self::drhd::Drhd; +use memory::Frame; +use paging::{entry, ActivePageTable, PhysicalAddress}; + +pub mod drhd; /// The DMA Remapping Table #[derive(Debug)] @@ -52,6 +57,13 @@ pub struct DmarDrhd { base: u64, } +impl DmarDrhd { + pub fn get(&self, active_table: &mut ActivePageTable) -> &'static mut Drhd { + active_table.identity_map(Frame::containing_address(PhysicalAddress::new(self.base as usize)), entry::PRESENT | entry::WRITABLE | entry::NO_EXECUTE); + unsafe { &mut *(self.base as *mut Drhd) } + } +} + /// DMAR Reserved Memory Region Reporting // TODO: Implement iterator on DmarRmrr scope #[derive(Debug)] diff --git a/arch/x86_64/src/acpi/mod.rs b/arch/x86_64/src/acpi/mod.rs index dd94fab..725817f 100644 --- a/arch/x86_64/src/acpi/mod.rs +++ b/arch/x86_64/src/acpi/mod.rs @@ -9,7 +9,7 @@ use memory::{allocate_frames, Frame}; use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress}; use start::{kstart_ap, CPU_COUNT, AP_READY}; -use self::dmar::Dmar; +use self::dmar::{Dmar, DmarEntry}; use self::local_apic::LocalApic; use self::madt::{Madt, MadtEntry}; use self::rsdt::Rsdt; @@ -140,6 +140,19 @@ pub fn init_sdt(sdt: &'static Sdt, active_table: &mut ActivePageTable) { for dmar_entry in dmar.iter() { println!(" {:?}", dmar_entry); + match dmar_entry { + DmarEntry::Drhd(dmar_drhd) => { + let drhd = dmar_drhd.get(active_table); + + println!("VER: {:X}", drhd.version); + println!("CAP: {:X}", drhd.cap); + println!("EXT_CAP: {:X}", drhd.ext_cap); + println!("GCMD: {:X}", drhd.gl_cmd); + println!("GSTS: {:X}", drhd.gl_sts); + println!("RT: {:X}", drhd.root_table); + }, + _ => () + } } } else { println!(": Unknown"); diff --git a/schemes/tcpd/src/main.rs b/schemes/tcpd/src/main.rs index d2e670c..1c0e85f 100644 --- a/schemes/tcpd/src/main.rs +++ b/schemes/tcpd/src/main.rs @@ -600,7 +600,6 @@ impl SchemeMut for Tcpd { } fn close(&mut self, file: usize) -> Result { - let closed = { let mut handle = self.handles.get_mut(&file).ok_or(Error::new(EBADF))?;