blob: 01d10c2b20417f54266194b3af97a3a4f9398a5e [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
Jonathan Zhang3164b642021-04-21 17:51:31 -0700284#define ACPI_SRAT_STRUCTURE_LAPIC 0
285#define ACPI_SRAT_STRUCTURE_MEM 1
286#define ACPI_SRAT_STRUCTURE_GIA 5
287
Furquan Shaikhe0844632020-05-02 10:23:37 -0700288/* SRAT: Processor Local APIC/SAPIC Affinity Structure */
289typedef struct acpi_srat_lapic {
290 u8 type; /* Type (0) */
291 u8 length; /* Length in bytes (16) */
292 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
293 u8 apic_id; /* Local APIC ID */
294 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
295 u8 local_sapic_eid; /* Local SAPIC EID */
296 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
297 u32 clock_domain; /* _CDM Clock Domain */
298} __packed acpi_srat_lapic_t;
299
300/* SRAT: Memory Affinity Structure */
301typedef struct acpi_srat_mem {
302 u8 type; /* Type (1) */
303 u8 length; /* Length in bytes (40) */
304 u32 proximity_domain; /* Proximity domain */
305 u16 resv;
306 u32 base_address_low; /* Mem range base address, low */
307 u32 base_address_high; /* Mem range base address, high */
308 u32 length_low; /* Mem range length, low */
309 u32 length_high; /* Mem range length, high */
310 u32 resv1;
311 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2,
312 * other bits reserved to 0
313 */
314 u32 resv2[2];
315} __packed acpi_srat_mem_t;
316
Jonathan Zhang3164b642021-04-21 17:51:31 -0700317/* SRAT: Generic Initiator Affinity Structure (ACPI spec 6.4 section 5.2.16.6) */
318typedef struct acpi_srat_gia {
319 u8 type; /* Type (5) */
320 u8 length; /* Length in bytes (32) */
321 u8 resv;
322 u8 dev_handle_type; /* Device handle type */
323 u32 proximity_domain; /*Proximity domain */
324 u8 dev_handle[16]; /* Device handle */
325 u32 flags;
326 u32 resv1;
327} __packed acpi_srat_gia_t;
328
329#define ACPI_SRAT_GIA_DEV_HANDLE_ACPI 0
330#define ACPI_SRAT_GIA_DEV_HANDLE_PCI 1
331
Furquan Shaikhe0844632020-05-02 10:23:37 -0700332/* SLIT (System Locality Distance Information Table) */
333typedef struct acpi_slit {
334 acpi_header_t header;
335 /* Followed by static resource allocation 8+byte[num*num] */
336} __packed acpi_slit_t;
337
338/* MADT (Multiple APIC Description Table) */
339typedef struct acpi_madt {
340 acpi_header_t header;
341 u32 lapic_addr; /* Local APIC address */
342 u32 flags; /* Multiple APIC flags */
343} __packed acpi_madt_t;
344
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100345/*
346 * LPIT (Low Power Idle Table)
347 * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017.
348 */
349typedef struct acpi_lpit {
350 acpi_header_t header;
351} __packed acpi_lpit_t;
352
353/* LPIT: LPI descriptor flags */
354typedef struct acpi_lpi_flags {
355 uint32_t disabled : 1;
356 uint32_t counter_not_available : 1;
357 uint32_t reserved : 30;
358} __packed acpi_lpi_desc_flags_t;
359
360/* LPIT: LPI descriptor types */
361enum acpi_lpi_desc_type {
362 ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00,
363 /* type >= 1 reserved */
364};
365
366/* LPIT: LPI descriptor header */
367typedef struct acpi_lpi_desc_hdr {
368 uint32_t type;
369 uint32_t length;
370 uint16_t uid;
371 uint16_t reserved;
372} __packed acpi_lpi_desc_hdr_t;
373
374#define ACPI_LPIT_CTR_FREQ_TSC 0
375
376/* LPIT: Native C-state instruction based LPI structure */
377typedef struct acpi_lpi_desc_ncst {
378 acpi_lpi_desc_hdr_t header;
379 acpi_lpi_desc_flags_t flags;
380 acpi_addr_t entry_trigger; /* Entry trigger C-state */
381 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
382 uint32_t max_latency; /* Worst case exit latency in microseconds */
383 acpi_addr_t residency_counter;
384 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
385} __packed acpi_lpi_desc_ncst_t;
386
Furquan Shaikhe0844632020-05-02 10:23:37 -0700387/* VFCT image header */
388typedef struct acpi_vfct_image_hdr {
389 u32 PCIBus;
390 u32 PCIDevice;
391 u32 PCIFunction;
392 u16 VendorID;
393 u16 DeviceID;
394 u16 SSVID;
395 u16 SSID;
396 u32 Revision;
397 u32 ImageLength;
398 u8 VbiosContent; // dummy - copy VBIOS here
399} __packed acpi_vfct_image_hdr_t;
400
401/* VFCT (VBIOS Fetch Table) */
402typedef struct acpi_vfct {
403 acpi_header_t header;
404 u8 TableUUID[16];
405 u32 VBIOSImageOffset;
406 u32 Lib1ImageOffset;
407 u32 Reserved[4];
408 acpi_vfct_image_hdr_t image_hdr;
409} __packed acpi_vfct_t;
410
411typedef struct acpi_ivrs_info {
412} __packed acpi_ivrs_info_t;
413
414/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
415typedef struct acpi_ivrs_ivhd {
416 uint8_t type;
417 uint8_t flags;
418 uint16_t length;
419 uint16_t device_id;
420 uint16_t capability_offset;
421 uint32_t iommu_base_low;
422 uint32_t iommu_base_high;
423 uint16_t pci_segment_group;
424 uint16_t iommu_info;
425 uint32_t iommu_feature_info;
426 uint8_t entry[0];
427} __packed acpi_ivrs_ivhd_t;
428
429/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
430typedef struct acpi_ivrs {
431 acpi_header_t header;
432 uint32_t iv_info;
433 uint32_t reserved[2];
434 struct acpi_ivrs_ivhd ivhd;
435} __packed acpi_ivrs_t;
436
Jason Glenesk61624b22020-11-02 20:06:23 -0800437/* CRAT (Component Resource Affinity Table Structure) */
438struct acpi_crat_header {
439 acpi_header_t header;
440 uint32_t total_entries;
441 uint16_t num_nodes;
442 uint8_t reserved[6];
443} __packed;
444
Furquan Shaikhe0844632020-05-02 10:23:37 -0700445/* IVHD Type 11h IOMMU Attributes */
446typedef struct ivhd11_iommu_attr {
447 uint32_t reserved1 : 13;
448 uint32_t perf_counters : 4;
449 uint32_t perf_counter_banks : 6;
450 uint32_t msi_num_ppr : 5;
451 uint32_t reserved2 : 4;
452} __packed ivhd11_iommu_attr_t;
453
454/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
455typedef struct acpi_ivrs_ivhd_11 {
456 uint8_t type;
457 uint8_t flags;
458 uint16_t length;
459 uint16_t device_id;
460 uint16_t capability_offset;
461 uint32_t iommu_base_low;
462 uint32_t iommu_base_high;
463 uint16_t pci_segment_group;
464 uint16_t iommu_info;
465 struct ivhd11_iommu_attr iommu_attributes;
466 uint32_t efr_reg_image_low;
467 uint32_t efr_reg_image_high;
468 uint32_t reserved[2];
469 uint8_t entry[0];
470} __packed acpi_ivrs_ivhd11_t;
471
472enum dev_scope_type {
473 SCOPE_PCI_ENDPOINT = 1,
474 SCOPE_PCI_SUB = 2,
475 SCOPE_IOAPIC = 3,
476 SCOPE_MSI_HPET = 4,
477 SCOPE_ACPI_NAMESPACE_DEVICE = 5
478};
479
480typedef struct dev_scope {
481 u8 type;
482 u8 length;
483 u8 reserved[2];
484 u8 enumeration;
485 u8 start_bus;
486 struct {
487 u8 dev;
488 u8 fn;
489 } __packed path[0];
490} __packed dev_scope_t;
491
492enum dmar_type {
493 DMAR_DRHD = 0,
494 DMAR_RMRR = 1,
495 DMAR_ATSR = 2,
496 DMAR_RHSA = 3,
John Zhao6edbb182021-03-24 11:55:09 -0700497 DMAR_ANDD = 4,
498 DMAR_SATC = 5
Furquan Shaikhe0844632020-05-02 10:23:37 -0700499};
500
501enum {
502 DRHD_INCLUDE_PCI_ALL = 1
503};
504
John Zhao091532d2021-04-17 16:03:21 -0700505enum {
506 ATC_REQUIRED = 1
507};
508
Furquan Shaikhe0844632020-05-02 10:23:37 -0700509enum dmar_flags {
510 DMAR_INTR_REMAP = 1 << 0,
511 DMAR_X2APIC_OPT_OUT = 1 << 1,
512 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
513};
514
515typedef struct dmar_entry {
516 u16 type;
517 u16 length;
518 u8 flags;
519 u8 reserved;
520 u16 segment;
521 u64 bar;
522} __packed dmar_entry_t;
523
524typedef struct dmar_rmrr_entry {
525 u16 type;
526 u16 length;
527 u16 reserved;
528 u16 segment;
529 u64 bar;
530 u64 limit;
531} __packed dmar_rmrr_entry_t;
532
533typedef struct dmar_atsr_entry {
534 u16 type;
535 u16 length;
536 u8 flags;
537 u8 reserved;
538 u16 segment;
539} __packed dmar_atsr_entry_t;
540
541typedef struct dmar_rhsa_entry {
542 u16 type;
543 u16 length;
544 u32 reserved;
545 u64 base_address;
546 u32 proximity_domain;
547} __packed dmar_rhsa_entry_t;
548
549typedef struct dmar_andd_entry {
550 u16 type;
551 u16 length;
552 u8 reserved[3];
553 u8 device_number;
554 u8 device_name[];
555} __packed dmar_andd_entry_t;
556
John Zhao6edbb182021-03-24 11:55:09 -0700557typedef struct dmar_satc_entry {
558 u16 type;
559 u16 length;
560 u8 flags;
561 u8 reserved;
562 u16 segment_number;
John Zhao6edbb182021-03-24 11:55:09 -0700563} __packed dmar_satc_entry_t;
564
Furquan Shaikhe0844632020-05-02 10:23:37 -0700565/* DMAR (DMA Remapping Reporting Structure) */
566typedef struct acpi_dmar {
567 acpi_header_t header;
568 u8 host_address_width;
569 u8 flags;
570 u8 reserved[10];
571 dmar_entry_t structure[0];
572} __packed acpi_dmar_t;
573
574/* MADT: APIC Structure Types */
575enum acpi_apic_types {
576 LOCAL_APIC, /* Processor local APIC */
577 IO_APIC, /* I/O APIC */
578 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
579 NMI_TYPE, /* NMI source */
580 LOCAL_APIC_NMI, /* Local APIC NMI */
581 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
582 IO_SAPIC, /* I/O SAPIC */
583 LOCAL_SAPIC, /* Local SAPIC */
584 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
585 LOCAL_X2APIC, /* Processor local x2APIC */
586 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
587 GICC, /* GIC CPU Interface */
588 GICD, /* GIC Distributor */
589 GIC_MSI_FRAME, /* GIC MSI Frame */
590 GICR, /* GIC Redistributor */
591 GIC_ITS, /* Interrupt Translation Service */
592 /* 0x10-0x7f: Reserved */
593 /* 0x80-0xff: Reserved for OEM use */
594};
595
596/* MADT: Processor Local APIC Structure */
597typedef struct acpi_madt_lapic {
598 u8 type; /* Type (0) */
599 u8 length; /* Length in bytes (8) */
600 u8 processor_id; /* ACPI processor ID */
601 u8 apic_id; /* Local APIC ID */
602 u32 flags; /* Local APIC flags */
603} __packed acpi_madt_lapic_t;
604
605/* MADT: Local APIC NMI Structure */
606typedef struct acpi_madt_lapic_nmi {
607 u8 type; /* Type (4) */
608 u8 length; /* Length in bytes (6) */
609 u8 processor_id; /* ACPI processor ID */
610 u16 flags; /* MPS INTI flags */
611 u8 lint; /* Local APIC LINT# */
612} __packed acpi_madt_lapic_nmi_t;
613
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700614#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
615
Furquan Shaikhe0844632020-05-02 10:23:37 -0700616/* MADT: I/O APIC Structure */
617typedef struct acpi_madt_ioapic {
618 u8 type; /* Type (1) */
619 u8 length; /* Length in bytes (12) */
620 u8 ioapic_id; /* I/O APIC ID */
621 u8 reserved;
622 u32 ioapic_addr; /* I/O APIC address */
623 u32 gsi_base; /* Global system interrupt base */
624} __packed acpi_madt_ioapic_t;
625
626/* MADT: Interrupt Source Override Structure */
627typedef struct acpi_madt_irqoverride {
628 u8 type; /* Type (2) */
629 u8 length; /* Length in bytes (10) */
630 u8 bus; /* ISA (0) */
631 u8 source; /* Bus-relative int. source (IRQ) */
632 u32 gsirq; /* Global system interrupt */
633 u16 flags; /* MPS INTI flags */
634} __packed acpi_madt_irqoverride_t;
635
636/* MADT: Processor Local x2APIC Structure */
637typedef struct acpi_madt_lx2apic {
638 u8 type; /* Type (9) */
639 u8 length; /* Length in bytes (16) */
640 u16 reserved;
641 u32 x2apic_id; /* Local x2APIC ID */
642 u32 flags; /* Same as Local APIC flags */
643 u32 processor_id; /* ACPI processor ID */
644} __packed acpi_madt_lx2apic_t;
645
646/* MADT: Processor Local x2APIC NMI Structure */
647typedef struct acpi_madt_lx2apic_nmi {
648 u8 type; /* Type (10) */
649 u8 length; /* Length in bytes (12) */
650 u16 flags; /* Same as MPS INTI flags */
651 u32 processor_id; /* ACPI processor ID */
652 u8 lint; /* Local APIC LINT# */
653 u8 reserved[3];
654} __packed acpi_madt_lx2apic_nmi_t;
655
656#define ACPI_DBG2_PORT_SERIAL 0x8000
657#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
658#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
659#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
660#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
661#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
662#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
663#define ACPI_DBG2_PORT_IEEE1394 0x8001
664#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
665#define ACPI_DBG2_PORT_USB 0x8002
666#define ACPI_DBG2_PORT_USB_XHCI 0x0000
667#define ACPI_DBG2_PORT_USB_EHCI 0x0001
668#define ACPI_DBG2_PORT_NET 0x8003
669
670/* DBG2: Microsoft Debug Port Table 2 header */
671typedef struct acpi_dbg2_header {
672 acpi_header_t header;
673 uint32_t devices_offset;
674 uint32_t devices_count;
675} __attribute__((packed)) acpi_dbg2_header_t;
676
677/* DBG2: Microsoft Debug Port Table 2 device entry */
678typedef struct acpi_dbg2_device {
679 uint8_t revision;
680 uint16_t length;
681 uint8_t address_count;
682 uint16_t namespace_string_length;
683 uint16_t namespace_string_offset;
684 uint16_t oem_data_length;
685 uint16_t oem_data_offset;
686 uint16_t port_type;
687 uint16_t port_subtype;
688 uint8_t reserved[2];
689 uint16_t base_address_offset;
690 uint16_t address_size_offset;
691} __attribute__((packed)) acpi_dbg2_device_t;
692
693/* FADT (Fixed ACPI Description Table) */
694typedef struct acpi_fadt {
695 acpi_header_t header;
696 u32 firmware_ctrl;
697 u32 dsdt;
698 u8 reserved; /* Should be 0 */
699 u8 preferred_pm_profile;
700 u16 sci_int;
701 u32 smi_cmd;
702 u8 acpi_enable;
703 u8 acpi_disable;
704 u8 s4bios_req;
705 u8 pstate_cnt;
706 u32 pm1a_evt_blk;
707 u32 pm1b_evt_blk;
708 u32 pm1a_cnt_blk;
709 u32 pm1b_cnt_blk;
710 u32 pm2_cnt_blk;
711 u32 pm_tmr_blk;
712 u32 gpe0_blk;
713 u32 gpe1_blk;
714 u8 pm1_evt_len;
715 u8 pm1_cnt_len;
716 u8 pm2_cnt_len;
717 u8 pm_tmr_len;
718 u8 gpe0_blk_len;
719 u8 gpe1_blk_len;
720 u8 gpe1_base;
721 u8 cst_cnt;
722 u16 p_lvl2_lat;
723 u16 p_lvl3_lat;
724 u16 flush_size;
725 u16 flush_stride;
726 u8 duty_offset;
727 u8 duty_width;
728 u8 day_alrm;
729 u8 mon_alrm;
730 u8 century;
731 u16 iapc_boot_arch;
732 u8 res2;
733 u32 flags;
734 acpi_addr_t reset_reg;
735 u8 reset_value;
736 u16 ARM_boot_arch; /* Revision 6 only, Revision 5: Must be zero */
737 u8 FADT_MinorVersion; /* Revision 6 only, Revision 5: Must be zero */
738 u32 x_firmware_ctl_l;
739 u32 x_firmware_ctl_h;
740 u32 x_dsdt_l;
741 u32 x_dsdt_h;
742 acpi_addr_t x_pm1a_evt_blk;
743 acpi_addr_t x_pm1b_evt_blk;
744 acpi_addr_t x_pm1a_cnt_blk;
745 acpi_addr_t x_pm1b_cnt_blk;
746 acpi_addr_t x_pm2_cnt_blk;
747 acpi_addr_t x_pm_tmr_blk;
748 acpi_addr_t x_gpe0_blk;
749 acpi_addr_t x_gpe1_blk;
750 /* Revision 5 */
751 acpi_addr_t sleep_control_reg;
752 acpi_addr_t sleep_status_reg;
753 /* Revision 6 */
754 u64 hypervisor_vendor_identity;
755} __packed acpi_fadt_t;
756
757/* FADT TABLE Revision values */
758#define ACPI_FADT_REV_ACPI_1_0 1
759#define ACPI_FADT_REV_ACPI_2_0 3
760#define ACPI_FADT_REV_ACPI_3_0 4
761#define ACPI_FADT_REV_ACPI_4_0 4
762#define ACPI_FADT_REV_ACPI_5_0 5
763#define ACPI_FADT_REV_ACPI_6_0 6
764
765/* Flags for p_lvl2_lat and p_lvl3_lat */
766#define ACPI_FADT_C2_NOT_SUPPORTED 101
767#define ACPI_FADT_C3_NOT_SUPPORTED 1001
768
769/* FADT Feature Flags */
770#define ACPI_FADT_WBINVD (1 << 0)
771#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
772#define ACPI_FADT_C1_SUPPORTED (1 << 2)
773#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
774#define ACPI_FADT_POWER_BUTTON (1 << 4)
775#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
776#define ACPI_FADT_FIXED_RTC (1 << 6)
777#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
778#define ACPI_FADT_32BIT_TIMER (1 << 8)
779#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
780#define ACPI_FADT_RESET_REGISTER (1 << 10)
781#define ACPI_FADT_SEALED_CASE (1 << 11)
782#define ACPI_FADT_HEADLESS (1 << 12)
783#define ACPI_FADT_SLEEP_TYPE (1 << 13)
784#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
785#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
786#define ACPI_FADT_S4_RTC_VALID (1 << 16)
787#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
788#define ACPI_FADT_APIC_CLUSTER (1 << 18)
789#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
790/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
791#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
792#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
793/* bits 22-31: reserved since ACPI 5.0 */
794
795/* FADT Boot Architecture Flags */
796#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
797#define ACPI_FADT_8042 (1 << 1)
798#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
799#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
800#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
801#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
802#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
803
804/* FADT ARM Boot Architecture Flags */
805#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
806#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
807/* bits 2-16: reserved since ACPI 5.1 */
808
809/* FADT Preferred Power Management Profile */
810enum acpi_preferred_pm_profiles {
811 PM_UNSPECIFIED = 0,
812 PM_DESKTOP = 1,
813 PM_MOBILE = 2,
814 PM_WORKSTATION = 3,
815 PM_ENTERPRISE_SERVER = 4,
816 PM_SOHO_SERVER = 5,
817 PM_APPLIANCE_PC = 6,
818 PM_PERFORMANCE_SERVER = 7,
819 PM_TABLET = 8, /* ACPI 5.0 & greater */
820};
821
822/* FACS (Firmware ACPI Control Structure) */
823typedef struct acpi_facs {
824 char signature[4]; /* "FACS" */
825 u32 length; /* Length in bytes (>= 64) */
826 u32 hardware_signature; /* Hardware signature */
827 u32 firmware_waking_vector; /* Firmware waking vector */
828 u32 global_lock; /* Global lock */
829 u32 flags; /* FACS flags */
830 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
831 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
832 u8 version; /* FACS version */
833 u8 resv1[3]; /* This value is 0 */
834 u32 ospm_flags; /* 64BIT_WAKE_F */
835 u8 resv2[24]; /* This value is 0 */
836} __packed acpi_facs_t;
837
838/* FACS flags */
839#define ACPI_FACS_S4BIOS_F (1 << 0)
840#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
841/* Bits 31..2: reserved */
842
843/* ECDT (Embedded Controller Boot Resources Table) */
844typedef struct acpi_ecdt {
845 acpi_header_t header;
846 acpi_addr_t ec_control; /* EC control register */
847 acpi_addr_t ec_data; /* EC data register */
848 u32 uid; /* UID */
849 u8 gpe_bit; /* GPE bit */
850 u8 ec_id[]; /* EC ID */
851} __packed acpi_ecdt_t;
852
853/* HEST (Hardware Error Source Table) */
854typedef struct acpi_hest {
855 acpi_header_t header;
856 u32 error_source_count;
857 /* error_source_struct(s) */
858} __packed acpi_hest_t;
859
860/* Error Source Descriptors */
861typedef struct acpi_hest_esd {
862 u16 type;
863 u16 source_id;
864 u16 resv;
865 u8 flags;
866 u8 enabled;
867 u32 prealloc_erecords; /* The number of error records to
868 * pre-allocate for this error source.
869 */
870 u32 max_section_per_record;
871} __packed acpi_hest_esd_t;
872
873/* Hardware Error Notification */
874typedef struct acpi_hest_hen {
875 u8 type;
876 u8 length;
877 u16 conf_we; /* Configuration Write Enable */
878 u32 poll_interval;
879 u32 vector;
880 u32 sw2poll_threshold_val;
881 u32 sw2poll_threshold_win;
882 u32 error_threshold_val;
883 u32 error_threshold_win;
884} __packed acpi_hest_hen_t;
885
886/* BERT (Boot Error Record Table) */
887typedef struct acpi_bert {
888 acpi_header_t header;
889 u32 region_length;
890 u64 error_region;
891} __packed acpi_bert_t;
892
893/* Generic Error Data Entry */
894typedef struct acpi_hest_generic_data {
895 guid_t section_type;
896 u32 error_severity;
897 u16 revision;
898 u8 validation_bits;
899 u8 flags;
900 u32 data_length;
901 guid_t fru_id;
902 u8 fru_text[20];
903 /* error data */
904} __packed acpi_hest_generic_data_t;
905
906/* Generic Error Data Entry v300 */
907typedef struct acpi_hest_generic_data_v300 {
908 guid_t section_type;
909 u32 error_severity;
910 u16 revision;
911 u8 validation_bits;
912 u8 flags; /* see CPER Section Descriptor, Flags field */
913 u32 data_length;
914 guid_t fru_id;
915 u8 fru_text[20];
916 cper_timestamp_t timestamp;
917 /* error data */
918} __packed acpi_hest_generic_data_v300_t;
919#define HEST_GENERIC_ENTRY_V300 0x300
920
921/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
922#define ACPI_GENERROR_SEV_RECOVERABLE 0
923#define ACPI_GENERROR_SEV_FATAL 1
924#define ACPI_GENERROR_SEV_CORRECTED 2
925#define ACPI_GENERROR_SEV_NONE 3
926
927/* Generic Error Data Entry, Validation Bits field */
928#define ACPI_GENERROR_VALID_FRUID BIT(0)
929#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
930#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
931
Felix Held403fa862021-07-26 22:43:00 +0200932/*
933 * Generic Error Status Block
934 *
935 * If there is a raw data section at the end of the generic error status block after the
936 * zero or more generic error data entries, raw_data_length indicates the length of the raw
937 * section and raw_data_offset is the offset of the beginning of the raw data section from
938 * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length
939 * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t).
940 */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700941typedef struct acpi_generic_error_status {
942 u32 block_status;
943 u32 raw_data_offset; /* must follow any generic entries */
944 u32 raw_data_length;
945 u32 data_length; /* generic data */
946 u32 error_severity;
947 /* Generic Error Data structures, zero or more entries */
948} __packed acpi_generic_error_status_t;
949
950/* Generic Status Block, Block Status values */
951#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
952#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
953#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
954#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
955#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
956#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
957#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
958 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
959 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
960
961typedef struct acpi_cstate {
962 u8 ctype;
963 u16 latency;
964 u32 power;
965 acpi_addr_t resource;
966} __packed acpi_cstate_t;
967
Jason Gleneskca36aed2020-09-15 21:01:57 -0700968struct acpi_sw_pstate {
969 u32 core_freq;
970 u32 power;
971 u32 transition_latency;
972 u32 bus_master_latency;
973 u32 control_value;
974 u32 status_value;
975} __packed;
976
977struct acpi_xpss_sw_pstate {
978 u64 core_freq;
979 u64 power;
980 u64 transition_latency;
981 u64 bus_master_latency;
982 u64 control_value;
983 u64 status_value;
984 u64 control_mask;
985 u64 status_mask;
986} __packed;
987
Furquan Shaikhe0844632020-05-02 10:23:37 -0700988typedef struct acpi_tstate {
989 u32 percent;
990 u32 power;
991 u32 latency;
992 u32 control;
993 u32 status;
994} __packed acpi_tstate_t;
995
Raul E Rangelc7048322021-04-19 15:58:25 -0600996enum acpi_lpi_state_flags {
997 ACPI_LPI_STATE_DISABLED = 0,
998 ACPI_LPI_STATE_ENABLED
999};
1000
1001/* Low Power Idle State */
1002struct acpi_lpi_state {
1003 u32 min_residency_us;
1004 u32 worst_case_wakeup_latency_us;
1005 u32 flags;
1006 u32 arch_context_lost_flags;
1007 u32 residency_counter_frequency_hz;
1008 u32 enabled_parent_state;
1009 acpi_addr_t entry_method;
1010 acpi_addr_t residency_counter_register;
1011 acpi_addr_t usage_counter_register;
1012 const char *state_name;
1013};
1014
Furquan Shaikhe0844632020-05-02 10:23:37 -07001015/* Port types for ACPI _UPC object */
1016enum acpi_upc_type {
1017 UPC_TYPE_A,
1018 UPC_TYPE_MINI_AB,
1019 UPC_TYPE_EXPRESSCARD,
1020 UPC_TYPE_USB3_A,
1021 UPC_TYPE_USB3_B,
1022 UPC_TYPE_USB3_MICRO_B,
1023 UPC_TYPE_USB3_MICRO_AB,
1024 UPC_TYPE_USB3_POWER_B,
1025 UPC_TYPE_C_USB2_ONLY,
1026 UPC_TYPE_C_USB2_SS_SWITCH,
1027 UPC_TYPE_C_USB2_SS,
1028 UPC_TYPE_PROPRIETARY = 0xff,
1029 /*
1030 * The following types are not directly defined in the ACPI
1031 * spec but are used by coreboot to identify a USB device type.
1032 */
1033 UPC_TYPE_INTERNAL = 0xff,
1034 UPC_TYPE_UNUSED,
1035 UPC_TYPE_HUB
1036};
1037
1038enum acpi_ipmi_interface_type {
1039 IPMI_INTERFACE_RESERVED = 0,
1040 IPMI_INTERFACE_KCS,
1041 IPMI_INTERFACE_SMIC,
1042 IPMI_INTERFACE_BT,
1043 IPMI_INTERFACE_SSIF,
1044};
1045
1046#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
1047#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
1048#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
1049
1050/* ACPI IPMI 2.0 */
1051struct acpi_spmi {
1052 acpi_header_t header;
1053 u8 interface_type;
1054 u8 reserved;
1055 u16 specification_revision;
1056 u8 interrupt_type;
1057 u8 gpe;
1058 u8 reserved2;
1059 u8 pci_device_flag;
1060
1061 u32 global_system_interrupt;
1062 acpi_addr_t base_address;
1063 union {
1064 struct {
1065 u8 pci_segment_group;
1066 u8 pci_bus;
1067 u8 pci_device;
1068 u8 pci_function;
1069 };
1070 u8 uid[4];
1071 };
1072 u8 reserved3;
1073} __packed;
1074
Rocky Phaguraeff07132021-01-10 15:42:50 -08001075/* EINJ APEI Standard Definitions */
1076/* EINJ Error Types
1077 Refer to the ACPI spec, EINJ section, for more info on bit definitions
1078*/
1079#define ACPI_EINJ_CPU_CE (1 << 0)
1080#define ACPI_EINJ_CPU_UCE (1 << 1)
1081#define ACPI_EINJ_CPU_UCE_FATAL (1 << 2)
1082#define ACPI_EINJ_MEM_CE (1 << 3)
1083#define ACPI_EINJ_MEM_UCE (1 << 4)
1084#define ACPI_EINJ_MEM_UCE_FATAL (1 << 5)
1085#define ACPI_EINJ_PCIE_CE (1 << 6)
1086#define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7)
1087#define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8)
1088#define ACPI_EINJ_PLATFORM_CE (1 << 9)
1089#define ACPI_EINJ_PLATFORM_UCE (1 << 10)
1090#define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11)
1091#define ACPI_EINJ_VENDOR_DEFINED (1 << 31)
1092#define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \
1093 ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL)
1094
1095/* EINJ actions */
1096#define ACTION_COUNT 9
1097#define BEGIN_INJECT_OP 0x00
1098#define GET_TRIGGER_ACTION_TABLE 0x01
1099#define SET_ERROR_TYPE 0x02
1100#define GET_ERROR_TYPE 0x03
1101#define END_INJECT_OP 0x04
1102#define EXECUTE_INJECT_OP 0x05
1103#define CHECK_BUSY_STATUS 0x06
1104#define GET_CMD_STATUS 0x07
1105#define SET_ERROR_TYPE_WITH_ADDRESS 0x08
1106#define TRIGGER_ERROR 0xFF
1107
1108/* EINJ Instructions */
1109#define READ_REGISTER 0x00
1110#define READ_REGISTER_VALUE 0x01
1111#define WRITE_REGISTER 0x02
1112#define WRITE_REGISTER_VALUE 0x03
1113#define NO_OP 0x04
1114
1115/* EINJ (Error Injection Table) */
1116typedef struct acpi_gen_regaddr1 {
1117 u8 space_id; /* Address space ID */
1118 u8 bit_width; /* Register size in bits */
1119 u8 bit_offset; /* Register bit offset */
1120 u8 access_size; /* Access size since ACPI 2.0c */
1121 u64 addr; /* Register address */
1122} __packed acpi_addr64_t;
1123
1124/* Instruction entry */
1125typedef struct acpi_einj_action_table {
1126 u8 action;
1127 u8 instruction;
1128 u16 flags;
1129 acpi_addr64_t reg;
1130 u64 value;
1131 u64 mask;
1132} __packed acpi_einj_action_table_t;
1133
1134typedef struct acpi_injection_header {
1135 u32 einj_header_size;
1136 u32 flags;
1137 u32 entry_count;
1138} __packed acpi_injection_header_t;
1139
1140typedef struct acpi_einj_trigger_table {
1141 u32 header_size;
1142 u32 revision;
1143 u32 table_size;
1144 u32 entry_count;
1145 acpi_einj_action_table_t trigger_action[1];
1146} __packed acpi_einj_trigger_table_t;
1147
1148typedef struct set_error_type {
1149 u32 errtype;
1150 u32 vendorerrortype;
1151 u32 flags;
1152 u32 apicid;
1153 u64 memaddr;
1154 u64 memrange;
1155 u32 pciesbdf;
1156} __packed set_error_type_t;
1157
1158#define EINJ_PARAM_NUM 6
1159typedef struct acpi_einj_smi {
1160 u64 op_state;
1161 u64 err_inject[EINJ_PARAM_NUM];
1162 u64 trigger_action_table;
1163 u64 err_inj_cap;
1164 u64 op_status;
1165 u64 cmd_sts;
1166 u64 einj_addr;
1167 u64 einj_addr_msk;
1168 set_error_type_t setaddrtable;
1169 u64 reserved[50];
1170} __packed acpi_einj_smi_t;
1171
1172/* EINJ Flags */
1173#define EINJ_DEF_TRIGGER_PORT 0xb2
1174#define FLAG_PRESERVE 0x01
1175#define FLAG_IGNORE 0x00
1176
1177/* EINJ Registers */
1178#define EINJ_REG_MEMORY(address) \
1179 { \
1180 .space_id = ACPI_ADDRESS_SPACE_MEMORY, \
1181 .bit_width = 64, \
1182 .bit_offset = 0, \
1183 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
1184 .addr = address}
1185
1186#define EINJ_REG_IO() \
1187 { \
1188 .space_id = ACPI_ADDRESS_SPACE_IO, \
1189 .bit_width = 0x10, \
1190 .bit_offset = 0, \
1191 .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \
1192 .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */
1193
1194typedef struct acpi_einj {
1195 acpi_header_t header;
1196 acpi_injection_header_t inj_header;
1197 acpi_einj_action_table_t action_table[ACTION_COUNT];
1198} __packed acpi_einj_t;
1199
1200
1201void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);
1202
Furquan Shaikhe0844632020-05-02 10:23:37 -07001203unsigned long fw_cfg_acpi_tables(unsigned long start);
1204
1205/* These are implemented by the target port or north/southbridge. */
1206unsigned long write_acpi_tables(unsigned long addr);
1207unsigned long acpi_fill_madt(unsigned long current);
1208unsigned long acpi_fill_mcfg(unsigned long current);
1209unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current);
1210void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id);
1211void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length);
1212void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001213
Furquan Shaikhe0844632020-05-02 10:23:37 -07001214void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +02001215void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001216void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001217void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001218
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001219void acpi_fill_gnvs(void);
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02001220void acpi_fill_cnvs(void);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001221
Furquan Shaikhe0844632020-05-02 10:23:37 -07001222void update_ssdt(void *ssdt);
1223void update_ssdtx(void *ssdtx, int i);
1224
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001225unsigned long acpi_fill_lpit(unsigned long current);
1226
Furquan Shaikhe0844632020-05-02 10:23:37 -07001227/* These can be used by the target port. */
1228u8 acpi_checksum(u8 *table, u32 length);
1229
1230void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
1231
1232int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
1233int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
1234 u32 gsi_base);
1235int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
1236 u8 bus, u8 source, u32 gsirq, u16 flags);
1237int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
1238 u16 flags, u8 lint);
1239void acpi_create_madt(acpi_madt_t *madt);
1240unsigned long acpi_create_madt_lapics(unsigned long current);
1241unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
1242 u8 lint);
1243int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic);
1244int acpi_create_madt_lx2apic_nmi(acpi_madt_lx2apic_nmi_t *lapic_nmi, u32 cpu,
1245 u16 flags, u8 lint);
1246int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
1247int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
1248 u32 flags);
Jonathan Zhang3164b642021-04-21 17:51:31 -07001249/*
1250 * Given the Generic Initiator device's BDF, the proximity domain's ID
1251 * and flag, create Generic Initiator Affinity structure in SRAT.
1252 */
1253int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
1254 u16 seg, u8 bus, u8 dev, u8 func, u32 flags);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001255int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
1256 u16 seg_nr, u8 start, u8 end);
1257unsigned long acpi_create_srat_lapics(unsigned long current);
1258void acpi_create_srat(acpi_srat_t *srat,
1259 unsigned long (*acpi_fill_srat)(unsigned long current));
1260
1261void acpi_create_slit(acpi_slit_t *slit,
1262 unsigned long (*acpi_fill_slit)(unsigned long current));
1263
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001264/*
1265 * Create a Memory Proximity Domain Attributes structure for HMAT,
1266 * given proximity domain for the attached initiaor, and
1267 * proximimity domain for the memory.
1268 */
1269int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory);
1270/* Create Heterogenous Memory Attribute Table */
1271void acpi_create_hmat(acpi_hmat_t *hmat,
1272 unsigned long (*acpi_fill_hmat)(unsigned long current));
1273
Furquan Shaikhe0844632020-05-02 10:23:37 -07001274void acpi_create_vfct(const struct device *device,
1275 acpi_vfct_t *vfct,
1276 unsigned long (*acpi_fill_vfct)(const struct device *device,
1277 acpi_vfct_t *vfct_struct,
1278 unsigned long current));
1279
1280void acpi_create_ipmi(const struct device *device,
1281 struct acpi_spmi *spmi,
1282 const u16 ipmi_revision,
1283 const acpi_addr_t *addr,
1284 const enum acpi_ipmi_interface_type type,
1285 const s8 gpe_interrupt,
1286 const u32 apic_interrupt,
1287 const u32 uid);
1288
1289void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1290 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1291 unsigned long current));
1292
Jason Glenesk61624b22020-11-02 20:06:23 -08001293void acpi_create_crat(struct acpi_crat_header *crat,
1294 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1295 unsigned long current));
1296
Furquan Shaikhe0844632020-05-02 10:23:37 -07001297void acpi_create_hpet(acpi_hpet_t *hpet);
1298unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1299 acpi_rsdp_t *rsdp);
1300
1301/* cpu/intel/speedstep/acpi.c */
1302void generate_cpu_entries(const struct device *device);
1303
1304void acpi_create_mcfg(acpi_mcfg_t *mcfg);
1305
1306void acpi_create_facs(acpi_facs_t *facs);
1307
1308void acpi_create_dbg2(acpi_dbg2_header_t *dbg2_header,
1309 int port_type, int port_subtype,
1310 acpi_addr_t *address, uint32_t address_size,
1311 const char *device_path);
1312
1313unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
1314 const struct device *dev, uint8_t access_size);
1315void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1316 unsigned long (*acpi_fill_dmar)(unsigned long));
1317unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1318 u16 segment, u64 bar);
1319unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1320 u64 bar, u64 limit);
1321unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1322 u16 segment);
1323unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1324 u32 proximity_domain);
1325unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1326 const char *device_name);
John Zhao6edbb182021-03-24 11:55:09 -07001327unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags,
John Zhao091532d2021-04-17 16:03:21 -07001328 u16 segment);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001329void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1330void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1331void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
John Zhao6edbb182021-03-24 11:55:09 -07001332void acpi_dmar_satc_fixup(unsigned long base, unsigned long current);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001333unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1334 u8 bus, u8 dev, u8 fn);
1335unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1336 u8 bus, u8 dev, u8 fn);
1337unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1338 u8 enumeration_id,
1339 u8 bus, u8 dev, u8 fn);
1340unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1341 u8 enumeration_id,
1342 u8 bus, u8 dev, u8 fn);
1343void acpi_write_hest(acpi_hest_t *hest,
1344 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1345
1346unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1347 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1348
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001349void acpi_create_lpit(acpi_lpit_t *lpit);
1350unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1351
Felix Heldf7dbf4a2021-06-07 16:56:04 +02001352/* chipsets that select ACPI_BERT must implement this function */
Felix Held29405482021-05-28 16:01:57 +02001353enum cb_err acpi_soc_get_bert_region(void **region, size_t *length);
Francois Toguo522e0db2021-01-21 09:55:19 -08001354
Furquan Shaikhe0844632020-05-02 10:23:37 -07001355/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001356void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001357void mainboard_suspend_resume(void);
1358void *acpi_find_wakeup_vector(void);
1359
1360/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1361enum {
1362 ACPI_S0 = 0,
1363 ACPI_S1 = 1,
1364 ACPI_S2 = 2,
1365 ACPI_S3 = 3,
1366 ACPI_S4 = 4,
1367 ACPI_S5 = 5,
1368};
1369
1370#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1371 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1372/* Given the provided PM1 control register return the ACPI sleep type. */
1373static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1374{
1375 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1376 case SLP_TYP_S0: return ACPI_S0;
1377 case SLP_TYP_S1: return ACPI_S1;
1378 case SLP_TYP_S3: return ACPI_S3;
1379 case SLP_TYP_S4: return ACPI_S4;
1380 case SLP_TYP_S5: return ACPI_S5;
1381 }
1382 return -1;
1383}
1384#endif
1385
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001386uint8_t acpi_get_preferred_pm_profile(void);
1387
Furquan Shaikhe0844632020-05-02 10:23:37 -07001388/* Returns ACPI_Sx values. */
1389int acpi_get_sleep_type(void);
1390
1391/* Read and clear GPE status */
1392int acpi_get_gpe(int gpe);
1393
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001394/* Once we enter payload, is SMI handler installed and capable of
1395 responding to APM_CNT Advanced Power Management Control commands. */
1396static inline int permanent_smi_handler(void)
1397{
1398 return CONFIG(HAVE_SMI_HANDLER);
1399}
1400
Furquan Shaikhe0844632020-05-02 10:23:37 -07001401static inline int acpi_s3_resume_allowed(void)
1402{
1403 return CONFIG(HAVE_ACPI_RESUME);
1404}
1405
Furquan Shaikhe0844632020-05-02 10:23:37 -07001406static inline int acpi_is_wakeup_s3(void)
1407{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001408 if (!acpi_s3_resume_allowed())
1409 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001410
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001411 if (ENV_ROMSTAGE_OR_BEFORE)
1412 return (acpi_get_sleep_type() == ACPI_S3);
1413
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001414 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001415}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001416
1417static inline uintptr_t acpi_align_current(uintptr_t current)
1418{
1419 return ALIGN_UP(current, 16);
1420}
1421
1422/* ACPI table revisions should match the revision of the ACPI spec
1423 * supported. This function keeps the table versions synced. This could
1424 * be made into a weak function if there is ever a need to override the
1425 * coreboot default ACPI spec version supported. */
1426int get_acpi_table_revision(enum acpi_tables table);
1427
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001428#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001429
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001430#endif /* __ACPI_ACPI_H__ */