From 2af9916de92f8ca1e694bb6ac5e33111bbcf51fd Mon Sep 17 00:00:00 2001 From: Hsy-Intel Date: Thu, 10 Oct 2024 02:18:58 -0400 Subject: [PATCH] Upgrade the `acpi` crate to the latest version --- Cargo.lock | 16 +---- ostd/Cargo.toml | 3 +- ostd/src/arch/x86/device/cmos.rs | 15 ++--- ostd/src/arch/x86/kernel/acpi/dmar.rs | 23 +++---- ostd/src/arch/x86/kernel/acpi/mod.rs | 94 ++------------------------- 5 files changed, 25 insertions(+), 126 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1ed285d2..b560bd0a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,13 +4,13 @@ version = 3 [[package]] name = "acpi" -version = "4.1.1" +version = "5.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "654f48ab3178632ea535be1765073b990895cb62f70a7e5671975d7150c26d15" +checksum = "9e42f25ac5fa51f4188d14baf8f387a97dcd8639644b2f3df948bf5f6dd7d6fa" dependencies = [ "bit_field", + "bitflags 2.6.0", "log", - "rsdp", ] [[package]] @@ -1112,7 +1112,6 @@ dependencies = [ "ostd-test", "owo-colors 3.5.0", "riscv", - "rsdp", "sbi-rt", "spin 0.9.8", "static_assertions", @@ -1309,15 +1308,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3582f63211428f83597b51b2ddb88e2a91a9d52d12831f9d08f5e624e8977422" -[[package]] -name = "rsdp" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d3add2fc55ef37511bcf81a08ee7a09eff07b23aae38b06a29024a38c604b1" -dependencies = [ - "log", -] - [[package]] name = "rustversion" version = "1.0.14" diff --git a/ostd/Cargo.toml b/ostd/Cargo.toml index 6208a713d..e5d21aedc 100644 --- a/ostd/Cargo.toml +++ b/ostd/Cargo.toml @@ -46,10 +46,9 @@ xarray = { git = "https://github.com/asterinas/xarray", version = "0.1.0" } [target.x86_64-unknown-none.dependencies] x86_64 = "0.14.2" x86 = "0.52.0" -acpi = "4.1.1" +acpi = "5.1.0" aml = "0.16.3" multiboot2 = "0.23.0" -rsdp = "2.0.0" iced-x86 = { version = "1.21.0", default-features = false, features = [ "no_std", "decoder", diff --git a/ostd/src/arch/x86/device/cmos.rs b/ostd/src/arch/x86/device/cmos.rs index 512369589..1fedda482 100644 --- a/ostd/src/arch/x86/device/cmos.rs +++ b/ostd/src/arch/x86/device/cmos.rs @@ -9,7 +9,7 @@ #![allow(unused_variables)] -use acpi::{fadt::Fadt, sdt::Signature}; +use acpi::fadt::Fadt; use x86_64::instructions::port::{ReadOnlyAccess, WriteOnlyAccess}; use super::io_port::IoPort; @@ -26,15 +26,8 @@ pub fn century_register() -> Option { if !ACPI_TABLES.is_completed() { return None; } - unsafe { - match ACPI_TABLES - .get() - .unwrap() - .lock() - .get_sdt::(Signature::FADT) - { - Ok(a) => Some(a.unwrap().century), - Err(er) => None, - } + match ACPI_TABLES.get().unwrap().lock().find_table::() { + Ok(a) => Some(a.century), + Err(er) => None, } } diff --git a/ostd/src/arch/x86/kernel/acpi/dmar.rs b/ostd/src/arch/x86/kernel/acpi/dmar.rs index 53d01bd0c..16849b005 100644 --- a/ostd/src/arch/x86/kernel/acpi/dmar.rs +++ b/ostd/src/arch/x86/kernel/acpi/dmar.rs @@ -5,12 +5,12 @@ use alloc::vec::Vec; use core::{fmt::Debug, mem::size_of, slice::Iter}; -use acpi::{sdt::Signature, AcpiTable}; - -use super::{ - remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp}, - SdtHeaderWrapper, +use acpi::{ + sdt::{SdtHeader, Signature}, + AcpiTable, }; + +use super::remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp}; use crate::mm::paddr_to_vaddr; /// DMA Remapping structure. When IOMMU is enabled, the structure should be present in the ACPI table, @@ -51,15 +51,16 @@ pub enum RemappingType { #[derive(Debug, Clone, Copy)] #[repr(C)] struct DmarHeader { - header: SdtHeaderWrapper, + header: SdtHeader, host_address_width: u8, flags: u8, reserved: [u8; 10], } -impl AcpiTable for DmarHeader { +unsafe impl AcpiTable for DmarHeader { + const SIGNATURE: Signature = Signature::DMAR; fn header(&self) -> &acpi::sdt::SdtHeader { - &self.header.0 + &self.header } } @@ -71,11 +72,7 @@ impl Dmar { } let acpi_table_lock = super::ACPI_TABLES.get().unwrap().lock(); // SAFETY: The DmarHeader is the header for the DMAR structure, it fits all the field described in Intel manual. - let dmar_mapping = unsafe { - acpi_table_lock - .get_sdt::(Signature::DMAR) - .unwrap()? - }; + let dmar_mapping = acpi_table_lock.find_table::().ok()?; let physical_address = dmar_mapping.physical_start(); let len = dmar_mapping.mapped_length(); diff --git a/ostd/src/arch/x86/kernel/acpi/mod.rs b/ostd/src/arch/x86/kernel/acpi/mod.rs index 7775a300a..f1f3e2833 100644 --- a/ostd/src/arch/x86/kernel/acpi/mod.rs +++ b/ostd/src/arch/x86/kernel/acpi/mod.rs @@ -6,12 +6,9 @@ pub mod dmar; pub mod remapping; use alloc::borrow::ToOwned; -use core::{ - ops::{Deref, DerefMut}, - ptr::NonNull, -}; +use core::ptr::NonNull; -use acpi::{sdt::SdtHeader, AcpiHandler, AcpiTable, AcpiTables}; +use acpi::{rsdp::Rsdp, AcpiHandler, AcpiTables}; use log::{info, warn}; use spin::Once; @@ -24,59 +21,6 @@ use crate::{ /// RSDP information, key is the signature, value is the virtual address of the signature pub static ACPI_TABLES: Once>> = Once::new(); -/// Sdt header wrapper, user can use this structure to easily derive Debug, get table information without creating a new structure. -/// -/// For example, in DMAR (DMA Remapping) structure, -/// we can use the following code to get some information of DMAR, including address, length: -/// -/// ```rust -/// acpi_table.get_sdt::(Signature::DMAR).unwrap() -/// ``` -/// -#[derive(Clone, Copy)] -pub struct SdtHeaderWrapper(SdtHeader); - -impl AcpiTable for SdtHeaderWrapper { - fn header(&self) -> &acpi::sdt::SdtHeader { - &self.0 - } -} - -impl Deref for SdtHeaderWrapper { - type Target = SdtHeader; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for SdtHeaderWrapper { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl core::fmt::Debug for SdtHeaderWrapper { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let length = self.0.length; - let oem_revision = self.0.oem_revision; - let creator_id = self.0.creator_id; - let creator_revision = self.0.creator_revision; - - f.debug_struct("Dmar") - .field("signature", &self.0.signature) - .field("length", &length) - .field("revision", &self.0.revision) - .field("checksum", &self.0.checksum) - .field("oem_id", &self.0.oem_id()) - .field("oem_table_id", &self.0.oem_table_id()) - .field("oem_revision", &oem_revision) - .field("creator_id", &creator_id) - .field("creator_revision", &creator_revision) - .finish() - } -} - #[derive(Debug, Clone)] pub struct AcpiMemoryHandler {} @@ -111,34 +55,10 @@ pub fn init() { }, BootloaderAcpiArg::NotProvided => { // We search by ourselves if the bootloader decides not to provide a rsdp location. - let rsdp = unsafe { rsdp::Rsdp::search_for_on_bios(AcpiMemoryHandler {}) }; + let rsdp = unsafe { Rsdp::search_for_on_bios(AcpiMemoryHandler {}) }; match rsdp { - Ok(map) => match map.validate() { - Ok(_) => { - if map.revision() > 0 { - unsafe { - AcpiTables::from_rsdt( - AcpiMemoryHandler {}, - 1, - map.xsdt_address() as usize, - ) - .unwrap() - } - } else { - unsafe { - AcpiTables::from_rsdt( - AcpiMemoryHandler {}, - 0, - map.rsdt_address() as usize, - ) - .unwrap() - } - } - } - Err(_) => { - warn!("ACPI info not found!"); - return; - } + Ok(map) => unsafe { + AcpiTables::from_rsdp(AcpiMemoryHandler {}, map.physical_start()).unwrap() }, Err(_) => { warn!("ACPI info not found!"); @@ -148,8 +68,8 @@ pub fn init() { } }; - for (signature, sdt) in acpi_tables.sdts.iter() { - info!("ACPI found signature:{:?}", signature); + for header in acpi_tables.headers() { + info!("ACPI found signature:{:?}", header.signature); } ACPI_TABLES.call_once(|| SpinLock::new(acpi_tables));