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]]
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"

View File

@ -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",

View File

@ -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<u8> {
if !ACPI_TABLES.is_completed() {
return None;
}
unsafe {
match ACPI_TABLES
.get()
.unwrap()
.lock()
.get_sdt::<Fadt>(Signature::FADT)
{
Ok(a) => Some(a.unwrap().century),
Err(er) => None,
}
match ACPI_TABLES.get().unwrap().lock().find_table::<Fadt>() {
Ok(a) => Some(a.century),
Err(er) => None,
}
}

View File

@ -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::<DmarHeader>(Signature::DMAR)
.unwrap()?
};
let dmar_mapping = acpi_table_lock.find_table::<DmarHeader>().ok()?;
let physical_address = dmar_mapping.physical_start();
let len = dmar_mapping.mapped_length();

View File

@ -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<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)]
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));