blob: 775fc316e7c883da3cbeefc7ec7f2b968657621b [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 */
74 BERT, DBG2, DMAR, DSDT, FACS, FADT, HEST, HPET, IVRS, MADT, MCFG,
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +010075 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
211/* SRAT (System Resource Affinity Table) */
212typedef struct acpi_srat {
213 acpi_header_t header;
214 u32 resv;
215 u64 resv1;
216 /* Followed by static resource allocation structure[n] */
217} __packed acpi_srat_t;
218
219/* SRAT: Processor Local APIC/SAPIC Affinity Structure */
220typedef struct acpi_srat_lapic {
221 u8 type; /* Type (0) */
222 u8 length; /* Length in bytes (16) */
223 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
224 u8 apic_id; /* Local APIC ID */
225 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
226 u8 local_sapic_eid; /* Local SAPIC EID */
227 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
228 u32 clock_domain; /* _CDM Clock Domain */
229} __packed acpi_srat_lapic_t;
230
231/* SRAT: Memory Affinity Structure */
232typedef struct acpi_srat_mem {
233 u8 type; /* Type (1) */
234 u8 length; /* Length in bytes (40) */
235 u32 proximity_domain; /* Proximity domain */
236 u16 resv;
237 u32 base_address_low; /* Mem range base address, low */
238 u32 base_address_high; /* Mem range base address, high */
239 u32 length_low; /* Mem range length, low */
240 u32 length_high; /* Mem range length, high */
241 u32 resv1;
242 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2,
243 * other bits reserved to 0
244 */
245 u32 resv2[2];
246} __packed acpi_srat_mem_t;
247
248/* SLIT (System Locality Distance Information Table) */
249typedef struct acpi_slit {
250 acpi_header_t header;
251 /* Followed by static resource allocation 8+byte[num*num] */
252} __packed acpi_slit_t;
253
254/* MADT (Multiple APIC Description Table) */
255typedef struct acpi_madt {
256 acpi_header_t header;
257 u32 lapic_addr; /* Local APIC address */
258 u32 flags; /* Multiple APIC flags */
259} __packed acpi_madt_t;
260
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100261/*
262 * LPIT (Low Power Idle Table)
263 * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017.
264 */
265typedef struct acpi_lpit {
266 acpi_header_t header;
267} __packed acpi_lpit_t;
268
269/* LPIT: LPI descriptor flags */
270typedef struct acpi_lpi_flags {
271 uint32_t disabled : 1;
272 uint32_t counter_not_available : 1;
273 uint32_t reserved : 30;
274} __packed acpi_lpi_desc_flags_t;
275
276/* LPIT: LPI descriptor types */
277enum acpi_lpi_desc_type {
278 ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00,
279 /* type >= 1 reserved */
280};
281
282/* LPIT: LPI descriptor header */
283typedef struct acpi_lpi_desc_hdr {
284 uint32_t type;
285 uint32_t length;
286 uint16_t uid;
287 uint16_t reserved;
288} __packed acpi_lpi_desc_hdr_t;
289
290#define ACPI_LPIT_CTR_FREQ_TSC 0
291
292/* LPIT: Native C-state instruction based LPI structure */
293typedef struct acpi_lpi_desc_ncst {
294 acpi_lpi_desc_hdr_t header;
295 acpi_lpi_desc_flags_t flags;
296 acpi_addr_t entry_trigger; /* Entry trigger C-state */
297 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
298 uint32_t max_latency; /* Worst case exit latency in microseconds */
299 acpi_addr_t residency_counter;
300 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
301} __packed acpi_lpi_desc_ncst_t;
302
Furquan Shaikhe0844632020-05-02 10:23:37 -0700303/* VFCT image header */
304typedef struct acpi_vfct_image_hdr {
305 u32 PCIBus;
306 u32 PCIDevice;
307 u32 PCIFunction;
308 u16 VendorID;
309 u16 DeviceID;
310 u16 SSVID;
311 u16 SSID;
312 u32 Revision;
313 u32 ImageLength;
314 u8 VbiosContent; // dummy - copy VBIOS here
315} __packed acpi_vfct_image_hdr_t;
316
317/* VFCT (VBIOS Fetch Table) */
318typedef struct acpi_vfct {
319 acpi_header_t header;
320 u8 TableUUID[16];
321 u32 VBIOSImageOffset;
322 u32 Lib1ImageOffset;
323 u32 Reserved[4];
324 acpi_vfct_image_hdr_t image_hdr;
325} __packed acpi_vfct_t;
326
327typedef struct acpi_ivrs_info {
328} __packed acpi_ivrs_info_t;
329
330/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
331typedef struct acpi_ivrs_ivhd {
332 uint8_t type;
333 uint8_t flags;
334 uint16_t length;
335 uint16_t device_id;
336 uint16_t capability_offset;
337 uint32_t iommu_base_low;
338 uint32_t iommu_base_high;
339 uint16_t pci_segment_group;
340 uint16_t iommu_info;
341 uint32_t iommu_feature_info;
342 uint8_t entry[0];
343} __packed acpi_ivrs_ivhd_t;
344
345/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
346typedef struct acpi_ivrs {
347 acpi_header_t header;
348 uint32_t iv_info;
349 uint32_t reserved[2];
350 struct acpi_ivrs_ivhd ivhd;
351} __packed acpi_ivrs_t;
352
Jason Glenesk61624b22020-11-02 20:06:23 -0800353/* CRAT (Component Resource Affinity Table Structure) */
354struct acpi_crat_header {
355 acpi_header_t header;
356 uint32_t total_entries;
357 uint16_t num_nodes;
358 uint8_t reserved[6];
359} __packed;
360
Furquan Shaikhe0844632020-05-02 10:23:37 -0700361/* IVHD Type 11h IOMMU Attributes */
362typedef struct ivhd11_iommu_attr {
363 uint32_t reserved1 : 13;
364 uint32_t perf_counters : 4;
365 uint32_t perf_counter_banks : 6;
366 uint32_t msi_num_ppr : 5;
367 uint32_t reserved2 : 4;
368} __packed ivhd11_iommu_attr_t;
369
370/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
371typedef struct acpi_ivrs_ivhd_11 {
372 uint8_t type;
373 uint8_t flags;
374 uint16_t length;
375 uint16_t device_id;
376 uint16_t capability_offset;
377 uint32_t iommu_base_low;
378 uint32_t iommu_base_high;
379 uint16_t pci_segment_group;
380 uint16_t iommu_info;
381 struct ivhd11_iommu_attr iommu_attributes;
382 uint32_t efr_reg_image_low;
383 uint32_t efr_reg_image_high;
384 uint32_t reserved[2];
385 uint8_t entry[0];
386} __packed acpi_ivrs_ivhd11_t;
387
388enum dev_scope_type {
389 SCOPE_PCI_ENDPOINT = 1,
390 SCOPE_PCI_SUB = 2,
391 SCOPE_IOAPIC = 3,
392 SCOPE_MSI_HPET = 4,
393 SCOPE_ACPI_NAMESPACE_DEVICE = 5
394};
395
396typedef struct dev_scope {
397 u8 type;
398 u8 length;
399 u8 reserved[2];
400 u8 enumeration;
401 u8 start_bus;
402 struct {
403 u8 dev;
404 u8 fn;
405 } __packed path[0];
406} __packed dev_scope_t;
407
408enum dmar_type {
409 DMAR_DRHD = 0,
410 DMAR_RMRR = 1,
411 DMAR_ATSR = 2,
412 DMAR_RHSA = 3,
413 DMAR_ANDD = 4
414};
415
416enum {
417 DRHD_INCLUDE_PCI_ALL = 1
418};
419
420enum dmar_flags {
421 DMAR_INTR_REMAP = 1 << 0,
422 DMAR_X2APIC_OPT_OUT = 1 << 1,
423 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
424};
425
426typedef struct dmar_entry {
427 u16 type;
428 u16 length;
429 u8 flags;
430 u8 reserved;
431 u16 segment;
432 u64 bar;
433} __packed dmar_entry_t;
434
435typedef struct dmar_rmrr_entry {
436 u16 type;
437 u16 length;
438 u16 reserved;
439 u16 segment;
440 u64 bar;
441 u64 limit;
442} __packed dmar_rmrr_entry_t;
443
444typedef struct dmar_atsr_entry {
445 u16 type;
446 u16 length;
447 u8 flags;
448 u8 reserved;
449 u16 segment;
450} __packed dmar_atsr_entry_t;
451
452typedef struct dmar_rhsa_entry {
453 u16 type;
454 u16 length;
455 u32 reserved;
456 u64 base_address;
457 u32 proximity_domain;
458} __packed dmar_rhsa_entry_t;
459
460typedef struct dmar_andd_entry {
461 u16 type;
462 u16 length;
463 u8 reserved[3];
464 u8 device_number;
465 u8 device_name[];
466} __packed dmar_andd_entry_t;
467
468/* DMAR (DMA Remapping Reporting Structure) */
469typedef struct acpi_dmar {
470 acpi_header_t header;
471 u8 host_address_width;
472 u8 flags;
473 u8 reserved[10];
474 dmar_entry_t structure[0];
475} __packed acpi_dmar_t;
476
477/* MADT: APIC Structure Types */
478enum acpi_apic_types {
479 LOCAL_APIC, /* Processor local APIC */
480 IO_APIC, /* I/O APIC */
481 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
482 NMI_TYPE, /* NMI source */
483 LOCAL_APIC_NMI, /* Local APIC NMI */
484 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
485 IO_SAPIC, /* I/O SAPIC */
486 LOCAL_SAPIC, /* Local SAPIC */
487 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
488 LOCAL_X2APIC, /* Processor local x2APIC */
489 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
490 GICC, /* GIC CPU Interface */
491 GICD, /* GIC Distributor */
492 GIC_MSI_FRAME, /* GIC MSI Frame */
493 GICR, /* GIC Redistributor */
494 GIC_ITS, /* Interrupt Translation Service */
495 /* 0x10-0x7f: Reserved */
496 /* 0x80-0xff: Reserved for OEM use */
497};
498
499/* MADT: Processor Local APIC Structure */
500typedef struct acpi_madt_lapic {
501 u8 type; /* Type (0) */
502 u8 length; /* Length in bytes (8) */
503 u8 processor_id; /* ACPI processor ID */
504 u8 apic_id; /* Local APIC ID */
505 u32 flags; /* Local APIC flags */
506} __packed acpi_madt_lapic_t;
507
508/* MADT: Local APIC NMI Structure */
509typedef struct acpi_madt_lapic_nmi {
510 u8 type; /* Type (4) */
511 u8 length; /* Length in bytes (6) */
512 u8 processor_id; /* ACPI processor ID */
513 u16 flags; /* MPS INTI flags */
514 u8 lint; /* Local APIC LINT# */
515} __packed acpi_madt_lapic_nmi_t;
516
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700517#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
518
Furquan Shaikhe0844632020-05-02 10:23:37 -0700519/* MADT: I/O APIC Structure */
520typedef struct acpi_madt_ioapic {
521 u8 type; /* Type (1) */
522 u8 length; /* Length in bytes (12) */
523 u8 ioapic_id; /* I/O APIC ID */
524 u8 reserved;
525 u32 ioapic_addr; /* I/O APIC address */
526 u32 gsi_base; /* Global system interrupt base */
527} __packed acpi_madt_ioapic_t;
528
529/* MADT: Interrupt Source Override Structure */
530typedef struct acpi_madt_irqoverride {
531 u8 type; /* Type (2) */
532 u8 length; /* Length in bytes (10) */
533 u8 bus; /* ISA (0) */
534 u8 source; /* Bus-relative int. source (IRQ) */
535 u32 gsirq; /* Global system interrupt */
536 u16 flags; /* MPS INTI flags */
537} __packed acpi_madt_irqoverride_t;
538
539/* MADT: Processor Local x2APIC Structure */
540typedef struct acpi_madt_lx2apic {
541 u8 type; /* Type (9) */
542 u8 length; /* Length in bytes (16) */
543 u16 reserved;
544 u32 x2apic_id; /* Local x2APIC ID */
545 u32 flags; /* Same as Local APIC flags */
546 u32 processor_id; /* ACPI processor ID */
547} __packed acpi_madt_lx2apic_t;
548
549/* MADT: Processor Local x2APIC NMI Structure */
550typedef struct acpi_madt_lx2apic_nmi {
551 u8 type; /* Type (10) */
552 u8 length; /* Length in bytes (12) */
553 u16 flags; /* Same as MPS INTI flags */
554 u32 processor_id; /* ACPI processor ID */
555 u8 lint; /* Local APIC LINT# */
556 u8 reserved[3];
557} __packed acpi_madt_lx2apic_nmi_t;
558
559#define ACPI_DBG2_PORT_SERIAL 0x8000
560#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
561#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
562#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
563#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
564#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
565#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
566#define ACPI_DBG2_PORT_IEEE1394 0x8001
567#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
568#define ACPI_DBG2_PORT_USB 0x8002
569#define ACPI_DBG2_PORT_USB_XHCI 0x0000
570#define ACPI_DBG2_PORT_USB_EHCI 0x0001
571#define ACPI_DBG2_PORT_NET 0x8003
572
573/* DBG2: Microsoft Debug Port Table 2 header */
574typedef struct acpi_dbg2_header {
575 acpi_header_t header;
576 uint32_t devices_offset;
577 uint32_t devices_count;
578} __attribute__((packed)) acpi_dbg2_header_t;
579
580/* DBG2: Microsoft Debug Port Table 2 device entry */
581typedef struct acpi_dbg2_device {
582 uint8_t revision;
583 uint16_t length;
584 uint8_t address_count;
585 uint16_t namespace_string_length;
586 uint16_t namespace_string_offset;
587 uint16_t oem_data_length;
588 uint16_t oem_data_offset;
589 uint16_t port_type;
590 uint16_t port_subtype;
591 uint8_t reserved[2];
592 uint16_t base_address_offset;
593 uint16_t address_size_offset;
594} __attribute__((packed)) acpi_dbg2_device_t;
595
596/* FADT (Fixed ACPI Description Table) */
597typedef struct acpi_fadt {
598 acpi_header_t header;
599 u32 firmware_ctrl;
600 u32 dsdt;
601 u8 reserved; /* Should be 0 */
602 u8 preferred_pm_profile;
603 u16 sci_int;
604 u32 smi_cmd;
605 u8 acpi_enable;
606 u8 acpi_disable;
607 u8 s4bios_req;
608 u8 pstate_cnt;
609 u32 pm1a_evt_blk;
610 u32 pm1b_evt_blk;
611 u32 pm1a_cnt_blk;
612 u32 pm1b_cnt_blk;
613 u32 pm2_cnt_blk;
614 u32 pm_tmr_blk;
615 u32 gpe0_blk;
616 u32 gpe1_blk;
617 u8 pm1_evt_len;
618 u8 pm1_cnt_len;
619 u8 pm2_cnt_len;
620 u8 pm_tmr_len;
621 u8 gpe0_blk_len;
622 u8 gpe1_blk_len;
623 u8 gpe1_base;
624 u8 cst_cnt;
625 u16 p_lvl2_lat;
626 u16 p_lvl3_lat;
627 u16 flush_size;
628 u16 flush_stride;
629 u8 duty_offset;
630 u8 duty_width;
631 u8 day_alrm;
632 u8 mon_alrm;
633 u8 century;
634 u16 iapc_boot_arch;
635 u8 res2;
636 u32 flags;
637 acpi_addr_t reset_reg;
638 u8 reset_value;
639 u16 ARM_boot_arch; /* Revision 6 only, Revision 5: Must be zero */
640 u8 FADT_MinorVersion; /* Revision 6 only, Revision 5: Must be zero */
641 u32 x_firmware_ctl_l;
642 u32 x_firmware_ctl_h;
643 u32 x_dsdt_l;
644 u32 x_dsdt_h;
645 acpi_addr_t x_pm1a_evt_blk;
646 acpi_addr_t x_pm1b_evt_blk;
647 acpi_addr_t x_pm1a_cnt_blk;
648 acpi_addr_t x_pm1b_cnt_blk;
649 acpi_addr_t x_pm2_cnt_blk;
650 acpi_addr_t x_pm_tmr_blk;
651 acpi_addr_t x_gpe0_blk;
652 acpi_addr_t x_gpe1_blk;
653 /* Revision 5 */
654 acpi_addr_t sleep_control_reg;
655 acpi_addr_t sleep_status_reg;
656 /* Revision 6 */
657 u64 hypervisor_vendor_identity;
658} __packed acpi_fadt_t;
659
660/* FADT TABLE Revision values */
661#define ACPI_FADT_REV_ACPI_1_0 1
662#define ACPI_FADT_REV_ACPI_2_0 3
663#define ACPI_FADT_REV_ACPI_3_0 4
664#define ACPI_FADT_REV_ACPI_4_0 4
665#define ACPI_FADT_REV_ACPI_5_0 5
666#define ACPI_FADT_REV_ACPI_6_0 6
667
668/* Flags for p_lvl2_lat and p_lvl3_lat */
669#define ACPI_FADT_C2_NOT_SUPPORTED 101
670#define ACPI_FADT_C3_NOT_SUPPORTED 1001
671
672/* FADT Feature Flags */
673#define ACPI_FADT_WBINVD (1 << 0)
674#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
675#define ACPI_FADT_C1_SUPPORTED (1 << 2)
676#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
677#define ACPI_FADT_POWER_BUTTON (1 << 4)
678#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
679#define ACPI_FADT_FIXED_RTC (1 << 6)
680#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
681#define ACPI_FADT_32BIT_TIMER (1 << 8)
682#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
683#define ACPI_FADT_RESET_REGISTER (1 << 10)
684#define ACPI_FADT_SEALED_CASE (1 << 11)
685#define ACPI_FADT_HEADLESS (1 << 12)
686#define ACPI_FADT_SLEEP_TYPE (1 << 13)
687#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
688#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
689#define ACPI_FADT_S4_RTC_VALID (1 << 16)
690#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
691#define ACPI_FADT_APIC_CLUSTER (1 << 18)
692#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
693/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
694#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
695#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
696/* bits 22-31: reserved since ACPI 5.0 */
697
698/* FADT Boot Architecture Flags */
699#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
700#define ACPI_FADT_8042 (1 << 1)
701#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
702#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
703#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
704#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
705#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
706
707/* FADT ARM Boot Architecture Flags */
708#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
709#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
710/* bits 2-16: reserved since ACPI 5.1 */
711
712/* FADT Preferred Power Management Profile */
713enum acpi_preferred_pm_profiles {
714 PM_UNSPECIFIED = 0,
715 PM_DESKTOP = 1,
716 PM_MOBILE = 2,
717 PM_WORKSTATION = 3,
718 PM_ENTERPRISE_SERVER = 4,
719 PM_SOHO_SERVER = 5,
720 PM_APPLIANCE_PC = 6,
721 PM_PERFORMANCE_SERVER = 7,
722 PM_TABLET = 8, /* ACPI 5.0 & greater */
723};
724
725/* FACS (Firmware ACPI Control Structure) */
726typedef struct acpi_facs {
727 char signature[4]; /* "FACS" */
728 u32 length; /* Length in bytes (>= 64) */
729 u32 hardware_signature; /* Hardware signature */
730 u32 firmware_waking_vector; /* Firmware waking vector */
731 u32 global_lock; /* Global lock */
732 u32 flags; /* FACS flags */
733 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
734 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
735 u8 version; /* FACS version */
736 u8 resv1[3]; /* This value is 0 */
737 u32 ospm_flags; /* 64BIT_WAKE_F */
738 u8 resv2[24]; /* This value is 0 */
739} __packed acpi_facs_t;
740
741/* FACS flags */
742#define ACPI_FACS_S4BIOS_F (1 << 0)
743#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
744/* Bits 31..2: reserved */
745
746/* ECDT (Embedded Controller Boot Resources Table) */
747typedef struct acpi_ecdt {
748 acpi_header_t header;
749 acpi_addr_t ec_control; /* EC control register */
750 acpi_addr_t ec_data; /* EC data register */
751 u32 uid; /* UID */
752 u8 gpe_bit; /* GPE bit */
753 u8 ec_id[]; /* EC ID */
754} __packed acpi_ecdt_t;
755
756/* HEST (Hardware Error Source Table) */
757typedef struct acpi_hest {
758 acpi_header_t header;
759 u32 error_source_count;
760 /* error_source_struct(s) */
761} __packed acpi_hest_t;
762
763/* Error Source Descriptors */
764typedef struct acpi_hest_esd {
765 u16 type;
766 u16 source_id;
767 u16 resv;
768 u8 flags;
769 u8 enabled;
770 u32 prealloc_erecords; /* The number of error records to
771 * pre-allocate for this error source.
772 */
773 u32 max_section_per_record;
774} __packed acpi_hest_esd_t;
775
776/* Hardware Error Notification */
777typedef struct acpi_hest_hen {
778 u8 type;
779 u8 length;
780 u16 conf_we; /* Configuration Write Enable */
781 u32 poll_interval;
782 u32 vector;
783 u32 sw2poll_threshold_val;
784 u32 sw2poll_threshold_win;
785 u32 error_threshold_val;
786 u32 error_threshold_win;
787} __packed acpi_hest_hen_t;
788
789/* BERT (Boot Error Record Table) */
790typedef struct acpi_bert {
791 acpi_header_t header;
792 u32 region_length;
793 u64 error_region;
794} __packed acpi_bert_t;
795
796/* Generic Error Data Entry */
797typedef struct acpi_hest_generic_data {
798 guid_t section_type;
799 u32 error_severity;
800 u16 revision;
801 u8 validation_bits;
802 u8 flags;
803 u32 data_length;
804 guid_t fru_id;
805 u8 fru_text[20];
806 /* error data */
807} __packed acpi_hest_generic_data_t;
808
809/* Generic Error Data Entry v300 */
810typedef struct acpi_hest_generic_data_v300 {
811 guid_t section_type;
812 u32 error_severity;
813 u16 revision;
814 u8 validation_bits;
815 u8 flags; /* see CPER Section Descriptor, Flags field */
816 u32 data_length;
817 guid_t fru_id;
818 u8 fru_text[20];
819 cper_timestamp_t timestamp;
820 /* error data */
821} __packed acpi_hest_generic_data_v300_t;
822#define HEST_GENERIC_ENTRY_V300 0x300
823
824/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
825#define ACPI_GENERROR_SEV_RECOVERABLE 0
826#define ACPI_GENERROR_SEV_FATAL 1
827#define ACPI_GENERROR_SEV_CORRECTED 2
828#define ACPI_GENERROR_SEV_NONE 3
829
830/* Generic Error Data Entry, Validation Bits field */
831#define ACPI_GENERROR_VALID_FRUID BIT(0)
832#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
833#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
834
835/* Generic Error Status Block */
836typedef struct acpi_generic_error_status {
837 u32 block_status;
838 u32 raw_data_offset; /* must follow any generic entries */
839 u32 raw_data_length;
840 u32 data_length; /* generic data */
841 u32 error_severity;
842 /* Generic Error Data structures, zero or more entries */
843} __packed acpi_generic_error_status_t;
844
845/* Generic Status Block, Block Status values */
846#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
847#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
848#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
849#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
850#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
851#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
852#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
853 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
854 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
855
856typedef struct acpi_cstate {
857 u8 ctype;
858 u16 latency;
859 u32 power;
860 acpi_addr_t resource;
861} __packed acpi_cstate_t;
862
Jason Gleneskca36aed2020-09-15 21:01:57 -0700863struct acpi_sw_pstate {
864 u32 core_freq;
865 u32 power;
866 u32 transition_latency;
867 u32 bus_master_latency;
868 u32 control_value;
869 u32 status_value;
870} __packed;
871
872struct acpi_xpss_sw_pstate {
873 u64 core_freq;
874 u64 power;
875 u64 transition_latency;
876 u64 bus_master_latency;
877 u64 control_value;
878 u64 status_value;
879 u64 control_mask;
880 u64 status_mask;
881} __packed;
882
Furquan Shaikhe0844632020-05-02 10:23:37 -0700883typedef struct acpi_tstate {
884 u32 percent;
885 u32 power;
886 u32 latency;
887 u32 control;
888 u32 status;
889} __packed acpi_tstate_t;
890
891/* Port types for ACPI _UPC object */
892enum acpi_upc_type {
893 UPC_TYPE_A,
894 UPC_TYPE_MINI_AB,
895 UPC_TYPE_EXPRESSCARD,
896 UPC_TYPE_USB3_A,
897 UPC_TYPE_USB3_B,
898 UPC_TYPE_USB3_MICRO_B,
899 UPC_TYPE_USB3_MICRO_AB,
900 UPC_TYPE_USB3_POWER_B,
901 UPC_TYPE_C_USB2_ONLY,
902 UPC_TYPE_C_USB2_SS_SWITCH,
903 UPC_TYPE_C_USB2_SS,
904 UPC_TYPE_PROPRIETARY = 0xff,
905 /*
906 * The following types are not directly defined in the ACPI
907 * spec but are used by coreboot to identify a USB device type.
908 */
909 UPC_TYPE_INTERNAL = 0xff,
910 UPC_TYPE_UNUSED,
911 UPC_TYPE_HUB
912};
913
914enum acpi_ipmi_interface_type {
915 IPMI_INTERFACE_RESERVED = 0,
916 IPMI_INTERFACE_KCS,
917 IPMI_INTERFACE_SMIC,
918 IPMI_INTERFACE_BT,
919 IPMI_INTERFACE_SSIF,
920};
921
922#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
923#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
924#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
925
926/* ACPI IPMI 2.0 */
927struct acpi_spmi {
928 acpi_header_t header;
929 u8 interface_type;
930 u8 reserved;
931 u16 specification_revision;
932 u8 interrupt_type;
933 u8 gpe;
934 u8 reserved2;
935 u8 pci_device_flag;
936
937 u32 global_system_interrupt;
938 acpi_addr_t base_address;
939 union {
940 struct {
941 u8 pci_segment_group;
942 u8 pci_bus;
943 u8 pci_device;
944 u8 pci_function;
945 };
946 u8 uid[4];
947 };
948 u8 reserved3;
949} __packed;
950
951unsigned long fw_cfg_acpi_tables(unsigned long start);
952
953/* These are implemented by the target port or north/southbridge. */
954unsigned long write_acpi_tables(unsigned long addr);
955unsigned long acpi_fill_madt(unsigned long current);
956unsigned long acpi_fill_mcfg(unsigned long current);
957unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current);
958void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id);
959void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length);
960void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +0300961
Furquan Shaikhe0844632020-05-02 10:23:37 -0700962void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +0200963void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +0300964void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +0300965void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700966
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +0300967void acpi_fill_gnvs(void);
968
Furquan Shaikhe0844632020-05-02 10:23:37 -0700969void update_ssdt(void *ssdt);
970void update_ssdtx(void *ssdtx, int i);
971
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100972unsigned long acpi_fill_lpit(unsigned long current);
973
Furquan Shaikhe0844632020-05-02 10:23:37 -0700974/* These can be used by the target port. */
975u8 acpi_checksum(u8 *table, u32 length);
976
977void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
978
979int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
980int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
981 u32 gsi_base);
982int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
983 u8 bus, u8 source, u32 gsirq, u16 flags);
984int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
985 u16 flags, u8 lint);
986void acpi_create_madt(acpi_madt_t *madt);
987unsigned long acpi_create_madt_lapics(unsigned long current);
988unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
989 u8 lint);
990int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic);
991int acpi_create_madt_lx2apic_nmi(acpi_madt_lx2apic_nmi_t *lapic_nmi, u32 cpu,
992 u16 flags, u8 lint);
993int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
994int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
995 u32 flags);
996int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
997 u16 seg_nr, u8 start, u8 end);
998unsigned long acpi_create_srat_lapics(unsigned long current);
999void acpi_create_srat(acpi_srat_t *srat,
1000 unsigned long (*acpi_fill_srat)(unsigned long current));
1001
1002void acpi_create_slit(acpi_slit_t *slit,
1003 unsigned long (*acpi_fill_slit)(unsigned long current));
1004
1005void acpi_create_vfct(const struct device *device,
1006 acpi_vfct_t *vfct,
1007 unsigned long (*acpi_fill_vfct)(const struct device *device,
1008 acpi_vfct_t *vfct_struct,
1009 unsigned long current));
1010
1011void acpi_create_ipmi(const struct device *device,
1012 struct acpi_spmi *spmi,
1013 const u16 ipmi_revision,
1014 const acpi_addr_t *addr,
1015 const enum acpi_ipmi_interface_type type,
1016 const s8 gpe_interrupt,
1017 const u32 apic_interrupt,
1018 const u32 uid);
1019
1020void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1021 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1022 unsigned long current));
1023
Jason Glenesk61624b22020-11-02 20:06:23 -08001024void acpi_create_crat(struct acpi_crat_header *crat,
1025 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1026 unsigned long current));
1027
Furquan Shaikhe0844632020-05-02 10:23:37 -07001028void acpi_create_hpet(acpi_hpet_t *hpet);
1029unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1030 acpi_rsdp_t *rsdp);
1031
1032/* cpu/intel/speedstep/acpi.c */
1033void generate_cpu_entries(const struct device *device);
1034
1035void acpi_create_mcfg(acpi_mcfg_t *mcfg);
1036
1037void acpi_create_facs(acpi_facs_t *facs);
1038
1039void acpi_create_dbg2(acpi_dbg2_header_t *dbg2_header,
1040 int port_type, int port_subtype,
1041 acpi_addr_t *address, uint32_t address_size,
1042 const char *device_path);
1043
1044unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
1045 const struct device *dev, uint8_t access_size);
1046void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1047 unsigned long (*acpi_fill_dmar)(unsigned long));
1048unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1049 u16 segment, u64 bar);
1050unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1051 u64 bar, u64 limit);
1052unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1053 u16 segment);
1054unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1055 u32 proximity_domain);
1056unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1057 const char *device_name);
1058void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1059void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1060void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
1061unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1062 u8 bus, u8 dev, u8 fn);
1063unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1064 u8 bus, u8 dev, u8 fn);
1065unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1066 u8 enumeration_id,
1067 u8 bus, u8 dev, u8 fn);
1068unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1069 u8 enumeration_id,
1070 u8 bus, u8 dev, u8 fn);
1071void acpi_write_hest(acpi_hest_t *hest,
1072 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1073
1074unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1075 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1076
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001077void acpi_create_lpit(acpi_lpit_t *lpit);
1078unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1079
Francois Toguo522e0db2021-01-21 09:55:19 -08001080/* For crashlog. */
1081bool acpi_is_boot_error_src_present(void);
1082void acpi_soc_fill_bert(acpi_bert_t *bert, void **region, size_t *length);
1083
Furquan Shaikhe0844632020-05-02 10:23:37 -07001084/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001085void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001086void mainboard_suspend_resume(void);
1087void *acpi_find_wakeup_vector(void);
1088
1089/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1090enum {
1091 ACPI_S0 = 0,
1092 ACPI_S1 = 1,
1093 ACPI_S2 = 2,
1094 ACPI_S3 = 3,
1095 ACPI_S4 = 4,
1096 ACPI_S5 = 5,
1097};
1098
1099#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1100 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1101/* Given the provided PM1 control register return the ACPI sleep type. */
1102static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1103{
1104 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1105 case SLP_TYP_S0: return ACPI_S0;
1106 case SLP_TYP_S1: return ACPI_S1;
1107 case SLP_TYP_S3: return ACPI_S3;
1108 case SLP_TYP_S4: return ACPI_S4;
1109 case SLP_TYP_S5: return ACPI_S5;
1110 }
1111 return -1;
1112}
1113#endif
1114
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001115uint8_t acpi_get_preferred_pm_profile(void);
1116
Furquan Shaikhe0844632020-05-02 10:23:37 -07001117/* Returns ACPI_Sx values. */
1118int acpi_get_sleep_type(void);
1119
1120/* Read and clear GPE status */
1121int acpi_get_gpe(int gpe);
1122
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001123/* Once we enter payload, is SMI handler installed and capable of
1124 responding to APM_CNT Advanced Power Management Control commands. */
1125static inline int permanent_smi_handler(void)
1126{
1127 return CONFIG(HAVE_SMI_HANDLER);
1128}
1129
Furquan Shaikhe0844632020-05-02 10:23:37 -07001130static inline int acpi_s3_resume_allowed(void)
1131{
1132 return CONFIG(HAVE_ACPI_RESUME);
1133}
1134
Furquan Shaikhe0844632020-05-02 10:23:37 -07001135static inline int acpi_is_wakeup_s3(void)
1136{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001137 if (!acpi_s3_resume_allowed())
1138 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001139
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001140 if (ENV_ROMSTAGE_OR_BEFORE)
1141 return (acpi_get_sleep_type() == ACPI_S3);
1142
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001143 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001144}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001145
1146static inline uintptr_t acpi_align_current(uintptr_t current)
1147{
1148 return ALIGN_UP(current, 16);
1149}
1150
1151/* ACPI table revisions should match the revision of the ACPI spec
1152 * supported. This function keeps the table versions synced. This could
1153 * be made into a weak function if there is ever a need to override the
1154 * coreboot default ACPI spec version supported. */
1155int get_acpi_table_revision(enum acpi_tables table);
1156
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001157#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001158
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001159#endif /* __ACPI_ACPI_H__ */