Skip to main content

strat9_kernel/acpi/
fadt.rs

1/*
2 * This file is part of strat9-os.
3 *
4 * strat9-os is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * strat9-os is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with strat9-os. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * Website: https://www.strat9-os.org
18 * Repository: https://github.com/strat9-os/strat9-os
19 *
20 * Copyright (C) 2023-26 Guillaume Gielly
21 */
22
23//! Definitions for FADT, the Fixed ACPI Description Table.
24//! Inspired by Theseus OS.
25
26use super::sdt::{GenericAddressStructure, Sdt};
27use zerocopy::FromBytes;
28
29pub const FADT_SIGNATURE: &[u8; 4] = b"FACP";
30
31#[repr(C, packed)]
32#[derive(Clone, Copy, Debug, FromBytes)]
33pub struct Fadt {
34    pub header: Sdt,
35    pub firmware_ctrl: u32,
36    /// 32-bit physical address of the DSDT.
37    pub dsdt: u32,
38    _reserved: u8,
39    pub preferred_power_managament: u8,
40    pub sci_interrupt: u16,
41    pub smi_command_port: u32,
42    pub acpi_enable: u8,
43    pub acpi_disable: u8,
44    pub s4_bios_req: u8,
45    pub pstate_control: u8,
46    pub pm1a_event_block: u32,
47    pub pm1b_event_block: u32,
48    pub pm1a_control_block: u32,
49    pub pm1b_control_block: u32,
50    pub pm2_control_block: u32,
51    pub pm_timer_block: u32,
52    pub gpe0_block: u32,
53    pub gpe1_block: u32,
54    pub pm1_event_length: u8,
55    pub pm1_control_length: u8,
56    pub pm2_control_length: u8,
57    pub pm_timer_length: u8,
58    pub gpe0_length: u8,
59    pub gpe1_length: u8,
60    pub gpe1_base: u8,
61    pub c_state_control: u8,
62    pub worst_c2_latency: u16,
63    pub worst_c3_latency: u16,
64    pub flush_size: u16,
65    pub flush_stride: u16,
66    pub duty_offset: u8,
67    pub duty_width: u8,
68    pub day_alarm: u8,
69    pub month_alarm: u8,
70    pub century: u8,
71    pub iapc_boot_architecture_flags: u16,
72    _reserved2: u8,
73    pub flags: u32,
74    pub reset_reg: GenericAddressStructure,
75    pub reset_value: u8,
76    _reserved3: [u8; 3],
77    /// 64-bit physical address of the FACS.
78    pub x_firmware_control: u64,
79    /// 64-bit physical address of the DSDT.
80    pub x_dsdt: u64,
81    pub x_pm1a_event_block: GenericAddressStructure,
82    pub x_pm1b_event_block: GenericAddressStructure,
83    pub x_pm1a_control_block: GenericAddressStructure,
84    pub x_pm1b_control_block: GenericAddressStructure,
85    pub x_pm2_control_block: GenericAddressStructure,
86    pub x_pm_timer_block: GenericAddressStructure,
87    pub x_gpe0_block: GenericAddressStructure,
88    pub x_gpe1_block: GenericAddressStructure,
89}
90
91impl Fadt {
92    /// Finds the FADT in the given `AcpiTables` and returns a reference to it.
93    pub fn get() -> Option<&'static Fadt> {
94        unsafe { super::find_table(FADT_SIGNATURE).map(|ptr| &*(ptr as *const Fadt)) }
95    }
96}