2
0
Эх сурвалжийг харах

Improve documentation of HPET fields, add methods to extract info

Isaac Woods 4 жил өмнө
parent
commit
5865cfb92c
1 өөрчлөгдсөн 25 нэмэгдсэн , 3 устгасан
  1. 25 3
      acpi/src/hpet.rs

+ 25 - 3
acpi/src/hpet.rs

@@ -4,16 +4,17 @@ use bit_field::BitField;
 #[derive(Debug)]
 pub enum PageProtection {
     None,
-    /// Access to the adjacent 3KB to the base address will not generate a fault.
+    /// Access to the rest of the 4KiB, relative to the base address, will not generate a fault.
     Protected4K,
-    /// Access to the adjacent 64KB to the base address will not generate a fault.
+    /// Access to the rest of the 64KiB, relative to the base address, will not generate a fault.
     Protected64K,
     Other,
 }
 
-/// Information about the High Precision Event Timer
+/// Information about the High Precision Event Timer (HPET)
 #[derive(Debug)]
 pub struct HpetInfo {
+    // TODO(3.0.0): unpack these fields directly, and get rid of methods
     pub event_timer_block_id: u32,
     pub base_address: usize,
     pub hpet_number: u8,
@@ -50,10 +51,31 @@ impl HpetInfo {
             },
         })
     }
+
+    pub fn hardware_rev(&self) -> u8 {
+        self.event_timer_block_id.get_bits(0..8) as u8
+    }
+
+    pub fn num_comparators(&self) -> u8 {
+        self.event_timer_block_id.get_bits(8..13) as u8
+    }
+
+    pub fn main_counter_is_64bits(&self) -> bool {
+        self.event_timer_block_id.get_bit(13)
+    }
+
+    pub fn legacy_irq_capable(&self) -> bool {
+        self.event_timer_block_id.get_bit(15)
+    }
+
+    pub fn pci_vendor_id(&self) -> u16 {
+        self.event_timer_block_id.get_bits(16..32) as u16
+    }
 }
 
 #[repr(C, packed)]
 pub(crate) struct HpetTable {
+    /// The contents of the HPET's 'General Capabilities and ID register'
     header: SdtHeader,
     event_timer_block_id: u32,
     base_address: RawGenericAddress,