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