blob: 058c0d0217b6afa5b14e6766b440671b94c57926 [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
517/* MADT: I/O APIC Structure */
518typedef struct acpi_madt_ioapic {
519 u8 type; /* Type (1) */
520 u8 length; /* Length in bytes (12) */
521 u8 ioapic_id; /* I/O APIC ID */
522 u8 reserved;
523 u32 ioapic_addr; /* I/O APIC address */
524 u32 gsi_base; /* Global system interrupt base */
525} __packed acpi_madt_ioapic_t;
526
527/* MADT: Interrupt Source Override Structure */
528typedef struct acpi_madt_irqoverride {
529 u8 type; /* Type (2) */
530 u8 length; /* Length in bytes (10) */
531 u8 bus; /* ISA (0) */
532 u8 source; /* Bus-relative int. source (IRQ) */
533 u32 gsirq; /* Global system interrupt */
534 u16 flags; /* MPS INTI flags */
535} __packed acpi_madt_irqoverride_t;
536
537/* MADT: Processor Local x2APIC Structure */
538typedef struct acpi_madt_lx2apic {
539 u8 type; /* Type (9) */
540 u8 length; /* Length in bytes (16) */
541 u16 reserved;
542 u32 x2apic_id; /* Local x2APIC ID */
543 u32 flags; /* Same as Local APIC flags */
544 u32 processor_id; /* ACPI processor ID */
545} __packed acpi_madt_lx2apic_t;
546
547/* MADT: Processor Local x2APIC NMI Structure */
548typedef struct acpi_madt_lx2apic_nmi {
549 u8 type; /* Type (10) */
550 u8 length; /* Length in bytes (12) */
551 u16 flags; /* Same as MPS INTI flags */
552 u32 processor_id; /* ACPI processor ID */
553 u8 lint; /* Local APIC LINT# */
554 u8 reserved[3];
555} __packed acpi_madt_lx2apic_nmi_t;
556
557#define ACPI_DBG2_PORT_SERIAL 0x8000
558#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
559#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
560#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
561#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
562#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
563#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
564#define ACPI_DBG2_PORT_IEEE1394 0x8001
565#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
566#define ACPI_DBG2_PORT_USB 0x8002
567#define ACPI_DBG2_PORT_USB_XHCI 0x0000
568#define ACPI_DBG2_PORT_USB_EHCI 0x0001
569#define ACPI_DBG2_PORT_NET 0x8003
570
571/* DBG2: Microsoft Debug Port Table 2 header */
572typedef struct acpi_dbg2_header {
573 acpi_header_t header;
574 uint32_t devices_offset;
575 uint32_t devices_count;
576} __attribute__((packed)) acpi_dbg2_header_t;
577
578/* DBG2: Microsoft Debug Port Table 2 device entry */
579typedef struct acpi_dbg2_device {
580 uint8_t revision;
581 uint16_t length;
582 uint8_t address_count;
583 uint16_t namespace_string_length;
584 uint16_t namespace_string_offset;
585 uint16_t oem_data_length;
586 uint16_t oem_data_offset;
587 uint16_t port_type;
588 uint16_t port_subtype;
589 uint8_t reserved[2];
590 uint16_t base_address_offset;
591 uint16_t address_size_offset;
592} __attribute__((packed)) acpi_dbg2_device_t;
593
594/* FADT (Fixed ACPI Description Table) */
595typedef struct acpi_fadt {
596 acpi_header_t header;
597 u32 firmware_ctrl;
598 u32 dsdt;
599 u8 reserved; /* Should be 0 */
600 u8 preferred_pm_profile;
601 u16 sci_int;
602 u32 smi_cmd;
603 u8 acpi_enable;
604 u8 acpi_disable;
605 u8 s4bios_req;
606 u8 pstate_cnt;
607 u32 pm1a_evt_blk;
608 u32 pm1b_evt_blk;
609 u32 pm1a_cnt_blk;
610 u32 pm1b_cnt_blk;
611 u32 pm2_cnt_blk;
612 u32 pm_tmr_blk;
613 u32 gpe0_blk;
614 u32 gpe1_blk;
615 u8 pm1_evt_len;
616 u8 pm1_cnt_len;
617 u8 pm2_cnt_len;
618 u8 pm_tmr_len;
619 u8 gpe0_blk_len;
620 u8 gpe1_blk_len;
621 u8 gpe1_base;
622 u8 cst_cnt;
623 u16 p_lvl2_lat;
624 u16 p_lvl3_lat;
625 u16 flush_size;
626 u16 flush_stride;
627 u8 duty_offset;
628 u8 duty_width;
629 u8 day_alrm;
630 u8 mon_alrm;
631 u8 century;
632 u16 iapc_boot_arch;
633 u8 res2;
634 u32 flags;
635 acpi_addr_t reset_reg;
636 u8 reset_value;
637 u16 ARM_boot_arch; /* Revision 6 only, Revision 5: Must be zero */
638 u8 FADT_MinorVersion; /* Revision 6 only, Revision 5: Must be zero */
639 u32 x_firmware_ctl_l;
640 u32 x_firmware_ctl_h;
641 u32 x_dsdt_l;
642 u32 x_dsdt_h;
643 acpi_addr_t x_pm1a_evt_blk;
644 acpi_addr_t x_pm1b_evt_blk;
645 acpi_addr_t x_pm1a_cnt_blk;
646 acpi_addr_t x_pm1b_cnt_blk;
647 acpi_addr_t x_pm2_cnt_blk;
648 acpi_addr_t x_pm_tmr_blk;
649 acpi_addr_t x_gpe0_blk;
650 acpi_addr_t x_gpe1_blk;
651 /* Revision 5 */
652 acpi_addr_t sleep_control_reg;
653 acpi_addr_t sleep_status_reg;
654 /* Revision 6 */
655 u64 hypervisor_vendor_identity;
656} __packed acpi_fadt_t;
657
658/* FADT TABLE Revision values */
659#define ACPI_FADT_REV_ACPI_1_0 1
660#define ACPI_FADT_REV_ACPI_2_0 3
661#define ACPI_FADT_REV_ACPI_3_0 4
662#define ACPI_FADT_REV_ACPI_4_0 4
663#define ACPI_FADT_REV_ACPI_5_0 5
664#define ACPI_FADT_REV_ACPI_6_0 6
665
666/* Flags for p_lvl2_lat and p_lvl3_lat */
667#define ACPI_FADT_C2_NOT_SUPPORTED 101
668#define ACPI_FADT_C3_NOT_SUPPORTED 1001
669
670/* FADT Feature Flags */
671#define ACPI_FADT_WBINVD (1 << 0)
672#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
673#define ACPI_FADT_C1_SUPPORTED (1 << 2)
674#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
675#define ACPI_FADT_POWER_BUTTON (1 << 4)
676#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
677#define ACPI_FADT_FIXED_RTC (1 << 6)
678#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
679#define ACPI_FADT_32BIT_TIMER (1 << 8)
680#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
681#define ACPI_FADT_RESET_REGISTER (1 << 10)
682#define ACPI_FADT_SEALED_CASE (1 << 11)
683#define ACPI_FADT_HEADLESS (1 << 12)
684#define ACPI_FADT_SLEEP_TYPE (1 << 13)
685#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
686#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
687#define ACPI_FADT_S4_RTC_VALID (1 << 16)
688#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
689#define ACPI_FADT_APIC_CLUSTER (1 << 18)
690#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
691/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
692#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
693#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
694/* bits 22-31: reserved since ACPI 5.0 */
695
696/* FADT Boot Architecture Flags */
697#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
698#define ACPI_FADT_8042 (1 << 1)
699#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
700#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
701#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
702#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
703#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
704
705/* FADT ARM Boot Architecture Flags */
706#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
707#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
708/* bits 2-16: reserved since ACPI 5.1 */
709
710/* FADT Preferred Power Management Profile */
711enum acpi_preferred_pm_profiles {
712 PM_UNSPECIFIED = 0,
713 PM_DESKTOP = 1,
714 PM_MOBILE = 2,
715 PM_WORKSTATION = 3,
716 PM_ENTERPRISE_SERVER = 4,
717 PM_SOHO_SERVER = 5,
718 PM_APPLIANCE_PC = 6,
719 PM_PERFORMANCE_SERVER = 7,
720 PM_TABLET = 8, /* ACPI 5.0 & greater */
721};
722
723/* FACS (Firmware ACPI Control Structure) */
724typedef struct acpi_facs {
725 char signature[4]; /* "FACS" */
726 u32 length; /* Length in bytes (>= 64) */
727 u32 hardware_signature; /* Hardware signature */
728 u32 firmware_waking_vector; /* Firmware waking vector */
729 u32 global_lock; /* Global lock */
730 u32 flags; /* FACS flags */
731 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
732 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
733 u8 version; /* FACS version */
734 u8 resv1[3]; /* This value is 0 */
735 u32 ospm_flags; /* 64BIT_WAKE_F */
736 u8 resv2[24]; /* This value is 0 */
737} __packed acpi_facs_t;
738
739/* FACS flags */
740#define ACPI_FACS_S4BIOS_F (1 << 0)
741#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
742/* Bits 31..2: reserved */
743
744/* ECDT (Embedded Controller Boot Resources Table) */
745typedef struct acpi_ecdt {
746 acpi_header_t header;
747 acpi_addr_t ec_control; /* EC control register */
748 acpi_addr_t ec_data; /* EC data register */
749 u32 uid; /* UID */
750 u8 gpe_bit; /* GPE bit */
751 u8 ec_id[]; /* EC ID */
752} __packed acpi_ecdt_t;
753
754/* HEST (Hardware Error Source Table) */
755typedef struct acpi_hest {
756 acpi_header_t header;
757 u32 error_source_count;
758 /* error_source_struct(s) */
759} __packed acpi_hest_t;
760
761/* Error Source Descriptors */
762typedef struct acpi_hest_esd {
763 u16 type;
764 u16 source_id;
765 u16 resv;
766 u8 flags;
767 u8 enabled;
768 u32 prealloc_erecords; /* The number of error records to
769 * pre-allocate for this error source.
770 */
771 u32 max_section_per_record;
772} __packed acpi_hest_esd_t;
773
774/* Hardware Error Notification */
775typedef struct acpi_hest_hen {
776 u8 type;
777 u8 length;
778 u16 conf_we; /* Configuration Write Enable */
779 u32 poll_interval;
780 u32 vector;
781 u32 sw2poll_threshold_val;
782 u32 sw2poll_threshold_win;
783 u32 error_threshold_val;
784 u32 error_threshold_win;
785} __packed acpi_hest_hen_t;
786
787/* BERT (Boot Error Record Table) */
788typedef struct acpi_bert {
789 acpi_header_t header;
790 u32 region_length;
791 u64 error_region;
792} __packed acpi_bert_t;
793
794/* Generic Error Data Entry */
795typedef struct acpi_hest_generic_data {
796 guid_t section_type;
797 u32 error_severity;
798 u16 revision;
799 u8 validation_bits;
800 u8 flags;
801 u32 data_length;
802 guid_t fru_id;
803 u8 fru_text[20];
804 /* error data */
805} __packed acpi_hest_generic_data_t;
806
807/* Generic Error Data Entry v300 */
808typedef struct acpi_hest_generic_data_v300 {
809 guid_t section_type;
810 u32 error_severity;
811 u16 revision;
812 u8 validation_bits;
813 u8 flags; /* see CPER Section Descriptor, Flags field */
814 u32 data_length;
815 guid_t fru_id;
816 u8 fru_text[20];
817 cper_timestamp_t timestamp;
818 /* error data */
819} __packed acpi_hest_generic_data_v300_t;
820#define HEST_GENERIC_ENTRY_V300 0x300
821
822/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
823#define ACPI_GENERROR_SEV_RECOVERABLE 0
824#define ACPI_GENERROR_SEV_FATAL 1
825#define ACPI_GENERROR_SEV_CORRECTED 2
826#define ACPI_GENERROR_SEV_NONE 3
827
828/* Generic Error Data Entry, Validation Bits field */
829#define ACPI_GENERROR_VALID_FRUID BIT(0)
830#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
831#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
832
833/* Generic Error Status Block */
834typedef struct acpi_generic_error_status {
835 u32 block_status;
836 u32 raw_data_offset; /* must follow any generic entries */
837 u32 raw_data_length;
838 u32 data_length; /* generic data */
839 u32 error_severity;
840 /* Generic Error Data structures, zero or more entries */
841} __packed acpi_generic_error_status_t;
842
843/* Generic Status Block, Block Status values */
844#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
845#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
846#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
847#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
848#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
849#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
850#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
851 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
852 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
853
854typedef struct acpi_cstate {
855 u8 ctype;
856 u16 latency;
857 u32 power;
858 acpi_addr_t resource;
859} __packed acpi_cstate_t;
860
Jason Gleneskca36aed2020-09-15 21:01:57 -0700861struct acpi_sw_pstate {
862 u32 core_freq;
863 u32 power;
864 u32 transition_latency;
865 u32 bus_master_latency;
866 u32 control_value;
867 u32 status_value;
868} __packed;
869
870struct acpi_xpss_sw_pstate {
871 u64 core_freq;
872 u64 power;
873 u64 transition_latency;
874 u64 bus_master_latency;
875 u64 control_value;
876 u64 status_value;
877 u64 control_mask;
878 u64 status_mask;
879} __packed;
880
Furquan Shaikhe0844632020-05-02 10:23:37 -0700881typedef struct acpi_tstate {
882 u32 percent;
883 u32 power;
884 u32 latency;
885 u32 control;
886 u32 status;
887} __packed acpi_tstate_t;
888
889/* Port types for ACPI _UPC object */
890enum acpi_upc_type {
891 UPC_TYPE_A,
892 UPC_TYPE_MINI_AB,
893 UPC_TYPE_EXPRESSCARD,
894 UPC_TYPE_USB3_A,
895 UPC_TYPE_USB3_B,
896 UPC_TYPE_USB3_MICRO_B,
897 UPC_TYPE_USB3_MICRO_AB,
898 UPC_TYPE_USB3_POWER_B,
899 UPC_TYPE_C_USB2_ONLY,
900 UPC_TYPE_C_USB2_SS_SWITCH,
901 UPC_TYPE_C_USB2_SS,
902 UPC_TYPE_PROPRIETARY = 0xff,
903 /*
904 * The following types are not directly defined in the ACPI
905 * spec but are used by coreboot to identify a USB device type.
906 */
907 UPC_TYPE_INTERNAL = 0xff,
908 UPC_TYPE_UNUSED,
909 UPC_TYPE_HUB
910};
911
912enum acpi_ipmi_interface_type {
913 IPMI_INTERFACE_RESERVED = 0,
914 IPMI_INTERFACE_KCS,
915 IPMI_INTERFACE_SMIC,
916 IPMI_INTERFACE_BT,
917 IPMI_INTERFACE_SSIF,
918};
919
920#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
921#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
922#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
923
924/* ACPI IPMI 2.0 */
925struct acpi_spmi {
926 acpi_header_t header;
927 u8 interface_type;
928 u8 reserved;
929 u16 specification_revision;
930 u8 interrupt_type;
931 u8 gpe;
932 u8 reserved2;
933 u8 pci_device_flag;
934
935 u32 global_system_interrupt;
936 acpi_addr_t base_address;
937 union {
938 struct {
939 u8 pci_segment_group;
940 u8 pci_bus;
941 u8 pci_device;
942 u8 pci_function;
943 };
944 u8 uid[4];
945 };
946 u8 reserved3;
947} __packed;
948
949unsigned long fw_cfg_acpi_tables(unsigned long start);
950
951/* These are implemented by the target port or north/southbridge. */
952unsigned long write_acpi_tables(unsigned long addr);
953unsigned long acpi_fill_madt(unsigned long current);
954unsigned long acpi_fill_mcfg(unsigned long current);
955unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current);
956void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id);
957void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length);
958void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +0300959
Furquan Shaikhe0844632020-05-02 10:23:37 -0700960void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +0200961void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +0300962void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +0300963void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700964
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +0300965void acpi_fill_gnvs(void);
966
Furquan Shaikhe0844632020-05-02 10:23:37 -0700967void update_ssdt(void *ssdt);
968void update_ssdtx(void *ssdtx, int i);
969
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100970unsigned long acpi_fill_lpit(unsigned long current);
971
Furquan Shaikhe0844632020-05-02 10:23:37 -0700972/* These can be used by the target port. */
973u8 acpi_checksum(u8 *table, u32 length);
974
975void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
976
977int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
978int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
979 u32 gsi_base);
980int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
981 u8 bus, u8 source, u32 gsirq, u16 flags);
982int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
983 u16 flags, u8 lint);
984void acpi_create_madt(acpi_madt_t *madt);
985unsigned long acpi_create_madt_lapics(unsigned long current);
986unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
987 u8 lint);
988int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic);
989int acpi_create_madt_lx2apic_nmi(acpi_madt_lx2apic_nmi_t *lapic_nmi, u32 cpu,
990 u16 flags, u8 lint);
991int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
992int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
993 u32 flags);
994int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
995 u16 seg_nr, u8 start, u8 end);
996unsigned long acpi_create_srat_lapics(unsigned long current);
997void acpi_create_srat(acpi_srat_t *srat,
998 unsigned long (*acpi_fill_srat)(unsigned long current));
999
1000void acpi_create_slit(acpi_slit_t *slit,
1001 unsigned long (*acpi_fill_slit)(unsigned long current));
1002
1003void acpi_create_vfct(const struct device *device,
1004 acpi_vfct_t *vfct,
1005 unsigned long (*acpi_fill_vfct)(const struct device *device,
1006 acpi_vfct_t *vfct_struct,
1007 unsigned long current));
1008
1009void acpi_create_ipmi(const struct device *device,
1010 struct acpi_spmi *spmi,
1011 const u16 ipmi_revision,
1012 const acpi_addr_t *addr,
1013 const enum acpi_ipmi_interface_type type,
1014 const s8 gpe_interrupt,
1015 const u32 apic_interrupt,
1016 const u32 uid);
1017
1018void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1019 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1020 unsigned long current));
1021
Jason Glenesk61624b22020-11-02 20:06:23 -08001022void acpi_create_crat(struct acpi_crat_header *crat,
1023 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1024 unsigned long current));
1025
Furquan Shaikhe0844632020-05-02 10:23:37 -07001026void acpi_create_hpet(acpi_hpet_t *hpet);
1027unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1028 acpi_rsdp_t *rsdp);
1029
1030/* cpu/intel/speedstep/acpi.c */
1031void generate_cpu_entries(const struct device *device);
1032
1033void acpi_create_mcfg(acpi_mcfg_t *mcfg);
1034
1035void acpi_create_facs(acpi_facs_t *facs);
1036
1037void acpi_create_dbg2(acpi_dbg2_header_t *dbg2_header,
1038 int port_type, int port_subtype,
1039 acpi_addr_t *address, uint32_t address_size,
1040 const char *device_path);
1041
1042unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
1043 const struct device *dev, uint8_t access_size);
1044void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1045 unsigned long (*acpi_fill_dmar)(unsigned long));
1046unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1047 u16 segment, u64 bar);
1048unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1049 u64 bar, u64 limit);
1050unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1051 u16 segment);
1052unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1053 u32 proximity_domain);
1054unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1055 const char *device_name);
1056void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1057void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1058void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
1059unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1060 u8 bus, u8 dev, u8 fn);
1061unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1062 u8 bus, u8 dev, u8 fn);
1063unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1064 u8 enumeration_id,
1065 u8 bus, u8 dev, u8 fn);
1066unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1067 u8 enumeration_id,
1068 u8 bus, u8 dev, u8 fn);
1069void acpi_write_hest(acpi_hest_t *hest,
1070 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1071
1072unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1073 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1074
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001075void acpi_create_lpit(acpi_lpit_t *lpit);
1076unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1077
Francois Toguo522e0db2021-01-21 09:55:19 -08001078/* For crashlog. */
1079bool acpi_is_boot_error_src_present(void);
1080void acpi_soc_fill_bert(acpi_bert_t *bert, void **region, size_t *length);
1081
Furquan Shaikhe0844632020-05-02 10:23:37 -07001082/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001083void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001084void mainboard_suspend_resume(void);
1085void *acpi_find_wakeup_vector(void);
1086
1087/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1088enum {
1089 ACPI_S0 = 0,
1090 ACPI_S1 = 1,
1091 ACPI_S2 = 2,
1092 ACPI_S3 = 3,
1093 ACPI_S4 = 4,
1094 ACPI_S5 = 5,
1095};
1096
1097#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1098 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1099/* Given the provided PM1 control register return the ACPI sleep type. */
1100static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1101{
1102 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1103 case SLP_TYP_S0: return ACPI_S0;
1104 case SLP_TYP_S1: return ACPI_S1;
1105 case SLP_TYP_S3: return ACPI_S3;
1106 case SLP_TYP_S4: return ACPI_S4;
1107 case SLP_TYP_S5: return ACPI_S5;
1108 }
1109 return -1;
1110}
1111#endif
1112
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001113uint8_t acpi_get_preferred_pm_profile(void);
1114
Furquan Shaikhe0844632020-05-02 10:23:37 -07001115/* Returns ACPI_Sx values. */
1116int acpi_get_sleep_type(void);
1117
1118/* Read and clear GPE status */
1119int acpi_get_gpe(int gpe);
1120
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001121/* Once we enter payload, is SMI handler installed and capable of
1122 responding to APM_CNT Advanced Power Management Control commands. */
1123static inline int permanent_smi_handler(void)
1124{
1125 return CONFIG(HAVE_SMI_HANDLER);
1126}
1127
Furquan Shaikhe0844632020-05-02 10:23:37 -07001128static inline int acpi_s3_resume_allowed(void)
1129{
1130 return CONFIG(HAVE_ACPI_RESUME);
1131}
1132
Furquan Shaikhe0844632020-05-02 10:23:37 -07001133static inline int acpi_is_wakeup_s3(void)
1134{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001135 if (!acpi_s3_resume_allowed())
1136 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001137
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001138 if (ENV_ROMSTAGE_OR_BEFORE)
1139 return (acpi_get_sleep_type() == ACPI_S3);
1140
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001141 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001142}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001143
1144static inline uintptr_t acpi_align_current(uintptr_t current)
1145{
1146 return ALIGN_UP(current, 16);
1147}
1148
1149/* ACPI table revisions should match the revision of the ACPI spec
1150 * supported. This function keeps the table versions synced. This could
1151 * be made into a weak function if there is ever a need to override the
1152 * coreboot default ACPI spec version supported. */
1153int get_acpi_table_revision(enum acpi_tables table);
1154
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001155#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001156
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001157#endif /* __ACPI_ACPI_H__ */