PatchworkOS  321f6ec
A non-POSIX operating system.
Loading...
Searching...
No Matches
tables.h
Go to the documentation of this file.
1#pragma once
2
3#include <modules/acpi/acpi.h>
4
5/**
6 * @brief System Description Tables
7 * @defgroup modules_acpi_tables Tables
8 * @ingroup modules_acpi
9 *
10 * This module defines the ACPI tables found in the ACPI specification, tables defined outside of the specification, for
11 * example, MCFG is defined in their own files.
12 *
13 * @{
14 */
15
16/**
17 * @brief Enum for the `fadt_t::bootArchFlags` field.
18 */
23
24/**
25 * @brief FADT generic Address
26 * @struct fadt_gas_t
27 *
28 */
37
38/**
39 * @brief Fixed ACPI Description Table
40 * @struct fadt_t
41 *
42 * @see Section 5.2.9 table 5.9 of the ACPI specification for more details.
43 */
99
100/**
101 * @brief FADT table signature
102 */
103#define FADT_SIGNATURE "FACP"
104
105/**
106 * @brief Multiple APIC Description Table flags.
107 *
108 * @see Section 5.2.12 table 5.20 of the ACPI specification for more details.
109 */
111
112#define MADT_FLAG_PCAT_COMPAT ((madt_flags_t)(1 << 0))
113
114/**
115 * @brief MADT Interrupt Controller Types.
116 *
117 * @see Section 5.2.12 table 5.21 of the ACPI specification for more details.
118 */
120
121#define INTERRUPT_CONTROLLER_PROCESSOR_LOCAL_APIC ((interrupt_controller_type_t)0)
122#define INTERRUPT_CONTROLLER_IO_APIC ((interrupt_controller_type_t)1)
123
124/**
125 * @brief MADT Interrupt Controller Header
126 * @struct madt_interrupt_controller_header_t
127 */
133
134/**
135 * @brief MADT Processor Local APIC flags
136 *
137 * @see Section 5.2.12.2 table 5.23 of the ACPI specification for more details.
138 */
140
141#define PROCESSOR_LOCAL_APIC_ENABLED (1 << 0)
142#define PROCESSOR_LOCAL_APIC_ONLINE_CAPABLE (1 << 1)
143
144/**
145 * @brief Processor Local APIC
146 * @struct processor_local_apic_t
147 *
148 * @see Section 5.2.12.2 table 5.22 of the ACPI specification for more details.
149 */
157
158/**
159 * @brief IO APIC
160 * @struct ioapic_t
161 *
162 * @see Section 5.2.12.3 table 5.24 of the ACPI specification for more details.
163 */
172
173/**
174 * @brief Multiple APIC Description Table
175 * @struct madt_t
176 *
177 * @see Section 5.2.12 table 5.19 of the ACPI specification for more details.
178 */
186
187/**
188 * @brief Iterate over all MADT interrupt controllers
189 *
190 * @param madt The MADT table to iterate over.
191 * @param ic A pointer to a madt_interrupt_controller_header_t* that will be set to the current interrupt controller.
192 */
193#define MADT_FOR_EACH(madt, ic) \
194 for (ic = (typeof(ic))madt->interruptControllers; (uint8_t*)ic < (uint8_t*)madt + madt->header.length && \
195 (uint8_t*)ic + sizeof(interrupt_controller_header_t) <= (uint8_t*)madt + madt->header.length && \
196 (uint8_t*)ic + ic->header.length <= (uint8_t*)madt + madt->header.length; \
197 ic = (typeof(ic))((uint8_t*)ic + ic->header.length))
198
199/**
200 * @brief MADT table signature
201 */
202#define MADT_SIGNATURE "APIC"
203
204/**
205 * @brief Differentiated System Description Table
206 * @struct dsdt_t
207 *
208 * @see Section 5.2.11.1 table 5.17 of the ACPI specification for more details.
209 */
210typedef struct PACKED
211{
213 uint8_t definitionBlock[];
214} dsdt_t;
215
216/**
217 * @brief DSDT table signature
218 */
219#define DSDT_SIGNATURE "DSDT"
220
221/**
222 * @brief Secondary System Description Table
223 * @struct ssdt_t
224 *
225 * @see Section 5.2.11.2 table 5.18 of the ACPI specification for more details.
226 */
227typedef struct PACKED
228{
230 uint8_t definitionBlock[];
231} ssdt_t;
232
233/**
234 * @brief SSDT table signature
235 *
236 * Note that there might be multiple SSDT tables.
237 */
238#define SSDT_SIGNATURE "SSDT"
239
240/**
241 * @brief Cached ACPI table
242 * @struct acpi_cached_table_t
243 *
244 * This structure is used to cache ACPI tables that have been loaded.
245 */
246typedef struct
247{
249 dentry_t* file; ///< The sysfs file representing the table.
251
252/**
253 * @brief Initialize ACPI tables and call their init handlers.
254 *
255 * @param rsdp Pointer to the RSDP structure.
256 * @return On success, `0`. On failure, `ERR`.
257 */
259
260/**
261 * @brief Expose ACPI tables to sysfs.
262 *
263 * @return On success, `0`. On failure, `ERR`.
264 */
266
267/**
268 * @brief Lookup the n'th table matching the signature.
269 *
270 * @param signature The signature of the table to look up.
271 * @param minSize The minimum size of the table to look up, should usually be `sizeof()` of the table struct.
272 * @param n The index of the table to look up (0 indexed).
273 * @return On success, a pointer to the table. On error, `NULL` and `errno` is set to:
274 * - `EINVAL`: Invalid parameters.
275 * - `ENOENT`: No table matching the signature was found.
276 * - `ERANGE`: A table was found, but not enough matching tables to satisfy `n`.
277 * - `EILSEQ`: The table found was smaller than `minSize`.
278 */
279sdt_header_t* acpi_tables_lookup(const char* signature, uint64_t minSize, uint64_t n);
280
281/** @} */
#define PACKED
GCC packed attribute.
Definition defs.h:32
fadt_boot_arch_flags_t
Enum for the fadt_t::bootArchFlags field.
Definition tables.h:20
uint32_t madt_flags_t
Multiple APIC Description Table flags.
Definition tables.h:110
uint32_t processor_local_apic_flags_t
MADT Processor Local APIC flags.
Definition tables.h:139
uint64_t acpi_tables_init(rsdp_t *rsdp)
Initialize ACPI tables and call their init handlers.
Definition tables.c:195
sdt_header_t * acpi_tables_lookup(const char *signature, uint64_t minSize, uint64_t n)
Lookup the n'th table matching the signature.
Definition tables.c:260
uint64_t acpi_tables_expose(void)
Expose ACPI tables to sysfs.
Definition tables.c:221
uint8_t interrupt_controller_type_t
MADT Interrupt Controller Types.
Definition tables.h:119
@ FADT_BOOT_ARCH_PS2_EXISTS
Definition tables.h:21
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
Cached ACPI table.
Definition tables.h:247
sdt_header_t * table
Definition tables.h:248
dentry_t * file
The sysfs file representing the table.
Definition tables.h:249
Directory entry structure.
Definition dentry.h:84
Differentiated System Description Table.
Definition tables.h:211
sdt_header_t header
Definition tables.h:212
FADT generic Address.
Definition tables.h:30
uint8_t bitWidth
Definition tables.h:32
uint64_t address
Definition tables.h:35
uint8_t bitOffset
Definition tables.h:33
uint8_t addressSpace
Definition tables.h:31
uint8_t accessSize
Definition tables.h:34
Fixed ACPI Description Table.
Definition tables.h:45
uint32_t gpe0Block
Definition tables.h:63
uint16_t sciInterrupt
Definition tables.h:51
uint8_t preferredPowerManagementProfile
Definition tables.h:50
fadt_gas_t xPm2ControlBlock
Definition tables.h:94
uint8_t cStateControl
Definition tables.h:72
uint8_t gpe0Length
Definition tables.h:69
uint8_t reserved
Definition tables.h:49
uint32_t gpe1Block
Definition tables.h:64
fadt_gas_t xPm1aControlBlock
Definition tables.h:92
uint32_t pm1aControlBlock
Definition tables.h:59
uint8_t pm1EventLength
Definition tables.h:65
fadt_gas_t xGpe0Block
Definition tables.h:96
uint8_t pm1ControlLength
Definition tables.h:66
uint8_t pstateControl
Definition tables.h:56
uint32_t firmwareControl
Definition tables.h:47
uint8_t s4BiosReq
Definition tables.h:55
uint8_t gpe1Length
Definition tables.h:70
uint8_t dayAlarm
Definition tables.h:79
uint32_t pm2ControlBlock
Definition tables.h:61
uint32_t pmTimerBlock
Definition tables.h:62
uint32_t pm1bEventBlock
Definition tables.h:58
uint32_t flags
Definition tables.h:84
uint32_t pm1aEventBlock
Definition tables.h:57
uint8_t pm2ControlLength
Definition tables.h:67
uint8_t reserved2
Definition tables.h:83
uint8_t century
Definition tables.h:81
fadt_gas_t xPmTimerBlock
Definition tables.h:95
uint8_t acpiDisable
Definition tables.h:54
uint64_t xDsdt
Extended pointer to dsdt, should be used if dsdt is 0.
Definition tables.h:89
uint8_t gpe1Base
Definition tables.h:71
fadt_gas_t xPm1bEventBlock
Definition tables.h:91
uint16_t worstC2Latency
Definition tables.h:73
uint32_t dsdt
Definition tables.h:48
uint8_t pmTimerLength
Definition tables.h:68
uint32_t smiCommandPort
Definition tables.h:52
uint8_t acpiEnable
Definition tables.h:53
uint16_t bootArchFlags
Definition tables.h:82
fadt_gas_t xPm1aEventBlock
Definition tables.h:90
fadt_gas_t xPm1bControlBlock
Definition tables.h:93
uint8_t dutyOffset
Definition tables.h:77
uint32_t pm1bControlBlock
Definition tables.h:60
fadt_gas_t resetReg
Definition tables.h:85
uint16_t flushStride
Definition tables.h:76
uint64_t xFirmwareControl
Definition tables.h:88
uint16_t flushSize
Definition tables.h:75
sdt_header_t header
Definition tables.h:46
uint8_t dutyWidth
Definition tables.h:78
uint16_t worstC3Latency
Definition tables.h:74
uint8_t monthAlarm
Definition tables.h:80
fadt_gas_t xGpe1Block
Definition tables.h:97
uint8_t resetValue
Definition tables.h:86
interrupt_controller_type_t type
Definition tables.h:130
IO APIC.
Definition tables.h:165
uint32_t ioApicAddress
Definition tables.h:169
uint8_t ioApicId
Definition tables.h:167
uint32_t globalSystemInterruptBase
Definition tables.h:170
interrupt_controller_header_t header
Definition tables.h:166
uint8_t reserved
Definition tables.h:168
Multiple APIC Description Table.
Definition tables.h:180
madt_flags_t flags
Definition tables.h:183
sdt_header_t header
Definition tables.h:181
uint32_t localInterruptControllerAddress
Definition tables.h:182
Processor Local APIC.
Definition tables.h:151
interrupt_controller_header_t header
Definition tables.h:152
uint8_t acpiProcessorUid
Definition tables.h:153
Root System Description Pointer.
Definition acpi.h:114
System Description Table Header.
Definition acpi.h:90
Secondary System Description Table.
Definition tables.h:228
sdt_header_t header
Definition tables.h:229