소스 검색

Remove centralized ACPI versions

Looking at this closer, it doesn't look like this is as simple as it looked
before. Each table's revision fields seem to be incremented as needed, as
opposed to being linked to an actual ACPI version. We hard-code the FADT
revision to do the same thing there (NOTE: I'm not sure that the FADT
should actually be using this mechanism - "if the field is present" points
me towards just checking the length, instead of the revision?).

NOTE: this module isn't public, so this doesn't break semver
Isaac Woods 4 년 전
부모
커밋
7bfde8f359
2개의 변경된 파일20개의 추가작업 그리고 23개의 파일을 삭제
  1. 14 14
      acpi/src/fadt.rs
  2. 6 9
      acpi/src/sdt.rs

+ 14 - 14
acpi/src/fadt.rs

@@ -1,5 +1,5 @@
 use crate::{
-    sdt::{ExtendedField, SdtHeader, ACPI_VERSION_2_0},
+    sdt::{ExtendedField, SdtHeader},
     AcpiError,
     AcpiTable,
     GenericAddress,
@@ -75,19 +75,19 @@ pub struct Fadt {
     reset_value: u8,
     arm_boot_arch: u16,
     fadt_minor_version: u8,
-    x_firmware_ctrl: ExtendedField<u64, ACPI_VERSION_2_0>,
-    x_dsdt_address: ExtendedField<u64, ACPI_VERSION_2_0>,
-    x_pm1a_event_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    x_pm1b_event_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    x_pm1a_control_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    x_pm1b_control_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    x_pm2_control_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    x_pm_timer_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    x_gpe0_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    x_gpe1_block: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    sleep_control_reg: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    sleep_status_reg: ExtendedField<GenericAddress, ACPI_VERSION_2_0>,
-    hypervisor_vendor_id: ExtendedField<u64, ACPI_VERSION_2_0>,
+    x_firmware_ctrl: ExtendedField<u64, 2>,
+    x_dsdt_address: ExtendedField<u64, 2>,
+    x_pm1a_event_block: ExtendedField<GenericAddress, 2>,
+    x_pm1b_event_block: ExtendedField<GenericAddress, 2>,
+    x_pm1a_control_block: ExtendedField<GenericAddress, 2>,
+    x_pm1b_control_block: ExtendedField<GenericAddress, 2>,
+    x_pm2_control_block: ExtendedField<GenericAddress, 2>,
+    x_pm_timer_block: ExtendedField<GenericAddress, 2>,
+    x_gpe0_block: ExtendedField<GenericAddress, 2>,
+    x_gpe1_block: ExtendedField<GenericAddress, 2>,
+    sleep_control_reg: ExtendedField<GenericAddress, 2>,
+    sleep_status_reg: ExtendedField<GenericAddress, 2>,
+    hypervisor_vendor_id: ExtendedField<u64, 2>,
 }
 
 impl AcpiTable for Fadt {

+ 6 - 9
acpi/src/sdt.rs

@@ -1,21 +1,18 @@
 use crate::{AcpiError, AcpiHandler};
 use core::{fmt, mem, mem::MaybeUninit, str};
 
-pub const ACPI_VERSION_2_0: u8 = 20;
-
 /// Represents a field which may or may not be present within an ACPI structure, depending on the version of ACPI
 /// that a system supports. If the field is not present, it is not safe to treat the data as initialised.
 #[repr(C, packed)]
-pub struct ExtendedField<T: Copy, const MIN_VERSION: u8>(MaybeUninit<T>);
+pub struct ExtendedField<T: Copy, const MIN_REVISION: u8>(MaybeUninit<T>);
 
-impl<T: Copy, const MIN_VERSION: u8> ExtendedField<T, MIN_VERSION> {
-    /// Access the field if it's present for the given ACPI version. You should get this version from another ACPI
-    /// structure, such as the RSDT/XSDT.
+impl<T: Copy, const MIN_REVISION: u8> ExtendedField<T, MIN_REVISION> {
+    /// Access the field if it's present for the given revision of the table.
     ///
     /// ### Safety
-    /// 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 {
+    /// If a bogus ACPI version is passed, this function may access uninitialised data.
+    pub unsafe fn access(&self, revision: u8) -> Option<T> {
+        if revision >= MIN_REVISION {
             Some(unsafe { self.0.assume_init() })
         } else {
             None