blob: 0aa802665140e5972e4de5fc71f466447015c0ac [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 {
220 u32 base_address;
221 u32 base_reserved;
222 u16 pci_segment_group_number;
223 u8 start_bus_number;
224 u8 end_bus_number;
225 u8 reserved[4];
226} __packed acpi_mcfg_mmconfig_t;
227
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700228/*
Jonathan Zhang3dcafa82022-05-11 13:11:20 -0700229 * CEDT (CXL Early Discovery Table)
230 * CXL spec 2.0 section 9.14.1
231 */
232typedef struct acpi_cedt {
233 acpi_header_t header;
234 /* Followed by CEDT structures[n] */
235} __packed acpi_cedt_t;
236
237#define ACPI_CEDT_STRUCTURE_CHBS 0
238#define ACPI_CEDT_STRUCTURE_CFMWS 1
239
240#define ACPI_CEDT_CHBS_CXL_VER_1_1 0x00
241#define ACPI_CEDT_CHBS_CXL_VER_2_0 0x01
242
243/* CHBS: CXL Host Bridge Structure */
244typedef struct acpi_cedt_chbs {
245 u8 type; /* Always 0, other values reserved */
246 u8 resv1;
247 u16 length; /* Length in bytes (32) */
248 u32 uid; /* CXL Host Bridge Unique ID */
249 u32 cxl_ver;
250 u32 resv2;
251 /*
252 * For CXL 1.1, the base is Downstream Port Root Complex Resource Block;
253 * For CXL 2.0, the base is CXL Host Bridge Component Registers.
254 */
255 u64 base;
256 u64 len;
257} __packed acpi_cedt_chbs_t;
258
259#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_2_MEM (1 << 0)
260#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_3_MEM (1 << 1)
261#define ACPI_CEDT_CFMWS_RESTRICTION_VOLATIL (1 << 2)
262#define ACPI_CEDT_CFMWS_RESTRICTION_PERSISTENT (1 << 3)
263#define ACPI_CEDT_CFMWS_RESTRICTION_FIXED (1 << 4)
264
265/* CFMWS: CXL Fixed Memory Window Structure */
266typedef struct acpi_cedt_cfmws {
267 u8 type; /* Type (0) */
268 u8 resv1;
269 u16 length; /* Length in bytes (32) */
270 u32 resv2;
271 u64 base_hpa; /* Base of the HPA range, 256MB aligned */
272 u64 window_size; /* Number of bytes this window represents */
273 u8 eniw; /* Encoded Number of Interleave Ways */
274 u8 interleave_arithmetic; /* Standard Modulo arithmetic (0) */
275 u16 resv3;
276 u32 hbig; /* Host Bridge Interleave Granularity */
277 u16 restriction;
278 u16 qtg_id;
279 u32 interleave_target[]; /* Interleave Target List */
280} __packed acpi_cedt_cfmws_t;
281
282/*
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700283 * HMAT (Heterogeneous Memory Attribute Table)
284 * ACPI spec 6.4 section 5.2.27
285 */
286typedef struct acpi_hmat {
287 acpi_header_t header;
288 u32 resv;
289 /* Followed by HMAT table structure[n] */
290} __packed acpi_hmat_t;
291
292/* HMAT: Memory Proximity Domain Attributes structure */
293typedef struct acpi_hmat_mpda {
294 u16 type; /* Type (0) */
295 u16 resv;
296 u32 length; /* Length in bytes (40) */
297 u16 flags;
298 u16 resv1;
299 u32 proximity_domain_initiator;
300 u32 proximity_domain_memory;
301 u32 resv2;
302 u64 resv3;
303 u64 resv4;
304} __packed acpi_hmat_mpda_t;
305
306/* HMAT: System Locality Latency and Bandwidth Information structure */
307typedef struct acpi_hmat_sllbi {
308 u16 type; /* Type (1) */
309 u16 resv;
310 u32 length; /* Length in bytes */
311 u8 flags;
312 u8 data_type;
313 /*
314 * Transfer size defined as a 5-biased power of 2 exponent,
315 * when the bandwidth/latency value is achieved.
316 */
317 u8 min_transfer_size;
318 u8 resv1;
319 u32 num_initiator_domains;
320 u32 num_target_domains;
321 u32 resv2;
322 u64 entry_base_unit;
323 /* Followed by initiator proximity domain list */
324 /* Followed by target proximity domain list */
325 /* Followed by latency / bandwidth values */
326} __packed acpi_hmat_sllbi_t;
327
328/* HMAT: Memory Side Cache Information structure */
329typedef struct acpi_hmat_msci {
330 u16 type; /* Type (2) */
331 u16 resv;
332 u32 length; /* Length in bytes */
333 u32 domain; /* Proximity domain for the memory */
334 u32 resv1;
335 u64 cache_size;
336 /* Describes level, associativity, write policy, cache line size */
337 u32 cache_attributes;
338 u16 resv2;
339 /*
340 * Number of SMBIOS handlers that contribute to the
341 * memory side cache physical devices
342 */
343 u16 num_handlers;
344 /* Followed by SMBIOS handlers*/
345} __packed acpi_hmat_msci_t;
346
Furquan Shaikhe0844632020-05-02 10:23:37 -0700347/* SRAT (System Resource Affinity Table) */
348typedef struct acpi_srat {
349 acpi_header_t header;
350 u32 resv;
351 u64 resv1;
352 /* Followed by static resource allocation structure[n] */
353} __packed acpi_srat_t;
354
Jonathan Zhang3164b642021-04-21 17:51:31 -0700355#define ACPI_SRAT_STRUCTURE_LAPIC 0
356#define ACPI_SRAT_STRUCTURE_MEM 1
357#define ACPI_SRAT_STRUCTURE_GIA 5
358
Naresh Solanki76835cc2023-01-20 19:13:02 +0100359/* SRAT: Processor x2APIC Structure */
360typedef struct acpi_srat_x2apic {
361 u8 type; /* Type (0) */
362 u8 length; /* Length in bytes (16) */
363 u16 reserved; /* Reserved - Must be zero */
364 u32 proximity_domain; /* Proximity domain */
365 u32 x2apic_id; /* x2APIC ID */
366 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
367 u32 clock_domain; /* _CDM Clock Domain */
368 u32 reserved1; /* Reserved */
369} __packed acpi_srat_x2apic_t;
370
Furquan Shaikhe0844632020-05-02 10:23:37 -0700371/* SRAT: Processor Local APIC/SAPIC Affinity Structure */
372typedef struct acpi_srat_lapic {
373 u8 type; /* Type (0) */
374 u8 length; /* Length in bytes (16) */
375 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
376 u8 apic_id; /* Local APIC ID */
377 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
378 u8 local_sapic_eid; /* Local SAPIC EID */
379 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
380 u32 clock_domain; /* _CDM Clock Domain */
381} __packed acpi_srat_lapic_t;
382
383/* SRAT: Memory Affinity Structure */
384typedef struct acpi_srat_mem {
385 u8 type; /* Type (1) */
386 u8 length; /* Length in bytes (40) */
387 u32 proximity_domain; /* Proximity domain */
388 u16 resv;
389 u32 base_address_low; /* Mem range base address, low */
390 u32 base_address_high; /* Mem range base address, high */
391 u32 length_low; /* Mem range length, low */
392 u32 length_high; /* Mem range length, high */
393 u32 resv1;
394 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2,
395 * other bits reserved to 0
396 */
397 u32 resv2[2];
398} __packed acpi_srat_mem_t;
399
Jonathan Zhang3164b642021-04-21 17:51:31 -0700400/* SRAT: Generic Initiator Affinity Structure (ACPI spec 6.4 section 5.2.16.6) */
401typedef struct acpi_srat_gia {
402 u8 type; /* Type (5) */
403 u8 length; /* Length in bytes (32) */
404 u8 resv;
405 u8 dev_handle_type; /* Device handle type */
406 u32 proximity_domain; /*Proximity domain */
407 u8 dev_handle[16]; /* Device handle */
408 u32 flags;
409 u32 resv1;
410} __packed acpi_srat_gia_t;
411
412#define ACPI_SRAT_GIA_DEV_HANDLE_ACPI 0
413#define ACPI_SRAT_GIA_DEV_HANDLE_PCI 1
414
Furquan Shaikhe0844632020-05-02 10:23:37 -0700415/* SLIT (System Locality Distance Information Table) */
416typedef struct acpi_slit {
417 acpi_header_t header;
418 /* Followed by static resource allocation 8+byte[num*num] */
419} __packed acpi_slit_t;
420
421/* MADT (Multiple APIC Description Table) */
422typedef struct acpi_madt {
423 acpi_header_t header;
424 u32 lapic_addr; /* Local APIC address */
425 u32 flags; /* Multiple APIC flags */
426} __packed acpi_madt_t;
427
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100428/*
429 * LPIT (Low Power Idle Table)
430 * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017.
431 */
432typedef struct acpi_lpit {
433 acpi_header_t header;
434} __packed acpi_lpit_t;
435
436/* LPIT: LPI descriptor flags */
437typedef struct acpi_lpi_flags {
438 uint32_t disabled : 1;
439 uint32_t counter_not_available : 1;
440 uint32_t reserved : 30;
441} __packed acpi_lpi_desc_flags_t;
442
443/* LPIT: LPI descriptor types */
444enum acpi_lpi_desc_type {
445 ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00,
446 /* type >= 1 reserved */
447};
448
449/* LPIT: LPI descriptor header */
450typedef struct acpi_lpi_desc_hdr {
451 uint32_t type;
452 uint32_t length;
453 uint16_t uid;
454 uint16_t reserved;
455} __packed acpi_lpi_desc_hdr_t;
456
457#define ACPI_LPIT_CTR_FREQ_TSC 0
458
459/* LPIT: Native C-state instruction based LPI structure */
460typedef struct acpi_lpi_desc_ncst {
461 acpi_lpi_desc_hdr_t header;
462 acpi_lpi_desc_flags_t flags;
463 acpi_addr_t entry_trigger; /* Entry trigger C-state */
464 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
465 uint32_t max_latency; /* Worst case exit latency in microseconds */
466 acpi_addr_t residency_counter;
467 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
468} __packed acpi_lpi_desc_ncst_t;
469
Furquan Shaikhe0844632020-05-02 10:23:37 -0700470/* VFCT image header */
471typedef struct acpi_vfct_image_hdr {
472 u32 PCIBus;
473 u32 PCIDevice;
474 u32 PCIFunction;
475 u16 VendorID;
476 u16 DeviceID;
477 u16 SSVID;
478 u16 SSID;
479 u32 Revision;
480 u32 ImageLength;
481 u8 VbiosContent; // dummy - copy VBIOS here
482} __packed acpi_vfct_image_hdr_t;
483
484/* VFCT (VBIOS Fetch Table) */
485typedef struct acpi_vfct {
486 acpi_header_t header;
487 u8 TableUUID[16];
488 u32 VBIOSImageOffset;
489 u32 Lib1ImageOffset;
490 u32 Reserved[4];
491 acpi_vfct_image_hdr_t image_hdr;
492} __packed acpi_vfct_t;
493
494typedef struct acpi_ivrs_info {
495} __packed acpi_ivrs_info_t;
496
497/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
498typedef struct acpi_ivrs_ivhd {
499 uint8_t type;
500 uint8_t flags;
501 uint16_t length;
502 uint16_t device_id;
503 uint16_t capability_offset;
504 uint32_t iommu_base_low;
505 uint32_t iommu_base_high;
506 uint16_t pci_segment_group;
507 uint16_t iommu_info;
508 uint32_t iommu_feature_info;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200509 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700510} __packed acpi_ivrs_ivhd_t;
511
512/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
513typedef struct acpi_ivrs {
514 acpi_header_t header;
515 uint32_t iv_info;
516 uint32_t reserved[2];
517 struct acpi_ivrs_ivhd ivhd;
518} __packed acpi_ivrs_t;
519
Jason Glenesk61624b22020-11-02 20:06:23 -0800520/* CRAT (Component Resource Affinity Table Structure) */
521struct acpi_crat_header {
522 acpi_header_t header;
523 uint32_t total_entries;
524 uint16_t num_nodes;
525 uint8_t reserved[6];
526} __packed;
527
Furquan Shaikhe0844632020-05-02 10:23:37 -0700528/* IVHD Type 11h IOMMU Attributes */
529typedef struct ivhd11_iommu_attr {
530 uint32_t reserved1 : 13;
531 uint32_t perf_counters : 4;
532 uint32_t perf_counter_banks : 6;
533 uint32_t msi_num_ppr : 5;
534 uint32_t reserved2 : 4;
535} __packed ivhd11_iommu_attr_t;
536
537/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
538typedef struct acpi_ivrs_ivhd_11 {
539 uint8_t type;
540 uint8_t flags;
541 uint16_t length;
542 uint16_t device_id;
543 uint16_t capability_offset;
544 uint32_t iommu_base_low;
545 uint32_t iommu_base_high;
546 uint16_t pci_segment_group;
547 uint16_t iommu_info;
548 struct ivhd11_iommu_attr iommu_attributes;
549 uint32_t efr_reg_image_low;
550 uint32_t efr_reg_image_high;
551 uint32_t reserved[2];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200552 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700553} __packed acpi_ivrs_ivhd11_t;
554
555enum dev_scope_type {
556 SCOPE_PCI_ENDPOINT = 1,
557 SCOPE_PCI_SUB = 2,
558 SCOPE_IOAPIC = 3,
559 SCOPE_MSI_HPET = 4,
560 SCOPE_ACPI_NAMESPACE_DEVICE = 5
561};
562
563typedef struct dev_scope {
564 u8 type;
565 u8 length;
566 u8 reserved[2];
567 u8 enumeration;
568 u8 start_bus;
569 struct {
570 u8 dev;
571 u8 fn;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200572 } __packed path[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700573} __packed dev_scope_t;
574
575enum dmar_type {
576 DMAR_DRHD = 0,
577 DMAR_RMRR = 1,
578 DMAR_ATSR = 2,
579 DMAR_RHSA = 3,
John Zhao6edbb182021-03-24 11:55:09 -0700580 DMAR_ANDD = 4,
581 DMAR_SATC = 5
Furquan Shaikhe0844632020-05-02 10:23:37 -0700582};
583
584enum {
585 DRHD_INCLUDE_PCI_ALL = 1
586};
587
John Zhao091532d2021-04-17 16:03:21 -0700588enum {
589 ATC_REQUIRED = 1
590};
591
Furquan Shaikhe0844632020-05-02 10:23:37 -0700592enum dmar_flags {
593 DMAR_INTR_REMAP = 1 << 0,
594 DMAR_X2APIC_OPT_OUT = 1 << 1,
595 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
596};
597
598typedef struct dmar_entry {
599 u16 type;
600 u16 length;
601 u8 flags;
602 u8 reserved;
603 u16 segment;
604 u64 bar;
605} __packed dmar_entry_t;
606
607typedef struct dmar_rmrr_entry {
608 u16 type;
609 u16 length;
610 u16 reserved;
611 u16 segment;
612 u64 bar;
613 u64 limit;
614} __packed dmar_rmrr_entry_t;
615
616typedef struct dmar_atsr_entry {
617 u16 type;
618 u16 length;
619 u8 flags;
620 u8 reserved;
621 u16 segment;
622} __packed dmar_atsr_entry_t;
623
624typedef struct dmar_rhsa_entry {
625 u16 type;
626 u16 length;
627 u32 reserved;
628 u64 base_address;
629 u32 proximity_domain;
630} __packed dmar_rhsa_entry_t;
631
632typedef struct dmar_andd_entry {
633 u16 type;
634 u16 length;
635 u8 reserved[3];
636 u8 device_number;
637 u8 device_name[];
638} __packed dmar_andd_entry_t;
639
John Zhao6edbb182021-03-24 11:55:09 -0700640typedef struct dmar_satc_entry {
641 u16 type;
642 u16 length;
643 u8 flags;
644 u8 reserved;
645 u16 segment_number;
John Zhao6edbb182021-03-24 11:55:09 -0700646} __packed dmar_satc_entry_t;
647
Furquan Shaikhe0844632020-05-02 10:23:37 -0700648/* DMAR (DMA Remapping Reporting Structure) */
649typedef struct acpi_dmar {
650 acpi_header_t header;
651 u8 host_address_width;
652 u8 flags;
653 u8 reserved[10];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200654 dmar_entry_t structure[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700655} __packed acpi_dmar_t;
656
657/* MADT: APIC Structure Types */
658enum acpi_apic_types {
659 LOCAL_APIC, /* Processor local APIC */
660 IO_APIC, /* I/O APIC */
661 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
662 NMI_TYPE, /* NMI source */
663 LOCAL_APIC_NMI, /* Local APIC NMI */
664 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
665 IO_SAPIC, /* I/O SAPIC */
666 LOCAL_SAPIC, /* Local SAPIC */
667 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
668 LOCAL_X2APIC, /* Processor local x2APIC */
669 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
670 GICC, /* GIC CPU Interface */
671 GICD, /* GIC Distributor */
672 GIC_MSI_FRAME, /* GIC MSI Frame */
673 GICR, /* GIC Redistributor */
674 GIC_ITS, /* Interrupt Translation Service */
675 /* 0x10-0x7f: Reserved */
676 /* 0x80-0xff: Reserved for OEM use */
677};
678
679/* MADT: Processor Local APIC Structure */
680typedef struct acpi_madt_lapic {
681 u8 type; /* Type (0) */
682 u8 length; /* Length in bytes (8) */
683 u8 processor_id; /* ACPI processor ID */
684 u8 apic_id; /* Local APIC ID */
685 u32 flags; /* Local APIC flags */
686} __packed acpi_madt_lapic_t;
687
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300688#define ACPI_MADT_MAX_LAPIC_ID 0xfe
689
Furquan Shaikhe0844632020-05-02 10:23:37 -0700690/* MADT: Local APIC NMI Structure */
691typedef struct acpi_madt_lapic_nmi {
692 u8 type; /* Type (4) */
693 u8 length; /* Length in bytes (6) */
694 u8 processor_id; /* ACPI processor ID */
695 u16 flags; /* MPS INTI flags */
696 u8 lint; /* Local APIC LINT# */
697} __packed acpi_madt_lapic_nmi_t;
698
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200699#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
700#define ACPI_MADT_LX2APIC_NMI_ALL_PROCESSORS ((u32)-1)
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700701
Furquan Shaikhe0844632020-05-02 10:23:37 -0700702/* MADT: I/O APIC Structure */
703typedef struct acpi_madt_ioapic {
704 u8 type; /* Type (1) */
705 u8 length; /* Length in bytes (12) */
706 u8 ioapic_id; /* I/O APIC ID */
707 u8 reserved;
708 u32 ioapic_addr; /* I/O APIC address */
709 u32 gsi_base; /* Global system interrupt base */
710} __packed acpi_madt_ioapic_t;
711
Raul E Rangel169302a2022-04-25 14:59:05 -0600712#define MP_IRQ_POLARITY_DEFAULT 0x0
713#define MP_IRQ_POLARITY_HIGH 0x1
714#define MP_IRQ_POLARITY_LOW 0x3
715#define MP_IRQ_POLARITY_MASK 0x3
716#define MP_IRQ_TRIGGER_DEFAULT 0x0
717#define MP_IRQ_TRIGGER_EDGE 0x4
718#define MP_IRQ_TRIGGER_LEVEL 0xc
719#define MP_IRQ_TRIGGER_MASK 0xc
720
Furquan Shaikhe0844632020-05-02 10:23:37 -0700721/* MADT: Interrupt Source Override Structure */
722typedef struct acpi_madt_irqoverride {
723 u8 type; /* Type (2) */
724 u8 length; /* Length in bytes (10) */
725 u8 bus; /* ISA (0) */
726 u8 source; /* Bus-relative int. source (IRQ) */
727 u32 gsirq; /* Global system interrupt */
728 u16 flags; /* MPS INTI flags */
729} __packed acpi_madt_irqoverride_t;
730
731/* MADT: Processor Local x2APIC Structure */
732typedef struct acpi_madt_lx2apic {
733 u8 type; /* Type (9) */
734 u8 length; /* Length in bytes (16) */
735 u16 reserved;
736 u32 x2apic_id; /* Local x2APIC ID */
737 u32 flags; /* Same as Local APIC flags */
738 u32 processor_id; /* ACPI processor ID */
739} __packed acpi_madt_lx2apic_t;
740
741/* MADT: Processor Local x2APIC NMI Structure */
742typedef struct acpi_madt_lx2apic_nmi {
743 u8 type; /* Type (10) */
744 u8 length; /* Length in bytes (12) */
745 u16 flags; /* Same as MPS INTI flags */
746 u32 processor_id; /* ACPI processor ID */
747 u8 lint; /* Local APIC LINT# */
748 u8 reserved[3];
749} __packed acpi_madt_lx2apic_nmi_t;
750
751#define ACPI_DBG2_PORT_SERIAL 0x8000
752#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
753#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
754#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
755#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
756#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
757#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
758#define ACPI_DBG2_PORT_IEEE1394 0x8001
759#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
760#define ACPI_DBG2_PORT_USB 0x8002
761#define ACPI_DBG2_PORT_USB_XHCI 0x0000
762#define ACPI_DBG2_PORT_USB_EHCI 0x0001
763#define ACPI_DBG2_PORT_NET 0x8003
764
765/* DBG2: Microsoft Debug Port Table 2 header */
766typedef struct acpi_dbg2_header {
767 acpi_header_t header;
768 uint32_t devices_offset;
769 uint32_t devices_count;
770} __attribute__((packed)) acpi_dbg2_header_t;
771
772/* DBG2: Microsoft Debug Port Table 2 device entry */
773typedef struct acpi_dbg2_device {
774 uint8_t revision;
775 uint16_t length;
776 uint8_t address_count;
777 uint16_t namespace_string_length;
778 uint16_t namespace_string_offset;
779 uint16_t oem_data_length;
780 uint16_t oem_data_offset;
781 uint16_t port_type;
782 uint16_t port_subtype;
783 uint8_t reserved[2];
784 uint16_t base_address_offset;
785 uint16_t address_size_offset;
786} __attribute__((packed)) acpi_dbg2_device_t;
787
788/* FADT (Fixed ACPI Description Table) */
789typedef struct acpi_fadt {
790 acpi_header_t header;
791 u32 firmware_ctrl;
792 u32 dsdt;
793 u8 reserved; /* Should be 0 */
794 u8 preferred_pm_profile;
795 u16 sci_int;
796 u32 smi_cmd;
797 u8 acpi_enable;
798 u8 acpi_disable;
799 u8 s4bios_req;
800 u8 pstate_cnt;
801 u32 pm1a_evt_blk;
802 u32 pm1b_evt_blk;
803 u32 pm1a_cnt_blk;
804 u32 pm1b_cnt_blk;
805 u32 pm2_cnt_blk;
806 u32 pm_tmr_blk;
807 u32 gpe0_blk;
808 u32 gpe1_blk;
809 u8 pm1_evt_len;
810 u8 pm1_cnt_len;
811 u8 pm2_cnt_len;
812 u8 pm_tmr_len;
813 u8 gpe0_blk_len;
814 u8 gpe1_blk_len;
815 u8 gpe1_base;
816 u8 cst_cnt;
817 u16 p_lvl2_lat;
818 u16 p_lvl3_lat;
819 u16 flush_size;
820 u16 flush_stride;
821 u8 duty_offset;
822 u8 duty_width;
823 u8 day_alrm;
824 u8 mon_alrm;
825 u8 century;
826 u16 iapc_boot_arch;
827 u8 res2;
828 u32 flags;
829 acpi_addr_t reset_reg;
830 u8 reset_value;
Elyes Haouasb55ac092022-02-16 14:42:19 +0100831 u16 ARM_boot_arch; /* Must be zero if ACPI Revision <= 5.0 */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100832 u8 FADT_MinorVersion; /* Must be zero if ACPI Revision <= 5.0 */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700833 u32 x_firmware_ctl_l;
834 u32 x_firmware_ctl_h;
835 u32 x_dsdt_l;
836 u32 x_dsdt_h;
837 acpi_addr_t x_pm1a_evt_blk;
838 acpi_addr_t x_pm1b_evt_blk;
839 acpi_addr_t x_pm1a_cnt_blk;
840 acpi_addr_t x_pm1b_cnt_blk;
841 acpi_addr_t x_pm2_cnt_blk;
842 acpi_addr_t x_pm_tmr_blk;
843 acpi_addr_t x_gpe0_blk;
844 acpi_addr_t x_gpe1_blk;
845 /* Revision 5 */
846 acpi_addr_t sleep_control_reg;
847 acpi_addr_t sleep_status_reg;
848 /* Revision 6 */
849 u64 hypervisor_vendor_identity;
850} __packed acpi_fadt_t;
851
852/* FADT TABLE Revision values */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100853#define ACPI_FADT_REV_ACPI_1 1
854#define ACPI_FADT_REV_ACPI_2 3
855#define ACPI_FADT_REV_ACPI_3 4
856#define ACPI_FADT_REV_ACPI_4 4
857#define ACPI_FADT_REV_ACPI_5 5
858#define ACPI_FADT_REV_ACPI_6 6
859
860/* FADT Minor Version value:
861 * Bits 0-3: minor version
862 * Bits 4-7: Errata
863 * value of 1 means this is compatible with Errata A,
864 * value of 2 would be compatible with Errata B, and so on
865 * Version 6.3 Errata A would be: (1 << 4) | 3
866 */
867#define ACPI_FADT_MINOR_VERSION_0 0 /* coreboot currently use this version */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700868
869/* Flags for p_lvl2_lat and p_lvl3_lat */
870#define ACPI_FADT_C2_NOT_SUPPORTED 101
871#define ACPI_FADT_C3_NOT_SUPPORTED 1001
872
873/* FADT Feature Flags */
874#define ACPI_FADT_WBINVD (1 << 0)
875#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
876#define ACPI_FADT_C1_SUPPORTED (1 << 2)
877#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
878#define ACPI_FADT_POWER_BUTTON (1 << 4)
879#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
880#define ACPI_FADT_FIXED_RTC (1 << 6)
881#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
882#define ACPI_FADT_32BIT_TIMER (1 << 8)
883#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
884#define ACPI_FADT_RESET_REGISTER (1 << 10)
885#define ACPI_FADT_SEALED_CASE (1 << 11)
886#define ACPI_FADT_HEADLESS (1 << 12)
887#define ACPI_FADT_SLEEP_TYPE (1 << 13)
888#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
889#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
890#define ACPI_FADT_S4_RTC_VALID (1 << 16)
891#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
892#define ACPI_FADT_APIC_CLUSTER (1 << 18)
893#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
894/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
895#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
896#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
897/* bits 22-31: reserved since ACPI 5.0 */
898
899/* FADT Boot Architecture Flags */
900#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
901#define ACPI_FADT_8042 (1 << 1)
902#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
903#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
904#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
905#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
906#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
907
908/* FADT ARM Boot Architecture Flags */
909#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
910#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
911/* bits 2-16: reserved since ACPI 5.1 */
912
913/* FADT Preferred Power Management Profile */
914enum acpi_preferred_pm_profiles {
915 PM_UNSPECIFIED = 0,
916 PM_DESKTOP = 1,
917 PM_MOBILE = 2,
918 PM_WORKSTATION = 3,
919 PM_ENTERPRISE_SERVER = 4,
920 PM_SOHO_SERVER = 5,
921 PM_APPLIANCE_PC = 6,
922 PM_PERFORMANCE_SERVER = 7,
923 PM_TABLET = 8, /* ACPI 5.0 & greater */
924};
925
926/* FACS (Firmware ACPI Control Structure) */
927typedef struct acpi_facs {
928 char signature[4]; /* "FACS" */
929 u32 length; /* Length in bytes (>= 64) */
930 u32 hardware_signature; /* Hardware signature */
931 u32 firmware_waking_vector; /* Firmware waking vector */
932 u32 global_lock; /* Global lock */
933 u32 flags; /* FACS flags */
934 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
935 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
936 u8 version; /* FACS version */
937 u8 resv1[3]; /* This value is 0 */
938 u32 ospm_flags; /* 64BIT_WAKE_F */
939 u8 resv2[24]; /* This value is 0 */
940} __packed acpi_facs_t;
941
942/* FACS flags */
943#define ACPI_FACS_S4BIOS_F (1 << 0)
944#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
945/* Bits 31..2: reserved */
946
947/* ECDT (Embedded Controller Boot Resources Table) */
948typedef struct acpi_ecdt {
949 acpi_header_t header;
950 acpi_addr_t ec_control; /* EC control register */
951 acpi_addr_t ec_data; /* EC data register */
952 u32 uid; /* UID */
953 u8 gpe_bit; /* GPE bit */
954 u8 ec_id[]; /* EC ID */
955} __packed acpi_ecdt_t;
956
957/* HEST (Hardware Error Source Table) */
958typedef struct acpi_hest {
959 acpi_header_t header;
960 u32 error_source_count;
961 /* error_source_struct(s) */
962} __packed acpi_hest_t;
963
964/* Error Source Descriptors */
965typedef struct acpi_hest_esd {
966 u16 type;
967 u16 source_id;
968 u16 resv;
969 u8 flags;
970 u8 enabled;
971 u32 prealloc_erecords; /* The number of error records to
972 * pre-allocate for this error source.
973 */
974 u32 max_section_per_record;
975} __packed acpi_hest_esd_t;
976
977/* Hardware Error Notification */
978typedef struct acpi_hest_hen {
979 u8 type;
980 u8 length;
981 u16 conf_we; /* Configuration Write Enable */
982 u32 poll_interval;
983 u32 vector;
984 u32 sw2poll_threshold_val;
985 u32 sw2poll_threshold_win;
986 u32 error_threshold_val;
987 u32 error_threshold_win;
988} __packed acpi_hest_hen_t;
989
990/* BERT (Boot Error Record Table) */
991typedef struct acpi_bert {
992 acpi_header_t header;
993 u32 region_length;
994 u64 error_region;
995} __packed acpi_bert_t;
996
997/* Generic Error Data Entry */
998typedef struct acpi_hest_generic_data {
999 guid_t section_type;
1000 u32 error_severity;
1001 u16 revision;
1002 u8 validation_bits;
1003 u8 flags;
1004 u32 data_length;
1005 guid_t fru_id;
1006 u8 fru_text[20];
1007 /* error data */
1008} __packed acpi_hest_generic_data_t;
1009
1010/* Generic Error Data Entry v300 */
1011typedef struct acpi_hest_generic_data_v300 {
1012 guid_t section_type;
1013 u32 error_severity;
1014 u16 revision;
1015 u8 validation_bits;
1016 u8 flags; /* see CPER Section Descriptor, Flags field */
1017 u32 data_length;
1018 guid_t fru_id;
1019 u8 fru_text[20];
1020 cper_timestamp_t timestamp;
1021 /* error data */
1022} __packed acpi_hest_generic_data_v300_t;
1023#define HEST_GENERIC_ENTRY_V300 0x300
1024
1025/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
1026#define ACPI_GENERROR_SEV_RECOVERABLE 0
1027#define ACPI_GENERROR_SEV_FATAL 1
1028#define ACPI_GENERROR_SEV_CORRECTED 2
1029#define ACPI_GENERROR_SEV_NONE 3
1030
1031/* Generic Error Data Entry, Validation Bits field */
1032#define ACPI_GENERROR_VALID_FRUID BIT(0)
1033#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
1034#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
1035
Felix Held403fa862021-07-26 22:43:00 +02001036/*
1037 * Generic Error Status Block
1038 *
1039 * If there is a raw data section at the end of the generic error status block after the
1040 * zero or more generic error data entries, raw_data_length indicates the length of the raw
1041 * section and raw_data_offset is the offset of the beginning of the raw data section from
1042 * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length
1043 * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t).
1044 */
Furquan Shaikhe0844632020-05-02 10:23:37 -07001045typedef struct acpi_generic_error_status {
1046 u32 block_status;
1047 u32 raw_data_offset; /* must follow any generic entries */
1048 u32 raw_data_length;
1049 u32 data_length; /* generic data */
1050 u32 error_severity;
1051 /* Generic Error Data structures, zero or more entries */
1052} __packed acpi_generic_error_status_t;
1053
1054/* Generic Status Block, Block Status values */
1055#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
1056#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
1057#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
1058#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
1059#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
1060#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
1061#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
1062 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
1063 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
1064
1065typedef struct acpi_cstate {
1066 u8 ctype;
1067 u16 latency;
1068 u32 power;
1069 acpi_addr_t resource;
1070} __packed acpi_cstate_t;
1071
Jason Gleneskca36aed2020-09-15 21:01:57 -07001072struct acpi_sw_pstate {
1073 u32 core_freq;
1074 u32 power;
1075 u32 transition_latency;
1076 u32 bus_master_latency;
1077 u32 control_value;
1078 u32 status_value;
1079} __packed;
1080
1081struct acpi_xpss_sw_pstate {
1082 u64 core_freq;
1083 u64 power;
1084 u64 transition_latency;
1085 u64 bus_master_latency;
1086 u64 control_value;
1087 u64 status_value;
1088 u64 control_mask;
1089 u64 status_mask;
1090} __packed;
1091
Furquan Shaikhe0844632020-05-02 10:23:37 -07001092typedef struct acpi_tstate {
1093 u32 percent;
1094 u32 power;
1095 u32 latency;
1096 u32 control;
1097 u32 status;
1098} __packed acpi_tstate_t;
1099
Raul E Rangelc7048322021-04-19 15:58:25 -06001100enum acpi_lpi_state_flags {
1101 ACPI_LPI_STATE_DISABLED = 0,
1102 ACPI_LPI_STATE_ENABLED
1103};
1104
1105/* Low Power Idle State */
1106struct acpi_lpi_state {
1107 u32 min_residency_us;
1108 u32 worst_case_wakeup_latency_us;
1109 u32 flags;
1110 u32 arch_context_lost_flags;
1111 u32 residency_counter_frequency_hz;
1112 u32 enabled_parent_state;
1113 acpi_addr_t entry_method;
1114 acpi_addr_t residency_counter_register;
1115 acpi_addr_t usage_counter_register;
1116 const char *state_name;
1117};
1118
Furquan Shaikhe0844632020-05-02 10:23:37 -07001119/* Port types for ACPI _UPC object */
1120enum acpi_upc_type {
1121 UPC_TYPE_A,
1122 UPC_TYPE_MINI_AB,
1123 UPC_TYPE_EXPRESSCARD,
1124 UPC_TYPE_USB3_A,
1125 UPC_TYPE_USB3_B,
1126 UPC_TYPE_USB3_MICRO_B,
1127 UPC_TYPE_USB3_MICRO_AB,
1128 UPC_TYPE_USB3_POWER_B,
1129 UPC_TYPE_C_USB2_ONLY,
1130 UPC_TYPE_C_USB2_SS_SWITCH,
1131 UPC_TYPE_C_USB2_SS,
1132 UPC_TYPE_PROPRIETARY = 0xff,
1133 /*
1134 * The following types are not directly defined in the ACPI
1135 * spec but are used by coreboot to identify a USB device type.
1136 */
1137 UPC_TYPE_INTERNAL = 0xff,
1138 UPC_TYPE_UNUSED,
1139 UPC_TYPE_HUB
1140};
1141
1142enum acpi_ipmi_interface_type {
1143 IPMI_INTERFACE_RESERVED = 0,
1144 IPMI_INTERFACE_KCS,
1145 IPMI_INTERFACE_SMIC,
1146 IPMI_INTERFACE_BT,
1147 IPMI_INTERFACE_SSIF,
1148};
1149
1150#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
1151#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
1152#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
1153
1154/* ACPI IPMI 2.0 */
1155struct acpi_spmi {
1156 acpi_header_t header;
1157 u8 interface_type;
1158 u8 reserved;
1159 u16 specification_revision;
1160 u8 interrupt_type;
1161 u8 gpe;
1162 u8 reserved2;
1163 u8 pci_device_flag;
1164
1165 u32 global_system_interrupt;
1166 acpi_addr_t base_address;
1167 union {
1168 struct {
1169 u8 pci_segment_group;
1170 u8 pci_bus;
1171 u8 pci_device;
1172 u8 pci_function;
1173 };
1174 u8 uid[4];
1175 };
1176 u8 reserved3;
1177} __packed;
1178
Rocky Phaguraeff07132021-01-10 15:42:50 -08001179/* EINJ APEI Standard Definitions */
1180/* EINJ Error Types
1181 Refer to the ACPI spec, EINJ section, for more info on bit definitions
1182*/
1183#define ACPI_EINJ_CPU_CE (1 << 0)
1184#define ACPI_EINJ_CPU_UCE (1 << 1)
1185#define ACPI_EINJ_CPU_UCE_FATAL (1 << 2)
1186#define ACPI_EINJ_MEM_CE (1 << 3)
1187#define ACPI_EINJ_MEM_UCE (1 << 4)
1188#define ACPI_EINJ_MEM_UCE_FATAL (1 << 5)
1189#define ACPI_EINJ_PCIE_CE (1 << 6)
1190#define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7)
1191#define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8)
1192#define ACPI_EINJ_PLATFORM_CE (1 << 9)
1193#define ACPI_EINJ_PLATFORM_UCE (1 << 10)
1194#define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11)
1195#define ACPI_EINJ_VENDOR_DEFINED (1 << 31)
1196#define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \
1197 ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL)
1198
1199/* EINJ actions */
1200#define ACTION_COUNT 9
1201#define BEGIN_INJECT_OP 0x00
1202#define GET_TRIGGER_ACTION_TABLE 0x01
1203#define SET_ERROR_TYPE 0x02
1204#define GET_ERROR_TYPE 0x03
1205#define END_INJECT_OP 0x04
1206#define EXECUTE_INJECT_OP 0x05
1207#define CHECK_BUSY_STATUS 0x06
1208#define GET_CMD_STATUS 0x07
1209#define SET_ERROR_TYPE_WITH_ADDRESS 0x08
1210#define TRIGGER_ERROR 0xFF
1211
1212/* EINJ Instructions */
1213#define READ_REGISTER 0x00
1214#define READ_REGISTER_VALUE 0x01
1215#define WRITE_REGISTER 0x02
1216#define WRITE_REGISTER_VALUE 0x03
1217#define NO_OP 0x04
1218
1219/* EINJ (Error Injection Table) */
1220typedef struct acpi_gen_regaddr1 {
1221 u8 space_id; /* Address space ID */
1222 u8 bit_width; /* Register size in bits */
1223 u8 bit_offset; /* Register bit offset */
1224 u8 access_size; /* Access size since ACPI 2.0c */
1225 u64 addr; /* Register address */
1226} __packed acpi_addr64_t;
1227
1228/* Instruction entry */
1229typedef struct acpi_einj_action_table {
1230 u8 action;
1231 u8 instruction;
1232 u16 flags;
1233 acpi_addr64_t reg;
1234 u64 value;
1235 u64 mask;
1236} __packed acpi_einj_action_table_t;
1237
1238typedef struct acpi_injection_header {
1239 u32 einj_header_size;
1240 u32 flags;
1241 u32 entry_count;
1242} __packed acpi_injection_header_t;
1243
1244typedef struct acpi_einj_trigger_table {
1245 u32 header_size;
1246 u32 revision;
1247 u32 table_size;
1248 u32 entry_count;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +02001249 acpi_einj_action_table_t trigger_action[];
Rocky Phaguraeff07132021-01-10 15:42:50 -08001250} __packed acpi_einj_trigger_table_t;
1251
1252typedef struct set_error_type {
1253 u32 errtype;
1254 u32 vendorerrortype;
1255 u32 flags;
1256 u32 apicid;
1257 u64 memaddr;
1258 u64 memrange;
1259 u32 pciesbdf;
1260} __packed set_error_type_t;
1261
1262#define EINJ_PARAM_NUM 6
1263typedef struct acpi_einj_smi {
1264 u64 op_state;
1265 u64 err_inject[EINJ_PARAM_NUM];
1266 u64 trigger_action_table;
1267 u64 err_inj_cap;
1268 u64 op_status;
1269 u64 cmd_sts;
1270 u64 einj_addr;
1271 u64 einj_addr_msk;
1272 set_error_type_t setaddrtable;
1273 u64 reserved[50];
1274} __packed acpi_einj_smi_t;
1275
1276/* EINJ Flags */
1277#define EINJ_DEF_TRIGGER_PORT 0xb2
1278#define FLAG_PRESERVE 0x01
1279#define FLAG_IGNORE 0x00
1280
1281/* EINJ Registers */
1282#define EINJ_REG_MEMORY(address) \
1283 { \
1284 .space_id = ACPI_ADDRESS_SPACE_MEMORY, \
1285 .bit_width = 64, \
1286 .bit_offset = 0, \
1287 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
1288 .addr = address}
1289
1290#define EINJ_REG_IO() \
1291 { \
1292 .space_id = ACPI_ADDRESS_SPACE_IO, \
1293 .bit_width = 0x10, \
1294 .bit_offset = 0, \
1295 .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \
1296 .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */
1297
1298typedef struct acpi_einj {
1299 acpi_header_t header;
1300 acpi_injection_header_t inj_header;
1301 acpi_einj_action_table_t action_table[ACTION_COUNT];
1302} __packed acpi_einj_t;
1303
Arthur Heymanse7aaf042023-06-07 12:12:45 +02001304/* SPCR (Serial Port Console Redirection Table) */
1305typedef struct acpi_spcr {
1306 acpi_header_t header;
1307 uint8_t interface_type;
1308 uint8_t reserved[3];
1309 acpi_addr_t base_address;
1310 uint8_t interrupt_type;
1311 uint8_t irq;
1312 uint32_t global_system_interrupt;
1313 uint8_t configured_baudrate;
1314 uint8_t parity;
1315 uint8_t stop_bits;
1316 uint8_t flow_control;
1317 uint8_t terminal_type;
1318 uint8_t language;
1319 uint16_t pci_did;
1320 uint16_t pci_vid;
1321 uint8_t pci_bus;
1322 uint8_t pci_dev;
1323 uint8_t pci_fun;
1324 uint32_t pci_flags;
1325 uint8_t pci_segment;
1326 uint32_t uart_clock;
1327 uint32_t precise_baud_rate;
1328 uint16_t namespace_string_length;
1329 uint16_t namespace_string_offset;
1330 char namespacestring[];
1331} __packed acpi_spcr_t;
1332_Static_assert(sizeof(acpi_spcr_t) == 88, "acpi_spcr_t must have an 88 byte size\n");
1333
Arthur Heymans90464072023-06-07 12:53:50 +02001334#define PC_AT_COMPATIBLE_INTERRUPT (1 << 0)
1335#define IO_APIC_COMPATIBLE_INTERRUPT (1 << 1)
1336#define IO_SAPIC_COMPATIBLE_INTERRUPT (1 << 2)
1337#define ARMH_GIC_COMPATIBLE_INTERRUPT (1 << 3)
1338#define RISCV_PLIC_COMPATIBLE_INTERRUPT (1 << 4)
1339
Arthur Heymans8193eab2023-06-20 10:17:23 +02001340/* GTDT - Generic Timer Description Table (ACPI 5.1) Version 2 */
1341typedef struct acpi_table_gtdt {
1342 acpi_header_t header; /* Common ACPI table header */
1343 u64 counter_block_addresss;
1344 u32 reserved;
1345 u32 secure_el1_interrupt;
1346 u32 secure_el1_flags;
1347 u32 non_secure_el1_interrupt;
1348 u32 non_secure_el1_flags;
1349 u32 virtual_timer_interrupt;
1350 u32 virtual_timer_flags;
1351 u32 non_secure_el2_interrupt;
1352 u32 non_secure_el2_flags;
1353 u64 counter_read_block_address;
1354 u32 platform_timer_count;
1355 u32 platform_timer_offset;
1356} __packed acpi_gtdt_t;
1357
1358/* Flag Definitions: Timer Block Physical Timers and Virtual timers */
1359
1360#define ACPI_GTDT_INTERRUPT_MODE (1)
1361#define ACPI_GTDT_INTERRUPT_POLARITY (1<<1)
1362#define ACPI_GTDT_ALWAYS_ON (1<<2)
1363
1364struct acpi_gtdt_el2 {
1365 u32 virtual_el2_timer_gsiv;
1366 u32 virtual_el2_timer_flags;
1367};
1368
1369/* Common GTDT subtable header */
1370
1371struct acpi_gtdt_header {
1372 u8 type;
1373 u16 length;
1374} __packed;
1375
1376/* Values for GTDT subtable type above */
1377
1378enum acpi_gtdt_type {
1379 ACPI_GTDT_TYPE_TIMER_BLOCK = 0,
1380 ACPI_GTDT_TYPE_WATCHDOG = 1,
1381 ACPI_GTDT_TYPE_RESERVED = 2 /* 2 and greater are reserved */
1382};
1383
1384/* GTDT Subtables, correspond to Type in struct acpi_gtdt_header */
1385
1386/* 0: Generic Timer Block */
1387
1388struct acpi_gtdt_timer_block {
1389 struct acpi_gtdt_header header;
1390 u8 reserved;
1391 u64 block_address;
1392 u32 timer_count;
1393 u32 timer_offset;
1394} __packed;
1395
1396/* Timer Sub-Structure, one per timer */
1397
1398struct acpi_gtdt_timer_entry {
1399 u8 frame_number;
1400 u8 reserved[3];
1401 u64 base_address;
1402 u64 el0_base_address;
1403 u32 timer_interrupt;
1404 u32 timer_flags;
1405 u32 virtual_timer_interrupt;
1406 u32 virtual_timer_flags;
1407 u32 common_flags;
1408} __packed;
1409
1410/* Flag Definitions: timer_flags and virtual_timer_flags above */
1411
1412#define ACPI_GTDT_GT_IRQ_MODE (1)
1413#define ACPI_GTDT_GT_IRQ_POLARITY (1<<1)
1414
1415/* Flag Definitions: common_flags above */
1416
1417#define ACPI_GTDT_GT_IS_SECURE_TIMER (1)
1418#define ACPI_GTDT_GT_ALWAYS_ON (1<<1)
1419
1420/* 1: SBSA Generic Watchdog Structure */
1421
1422struct acpi_gtdt_watchdog {
1423 struct acpi_gtdt_header header;
1424 u8 reserved;
1425 u64 refresh_frame_address;
1426 u64 control_frame_address;
1427 u32 timer_interrupt;
1428 u32 timer_flags;
1429} __packed;
1430
1431/* Flag Definitions: timer_flags above */
1432
1433#define ACPI_GTDT_WATCHDOG_IRQ_MODE (1)
1434#define ACPI_GTDT_WATCHDOG_IRQ_POLARITY (1<<1)
1435#define ACPI_GTDT_WATCHDOG_SECURE (1<<2)
1436
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01001437uintptr_t get_coreboot_rsdp(void);
Rocky Phaguraeff07132021-01-10 15:42:50 -08001438void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);
1439
Furquan Shaikhe0844632020-05-02 10:23:37 -07001440unsigned long fw_cfg_acpi_tables(unsigned long start);
1441
1442/* These are implemented by the target port or north/southbridge. */
Raul E Rangel6b446b92021-11-19 11:38:35 -07001443void preload_acpi_dsdt(void);
Arthur Heymans7ebebf72023-06-17 14:08:46 +02001444unsigned long write_acpi_tables(const unsigned long addr);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001445unsigned long acpi_fill_madt(unsigned long current);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001446
Furquan Shaikhe0844632020-05-02 10:23:37 -07001447void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +02001448void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001449void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001450void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001451
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001452void acpi_fill_gnvs(void);
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02001453void acpi_fill_cnvs(void);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001454
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001455unsigned long acpi_fill_lpit(unsigned long current);
1456
Furquan Shaikhe0844632020-05-02 10:23:37 -07001457/* These can be used by the target port. */
1458u8 acpi_checksum(u8 *table, u32 length);
1459
1460void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
1461
Jonathan Zhang3dcafa82022-05-11 13:11:20 -07001462/* Create CXL Early Discovery Table */
1463void acpi_create_cedt(acpi_cedt_t *cedt,
1464 unsigned long (*acpi_fill_cedt)(unsigned long current));
1465/* Create a CXL Host Bridge Structure for CEDT */
1466int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base);
1467/* Create a CXL Fixed Memory Window Structure for CEDT */
1468int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size,
1469 u8 eniw, u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target);
1470
Arthur Heymans92a3b672023-06-22 21:30:58 +02001471
1472unsigned long acpi_create_madt_ioapic_gsi0_default(unsigned long current);
Kyösti Mälkkic7da0272021-06-08 11:37:08 +03001473int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001474
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +03001475unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 cpu, u32 apic);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001476
Arthur Heymans92a3b672023-06-22 21:30:58 +02001477unsigned long acpi_create_madt_lapics_with_nmis(unsigned long current);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001478unsigned long acpi_create_madt_lapic_nmis(unsigned long current);
1479
Furquan Shaikhe0844632020-05-02 10:23:37 -07001480int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
Naresh Solanki76835cc2023-01-20 19:13:02 +01001481int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001482int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
1483 u32 flags);
Jonathan Zhang3164b642021-04-21 17:51:31 -07001484/*
1485 * Given the Generic Initiator device's BDF, the proximity domain's ID
1486 * and flag, create Generic Initiator Affinity structure in SRAT.
1487 */
1488int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
1489 u16 seg, u8 bus, u8 dev, u8 func, u32 flags);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001490unsigned long acpi_create_srat_lapics(unsigned long current);
1491void acpi_create_srat(acpi_srat_t *srat,
1492 unsigned long (*acpi_fill_srat)(unsigned long current));
1493
1494void acpi_create_slit(acpi_slit_t *slit,
1495 unsigned long (*acpi_fill_slit)(unsigned long current));
1496
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001497/*
1498 * Create a Memory Proximity Domain Attributes structure for HMAT,
1499 * given proximity domain for the attached initiaor, and
1500 * proximimity domain for the memory.
1501 */
1502int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory);
Martin Roth0949e732021-10-01 14:28:22 -06001503/* Create Heterogeneous Memory Attribute Table */
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001504void acpi_create_hmat(acpi_hmat_t *hmat,
1505 unsigned long (*acpi_fill_hmat)(unsigned long current));
1506
Furquan Shaikhe0844632020-05-02 10:23:37 -07001507void acpi_create_vfct(const struct device *device,
1508 acpi_vfct_t *vfct,
1509 unsigned long (*acpi_fill_vfct)(const struct device *device,
1510 acpi_vfct_t *vfct_struct,
1511 unsigned long current));
1512
1513void acpi_create_ipmi(const struct device *device,
1514 struct acpi_spmi *spmi,
1515 const u16 ipmi_revision,
1516 const acpi_addr_t *addr,
1517 const enum acpi_ipmi_interface_type type,
1518 const s8 gpe_interrupt,
1519 const u32 apic_interrupt,
1520 const u32 uid);
1521
1522void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1523 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1524 unsigned long current));
1525
Jason Glenesk61624b22020-11-02 20:06:23 -08001526void acpi_create_crat(struct acpi_crat_header *crat,
1527 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1528 unsigned long current));
1529
Furquan Shaikhe0844632020-05-02 10:23:37 -07001530unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1531 acpi_rsdp_t *rsdp);
1532
1533/* cpu/intel/speedstep/acpi.c */
1534void generate_cpu_entries(const struct device *device);
1535
Furquan Shaikhe0844632020-05-02 10:23:37 -07001536unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
1537 const struct device *dev, uint8_t access_size);
1538void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1539 unsigned long (*acpi_fill_dmar)(unsigned long));
1540unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1541 u16 segment, u64 bar);
1542unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1543 u64 bar, u64 limit);
1544unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1545 u16 segment);
1546unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1547 u32 proximity_domain);
1548unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1549 const char *device_name);
John Zhao6edbb182021-03-24 11:55:09 -07001550unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags,
John Zhao091532d2021-04-17 16:03:21 -07001551 u16 segment);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001552void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1553void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1554void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
John Zhao6edbb182021-03-24 11:55:09 -07001555void acpi_dmar_satc_fixup(unsigned long base, unsigned long current);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001556unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1557 u8 bus, u8 dev, u8 fn);
1558unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1559 u8 bus, u8 dev, u8 fn);
1560unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1561 u8 enumeration_id,
1562 u8 bus, u8 dev, u8 fn);
Arthur Heymansbc8f8592022-12-02 13:17:39 +01001563unsigned long acpi_create_dmar_ds_ioapic_from_hw(unsigned long current,
1564 u32 addr, u8 bus, u8 dev, u8 fn);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001565unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1566 u8 enumeration_id,
1567 u8 bus, u8 dev, u8 fn);
1568void acpi_write_hest(acpi_hest_t *hest,
1569 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1570
1571unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1572 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1573
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001574unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1575
Felix Heldf7dbf4a2021-06-07 16:56:04 +02001576/* chipsets that select ACPI_BERT must implement this function */
Felix Held29405482021-05-28 16:01:57 +02001577enum cb_err acpi_soc_get_bert_region(void **region, size_t *length);
Francois Toguo522e0db2021-01-21 09:55:19 -08001578
Arthur Heymans2e3cb632023-06-30 15:01:08 +02001579void acpi_soc_fill_gtdt(acpi_gtdt_t *gtdt);
1580unsigned long acpi_soc_gtdt_add_timers(uint32_t *count, unsigned long current);
1581unsigned long acpi_gtdt_add_timer_block(unsigned long current, const uint64_t address,
1582 struct acpi_gtdt_timer_entry *timers, size_t number);
1583unsigned long acpi_gtdt_add_watchdog(unsigned long current, uint64_t refresh_frame,
1584 uint64_t control_frame, uint32_t gsiv, uint32_t flags);
1585
Furquan Shaikhe0844632020-05-02 10:23:37 -07001586/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001587void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001588void mainboard_suspend_resume(void);
1589void *acpi_find_wakeup_vector(void);
1590
1591/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1592enum {
1593 ACPI_S0 = 0,
1594 ACPI_S1 = 1,
1595 ACPI_S2 = 2,
1596 ACPI_S3 = 3,
1597 ACPI_S4 = 4,
1598 ACPI_S5 = 5,
1599};
1600
1601#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1602 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1603/* Given the provided PM1 control register return the ACPI sleep type. */
1604static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1605{
1606 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1607 case SLP_TYP_S0: return ACPI_S0;
1608 case SLP_TYP_S1: return ACPI_S1;
1609 case SLP_TYP_S3: return ACPI_S3;
1610 case SLP_TYP_S4: return ACPI_S4;
1611 case SLP_TYP_S5: return ACPI_S5;
1612 }
1613 return -1;
1614}
1615#endif
1616
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001617uint8_t acpi_get_preferred_pm_profile(void);
1618
Furquan Shaikhe0844632020-05-02 10:23:37 -07001619/* Returns ACPI_Sx values. */
1620int acpi_get_sleep_type(void);
1621
1622/* Read and clear GPE status */
1623int acpi_get_gpe(int gpe);
1624
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001625/* Once we enter payload, is SMI handler installed and capable of
1626 responding to APM_CNT Advanced Power Management Control commands. */
1627static inline int permanent_smi_handler(void)
1628{
1629 return CONFIG(HAVE_SMI_HANDLER);
1630}
1631
Furquan Shaikhe0844632020-05-02 10:23:37 -07001632static inline int acpi_s3_resume_allowed(void)
1633{
1634 return CONFIG(HAVE_ACPI_RESUME);
1635}
1636
Furquan Shaikhe0844632020-05-02 10:23:37 -07001637static inline int acpi_is_wakeup_s3(void)
1638{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001639 if (!acpi_s3_resume_allowed())
1640 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001641
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001642 if (ENV_ROMSTAGE_OR_BEFORE)
1643 return (acpi_get_sleep_type() == ACPI_S3);
1644
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001645 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001646}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001647
1648static inline uintptr_t acpi_align_current(uintptr_t current)
1649{
1650 return ALIGN_UP(current, 16);
1651}
1652
1653/* ACPI table revisions should match the revision of the ACPI spec
1654 * supported. This function keeps the table versions synced. This could
1655 * be made into a weak function if there is ever a need to override the
1656 * coreboot default ACPI spec version supported. */
1657int get_acpi_table_revision(enum acpi_tables table);
Elyes Haouas8b950f42022-02-16 12:08:16 +01001658u8 get_acpi_fadt_minor_version(void);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001659
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001660#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001661
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001662#endif /* __ACPI_ACPI_H__ */