blob: 9a9a66d50be65df82227dd26f23d355436458f46 [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 */
96 RSDP, /* Root System Description Pointer */
97 RSDT, /* Root System Description Table */
98 SLIT, /* System Locality Distance Information Table */
99 SPCR, /* Serial Port Console Redirection Table */
100 SRAT, /* System Resource Affinity Table */
101 SSDT, /* Secondary System Description Table */
102 TCPA, /* Trusted Computing Platform Alliance Table */
103 TPM2, /* Trusted Platform Module 2.0 Table */
104 XSDT, /* Extended System Description Table */
105
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 */
108 NHLT, /* Non HD audio Link Table */
109 SPMI, /* Server Platform Management Interface table */
110 VFCT /* VBIOS Fetch Table */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700111};
112
113/* RSDP (Root System Description Pointer) */
114typedef struct acpi_rsdp {
115 char signature[8]; /* RSDP signature */
116 u8 checksum; /* Checksum of the first 20 bytes */
117 char oem_id[6]; /* OEM ID */
118 u8 revision; /* RSDP revision */
119 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
120 u32 length; /* Total RSDP length (incl. extended part) */
121 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
122 u8 ext_checksum; /* Checksum of the whole table */
123 u8 reserved[3];
124} __packed acpi_rsdp_t;
125
126/* GAS (Generic Address Structure) */
127typedef struct acpi_gen_regaddr {
128 u8 space_id; /* Address space ID */
129 u8 bit_width; /* Register size in bits */
130 u8 bit_offset; /* Register bit offset */
131 u8 access_size; /* Access size since ACPI 2.0c */
132 u32 addrl; /* Register address, low 32 bits */
133 u32 addrh; /* Register address, high 32 bits */
134} __packed acpi_addr_t;
135
Elyes HAOUAS5f5fd852020-10-15 12:24:00 +0200136#define ACPI_ADDRESS_SPACE_MEMORY 0 /* System memory */
137#define ACPI_ADDRESS_SPACE_IO 1 /* System I/O */
138#define ACPI_ADDRESS_SPACE_PCI 2 /* PCI config space */
139#define ACPI_ADDRESS_SPACE_EC 3 /* Embedded controller */
140#define ACPI_ADDRESS_SPACE_SMBUS 4 /* SMBus */
141#define ACPI_ADDRESS_SPACE_CMOS 5 /* SystemCMOS */
142#define ACPI_ADDRESS_SPACE_PCI_BAR_TARGET 6 /* PciBarTarget */
143#define ACPI_ADDRESS_SPACE_IPMI 7 /* IPMI */
144#define ACPI_ADDRESS_SPACE_GENERAL_PURPOSE_IO 8 /* GeneralPurposeIO */
145#define ACPI_ADDRESS_SPACE_GENERIC_SERIAL_BUS 9 /* GenericSerialBus */
146#define ACPI_ADDRESS_SPACE_PCC 0x0A /* Platform Comm. Channel */
147#define ACPI_ADDRESS_SPACE_FIXED 0x7f /* Functional fixed hardware */
148#define ACPI_FFIXEDHW_VENDOR_INTEL 1 /* Intel */
149#define ACPI_FFIXEDHW_CLASS_HLT 0 /* C1 Halt */
150#define ACPI_FFIXEDHW_CLASS_IO_HLT 1 /* C1 I/O then Halt */
151#define ACPI_FFIXEDHW_CLASS_MWAIT 2 /* MWAIT Native C-state */
152#define ACPI_FFIXEDHW_FLAG_HW_COORD 1 /* Hardware Coordination bit */
153#define ACPI_FFIXEDHW_FLAG_BM_STS 2 /* BM_STS avoidance bit */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700154/* 0x80-0xbf: Reserved */
155/* 0xc0-0xff: OEM defined */
156
157/* Access size definitions for Generic address structure */
158#define ACPI_ACCESS_SIZE_UNDEFINED 0 /* Undefined (legacy reasons) */
159#define ACPI_ACCESS_SIZE_BYTE_ACCESS 1
160#define ACPI_ACCESS_SIZE_WORD_ACCESS 2
161#define ACPI_ACCESS_SIZE_DWORD_ACCESS 3
162#define ACPI_ACCESS_SIZE_QWORD_ACCESS 4
163
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200164/* Macros for common resource types */
165#define ACPI_REG_MSR(address, offset, width) \
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200166 (acpi_addr_t){ \
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200167 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
168 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
169 .addrl = address, \
170 .bit_offset = offset, \
171 .bit_width = width, \
172 }
173
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200174#define ACPI_REG_UNSUPPORTED (acpi_addr_t){0}
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200175
Furquan Shaikhe0844632020-05-02 10:23:37 -0700176/* Common ACPI HIDs */
177#define ACPI_HID_FDC "PNP0700"
178#define ACPI_HID_KEYBOARD "PNP0303"
179#define ACPI_HID_MOUSE "PNP0F03"
180#define ACPI_HID_COM "PNP0501"
181#define ACPI_HID_LPT "PNP0400"
182#define ACPI_HID_PNP "PNP0C02"
183#define ACPI_HID_CONTAINER "PNP0A05"
184
185/* Generic ACPI header, provided by (almost) all tables */
186typedef struct acpi_table_header {
187 char signature[4]; /* ACPI signature (4 ASCII characters) */
188 u32 length; /* Table length in bytes (incl. header) */
189 u8 revision; /* Table version (not ACPI version!) */
190 u8 checksum; /* To make sum of entire table == 0 */
191 char oem_id[6]; /* OEM identification */
192 char oem_table_id[8]; /* OEM table identification */
193 u32 oem_revision; /* OEM revision number */
194 char asl_compiler_id[4]; /* ASL compiler vendor ID */
195 u32 asl_compiler_revision; /* ASL compiler revision number */
196} __packed acpi_header_t;
197
198/* A maximum number of 32 ACPI tables ought to be enough for now. */
199#define MAX_ACPI_TABLES 32
200
201/* RSDT (Root System Description Table) */
202typedef struct acpi_rsdt {
203 acpi_header_t header;
204 u32 entry[MAX_ACPI_TABLES];
205} __packed acpi_rsdt_t;
206
207/* XSDT (Extended System Description Table) */
208typedef struct acpi_xsdt {
209 acpi_header_t header;
210 u64 entry[MAX_ACPI_TABLES];
211} __packed acpi_xsdt_t;
212
213/* HPET timers */
214typedef struct acpi_hpet {
215 acpi_header_t header;
216 u32 id;
217 acpi_addr_t addr;
218 u8 number;
219 u16 min_tick;
220 u8 attributes;
221} __packed acpi_hpet_t;
222
223/* MCFG (PCI Express MMIO config space BAR description table) */
224typedef struct acpi_mcfg {
225 acpi_header_t header;
226 u8 reserved[8];
227} __packed acpi_mcfg_t;
228
229typedef struct acpi_tcpa {
230 acpi_header_t header;
231 u16 platform_class;
232 u32 laml;
233 u64 lasa;
234} __packed acpi_tcpa_t;
235
236typedef struct acpi_tpm2 {
237 acpi_header_t header;
238 u16 platform_class;
239 u8 reserved[2];
240 u64 control_area;
241 u32 start_method;
242 u8 msp[12];
243 u32 laml;
244 u64 lasa;
245} __packed acpi_tpm2_t;
246
247typedef struct acpi_mcfg_mmconfig {
Naresh Solanki4d0b1842023-08-25 12:58:11 +0200248 u64 base_address;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700249 u16 pci_segment_group_number;
250 u8 start_bus_number;
251 u8 end_bus_number;
252 u8 reserved[4];
253} __packed acpi_mcfg_mmconfig_t;
254
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700255/*
Jonathan Zhang3dcafa82022-05-11 13:11:20 -0700256 * CEDT (CXL Early Discovery Table)
257 * CXL spec 2.0 section 9.14.1
258 */
259typedef struct acpi_cedt {
260 acpi_header_t header;
261 /* Followed by CEDT structures[n] */
262} __packed acpi_cedt_t;
263
264#define ACPI_CEDT_STRUCTURE_CHBS 0
265#define ACPI_CEDT_STRUCTURE_CFMWS 1
266
267#define ACPI_CEDT_CHBS_CXL_VER_1_1 0x00
268#define ACPI_CEDT_CHBS_CXL_VER_2_0 0x01
269
270/* CHBS: CXL Host Bridge Structure */
271typedef struct acpi_cedt_chbs {
272 u8 type; /* Always 0, other values reserved */
273 u8 resv1;
274 u16 length; /* Length in bytes (32) */
275 u32 uid; /* CXL Host Bridge Unique ID */
276 u32 cxl_ver;
277 u32 resv2;
278 /*
279 * For CXL 1.1, the base is Downstream Port Root Complex Resource Block;
280 * For CXL 2.0, the base is CXL Host Bridge Component Registers.
281 */
282 u64 base;
283 u64 len;
284} __packed acpi_cedt_chbs_t;
285
286#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_2_MEM (1 << 0)
287#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_3_MEM (1 << 1)
288#define ACPI_CEDT_CFMWS_RESTRICTION_VOLATIL (1 << 2)
289#define ACPI_CEDT_CFMWS_RESTRICTION_PERSISTENT (1 << 3)
290#define ACPI_CEDT_CFMWS_RESTRICTION_FIXED (1 << 4)
291
292/* CFMWS: CXL Fixed Memory Window Structure */
293typedef struct acpi_cedt_cfmws {
294 u8 type; /* Type (0) */
295 u8 resv1;
296 u16 length; /* Length in bytes (32) */
297 u32 resv2;
298 u64 base_hpa; /* Base of the HPA range, 256MB aligned */
299 u64 window_size; /* Number of bytes this window represents */
300 u8 eniw; /* Encoded Number of Interleave Ways */
301 u8 interleave_arithmetic; /* Standard Modulo arithmetic (0) */
302 u16 resv3;
303 u32 hbig; /* Host Bridge Interleave Granularity */
304 u16 restriction;
305 u16 qtg_id;
306 u32 interleave_target[]; /* Interleave Target List */
307} __packed acpi_cedt_cfmws_t;
308
309/*
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700310 * HMAT (Heterogeneous Memory Attribute Table)
311 * ACPI spec 6.4 section 5.2.27
312 */
313typedef struct acpi_hmat {
314 acpi_header_t header;
315 u32 resv;
316 /* Followed by HMAT table structure[n] */
317} __packed acpi_hmat_t;
318
319/* HMAT: Memory Proximity Domain Attributes structure */
320typedef struct acpi_hmat_mpda {
321 u16 type; /* Type (0) */
322 u16 resv;
323 u32 length; /* Length in bytes (40) */
324 u16 flags;
325 u16 resv1;
326 u32 proximity_domain_initiator;
327 u32 proximity_domain_memory;
328 u32 resv2;
329 u64 resv3;
330 u64 resv4;
331} __packed acpi_hmat_mpda_t;
332
333/* HMAT: System Locality Latency and Bandwidth Information structure */
334typedef struct acpi_hmat_sllbi {
335 u16 type; /* Type (1) */
336 u16 resv;
337 u32 length; /* Length in bytes */
338 u8 flags;
339 u8 data_type;
340 /*
341 * Transfer size defined as a 5-biased power of 2 exponent,
342 * when the bandwidth/latency value is achieved.
343 */
344 u8 min_transfer_size;
345 u8 resv1;
346 u32 num_initiator_domains;
347 u32 num_target_domains;
348 u32 resv2;
349 u64 entry_base_unit;
350 /* Followed by initiator proximity domain list */
351 /* Followed by target proximity domain list */
352 /* Followed by latency / bandwidth values */
353} __packed acpi_hmat_sllbi_t;
354
355/* HMAT: Memory Side Cache Information structure */
356typedef struct acpi_hmat_msci {
357 u16 type; /* Type (2) */
358 u16 resv;
359 u32 length; /* Length in bytes */
360 u32 domain; /* Proximity domain for the memory */
361 u32 resv1;
362 u64 cache_size;
363 /* Describes level, associativity, write policy, cache line size */
364 u32 cache_attributes;
365 u16 resv2;
366 /*
367 * Number of SMBIOS handlers that contribute to the
368 * memory side cache physical devices
369 */
370 u16 num_handlers;
371 /* Followed by SMBIOS handlers*/
372} __packed acpi_hmat_msci_t;
373
Furquan Shaikhe0844632020-05-02 10:23:37 -0700374/* SRAT (System Resource Affinity Table) */
375typedef struct acpi_srat {
376 acpi_header_t header;
377 u32 resv;
378 u64 resv1;
379 /* Followed by static resource allocation structure[n] */
380} __packed acpi_srat_t;
381
Jonathan Zhang3164b642021-04-21 17:51:31 -0700382#define ACPI_SRAT_STRUCTURE_LAPIC 0
383#define ACPI_SRAT_STRUCTURE_MEM 1
384#define ACPI_SRAT_STRUCTURE_GIA 5
385
Naresh Solanki76835cc2023-01-20 19:13:02 +0100386/* SRAT: Processor x2APIC Structure */
387typedef struct acpi_srat_x2apic {
388 u8 type; /* Type (0) */
389 u8 length; /* Length in bytes (16) */
390 u16 reserved; /* Reserved - Must be zero */
391 u32 proximity_domain; /* Proximity domain */
392 u32 x2apic_id; /* x2APIC ID */
393 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
394 u32 clock_domain; /* _CDM Clock Domain */
395 u32 reserved1; /* Reserved */
396} __packed acpi_srat_x2apic_t;
397
Furquan Shaikhe0844632020-05-02 10:23:37 -0700398/* SRAT: Processor Local APIC/SAPIC Affinity Structure */
399typedef struct acpi_srat_lapic {
400 u8 type; /* Type (0) */
401 u8 length; /* Length in bytes (16) */
402 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
403 u8 apic_id; /* Local APIC ID */
404 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
405 u8 local_sapic_eid; /* Local SAPIC EID */
406 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
407 u32 clock_domain; /* _CDM Clock Domain */
408} __packed acpi_srat_lapic_t;
409
410/* SRAT: Memory Affinity Structure */
411typedef struct acpi_srat_mem {
412 u8 type; /* Type (1) */
413 u8 length; /* Length in bytes (40) */
414 u32 proximity_domain; /* Proximity domain */
415 u16 resv;
416 u32 base_address_low; /* Mem range base address, low */
417 u32 base_address_high; /* Mem range base address, high */
418 u32 length_low; /* Mem range length, low */
419 u32 length_high; /* Mem range length, high */
420 u32 resv1;
421 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2,
422 * other bits reserved to 0
423 */
424 u32 resv2[2];
425} __packed acpi_srat_mem_t;
426
Jonathan Zhang3164b642021-04-21 17:51:31 -0700427/* SRAT: Generic Initiator Affinity Structure (ACPI spec 6.4 section 5.2.16.6) */
428typedef struct acpi_srat_gia {
429 u8 type; /* Type (5) */
430 u8 length; /* Length in bytes (32) */
431 u8 resv;
432 u8 dev_handle_type; /* Device handle type */
433 u32 proximity_domain; /*Proximity domain */
434 u8 dev_handle[16]; /* Device handle */
435 u32 flags;
436 u32 resv1;
437} __packed acpi_srat_gia_t;
438
439#define ACPI_SRAT_GIA_DEV_HANDLE_ACPI 0
440#define ACPI_SRAT_GIA_DEV_HANDLE_PCI 1
441
Furquan Shaikhe0844632020-05-02 10:23:37 -0700442/* SLIT (System Locality Distance Information Table) */
443typedef struct acpi_slit {
444 acpi_header_t header;
445 /* Followed by static resource allocation 8+byte[num*num] */
446} __packed acpi_slit_t;
447
448/* MADT (Multiple APIC Description Table) */
449typedef struct acpi_madt {
450 acpi_header_t header;
451 u32 lapic_addr; /* Local APIC address */
452 u32 flags; /* Multiple APIC flags */
453} __packed acpi_madt_t;
454
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100455/*
456 * LPIT (Low Power Idle Table)
457 * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017.
458 */
459typedef struct acpi_lpit {
460 acpi_header_t header;
461} __packed acpi_lpit_t;
462
463/* LPIT: LPI descriptor flags */
464typedef struct acpi_lpi_flags {
465 uint32_t disabled : 1;
466 uint32_t counter_not_available : 1;
467 uint32_t reserved : 30;
468} __packed acpi_lpi_desc_flags_t;
469
470/* LPIT: LPI descriptor types */
471enum acpi_lpi_desc_type {
472 ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00,
473 /* type >= 1 reserved */
474};
475
476/* LPIT: LPI descriptor header */
477typedef struct acpi_lpi_desc_hdr {
478 uint32_t type;
479 uint32_t length;
480 uint16_t uid;
481 uint16_t reserved;
482} __packed acpi_lpi_desc_hdr_t;
483
Sukumar Ghoraied1c03a2023-09-28 23:44:30 -0700484#define ACPI_LPIT_CTR_FREQ_TSC 0
Sukumar Ghoraibd9c5622023-10-07 23:19:34 -0700485
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100486
487/* LPIT: Native C-state instruction based LPI structure */
488typedef struct acpi_lpi_desc_ncst {
489 acpi_lpi_desc_hdr_t header;
490 acpi_lpi_desc_flags_t flags;
491 acpi_addr_t entry_trigger; /* Entry trigger C-state */
492 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
493 uint32_t max_latency; /* Worst case exit latency in microseconds */
494 acpi_addr_t residency_counter;
495 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
496} __packed acpi_lpi_desc_ncst_t;
497
Matt DeVillier7c04d0e2023-09-03 12:51:58 -0500498#define VFCT_VBIOS_CHECKSUM_OFFSET 0x21
499
Furquan Shaikhe0844632020-05-02 10:23:37 -0700500/* VFCT image header */
501typedef struct acpi_vfct_image_hdr {
502 u32 PCIBus;
503 u32 PCIDevice;
504 u32 PCIFunction;
505 u16 VendorID;
506 u16 DeviceID;
507 u16 SSVID;
508 u16 SSID;
509 u32 Revision;
510 u32 ImageLength;
Matt DeVillier7c04d0e2023-09-03 12:51:58 -0500511 u8 VbiosContent[]; // dummy - copy VBIOS here
Furquan Shaikhe0844632020-05-02 10:23:37 -0700512} __packed acpi_vfct_image_hdr_t;
513
514/* VFCT (VBIOS Fetch Table) */
515typedef struct acpi_vfct {
516 acpi_header_t header;
517 u8 TableUUID[16];
518 u32 VBIOSImageOffset;
519 u32 Lib1ImageOffset;
520 u32 Reserved[4];
521 acpi_vfct_image_hdr_t image_hdr;
522} __packed acpi_vfct_t;
523
524typedef struct acpi_ivrs_info {
525} __packed acpi_ivrs_info_t;
526
527/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
528typedef struct acpi_ivrs_ivhd {
529 uint8_t type;
530 uint8_t flags;
531 uint16_t length;
532 uint16_t device_id;
533 uint16_t capability_offset;
534 uint32_t iommu_base_low;
535 uint32_t iommu_base_high;
536 uint16_t pci_segment_group;
537 uint16_t iommu_info;
538 uint32_t iommu_feature_info;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200539 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700540} __packed acpi_ivrs_ivhd_t;
541
542/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
543typedef struct acpi_ivrs {
544 acpi_header_t header;
545 uint32_t iv_info;
546 uint32_t reserved[2];
547 struct acpi_ivrs_ivhd ivhd;
548} __packed acpi_ivrs_t;
549
Jason Glenesk61624b22020-11-02 20:06:23 -0800550/* CRAT (Component Resource Affinity Table Structure) */
551struct acpi_crat_header {
552 acpi_header_t header;
553 uint32_t total_entries;
554 uint16_t num_nodes;
555 uint8_t reserved[6];
556} __packed;
557
Furquan Shaikhe0844632020-05-02 10:23:37 -0700558/* IVHD Type 11h IOMMU Attributes */
559typedef struct ivhd11_iommu_attr {
560 uint32_t reserved1 : 13;
561 uint32_t perf_counters : 4;
562 uint32_t perf_counter_banks : 6;
563 uint32_t msi_num_ppr : 5;
564 uint32_t reserved2 : 4;
565} __packed ivhd11_iommu_attr_t;
566
567/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
568typedef struct acpi_ivrs_ivhd_11 {
569 uint8_t type;
570 uint8_t flags;
571 uint16_t length;
572 uint16_t device_id;
573 uint16_t capability_offset;
574 uint32_t iommu_base_low;
575 uint32_t iommu_base_high;
576 uint16_t pci_segment_group;
577 uint16_t iommu_info;
578 struct ivhd11_iommu_attr iommu_attributes;
579 uint32_t efr_reg_image_low;
580 uint32_t efr_reg_image_high;
581 uint32_t reserved[2];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200582 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700583} __packed acpi_ivrs_ivhd11_t;
584
585enum dev_scope_type {
586 SCOPE_PCI_ENDPOINT = 1,
587 SCOPE_PCI_SUB = 2,
588 SCOPE_IOAPIC = 3,
589 SCOPE_MSI_HPET = 4,
590 SCOPE_ACPI_NAMESPACE_DEVICE = 5
591};
592
593typedef struct dev_scope {
594 u8 type;
595 u8 length;
596 u8 reserved[2];
597 u8 enumeration;
598 u8 start_bus;
599 struct {
600 u8 dev;
601 u8 fn;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200602 } __packed path[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700603} __packed dev_scope_t;
604
605enum dmar_type {
606 DMAR_DRHD = 0,
607 DMAR_RMRR = 1,
608 DMAR_ATSR = 2,
609 DMAR_RHSA = 3,
John Zhao6edbb182021-03-24 11:55:09 -0700610 DMAR_ANDD = 4,
611 DMAR_SATC = 5
Furquan Shaikhe0844632020-05-02 10:23:37 -0700612};
613
614enum {
615 DRHD_INCLUDE_PCI_ALL = 1
616};
617
John Zhao091532d2021-04-17 16:03:21 -0700618enum {
619 ATC_REQUIRED = 1
620};
621
Furquan Shaikhe0844632020-05-02 10:23:37 -0700622enum dmar_flags {
623 DMAR_INTR_REMAP = 1 << 0,
624 DMAR_X2APIC_OPT_OUT = 1 << 1,
625 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
626};
627
628typedef struct dmar_entry {
629 u16 type;
630 u16 length;
631 u8 flags;
632 u8 reserved;
633 u16 segment;
634 u64 bar;
635} __packed dmar_entry_t;
636
637typedef struct dmar_rmrr_entry {
638 u16 type;
639 u16 length;
640 u16 reserved;
641 u16 segment;
642 u64 bar;
643 u64 limit;
644} __packed dmar_rmrr_entry_t;
645
646typedef struct dmar_atsr_entry {
647 u16 type;
648 u16 length;
649 u8 flags;
650 u8 reserved;
651 u16 segment;
652} __packed dmar_atsr_entry_t;
653
654typedef struct dmar_rhsa_entry {
655 u16 type;
656 u16 length;
657 u32 reserved;
658 u64 base_address;
659 u32 proximity_domain;
660} __packed dmar_rhsa_entry_t;
661
662typedef struct dmar_andd_entry {
663 u16 type;
664 u16 length;
665 u8 reserved[3];
666 u8 device_number;
667 u8 device_name[];
668} __packed dmar_andd_entry_t;
669
John Zhao6edbb182021-03-24 11:55:09 -0700670typedef struct dmar_satc_entry {
671 u16 type;
672 u16 length;
673 u8 flags;
674 u8 reserved;
675 u16 segment_number;
John Zhao6edbb182021-03-24 11:55:09 -0700676} __packed dmar_satc_entry_t;
677
Furquan Shaikhe0844632020-05-02 10:23:37 -0700678/* DMAR (DMA Remapping Reporting Structure) */
679typedef struct acpi_dmar {
680 acpi_header_t header;
681 u8 host_address_width;
682 u8 flags;
683 u8 reserved[10];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200684 dmar_entry_t structure[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700685} __packed acpi_dmar_t;
686
687/* MADT: APIC Structure Types */
688enum acpi_apic_types {
689 LOCAL_APIC, /* Processor local APIC */
690 IO_APIC, /* I/O APIC */
691 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
692 NMI_TYPE, /* NMI source */
693 LOCAL_APIC_NMI, /* Local APIC NMI */
694 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
695 IO_SAPIC, /* I/O SAPIC */
696 LOCAL_SAPIC, /* Local SAPIC */
697 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
698 LOCAL_X2APIC, /* Processor local x2APIC */
699 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
700 GICC, /* GIC CPU Interface */
701 GICD, /* GIC Distributor */
702 GIC_MSI_FRAME, /* GIC MSI Frame */
703 GICR, /* GIC Redistributor */
704 GIC_ITS, /* Interrupt Translation Service */
705 /* 0x10-0x7f: Reserved */
706 /* 0x80-0xff: Reserved for OEM use */
707};
708
709/* MADT: Processor Local APIC Structure */
710typedef struct acpi_madt_lapic {
711 u8 type; /* Type (0) */
712 u8 length; /* Length in bytes (8) */
713 u8 processor_id; /* ACPI processor ID */
714 u8 apic_id; /* Local APIC ID */
715 u32 flags; /* Local APIC flags */
716} __packed acpi_madt_lapic_t;
717
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300718#define ACPI_MADT_MAX_LAPIC_ID 0xfe
719
Furquan Shaikhe0844632020-05-02 10:23:37 -0700720/* MADT: Local APIC NMI Structure */
721typedef struct acpi_madt_lapic_nmi {
722 u8 type; /* Type (4) */
723 u8 length; /* Length in bytes (6) */
724 u8 processor_id; /* ACPI processor ID */
725 u16 flags; /* MPS INTI flags */
726 u8 lint; /* Local APIC LINT# */
727} __packed acpi_madt_lapic_nmi_t;
728
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200729#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
730#define ACPI_MADT_LX2APIC_NMI_ALL_PROCESSORS ((u32)-1)
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700731
Furquan Shaikhe0844632020-05-02 10:23:37 -0700732/* MADT: I/O APIC Structure */
733typedef struct acpi_madt_ioapic {
734 u8 type; /* Type (1) */
735 u8 length; /* Length in bytes (12) */
736 u8 ioapic_id; /* I/O APIC ID */
737 u8 reserved;
738 u32 ioapic_addr; /* I/O APIC address */
739 u32 gsi_base; /* Global system interrupt base */
740} __packed acpi_madt_ioapic_t;
741
Raul E Rangel169302a2022-04-25 14:59:05 -0600742#define MP_IRQ_POLARITY_DEFAULT 0x0
743#define MP_IRQ_POLARITY_HIGH 0x1
744#define MP_IRQ_POLARITY_LOW 0x3
745#define MP_IRQ_POLARITY_MASK 0x3
746#define MP_IRQ_TRIGGER_DEFAULT 0x0
747#define MP_IRQ_TRIGGER_EDGE 0x4
748#define MP_IRQ_TRIGGER_LEVEL 0xc
749#define MP_IRQ_TRIGGER_MASK 0xc
750
Furquan Shaikhe0844632020-05-02 10:23:37 -0700751/* MADT: Interrupt Source Override Structure */
752typedef struct acpi_madt_irqoverride {
753 u8 type; /* Type (2) */
754 u8 length; /* Length in bytes (10) */
755 u8 bus; /* ISA (0) */
756 u8 source; /* Bus-relative int. source (IRQ) */
757 u32 gsirq; /* Global system interrupt */
758 u16 flags; /* MPS INTI flags */
759} __packed acpi_madt_irqoverride_t;
760
761/* MADT: Processor Local x2APIC Structure */
762typedef struct acpi_madt_lx2apic {
763 u8 type; /* Type (9) */
764 u8 length; /* Length in bytes (16) */
765 u16 reserved;
766 u32 x2apic_id; /* Local x2APIC ID */
767 u32 flags; /* Same as Local APIC flags */
768 u32 processor_id; /* ACPI processor ID */
769} __packed acpi_madt_lx2apic_t;
770
771/* MADT: Processor Local x2APIC NMI Structure */
772typedef struct acpi_madt_lx2apic_nmi {
773 u8 type; /* Type (10) */
774 u8 length; /* Length in bytes (12) */
775 u16 flags; /* Same as MPS INTI flags */
776 u32 processor_id; /* ACPI processor ID */
777 u8 lint; /* Local APIC LINT# */
778 u8 reserved[3];
779} __packed acpi_madt_lx2apic_nmi_t;
780
Arthur Heymans51d94c72023-06-27 15:37:37 +0200781/* MADT: GIC CPU Interface (GICC) Structure 6.5 */
782struct gicc_flags {
783 uint32_t enabled : 1;
784 /* 0 - Level-triggered | 1 - Edge-Triggered */
785 uint32_t performance_interrupt_mode : 1;
786 uint32_t vgic_maintenance_interrupt_mode : 1;
787 uint32_t online_capable : 1;
788 uint32_t reserved : 28;
789};
790_Static_assert(sizeof(struct gicc_flags) == sizeof(uint32_t), "Wrong gicc_flags size\n");
791
792typedef struct acpi_gicc {
793 uint8_t type;
794 uint8_t length;
795 uint16_t reserved;
796 uint32_t cpu_interface_number;
797 uint32_t acpi_processor_uid;
798 struct gicc_flags flags;
799 uint32_t parking_protocol_version;
800 uint32_t performance_interrupt_gsiv;
801 uint64_t parked_address;
802 uint64_t physical_base_address; /* GIC v1/v2 or GIC v3/v4 in v2 compat mode */
803 uint64_t gicv;
804 uint64_t gich;
805 uint32_t vgic_maintenance_interrupt;
806 uint64_t gicr_base_address; /* Only GIC v3 and above */
807 uint64_t mpidr;
808 uint8_t processor_power_efficiency_class;
809 uint8_t reserved1;
810 uint16_t spe_overflow_interrupt;
811 uint16_t trbe_interrupt;
812} __packed acpi_madt_gicc_t;
813_Static_assert(sizeof(acpi_madt_gicc_t) == 82, "Wrong acpi_madt_gicc_t size\n");
814
815/* MADT: GIC Distributor (GICD) Structure */
816typedef struct acpi_gicd {
817 uint8_t type;
818 uint8_t length;
819 uint16_t reserved1;
820 uint32_t gic_id;
821 uint64_t physical_base_address;
822 uint32_t system_vector_base;
823 uint8_t gic_version;
824 uint8_t reserved2[3];
825} __packed acpi_madt_gicd_t;
826_Static_assert(sizeof(acpi_madt_gicd_t) == 24, "Wrong acpi_madt_gicd_t size\n");
827
828/* MADT: GIC MSI Frame Structure */
829struct gic_msi_flags {
830 uint32_t spi_count_select : 1;
831 uint32_t reserved : 31;
832};
833_Static_assert(sizeof(struct gic_msi_flags) == sizeof(uint32_t), "Wrong gic_msi_flags size\n");
834
835typedef struct acpi_gic_msi {
836 uint8_t type;
837 uint8_t length;
838 uint16_t reserved;
839 uint32_t gic_msi_frame_id;
840 uint64_t physical_base_address;
841 struct gic_msi_flags flags;
842 uint16_t spi_count;
843 uint16_t spi_base;
844} __packed acpi_gic_msi_t;
845_Static_assert(sizeof(acpi_gic_msi_t) == 24, "Wrong acpi_gic_msi_t size\n");
846
847/* MADT: GIC Redistributor (GICR) Structure */
848typedef struct acpi_girr {
849 uint8_t type;
850 uint8_t length;
851 uint16_t reserved;
852 uint64_t discovery_range_base_address;
853 uint32_t discovery_range_length;
854} __packed acpi_madt_gicr_t;
855_Static_assert(sizeof(acpi_madt_gicr_t) == 16, "Wrong acpi_madt_gicr_t size\n");
856
857/* MADT: GIC Interrupt Translation Service (ITS) Structure */
858typedef struct acpi_gic_its {
859 uint8_t type;
860 uint8_t length;
861 uint16_t reserved;
862 uint32_t gic_its_id;
863 uint64_t physical_base_address;
864 uint32_t reserved2;
865} __packed acpi_madt_gic_its_t;
866_Static_assert(sizeof(acpi_madt_gic_its_t) == 20, "Wrong MADT acpi_madt_gic_its_t size\n");
867
Furquan Shaikhe0844632020-05-02 10:23:37 -0700868#define ACPI_DBG2_PORT_SERIAL 0x8000
869#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
870#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
871#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
872#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
873#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
874#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
875#define ACPI_DBG2_PORT_IEEE1394 0x8001
876#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
877#define ACPI_DBG2_PORT_USB 0x8002
878#define ACPI_DBG2_PORT_USB_XHCI 0x0000
879#define ACPI_DBG2_PORT_USB_EHCI 0x0001
880#define ACPI_DBG2_PORT_NET 0x8003
881
882/* DBG2: Microsoft Debug Port Table 2 header */
883typedef struct acpi_dbg2_header {
884 acpi_header_t header;
885 uint32_t devices_offset;
886 uint32_t devices_count;
Elyes Haouas139cb062023-08-26 17:04:21 +0200887} __packed acpi_dbg2_header_t;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700888
889/* DBG2: Microsoft Debug Port Table 2 device entry */
890typedef struct acpi_dbg2_device {
891 uint8_t revision;
892 uint16_t length;
893 uint8_t address_count;
894 uint16_t namespace_string_length;
895 uint16_t namespace_string_offset;
896 uint16_t oem_data_length;
897 uint16_t oem_data_offset;
898 uint16_t port_type;
899 uint16_t port_subtype;
900 uint8_t reserved[2];
901 uint16_t base_address_offset;
902 uint16_t address_size_offset;
Elyes Haouas139cb062023-08-26 17:04:21 +0200903} __packed acpi_dbg2_device_t;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700904
905/* FADT (Fixed ACPI Description Table) */
906typedef struct acpi_fadt {
907 acpi_header_t header;
908 u32 firmware_ctrl;
909 u32 dsdt;
910 u8 reserved; /* Should be 0 */
911 u8 preferred_pm_profile;
912 u16 sci_int;
913 u32 smi_cmd;
914 u8 acpi_enable;
915 u8 acpi_disable;
916 u8 s4bios_req;
917 u8 pstate_cnt;
918 u32 pm1a_evt_blk;
919 u32 pm1b_evt_blk;
920 u32 pm1a_cnt_blk;
921 u32 pm1b_cnt_blk;
922 u32 pm2_cnt_blk;
923 u32 pm_tmr_blk;
924 u32 gpe0_blk;
925 u32 gpe1_blk;
926 u8 pm1_evt_len;
927 u8 pm1_cnt_len;
928 u8 pm2_cnt_len;
929 u8 pm_tmr_len;
930 u8 gpe0_blk_len;
931 u8 gpe1_blk_len;
932 u8 gpe1_base;
933 u8 cst_cnt;
934 u16 p_lvl2_lat;
935 u16 p_lvl3_lat;
936 u16 flush_size;
937 u16 flush_stride;
938 u8 duty_offset;
939 u8 duty_width;
940 u8 day_alrm;
941 u8 mon_alrm;
942 u8 century;
943 u16 iapc_boot_arch;
944 u8 res2;
945 u32 flags;
946 acpi_addr_t reset_reg;
947 u8 reset_value;
Elyes Haouasb55ac092022-02-16 14:42:19 +0100948 u16 ARM_boot_arch; /* Must be zero if ACPI Revision <= 5.0 */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100949 u8 FADT_MinorVersion; /* Must be zero if ACPI Revision <= 5.0 */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700950 u32 x_firmware_ctl_l;
951 u32 x_firmware_ctl_h;
952 u32 x_dsdt_l;
953 u32 x_dsdt_h;
954 acpi_addr_t x_pm1a_evt_blk;
955 acpi_addr_t x_pm1b_evt_blk;
956 acpi_addr_t x_pm1a_cnt_blk;
957 acpi_addr_t x_pm1b_cnt_blk;
958 acpi_addr_t x_pm2_cnt_blk;
959 acpi_addr_t x_pm_tmr_blk;
960 acpi_addr_t x_gpe0_blk;
961 acpi_addr_t x_gpe1_blk;
962 /* Revision 5 */
963 acpi_addr_t sleep_control_reg;
964 acpi_addr_t sleep_status_reg;
965 /* Revision 6 */
966 u64 hypervisor_vendor_identity;
967} __packed acpi_fadt_t;
968
969/* FADT TABLE Revision values */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100970#define ACPI_FADT_REV_ACPI_1 1
971#define ACPI_FADT_REV_ACPI_2 3
972#define ACPI_FADT_REV_ACPI_3 4
973#define ACPI_FADT_REV_ACPI_4 4
974#define ACPI_FADT_REV_ACPI_5 5
975#define ACPI_FADT_REV_ACPI_6 6
976
977/* FADT Minor Version value:
978 * Bits 0-3: minor version
979 * Bits 4-7: Errata
980 * value of 1 means this is compatible with Errata A,
981 * value of 2 would be compatible with Errata B, and so on
982 * Version 6.3 Errata A would be: (1 << 4) | 3
983 */
984#define ACPI_FADT_MINOR_VERSION_0 0 /* coreboot currently use this version */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700985
986/* Flags for p_lvl2_lat and p_lvl3_lat */
987#define ACPI_FADT_C2_NOT_SUPPORTED 101
988#define ACPI_FADT_C3_NOT_SUPPORTED 1001
989
990/* FADT Feature Flags */
991#define ACPI_FADT_WBINVD (1 << 0)
992#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
993#define ACPI_FADT_C1_SUPPORTED (1 << 2)
994#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
995#define ACPI_FADT_POWER_BUTTON (1 << 4)
996#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
997#define ACPI_FADT_FIXED_RTC (1 << 6)
998#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
999#define ACPI_FADT_32BIT_TIMER (1 << 8)
1000#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
1001#define ACPI_FADT_RESET_REGISTER (1 << 10)
1002#define ACPI_FADT_SEALED_CASE (1 << 11)
1003#define ACPI_FADT_HEADLESS (1 << 12)
1004#define ACPI_FADT_SLEEP_TYPE (1 << 13)
1005#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
1006#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
1007#define ACPI_FADT_S4_RTC_VALID (1 << 16)
1008#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
1009#define ACPI_FADT_APIC_CLUSTER (1 << 18)
1010#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
1011/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
1012#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
1013#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
1014/* bits 22-31: reserved since ACPI 5.0 */
1015
1016/* FADT Boot Architecture Flags */
1017#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
1018#define ACPI_FADT_8042 (1 << 1)
1019#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
1020#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
1021#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
1022#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
1023#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
1024
1025/* FADT ARM Boot Architecture Flags */
1026#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
1027#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
1028/* bits 2-16: reserved since ACPI 5.1 */
1029
1030/* FADT Preferred Power Management Profile */
1031enum acpi_preferred_pm_profiles {
1032 PM_UNSPECIFIED = 0,
1033 PM_DESKTOP = 1,
1034 PM_MOBILE = 2,
1035 PM_WORKSTATION = 3,
1036 PM_ENTERPRISE_SERVER = 4,
1037 PM_SOHO_SERVER = 5,
1038 PM_APPLIANCE_PC = 6,
1039 PM_PERFORMANCE_SERVER = 7,
1040 PM_TABLET = 8, /* ACPI 5.0 & greater */
1041};
1042
1043/* FACS (Firmware ACPI Control Structure) */
1044typedef struct acpi_facs {
1045 char signature[4]; /* "FACS" */
1046 u32 length; /* Length in bytes (>= 64) */
1047 u32 hardware_signature; /* Hardware signature */
1048 u32 firmware_waking_vector; /* Firmware waking vector */
1049 u32 global_lock; /* Global lock */
1050 u32 flags; /* FACS flags */
1051 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
1052 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
1053 u8 version; /* FACS version */
1054 u8 resv1[3]; /* This value is 0 */
1055 u32 ospm_flags; /* 64BIT_WAKE_F */
1056 u8 resv2[24]; /* This value is 0 */
1057} __packed acpi_facs_t;
1058
1059/* FACS flags */
1060#define ACPI_FACS_S4BIOS_F (1 << 0)
1061#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
1062/* Bits 31..2: reserved */
1063
1064/* ECDT (Embedded Controller Boot Resources Table) */
1065typedef struct acpi_ecdt {
1066 acpi_header_t header;
1067 acpi_addr_t ec_control; /* EC control register */
1068 acpi_addr_t ec_data; /* EC data register */
1069 u32 uid; /* UID */
1070 u8 gpe_bit; /* GPE bit */
1071 u8 ec_id[]; /* EC ID */
1072} __packed acpi_ecdt_t;
1073
1074/* HEST (Hardware Error Source Table) */
1075typedef struct acpi_hest {
1076 acpi_header_t header;
1077 u32 error_source_count;
1078 /* error_source_struct(s) */
1079} __packed acpi_hest_t;
1080
1081/* Error Source Descriptors */
1082typedef struct acpi_hest_esd {
1083 u16 type;
1084 u16 source_id;
1085 u16 resv;
1086 u8 flags;
1087 u8 enabled;
1088 u32 prealloc_erecords; /* The number of error records to
1089 * pre-allocate for this error source.
1090 */
1091 u32 max_section_per_record;
1092} __packed acpi_hest_esd_t;
1093
1094/* Hardware Error Notification */
1095typedef struct acpi_hest_hen {
1096 u8 type;
1097 u8 length;
1098 u16 conf_we; /* Configuration Write Enable */
1099 u32 poll_interval;
1100 u32 vector;
1101 u32 sw2poll_threshold_val;
1102 u32 sw2poll_threshold_win;
1103 u32 error_threshold_val;
1104 u32 error_threshold_win;
1105} __packed acpi_hest_hen_t;
1106
1107/* BERT (Boot Error Record Table) */
1108typedef struct acpi_bert {
1109 acpi_header_t header;
1110 u32 region_length;
1111 u64 error_region;
1112} __packed acpi_bert_t;
1113
1114/* Generic Error Data Entry */
1115typedef struct acpi_hest_generic_data {
1116 guid_t section_type;
1117 u32 error_severity;
1118 u16 revision;
1119 u8 validation_bits;
1120 u8 flags;
1121 u32 data_length;
1122 guid_t fru_id;
1123 u8 fru_text[20];
1124 /* error data */
1125} __packed acpi_hest_generic_data_t;
1126
1127/* Generic Error Data Entry v300 */
1128typedef struct acpi_hest_generic_data_v300 {
1129 guid_t section_type;
1130 u32 error_severity;
1131 u16 revision;
1132 u8 validation_bits;
1133 u8 flags; /* see CPER Section Descriptor, Flags field */
1134 u32 data_length;
1135 guid_t fru_id;
1136 u8 fru_text[20];
1137 cper_timestamp_t timestamp;
1138 /* error data */
1139} __packed acpi_hest_generic_data_v300_t;
1140#define HEST_GENERIC_ENTRY_V300 0x300
1141
1142/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
1143#define ACPI_GENERROR_SEV_RECOVERABLE 0
1144#define ACPI_GENERROR_SEV_FATAL 1
1145#define ACPI_GENERROR_SEV_CORRECTED 2
1146#define ACPI_GENERROR_SEV_NONE 3
1147
1148/* Generic Error Data Entry, Validation Bits field */
1149#define ACPI_GENERROR_VALID_FRUID BIT(0)
1150#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
1151#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
1152
Felix Held403fa862021-07-26 22:43:00 +02001153/*
1154 * Generic Error Status Block
1155 *
1156 * If there is a raw data section at the end of the generic error status block after the
1157 * zero or more generic error data entries, raw_data_length indicates the length of the raw
1158 * section and raw_data_offset is the offset of the beginning of the raw data section from
1159 * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length
1160 * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t).
1161 */
Furquan Shaikhe0844632020-05-02 10:23:37 -07001162typedef struct acpi_generic_error_status {
1163 u32 block_status;
1164 u32 raw_data_offset; /* must follow any generic entries */
1165 u32 raw_data_length;
1166 u32 data_length; /* generic data */
1167 u32 error_severity;
1168 /* Generic Error Data structures, zero or more entries */
1169} __packed acpi_generic_error_status_t;
1170
1171/* Generic Status Block, Block Status values */
1172#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
1173#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
1174#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
1175#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
1176#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
1177#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
1178#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
1179 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
1180 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
1181
1182typedef struct acpi_cstate {
1183 u8 ctype;
1184 u16 latency;
1185 u32 power;
1186 acpi_addr_t resource;
1187} __packed acpi_cstate_t;
1188
Jason Gleneskca36aed2020-09-15 21:01:57 -07001189struct acpi_sw_pstate {
1190 u32 core_freq;
1191 u32 power;
1192 u32 transition_latency;
1193 u32 bus_master_latency;
1194 u32 control_value;
1195 u32 status_value;
1196} __packed;
1197
1198struct acpi_xpss_sw_pstate {
1199 u64 core_freq;
1200 u64 power;
1201 u64 transition_latency;
1202 u64 bus_master_latency;
1203 u64 control_value;
1204 u64 status_value;
1205 u64 control_mask;
1206 u64 status_mask;
1207} __packed;
1208
Furquan Shaikhe0844632020-05-02 10:23:37 -07001209typedef struct acpi_tstate {
1210 u32 percent;
1211 u32 power;
1212 u32 latency;
1213 u32 control;
1214 u32 status;
1215} __packed acpi_tstate_t;
1216
Raul E Rangelc7048322021-04-19 15:58:25 -06001217enum acpi_lpi_state_flags {
1218 ACPI_LPI_STATE_DISABLED = 0,
1219 ACPI_LPI_STATE_ENABLED
1220};
1221
1222/* Low Power Idle State */
1223struct acpi_lpi_state {
1224 u32 min_residency_us;
1225 u32 worst_case_wakeup_latency_us;
1226 u32 flags;
1227 u32 arch_context_lost_flags;
1228 u32 residency_counter_frequency_hz;
1229 u32 enabled_parent_state;
1230 acpi_addr_t entry_method;
1231 acpi_addr_t residency_counter_register;
1232 acpi_addr_t usage_counter_register;
1233 const char *state_name;
1234};
1235
Furquan Shaikhe0844632020-05-02 10:23:37 -07001236/* Port types for ACPI _UPC object */
1237enum acpi_upc_type {
1238 UPC_TYPE_A,
1239 UPC_TYPE_MINI_AB,
1240 UPC_TYPE_EXPRESSCARD,
1241 UPC_TYPE_USB3_A,
1242 UPC_TYPE_USB3_B,
1243 UPC_TYPE_USB3_MICRO_B,
1244 UPC_TYPE_USB3_MICRO_AB,
1245 UPC_TYPE_USB3_POWER_B,
1246 UPC_TYPE_C_USB2_ONLY,
1247 UPC_TYPE_C_USB2_SS_SWITCH,
1248 UPC_TYPE_C_USB2_SS,
1249 UPC_TYPE_PROPRIETARY = 0xff,
1250 /*
1251 * The following types are not directly defined in the ACPI
1252 * spec but are used by coreboot to identify a USB device type.
1253 */
1254 UPC_TYPE_INTERNAL = 0xff,
1255 UPC_TYPE_UNUSED,
1256 UPC_TYPE_HUB
1257};
1258
1259enum acpi_ipmi_interface_type {
1260 IPMI_INTERFACE_RESERVED = 0,
1261 IPMI_INTERFACE_KCS,
1262 IPMI_INTERFACE_SMIC,
1263 IPMI_INTERFACE_BT,
1264 IPMI_INTERFACE_SSIF,
1265};
1266
1267#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
1268#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
1269#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
1270
1271/* ACPI IPMI 2.0 */
1272struct acpi_spmi {
1273 acpi_header_t header;
1274 u8 interface_type;
1275 u8 reserved;
1276 u16 specification_revision;
1277 u8 interrupt_type;
1278 u8 gpe;
1279 u8 reserved2;
1280 u8 pci_device_flag;
1281
1282 u32 global_system_interrupt;
1283 acpi_addr_t base_address;
1284 union {
1285 struct {
1286 u8 pci_segment_group;
1287 u8 pci_bus;
1288 u8 pci_device;
1289 u8 pci_function;
1290 };
1291 u8 uid[4];
1292 };
1293 u8 reserved3;
1294} __packed;
1295
Rocky Phaguraeff07132021-01-10 15:42:50 -08001296/* EINJ APEI Standard Definitions */
1297/* EINJ Error Types
1298 Refer to the ACPI spec, EINJ section, for more info on bit definitions
1299*/
1300#define ACPI_EINJ_CPU_CE (1 << 0)
1301#define ACPI_EINJ_CPU_UCE (1 << 1)
1302#define ACPI_EINJ_CPU_UCE_FATAL (1 << 2)
1303#define ACPI_EINJ_MEM_CE (1 << 3)
1304#define ACPI_EINJ_MEM_UCE (1 << 4)
1305#define ACPI_EINJ_MEM_UCE_FATAL (1 << 5)
1306#define ACPI_EINJ_PCIE_CE (1 << 6)
1307#define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7)
1308#define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8)
1309#define ACPI_EINJ_PLATFORM_CE (1 << 9)
1310#define ACPI_EINJ_PLATFORM_UCE (1 << 10)
1311#define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11)
1312#define ACPI_EINJ_VENDOR_DEFINED (1 << 31)
1313#define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \
1314 ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL)
1315
1316/* EINJ actions */
1317#define ACTION_COUNT 9
1318#define BEGIN_INJECT_OP 0x00
1319#define GET_TRIGGER_ACTION_TABLE 0x01
1320#define SET_ERROR_TYPE 0x02
1321#define GET_ERROR_TYPE 0x03
1322#define END_INJECT_OP 0x04
1323#define EXECUTE_INJECT_OP 0x05
1324#define CHECK_BUSY_STATUS 0x06
1325#define GET_CMD_STATUS 0x07
1326#define SET_ERROR_TYPE_WITH_ADDRESS 0x08
1327#define TRIGGER_ERROR 0xFF
1328
1329/* EINJ Instructions */
1330#define READ_REGISTER 0x00
1331#define READ_REGISTER_VALUE 0x01
1332#define WRITE_REGISTER 0x02
1333#define WRITE_REGISTER_VALUE 0x03
1334#define NO_OP 0x04
1335
1336/* EINJ (Error Injection Table) */
1337typedef struct acpi_gen_regaddr1 {
1338 u8 space_id; /* Address space ID */
1339 u8 bit_width; /* Register size in bits */
1340 u8 bit_offset; /* Register bit offset */
1341 u8 access_size; /* Access size since ACPI 2.0c */
1342 u64 addr; /* Register address */
1343} __packed acpi_addr64_t;
1344
1345/* Instruction entry */
1346typedef struct acpi_einj_action_table {
1347 u8 action;
1348 u8 instruction;
1349 u16 flags;
1350 acpi_addr64_t reg;
1351 u64 value;
1352 u64 mask;
1353} __packed acpi_einj_action_table_t;
1354
1355typedef struct acpi_injection_header {
1356 u32 einj_header_size;
1357 u32 flags;
1358 u32 entry_count;
1359} __packed acpi_injection_header_t;
1360
1361typedef struct acpi_einj_trigger_table {
1362 u32 header_size;
1363 u32 revision;
1364 u32 table_size;
1365 u32 entry_count;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +02001366 acpi_einj_action_table_t trigger_action[];
Rocky Phaguraeff07132021-01-10 15:42:50 -08001367} __packed acpi_einj_trigger_table_t;
1368
1369typedef struct set_error_type {
1370 u32 errtype;
1371 u32 vendorerrortype;
1372 u32 flags;
1373 u32 apicid;
1374 u64 memaddr;
1375 u64 memrange;
1376 u32 pciesbdf;
1377} __packed set_error_type_t;
1378
1379#define EINJ_PARAM_NUM 6
1380typedef struct acpi_einj_smi {
1381 u64 op_state;
1382 u64 err_inject[EINJ_PARAM_NUM];
1383 u64 trigger_action_table;
1384 u64 err_inj_cap;
1385 u64 op_status;
1386 u64 cmd_sts;
1387 u64 einj_addr;
1388 u64 einj_addr_msk;
1389 set_error_type_t setaddrtable;
1390 u64 reserved[50];
1391} __packed acpi_einj_smi_t;
1392
1393/* EINJ Flags */
1394#define EINJ_DEF_TRIGGER_PORT 0xb2
1395#define FLAG_PRESERVE 0x01
1396#define FLAG_IGNORE 0x00
1397
1398/* EINJ Registers */
1399#define EINJ_REG_MEMORY(address) \
1400 { \
1401 .space_id = ACPI_ADDRESS_SPACE_MEMORY, \
1402 .bit_width = 64, \
1403 .bit_offset = 0, \
1404 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
1405 .addr = address}
1406
1407#define EINJ_REG_IO() \
1408 { \
1409 .space_id = ACPI_ADDRESS_SPACE_IO, \
1410 .bit_width = 0x10, \
1411 .bit_offset = 0, \
1412 .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \
1413 .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */
1414
1415typedef struct acpi_einj {
1416 acpi_header_t header;
1417 acpi_injection_header_t inj_header;
1418 acpi_einj_action_table_t action_table[ACTION_COUNT];
1419} __packed acpi_einj_t;
1420
Arthur Heymanse7aaf042023-06-07 12:12:45 +02001421/* SPCR (Serial Port Console Redirection Table) */
1422typedef struct acpi_spcr {
1423 acpi_header_t header;
1424 uint8_t interface_type;
1425 uint8_t reserved[3];
1426 acpi_addr_t base_address;
1427 uint8_t interrupt_type;
1428 uint8_t irq;
1429 uint32_t global_system_interrupt;
1430 uint8_t configured_baudrate;
1431 uint8_t parity;
1432 uint8_t stop_bits;
1433 uint8_t flow_control;
1434 uint8_t terminal_type;
1435 uint8_t language;
1436 uint16_t pci_did;
1437 uint16_t pci_vid;
1438 uint8_t pci_bus;
1439 uint8_t pci_dev;
1440 uint8_t pci_fun;
1441 uint32_t pci_flags;
1442 uint8_t pci_segment;
1443 uint32_t uart_clock;
1444 uint32_t precise_baud_rate;
1445 uint16_t namespace_string_length;
1446 uint16_t namespace_string_offset;
1447 char namespacestring[];
1448} __packed acpi_spcr_t;
1449_Static_assert(sizeof(acpi_spcr_t) == 88, "acpi_spcr_t must have an 88 byte size\n");
1450
Arthur Heymans90464072023-06-07 12:53:50 +02001451#define PC_AT_COMPATIBLE_INTERRUPT (1 << 0)
1452#define IO_APIC_COMPATIBLE_INTERRUPT (1 << 1)
1453#define IO_SAPIC_COMPATIBLE_INTERRUPT (1 << 2)
1454#define ARMH_GIC_COMPATIBLE_INTERRUPT (1 << 3)
1455#define RISCV_PLIC_COMPATIBLE_INTERRUPT (1 << 4)
1456
Arthur Heymans8193eab2023-06-20 10:17:23 +02001457/* GTDT - Generic Timer Description Table (ACPI 5.1) Version 2 */
1458typedef struct acpi_table_gtdt {
1459 acpi_header_t header; /* Common ACPI table header */
Naresh Solanki75f0b602023-09-25 13:59:25 +02001460 u64 counter_block_address;
Arthur Heymans8193eab2023-06-20 10:17:23 +02001461 u32 reserved;
1462 u32 secure_el1_interrupt;
1463 u32 secure_el1_flags;
1464 u32 non_secure_el1_interrupt;
1465 u32 non_secure_el1_flags;
1466 u32 virtual_timer_interrupt;
1467 u32 virtual_timer_flags;
1468 u32 non_secure_el2_interrupt;
1469 u32 non_secure_el2_flags;
1470 u64 counter_read_block_address;
1471 u32 platform_timer_count;
1472 u32 platform_timer_offset;
1473} __packed acpi_gtdt_t;
1474
1475/* Flag Definitions: Timer Block Physical Timers and Virtual timers */
1476
1477#define ACPI_GTDT_INTERRUPT_MODE (1)
1478#define ACPI_GTDT_INTERRUPT_POLARITY (1<<1)
1479#define ACPI_GTDT_ALWAYS_ON (1<<2)
1480
1481struct acpi_gtdt_el2 {
1482 u32 virtual_el2_timer_gsiv;
1483 u32 virtual_el2_timer_flags;
1484};
1485
1486/* Common GTDT subtable header */
1487
1488struct acpi_gtdt_header {
1489 u8 type;
1490 u16 length;
1491} __packed;
1492
1493/* Values for GTDT subtable type above */
1494
1495enum acpi_gtdt_type {
1496 ACPI_GTDT_TYPE_TIMER_BLOCK = 0,
1497 ACPI_GTDT_TYPE_WATCHDOG = 1,
1498 ACPI_GTDT_TYPE_RESERVED = 2 /* 2 and greater are reserved */
1499};
1500
1501/* GTDT Subtables, correspond to Type in struct acpi_gtdt_header */
1502
1503/* 0: Generic Timer Block */
1504
1505struct acpi_gtdt_timer_block {
1506 struct acpi_gtdt_header header;
1507 u8 reserved;
1508 u64 block_address;
1509 u32 timer_count;
1510 u32 timer_offset;
1511} __packed;
1512
1513/* Timer Sub-Structure, one per timer */
1514
1515struct acpi_gtdt_timer_entry {
1516 u8 frame_number;
1517 u8 reserved[3];
1518 u64 base_address;
1519 u64 el0_base_address;
1520 u32 timer_interrupt;
1521 u32 timer_flags;
1522 u32 virtual_timer_interrupt;
1523 u32 virtual_timer_flags;
1524 u32 common_flags;
1525} __packed;
1526
1527/* Flag Definitions: timer_flags and virtual_timer_flags above */
1528
1529#define ACPI_GTDT_GT_IRQ_MODE (1)
1530#define ACPI_GTDT_GT_IRQ_POLARITY (1<<1)
1531
1532/* Flag Definitions: common_flags above */
1533
1534#define ACPI_GTDT_GT_IS_SECURE_TIMER (1)
1535#define ACPI_GTDT_GT_ALWAYS_ON (1<<1)
1536
1537/* 1: SBSA Generic Watchdog Structure */
1538
1539struct acpi_gtdt_watchdog {
1540 struct acpi_gtdt_header header;
1541 u8 reserved;
1542 u64 refresh_frame_address;
1543 u64 control_frame_address;
1544 u32 timer_interrupt;
1545 u32 timer_flags;
1546} __packed;
1547
1548/* Flag Definitions: timer_flags above */
1549
1550#define ACPI_GTDT_WATCHDOG_IRQ_MODE (1)
1551#define ACPI_GTDT_WATCHDOG_IRQ_POLARITY (1<<1)
1552#define ACPI_GTDT_WATCHDOG_SECURE (1<<2)
1553
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01001554uintptr_t get_coreboot_rsdp(void);
Rocky Phaguraeff07132021-01-10 15:42:50 -08001555void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);
1556
Furquan Shaikhe0844632020-05-02 10:23:37 -07001557unsigned long fw_cfg_acpi_tables(unsigned long start);
1558
1559/* These are implemented by the target port or north/southbridge. */
Raul E Rangel6b446b92021-11-19 11:38:35 -07001560void preload_acpi_dsdt(void);
Arthur Heymans7ebebf72023-06-17 14:08:46 +02001561unsigned long write_acpi_tables(const unsigned long addr);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001562unsigned long acpi_fill_madt(unsigned long current);
Arthur Heymanscd46e5f2023-06-22 21:34:16 +02001563unsigned long acpi_arch_fill_madt(acpi_madt_t *madt, unsigned long current);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001564
Furquan Shaikhe0844632020-05-02 10:23:37 -07001565void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +02001566void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001567void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001568void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001569
Kyösti Mälkki88decca2023-04-28 07:04:34 +03001570void fill_fadt_extended_pm_io(acpi_fadt_t *fadt);
1571
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001572void acpi_fill_gnvs(void);
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02001573void acpi_fill_cnvs(void);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001574
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001575unsigned long acpi_fill_lpit(unsigned long current);
1576
Furquan Shaikhe0844632020-05-02 10:23:37 -07001577/* These can be used by the target port. */
1578u8 acpi_checksum(u8 *table, u32 length);
1579
1580void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
1581
Jonathan Zhang3dcafa82022-05-11 13:11:20 -07001582/* Create CXL Early Discovery Table */
1583void acpi_create_cedt(acpi_cedt_t *cedt,
1584 unsigned long (*acpi_fill_cedt)(unsigned long current));
1585/* Create a CXL Host Bridge Structure for CEDT */
1586int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base);
1587/* Create a CXL Fixed Memory Window Structure for CEDT */
1588int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size,
1589 u8 eniw, u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target);
1590
Arthur Heymans92a3b672023-06-22 21:30:58 +02001591
Kyösti Mälkkic7da0272021-06-08 11:37:08 +03001592int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001593
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +03001594unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 cpu, u32 apic);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001595
1596unsigned long acpi_create_madt_lapic_nmis(unsigned long current);
1597
Arthur Heymans3df6cc92023-06-27 16:44:59 +02001598uintptr_t platform_get_gicd_base(void);
1599uintptr_t platform_get_gicr_base(void);
1600
Furquan Shaikhe0844632020-05-02 10:23:37 -07001601int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
Naresh Solanki76835cc2023-01-20 19:13:02 +01001602int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001603int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
1604 u32 flags);
Jonathan Zhang3164b642021-04-21 17:51:31 -07001605/*
1606 * Given the Generic Initiator device's BDF, the proximity domain's ID
1607 * and flag, create Generic Initiator Affinity structure in SRAT.
1608 */
1609int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
1610 u16 seg, u8 bus, u8 dev, u8 func, u32 flags);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001611unsigned long acpi_create_srat_lapics(unsigned long current);
1612void acpi_create_srat(acpi_srat_t *srat,
1613 unsigned long (*acpi_fill_srat)(unsigned long current));
1614
1615void acpi_create_slit(acpi_slit_t *slit,
1616 unsigned long (*acpi_fill_slit)(unsigned long current));
1617
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001618/*
1619 * Create a Memory Proximity Domain Attributes structure for HMAT,
1620 * given proximity domain for the attached initiaor, and
1621 * proximimity domain for the memory.
1622 */
1623int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory);
Martin Roth0949e732021-10-01 14:28:22 -06001624/* Create Heterogeneous Memory Attribute Table */
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001625void acpi_create_hmat(acpi_hmat_t *hmat,
1626 unsigned long (*acpi_fill_hmat)(unsigned long current));
1627
Furquan Shaikhe0844632020-05-02 10:23:37 -07001628void acpi_create_vfct(const struct device *device,
1629 acpi_vfct_t *vfct,
1630 unsigned long (*acpi_fill_vfct)(const struct device *device,
1631 acpi_vfct_t *vfct_struct,
1632 unsigned long current));
1633
1634void acpi_create_ipmi(const struct device *device,
1635 struct acpi_spmi *spmi,
1636 const u16 ipmi_revision,
1637 const acpi_addr_t *addr,
1638 const enum acpi_ipmi_interface_type type,
1639 const s8 gpe_interrupt,
1640 const u32 apic_interrupt,
1641 const u32 uid);
1642
1643void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1644 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1645 unsigned long current));
1646
Jason Glenesk61624b22020-11-02 20:06:23 -08001647void acpi_create_crat(struct acpi_crat_header *crat,
1648 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1649 unsigned long current));
1650
Furquan Shaikhe0844632020-05-02 10:23:37 -07001651unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1652 acpi_rsdp_t *rsdp);
1653
1654/* cpu/intel/speedstep/acpi.c */
1655void generate_cpu_entries(const struct device *device);
1656
Furquan Shaikhe0844632020-05-02 10:23:37 -07001657unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
Arthur Heymans736d4d22023-06-30 15:37:38 +02001658 const struct device *dev, uint8_t access_size);
1659unsigned long acpi_pl011_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current,
1660 uint64_t base, const char *name);
1661
Furquan Shaikhe0844632020-05-02 10:23:37 -07001662void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1663 unsigned long (*acpi_fill_dmar)(unsigned long));
1664unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1665 u16 segment, u64 bar);
1666unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1667 u64 bar, u64 limit);
1668unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1669 u16 segment);
1670unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1671 u32 proximity_domain);
1672unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1673 const char *device_name);
John Zhao6edbb182021-03-24 11:55:09 -07001674unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags,
John Zhao091532d2021-04-17 16:03:21 -07001675 u16 segment);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001676void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1677void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1678void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
John Zhao6edbb182021-03-24 11:55:09 -07001679void acpi_dmar_satc_fixup(unsigned long base, unsigned long current);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001680unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1681 u8 bus, u8 dev, u8 fn);
1682unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1683 u8 bus, u8 dev, u8 fn);
1684unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1685 u8 enumeration_id,
1686 u8 bus, u8 dev, u8 fn);
Arthur Heymansbc8f8592022-12-02 13:17:39 +01001687unsigned long acpi_create_dmar_ds_ioapic_from_hw(unsigned long current,
1688 u32 addr, u8 bus, u8 dev, u8 fn);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001689unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1690 u8 enumeration_id,
1691 u8 bus, u8 dev, u8 fn);
1692void acpi_write_hest(acpi_hest_t *hest,
1693 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1694
1695unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1696 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1697
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001698unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1699
Felix Heldf7dbf4a2021-06-07 16:56:04 +02001700/* chipsets that select ACPI_BERT must implement this function */
Felix Held29405482021-05-28 16:01:57 +02001701enum cb_err acpi_soc_get_bert_region(void **region, size_t *length);
Francois Toguo522e0db2021-01-21 09:55:19 -08001702
Arthur Heymans2e3cb632023-06-30 15:01:08 +02001703void acpi_soc_fill_gtdt(acpi_gtdt_t *gtdt);
1704unsigned long acpi_soc_gtdt_add_timers(uint32_t *count, unsigned long current);
1705unsigned long acpi_gtdt_add_timer_block(unsigned long current, const uint64_t address,
1706 struct acpi_gtdt_timer_entry *timers, size_t number);
1707unsigned long acpi_gtdt_add_watchdog(unsigned long current, uint64_t refresh_frame,
1708 uint64_t control_frame, uint32_t gsiv, uint32_t flags);
1709
Furquan Shaikhe0844632020-05-02 10:23:37 -07001710/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001711void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001712void mainboard_suspend_resume(void);
1713void *acpi_find_wakeup_vector(void);
1714
1715/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1716enum {
1717 ACPI_S0 = 0,
1718 ACPI_S1 = 1,
1719 ACPI_S2 = 2,
1720 ACPI_S3 = 3,
1721 ACPI_S4 = 4,
1722 ACPI_S5 = 5,
1723};
1724
1725#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1726 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1727/* Given the provided PM1 control register return the ACPI sleep type. */
1728static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1729{
1730 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1731 case SLP_TYP_S0: return ACPI_S0;
1732 case SLP_TYP_S1: return ACPI_S1;
1733 case SLP_TYP_S3: return ACPI_S3;
1734 case SLP_TYP_S4: return ACPI_S4;
1735 case SLP_TYP_S5: return ACPI_S5;
1736 }
1737 return -1;
1738}
1739#endif
1740
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001741uint8_t acpi_get_preferred_pm_profile(void);
1742
Furquan Shaikhe0844632020-05-02 10:23:37 -07001743/* Returns ACPI_Sx values. */
1744int acpi_get_sleep_type(void);
1745
1746/* Read and clear GPE status */
1747int acpi_get_gpe(int gpe);
1748
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001749/* Once we enter payload, is SMI handler installed and capable of
1750 responding to APM_CNT Advanced Power Management Control commands. */
1751static inline int permanent_smi_handler(void)
1752{
1753 return CONFIG(HAVE_SMI_HANDLER);
1754}
1755
Furquan Shaikhe0844632020-05-02 10:23:37 -07001756static inline int acpi_s3_resume_allowed(void)
1757{
1758 return CONFIG(HAVE_ACPI_RESUME);
1759}
1760
Furquan Shaikhe0844632020-05-02 10:23:37 -07001761static inline int acpi_is_wakeup_s3(void)
1762{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001763 if (!acpi_s3_resume_allowed())
1764 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001765
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001766 if (ENV_ROMSTAGE_OR_BEFORE)
1767 return (acpi_get_sleep_type() == ACPI_S3);
1768
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001769 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001770}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001771
1772static inline uintptr_t acpi_align_current(uintptr_t current)
1773{
1774 return ALIGN_UP(current, 16);
1775}
1776
1777/* ACPI table revisions should match the revision of the ACPI spec
1778 * supported. This function keeps the table versions synced. This could
1779 * be made into a weak function if there is ever a need to override the
1780 * coreboot default ACPI spec version supported. */
1781int get_acpi_table_revision(enum acpi_tables table);
Elyes Haouas8b950f42022-02-16 12:08:16 +01001782u8 get_acpi_fadt_minor_version(void);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001783
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001784#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001785
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001786#endif /* __ACPI_ACPI_H__ */