Przeglądaj źródła

Some small clean-ups

* Convenience method `AcpiTables::platform_info` added to aid discoverability
* Deny unsafe ops in unsafe fn
* Fix errors created by that lint
* Make method in MADT private, as it's called as an implementation detail
* Remove unneeded Rsdp::oem_id method. We should probably work out some way
  of exposing OEM details, but so few people probably care about it, it
  seems a waste to heap-alloc a string for it just in case.
Isaac Woods 4 lat temu
rodzic
commit
20a076fecd
4 zmienionych plików z 10 dodań i 7 usunięć
  1. 7 0
      acpi/src/lib.rs
  2. 1 1
      acpi/src/madt.rs
  3. 0 4
      acpi/src/rsdp.rs
  4. 2 2
      acpi/src/sdt.rs

+ 7 - 0
acpi/src/lib.rs

@@ -23,6 +23,7 @@
 
 #![no_std]
 #![feature(const_generics, unsafe_block_in_unsafe_fn)]
+#![deny(unsafe_op_in_unsafe_fn)]
 
 extern crate alloc;
 #[cfg_attr(test, macro_use)]
@@ -249,6 +250,12 @@ where
 
         Ok(Some(mapping))
     }
+
+    /// Convenience method for contructing a [`PlatformInfo`](crate::platform::PlatformInfo). This is one of the
+    /// first things you should usually do with an `AcpiTables`, and allows to collect helpful information about
+    /// the platform from the ACPI tables.
+    pub fn platform_info(&self) -> Result<PlatformInfo, AcpiError> {
+        PlatformInfo::new(self)
     }
 }
 

+ 1 - 1
acpi/src/madt.rs

@@ -92,7 +92,7 @@ impl Madt {
         Ok((InterruptModel::Unknown, None))
     }
 
-    pub fn parse_apic_model(&self) -> Result<(InterruptModel, Option<ProcessorInfo>), AcpiError> {
+    fn parse_apic_model(&self) -> Result<(InterruptModel, Option<ProcessorInfo>), AcpiError> {
         let mut local_apic_address = self.local_apic_address as u64;
         let mut io_apic_count = 0;
         let mut iso_count = 0;

+ 0 - 4
acpi/src/rsdp.rs

@@ -71,10 +71,6 @@ impl Rsdp {
         Ok(())
     }
 
-    pub(crate) fn oem_id<'a>(&'a self) -> &'a str {
-        str::from_utf8(&self.oem_id).unwrap()
-    }
-
     pub(crate) fn revision(&self) -> u8 {
         self.revision
     }

+ 2 - 2
acpi/src/sdt.rs

@@ -1,4 +1,4 @@
-use crate::{fadt::Fadt, hpet::HpetTable, madt::Madt, mcfg::Mcfg, AcpiError, AcpiHandler, AmlTable};
+use crate::{AcpiError, AcpiHandler};
 use core::{fmt, mem, mem::MaybeUninit, str};
 
 pub const ACPI_VERSION_2_0: u8 = 20;
@@ -16,7 +16,7 @@ impl<T: Copy, const MIN_VERSION: u8> ExtendedField<T, MIN_VERSION> {
     /// If a bogus ACPI version is passed, this function may access uninitialised data, which is unsafe.
     pub unsafe fn access(&self, version: u8) -> Option<T> {
         if version >= MIN_VERSION {
-            Some(self.0.assume_init())
+            Some(unsafe { self.0.assume_init() })
         } else {
             None
         }