blob: 17043931f2254c6e31b88f34ca93a370f0f8b936 [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 */
71 COREBOOT_ACPI_ID_MAX = 0xFFFF, /* BOOTFFFF */
72};
73
74enum acpi_tables {
75 /* Tables defined by ACPI and used by coreboot */
Jonathan Zhang3dcafa82022-05-11 13:11:20 -070076 BERT, CEDT, DBG2, DMAR, DSDT, EINJ, FACS, FADT, HEST, HMAT, HPET, IVRS,
77 MADT, MCFG, RSDP, RSDT, SLIT, SRAT, SSDT, TCPA, TPM2, XSDT, ECDT, LPIT,
Arthur Heymans90464072023-06-07 12:53:50 +020078 SPCR,
Furquan Shaikhe0844632020-05-02 10:23:37 -070079 /* Additional proprietary tables used by coreboot */
Jason Glenesk61624b22020-11-02 20:06:23 -080080 VFCT, NHLT, SPMI, CRAT
Furquan Shaikhe0844632020-05-02 10:23:37 -070081};
82
83/* RSDP (Root System Description Pointer) */
84typedef struct acpi_rsdp {
85 char signature[8]; /* RSDP signature */
86 u8 checksum; /* Checksum of the first 20 bytes */
87 char oem_id[6]; /* OEM ID */
88 u8 revision; /* RSDP revision */
89 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
90 u32 length; /* Total RSDP length (incl. extended part) */
91 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
92 u8 ext_checksum; /* Checksum of the whole table */
93 u8 reserved[3];
94} __packed acpi_rsdp_t;
95
96/* GAS (Generic Address Structure) */
97typedef struct acpi_gen_regaddr {
98 u8 space_id; /* Address space ID */
99 u8 bit_width; /* Register size in bits */
100 u8 bit_offset; /* Register bit offset */
101 u8 access_size; /* Access size since ACPI 2.0c */
102 u32 addrl; /* Register address, low 32 bits */
103 u32 addrh; /* Register address, high 32 bits */
104} __packed acpi_addr_t;
105
Elyes HAOUAS5f5fd852020-10-15 12:24:00 +0200106#define ACPI_ADDRESS_SPACE_MEMORY 0 /* System memory */
107#define ACPI_ADDRESS_SPACE_IO 1 /* System I/O */
108#define ACPI_ADDRESS_SPACE_PCI 2 /* PCI config space */
109#define ACPI_ADDRESS_SPACE_EC 3 /* Embedded controller */
110#define ACPI_ADDRESS_SPACE_SMBUS 4 /* SMBus */
111#define ACPI_ADDRESS_SPACE_CMOS 5 /* SystemCMOS */
112#define ACPI_ADDRESS_SPACE_PCI_BAR_TARGET 6 /* PciBarTarget */
113#define ACPI_ADDRESS_SPACE_IPMI 7 /* IPMI */
114#define ACPI_ADDRESS_SPACE_GENERAL_PURPOSE_IO 8 /* GeneralPurposeIO */
115#define ACPI_ADDRESS_SPACE_GENERIC_SERIAL_BUS 9 /* GenericSerialBus */
116#define ACPI_ADDRESS_SPACE_PCC 0x0A /* Platform Comm. Channel */
117#define ACPI_ADDRESS_SPACE_FIXED 0x7f /* Functional fixed hardware */
118#define ACPI_FFIXEDHW_VENDOR_INTEL 1 /* Intel */
119#define ACPI_FFIXEDHW_CLASS_HLT 0 /* C1 Halt */
120#define ACPI_FFIXEDHW_CLASS_IO_HLT 1 /* C1 I/O then Halt */
121#define ACPI_FFIXEDHW_CLASS_MWAIT 2 /* MWAIT Native C-state */
122#define ACPI_FFIXEDHW_FLAG_HW_COORD 1 /* Hardware Coordination bit */
123#define ACPI_FFIXEDHW_FLAG_BM_STS 2 /* BM_STS avoidance bit */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700124/* 0x80-0xbf: Reserved */
125/* 0xc0-0xff: OEM defined */
126
127/* Access size definitions for Generic address structure */
128#define ACPI_ACCESS_SIZE_UNDEFINED 0 /* Undefined (legacy reasons) */
129#define ACPI_ACCESS_SIZE_BYTE_ACCESS 1
130#define ACPI_ACCESS_SIZE_WORD_ACCESS 2
131#define ACPI_ACCESS_SIZE_DWORD_ACCESS 3
132#define ACPI_ACCESS_SIZE_QWORD_ACCESS 4
133
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200134/* Macros for common resource types */
135#define ACPI_REG_MSR(address, offset, width) \
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200136 (acpi_addr_t){ \
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200137 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
138 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
139 .addrl = address, \
140 .bit_offset = offset, \
141 .bit_width = width, \
142 }
143
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200144#define ACPI_REG_UNSUPPORTED (acpi_addr_t){0}
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200145
Furquan Shaikhe0844632020-05-02 10:23:37 -0700146/* Common ACPI HIDs */
147#define ACPI_HID_FDC "PNP0700"
148#define ACPI_HID_KEYBOARD "PNP0303"
149#define ACPI_HID_MOUSE "PNP0F03"
150#define ACPI_HID_COM "PNP0501"
151#define ACPI_HID_LPT "PNP0400"
152#define ACPI_HID_PNP "PNP0C02"
153#define ACPI_HID_CONTAINER "PNP0A05"
154
155/* Generic ACPI header, provided by (almost) all tables */
156typedef struct acpi_table_header {
157 char signature[4]; /* ACPI signature (4 ASCII characters) */
158 u32 length; /* Table length in bytes (incl. header) */
159 u8 revision; /* Table version (not ACPI version!) */
160 u8 checksum; /* To make sum of entire table == 0 */
161 char oem_id[6]; /* OEM identification */
162 char oem_table_id[8]; /* OEM table identification */
163 u32 oem_revision; /* OEM revision number */
164 char asl_compiler_id[4]; /* ASL compiler vendor ID */
165 u32 asl_compiler_revision; /* ASL compiler revision number */
166} __packed acpi_header_t;
167
168/* A maximum number of 32 ACPI tables ought to be enough for now. */
169#define MAX_ACPI_TABLES 32
170
171/* RSDT (Root System Description Table) */
172typedef struct acpi_rsdt {
173 acpi_header_t header;
174 u32 entry[MAX_ACPI_TABLES];
175} __packed acpi_rsdt_t;
176
177/* XSDT (Extended System Description Table) */
178typedef struct acpi_xsdt {
179 acpi_header_t header;
180 u64 entry[MAX_ACPI_TABLES];
181} __packed acpi_xsdt_t;
182
183/* HPET timers */
184typedef struct acpi_hpet {
185 acpi_header_t header;
186 u32 id;
187 acpi_addr_t addr;
188 u8 number;
189 u16 min_tick;
190 u8 attributes;
191} __packed acpi_hpet_t;
192
193/* MCFG (PCI Express MMIO config space BAR description table) */
194typedef struct acpi_mcfg {
195 acpi_header_t header;
196 u8 reserved[8];
197} __packed acpi_mcfg_t;
198
199typedef struct acpi_tcpa {
200 acpi_header_t header;
201 u16 platform_class;
202 u32 laml;
203 u64 lasa;
204} __packed acpi_tcpa_t;
205
206typedef struct acpi_tpm2 {
207 acpi_header_t header;
208 u16 platform_class;
209 u8 reserved[2];
210 u64 control_area;
211 u32 start_method;
212 u8 msp[12];
213 u32 laml;
214 u64 lasa;
215} __packed acpi_tpm2_t;
216
217typedef struct acpi_mcfg_mmconfig {
218 u32 base_address;
219 u32 base_reserved;
220 u16 pci_segment_group_number;
221 u8 start_bus_number;
222 u8 end_bus_number;
223 u8 reserved[4];
224} __packed acpi_mcfg_mmconfig_t;
225
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700226/*
Jonathan Zhang3dcafa82022-05-11 13:11:20 -0700227 * CEDT (CXL Early Discovery Table)
228 * CXL spec 2.0 section 9.14.1
229 */
230typedef struct acpi_cedt {
231 acpi_header_t header;
232 /* Followed by CEDT structures[n] */
233} __packed acpi_cedt_t;
234
235#define ACPI_CEDT_STRUCTURE_CHBS 0
236#define ACPI_CEDT_STRUCTURE_CFMWS 1
237
238#define ACPI_CEDT_CHBS_CXL_VER_1_1 0x00
239#define ACPI_CEDT_CHBS_CXL_VER_2_0 0x01
240
241/* CHBS: CXL Host Bridge Structure */
242typedef struct acpi_cedt_chbs {
243 u8 type; /* Always 0, other values reserved */
244 u8 resv1;
245 u16 length; /* Length in bytes (32) */
246 u32 uid; /* CXL Host Bridge Unique ID */
247 u32 cxl_ver;
248 u32 resv2;
249 /*
250 * For CXL 1.1, the base is Downstream Port Root Complex Resource Block;
251 * For CXL 2.0, the base is CXL Host Bridge Component Registers.
252 */
253 u64 base;
254 u64 len;
255} __packed acpi_cedt_chbs_t;
256
257#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_2_MEM (1 << 0)
258#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_3_MEM (1 << 1)
259#define ACPI_CEDT_CFMWS_RESTRICTION_VOLATIL (1 << 2)
260#define ACPI_CEDT_CFMWS_RESTRICTION_PERSISTENT (1 << 3)
261#define ACPI_CEDT_CFMWS_RESTRICTION_FIXED (1 << 4)
262
263/* CFMWS: CXL Fixed Memory Window Structure */
264typedef struct acpi_cedt_cfmws {
265 u8 type; /* Type (0) */
266 u8 resv1;
267 u16 length; /* Length in bytes (32) */
268 u32 resv2;
269 u64 base_hpa; /* Base of the HPA range, 256MB aligned */
270 u64 window_size; /* Number of bytes this window represents */
271 u8 eniw; /* Encoded Number of Interleave Ways */
272 u8 interleave_arithmetic; /* Standard Modulo arithmetic (0) */
273 u16 resv3;
274 u32 hbig; /* Host Bridge Interleave Granularity */
275 u16 restriction;
276 u16 qtg_id;
277 u32 interleave_target[]; /* Interleave Target List */
278} __packed acpi_cedt_cfmws_t;
279
280/*
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700281 * HMAT (Heterogeneous Memory Attribute Table)
282 * ACPI spec 6.4 section 5.2.27
283 */
284typedef struct acpi_hmat {
285 acpi_header_t header;
286 u32 resv;
287 /* Followed by HMAT table structure[n] */
288} __packed acpi_hmat_t;
289
290/* HMAT: Memory Proximity Domain Attributes structure */
291typedef struct acpi_hmat_mpda {
292 u16 type; /* Type (0) */
293 u16 resv;
294 u32 length; /* Length in bytes (40) */
295 u16 flags;
296 u16 resv1;
297 u32 proximity_domain_initiator;
298 u32 proximity_domain_memory;
299 u32 resv2;
300 u64 resv3;
301 u64 resv4;
302} __packed acpi_hmat_mpda_t;
303
304/* HMAT: System Locality Latency and Bandwidth Information structure */
305typedef struct acpi_hmat_sllbi {
306 u16 type; /* Type (1) */
307 u16 resv;
308 u32 length; /* Length in bytes */
309 u8 flags;
310 u8 data_type;
311 /*
312 * Transfer size defined as a 5-biased power of 2 exponent,
313 * when the bandwidth/latency value is achieved.
314 */
315 u8 min_transfer_size;
316 u8 resv1;
317 u32 num_initiator_domains;
318 u32 num_target_domains;
319 u32 resv2;
320 u64 entry_base_unit;
321 /* Followed by initiator proximity domain list */
322 /* Followed by target proximity domain list */
323 /* Followed by latency / bandwidth values */
324} __packed acpi_hmat_sllbi_t;
325
326/* HMAT: Memory Side Cache Information structure */
327typedef struct acpi_hmat_msci {
328 u16 type; /* Type (2) */
329 u16 resv;
330 u32 length; /* Length in bytes */
331 u32 domain; /* Proximity domain for the memory */
332 u32 resv1;
333 u64 cache_size;
334 /* Describes level, associativity, write policy, cache line size */
335 u32 cache_attributes;
336 u16 resv2;
337 /*
338 * Number of SMBIOS handlers that contribute to the
339 * memory side cache physical devices
340 */
341 u16 num_handlers;
342 /* Followed by SMBIOS handlers*/
343} __packed acpi_hmat_msci_t;
344
Furquan Shaikhe0844632020-05-02 10:23:37 -0700345/* SRAT (System Resource Affinity Table) */
346typedef struct acpi_srat {
347 acpi_header_t header;
348 u32 resv;
349 u64 resv1;
350 /* Followed by static resource allocation structure[n] */
351} __packed acpi_srat_t;
352
Jonathan Zhang3164b642021-04-21 17:51:31 -0700353#define ACPI_SRAT_STRUCTURE_LAPIC 0
354#define ACPI_SRAT_STRUCTURE_MEM 1
355#define ACPI_SRAT_STRUCTURE_GIA 5
356
Naresh Solanki76835cc2023-01-20 19:13:02 +0100357/* SRAT: Processor x2APIC Structure */
358typedef struct acpi_srat_x2apic {
359 u8 type; /* Type (0) */
360 u8 length; /* Length in bytes (16) */
361 u16 reserved; /* Reserved - Must be zero */
362 u32 proximity_domain; /* Proximity domain */
363 u32 x2apic_id; /* x2APIC ID */
364 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
365 u32 clock_domain; /* _CDM Clock Domain */
366 u32 reserved1; /* Reserved */
367} __packed acpi_srat_x2apic_t;
368
Furquan Shaikhe0844632020-05-02 10:23:37 -0700369/* SRAT: Processor Local APIC/SAPIC Affinity Structure */
370typedef struct acpi_srat_lapic {
371 u8 type; /* Type (0) */
372 u8 length; /* Length in bytes (16) */
373 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
374 u8 apic_id; /* Local APIC ID */
375 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
376 u8 local_sapic_eid; /* Local SAPIC EID */
377 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
378 u32 clock_domain; /* _CDM Clock Domain */
379} __packed acpi_srat_lapic_t;
380
381/* SRAT: Memory Affinity Structure */
382typedef struct acpi_srat_mem {
383 u8 type; /* Type (1) */
384 u8 length; /* Length in bytes (40) */
385 u32 proximity_domain; /* Proximity domain */
386 u16 resv;
387 u32 base_address_low; /* Mem range base address, low */
388 u32 base_address_high; /* Mem range base address, high */
389 u32 length_low; /* Mem range length, low */
390 u32 length_high; /* Mem range length, high */
391 u32 resv1;
392 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2,
393 * other bits reserved to 0
394 */
395 u32 resv2[2];
396} __packed acpi_srat_mem_t;
397
Jonathan Zhang3164b642021-04-21 17:51:31 -0700398/* SRAT: Generic Initiator Affinity Structure (ACPI spec 6.4 section 5.2.16.6) */
399typedef struct acpi_srat_gia {
400 u8 type; /* Type (5) */
401 u8 length; /* Length in bytes (32) */
402 u8 resv;
403 u8 dev_handle_type; /* Device handle type */
404 u32 proximity_domain; /*Proximity domain */
405 u8 dev_handle[16]; /* Device handle */
406 u32 flags;
407 u32 resv1;
408} __packed acpi_srat_gia_t;
409
410#define ACPI_SRAT_GIA_DEV_HANDLE_ACPI 0
411#define ACPI_SRAT_GIA_DEV_HANDLE_PCI 1
412
Furquan Shaikhe0844632020-05-02 10:23:37 -0700413/* SLIT (System Locality Distance Information Table) */
414typedef struct acpi_slit {
415 acpi_header_t header;
416 /* Followed by static resource allocation 8+byte[num*num] */
417} __packed acpi_slit_t;
418
419/* MADT (Multiple APIC Description Table) */
420typedef struct acpi_madt {
421 acpi_header_t header;
422 u32 lapic_addr; /* Local APIC address */
423 u32 flags; /* Multiple APIC flags */
424} __packed acpi_madt_t;
425
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100426/*
427 * LPIT (Low Power Idle Table)
428 * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017.
429 */
430typedef struct acpi_lpit {
431 acpi_header_t header;
432} __packed acpi_lpit_t;
433
434/* LPIT: LPI descriptor flags */
435typedef struct acpi_lpi_flags {
436 uint32_t disabled : 1;
437 uint32_t counter_not_available : 1;
438 uint32_t reserved : 30;
439} __packed acpi_lpi_desc_flags_t;
440
441/* LPIT: LPI descriptor types */
442enum acpi_lpi_desc_type {
443 ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00,
444 /* type >= 1 reserved */
445};
446
447/* LPIT: LPI descriptor header */
448typedef struct acpi_lpi_desc_hdr {
449 uint32_t type;
450 uint32_t length;
451 uint16_t uid;
452 uint16_t reserved;
453} __packed acpi_lpi_desc_hdr_t;
454
455#define ACPI_LPIT_CTR_FREQ_TSC 0
456
457/* LPIT: Native C-state instruction based LPI structure */
458typedef struct acpi_lpi_desc_ncst {
459 acpi_lpi_desc_hdr_t header;
460 acpi_lpi_desc_flags_t flags;
461 acpi_addr_t entry_trigger; /* Entry trigger C-state */
462 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
463 uint32_t max_latency; /* Worst case exit latency in microseconds */
464 acpi_addr_t residency_counter;
465 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
466} __packed acpi_lpi_desc_ncst_t;
467
Furquan Shaikhe0844632020-05-02 10:23:37 -0700468/* VFCT image header */
469typedef struct acpi_vfct_image_hdr {
470 u32 PCIBus;
471 u32 PCIDevice;
472 u32 PCIFunction;
473 u16 VendorID;
474 u16 DeviceID;
475 u16 SSVID;
476 u16 SSID;
477 u32 Revision;
478 u32 ImageLength;
479 u8 VbiosContent; // dummy - copy VBIOS here
480} __packed acpi_vfct_image_hdr_t;
481
482/* VFCT (VBIOS Fetch Table) */
483typedef struct acpi_vfct {
484 acpi_header_t header;
485 u8 TableUUID[16];
486 u32 VBIOSImageOffset;
487 u32 Lib1ImageOffset;
488 u32 Reserved[4];
489 acpi_vfct_image_hdr_t image_hdr;
490} __packed acpi_vfct_t;
491
492typedef struct acpi_ivrs_info {
493} __packed acpi_ivrs_info_t;
494
495/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
496typedef struct acpi_ivrs_ivhd {
497 uint8_t type;
498 uint8_t flags;
499 uint16_t length;
500 uint16_t device_id;
501 uint16_t capability_offset;
502 uint32_t iommu_base_low;
503 uint32_t iommu_base_high;
504 uint16_t pci_segment_group;
505 uint16_t iommu_info;
506 uint32_t iommu_feature_info;
507 uint8_t entry[0];
508} __packed acpi_ivrs_ivhd_t;
509
510/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
511typedef struct acpi_ivrs {
512 acpi_header_t header;
513 uint32_t iv_info;
514 uint32_t reserved[2];
515 struct acpi_ivrs_ivhd ivhd;
516} __packed acpi_ivrs_t;
517
Jason Glenesk61624b22020-11-02 20:06:23 -0800518/* CRAT (Component Resource Affinity Table Structure) */
519struct acpi_crat_header {
520 acpi_header_t header;
521 uint32_t total_entries;
522 uint16_t num_nodes;
523 uint8_t reserved[6];
524} __packed;
525
Furquan Shaikhe0844632020-05-02 10:23:37 -0700526/* IVHD Type 11h IOMMU Attributes */
527typedef struct ivhd11_iommu_attr {
528 uint32_t reserved1 : 13;
529 uint32_t perf_counters : 4;
530 uint32_t perf_counter_banks : 6;
531 uint32_t msi_num_ppr : 5;
532 uint32_t reserved2 : 4;
533} __packed ivhd11_iommu_attr_t;
534
535/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
536typedef struct acpi_ivrs_ivhd_11 {
537 uint8_t type;
538 uint8_t flags;
539 uint16_t length;
540 uint16_t device_id;
541 uint16_t capability_offset;
542 uint32_t iommu_base_low;
543 uint32_t iommu_base_high;
544 uint16_t pci_segment_group;
545 uint16_t iommu_info;
546 struct ivhd11_iommu_attr iommu_attributes;
547 uint32_t efr_reg_image_low;
548 uint32_t efr_reg_image_high;
549 uint32_t reserved[2];
550 uint8_t entry[0];
551} __packed acpi_ivrs_ivhd11_t;
552
553enum dev_scope_type {
554 SCOPE_PCI_ENDPOINT = 1,
555 SCOPE_PCI_SUB = 2,
556 SCOPE_IOAPIC = 3,
557 SCOPE_MSI_HPET = 4,
558 SCOPE_ACPI_NAMESPACE_DEVICE = 5
559};
560
561typedef struct dev_scope {
562 u8 type;
563 u8 length;
564 u8 reserved[2];
565 u8 enumeration;
566 u8 start_bus;
567 struct {
568 u8 dev;
569 u8 fn;
570 } __packed path[0];
571} __packed dev_scope_t;
572
573enum dmar_type {
574 DMAR_DRHD = 0,
575 DMAR_RMRR = 1,
576 DMAR_ATSR = 2,
577 DMAR_RHSA = 3,
John Zhao6edbb182021-03-24 11:55:09 -0700578 DMAR_ANDD = 4,
579 DMAR_SATC = 5
Furquan Shaikhe0844632020-05-02 10:23:37 -0700580};
581
582enum {
583 DRHD_INCLUDE_PCI_ALL = 1
584};
585
John Zhao091532d2021-04-17 16:03:21 -0700586enum {
587 ATC_REQUIRED = 1
588};
589
Furquan Shaikhe0844632020-05-02 10:23:37 -0700590enum dmar_flags {
591 DMAR_INTR_REMAP = 1 << 0,
592 DMAR_X2APIC_OPT_OUT = 1 << 1,
593 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
594};
595
596typedef struct dmar_entry {
597 u16 type;
598 u16 length;
599 u8 flags;
600 u8 reserved;
601 u16 segment;
602 u64 bar;
603} __packed dmar_entry_t;
604
605typedef struct dmar_rmrr_entry {
606 u16 type;
607 u16 length;
608 u16 reserved;
609 u16 segment;
610 u64 bar;
611 u64 limit;
612} __packed dmar_rmrr_entry_t;
613
614typedef struct dmar_atsr_entry {
615 u16 type;
616 u16 length;
617 u8 flags;
618 u8 reserved;
619 u16 segment;
620} __packed dmar_atsr_entry_t;
621
622typedef struct dmar_rhsa_entry {
623 u16 type;
624 u16 length;
625 u32 reserved;
626 u64 base_address;
627 u32 proximity_domain;
628} __packed dmar_rhsa_entry_t;
629
630typedef struct dmar_andd_entry {
631 u16 type;
632 u16 length;
633 u8 reserved[3];
634 u8 device_number;
635 u8 device_name[];
636} __packed dmar_andd_entry_t;
637
John Zhao6edbb182021-03-24 11:55:09 -0700638typedef struct dmar_satc_entry {
639 u16 type;
640 u16 length;
641 u8 flags;
642 u8 reserved;
643 u16 segment_number;
John Zhao6edbb182021-03-24 11:55:09 -0700644} __packed dmar_satc_entry_t;
645
Furquan Shaikhe0844632020-05-02 10:23:37 -0700646/* DMAR (DMA Remapping Reporting Structure) */
647typedef struct acpi_dmar {
648 acpi_header_t header;
649 u8 host_address_width;
650 u8 flags;
651 u8 reserved[10];
652 dmar_entry_t structure[0];
653} __packed acpi_dmar_t;
654
655/* MADT: APIC Structure Types */
656enum acpi_apic_types {
657 LOCAL_APIC, /* Processor local APIC */
658 IO_APIC, /* I/O APIC */
659 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
660 NMI_TYPE, /* NMI source */
661 LOCAL_APIC_NMI, /* Local APIC NMI */
662 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
663 IO_SAPIC, /* I/O SAPIC */
664 LOCAL_SAPIC, /* Local SAPIC */
665 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
666 LOCAL_X2APIC, /* Processor local x2APIC */
667 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
668 GICC, /* GIC CPU Interface */
669 GICD, /* GIC Distributor */
670 GIC_MSI_FRAME, /* GIC MSI Frame */
671 GICR, /* GIC Redistributor */
672 GIC_ITS, /* Interrupt Translation Service */
673 /* 0x10-0x7f: Reserved */
674 /* 0x80-0xff: Reserved for OEM use */
675};
676
677/* MADT: Processor Local APIC Structure */
678typedef struct acpi_madt_lapic {
679 u8 type; /* Type (0) */
680 u8 length; /* Length in bytes (8) */
681 u8 processor_id; /* ACPI processor ID */
682 u8 apic_id; /* Local APIC ID */
683 u32 flags; /* Local APIC flags */
684} __packed acpi_madt_lapic_t;
685
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300686#define ACPI_MADT_MAX_LAPIC_ID 0xfe
687
Furquan Shaikhe0844632020-05-02 10:23:37 -0700688/* MADT: Local APIC NMI Structure */
689typedef struct acpi_madt_lapic_nmi {
690 u8 type; /* Type (4) */
691 u8 length; /* Length in bytes (6) */
692 u8 processor_id; /* ACPI processor ID */
693 u16 flags; /* MPS INTI flags */
694 u8 lint; /* Local APIC LINT# */
695} __packed acpi_madt_lapic_nmi_t;
696
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200697#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
698#define ACPI_MADT_LX2APIC_NMI_ALL_PROCESSORS ((u32)-1)
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700699
Furquan Shaikhe0844632020-05-02 10:23:37 -0700700/* MADT: I/O APIC Structure */
701typedef struct acpi_madt_ioapic {
702 u8 type; /* Type (1) */
703 u8 length; /* Length in bytes (12) */
704 u8 ioapic_id; /* I/O APIC ID */
705 u8 reserved;
706 u32 ioapic_addr; /* I/O APIC address */
707 u32 gsi_base; /* Global system interrupt base */
708} __packed acpi_madt_ioapic_t;
709
Raul E Rangel169302a2022-04-25 14:59:05 -0600710#define MP_IRQ_POLARITY_DEFAULT 0x0
711#define MP_IRQ_POLARITY_HIGH 0x1
712#define MP_IRQ_POLARITY_LOW 0x3
713#define MP_IRQ_POLARITY_MASK 0x3
714#define MP_IRQ_TRIGGER_DEFAULT 0x0
715#define MP_IRQ_TRIGGER_EDGE 0x4
716#define MP_IRQ_TRIGGER_LEVEL 0xc
717#define MP_IRQ_TRIGGER_MASK 0xc
718
Furquan Shaikhe0844632020-05-02 10:23:37 -0700719/* MADT: Interrupt Source Override Structure */
720typedef struct acpi_madt_irqoverride {
721 u8 type; /* Type (2) */
722 u8 length; /* Length in bytes (10) */
723 u8 bus; /* ISA (0) */
724 u8 source; /* Bus-relative int. source (IRQ) */
725 u32 gsirq; /* Global system interrupt */
726 u16 flags; /* MPS INTI flags */
727} __packed acpi_madt_irqoverride_t;
728
729/* MADT: Processor Local x2APIC Structure */
730typedef struct acpi_madt_lx2apic {
731 u8 type; /* Type (9) */
732 u8 length; /* Length in bytes (16) */
733 u16 reserved;
734 u32 x2apic_id; /* Local x2APIC ID */
735 u32 flags; /* Same as Local APIC flags */
736 u32 processor_id; /* ACPI processor ID */
737} __packed acpi_madt_lx2apic_t;
738
739/* MADT: Processor Local x2APIC NMI Structure */
740typedef struct acpi_madt_lx2apic_nmi {
741 u8 type; /* Type (10) */
742 u8 length; /* Length in bytes (12) */
743 u16 flags; /* Same as MPS INTI flags */
744 u32 processor_id; /* ACPI processor ID */
745 u8 lint; /* Local APIC LINT# */
746 u8 reserved[3];
747} __packed acpi_madt_lx2apic_nmi_t;
748
749#define ACPI_DBG2_PORT_SERIAL 0x8000
750#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
751#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
752#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
753#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
754#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
755#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
756#define ACPI_DBG2_PORT_IEEE1394 0x8001
757#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
758#define ACPI_DBG2_PORT_USB 0x8002
759#define ACPI_DBG2_PORT_USB_XHCI 0x0000
760#define ACPI_DBG2_PORT_USB_EHCI 0x0001
761#define ACPI_DBG2_PORT_NET 0x8003
762
763/* DBG2: Microsoft Debug Port Table 2 header */
764typedef struct acpi_dbg2_header {
765 acpi_header_t header;
766 uint32_t devices_offset;
767 uint32_t devices_count;
768} __attribute__((packed)) acpi_dbg2_header_t;
769
770/* DBG2: Microsoft Debug Port Table 2 device entry */
771typedef struct acpi_dbg2_device {
772 uint8_t revision;
773 uint16_t length;
774 uint8_t address_count;
775 uint16_t namespace_string_length;
776 uint16_t namespace_string_offset;
777 uint16_t oem_data_length;
778 uint16_t oem_data_offset;
779 uint16_t port_type;
780 uint16_t port_subtype;
781 uint8_t reserved[2];
782 uint16_t base_address_offset;
783 uint16_t address_size_offset;
784} __attribute__((packed)) acpi_dbg2_device_t;
785
786/* FADT (Fixed ACPI Description Table) */
787typedef struct acpi_fadt {
788 acpi_header_t header;
789 u32 firmware_ctrl;
790 u32 dsdt;
791 u8 reserved; /* Should be 0 */
792 u8 preferred_pm_profile;
793 u16 sci_int;
794 u32 smi_cmd;
795 u8 acpi_enable;
796 u8 acpi_disable;
797 u8 s4bios_req;
798 u8 pstate_cnt;
799 u32 pm1a_evt_blk;
800 u32 pm1b_evt_blk;
801 u32 pm1a_cnt_blk;
802 u32 pm1b_cnt_blk;
803 u32 pm2_cnt_blk;
804 u32 pm_tmr_blk;
805 u32 gpe0_blk;
806 u32 gpe1_blk;
807 u8 pm1_evt_len;
808 u8 pm1_cnt_len;
809 u8 pm2_cnt_len;
810 u8 pm_tmr_len;
811 u8 gpe0_blk_len;
812 u8 gpe1_blk_len;
813 u8 gpe1_base;
814 u8 cst_cnt;
815 u16 p_lvl2_lat;
816 u16 p_lvl3_lat;
817 u16 flush_size;
818 u16 flush_stride;
819 u8 duty_offset;
820 u8 duty_width;
821 u8 day_alrm;
822 u8 mon_alrm;
823 u8 century;
824 u16 iapc_boot_arch;
825 u8 res2;
826 u32 flags;
827 acpi_addr_t reset_reg;
828 u8 reset_value;
Elyes Haouasb55ac092022-02-16 14:42:19 +0100829 u16 ARM_boot_arch; /* Must be zero if ACPI Revision <= 5.0 */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100830 u8 FADT_MinorVersion; /* Must be zero if ACPI Revision <= 5.0 */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700831 u32 x_firmware_ctl_l;
832 u32 x_firmware_ctl_h;
833 u32 x_dsdt_l;
834 u32 x_dsdt_h;
835 acpi_addr_t x_pm1a_evt_blk;
836 acpi_addr_t x_pm1b_evt_blk;
837 acpi_addr_t x_pm1a_cnt_blk;
838 acpi_addr_t x_pm1b_cnt_blk;
839 acpi_addr_t x_pm2_cnt_blk;
840 acpi_addr_t x_pm_tmr_blk;
841 acpi_addr_t x_gpe0_blk;
842 acpi_addr_t x_gpe1_blk;
843 /* Revision 5 */
844 acpi_addr_t sleep_control_reg;
845 acpi_addr_t sleep_status_reg;
846 /* Revision 6 */
847 u64 hypervisor_vendor_identity;
848} __packed acpi_fadt_t;
849
850/* FADT TABLE Revision values */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100851#define ACPI_FADT_REV_ACPI_1 1
852#define ACPI_FADT_REV_ACPI_2 3
853#define ACPI_FADT_REV_ACPI_3 4
854#define ACPI_FADT_REV_ACPI_4 4
855#define ACPI_FADT_REV_ACPI_5 5
856#define ACPI_FADT_REV_ACPI_6 6
857
858/* FADT Minor Version value:
859 * Bits 0-3: minor version
860 * Bits 4-7: Errata
861 * value of 1 means this is compatible with Errata A,
862 * value of 2 would be compatible with Errata B, and so on
863 * Version 6.3 Errata A would be: (1 << 4) | 3
864 */
865#define ACPI_FADT_MINOR_VERSION_0 0 /* coreboot currently use this version */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700866
867/* Flags for p_lvl2_lat and p_lvl3_lat */
868#define ACPI_FADT_C2_NOT_SUPPORTED 101
869#define ACPI_FADT_C3_NOT_SUPPORTED 1001
870
871/* FADT Feature Flags */
872#define ACPI_FADT_WBINVD (1 << 0)
873#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
874#define ACPI_FADT_C1_SUPPORTED (1 << 2)
875#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
876#define ACPI_FADT_POWER_BUTTON (1 << 4)
877#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
878#define ACPI_FADT_FIXED_RTC (1 << 6)
879#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
880#define ACPI_FADT_32BIT_TIMER (1 << 8)
881#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
882#define ACPI_FADT_RESET_REGISTER (1 << 10)
883#define ACPI_FADT_SEALED_CASE (1 << 11)
884#define ACPI_FADT_HEADLESS (1 << 12)
885#define ACPI_FADT_SLEEP_TYPE (1 << 13)
886#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
887#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
888#define ACPI_FADT_S4_RTC_VALID (1 << 16)
889#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
890#define ACPI_FADT_APIC_CLUSTER (1 << 18)
891#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
892/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
893#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
894#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
895/* bits 22-31: reserved since ACPI 5.0 */
896
897/* FADT Boot Architecture Flags */
898#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
899#define ACPI_FADT_8042 (1 << 1)
900#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
901#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
902#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
903#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
904#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
905
906/* FADT ARM Boot Architecture Flags */
907#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
908#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
909/* bits 2-16: reserved since ACPI 5.1 */
910
911/* FADT Preferred Power Management Profile */
912enum acpi_preferred_pm_profiles {
913 PM_UNSPECIFIED = 0,
914 PM_DESKTOP = 1,
915 PM_MOBILE = 2,
916 PM_WORKSTATION = 3,
917 PM_ENTERPRISE_SERVER = 4,
918 PM_SOHO_SERVER = 5,
919 PM_APPLIANCE_PC = 6,
920 PM_PERFORMANCE_SERVER = 7,
921 PM_TABLET = 8, /* ACPI 5.0 & greater */
922};
923
924/* FACS (Firmware ACPI Control Structure) */
925typedef struct acpi_facs {
926 char signature[4]; /* "FACS" */
927 u32 length; /* Length in bytes (>= 64) */
928 u32 hardware_signature; /* Hardware signature */
929 u32 firmware_waking_vector; /* Firmware waking vector */
930 u32 global_lock; /* Global lock */
931 u32 flags; /* FACS flags */
932 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
933 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
934 u8 version; /* FACS version */
935 u8 resv1[3]; /* This value is 0 */
936 u32 ospm_flags; /* 64BIT_WAKE_F */
937 u8 resv2[24]; /* This value is 0 */
938} __packed acpi_facs_t;
939
940/* FACS flags */
941#define ACPI_FACS_S4BIOS_F (1 << 0)
942#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
943/* Bits 31..2: reserved */
944
945/* ECDT (Embedded Controller Boot Resources Table) */
946typedef struct acpi_ecdt {
947 acpi_header_t header;
948 acpi_addr_t ec_control; /* EC control register */
949 acpi_addr_t ec_data; /* EC data register */
950 u32 uid; /* UID */
951 u8 gpe_bit; /* GPE bit */
952 u8 ec_id[]; /* EC ID */
953} __packed acpi_ecdt_t;
954
955/* HEST (Hardware Error Source Table) */
956typedef struct acpi_hest {
957 acpi_header_t header;
958 u32 error_source_count;
959 /* error_source_struct(s) */
960} __packed acpi_hest_t;
961
962/* Error Source Descriptors */
963typedef struct acpi_hest_esd {
964 u16 type;
965 u16 source_id;
966 u16 resv;
967 u8 flags;
968 u8 enabled;
969 u32 prealloc_erecords; /* The number of error records to
970 * pre-allocate for this error source.
971 */
972 u32 max_section_per_record;
973} __packed acpi_hest_esd_t;
974
975/* Hardware Error Notification */
976typedef struct acpi_hest_hen {
977 u8 type;
978 u8 length;
979 u16 conf_we; /* Configuration Write Enable */
980 u32 poll_interval;
981 u32 vector;
982 u32 sw2poll_threshold_val;
983 u32 sw2poll_threshold_win;
984 u32 error_threshold_val;
985 u32 error_threshold_win;
986} __packed acpi_hest_hen_t;
987
988/* BERT (Boot Error Record Table) */
989typedef struct acpi_bert {
990 acpi_header_t header;
991 u32 region_length;
992 u64 error_region;
993} __packed acpi_bert_t;
994
995/* Generic Error Data Entry */
996typedef struct acpi_hest_generic_data {
997 guid_t section_type;
998 u32 error_severity;
999 u16 revision;
1000 u8 validation_bits;
1001 u8 flags;
1002 u32 data_length;
1003 guid_t fru_id;
1004 u8 fru_text[20];
1005 /* error data */
1006} __packed acpi_hest_generic_data_t;
1007
1008/* Generic Error Data Entry v300 */
1009typedef struct acpi_hest_generic_data_v300 {
1010 guid_t section_type;
1011 u32 error_severity;
1012 u16 revision;
1013 u8 validation_bits;
1014 u8 flags; /* see CPER Section Descriptor, Flags field */
1015 u32 data_length;
1016 guid_t fru_id;
1017 u8 fru_text[20];
1018 cper_timestamp_t timestamp;
1019 /* error data */
1020} __packed acpi_hest_generic_data_v300_t;
1021#define HEST_GENERIC_ENTRY_V300 0x300
1022
1023/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
1024#define ACPI_GENERROR_SEV_RECOVERABLE 0
1025#define ACPI_GENERROR_SEV_FATAL 1
1026#define ACPI_GENERROR_SEV_CORRECTED 2
1027#define ACPI_GENERROR_SEV_NONE 3
1028
1029/* Generic Error Data Entry, Validation Bits field */
1030#define ACPI_GENERROR_VALID_FRUID BIT(0)
1031#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
1032#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
1033
Felix Held403fa862021-07-26 22:43:00 +02001034/*
1035 * Generic Error Status Block
1036 *
1037 * If there is a raw data section at the end of the generic error status block after the
1038 * zero or more generic error data entries, raw_data_length indicates the length of the raw
1039 * section and raw_data_offset is the offset of the beginning of the raw data section from
1040 * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length
1041 * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t).
1042 */
Furquan Shaikhe0844632020-05-02 10:23:37 -07001043typedef struct acpi_generic_error_status {
1044 u32 block_status;
1045 u32 raw_data_offset; /* must follow any generic entries */
1046 u32 raw_data_length;
1047 u32 data_length; /* generic data */
1048 u32 error_severity;
1049 /* Generic Error Data structures, zero or more entries */
1050} __packed acpi_generic_error_status_t;
1051
1052/* Generic Status Block, Block Status values */
1053#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
1054#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
1055#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
1056#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
1057#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
1058#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
1059#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
1060 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
1061 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
1062
1063typedef struct acpi_cstate {
1064 u8 ctype;
1065 u16 latency;
1066 u32 power;
1067 acpi_addr_t resource;
1068} __packed acpi_cstate_t;
1069
Jason Gleneskca36aed2020-09-15 21:01:57 -07001070struct acpi_sw_pstate {
1071 u32 core_freq;
1072 u32 power;
1073 u32 transition_latency;
1074 u32 bus_master_latency;
1075 u32 control_value;
1076 u32 status_value;
1077} __packed;
1078
1079struct acpi_xpss_sw_pstate {
1080 u64 core_freq;
1081 u64 power;
1082 u64 transition_latency;
1083 u64 bus_master_latency;
1084 u64 control_value;
1085 u64 status_value;
1086 u64 control_mask;
1087 u64 status_mask;
1088} __packed;
1089
Furquan Shaikhe0844632020-05-02 10:23:37 -07001090typedef struct acpi_tstate {
1091 u32 percent;
1092 u32 power;
1093 u32 latency;
1094 u32 control;
1095 u32 status;
1096} __packed acpi_tstate_t;
1097
Raul E Rangelc7048322021-04-19 15:58:25 -06001098enum acpi_lpi_state_flags {
1099 ACPI_LPI_STATE_DISABLED = 0,
1100 ACPI_LPI_STATE_ENABLED
1101};
1102
1103/* Low Power Idle State */
1104struct acpi_lpi_state {
1105 u32 min_residency_us;
1106 u32 worst_case_wakeup_latency_us;
1107 u32 flags;
1108 u32 arch_context_lost_flags;
1109 u32 residency_counter_frequency_hz;
1110 u32 enabled_parent_state;
1111 acpi_addr_t entry_method;
1112 acpi_addr_t residency_counter_register;
1113 acpi_addr_t usage_counter_register;
1114 const char *state_name;
1115};
1116
Furquan Shaikhe0844632020-05-02 10:23:37 -07001117/* Port types for ACPI _UPC object */
1118enum acpi_upc_type {
1119 UPC_TYPE_A,
1120 UPC_TYPE_MINI_AB,
1121 UPC_TYPE_EXPRESSCARD,
1122 UPC_TYPE_USB3_A,
1123 UPC_TYPE_USB3_B,
1124 UPC_TYPE_USB3_MICRO_B,
1125 UPC_TYPE_USB3_MICRO_AB,
1126 UPC_TYPE_USB3_POWER_B,
1127 UPC_TYPE_C_USB2_ONLY,
1128 UPC_TYPE_C_USB2_SS_SWITCH,
1129 UPC_TYPE_C_USB2_SS,
1130 UPC_TYPE_PROPRIETARY = 0xff,
1131 /*
1132 * The following types are not directly defined in the ACPI
1133 * spec but are used by coreboot to identify a USB device type.
1134 */
1135 UPC_TYPE_INTERNAL = 0xff,
1136 UPC_TYPE_UNUSED,
1137 UPC_TYPE_HUB
1138};
1139
1140enum acpi_ipmi_interface_type {
1141 IPMI_INTERFACE_RESERVED = 0,
1142 IPMI_INTERFACE_KCS,
1143 IPMI_INTERFACE_SMIC,
1144 IPMI_INTERFACE_BT,
1145 IPMI_INTERFACE_SSIF,
1146};
1147
1148#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
1149#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
1150#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
1151
1152/* ACPI IPMI 2.0 */
1153struct acpi_spmi {
1154 acpi_header_t header;
1155 u8 interface_type;
1156 u8 reserved;
1157 u16 specification_revision;
1158 u8 interrupt_type;
1159 u8 gpe;
1160 u8 reserved2;
1161 u8 pci_device_flag;
1162
1163 u32 global_system_interrupt;
1164 acpi_addr_t base_address;
1165 union {
1166 struct {
1167 u8 pci_segment_group;
1168 u8 pci_bus;
1169 u8 pci_device;
1170 u8 pci_function;
1171 };
1172 u8 uid[4];
1173 };
1174 u8 reserved3;
1175} __packed;
1176
Rocky Phaguraeff07132021-01-10 15:42:50 -08001177/* EINJ APEI Standard Definitions */
1178/* EINJ Error Types
1179 Refer to the ACPI spec, EINJ section, for more info on bit definitions
1180*/
1181#define ACPI_EINJ_CPU_CE (1 << 0)
1182#define ACPI_EINJ_CPU_UCE (1 << 1)
1183#define ACPI_EINJ_CPU_UCE_FATAL (1 << 2)
1184#define ACPI_EINJ_MEM_CE (1 << 3)
1185#define ACPI_EINJ_MEM_UCE (1 << 4)
1186#define ACPI_EINJ_MEM_UCE_FATAL (1 << 5)
1187#define ACPI_EINJ_PCIE_CE (1 << 6)
1188#define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7)
1189#define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8)
1190#define ACPI_EINJ_PLATFORM_CE (1 << 9)
1191#define ACPI_EINJ_PLATFORM_UCE (1 << 10)
1192#define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11)
1193#define ACPI_EINJ_VENDOR_DEFINED (1 << 31)
1194#define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \
1195 ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL)
1196
1197/* EINJ actions */
1198#define ACTION_COUNT 9
1199#define BEGIN_INJECT_OP 0x00
1200#define GET_TRIGGER_ACTION_TABLE 0x01
1201#define SET_ERROR_TYPE 0x02
1202#define GET_ERROR_TYPE 0x03
1203#define END_INJECT_OP 0x04
1204#define EXECUTE_INJECT_OP 0x05
1205#define CHECK_BUSY_STATUS 0x06
1206#define GET_CMD_STATUS 0x07
1207#define SET_ERROR_TYPE_WITH_ADDRESS 0x08
1208#define TRIGGER_ERROR 0xFF
1209
1210/* EINJ Instructions */
1211#define READ_REGISTER 0x00
1212#define READ_REGISTER_VALUE 0x01
1213#define WRITE_REGISTER 0x02
1214#define WRITE_REGISTER_VALUE 0x03
1215#define NO_OP 0x04
1216
1217/* EINJ (Error Injection Table) */
1218typedef struct acpi_gen_regaddr1 {
1219 u8 space_id; /* Address space ID */
1220 u8 bit_width; /* Register size in bits */
1221 u8 bit_offset; /* Register bit offset */
1222 u8 access_size; /* Access size since ACPI 2.0c */
1223 u64 addr; /* Register address */
1224} __packed acpi_addr64_t;
1225
1226/* Instruction entry */
1227typedef struct acpi_einj_action_table {
1228 u8 action;
1229 u8 instruction;
1230 u16 flags;
1231 acpi_addr64_t reg;
1232 u64 value;
1233 u64 mask;
1234} __packed acpi_einj_action_table_t;
1235
1236typedef struct acpi_injection_header {
1237 u32 einj_header_size;
1238 u32 flags;
1239 u32 entry_count;
1240} __packed acpi_injection_header_t;
1241
1242typedef struct acpi_einj_trigger_table {
1243 u32 header_size;
1244 u32 revision;
1245 u32 table_size;
1246 u32 entry_count;
1247 acpi_einj_action_table_t trigger_action[1];
1248} __packed acpi_einj_trigger_table_t;
1249
1250typedef struct set_error_type {
1251 u32 errtype;
1252 u32 vendorerrortype;
1253 u32 flags;
1254 u32 apicid;
1255 u64 memaddr;
1256 u64 memrange;
1257 u32 pciesbdf;
1258} __packed set_error_type_t;
1259
1260#define EINJ_PARAM_NUM 6
1261typedef struct acpi_einj_smi {
1262 u64 op_state;
1263 u64 err_inject[EINJ_PARAM_NUM];
1264 u64 trigger_action_table;
1265 u64 err_inj_cap;
1266 u64 op_status;
1267 u64 cmd_sts;
1268 u64 einj_addr;
1269 u64 einj_addr_msk;
1270 set_error_type_t setaddrtable;
1271 u64 reserved[50];
1272} __packed acpi_einj_smi_t;
1273
1274/* EINJ Flags */
1275#define EINJ_DEF_TRIGGER_PORT 0xb2
1276#define FLAG_PRESERVE 0x01
1277#define FLAG_IGNORE 0x00
1278
1279/* EINJ Registers */
1280#define EINJ_REG_MEMORY(address) \
1281 { \
1282 .space_id = ACPI_ADDRESS_SPACE_MEMORY, \
1283 .bit_width = 64, \
1284 .bit_offset = 0, \
1285 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
1286 .addr = address}
1287
1288#define EINJ_REG_IO() \
1289 { \
1290 .space_id = ACPI_ADDRESS_SPACE_IO, \
1291 .bit_width = 0x10, \
1292 .bit_offset = 0, \
1293 .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \
1294 .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */
1295
1296typedef struct acpi_einj {
1297 acpi_header_t header;
1298 acpi_injection_header_t inj_header;
1299 acpi_einj_action_table_t action_table[ACTION_COUNT];
1300} __packed acpi_einj_t;
1301
Arthur Heymanse7aaf042023-06-07 12:12:45 +02001302/* SPCR (Serial Port Console Redirection Table) */
1303typedef struct acpi_spcr {
1304 acpi_header_t header;
1305 uint8_t interface_type;
1306 uint8_t reserved[3];
1307 acpi_addr_t base_address;
1308 uint8_t interrupt_type;
1309 uint8_t irq;
1310 uint32_t global_system_interrupt;
1311 uint8_t configured_baudrate;
1312 uint8_t parity;
1313 uint8_t stop_bits;
1314 uint8_t flow_control;
1315 uint8_t terminal_type;
1316 uint8_t language;
1317 uint16_t pci_did;
1318 uint16_t pci_vid;
1319 uint8_t pci_bus;
1320 uint8_t pci_dev;
1321 uint8_t pci_fun;
1322 uint32_t pci_flags;
1323 uint8_t pci_segment;
1324 uint32_t uart_clock;
1325 uint32_t precise_baud_rate;
1326 uint16_t namespace_string_length;
1327 uint16_t namespace_string_offset;
1328 char namespacestring[];
1329} __packed acpi_spcr_t;
1330_Static_assert(sizeof(acpi_spcr_t) == 88, "acpi_spcr_t must have an 88 byte size\n");
1331
Arthur Heymans90464072023-06-07 12:53:50 +02001332#define PC_AT_COMPATIBLE_INTERRUPT (1 << 0)
1333#define IO_APIC_COMPATIBLE_INTERRUPT (1 << 1)
1334#define IO_SAPIC_COMPATIBLE_INTERRUPT (1 << 2)
1335#define ARMH_GIC_COMPATIBLE_INTERRUPT (1 << 3)
1336#define RISCV_PLIC_COMPATIBLE_INTERRUPT (1 << 4)
1337
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01001338uintptr_t get_coreboot_rsdp(void);
Rocky Phaguraeff07132021-01-10 15:42:50 -08001339void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);
1340
Furquan Shaikhe0844632020-05-02 10:23:37 -07001341unsigned long fw_cfg_acpi_tables(unsigned long start);
1342
1343/* These are implemented by the target port or north/southbridge. */
Raul E Rangel6b446b92021-11-19 11:38:35 -07001344void preload_acpi_dsdt(void);
Arthur Heymans7ebebf72023-06-17 14:08:46 +02001345unsigned long write_acpi_tables(const unsigned long addr);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001346unsigned long acpi_fill_madt(unsigned long current);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001347
Furquan Shaikhe0844632020-05-02 10:23:37 -07001348void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +02001349void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001350void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001351void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001352
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001353void acpi_fill_gnvs(void);
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02001354void acpi_fill_cnvs(void);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001355
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001356unsigned long acpi_fill_lpit(unsigned long current);
1357
Furquan Shaikhe0844632020-05-02 10:23:37 -07001358/* These can be used by the target port. */
1359u8 acpi_checksum(u8 *table, u32 length);
1360
1361void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
1362
Jonathan Zhang3dcafa82022-05-11 13:11:20 -07001363/* Create CXL Early Discovery Table */
1364void acpi_create_cedt(acpi_cedt_t *cedt,
1365 unsigned long (*acpi_fill_cedt)(unsigned long current));
1366/* Create a CXL Host Bridge Structure for CEDT */
1367int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base);
1368/* Create a CXL Fixed Memory Window Structure for CEDT */
1369int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size,
1370 u8 eniw, u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target);
1371
Kyösti Mälkkic7da0272021-06-08 11:37:08 +03001372int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001373
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +03001374unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 cpu, u32 apic);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001375
1376unsigned long acpi_create_madt_lapic_nmis(unsigned long current);
1377
Furquan Shaikhe0844632020-05-02 10:23:37 -07001378int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
Naresh Solanki76835cc2023-01-20 19:13:02 +01001379int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001380int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
1381 u32 flags);
Jonathan Zhang3164b642021-04-21 17:51:31 -07001382/*
1383 * Given the Generic Initiator device's BDF, the proximity domain's ID
1384 * and flag, create Generic Initiator Affinity structure in SRAT.
1385 */
1386int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
1387 u16 seg, u8 bus, u8 dev, u8 func, u32 flags);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001388unsigned long acpi_create_srat_lapics(unsigned long current);
1389void acpi_create_srat(acpi_srat_t *srat,
1390 unsigned long (*acpi_fill_srat)(unsigned long current));
1391
1392void acpi_create_slit(acpi_slit_t *slit,
1393 unsigned long (*acpi_fill_slit)(unsigned long current));
1394
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001395/*
1396 * Create a Memory Proximity Domain Attributes structure for HMAT,
1397 * given proximity domain for the attached initiaor, and
1398 * proximimity domain for the memory.
1399 */
1400int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory);
Martin Roth0949e732021-10-01 14:28:22 -06001401/* Create Heterogeneous Memory Attribute Table */
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001402void acpi_create_hmat(acpi_hmat_t *hmat,
1403 unsigned long (*acpi_fill_hmat)(unsigned long current));
1404
Furquan Shaikhe0844632020-05-02 10:23:37 -07001405void acpi_create_vfct(const struct device *device,
1406 acpi_vfct_t *vfct,
1407 unsigned long (*acpi_fill_vfct)(const struct device *device,
1408 acpi_vfct_t *vfct_struct,
1409 unsigned long current));
1410
1411void acpi_create_ipmi(const struct device *device,
1412 struct acpi_spmi *spmi,
1413 const u16 ipmi_revision,
1414 const acpi_addr_t *addr,
1415 const enum acpi_ipmi_interface_type type,
1416 const s8 gpe_interrupt,
1417 const u32 apic_interrupt,
1418 const u32 uid);
1419
1420void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1421 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1422 unsigned long current));
1423
Jason Glenesk61624b22020-11-02 20:06:23 -08001424void acpi_create_crat(struct acpi_crat_header *crat,
1425 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1426 unsigned long current));
1427
Furquan Shaikhe0844632020-05-02 10:23:37 -07001428unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1429 acpi_rsdp_t *rsdp);
1430
1431/* cpu/intel/speedstep/acpi.c */
1432void generate_cpu_entries(const struct device *device);
1433
Furquan Shaikhe0844632020-05-02 10:23:37 -07001434unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
1435 const struct device *dev, uint8_t access_size);
1436void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1437 unsigned long (*acpi_fill_dmar)(unsigned long));
1438unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1439 u16 segment, u64 bar);
1440unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1441 u64 bar, u64 limit);
1442unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1443 u16 segment);
1444unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1445 u32 proximity_domain);
1446unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1447 const char *device_name);
John Zhao6edbb182021-03-24 11:55:09 -07001448unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags,
John Zhao091532d2021-04-17 16:03:21 -07001449 u16 segment);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001450void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1451void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1452void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
John Zhao6edbb182021-03-24 11:55:09 -07001453void acpi_dmar_satc_fixup(unsigned long base, unsigned long current);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001454unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1455 u8 bus, u8 dev, u8 fn);
1456unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1457 u8 bus, u8 dev, u8 fn);
1458unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1459 u8 enumeration_id,
1460 u8 bus, u8 dev, u8 fn);
Arthur Heymansbc8f8592022-12-02 13:17:39 +01001461unsigned long acpi_create_dmar_ds_ioapic_from_hw(unsigned long current,
1462 u32 addr, u8 bus, u8 dev, u8 fn);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001463unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1464 u8 enumeration_id,
1465 u8 bus, u8 dev, u8 fn);
1466void acpi_write_hest(acpi_hest_t *hest,
1467 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1468
1469unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1470 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1471
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001472unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1473
Felix Heldf7dbf4a2021-06-07 16:56:04 +02001474/* chipsets that select ACPI_BERT must implement this function */
Felix Held29405482021-05-28 16:01:57 +02001475enum cb_err acpi_soc_get_bert_region(void **region, size_t *length);
Francois Toguo522e0db2021-01-21 09:55:19 -08001476
Furquan Shaikhe0844632020-05-02 10:23:37 -07001477/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001478void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001479void mainboard_suspend_resume(void);
1480void *acpi_find_wakeup_vector(void);
1481
1482/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1483enum {
1484 ACPI_S0 = 0,
1485 ACPI_S1 = 1,
1486 ACPI_S2 = 2,
1487 ACPI_S3 = 3,
1488 ACPI_S4 = 4,
1489 ACPI_S5 = 5,
1490};
1491
1492#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1493 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1494/* Given the provided PM1 control register return the ACPI sleep type. */
1495static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1496{
1497 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1498 case SLP_TYP_S0: return ACPI_S0;
1499 case SLP_TYP_S1: return ACPI_S1;
1500 case SLP_TYP_S3: return ACPI_S3;
1501 case SLP_TYP_S4: return ACPI_S4;
1502 case SLP_TYP_S5: return ACPI_S5;
1503 }
1504 return -1;
1505}
1506#endif
1507
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001508uint8_t acpi_get_preferred_pm_profile(void);
1509
Furquan Shaikhe0844632020-05-02 10:23:37 -07001510/* Returns ACPI_Sx values. */
1511int acpi_get_sleep_type(void);
1512
1513/* Read and clear GPE status */
1514int acpi_get_gpe(int gpe);
1515
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001516/* Once we enter payload, is SMI handler installed and capable of
1517 responding to APM_CNT Advanced Power Management Control commands. */
1518static inline int permanent_smi_handler(void)
1519{
1520 return CONFIG(HAVE_SMI_HANDLER);
1521}
1522
Furquan Shaikhe0844632020-05-02 10:23:37 -07001523static inline int acpi_s3_resume_allowed(void)
1524{
1525 return CONFIG(HAVE_ACPI_RESUME);
1526}
1527
Furquan Shaikhe0844632020-05-02 10:23:37 -07001528static inline int acpi_is_wakeup_s3(void)
1529{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001530 if (!acpi_s3_resume_allowed())
1531 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001532
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001533 if (ENV_ROMSTAGE_OR_BEFORE)
1534 return (acpi_get_sleep_type() == ACPI_S3);
1535
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001536 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001537}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001538
1539static inline uintptr_t acpi_align_current(uintptr_t current)
1540{
1541 return ALIGN_UP(current, 16);
1542}
1543
1544/* ACPI table revisions should match the revision of the ACPI spec
1545 * supported. This function keeps the table versions synced. This could
1546 * be made into a weak function if there is ever a need to override the
1547 * coreboot default ACPI spec version supported. */
1548int get_acpi_table_revision(enum acpi_tables table);
Elyes Haouas8b950f42022-02-16 12:08:16 +01001549u8 get_acpi_fadt_minor_version(void);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001550
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001551#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001552
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001553#endif /* __ACPI_ACPI_H__ */