blob: 1684e71840a9af4f46be3b5fe24b9a9bc1ab8e3e [file] [log] [blame]
Furquan Shaikhe0844632020-05-02 10:23:37 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Furquan Shaikhe0844632020-05-02 10:23:37 -07002
3/*
4 * coreboot ACPI support - headers and defines.
5 */
6
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07007#ifndef __ACPI_ACPI_H__
8#define __ACPI_ACPI_H__
Furquan Shaikhe0844632020-05-02 10:23:37 -07009
10/*
11 * The type and enable fields are common in ACPI, but the
12 * values themselves are hardware implementation defined.
13 */
14#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES)
15 #define SLP_EN (1 << 13)
16 #define SLP_TYP_SHIFT 10
17 #define SLP_TYP (7 << SLP_TYP_SHIFT)
18 #define SLP_TYP_S0 0
19 #define SLP_TYP_S1 1
20 #define SLP_TYP_S3 5
21 #define SLP_TYP_S4 6
22 #define SLP_TYP_S5 7
23#elif CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
24 #define SLP_EN (1 << 13)
25 #define SLP_TYP_SHIFT 10
26 #define SLP_TYP (7 << SLP_TYP_SHIFT)
27 #define SLP_TYP_S0 0
28 #define SLP_TYP_S1 1
29 #define SLP_TYP_S3 3
30 #define SLP_TYP_S4 4
31 #define SLP_TYP_S5 5
32#endif
33
34#define ACPI_TABLE_CREATOR "COREBOOT" /* Must be exactly 8 bytes long! */
35#define OEM_ID "COREv4" /* Must be exactly 6 bytes long! */
Elyes HAOUAS288426d2020-10-01 16:52:26 +020036#define ACPI_DSDT_REV_1 0x01 /* DSDT revision: ACPI v1 */
Elyes HAOUAS7f53ec62020-10-05 16:33:52 +020037#define ACPI_DSDT_REV_2 0x02 /* DSDT revision: ACPI v2.0 and greater */
Furquan Shaikhe0844632020-05-02 10:23:37 -070038
39#if !defined(__ASSEMBLER__) && !defined(__ACPI__)
40#include <commonlib/helpers.h>
41#include <device/device.h>
42#include <uuid.h>
43#include <cper.h>
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +020044#include <romstage_handoff.h>
Furquan Shaikhe0844632020-05-02 10:23:37 -070045#include <types.h>
46
Tim Wawrzynczak05a6d5c2021-11-24 09:54:59 -070047enum acpi_device_sleep_states {
48 ACPI_DEVICE_SLEEP_D0 = 0,
49 ACPI_DEVICE_SLEEP_D1 = 1,
50 ACPI_DEVICE_SLEEP_D2 = 2,
51 ACPI_DEVICE_SLEEP_D3 = 3,
52 ACPI_DEVICE_SLEEP_D3_HOT = ACPI_DEVICE_SLEEP_D3,
53 ACPI_DEVICE_SLEEP_D3_COLD = 4,
Eran Mitrani4c9440c2022-11-29 17:46:38 -080054 ACPI_DEVICE_SLEEP_NONE = 5,
Tim Wawrzynczak05a6d5c2021-11-24 09:54:59 -070055};
56
Furquan Shaikhe0844632020-05-02 10:23:37 -070057#define RSDP_SIG "RSD PTR " /* RSDT pointer signature */
58#define ASLC "CORE" /* Must be exactly 4 bytes long! */
59
Raul E Rangel1c0b9f22020-07-09 11:58:38 -060060#define ACPI_NAME_BUFFER_SIZE 5 /* 4 chars + 1 NUL */
61
Furquan Shaikhe0844632020-05-02 10:23:37 -070062/*
63 * The assigned ACPI ID for the coreboot project is 'BOOT'
64 * http://www.uefi.org/acpi_id_list
65 */
66#define COREBOOT_ACPI_ID "BOOT" /* ACPI ID for coreboot HIDs */
67
68/* List of ACPI HID that use the coreboot ACPI ID */
69enum coreboot_acpi_ids {
70 COREBOOT_ACPI_ID_CBTABLE = 0x0000, /* BOOT0000 */
CoolStarc7b27b32023-07-10 18:03:40 -070071 COREBOOT_ACPI_ID_IGD_GMBUS_ARB = 0x0001, /* BOOT0001 */
72 COREBOOT_ACPI_ID_IGD_GMBUS_LINK = 0x0002, /* BOOT0002 */
CoolStarce84a342023-10-15 16:51:54 -070073 COREBOOT_ACPI_ID_AMDGFX_ACP = 0x0003, /* BOOT0003 */
Furquan Shaikhe0844632020-05-02 10:23:37 -070074 COREBOOT_ACPI_ID_MAX = 0xFFFF, /* BOOTFFFF */
75};
76
77enum acpi_tables {
Naresh Solanki18051b32023-11-17 01:19:27 +053078 /* Alphabetic list of Tables defined by ACPI and used by coreboot */
79 BERT, /* Boot Error Record Table */
80 CEDT, /* CXL Early Discovery Table */
81 DBG2, /* Debug Port Table 2 */
82 DMAR, /* DMA Remapping Table */
83 DSDT, /* Differentiated System Description Table */
84 ECDT, /* Embedded Controller Boot Resources Table */
85 EINJ, /* Error Injection Table */
86 FACS, /* Firmware ACPI Control Structure */
87 FADT, /* Fixed ACPI Description Table */
88 GTDT, /* Generic Timer Description Table */
89 HEST, /* Hardware Error Source Table */
90 HMAT, /* Heterogeneous Memory Attribute Table */
91 HPET, /* High Precision Event Timer Table */
92 IVRS, /* I/O Virtualization Reporting Structure */
93 LPIT, /* Low Power Idle Table */
94 MADT, /* Multiple APIC Description Table */
95 MCFG, /* PCI Express Memory Mapped Configuration */
David Milosevicd9822742023-09-22 14:34:28 +020096 PPTT, /* Processor Properties Topology Table */
Naresh Solanki18051b32023-11-17 01:19:27 +053097 RSDP, /* Root System Description Pointer */
98 RSDT, /* Root System Description Table */
99 SLIT, /* System Locality Distance Information Table */
100 SPCR, /* Serial Port Console Redirection Table */
101 SRAT, /* System Resource Affinity Table */
102 SSDT, /* Secondary System Description Table */
103 TCPA, /* Trusted Computing Platform Alliance Table */
104 TPM2, /* Trusted Platform Module 2.0 Table */
105 XSDT, /* Extended System Description Table */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700106 /* Additional proprietary tables used by coreboot */
Naresh Solanki18051b32023-11-17 01:19:27 +0530107 CRAT, /* Component Resource Attribute Table */
Naresh Solanki6920c6f2023-09-13 12:01:58 +0200108 IORT, /* Input Output Remapping Table */
Naresh Solanki18051b32023-11-17 01:19:27 +0530109 NHLT, /* Non HD audio Link Table */
110 SPMI, /* Server Platform Management Interface table */
111 VFCT /* VBIOS Fetch Table */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700112};
113
114/* RSDP (Root System Description Pointer) */
115typedef struct acpi_rsdp {
116 char signature[8]; /* RSDP signature */
117 u8 checksum; /* Checksum of the first 20 bytes */
118 char oem_id[6]; /* OEM ID */
119 u8 revision; /* RSDP revision */
120 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
121 u32 length; /* Total RSDP length (incl. extended part) */
122 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
123 u8 ext_checksum; /* Checksum of the whole table */
124 u8 reserved[3];
125} __packed acpi_rsdp_t;
126
127/* GAS (Generic Address Structure) */
128typedef struct acpi_gen_regaddr {
129 u8 space_id; /* Address space ID */
130 u8 bit_width; /* Register size in bits */
131 u8 bit_offset; /* Register bit offset */
132 u8 access_size; /* Access size since ACPI 2.0c */
133 u32 addrl; /* Register address, low 32 bits */
134 u32 addrh; /* Register address, high 32 bits */
135} __packed acpi_addr_t;
136
Elyes HAOUAS5f5fd852020-10-15 12:24:00 +0200137#define ACPI_ADDRESS_SPACE_MEMORY 0 /* System memory */
138#define ACPI_ADDRESS_SPACE_IO 1 /* System I/O */
139#define ACPI_ADDRESS_SPACE_PCI 2 /* PCI config space */
140#define ACPI_ADDRESS_SPACE_EC 3 /* Embedded controller */
141#define ACPI_ADDRESS_SPACE_SMBUS 4 /* SMBus */
142#define ACPI_ADDRESS_SPACE_CMOS 5 /* SystemCMOS */
143#define ACPI_ADDRESS_SPACE_PCI_BAR_TARGET 6 /* PciBarTarget */
144#define ACPI_ADDRESS_SPACE_IPMI 7 /* IPMI */
145#define ACPI_ADDRESS_SPACE_GENERAL_PURPOSE_IO 8 /* GeneralPurposeIO */
146#define ACPI_ADDRESS_SPACE_GENERIC_SERIAL_BUS 9 /* GenericSerialBus */
147#define ACPI_ADDRESS_SPACE_PCC 0x0A /* Platform Comm. Channel */
148#define ACPI_ADDRESS_SPACE_FIXED 0x7f /* Functional fixed hardware */
149#define ACPI_FFIXEDHW_VENDOR_INTEL 1 /* Intel */
150#define ACPI_FFIXEDHW_CLASS_HLT 0 /* C1 Halt */
151#define ACPI_FFIXEDHW_CLASS_IO_HLT 1 /* C1 I/O then Halt */
152#define ACPI_FFIXEDHW_CLASS_MWAIT 2 /* MWAIT Native C-state */
153#define ACPI_FFIXEDHW_FLAG_HW_COORD 1 /* Hardware Coordination bit */
154#define ACPI_FFIXEDHW_FLAG_BM_STS 2 /* BM_STS avoidance bit */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700155/* 0x80-0xbf: Reserved */
156/* 0xc0-0xff: OEM defined */
157
158/* Access size definitions for Generic address structure */
159#define ACPI_ACCESS_SIZE_UNDEFINED 0 /* Undefined (legacy reasons) */
160#define ACPI_ACCESS_SIZE_BYTE_ACCESS 1
161#define ACPI_ACCESS_SIZE_WORD_ACCESS 2
162#define ACPI_ACCESS_SIZE_DWORD_ACCESS 3
163#define ACPI_ACCESS_SIZE_QWORD_ACCESS 4
164
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200165/* Macros for common resource types */
166#define ACPI_REG_MSR(address, offset, width) \
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200167 (acpi_addr_t){ \
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200168 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
169 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
170 .addrl = address, \
171 .bit_offset = offset, \
172 .bit_width = width, \
173 }
174
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200175#define ACPI_REG_UNSUPPORTED (acpi_addr_t){0}
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200176
Furquan Shaikhe0844632020-05-02 10:23:37 -0700177/* Common ACPI HIDs */
178#define ACPI_HID_FDC "PNP0700"
179#define ACPI_HID_KEYBOARD "PNP0303"
180#define ACPI_HID_MOUSE "PNP0F03"
181#define ACPI_HID_COM "PNP0501"
182#define ACPI_HID_LPT "PNP0400"
183#define ACPI_HID_PNP "PNP0C02"
184#define ACPI_HID_CONTAINER "PNP0A05"
185
186/* Generic ACPI header, provided by (almost) all tables */
187typedef struct acpi_table_header {
188 char signature[4]; /* ACPI signature (4 ASCII characters) */
189 u32 length; /* Table length in bytes (incl. header) */
190 u8 revision; /* Table version (not ACPI version!) */
191 u8 checksum; /* To make sum of entire table == 0 */
192 char oem_id[6]; /* OEM identification */
193 char oem_table_id[8]; /* OEM table identification */
194 u32 oem_revision; /* OEM revision number */
195 char asl_compiler_id[4]; /* ASL compiler vendor ID */
196 u32 asl_compiler_revision; /* ASL compiler revision number */
197} __packed acpi_header_t;
198
199/* A maximum number of 32 ACPI tables ought to be enough for now. */
200#define MAX_ACPI_TABLES 32
201
202/* RSDT (Root System Description Table) */
203typedef struct acpi_rsdt {
204 acpi_header_t header;
205 u32 entry[MAX_ACPI_TABLES];
206} __packed acpi_rsdt_t;
207
208/* XSDT (Extended System Description Table) */
209typedef struct acpi_xsdt {
210 acpi_header_t header;
211 u64 entry[MAX_ACPI_TABLES];
212} __packed acpi_xsdt_t;
213
214/* HPET timers */
215typedef struct acpi_hpet {
216 acpi_header_t header;
217 u32 id;
218 acpi_addr_t addr;
219 u8 number;
220 u16 min_tick;
221 u8 attributes;
222} __packed acpi_hpet_t;
223
224/* MCFG (PCI Express MMIO config space BAR description table) */
225typedef struct acpi_mcfg {
226 acpi_header_t header;
227 u8 reserved[8];
228} __packed acpi_mcfg_t;
229
230typedef struct acpi_tcpa {
231 acpi_header_t header;
232 u16 platform_class;
233 u32 laml;
234 u64 lasa;
235} __packed acpi_tcpa_t;
236
237typedef struct acpi_tpm2 {
238 acpi_header_t header;
239 u16 platform_class;
240 u8 reserved[2];
241 u64 control_area;
242 u32 start_method;
243 u8 msp[12];
244 u32 laml;
245 u64 lasa;
246} __packed acpi_tpm2_t;
247
248typedef struct acpi_mcfg_mmconfig {
Naresh Solanki4d0b1842023-08-25 12:58:11 +0200249 u64 base_address;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700250 u16 pci_segment_group_number;
251 u8 start_bus_number;
252 u8 end_bus_number;
253 u8 reserved[4];
254} __packed acpi_mcfg_mmconfig_t;
255
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700256/*
Jonathan Zhang3dcafa82022-05-11 13:11:20 -0700257 * CEDT (CXL Early Discovery Table)
258 * CXL spec 2.0 section 9.14.1
259 */
260typedef struct acpi_cedt {
261 acpi_header_t header;
262 /* Followed by CEDT structures[n] */
263} __packed acpi_cedt_t;
264
265#define ACPI_CEDT_STRUCTURE_CHBS 0
266#define ACPI_CEDT_STRUCTURE_CFMWS 1
267
268#define ACPI_CEDT_CHBS_CXL_VER_1_1 0x00
269#define ACPI_CEDT_CHBS_CXL_VER_2_0 0x01
270
271/* CHBS: CXL Host Bridge Structure */
272typedef struct acpi_cedt_chbs {
273 u8 type; /* Always 0, other values reserved */
274 u8 resv1;
275 u16 length; /* Length in bytes (32) */
276 u32 uid; /* CXL Host Bridge Unique ID */
277 u32 cxl_ver;
278 u32 resv2;
279 /*
280 * For CXL 1.1, the base is Downstream Port Root Complex Resource Block;
281 * For CXL 2.0, the base is CXL Host Bridge Component Registers.
282 */
283 u64 base;
284 u64 len;
285} __packed acpi_cedt_chbs_t;
286
287#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_2_MEM (1 << 0)
288#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_3_MEM (1 << 1)
289#define ACPI_CEDT_CFMWS_RESTRICTION_VOLATIL (1 << 2)
290#define ACPI_CEDT_CFMWS_RESTRICTION_PERSISTENT (1 << 3)
291#define ACPI_CEDT_CFMWS_RESTRICTION_FIXED (1 << 4)
292
293/* CFMWS: CXL Fixed Memory Window Structure */
294typedef struct acpi_cedt_cfmws {
295 u8 type; /* Type (0) */
296 u8 resv1;
297 u16 length; /* Length in bytes (32) */
298 u32 resv2;
299 u64 base_hpa; /* Base of the HPA range, 256MB aligned */
300 u64 window_size; /* Number of bytes this window represents */
301 u8 eniw; /* Encoded Number of Interleave Ways */
302 u8 interleave_arithmetic; /* Standard Modulo arithmetic (0) */
303 u16 resv3;
304 u32 hbig; /* Host Bridge Interleave Granularity */
305 u16 restriction;
306 u16 qtg_id;
307 u32 interleave_target[]; /* Interleave Target List */
308} __packed acpi_cedt_cfmws_t;
309
310/*
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700311 * HMAT (Heterogeneous Memory Attribute Table)
312 * ACPI spec 6.4 section 5.2.27
313 */
314typedef struct acpi_hmat {
315 acpi_header_t header;
316 u32 resv;
317 /* Followed by HMAT table structure[n] */
318} __packed acpi_hmat_t;
319
320/* HMAT: Memory Proximity Domain Attributes structure */
321typedef struct acpi_hmat_mpda {
322 u16 type; /* Type (0) */
323 u16 resv;
324 u32 length; /* Length in bytes (40) */
325 u16 flags;
326 u16 resv1;
327 u32 proximity_domain_initiator;
328 u32 proximity_domain_memory;
329 u32 resv2;
330 u64 resv3;
331 u64 resv4;
332} __packed acpi_hmat_mpda_t;
333
334/* HMAT: System Locality Latency and Bandwidth Information structure */
335typedef struct acpi_hmat_sllbi {
336 u16 type; /* Type (1) */
337 u16 resv;
338 u32 length; /* Length in bytes */
339 u8 flags;
340 u8 data_type;
341 /*
342 * Transfer size defined as a 5-biased power of 2 exponent,
343 * when the bandwidth/latency value is achieved.
344 */
345 u8 min_transfer_size;
346 u8 resv1;
347 u32 num_initiator_domains;
348 u32 num_target_domains;
349 u32 resv2;
350 u64 entry_base_unit;
351 /* Followed by initiator proximity domain list */
352 /* Followed by target proximity domain list */
353 /* Followed by latency / bandwidth values */
354} __packed acpi_hmat_sllbi_t;
355
356/* HMAT: Memory Side Cache Information structure */
357typedef struct acpi_hmat_msci {
358 u16 type; /* Type (2) */
359 u16 resv;
360 u32 length; /* Length in bytes */
361 u32 domain; /* Proximity domain for the memory */
362 u32 resv1;
363 u64 cache_size;
364 /* Describes level, associativity, write policy, cache line size */
365 u32 cache_attributes;
366 u16 resv2;
367 /*
368 * Number of SMBIOS handlers that contribute to the
369 * memory side cache physical devices
370 */
371 u16 num_handlers;
372 /* Followed by SMBIOS handlers*/
373} __packed acpi_hmat_msci_t;
374
Furquan Shaikhe0844632020-05-02 10:23:37 -0700375/* SRAT (System Resource Affinity Table) */
376typedef struct acpi_srat {
377 acpi_header_t header;
378 u32 resv;
379 u64 resv1;
380 /* Followed by static resource allocation structure[n] */
381} __packed acpi_srat_t;
382
Jonathan Zhang3164b642021-04-21 17:51:31 -0700383#define ACPI_SRAT_STRUCTURE_LAPIC 0
384#define ACPI_SRAT_STRUCTURE_MEM 1
385#define ACPI_SRAT_STRUCTURE_GIA 5
386
Naresh Solanki76835cc2023-01-20 19:13:02 +0100387/* SRAT: Processor x2APIC Structure */
388typedef struct acpi_srat_x2apic {
389 u8 type; /* Type (0) */
390 u8 length; /* Length in bytes (16) */
391 u16 reserved; /* Reserved - Must be zero */
392 u32 proximity_domain; /* Proximity domain */
393 u32 x2apic_id; /* x2APIC ID */
394 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
395 u32 clock_domain; /* _CDM Clock Domain */
396 u32 reserved1; /* Reserved */
397} __packed acpi_srat_x2apic_t;
398
Furquan Shaikhe0844632020-05-02 10:23:37 -0700399/* SRAT: Processor Local APIC/SAPIC Affinity Structure */
400typedef struct acpi_srat_lapic {
401 u8 type; /* Type (0) */
402 u8 length; /* Length in bytes (16) */
403 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
404 u8 apic_id; /* Local APIC ID */
405 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
406 u8 local_sapic_eid; /* Local SAPIC EID */
407 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
408 u32 clock_domain; /* _CDM Clock Domain */
409} __packed acpi_srat_lapic_t;
410
411/* SRAT: Memory Affinity Structure */
412typedef struct acpi_srat_mem {
413 u8 type; /* Type (1) */
414 u8 length; /* Length in bytes (40) */
415 u32 proximity_domain; /* Proximity domain */
416 u16 resv;
417 u32 base_address_low; /* Mem range base address, low */
418 u32 base_address_high; /* Mem range base address, high */
419 u32 length_low; /* Mem range length, low */
420 u32 length_high; /* Mem range length, high */
421 u32 resv1;
422 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2,
423 * other bits reserved to 0
424 */
425 u32 resv2[2];
426} __packed acpi_srat_mem_t;
427
Jonathan Zhang3164b642021-04-21 17:51:31 -0700428/* SRAT: Generic Initiator Affinity Structure (ACPI spec 6.4 section 5.2.16.6) */
429typedef struct acpi_srat_gia {
430 u8 type; /* Type (5) */
431 u8 length; /* Length in bytes (32) */
432 u8 resv;
433 u8 dev_handle_type; /* Device handle type */
434 u32 proximity_domain; /*Proximity domain */
435 u8 dev_handle[16]; /* Device handle */
436 u32 flags;
437 u32 resv1;
438} __packed acpi_srat_gia_t;
439
440#define ACPI_SRAT_GIA_DEV_HANDLE_ACPI 0
441#define ACPI_SRAT_GIA_DEV_HANDLE_PCI 1
442
Furquan Shaikhe0844632020-05-02 10:23:37 -0700443/* SLIT (System Locality Distance Information Table) */
444typedef struct acpi_slit {
445 acpi_header_t header;
446 /* Followed by static resource allocation 8+byte[num*num] */
447} __packed acpi_slit_t;
448
449/* MADT (Multiple APIC Description Table) */
450typedef struct acpi_madt {
451 acpi_header_t header;
452 u32 lapic_addr; /* Local APIC address */
453 u32 flags; /* Multiple APIC flags */
454} __packed acpi_madt_t;
455
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100456/*
457 * LPIT (Low Power Idle Table)
458 * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017.
459 */
460typedef struct acpi_lpit {
461 acpi_header_t header;
462} __packed acpi_lpit_t;
463
464/* LPIT: LPI descriptor flags */
465typedef struct acpi_lpi_flags {
466 uint32_t disabled : 1;
467 uint32_t counter_not_available : 1;
468 uint32_t reserved : 30;
469} __packed acpi_lpi_desc_flags_t;
470
471/* LPIT: LPI descriptor types */
472enum acpi_lpi_desc_type {
473 ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00,
474 /* type >= 1 reserved */
475};
476
477/* LPIT: LPI descriptor header */
478typedef struct acpi_lpi_desc_hdr {
479 uint32_t type;
480 uint32_t length;
481 uint16_t uid;
482 uint16_t reserved;
483} __packed acpi_lpi_desc_hdr_t;
484
Sukumar Ghoraied1c03a2023-09-28 23:44:30 -0700485#define ACPI_LPIT_CTR_FREQ_TSC 0
Sukumar Ghoraibd9c5622023-10-07 23:19:34 -0700486
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100487
488/* LPIT: Native C-state instruction based LPI structure */
489typedef struct acpi_lpi_desc_ncst {
490 acpi_lpi_desc_hdr_t header;
491 acpi_lpi_desc_flags_t flags;
492 acpi_addr_t entry_trigger; /* Entry trigger C-state */
493 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
494 uint32_t max_latency; /* Worst case exit latency in microseconds */
495 acpi_addr_t residency_counter;
496 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
497} __packed acpi_lpi_desc_ncst_t;
498
Matt DeVillier7c04d0e2023-09-03 12:51:58 -0500499#define VFCT_VBIOS_CHECKSUM_OFFSET 0x21
500
Furquan Shaikhe0844632020-05-02 10:23:37 -0700501/* VFCT image header */
502typedef struct acpi_vfct_image_hdr {
503 u32 PCIBus;
504 u32 PCIDevice;
505 u32 PCIFunction;
506 u16 VendorID;
507 u16 DeviceID;
508 u16 SSVID;
509 u16 SSID;
510 u32 Revision;
511 u32 ImageLength;
Matt DeVillier7c04d0e2023-09-03 12:51:58 -0500512 u8 VbiosContent[]; // dummy - copy VBIOS here
Furquan Shaikhe0844632020-05-02 10:23:37 -0700513} __packed acpi_vfct_image_hdr_t;
514
515/* VFCT (VBIOS Fetch Table) */
516typedef struct acpi_vfct {
517 acpi_header_t header;
518 u8 TableUUID[16];
519 u32 VBIOSImageOffset;
520 u32 Lib1ImageOffset;
521 u32 Reserved[4];
522 acpi_vfct_image_hdr_t image_hdr;
523} __packed acpi_vfct_t;
524
525typedef struct acpi_ivrs_info {
526} __packed acpi_ivrs_info_t;
527
528/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
529typedef struct acpi_ivrs_ivhd {
530 uint8_t type;
531 uint8_t flags;
532 uint16_t length;
533 uint16_t device_id;
534 uint16_t capability_offset;
535 uint32_t iommu_base_low;
536 uint32_t iommu_base_high;
537 uint16_t pci_segment_group;
538 uint16_t iommu_info;
539 uint32_t iommu_feature_info;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200540 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700541} __packed acpi_ivrs_ivhd_t;
542
543/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
544typedef struct acpi_ivrs {
545 acpi_header_t header;
546 uint32_t iv_info;
547 uint32_t reserved[2];
548 struct acpi_ivrs_ivhd ivhd;
549} __packed acpi_ivrs_t;
550
Jason Glenesk61624b22020-11-02 20:06:23 -0800551/* CRAT (Component Resource Affinity Table Structure) */
552struct acpi_crat_header {
553 acpi_header_t header;
554 uint32_t total_entries;
555 uint16_t num_nodes;
556 uint8_t reserved[6];
557} __packed;
558
Furquan Shaikhe0844632020-05-02 10:23:37 -0700559/* IVHD Type 11h IOMMU Attributes */
560typedef struct ivhd11_iommu_attr {
561 uint32_t reserved1 : 13;
562 uint32_t perf_counters : 4;
563 uint32_t perf_counter_banks : 6;
564 uint32_t msi_num_ppr : 5;
565 uint32_t reserved2 : 4;
566} __packed ivhd11_iommu_attr_t;
567
568/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
569typedef struct acpi_ivrs_ivhd_11 {
570 uint8_t type;
571 uint8_t flags;
572 uint16_t length;
573 uint16_t device_id;
574 uint16_t capability_offset;
575 uint32_t iommu_base_low;
576 uint32_t iommu_base_high;
577 uint16_t pci_segment_group;
578 uint16_t iommu_info;
579 struct ivhd11_iommu_attr iommu_attributes;
580 uint32_t efr_reg_image_low;
581 uint32_t efr_reg_image_high;
582 uint32_t reserved[2];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200583 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700584} __packed acpi_ivrs_ivhd11_t;
585
586enum dev_scope_type {
587 SCOPE_PCI_ENDPOINT = 1,
588 SCOPE_PCI_SUB = 2,
589 SCOPE_IOAPIC = 3,
590 SCOPE_MSI_HPET = 4,
591 SCOPE_ACPI_NAMESPACE_DEVICE = 5
592};
593
594typedef struct dev_scope {
595 u8 type;
596 u8 length;
597 u8 reserved[2];
598 u8 enumeration;
599 u8 start_bus;
600 struct {
601 u8 dev;
602 u8 fn;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200603 } __packed path[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700604} __packed dev_scope_t;
605
606enum dmar_type {
607 DMAR_DRHD = 0,
608 DMAR_RMRR = 1,
609 DMAR_ATSR = 2,
610 DMAR_RHSA = 3,
John Zhao6edbb182021-03-24 11:55:09 -0700611 DMAR_ANDD = 4,
612 DMAR_SATC = 5
Furquan Shaikhe0844632020-05-02 10:23:37 -0700613};
614
615enum {
616 DRHD_INCLUDE_PCI_ALL = 1
617};
618
John Zhao091532d2021-04-17 16:03:21 -0700619enum {
620 ATC_REQUIRED = 1
621};
622
Furquan Shaikhe0844632020-05-02 10:23:37 -0700623enum dmar_flags {
624 DMAR_INTR_REMAP = 1 << 0,
625 DMAR_X2APIC_OPT_OUT = 1 << 1,
626 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
627};
628
629typedef struct dmar_entry {
630 u16 type;
631 u16 length;
632 u8 flags;
633 u8 reserved;
634 u16 segment;
635 u64 bar;
636} __packed dmar_entry_t;
637
638typedef struct dmar_rmrr_entry {
639 u16 type;
640 u16 length;
641 u16 reserved;
642 u16 segment;
643 u64 bar;
644 u64 limit;
645} __packed dmar_rmrr_entry_t;
646
647typedef struct dmar_atsr_entry {
648 u16 type;
649 u16 length;
650 u8 flags;
651 u8 reserved;
652 u16 segment;
653} __packed dmar_atsr_entry_t;
654
655typedef struct dmar_rhsa_entry {
656 u16 type;
657 u16 length;
658 u32 reserved;
659 u64 base_address;
660 u32 proximity_domain;
661} __packed dmar_rhsa_entry_t;
662
663typedef struct dmar_andd_entry {
664 u16 type;
665 u16 length;
666 u8 reserved[3];
667 u8 device_number;
668 u8 device_name[];
669} __packed dmar_andd_entry_t;
670
John Zhao6edbb182021-03-24 11:55:09 -0700671typedef struct dmar_satc_entry {
672 u16 type;
673 u16 length;
674 u8 flags;
675 u8 reserved;
676 u16 segment_number;
John Zhao6edbb182021-03-24 11:55:09 -0700677} __packed dmar_satc_entry_t;
678
Furquan Shaikhe0844632020-05-02 10:23:37 -0700679/* DMAR (DMA Remapping Reporting Structure) */
680typedef struct acpi_dmar {
681 acpi_header_t header;
682 u8 host_address_width;
683 u8 flags;
684 u8 reserved[10];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200685 dmar_entry_t structure[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700686} __packed acpi_dmar_t;
687
688/* MADT: APIC Structure Types */
689enum acpi_apic_types {
690 LOCAL_APIC, /* Processor local APIC */
691 IO_APIC, /* I/O APIC */
692 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
693 NMI_TYPE, /* NMI source */
694 LOCAL_APIC_NMI, /* Local APIC NMI */
695 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
696 IO_SAPIC, /* I/O SAPIC */
697 LOCAL_SAPIC, /* Local SAPIC */
698 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
699 LOCAL_X2APIC, /* Processor local x2APIC */
700 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
701 GICC, /* GIC CPU Interface */
702 GICD, /* GIC Distributor */
703 GIC_MSI_FRAME, /* GIC MSI Frame */
704 GICR, /* GIC Redistributor */
705 GIC_ITS, /* Interrupt Translation Service */
706 /* 0x10-0x7f: Reserved */
707 /* 0x80-0xff: Reserved for OEM use */
708};
709
710/* MADT: Processor Local APIC Structure */
711typedef struct acpi_madt_lapic {
712 u8 type; /* Type (0) */
713 u8 length; /* Length in bytes (8) */
714 u8 processor_id; /* ACPI processor ID */
715 u8 apic_id; /* Local APIC ID */
716 u32 flags; /* Local APIC flags */
717} __packed acpi_madt_lapic_t;
718
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300719#define ACPI_MADT_MAX_LAPIC_ID 0xfe
720
Furquan Shaikhe0844632020-05-02 10:23:37 -0700721/* MADT: Local APIC NMI Structure */
722typedef struct acpi_madt_lapic_nmi {
723 u8 type; /* Type (4) */
724 u8 length; /* Length in bytes (6) */
725 u8 processor_id; /* ACPI processor ID */
726 u16 flags; /* MPS INTI flags */
727 u8 lint; /* Local APIC LINT# */
728} __packed acpi_madt_lapic_nmi_t;
729
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200730#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
731#define ACPI_MADT_LX2APIC_NMI_ALL_PROCESSORS ((u32)-1)
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700732
Furquan Shaikhe0844632020-05-02 10:23:37 -0700733/* MADT: I/O APIC Structure */
734typedef struct acpi_madt_ioapic {
735 u8 type; /* Type (1) */
736 u8 length; /* Length in bytes (12) */
737 u8 ioapic_id; /* I/O APIC ID */
738 u8 reserved;
739 u32 ioapic_addr; /* I/O APIC address */
740 u32 gsi_base; /* Global system interrupt base */
741} __packed acpi_madt_ioapic_t;
742
Raul E Rangel169302a2022-04-25 14:59:05 -0600743#define MP_IRQ_POLARITY_DEFAULT 0x0
744#define MP_IRQ_POLARITY_HIGH 0x1
745#define MP_IRQ_POLARITY_LOW 0x3
746#define MP_IRQ_POLARITY_MASK 0x3
747#define MP_IRQ_TRIGGER_DEFAULT 0x0
748#define MP_IRQ_TRIGGER_EDGE 0x4
749#define MP_IRQ_TRIGGER_LEVEL 0xc
750#define MP_IRQ_TRIGGER_MASK 0xc
751
Furquan Shaikhe0844632020-05-02 10:23:37 -0700752/* MADT: Interrupt Source Override Structure */
753typedef struct acpi_madt_irqoverride {
754 u8 type; /* Type (2) */
755 u8 length; /* Length in bytes (10) */
756 u8 bus; /* ISA (0) */
757 u8 source; /* Bus-relative int. source (IRQ) */
758 u32 gsirq; /* Global system interrupt */
759 u16 flags; /* MPS INTI flags */
760} __packed acpi_madt_irqoverride_t;
761
762/* MADT: Processor Local x2APIC Structure */
763typedef struct acpi_madt_lx2apic {
764 u8 type; /* Type (9) */
765 u8 length; /* Length in bytes (16) */
766 u16 reserved;
767 u32 x2apic_id; /* Local x2APIC ID */
768 u32 flags; /* Same as Local APIC flags */
769 u32 processor_id; /* ACPI processor ID */
770} __packed acpi_madt_lx2apic_t;
771
772/* MADT: Processor Local x2APIC NMI Structure */
773typedef struct acpi_madt_lx2apic_nmi {
774 u8 type; /* Type (10) */
775 u8 length; /* Length in bytes (12) */
776 u16 flags; /* Same as MPS INTI flags */
777 u32 processor_id; /* ACPI processor ID */
778 u8 lint; /* Local APIC LINT# */
779 u8 reserved[3];
780} __packed acpi_madt_lx2apic_nmi_t;
781
Arthur Heymans51d94c72023-06-27 15:37:37 +0200782/* MADT: GIC CPU Interface (GICC) Structure 6.5 */
783struct gicc_flags {
784 uint32_t enabled : 1;
785 /* 0 - Level-triggered | 1 - Edge-Triggered */
786 uint32_t performance_interrupt_mode : 1;
787 uint32_t vgic_maintenance_interrupt_mode : 1;
788 uint32_t online_capable : 1;
789 uint32_t reserved : 28;
790};
791_Static_assert(sizeof(struct gicc_flags) == sizeof(uint32_t), "Wrong gicc_flags size\n");
792
793typedef struct acpi_gicc {
794 uint8_t type;
795 uint8_t length;
796 uint16_t reserved;
797 uint32_t cpu_interface_number;
798 uint32_t acpi_processor_uid;
799 struct gicc_flags flags;
800 uint32_t parking_protocol_version;
801 uint32_t performance_interrupt_gsiv;
802 uint64_t parked_address;
803 uint64_t physical_base_address; /* GIC v1/v2 or GIC v3/v4 in v2 compat mode */
804 uint64_t gicv;
805 uint64_t gich;
806 uint32_t vgic_maintenance_interrupt;
807 uint64_t gicr_base_address; /* Only GIC v3 and above */
808 uint64_t mpidr;
809 uint8_t processor_power_efficiency_class;
810 uint8_t reserved1;
811 uint16_t spe_overflow_interrupt;
812 uint16_t trbe_interrupt;
813} __packed acpi_madt_gicc_t;
814_Static_assert(sizeof(acpi_madt_gicc_t) == 82, "Wrong acpi_madt_gicc_t size\n");
815
816/* MADT: GIC Distributor (GICD) Structure */
817typedef struct acpi_gicd {
818 uint8_t type;
819 uint8_t length;
820 uint16_t reserved1;
821 uint32_t gic_id;
822 uint64_t physical_base_address;
823 uint32_t system_vector_base;
824 uint8_t gic_version;
825 uint8_t reserved2[3];
826} __packed acpi_madt_gicd_t;
827_Static_assert(sizeof(acpi_madt_gicd_t) == 24, "Wrong acpi_madt_gicd_t size\n");
828
829/* MADT: GIC MSI Frame Structure */
830struct gic_msi_flags {
831 uint32_t spi_count_select : 1;
832 uint32_t reserved : 31;
833};
834_Static_assert(sizeof(struct gic_msi_flags) == sizeof(uint32_t), "Wrong gic_msi_flags size\n");
835
836typedef struct acpi_gic_msi {
837 uint8_t type;
838 uint8_t length;
839 uint16_t reserved;
840 uint32_t gic_msi_frame_id;
841 uint64_t physical_base_address;
842 struct gic_msi_flags flags;
843 uint16_t spi_count;
844 uint16_t spi_base;
845} __packed acpi_gic_msi_t;
846_Static_assert(sizeof(acpi_gic_msi_t) == 24, "Wrong acpi_gic_msi_t size\n");
847
848/* MADT: GIC Redistributor (GICR) Structure */
849typedef struct acpi_girr {
850 uint8_t type;
851 uint8_t length;
852 uint16_t reserved;
853 uint64_t discovery_range_base_address;
854 uint32_t discovery_range_length;
855} __packed acpi_madt_gicr_t;
856_Static_assert(sizeof(acpi_madt_gicr_t) == 16, "Wrong acpi_madt_gicr_t size\n");
857
858/* MADT: GIC Interrupt Translation Service (ITS) Structure */
859typedef struct acpi_gic_its {
860 uint8_t type;
861 uint8_t length;
862 uint16_t reserved;
863 uint32_t gic_its_id;
864 uint64_t physical_base_address;
865 uint32_t reserved2;
866} __packed acpi_madt_gic_its_t;
867_Static_assert(sizeof(acpi_madt_gic_its_t) == 20, "Wrong MADT acpi_madt_gic_its_t size\n");
868
Furquan Shaikhe0844632020-05-02 10:23:37 -0700869#define ACPI_DBG2_PORT_SERIAL 0x8000
Felix Held2eaebfc2023-11-22 00:31:37 +0100870#define ACPI_DBG2_PORT_SERIAL_16550_IO_ONLY 0x0000
Furquan Shaikhe0844632020-05-02 10:23:37 -0700871#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
872#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
873#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
874#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
875#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
Felix Held2eaebfc2023-11-22 00:31:37 +0100876#define ACPI_DBG2_PORT_SERIAL_16550 0x0012
Furquan Shaikhe0844632020-05-02 10:23:37 -0700877#define ACPI_DBG2_PORT_IEEE1394 0x8001
878#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
879#define ACPI_DBG2_PORT_USB 0x8002
880#define ACPI_DBG2_PORT_USB_XHCI 0x0000
881#define ACPI_DBG2_PORT_USB_EHCI 0x0001
882#define ACPI_DBG2_PORT_NET 0x8003
883
884/* DBG2: Microsoft Debug Port Table 2 header */
885typedef struct acpi_dbg2_header {
886 acpi_header_t header;
887 uint32_t devices_offset;
888 uint32_t devices_count;
Elyes Haouas139cb062023-08-26 17:04:21 +0200889} __packed acpi_dbg2_header_t;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700890
891/* DBG2: Microsoft Debug Port Table 2 device entry */
892typedef struct acpi_dbg2_device {
893 uint8_t revision;
894 uint16_t length;
895 uint8_t address_count;
896 uint16_t namespace_string_length;
897 uint16_t namespace_string_offset;
898 uint16_t oem_data_length;
899 uint16_t oem_data_offset;
900 uint16_t port_type;
901 uint16_t port_subtype;
902 uint8_t reserved[2];
903 uint16_t base_address_offset;
904 uint16_t address_size_offset;
Elyes Haouas139cb062023-08-26 17:04:21 +0200905} __packed acpi_dbg2_device_t;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700906
907/* FADT (Fixed ACPI Description Table) */
908typedef struct acpi_fadt {
909 acpi_header_t header;
910 u32 firmware_ctrl;
911 u32 dsdt;
912 u8 reserved; /* Should be 0 */
913 u8 preferred_pm_profile;
914 u16 sci_int;
915 u32 smi_cmd;
916 u8 acpi_enable;
917 u8 acpi_disable;
918 u8 s4bios_req;
919 u8 pstate_cnt;
920 u32 pm1a_evt_blk;
921 u32 pm1b_evt_blk;
922 u32 pm1a_cnt_blk;
923 u32 pm1b_cnt_blk;
924 u32 pm2_cnt_blk;
925 u32 pm_tmr_blk;
926 u32 gpe0_blk;
927 u32 gpe1_blk;
928 u8 pm1_evt_len;
929 u8 pm1_cnt_len;
930 u8 pm2_cnt_len;
931 u8 pm_tmr_len;
932 u8 gpe0_blk_len;
933 u8 gpe1_blk_len;
934 u8 gpe1_base;
935 u8 cst_cnt;
936 u16 p_lvl2_lat;
937 u16 p_lvl3_lat;
938 u16 flush_size;
939 u16 flush_stride;
940 u8 duty_offset;
941 u8 duty_width;
942 u8 day_alrm;
943 u8 mon_alrm;
944 u8 century;
945 u16 iapc_boot_arch;
946 u8 res2;
947 u32 flags;
948 acpi_addr_t reset_reg;
949 u8 reset_value;
Elyes Haouasb55ac092022-02-16 14:42:19 +0100950 u16 ARM_boot_arch; /* Must be zero if ACPI Revision <= 5.0 */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100951 u8 FADT_MinorVersion; /* Must be zero if ACPI Revision <= 5.0 */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700952 u32 x_firmware_ctl_l;
953 u32 x_firmware_ctl_h;
954 u32 x_dsdt_l;
955 u32 x_dsdt_h;
956 acpi_addr_t x_pm1a_evt_blk;
957 acpi_addr_t x_pm1b_evt_blk;
958 acpi_addr_t x_pm1a_cnt_blk;
959 acpi_addr_t x_pm1b_cnt_blk;
960 acpi_addr_t x_pm2_cnt_blk;
961 acpi_addr_t x_pm_tmr_blk;
962 acpi_addr_t x_gpe0_blk;
963 acpi_addr_t x_gpe1_blk;
964 /* Revision 5 */
965 acpi_addr_t sleep_control_reg;
966 acpi_addr_t sleep_status_reg;
967 /* Revision 6 */
968 u64 hypervisor_vendor_identity;
969} __packed acpi_fadt_t;
970
971/* FADT TABLE Revision values */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100972#define ACPI_FADT_REV_ACPI_1 1
973#define ACPI_FADT_REV_ACPI_2 3
974#define ACPI_FADT_REV_ACPI_3 4
975#define ACPI_FADT_REV_ACPI_4 4
976#define ACPI_FADT_REV_ACPI_5 5
977#define ACPI_FADT_REV_ACPI_6 6
978
979/* FADT Minor Version value:
980 * Bits 0-3: minor version
981 * Bits 4-7: Errata
982 * value of 1 means this is compatible with Errata A,
983 * value of 2 would be compatible with Errata B, and so on
984 * Version 6.3 Errata A would be: (1 << 4) | 3
985 */
986#define ACPI_FADT_MINOR_VERSION_0 0 /* coreboot currently use this version */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700987
988/* Flags for p_lvl2_lat and p_lvl3_lat */
989#define ACPI_FADT_C2_NOT_SUPPORTED 101
990#define ACPI_FADT_C3_NOT_SUPPORTED 1001
991
992/* FADT Feature Flags */
993#define ACPI_FADT_WBINVD (1 << 0)
994#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
995#define ACPI_FADT_C1_SUPPORTED (1 << 2)
996#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
997#define ACPI_FADT_POWER_BUTTON (1 << 4)
998#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
999#define ACPI_FADT_FIXED_RTC (1 << 6)
1000#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
1001#define ACPI_FADT_32BIT_TIMER (1 << 8)
1002#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
1003#define ACPI_FADT_RESET_REGISTER (1 << 10)
1004#define ACPI_FADT_SEALED_CASE (1 << 11)
1005#define ACPI_FADT_HEADLESS (1 << 12)
1006#define ACPI_FADT_SLEEP_TYPE (1 << 13)
1007#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
1008#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
1009#define ACPI_FADT_S4_RTC_VALID (1 << 16)
1010#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
1011#define ACPI_FADT_APIC_CLUSTER (1 << 18)
1012#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
1013/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
1014#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
1015#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
1016/* bits 22-31: reserved since ACPI 5.0 */
1017
1018/* FADT Boot Architecture Flags */
1019#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
1020#define ACPI_FADT_8042 (1 << 1)
1021#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
1022#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
1023#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
1024#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
1025#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
1026
1027/* FADT ARM Boot Architecture Flags */
1028#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
1029#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
1030/* bits 2-16: reserved since ACPI 5.1 */
1031
1032/* FADT Preferred Power Management Profile */
1033enum acpi_preferred_pm_profiles {
1034 PM_UNSPECIFIED = 0,
1035 PM_DESKTOP = 1,
1036 PM_MOBILE = 2,
1037 PM_WORKSTATION = 3,
1038 PM_ENTERPRISE_SERVER = 4,
1039 PM_SOHO_SERVER = 5,
1040 PM_APPLIANCE_PC = 6,
1041 PM_PERFORMANCE_SERVER = 7,
1042 PM_TABLET = 8, /* ACPI 5.0 & greater */
1043};
1044
1045/* FACS (Firmware ACPI Control Structure) */
1046typedef struct acpi_facs {
1047 char signature[4]; /* "FACS" */
1048 u32 length; /* Length in bytes (>= 64) */
1049 u32 hardware_signature; /* Hardware signature */
1050 u32 firmware_waking_vector; /* Firmware waking vector */
1051 u32 global_lock; /* Global lock */
1052 u32 flags; /* FACS flags */
1053 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
1054 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
1055 u8 version; /* FACS version */
1056 u8 resv1[3]; /* This value is 0 */
1057 u32 ospm_flags; /* 64BIT_WAKE_F */
1058 u8 resv2[24]; /* This value is 0 */
1059} __packed acpi_facs_t;
1060
1061/* FACS flags */
1062#define ACPI_FACS_S4BIOS_F (1 << 0)
1063#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
1064/* Bits 31..2: reserved */
1065
1066/* ECDT (Embedded Controller Boot Resources Table) */
1067typedef struct acpi_ecdt {
1068 acpi_header_t header;
1069 acpi_addr_t ec_control; /* EC control register */
1070 acpi_addr_t ec_data; /* EC data register */
1071 u32 uid; /* UID */
1072 u8 gpe_bit; /* GPE bit */
1073 u8 ec_id[]; /* EC ID */
1074} __packed acpi_ecdt_t;
1075
1076/* HEST (Hardware Error Source Table) */
1077typedef struct acpi_hest {
1078 acpi_header_t header;
1079 u32 error_source_count;
1080 /* error_source_struct(s) */
1081} __packed acpi_hest_t;
1082
1083/* Error Source Descriptors */
1084typedef struct acpi_hest_esd {
1085 u16 type;
1086 u16 source_id;
1087 u16 resv;
1088 u8 flags;
1089 u8 enabled;
1090 u32 prealloc_erecords; /* The number of error records to
1091 * pre-allocate for this error source.
1092 */
1093 u32 max_section_per_record;
1094} __packed acpi_hest_esd_t;
1095
1096/* Hardware Error Notification */
1097typedef struct acpi_hest_hen {
1098 u8 type;
1099 u8 length;
1100 u16 conf_we; /* Configuration Write Enable */
1101 u32 poll_interval;
1102 u32 vector;
1103 u32 sw2poll_threshold_val;
1104 u32 sw2poll_threshold_win;
1105 u32 error_threshold_val;
1106 u32 error_threshold_win;
1107} __packed acpi_hest_hen_t;
1108
1109/* BERT (Boot Error Record Table) */
1110typedef struct acpi_bert {
1111 acpi_header_t header;
1112 u32 region_length;
1113 u64 error_region;
1114} __packed acpi_bert_t;
1115
1116/* Generic Error Data Entry */
1117typedef struct acpi_hest_generic_data {
1118 guid_t section_type;
1119 u32 error_severity;
1120 u16 revision;
1121 u8 validation_bits;
1122 u8 flags;
1123 u32 data_length;
1124 guid_t fru_id;
1125 u8 fru_text[20];
1126 /* error data */
1127} __packed acpi_hest_generic_data_t;
1128
1129/* Generic Error Data Entry v300 */
1130typedef struct acpi_hest_generic_data_v300 {
1131 guid_t section_type;
1132 u32 error_severity;
1133 u16 revision;
1134 u8 validation_bits;
1135 u8 flags; /* see CPER Section Descriptor, Flags field */
1136 u32 data_length;
1137 guid_t fru_id;
1138 u8 fru_text[20];
1139 cper_timestamp_t timestamp;
1140 /* error data */
1141} __packed acpi_hest_generic_data_v300_t;
1142#define HEST_GENERIC_ENTRY_V300 0x300
1143
1144/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
1145#define ACPI_GENERROR_SEV_RECOVERABLE 0
1146#define ACPI_GENERROR_SEV_FATAL 1
1147#define ACPI_GENERROR_SEV_CORRECTED 2
1148#define ACPI_GENERROR_SEV_NONE 3
1149
1150/* Generic Error Data Entry, Validation Bits field */
1151#define ACPI_GENERROR_VALID_FRUID BIT(0)
1152#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
1153#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
1154
Felix Held403fa862021-07-26 22:43:00 +02001155/*
1156 * Generic Error Status Block
1157 *
1158 * If there is a raw data section at the end of the generic error status block after the
1159 * zero or more generic error data entries, raw_data_length indicates the length of the raw
1160 * section and raw_data_offset is the offset of the beginning of the raw data section from
1161 * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length
1162 * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t).
1163 */
Furquan Shaikhe0844632020-05-02 10:23:37 -07001164typedef struct acpi_generic_error_status {
1165 u32 block_status;
1166 u32 raw_data_offset; /* must follow any generic entries */
1167 u32 raw_data_length;
1168 u32 data_length; /* generic data */
1169 u32 error_severity;
1170 /* Generic Error Data structures, zero or more entries */
1171} __packed acpi_generic_error_status_t;
1172
1173/* Generic Status Block, Block Status values */
1174#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
1175#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
1176#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
1177#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
1178#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
1179#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
1180#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
1181 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
1182 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
1183
1184typedef struct acpi_cstate {
1185 u8 ctype;
1186 u16 latency;
1187 u32 power;
1188 acpi_addr_t resource;
1189} __packed acpi_cstate_t;
1190
Jason Gleneskca36aed2020-09-15 21:01:57 -07001191struct acpi_sw_pstate {
1192 u32 core_freq;
1193 u32 power;
1194 u32 transition_latency;
1195 u32 bus_master_latency;
1196 u32 control_value;
1197 u32 status_value;
1198} __packed;
1199
1200struct acpi_xpss_sw_pstate {
1201 u64 core_freq;
1202 u64 power;
1203 u64 transition_latency;
1204 u64 bus_master_latency;
1205 u64 control_value;
1206 u64 status_value;
1207 u64 control_mask;
1208 u64 status_mask;
1209} __packed;
1210
Furquan Shaikhe0844632020-05-02 10:23:37 -07001211typedef struct acpi_tstate {
1212 u32 percent;
1213 u32 power;
1214 u32 latency;
1215 u32 control;
1216 u32 status;
1217} __packed acpi_tstate_t;
1218
Raul E Rangelc7048322021-04-19 15:58:25 -06001219enum acpi_lpi_state_flags {
1220 ACPI_LPI_STATE_DISABLED = 0,
1221 ACPI_LPI_STATE_ENABLED
1222};
1223
1224/* Low Power Idle State */
1225struct acpi_lpi_state {
1226 u32 min_residency_us;
1227 u32 worst_case_wakeup_latency_us;
1228 u32 flags;
1229 u32 arch_context_lost_flags;
1230 u32 residency_counter_frequency_hz;
1231 u32 enabled_parent_state;
1232 acpi_addr_t entry_method;
1233 acpi_addr_t residency_counter_register;
1234 acpi_addr_t usage_counter_register;
1235 const char *state_name;
1236};
1237
Furquan Shaikhe0844632020-05-02 10:23:37 -07001238/* Port types for ACPI _UPC object */
1239enum acpi_upc_type {
1240 UPC_TYPE_A,
1241 UPC_TYPE_MINI_AB,
1242 UPC_TYPE_EXPRESSCARD,
1243 UPC_TYPE_USB3_A,
1244 UPC_TYPE_USB3_B,
1245 UPC_TYPE_USB3_MICRO_B,
1246 UPC_TYPE_USB3_MICRO_AB,
1247 UPC_TYPE_USB3_POWER_B,
1248 UPC_TYPE_C_USB2_ONLY,
1249 UPC_TYPE_C_USB2_SS_SWITCH,
1250 UPC_TYPE_C_USB2_SS,
1251 UPC_TYPE_PROPRIETARY = 0xff,
1252 /*
1253 * The following types are not directly defined in the ACPI
1254 * spec but are used by coreboot to identify a USB device type.
1255 */
1256 UPC_TYPE_INTERNAL = 0xff,
1257 UPC_TYPE_UNUSED,
1258 UPC_TYPE_HUB
1259};
1260
1261enum acpi_ipmi_interface_type {
1262 IPMI_INTERFACE_RESERVED = 0,
1263 IPMI_INTERFACE_KCS,
1264 IPMI_INTERFACE_SMIC,
1265 IPMI_INTERFACE_BT,
1266 IPMI_INTERFACE_SSIF,
1267};
1268
1269#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
1270#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
1271#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
1272
1273/* ACPI IPMI 2.0 */
1274struct acpi_spmi {
1275 acpi_header_t header;
1276 u8 interface_type;
1277 u8 reserved;
1278 u16 specification_revision;
1279 u8 interrupt_type;
1280 u8 gpe;
1281 u8 reserved2;
1282 u8 pci_device_flag;
1283
1284 u32 global_system_interrupt;
1285 acpi_addr_t base_address;
1286 union {
1287 struct {
1288 u8 pci_segment_group;
1289 u8 pci_bus;
1290 u8 pci_device;
1291 u8 pci_function;
1292 };
1293 u8 uid[4];
1294 };
1295 u8 reserved3;
1296} __packed;
1297
Rocky Phaguraeff07132021-01-10 15:42:50 -08001298/* EINJ APEI Standard Definitions */
1299/* EINJ Error Types
1300 Refer to the ACPI spec, EINJ section, for more info on bit definitions
1301*/
1302#define ACPI_EINJ_CPU_CE (1 << 0)
1303#define ACPI_EINJ_CPU_UCE (1 << 1)
1304#define ACPI_EINJ_CPU_UCE_FATAL (1 << 2)
1305#define ACPI_EINJ_MEM_CE (1 << 3)
1306#define ACPI_EINJ_MEM_UCE (1 << 4)
1307#define ACPI_EINJ_MEM_UCE_FATAL (1 << 5)
1308#define ACPI_EINJ_PCIE_CE (1 << 6)
1309#define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7)
1310#define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8)
1311#define ACPI_EINJ_PLATFORM_CE (1 << 9)
1312#define ACPI_EINJ_PLATFORM_UCE (1 << 10)
1313#define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11)
1314#define ACPI_EINJ_VENDOR_DEFINED (1 << 31)
1315#define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \
1316 ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL)
1317
1318/* EINJ actions */
1319#define ACTION_COUNT 9
1320#define BEGIN_INJECT_OP 0x00
1321#define GET_TRIGGER_ACTION_TABLE 0x01
1322#define SET_ERROR_TYPE 0x02
1323#define GET_ERROR_TYPE 0x03
1324#define END_INJECT_OP 0x04
1325#define EXECUTE_INJECT_OP 0x05
1326#define CHECK_BUSY_STATUS 0x06
1327#define GET_CMD_STATUS 0x07
1328#define SET_ERROR_TYPE_WITH_ADDRESS 0x08
1329#define TRIGGER_ERROR 0xFF
1330
1331/* EINJ Instructions */
1332#define READ_REGISTER 0x00
1333#define READ_REGISTER_VALUE 0x01
1334#define WRITE_REGISTER 0x02
1335#define WRITE_REGISTER_VALUE 0x03
1336#define NO_OP 0x04
1337
1338/* EINJ (Error Injection Table) */
1339typedef struct acpi_gen_regaddr1 {
1340 u8 space_id; /* Address space ID */
1341 u8 bit_width; /* Register size in bits */
1342 u8 bit_offset; /* Register bit offset */
1343 u8 access_size; /* Access size since ACPI 2.0c */
1344 u64 addr; /* Register address */
1345} __packed acpi_addr64_t;
1346
1347/* Instruction entry */
1348typedef struct acpi_einj_action_table {
1349 u8 action;
1350 u8 instruction;
1351 u16 flags;
1352 acpi_addr64_t reg;
1353 u64 value;
1354 u64 mask;
1355} __packed acpi_einj_action_table_t;
1356
1357typedef struct acpi_injection_header {
1358 u32 einj_header_size;
1359 u32 flags;
1360 u32 entry_count;
1361} __packed acpi_injection_header_t;
1362
1363typedef struct acpi_einj_trigger_table {
1364 u32 header_size;
1365 u32 revision;
1366 u32 table_size;
1367 u32 entry_count;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +02001368 acpi_einj_action_table_t trigger_action[];
Rocky Phaguraeff07132021-01-10 15:42:50 -08001369} __packed acpi_einj_trigger_table_t;
1370
1371typedef struct set_error_type {
1372 u32 errtype;
1373 u32 vendorerrortype;
1374 u32 flags;
1375 u32 apicid;
1376 u64 memaddr;
1377 u64 memrange;
1378 u32 pciesbdf;
1379} __packed set_error_type_t;
1380
1381#define EINJ_PARAM_NUM 6
1382typedef struct acpi_einj_smi {
1383 u64 op_state;
1384 u64 err_inject[EINJ_PARAM_NUM];
1385 u64 trigger_action_table;
1386 u64 err_inj_cap;
1387 u64 op_status;
1388 u64 cmd_sts;
1389 u64 einj_addr;
1390 u64 einj_addr_msk;
1391 set_error_type_t setaddrtable;
1392 u64 reserved[50];
1393} __packed acpi_einj_smi_t;
1394
1395/* EINJ Flags */
1396#define EINJ_DEF_TRIGGER_PORT 0xb2
1397#define FLAG_PRESERVE 0x01
1398#define FLAG_IGNORE 0x00
1399
1400/* EINJ Registers */
1401#define EINJ_REG_MEMORY(address) \
1402 { \
1403 .space_id = ACPI_ADDRESS_SPACE_MEMORY, \
1404 .bit_width = 64, \
1405 .bit_offset = 0, \
1406 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
1407 .addr = address}
1408
1409#define EINJ_REG_IO() \
1410 { \
1411 .space_id = ACPI_ADDRESS_SPACE_IO, \
1412 .bit_width = 0x10, \
1413 .bit_offset = 0, \
1414 .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \
1415 .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */
1416
1417typedef struct acpi_einj {
1418 acpi_header_t header;
1419 acpi_injection_header_t inj_header;
1420 acpi_einj_action_table_t action_table[ACTION_COUNT];
1421} __packed acpi_einj_t;
1422
David Milosevicd9822742023-09-22 14:34:28 +02001423/* PPTT definitions */
1424
1425#define PPTT_NODE_TYPE_CPU 0
1426#define PPTT_NODE_TYPE_CACHE 1
1427
1428/* PPTT structures for ACPI generation */
1429
1430typedef struct acpi_pptt_cpu_node {
1431 u8 type; // type = 0 (processor structure specification)
1432 u8 length; // in bytes
1433 u8 reserved[2]; // reserved, must be zero
1434 u32 flags; // processor hierarchy node structure flags
1435 u32 parent; // reference (delta of pptt-start and node) to parent node, must be zero if no parent
1436 u32 processor_id; // must match id in MADT, if actual processor
1437 u32 n_resources; // number of resource structure references
1438 u32 resources[]; // resource structure references
1439} acpi_pptt_cpu_node_t;
1440
1441typedef struct acpi_pptt_cache_node {
1442 u8 type; // type = 1 (cache type structure)
1443 u8 length; // length = 28
1444 u8 reserved[2]; // reserved, must be zero
1445 u32 flags; // cache structure flags
1446 u32 next_level; // reference to next level cache, null if last cache level
1447 u32 size; // cache size in bytes
1448 u32 n_sets; // number of sets in the cache
1449 u8 associativity; // integer number of ways
1450 u8 attributes; // bits[7:5] reserved, must be zero
1451 u16 line_size; // in bytes
1452 u32 cache_id; // unique, non-zero
1453} acpi_pptt_cache_node_t;
1454
1455union acpi_pptt_body {
1456 acpi_pptt_cpu_node_t cpu;
1457 acpi_pptt_cache_node_t cache;
1458};
1459
1460typedef struct acpi_pptt {
1461 acpi_header_t header;
1462
1463 /*
1464 * followed by a variable length body
1465 * consisting of processor topology structures.
1466 *
1467 * see acpi_pptt_cpu_node and
1468 * acpi_pptt_cache_node.
1469 */
1470 union acpi_pptt_body body[];
1471} __packed acpi_pptt_t;
1472
1473/* PPTT structures for topology description */
1474
1475union pptt_cache_flags {
1476 struct {
1477 u32 size_valid : 1;
1478 u32 n_sets_valid : 1;
1479 u32 associativity_valid : 1;
1480 u32 alloc_type_valid : 1;
1481 u32 cache_type_valid : 1;
1482 u32 write_policy_valid : 1;
1483 u32 line_size_valid : 1;
1484 u32 cache_id_valid : 1;
1485 u32 reserved : 24;
1486 };
1487
1488 u32 raw;
1489};
1490
1491union pptt_cpu_flags {
1492 struct {
1493 u32 is_physical_package : 1;
1494 u32 processor_id_valid : 1;
1495 u32 is_thread : 1;
1496 u32 is_leaf : 1;
1497 u32 is_identical_impl : 1;
1498 u32 reserved : 27;
1499 };
1500
1501 u32 raw;
1502};
1503
1504struct pptt_cache {
1505 u32 size;
1506 u32 numsets;
1507 u8 associativity;
1508 u8 attributes;
1509 u16 line_size;
1510 union pptt_cache_flags flags;
1511 struct pptt_cache *next_level;
1512};
1513
1514struct pptt_cpu_resources {
1515 struct pptt_cache *cache;
1516 struct pptt_cpu_resources *next;
1517};
1518
1519struct pptt_topology {
1520 u32 processor_id;
1521 union pptt_cpu_flags flags;
1522 struct pptt_cpu_resources *resources;
1523 struct pptt_topology *sibling;
1524 struct pptt_topology *child;
1525};
1526
Arthur Heymanse7aaf042023-06-07 12:12:45 +02001527/* SPCR (Serial Port Console Redirection Table) */
1528typedef struct acpi_spcr {
1529 acpi_header_t header;
1530 uint8_t interface_type;
1531 uint8_t reserved[3];
1532 acpi_addr_t base_address;
1533 uint8_t interrupt_type;
1534 uint8_t irq;
1535 uint32_t global_system_interrupt;
1536 uint8_t configured_baudrate;
1537 uint8_t parity;
1538 uint8_t stop_bits;
1539 uint8_t flow_control;
1540 uint8_t terminal_type;
1541 uint8_t language;
1542 uint16_t pci_did;
1543 uint16_t pci_vid;
1544 uint8_t pci_bus;
1545 uint8_t pci_dev;
1546 uint8_t pci_fun;
1547 uint32_t pci_flags;
1548 uint8_t pci_segment;
1549 uint32_t uart_clock;
1550 uint32_t precise_baud_rate;
1551 uint16_t namespace_string_length;
1552 uint16_t namespace_string_offset;
1553 char namespacestring[];
1554} __packed acpi_spcr_t;
1555_Static_assert(sizeof(acpi_spcr_t) == 88, "acpi_spcr_t must have an 88 byte size\n");
1556
Arthur Heymans90464072023-06-07 12:53:50 +02001557#define PC_AT_COMPATIBLE_INTERRUPT (1 << 0)
1558#define IO_APIC_COMPATIBLE_INTERRUPT (1 << 1)
1559#define IO_SAPIC_COMPATIBLE_INTERRUPT (1 << 2)
1560#define ARMH_GIC_COMPATIBLE_INTERRUPT (1 << 3)
1561#define RISCV_PLIC_COMPATIBLE_INTERRUPT (1 << 4)
1562
Arthur Heymans8193eab2023-06-20 10:17:23 +02001563/* GTDT - Generic Timer Description Table (ACPI 5.1) Version 2 */
1564typedef struct acpi_table_gtdt {
1565 acpi_header_t header; /* Common ACPI table header */
Naresh Solanki75f0b602023-09-25 13:59:25 +02001566 u64 counter_block_address;
Arthur Heymans8193eab2023-06-20 10:17:23 +02001567 u32 reserved;
1568 u32 secure_el1_interrupt;
1569 u32 secure_el1_flags;
1570 u32 non_secure_el1_interrupt;
1571 u32 non_secure_el1_flags;
1572 u32 virtual_timer_interrupt;
1573 u32 virtual_timer_flags;
1574 u32 non_secure_el2_interrupt;
1575 u32 non_secure_el2_flags;
1576 u64 counter_read_block_address;
1577 u32 platform_timer_count;
1578 u32 platform_timer_offset;
1579} __packed acpi_gtdt_t;
1580
1581/* Flag Definitions: Timer Block Physical Timers and Virtual timers */
1582
1583#define ACPI_GTDT_INTERRUPT_MODE (1)
1584#define ACPI_GTDT_INTERRUPT_POLARITY (1<<1)
1585#define ACPI_GTDT_ALWAYS_ON (1<<2)
1586
1587struct acpi_gtdt_el2 {
1588 u32 virtual_el2_timer_gsiv;
1589 u32 virtual_el2_timer_flags;
1590};
1591
1592/* Common GTDT subtable header */
1593
1594struct acpi_gtdt_header {
1595 u8 type;
1596 u16 length;
1597} __packed;
1598
1599/* Values for GTDT subtable type above */
1600
1601enum acpi_gtdt_type {
1602 ACPI_GTDT_TYPE_TIMER_BLOCK = 0,
1603 ACPI_GTDT_TYPE_WATCHDOG = 1,
1604 ACPI_GTDT_TYPE_RESERVED = 2 /* 2 and greater are reserved */
1605};
1606
1607/* GTDT Subtables, correspond to Type in struct acpi_gtdt_header */
1608
1609/* 0: Generic Timer Block */
1610
1611struct acpi_gtdt_timer_block {
1612 struct acpi_gtdt_header header;
1613 u8 reserved;
1614 u64 block_address;
1615 u32 timer_count;
1616 u32 timer_offset;
1617} __packed;
1618
1619/* Timer Sub-Structure, one per timer */
1620
1621struct acpi_gtdt_timer_entry {
1622 u8 frame_number;
1623 u8 reserved[3];
1624 u64 base_address;
1625 u64 el0_base_address;
1626 u32 timer_interrupt;
1627 u32 timer_flags;
1628 u32 virtual_timer_interrupt;
1629 u32 virtual_timer_flags;
1630 u32 common_flags;
1631} __packed;
1632
1633/* Flag Definitions: timer_flags and virtual_timer_flags above */
1634
1635#define ACPI_GTDT_GT_IRQ_MODE (1)
1636#define ACPI_GTDT_GT_IRQ_POLARITY (1<<1)
1637
1638/* Flag Definitions: common_flags above */
1639
1640#define ACPI_GTDT_GT_IS_SECURE_TIMER (1)
1641#define ACPI_GTDT_GT_ALWAYS_ON (1<<1)
1642
1643/* 1: SBSA Generic Watchdog Structure */
1644
1645struct acpi_gtdt_watchdog {
1646 struct acpi_gtdt_header header;
1647 u8 reserved;
1648 u64 refresh_frame_address;
1649 u64 control_frame_address;
1650 u32 timer_interrupt;
1651 u32 timer_flags;
1652} __packed;
1653
1654/* Flag Definitions: timer_flags above */
1655
1656#define ACPI_GTDT_WATCHDOG_IRQ_MODE (1)
1657#define ACPI_GTDT_WATCHDOG_IRQ_POLARITY (1<<1)
1658#define ACPI_GTDT_WATCHDOG_SECURE (1<<2)
1659
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01001660uintptr_t get_coreboot_rsdp(void);
Rocky Phaguraeff07132021-01-10 15:42:50 -08001661void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);
1662
Furquan Shaikhe0844632020-05-02 10:23:37 -07001663unsigned long fw_cfg_acpi_tables(unsigned long start);
1664
1665/* These are implemented by the target port or north/southbridge. */
Raul E Rangel6b446b92021-11-19 11:38:35 -07001666void preload_acpi_dsdt(void);
Arthur Heymans7ebebf72023-06-17 14:08:46 +02001667unsigned long write_acpi_tables(const unsigned long addr);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001668unsigned long acpi_fill_madt(unsigned long current);
Arthur Heymanscd46e5f2023-06-22 21:34:16 +02001669unsigned long acpi_arch_fill_madt(acpi_madt_t *madt, unsigned long current);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001670
Furquan Shaikhe0844632020-05-02 10:23:37 -07001671void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +02001672void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001673void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001674void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001675
Kyösti Mälkki88decca2023-04-28 07:04:34 +03001676void fill_fadt_extended_pm_io(acpi_fadt_t *fadt);
1677
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001678void acpi_fill_gnvs(void);
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02001679void acpi_fill_cnvs(void);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001680
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001681unsigned long acpi_fill_lpit(unsigned long current);
1682
Furquan Shaikhe0844632020-05-02 10:23:37 -07001683/* These can be used by the target port. */
1684u8 acpi_checksum(u8 *table, u32 length);
1685
1686void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
1687
Jonathan Zhang3dcafa82022-05-11 13:11:20 -07001688/* Create CXL Early Discovery Table */
1689void acpi_create_cedt(acpi_cedt_t *cedt,
1690 unsigned long (*acpi_fill_cedt)(unsigned long current));
1691/* Create a CXL Host Bridge Structure for CEDT */
1692int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base);
1693/* Create a CXL Fixed Memory Window Structure for CEDT */
1694int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size,
1695 u8 eniw, u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target);
1696
David Milosevicd9822742023-09-22 14:34:28 +02001697/* PPTT related functions */
1698void acpi_create_pptt_body(acpi_pptt_t *pptt);
1699struct pptt_topology *acpi_get_pptt_topology(void);
Arthur Heymans92a3b672023-06-22 21:30:58 +02001700
Kyösti Mälkkic7da0272021-06-08 11:37:08 +03001701int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001702
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +03001703unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 cpu, u32 apic);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001704
1705unsigned long acpi_create_madt_lapic_nmis(unsigned long current);
1706
Arthur Heymans3df6cc92023-06-27 16:44:59 +02001707uintptr_t platform_get_gicd_base(void);
1708uintptr_t platform_get_gicr_base(void);
Naresh Solanki1fe19042023-09-25 14:24:34 +02001709int platform_get_gic_its(uintptr_t **base);
Arthur Heymans3df6cc92023-06-27 16:44:59 +02001710
Furquan Shaikhe0844632020-05-02 10:23:37 -07001711int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
Naresh Solanki76835cc2023-01-20 19:13:02 +01001712int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001713int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
1714 u32 flags);
Jonathan Zhang3164b642021-04-21 17:51:31 -07001715/*
1716 * Given the Generic Initiator device's BDF, the proximity domain's ID
1717 * and flag, create Generic Initiator Affinity structure in SRAT.
1718 */
1719int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
1720 u16 seg, u8 bus, u8 dev, u8 func, u32 flags);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001721unsigned long acpi_create_srat_lapics(unsigned long current);
1722void acpi_create_srat(acpi_srat_t *srat,
1723 unsigned long (*acpi_fill_srat)(unsigned long current));
1724
1725void acpi_create_slit(acpi_slit_t *slit,
1726 unsigned long (*acpi_fill_slit)(unsigned long current));
1727
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001728/*
1729 * Create a Memory Proximity Domain Attributes structure for HMAT,
1730 * given proximity domain for the attached initiaor, and
1731 * proximimity domain for the memory.
1732 */
1733int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory);
Martin Roth0949e732021-10-01 14:28:22 -06001734/* Create Heterogeneous Memory Attribute Table */
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001735void acpi_create_hmat(acpi_hmat_t *hmat,
1736 unsigned long (*acpi_fill_hmat)(unsigned long current));
1737
Furquan Shaikhe0844632020-05-02 10:23:37 -07001738void acpi_create_vfct(const struct device *device,
1739 acpi_vfct_t *vfct,
1740 unsigned long (*acpi_fill_vfct)(const struct device *device,
1741 acpi_vfct_t *vfct_struct,
1742 unsigned long current));
1743
1744void acpi_create_ipmi(const struct device *device,
1745 struct acpi_spmi *spmi,
1746 const u16 ipmi_revision,
1747 const acpi_addr_t *addr,
1748 const enum acpi_ipmi_interface_type type,
1749 const s8 gpe_interrupt,
1750 const u32 apic_interrupt,
1751 const u32 uid);
1752
1753void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1754 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1755 unsigned long current));
1756
Jason Glenesk61624b22020-11-02 20:06:23 -08001757void acpi_create_crat(struct acpi_crat_header *crat,
1758 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1759 unsigned long current));
1760
Furquan Shaikhe0844632020-05-02 10:23:37 -07001761unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1762 acpi_rsdp_t *rsdp);
1763
1764/* cpu/intel/speedstep/acpi.c */
1765void generate_cpu_entries(const struct device *device);
1766
Furquan Shaikhe0844632020-05-02 10:23:37 -07001767unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
Arthur Heymans736d4d22023-06-30 15:37:38 +02001768 const struct device *dev, uint8_t access_size);
1769unsigned long acpi_pl011_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current,
1770 uint64_t base, const char *name);
Zheng Bao3ea3fbe2023-11-20 14:17:25 +08001771unsigned long acpi_16550_mmio32_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current,
1772 uint64_t base, const char *name);
Arthur Heymans736d4d22023-06-30 15:37:38 +02001773
Furquan Shaikhe0844632020-05-02 10:23:37 -07001774void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1775 unsigned long (*acpi_fill_dmar)(unsigned long));
1776unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1777 u16 segment, u64 bar);
1778unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1779 u64 bar, u64 limit);
1780unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1781 u16 segment);
1782unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1783 u32 proximity_domain);
1784unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1785 const char *device_name);
John Zhao6edbb182021-03-24 11:55:09 -07001786unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags,
John Zhao091532d2021-04-17 16:03:21 -07001787 u16 segment);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001788void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1789void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1790void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
John Zhao6edbb182021-03-24 11:55:09 -07001791void acpi_dmar_satc_fixup(unsigned long base, unsigned long current);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001792unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1793 u8 bus, u8 dev, u8 fn);
1794unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1795 u8 bus, u8 dev, u8 fn);
1796unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1797 u8 enumeration_id,
1798 u8 bus, u8 dev, u8 fn);
Arthur Heymansbc8f8592022-12-02 13:17:39 +01001799unsigned long acpi_create_dmar_ds_ioapic_from_hw(unsigned long current,
1800 u32 addr, u8 bus, u8 dev, u8 fn);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001801unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1802 u8 enumeration_id,
1803 u8 bus, u8 dev, u8 fn);
1804void acpi_write_hest(acpi_hest_t *hest,
1805 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1806
1807unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1808 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1809
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001810unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1811
Felix Heldf7dbf4a2021-06-07 16:56:04 +02001812/* chipsets that select ACPI_BERT must implement this function */
Felix Held29405482021-05-28 16:01:57 +02001813enum cb_err acpi_soc_get_bert_region(void **region, size_t *length);
Francois Toguo522e0db2021-01-21 09:55:19 -08001814
Arthur Heymans2e3cb632023-06-30 15:01:08 +02001815void acpi_soc_fill_gtdt(acpi_gtdt_t *gtdt);
1816unsigned long acpi_soc_gtdt_add_timers(uint32_t *count, unsigned long current);
1817unsigned long acpi_gtdt_add_timer_block(unsigned long current, const uint64_t address,
1818 struct acpi_gtdt_timer_entry *timers, size_t number);
1819unsigned long acpi_gtdt_add_watchdog(unsigned long current, uint64_t refresh_frame,
1820 uint64_t control_frame, uint32_t gsiv, uint32_t flags);
1821
Furquan Shaikhe0844632020-05-02 10:23:37 -07001822/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001823void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001824void mainboard_suspend_resume(void);
1825void *acpi_find_wakeup_vector(void);
1826
1827/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1828enum {
1829 ACPI_S0 = 0,
1830 ACPI_S1 = 1,
1831 ACPI_S2 = 2,
1832 ACPI_S3 = 3,
1833 ACPI_S4 = 4,
1834 ACPI_S5 = 5,
1835};
1836
1837#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1838 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1839/* Given the provided PM1 control register return the ACPI sleep type. */
1840static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1841{
1842 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1843 case SLP_TYP_S0: return ACPI_S0;
1844 case SLP_TYP_S1: return ACPI_S1;
1845 case SLP_TYP_S3: return ACPI_S3;
1846 case SLP_TYP_S4: return ACPI_S4;
1847 case SLP_TYP_S5: return ACPI_S5;
1848 }
1849 return -1;
1850}
1851#endif
1852
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001853uint8_t acpi_get_preferred_pm_profile(void);
1854
Furquan Shaikhe0844632020-05-02 10:23:37 -07001855/* Returns ACPI_Sx values. */
1856int acpi_get_sleep_type(void);
1857
1858/* Read and clear GPE status */
1859int acpi_get_gpe(int gpe);
1860
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001861/* Once we enter payload, is SMI handler installed and capable of
1862 responding to APM_CNT Advanced Power Management Control commands. */
1863static inline int permanent_smi_handler(void)
1864{
1865 return CONFIG(HAVE_SMI_HANDLER);
1866}
1867
Furquan Shaikhe0844632020-05-02 10:23:37 -07001868static inline int acpi_s3_resume_allowed(void)
1869{
1870 return CONFIG(HAVE_ACPI_RESUME);
1871}
1872
Furquan Shaikhe0844632020-05-02 10:23:37 -07001873static inline int acpi_is_wakeup_s3(void)
1874{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001875 if (!acpi_s3_resume_allowed())
1876 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001877
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001878 if (ENV_ROMSTAGE_OR_BEFORE)
1879 return (acpi_get_sleep_type() == ACPI_S3);
1880
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001881 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001882}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001883
1884static inline uintptr_t acpi_align_current(uintptr_t current)
1885{
1886 return ALIGN_UP(current, 16);
1887}
1888
1889/* ACPI table revisions should match the revision of the ACPI spec
1890 * supported. This function keeps the table versions synced. This could
1891 * be made into a weak function if there is ever a need to override the
1892 * coreboot default ACPI spec version supported. */
1893int get_acpi_table_revision(enum acpi_tables table);
Elyes Haouas8b950f42022-02-16 12:08:16 +01001894u8 get_acpi_fadt_minor_version(void);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001895
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001896#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001897
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001898#endif /* __ACPI_ACPI_H__ */