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