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