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