9bc1fbfe46
Fixes the build errors introduced by the Phase II.X.W FACS parser and the Sdt length() method: * src/acpi/sdt.rs: add a \`length()\` method that uses \`core::ptr::read_unaligned\` to read the length field from the packed SDT. The Sdt is \`#[repr(C, packed)]\` so direct field access is not allowed. The new method returns a u32 (matching the SDT spec). Fixes the E0308 errors in fadt.rs and facs.rs. * src/acpi/fadt.rs: use \`sdt.length()\` (the new method) instead of \`sdt.length\` (direct field access) for the FADT size check. * src/acpi/mod.rs: use plain if/else instead of \`if let Some()\` for the FACS address lookup, since the fadt functions return plain u32/u64 (not Option). The address 0 is treated as 'no FACS'. * src/scheme/acpi.rs: use \`payload.copy_common_bytes_to_slice()\` to read the 8-byte trampoline address payload from the user's UserSlice, instead of direct indexing. Fixes the E0608 error. All these fixes maintain the Phase II.X.W functionality (per-Linux 7.1 FACS parser, per-Linux acpi_set_firmware_ waking_vector semantics).
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
#[derive(Copy, Clone, Debug)]
|
|
#[repr(C, packed)]
|
|
pub struct Sdt {
|
|
pub signature: [u8; 4],
|
|
pub length: u32,
|
|
pub revision: u8,
|
|
pub checksum: u8,
|
|
pub oem_id: [u8; 6],
|
|
pub oem_table_id: [u8; 8],
|
|
pub oem_revision: u32,
|
|
pub creator_id: u32,
|
|
pub creator_revision: u32,
|
|
}
|
|
|
|
impl Sdt {
|
|
/// Get the address of this tables data
|
|
pub fn data_address(&self) -> usize {
|
|
self as *const _ as usize + size_of::<Sdt>()
|
|
}
|
|
|
|
/// Get the total length of the table (including the SDT
|
|
/// header), in bytes. The SDT is `#[repr(C, packed)]` so
|
|
/// direct field access requires an unaligned read.
|
|
pub fn length(&self) -> u32 {
|
|
// SAFETY: The Sdt is `#[repr(C, packed)]` and the
|
|
// `length` field is at offset 4 (after the 4-byte
|
|
// signature), aligned to a 4-byte boundary. The address
|
|
// is a valid pointer to the SDT; reading 4 bytes from
|
|
// offset 4 is safe.
|
|
unsafe {
|
|
let p = self as *const Self as *const u8;
|
|
core::ptr::read_unaligned(p.add(4) as *const u32)
|
|
}
|
|
}
|
|
|
|
/// Get the length of this tables data
|
|
pub fn data_len(&self) -> usize {
|
|
let total_size = self.length as usize;
|
|
let header_size = size_of::<Sdt>();
|
|
total_size.saturating_sub(header_size)
|
|
}
|
|
}
|