From dd9fc81a81c558038c98708ceec88cd4189d12ba Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Tue, 20 May 2025 13:16:31 +0800 Subject: [PATCH] Add some TODOs in IOMMU initialization --- ostd/src/arch/x86/iommu/dma_remapping/mod.rs | 5 +++++ ostd/src/arch/x86/iommu/registers/mod.rs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/ostd/src/arch/x86/iommu/dma_remapping/mod.rs b/ostd/src/arch/x86/iommu/dma_remapping/mod.rs index 2235fab0..33eae3d5 100644 --- a/ostd/src/arch/x86/iommu/dma_remapping/mod.rs +++ b/ostd/src/arch/x86/iommu/dma_remapping/mod.rs @@ -74,6 +74,11 @@ pub fn init() { // Create a Root Table instance. let mut root_table = RootTable::new(); // For all PCI devices, use the same page table. + // + // TODO: The BIOS reserves some memory regions as DMA targets and lists them in the Reserved + // Memory Region Reporting (RMRR) structures. These regions must be mapped for the hardware or + // firmware to function properly. For more details, see Intel(R) Virtualization Technology for + // Directed I/O (Revision 5.0), 3.16 Handling Requests to Reserved System Memory. let page_table = PageTable::::empty(); for table in PciDeviceLocation::all() { root_table.specify_device_page_table(table, unsafe { page_table.shallow_copy() }) diff --git a/ostd/src/arch/x86/iommu/registers/mod.rs b/ostd/src/arch/x86/iommu/registers/mod.rs index faac7f35..224cd1fd 100644 --- a/ostd/src/arch/x86/iommu/registers/mod.rs +++ b/ostd/src/arch/x86/iommu/registers/mod.rs @@ -258,6 +258,15 @@ impl IommuRegisters { let base_address = dmar .remapping_iter() + // TODO: Add support for multiple DMA remapping hardware unit definitions (DRHDs). Note + // that we use `rev()` here to select the last one, since DRHDs that control specific + // devices tend to be reported first. + // + // For example, Intel(R) Virtualization Technology for Directed I/O (Revision 5.0), 8.4 + // DMA Remapping Hardware Unit Definition Structure says "If a DRHD structure with + // INCLUDE_PCI_ALL flag Set is reported for a Segment, it must be enumerated by BIOS + // after all other DRHD structures for the same Segment". + .rev() .find_map(|remapping| match remapping { Remapping::Drhd(drhd) => Some(drhd.register_base_addr()), _ => None,