Explorar o código

Provide new way to get HPET info

Isaac Woods %!s(int64=4) %!d(string=hai) anos
pai
achega
7703f96b33
Modificáronse 1 ficheiros con 31 adicións e 25 borrados
  1. 31 25
      acpi/src/hpet.rs

+ 31 - 25
acpi/src/hpet.rs

@@ -1,4 +1,4 @@
-use crate::{sdt::SdtHeader, Acpi, AcpiError, GenericAddress, PhysicalMapping};
+use crate::{sdt::SdtHeader, AcpiError, AcpiHandler, AcpiTables, GenericAddress, PhysicalMapping};
 use bit_field::BitField;
 
 #[derive(Debug)]
@@ -22,6 +22,36 @@ pub struct HpetInfo {
     pub page_protection: PageProtection,
 }
 
+impl HpetInfo {
+    pub fn new<H>(tables: &AcpiTables<H>, handler: &mut H) -> Result<HpetInfo, AcpiError>
+    where
+        H: AcpiHandler,
+    {
+        let hpet = unsafe {
+            tables
+                .get_sdt::<HpetTable>(handler, crate::sdt::Signature::HPET)?
+                .ok_or(AcpiError::TableMissing(crate::sdt::Signature::HPET))?
+        };
+
+        // Make sure the HPET's in system memory
+        assert_eq!(hpet.base_address.address_space, 0);
+
+        Ok(HpetInfo {
+            event_timer_block_id: hpet.event_timer_block_id,
+            base_address: hpet.base_address.address as usize,
+            hpet_number: hpet.hpet_number,
+            clock_tick_unit: hpet.clock_tick_unit,
+            page_protection: match hpet.page_protection_oem.get_bits(0..5) {
+                0 => PageProtection::None,
+                1 => PageProtection::Protected4K,
+                2 => PageProtection::Protected64K,
+                3..=15 => PageProtection::Other,
+                _ => unreachable!(),
+            },
+        })
+    }
+}
+
 #[repr(C, packed)]
 pub(crate) struct HpetTable {
     header: SdtHeader,
@@ -31,27 +61,3 @@ pub(crate) struct HpetTable {
     clock_tick_unit: u16,
     page_protection_oem: u8,
 }
-
-pub(crate) fn parse_hpet(acpi: &mut Acpi, mapping: &PhysicalMapping<HpetTable>) -> Result<(), AcpiError> {
-    (*mapping).header.validate(crate::sdt::Signature::HPET)?;
-    let hpet = &*mapping;
-
-    // Make sure the HPET's in system memory
-    assert_eq!(hpet.base_address.address_space, 0);
-
-    acpi.hpet = Some(HpetInfo {
-        event_timer_block_id: hpet.event_timer_block_id,
-        base_address: hpet.base_address.address as usize,
-        hpet_number: hpet.hpet_number,
-        clock_tick_unit: hpet.clock_tick_unit,
-        page_protection: match hpet.page_protection_oem.get_bits(0..5) {
-            0 => PageProtection::None,
-            1 => PageProtection::Protected4K,
-            2 => PageProtection::Protected64K,
-            3..=15 => PageProtection::Other,
-            _ => unreachable!(),
-        },
-    });
-
-    Ok(())
-}