Upgrade the acpi crate to the latest version

This commit is contained in:
Hsy-Intel 2024-10-10 02:18:58 -04:00 committed by Tate, Hongliang Tian
parent c28cec2c6a
commit 2af9916de9
5 changed files with 25 additions and 126 deletions

16
Cargo.lock generated
View File

@ -4,13 +4,13 @@ version = 3
[[package]] [[package]]
name = "acpi" name = "acpi"
version = "4.1.1" version = "5.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "654f48ab3178632ea535be1765073b990895cb62f70a7e5671975d7150c26d15" checksum = "9e42f25ac5fa51f4188d14baf8f387a97dcd8639644b2f3df948bf5f6dd7d6fa"
dependencies = [ dependencies = [
"bit_field", "bit_field",
"bitflags 2.6.0",
"log", "log",
"rsdp",
] ]
[[package]] [[package]]
@ -1112,7 +1112,6 @@ dependencies = [
"ostd-test", "ostd-test",
"owo-colors 3.5.0", "owo-colors 3.5.0",
"riscv", "riscv",
"rsdp",
"sbi-rt", "sbi-rt",
"spin 0.9.8", "spin 0.9.8",
"static_assertions", "static_assertions",
@ -1309,15 +1308,6 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3582f63211428f83597b51b2ddb88e2a91a9d52d12831f9d08f5e624e8977422" checksum = "3582f63211428f83597b51b2ddb88e2a91a9d52d12831f9d08f5e624e8977422"
[[package]]
name = "rsdp"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d3add2fc55ef37511bcf81a08ee7a09eff07b23aae38b06a29024a38c604b1"
dependencies = [
"log",
]
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.14" version = "1.0.14"

View File

@ -46,10 +46,9 @@ xarray = { git = "https://github.com/asterinas/xarray", version = "0.1.0" }
[target.x86_64-unknown-none.dependencies] [target.x86_64-unknown-none.dependencies]
x86_64 = "0.14.2" x86_64 = "0.14.2"
x86 = "0.52.0" x86 = "0.52.0"
acpi = "4.1.1" acpi = "5.1.0"
aml = "0.16.3" aml = "0.16.3"
multiboot2 = "0.23.0" multiboot2 = "0.23.0"
rsdp = "2.0.0"
iced-x86 = { version = "1.21.0", default-features = false, features = [ iced-x86 = { version = "1.21.0", default-features = false, features = [
"no_std", "no_std",
"decoder", "decoder",

View File

@ -9,7 +9,7 @@
#![allow(unused_variables)] #![allow(unused_variables)]
use acpi::{fadt::Fadt, sdt::Signature}; use acpi::fadt::Fadt;
use x86_64::instructions::port::{ReadOnlyAccess, WriteOnlyAccess}; use x86_64::instructions::port::{ReadOnlyAccess, WriteOnlyAccess};
use super::io_port::IoPort; use super::io_port::IoPort;
@ -26,15 +26,8 @@ pub fn century_register() -> Option<u8> {
if !ACPI_TABLES.is_completed() { if !ACPI_TABLES.is_completed() {
return None; return None;
} }
unsafe { match ACPI_TABLES.get().unwrap().lock().find_table::<Fadt>() {
match ACPI_TABLES Ok(a) => Some(a.century),
.get()
.unwrap()
.lock()
.get_sdt::<Fadt>(Signature::FADT)
{
Ok(a) => Some(a.unwrap().century),
Err(er) => None, Err(er) => None,
} }
} }
}

View File

@ -5,12 +5,12 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use core::{fmt::Debug, mem::size_of, slice::Iter}; use core::{fmt::Debug, mem::size_of, slice::Iter};
use acpi::{sdt::Signature, AcpiTable}; use acpi::{
sdt::{SdtHeader, Signature},
use super::{ AcpiTable,
remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp},
SdtHeaderWrapper,
}; };
use super::remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp};
use crate::mm::paddr_to_vaddr; use crate::mm::paddr_to_vaddr;
/// DMA Remapping structure. When IOMMU is enabled, the structure should be present in the ACPI table, /// 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)] #[derive(Debug, Clone, Copy)]
#[repr(C)] #[repr(C)]
struct DmarHeader { struct DmarHeader {
header: SdtHeaderWrapper, header: SdtHeader,
host_address_width: u8, host_address_width: u8,
flags: u8, flags: u8,
reserved: [u8; 10], reserved: [u8; 10],
} }
impl AcpiTable for DmarHeader { unsafe impl AcpiTable for DmarHeader {
const SIGNATURE: Signature = Signature::DMAR;
fn header(&self) -> &acpi::sdt::SdtHeader { 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(); 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. // SAFETY: The DmarHeader is the header for the DMAR structure, it fits all the field described in Intel manual.
let dmar_mapping = unsafe { let dmar_mapping = acpi_table_lock.find_table::<DmarHeader>().ok()?;
acpi_table_lock
.get_sdt::<DmarHeader>(Signature::DMAR)
.unwrap()?
};
let physical_address = dmar_mapping.physical_start(); let physical_address = dmar_mapping.physical_start();
let len = dmar_mapping.mapped_length(); let len = dmar_mapping.mapped_length();

View File

@ -6,12 +6,9 @@ pub mod dmar;
pub mod remapping; pub mod remapping;
use alloc::borrow::ToOwned; use alloc::borrow::ToOwned;
use core::{ use core::ptr::NonNull;
ops::{Deref, DerefMut},
ptr::NonNull,
};
use acpi::{sdt::SdtHeader, AcpiHandler, AcpiTable, AcpiTables}; use acpi::{rsdp::Rsdp, AcpiHandler, AcpiTables};
use log::{info, warn}; use log::{info, warn};
use spin::Once; use spin::Once;
@ -24,59 +21,6 @@ use crate::{
/// RSDP information, key is the signature, value is the virtual address of the signature /// RSDP information, key is the signature, value is the virtual address of the signature
pub static ACPI_TABLES: Once<SpinLock<AcpiTables<AcpiMemoryHandler>>> = Once::new(); pub static ACPI_TABLES: Once<SpinLock<AcpiTables<AcpiMemoryHandler>>> = 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::<SdtHeaderWrapper>(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)] #[derive(Debug, Clone)]
pub struct AcpiMemoryHandler {} pub struct AcpiMemoryHandler {}
@ -111,34 +55,10 @@ pub fn init() {
}, },
BootloaderAcpiArg::NotProvided => { BootloaderAcpiArg::NotProvided => {
// We search by ourselves if the bootloader decides not to provide a rsdp location. // 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 { match rsdp {
Ok(map) => match map.validate() { Ok(map) => unsafe {
Ok(_) => { AcpiTables::from_rsdp(AcpiMemoryHandler {}, map.physical_start()).unwrap()
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;
}
}, },
Err(_) => { Err(_) => {
warn!("ACPI info not found!"); warn!("ACPI info not found!");
@ -148,8 +68,8 @@ pub fn init() {
} }
}; };
for (signature, sdt) in acpi_tables.sdts.iter() { for header in acpi_tables.headers() {
info!("ACPI found signature:{:?}", signature); info!("ACPI found signature:{:?}", header.signature);
} }
ACPI_TABLES.call_once(|| SpinLock::new(acpi_tables)); ACPI_TABLES.call_once(|| SpinLock::new(acpi_tables));