The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
13
#include "
common/boot/boot_info.h
"
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. */
21
typedef
struct
22
{
23
uint8_t
id
;
24
uint32_t
address
;
// physical address of its registers
25
uint32_t
gsi_base
;
// the first global system interrupt it handles
26
}
acpi_ioapic_t
;
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
*/
32
typedef
struct
33
{
34
uint8_t
source
;
35
uint32_t
gsi
;
36
bool
active_low
;
37
bool
level_triggered
;
38
}
acpi_iso_t
;
39
40
/** what the kernel takes from the ACPI tables. */
41
typedef
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
47
bool
has_madt
;
48
uint32_t
lapic_address
;
// physical address of the local APIC
49
bool
has_8259
;
// PCAT_COMPAT: there are 8259 PICs too
50
uint32_t
cpu_count
;
51
uint8_t
cpu_apic_ids
[
ACPI_MAX_CPUS
];
52
uint32_t
ioapic_count
;
53
acpi_ioapic_t
ioapics
[
ACPI_MAX_IOAPICS
];
54
uint32_t
iso_count
;
55
acpi_iso_t
isos
[
ACPI_MAX_ISOS
];
56
57
// FADT
58
bool
has_reset_register
;
59
uint8_t
reset_space
;
// 0: memory, 1: I/O port, 2: PCI configuration
60
uint64_t
reset_address
;
61
uint8_t
reset_value
;
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)
65
uint16_t
pm1b_control
;
66
bool
has_s5
;
// the _S5 sleep types were found in the DSDT
67
uint8_t
s5_type_a
;
68
uint8_t
s5_type_b
;
69
70
// HPET and MCFG
71
uint64_t
hpet_address
;
// 0: none
72
uint64_t
mcfg_address
;
// the PCI express configuration space, 0: none
73
}
acpi_info_t
;
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
*/
81
bool
acpi_init
(
const
boot_info_t
*boot);
82
83
/**
84
* what acpi_init found (present is false if it found nothing).
85
*/
86
const
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
*/
95
uint32_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
*/
101
void
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
*/
108
void
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
*/
115
bool
acpi_find_s5
(
const
uint8_t
*aml,
uint32_t
length,
uint8_t
*type_a,
uint8_t
*type_b);
acpi_init
bool acpi_init(const boot_info_t *boot)
find and read the tables.
Definition
acpi.c:334
acpi_reboot
void acpi_reboot(void)
restart the machine: the FADT reset register, then the keyboard controller, then a triple fault.
Definition
acpi.c:482
acpi_info
const acpi_info_t * acpi_info(void)
what acpi_init found (present is false if it found nothing).
Definition
acpi.c:378
acpi_power_off
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
acpi_irq_to_gsi
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
acpi_find_s5
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
ACPI_MAX_ISOS
#define ACPI_MAX_ISOS
Definition
acpi.h:18
ACPI_MAX_CPUS
#define ACPI_MAX_CPUS
Definition
acpi.h:16
ACPI_MAX_IOAPICS
#define ACPI_MAX_IOAPICS
Definition
acpi.h:17
boot_info.h
stdint.h
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uint8_t
unsigned char uint8_t
Definition
fb.h:18
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
uint16_t
unsigned short uint16_t
Definition
stdint.h:13
__attribute__
ELF32 file header.
Definition
elf.h:51
acpi_info_t
what the kernel takes from the ACPI tables.
Definition
acpi.h:42
acpi_info_t::isos
acpi_iso_t isos[ACPI_MAX_ISOS]
Definition
acpi.h:55
acpi_info_t::iso_count
uint32_t iso_count
Definition
acpi.h:54
acpi_info_t::acpi_enable
uint8_t acpi_enable
Definition
acpi.h:63
acpi_info_t::mcfg_address
uint64_t mcfg_address
Definition
acpi.h:72
acpi_info_t::present
bool present
Definition
acpi.h:43
acpi_info_t::has_s5
bool has_s5
Definition
acpi.h:66
acpi_info_t::has_madt
bool has_madt
Definition
acpi.h:47
acpi_info_t::s5_type_a
uint8_t s5_type_a
Definition
acpi.h:67
acpi_info_t::ioapics
acpi_ioapic_t ioapics[ACPI_MAX_IOAPICS]
Definition
acpi.h:53
acpi_info_t::hpet_address
uint64_t hpet_address
Definition
acpi.h:71
acpi_info_t::cpu_apic_ids
uint8_t cpu_apic_ids[ACPI_MAX_CPUS]
Definition
acpi.h:51
acpi_info_t::ioapic_count
uint32_t ioapic_count
Definition
acpi.h:52
acpi_info_t::s5_type_b
uint8_t s5_type_b
Definition
acpi.h:68
acpi_info_t::has_reset_register
bool has_reset_register
Definition
acpi.h:58
acpi_info_t::reset_value
uint8_t reset_value
Definition
acpi.h:61
acpi_info_t::reset_space
uint8_t reset_space
Definition
acpi.h:59
acpi_info_t::has_8259
bool has_8259
Definition
acpi.h:49
acpi_info_t::pm1b_control
uint16_t pm1b_control
Definition
acpi.h:65
acpi_info_t::cpu_count
uint32_t cpu_count
Definition
acpi.h:50
acpi_info_t::reset_address
uint64_t reset_address
Definition
acpi.h:60
acpi_info_t::pm1a_control
uint16_t pm1a_control
Definition
acpi.h:64
acpi_info_t::smi_command
uint32_t smi_command
Definition
acpi.h:62
acpi_info_t::lapic_address
uint32_t lapic_address
Definition
acpi.h:48
acpi_info_t::revision
uint8_t revision
Definition
acpi.h:44
acpi_ioapic_t
one I/O APIC from the MADT.
Definition
acpi.h:22
acpi_ioapic_t::gsi_base
uint32_t gsi_base
Definition
acpi.h:25
acpi_ioapic_t::address
uint32_t address
Definition
acpi.h:24
acpi_ioapic_t::id
uint8_t id
Definition
acpi.h:23
acpi_iso_t
an interrupt source override from the MADT: ISA IRQ source is global system interrupt gsi,...
Definition
acpi.h:33
acpi_iso_t::level_triggered
bool level_triggered
Definition
acpi.h:37
acpi_iso_t::active_low
bool active_low
Definition
acpi.h:36
acpi_iso_t::gsi
uint32_t gsi
Definition
acpi.h:35
acpi_iso_t::source
uint8_t source
Definition
acpi.h:34
boot_info_t
information the bootloader hands to the kernel.
Definition
boot_info.h:21
src
kernel
acpi
acpi.h
Generated by
1.18.0