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