Browse Source

chore: add `pm_timer` as a member of `PlatformInfo`

toku-sa-n 4 years ago
parent
commit
b26ea52c96
2 changed files with 10 additions and 15 deletions
  1. 6 13
      acpi/src/fadt.rs
  2. 4 2
      acpi/src/platform/mod.rs

+ 6 - 13
acpi/src/fadt.rs

@@ -1,12 +1,10 @@
 use crate::{
-    platform::address::{AccessSize, AddressSpace, GenericAddress, RawGenericAddress},
+    platform::address::{GenericAddress, RawGenericAddress},
     sdt::{ExtendedField, SdtHeader},
     AcpiError,
     AcpiTable,
-    AcpiTables,
 };
 use bit_field::BitField;
-use rsdp::handler::AcpiHandler;
 
 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
 pub enum PowerProfile {
@@ -131,6 +129,10 @@ impl Fadt {
         }
     }
 
+    pub fn pm_timer(&self) -> Result<Option<PmTimer>, AcpiError> {
+        PmTimer::new(self)
+    }
+
     fn pm_timer_block(&self) -> Result<Option<GenericAddress>, AcpiError> {
         let raw = unsafe {
             self.x_pm_timer_block.access(self.header().revision).or_else(|| {
@@ -165,16 +167,7 @@ pub struct PmTimer {
 }
 impl PmTimer {
     /// Creates a new instance of `PmTimer`.
-    pub fn new<H>(tables: &AcpiTables<H>) -> Result<Option<PmTimer>, AcpiError>
-    where
-        H: AcpiHandler,
-    {
-        let fadt = unsafe {
-            tables
-                .get_sdt::<Fadt>(crate::sdt::Signature::FADT)?
-                .ok_or(AcpiError::TableMissing(crate::sdt::Signature::FADT))?
-        };
-
+    pub fn new(fadt: &Fadt) -> Result<Option<PmTimer>, AcpiError> {
         let base = fadt.pm_timer_block()?;
         let flags = fadt.flags;
 

+ 4 - 2
acpi/src/platform/mod.rs

@@ -14,7 +14,7 @@ pub use interrupt::{
     TriggerMode,
 };
 
-use crate::{fadt::Fadt, madt::Madt, AcpiError, AcpiHandler, AcpiTables, PowerProfile};
+use crate::{fadt::Fadt, madt::Madt, AcpiError, AcpiHandler, AcpiTables, PmTimer, PowerProfile};
 use alloc::vec::Vec;
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -60,6 +60,7 @@ pub struct PlatformInfo {
     /// On `x86_64` platforms that support the APIC, the processor topology must also be inferred from the
     /// interrupt model. That information is stored here, if present.
     pub processor_info: Option<ProcessorInfo>,
+    pub pm_timer: Option<PmTimer>,
     /*
      * TODO: we could provide a nice view of the hardware register blocks in the FADT here.
      */
@@ -82,7 +83,8 @@ impl PlatformInfo {
             Some(madt) => madt.parse_interrupt_model()?,
             None => (InterruptModel::Unknown, None),
         };
+        let pm_timer = fadt.pm_timer()?;
 
-        Ok(PlatformInfo { power_profile, interrupt_model, processor_info })
+        Ok(PlatformInfo { power_profile, interrupt_model, processor_info, pm_timer })
     }
 }