Skip to main content

acpi_spec/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! ACPI types.
5
6#![expect(missing_docs)]
7#![forbid(unsafe_code)]
8#![no_std]
9
10#[cfg(feature = "alloc")]
11extern crate alloc;
12
13pub mod aspt;
14pub mod dmar;
15pub mod fadt;
16pub mod gtdt;
17pub mod iort;
18pub mod ivrs;
19pub mod madt;
20pub mod mcfg;
21pub mod pptt;
22pub mod slit;
23pub mod srat;
24
25#[expect(non_camel_case_types)]
26mod packed_nums {
27    pub type u16_ne = zerocopy::U16<zerocopy::NativeEndian>;
28    pub type u32_ne = zerocopy::U32<zerocopy::NativeEndian>;
29    pub type u64_ne = zerocopy::U64<zerocopy::NativeEndian>;
30}
31
32use self::packed_nums::*;
33use core::mem::size_of;
34use static_assertions::const_assert_eq;
35use zerocopy::FromBytes;
36use zerocopy::Immutable;
37use zerocopy::IntoBytes;
38use zerocopy::KnownLayout;
39use zerocopy::Unaligned;
40
41#[repr(C, packed)]
42#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
43pub struct Rsdp {
44    pub signature: [u8; 8], // "RSD PTR "
45    pub checksum: u8,       // first 20 bytes
46    pub oem_id: [u8; 6],
47    pub revision: u8, // 2
48    pub rsdt: u32,
49    pub length: u32,
50    pub xsdt: u64,
51    pub xchecksum: u8, // full checksum
52    pub rsvd: [u8; 3],
53}
54
55const_assert_eq!(size_of::<Rsdp>(), 36);
56
57#[repr(C)]
58#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
59pub struct Header {
60    pub signature: [u8; 4],
61    pub length: u32_ne,
62    pub revision: u8,
63    pub checksum: u8,
64    pub oem_id: [u8; 6],
65    pub oem_tableid: [u8; 8],
66    pub oem_revision: u32_ne,
67    pub creator_id: u32_ne,
68    pub creator_revision: u32_ne,
69}
70
71const_assert_eq!(size_of::<Header>(), 36);
72
73/// Marker trait for ACPI Table structs that encodes the table's signature
74pub trait Table: IntoBytes + Unaligned + Immutable + KnownLayout {
75    const SIGNATURE: [u8; 4];
76}