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