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