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 hyperv;
18pub mod iort;
19pub mod ivrs;
20pub mod madt;
21pub mod mcfg;
22pub mod pptt;
23pub mod slit;
24pub mod srat;
25
26#[expect(non_camel_case_types)]
27mod packed_nums {
28    pub type u16_ne = zerocopy::U16<zerocopy::NativeEndian>;
29    pub type u32_ne = zerocopy::U32<zerocopy::NativeEndian>;
30    pub type u64_ne = zerocopy::U64<zerocopy::NativeEndian>;
31}
32
33use self::packed_nums::*;
34use core::mem::size_of;
35use static_assertions::const_assert_eq;
36use zerocopy::FromBytes;
37use zerocopy::Immutable;
38use zerocopy::IntoBytes;
39use zerocopy::KnownLayout;
40use zerocopy::Unaligned;
41
42#[repr(C, packed)]
43#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
44pub struct Rsdp {
45    pub signature: [u8; 8], // "RSD PTR "
46    pub checksum: u8,       // first 20 bytes
47    pub oem_id: [u8; 6],
48    pub revision: u8, // 2
49    pub rsdt: u32,
50    pub length: u32,
51    pub xsdt: u64,
52    pub xchecksum: u8, // full checksum
53    pub rsvd: [u8; 3],
54}
55
56const_assert_eq!(size_of::<Rsdp>(), 36);
57
58#[repr(C)]
59#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
60pub struct Header {
61    pub signature: [u8; 4],
62    pub length: u32_ne,
63    pub revision: u8,
64    pub checksum: u8,
65    pub oem_id: [u8; 6],
66    pub oem_tableid: [u8; 8],
67    pub oem_revision: u32_ne,
68    pub creator_id: u32_ne,
69    pub creator_revision: u32_ne,
70}
71
72const_assert_eq!(size_of::<Header>(), 36);
73
74/// Marker trait for ACPI Table structs that encodes the table's signature
75pub trait Table: IntoBytes + Unaligned + Immutable + KnownLayout {
76    const SIGNATURE: [u8; 4];
77}