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