浏览代码

Move PCI config region parsing over to new system

Isaac Woods 4 年之前
父节点
当前提交
f11e229d89
共有 1 个文件被更改,包括 13 次插入9 次删除
  1. 13 9
      acpi/src/mcfg.rs

+ 13 - 9
acpi/src/mcfg.rs

@@ -1,4 +1,4 @@
-use crate::{handler::PhysicalMapping, sdt::SdtHeader, Acpi, AcpiError};
+use crate::{handler::PhysicalMapping, sdt::SdtHeader, AcpiError, AcpiHandler, AcpiTables};
 use alloc::vec::Vec;
 use core::{mem, slice};
 
@@ -13,6 +13,18 @@ pub struct PciConfigRegions {
 }
 
 impl PciConfigRegions {
+    pub fn new<H>(tables: &AcpiTables<H>, handler: &mut H) -> Result<PciConfigRegions, AcpiError>
+    where
+        H: AcpiHandler,
+    {
+        let mcfg = unsafe {
+            tables
+                .get_sdt::<Mcfg>(handler, crate::sdt::Signature::MCFG)?
+                .ok_or(AcpiError::TableMissing(crate::sdt::Signature::MCFG))?
+        };
+        Ok(PciConfigRegions { regions: mcfg.entries().iter().map(|&entry| entry).collect() })
+    }
+
     /// Get the physical address of the start of the configuration space for a given PCIe device
     /// function. Returns `None` if there isn't an entry in the MCFG that manages that device.
     pub fn physical_address(&self, segment_group_no: u16, bus: u8, device: u8, function: u8) -> Option<u64> {
@@ -64,11 +76,3 @@ struct McfgEntry {
     bus_number_end: u8,
     _reserved: u32,
 }
-
-pub(crate) fn parse_mcfg(acpi: &mut Acpi, mapping: &PhysicalMapping<Mcfg>) -> Result<(), AcpiError> {
-    (*mapping).header.validate(crate::sdt::Signature::MCFG)?;
-
-    acpi.pci_config_regions =
-        Some(PciConfigRegions { regions: mapping.entries().iter().map(|&entry| entry).collect() });
-    Ok(())
-}