The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
acpi.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file acpi.h
5 * @brief the ACPI tables: RSDP, RSDT/XSDT, MADT, FADT, HPET and MCFG.
6 *
7 * the kernel reads the static tables only. it has no AML interpreter, so it
8 * cannot run the DSDT: no device enumeration through ACPI. power-off reads
9 * only the _S5 package from the DSDT bytes. reboot uses the FADT reset
10 * register.
11 */
12
14#include "common/stdint.h"
15
16#define ACPI_MAX_CPUS 64 // CPU_MAX in kernel/cpu/cpu.h
17#define ACPI_MAX_IOAPICS 4
18#define ACPI_MAX_ISOS 16
19
20/** one I/O APIC from the MADT. */
21typedef struct
22{
24 uint32_t address; // physical address of its registers
25 uint32_t gsi_base; // the first global system interrupt it handles
27
28/**
29 * an interrupt source override from the MADT: ISA IRQ source is global
30 * system interrupt gsi, with the given polarity and trigger mode.
31 */
39
40/** what the kernel takes from the ACPI tables. */
41typedef struct
42{
43 bool present; // an RSDP with a valid checksum was found
44 uint8_t revision; // 0 for ACPI 1.0, 2 or more for XSDT tables
45
46 // MADT
48 uint32_t lapic_address; // physical address of the local APIC
49 bool has_8259; // PCAT_COMPAT: there are 8259 PICs too
56
57 // FADT
59 uint8_t reset_space; // 0: memory, 1: I/O port, 2: PCI configuration
62 uint32_t smi_command; // the port to give ACPI to the OS, 0: none
63 uint8_t acpi_enable; // the value for it
64 uint16_t pm1a_control; // the PM1 control ports (0: none)
66 bool has_s5; // the _S5 sleep types were found in the DSDT
69
70 // HPET and MCFG
72 uint64_t mcfg_address; // the PCI express configuration space, 0: none
74
75/**
76 * find and read the tables. the RSDP comes from the bootloader if it gave
77 * one, else from a scan of the BIOS areas. call after mmio_init.
78 * @param boot the boot information (rsdp, rsdp_size).
79 * @return true if the tables were found.
80 */
81bool acpi_init(const boot_info_t *boot);
82
83/**
84 * what acpi_init found (present is false if it found nothing).
85 */
86const acpi_info_t *acpi_info(void);
87
88/**
89 * the global system interrupt of a legacy ISA IRQ, after the MADT
90 * overrides (for example IRQ 0 is often GSI 2).
91 * @param irq an ISA IRQ, 0 to 15.
92 * @param active_low receives the polarity (may be NULL).
93 * @param level receives the trigger mode (may be NULL).
94 */
95uint32_t acpi_irq_to_gsi(uint8_t irq, bool *active_low, bool *level);
96
97/**
98 * restart the machine: the FADT reset register, then the keyboard
99 * controller, then a triple fault. does not return.
100 */
101void acpi_reboot(void) __attribute__((noreturn));
102
103/**
104 * turn the machine off: the ACPI S5 state (the _S5 sleep types into the
105 * PM1 control registers), then the QEMU and Bochs ports. if all fail, the
106 * CPU halts.
107 */
108void acpi_power_off(void) __attribute__((noreturn));
109
110/**
111 * find the S5 sleep types in DSDT bytes (the AML of "Name (_S5, Package
112 * () {a, b, ...})"), without an AML interpreter.
113 * @return false if there is no such package.
114 */
115bool acpi_find_s5(const uint8_t *aml, uint32_t length, uint8_t *type_a, uint8_t *type_b);
bool acpi_init(const boot_info_t *boot)
find and read the tables.
Definition acpi.c:334
void acpi_reboot(void)
restart the machine: the FADT reset register, then the keyboard controller, then a triple fault.
Definition acpi.c:482
const acpi_info_t * acpi_info(void)
what acpi_init found (present is false if it found nothing).
Definition acpi.c:378
void acpi_power_off(void)
turn the machine off: the ACPI S5 state (the _S5 sleep types into the PM1 control registers),...
Definition acpi.c:454
uint32_t acpi_irq_to_gsi(uint8_t irq, bool *active_low, bool *level)
the global system interrupt of a legacy ISA IRQ, after the MADT overrides (for example IRQ 0 is often...
Definition acpi.c:383
bool acpi_find_s5(const uint8_t *aml, uint32_t length, uint8_t *type_a, uint8_t *type_b)
find the S5 sleep types in DSDT bytes (the AML of "Name (_S5, Package() {a, b, ......
Definition acpi.c:177
#define ACPI_MAX_ISOS
Definition acpi.h:18
#define ACPI_MAX_CPUS
Definition acpi.h:16
#define ACPI_MAX_IOAPICS
Definition acpi.h:17
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
unsigned short uint16_t
Definition stdint.h:13
ELF32 file header.
Definition elf.h:51
what the kernel takes from the ACPI tables.
Definition acpi.h:42
acpi_iso_t isos[ACPI_MAX_ISOS]
Definition acpi.h:55
uint32_t iso_count
Definition acpi.h:54
uint8_t acpi_enable
Definition acpi.h:63
uint64_t mcfg_address
Definition acpi.h:72
bool present
Definition acpi.h:43
bool has_s5
Definition acpi.h:66
bool has_madt
Definition acpi.h:47
uint8_t s5_type_a
Definition acpi.h:67
acpi_ioapic_t ioapics[ACPI_MAX_IOAPICS]
Definition acpi.h:53
uint64_t hpet_address
Definition acpi.h:71
uint8_t cpu_apic_ids[ACPI_MAX_CPUS]
Definition acpi.h:51
uint32_t ioapic_count
Definition acpi.h:52
uint8_t s5_type_b
Definition acpi.h:68
bool has_reset_register
Definition acpi.h:58
uint8_t reset_value
Definition acpi.h:61
uint8_t reset_space
Definition acpi.h:59
bool has_8259
Definition acpi.h:49
uint16_t pm1b_control
Definition acpi.h:65
uint32_t cpu_count
Definition acpi.h:50
uint64_t reset_address
Definition acpi.h:60
uint16_t pm1a_control
Definition acpi.h:64
uint32_t smi_command
Definition acpi.h:62
uint32_t lapic_address
Definition acpi.h:48
uint8_t revision
Definition acpi.h:44
one I/O APIC from the MADT.
Definition acpi.h:22
uint32_t gsi_base
Definition acpi.h:25
uint32_t address
Definition acpi.h:24
uint8_t id
Definition acpi.h:23
an interrupt source override from the MADT: ISA IRQ source is global system interrupt gsi,...
Definition acpi.h:33
bool level_triggered
Definition acpi.h:37
bool active_low
Definition acpi.h:36
uint32_t gsi
Definition acpi.h:35
uint8_t source
Definition acpi.h:34
information the bootloader hands to the kernel.
Definition boot_info.h:21