Browse Source

refactor: move the definition of `PmTimer` to `platform` module

toku-sa-n 4 năm trước cách đây
mục cha
commit
1d60841585
3 tập tin đã thay đổi với 29 bổ sung28 xóa
  1. 3 25
      acpi/src/fadt.rs
  2. 1 1
      acpi/src/lib.rs
  3. 25 2
      acpi/src/platform/mod.rs

+ 3 - 25
acpi/src/fadt.rs

@@ -4,7 +4,6 @@ use crate::{
     AcpiError,
     AcpiTable,
 };
-use bit_field::BitField;
 
 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
 pub enum PowerProfile {
@@ -129,11 +128,7 @@ impl Fadt {
         }
     }
 
-    pub fn pm_timer(&self) -> Result<Option<PmTimer>, AcpiError> {
-        PmTimer::new(self)
-    }
-
-    fn pm_timer_block(&self) -> Result<Option<GenericAddress>, AcpiError> {
+    pub fn pm_timer_block(&self) -> Result<Option<GenericAddress>, AcpiError> {
         let raw = unsafe {
             self.x_pm_timer_block.access(self.header().revision).or_else(|| {
                 if self.pm_timer_block != 0 {
@@ -155,25 +150,8 @@ impl Fadt {
             None => Ok(None),
         }
     }
-}
 
-/// Information about the ACPI Power Management Timer (ACPI PM Timer).
-pub struct PmTimer {
-    /// A generic address to the register block of ACPI PM Timer.
-    pub base: GenericAddress,
-    /// This field is true if the hardware supports 32-bit timer, and false if the hardware
-    /// supports 24-bit timer.
-    pub supports_32bit: bool,
-}
-impl PmTimer {
-    /// Creates a new instance of `PmTimer`.
-    pub fn new(fadt: &Fadt) -> Result<Option<PmTimer>, AcpiError> {
-        let base = fadt.pm_timer_block()?;
-        let flags = fadt.flags;
-
-        match base {
-            Some(base) => Ok(Some(PmTimer { base, supports_32bit: flags.get_bit(8) })),
-            None => Ok(None),
-        }
+    pub fn flags(&self) -> u32 {
+        self.flags
     }
 }

+ 1 - 1
acpi/src/lib.rs

@@ -54,7 +54,7 @@ pub mod platform;
 pub mod sdt;
 
 pub use crate::{
-    fadt::{PmTimer, PowerProfile},
+    fadt::PowerProfile,
     hpet::HpetInfo,
     madt::MadtError,
     mcfg::PciConfigRegions,

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

@@ -1,6 +1,8 @@
 pub mod address;
 pub mod interrupt;
 
+use address::GenericAddress;
+use bit_field::BitField;
 pub use interrupt::{
     Apic,
     InterruptModel,
@@ -14,7 +16,7 @@ pub use interrupt::{
     TriggerMode,
 };
 
-use crate::{fadt::Fadt, madt::Madt, AcpiError, AcpiHandler, AcpiTables, PmTimer, PowerProfile};
+use crate::{fadt::Fadt, madt::Madt, AcpiError, AcpiHandler, AcpiTables, PowerProfile};
 use alloc::vec::Vec;
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -51,6 +53,27 @@ pub struct ProcessorInfo {
     pub application_processors: Vec<Processor>,
 }
 
+/// Information about the ACPI Power Management Timer (ACPI PM Timer).
+pub struct PmTimer {
+    /// A generic address to the register block of ACPI PM Timer.
+    pub base: GenericAddress,
+    /// This field is true if the hardware supports 32-bit timer, and false if the hardware
+    /// supports 24-bit timer.
+    pub supports_32bit: bool,
+}
+impl PmTimer {
+    /// Creates a new instance of `PmTimer`.
+    pub fn new(fadt: &Fadt) -> Result<Option<PmTimer>, AcpiError> {
+        let base = fadt.pm_timer_block()?;
+        let flags = fadt.flags();
+
+        match base {
+            Some(base) => Ok(Some(PmTimer { base, supports_32bit: flags.get_bit(8) })),
+            None => Ok(None),
+        }
+    }
+}
+
 /// `PlatformInfo` allows the collection of some basic information about the platform from some of the fixed-size
 /// tables in a nice way. It requires access to the `FADT` and `MADT`. It is the easiest way to get information
 /// about the processors and interrupt controllers on a platform.
@@ -83,7 +106,7 @@ impl PlatformInfo {
             Some(madt) => madt.parse_interrupt_model()?,
             None => (InterruptModel::Unknown, None),
         };
-        let pm_timer = fadt.pm_timer()?;
+        let pm_timer = PmTimer::new(&fadt)?;
 
         Ok(PlatformInfo { power_profile, interrupt_model, processor_info, pm_timer })
     }