blob: 151cdd0aab7475ab39f6db457390a725258f8c08 [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
34#define ACPI_TABLE_CREATOR "COREBOOT" /* Must be exactly 8 bytes long! */
35#define OEM_ID "COREv4" /* Must be exactly 6 bytes long! */
Elyes HAOUAS288426d2020-10-01 16:52:26 +020036#define ACPI_DSDT_REV_1 0x01 /* DSDT revision: ACPI v1 */
Elyes HAOUAS7f53ec62020-10-05 16:33:52 +020037#define ACPI_DSDT_REV_2 0x02 /* DSDT revision: ACPI v2.0 and greater */
Furquan Shaikhe0844632020-05-02 10:23:37 -070038
39#if !defined(__ASSEMBLER__) && !defined(__ACPI__)
40#include <commonlib/helpers.h>
41#include <device/device.h>
42#include <uuid.h>
43#include <cper.h>
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +020044#include <romstage_handoff.h>
Furquan Shaikhe0844632020-05-02 10:23:37 -070045#include <types.h>
46
Tim Wawrzynczak05a6d5c2021-11-24 09:54:59 -070047enum acpi_device_sleep_states {
48 ACPI_DEVICE_SLEEP_D0 = 0,
49 ACPI_DEVICE_SLEEP_D1 = 1,
50 ACPI_DEVICE_SLEEP_D2 = 2,
51 ACPI_DEVICE_SLEEP_D3 = 3,
52 ACPI_DEVICE_SLEEP_D3_HOT = ACPI_DEVICE_SLEEP_D3,
53 ACPI_DEVICE_SLEEP_D3_COLD = 4,
Eran Mitrani4c9440c2022-11-29 17:46:38 -080054 ACPI_DEVICE_SLEEP_NONE = 5,
Tim Wawrzynczak05a6d5c2021-11-24 09:54:59 -070055};
56
Furquan Shaikhe0844632020-05-02 10:23:37 -070057#define RSDP_SIG "RSD PTR " /* RSDT pointer signature */
58#define ASLC "CORE" /* Must be exactly 4 bytes long! */
59
Raul E Rangel1c0b9f22020-07-09 11:58:38 -060060#define ACPI_NAME_BUFFER_SIZE 5 /* 4 chars + 1 NUL */
61
Furquan Shaikhe0844632020-05-02 10:23:37 -070062/*
63 * The assigned ACPI ID for the coreboot project is 'BOOT'
64 * http://www.uefi.org/acpi_id_list
65 */
66#define COREBOOT_ACPI_ID "BOOT" /* ACPI ID for coreboot HIDs */
67
68/* List of ACPI HID that use the coreboot ACPI ID */
69enum coreboot_acpi_ids {
70 COREBOOT_ACPI_ID_CBTABLE = 0x0000, /* BOOT0000 */
CoolStarc7b27b32023-07-10 18:03:40 -070071 COREBOOT_ACPI_ID_IGD_GMBUS_ARB = 0x0001, /* BOOT0001 */
72 COREBOOT_ACPI_ID_IGD_GMBUS_LINK = 0x0002, /* BOOT0002 */
Furquan Shaikhe0844632020-05-02 10:23:37 -070073 COREBOOT_ACPI_ID_MAX = 0xFFFF, /* BOOTFFFF */
74};
75
76enum acpi_tables {
77 /* Tables defined by ACPI and used by coreboot */
Jonathan Zhang3dcafa82022-05-11 13:11:20 -070078 BERT, CEDT, DBG2, DMAR, DSDT, EINJ, FACS, FADT, HEST, HMAT, HPET, IVRS,
79 MADT, MCFG, RSDP, RSDT, SLIT, SRAT, SSDT, TCPA, TPM2, XSDT, ECDT, LPIT,
Arthur Heymans2e3cb632023-06-30 15:01:08 +020080 SPCR, GTDT,
Furquan Shaikhe0844632020-05-02 10:23:37 -070081 /* Additional proprietary tables used by coreboot */
Jason Glenesk61624b22020-11-02 20:06:23 -080082 VFCT, NHLT, SPMI, CRAT
Furquan Shaikhe0844632020-05-02 10:23:37 -070083};
84
85/* RSDP (Root System Description Pointer) */
86typedef struct acpi_rsdp {
87 char signature[8]; /* RSDP signature */
88 u8 checksum; /* Checksum of the first 20 bytes */
89 char oem_id[6]; /* OEM ID */
90 u8 revision; /* RSDP revision */
91 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
92 u32 length; /* Total RSDP length (incl. extended part) */
93 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
94 u8 ext_checksum; /* Checksum of the whole table */
95 u8 reserved[3];
96} __packed acpi_rsdp_t;
97
98/* GAS (Generic Address Structure) */
99typedef struct acpi_gen_regaddr {
100 u8 space_id; /* Address space ID */
101 u8 bit_width; /* Register size in bits */
102 u8 bit_offset; /* Register bit offset */
103 u8 access_size; /* Access size since ACPI 2.0c */
104 u32 addrl; /* Register address, low 32 bits */
105 u32 addrh; /* Register address, high 32 bits */
106} __packed acpi_addr_t;
107
Elyes HAOUAS5f5fd852020-10-15 12:24:00 +0200108#define ACPI_ADDRESS_SPACE_MEMORY 0 /* System memory */
109#define ACPI_ADDRESS_SPACE_IO 1 /* System I/O */
110#define ACPI_ADDRESS_SPACE_PCI 2 /* PCI config space */
111#define ACPI_ADDRESS_SPACE_EC 3 /* Embedded controller */
112#define ACPI_ADDRESS_SPACE_SMBUS 4 /* SMBus */
113#define ACPI_ADDRESS_SPACE_CMOS 5 /* SystemCMOS */
114#define ACPI_ADDRESS_SPACE_PCI_BAR_TARGET 6 /* PciBarTarget */
115#define ACPI_ADDRESS_SPACE_IPMI 7 /* IPMI */
116#define ACPI_ADDRESS_SPACE_GENERAL_PURPOSE_IO 8 /* GeneralPurposeIO */
117#define ACPI_ADDRESS_SPACE_GENERIC_SERIAL_BUS 9 /* GenericSerialBus */
118#define ACPI_ADDRESS_SPACE_PCC 0x0A /* Platform Comm. Channel */
119#define ACPI_ADDRESS_SPACE_FIXED 0x7f /* Functional fixed hardware */
120#define ACPI_FFIXEDHW_VENDOR_INTEL 1 /* Intel */
121#define ACPI_FFIXEDHW_CLASS_HLT 0 /* C1 Halt */
122#define ACPI_FFIXEDHW_CLASS_IO_HLT 1 /* C1 I/O then Halt */
123#define ACPI_FFIXEDHW_CLASS_MWAIT 2 /* MWAIT Native C-state */
124#define ACPI_FFIXEDHW_FLAG_HW_COORD 1 /* Hardware Coordination bit */
125#define ACPI_FFIXEDHW_FLAG_BM_STS 2 /* BM_STS avoidance bit */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700126/* 0x80-0xbf: Reserved */
127/* 0xc0-0xff: OEM defined */
128
129/* Access size definitions for Generic address structure */
130#define ACPI_ACCESS_SIZE_UNDEFINED 0 /* Undefined (legacy reasons) */
131#define ACPI_ACCESS_SIZE_BYTE_ACCESS 1
132#define ACPI_ACCESS_SIZE_WORD_ACCESS 2
133#define ACPI_ACCESS_SIZE_DWORD_ACCESS 3
134#define ACPI_ACCESS_SIZE_QWORD_ACCESS 4
135
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200136/* Macros for common resource types */
137#define ACPI_REG_MSR(address, offset, width) \
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200138 (acpi_addr_t){ \
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200139 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
140 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
141 .addrl = address, \
142 .bit_offset = offset, \
143 .bit_width = width, \
144 }
145
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200146#define ACPI_REG_UNSUPPORTED (acpi_addr_t){0}
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200147
Furquan Shaikhe0844632020-05-02 10:23:37 -0700148/* Common ACPI HIDs */
149#define ACPI_HID_FDC "PNP0700"
150#define ACPI_HID_KEYBOARD "PNP0303"
151#define ACPI_HID_MOUSE "PNP0F03"
152#define ACPI_HID_COM "PNP0501"
153#define ACPI_HID_LPT "PNP0400"
154#define ACPI_HID_PNP "PNP0C02"
155#define ACPI_HID_CONTAINER "PNP0A05"
156
157/* Generic ACPI header, provided by (almost) all tables */
158typedef struct acpi_table_header {
159 char signature[4]; /* ACPI signature (4 ASCII characters) */
160 u32 length; /* Table length in bytes (incl. header) */
161 u8 revision; /* Table version (not ACPI version!) */
162 u8 checksum; /* To make sum of entire table == 0 */
163 char oem_id[6]; /* OEM identification */
164 char oem_table_id[8]; /* OEM table identification */
165 u32 oem_revision; /* OEM revision number */
166 char asl_compiler_id[4]; /* ASL compiler vendor ID */
167 u32 asl_compiler_revision; /* ASL compiler revision number */
168} __packed acpi_header_t;
169
170/* A maximum number of 32 ACPI tables ought to be enough for now. */
171#define MAX_ACPI_TABLES 32
172
173/* RSDT (Root System Description Table) */
174typedef struct acpi_rsdt {
175 acpi_header_t header;
176 u32 entry[MAX_ACPI_TABLES];
177} __packed acpi_rsdt_t;
178
179/* XSDT (Extended System Description Table) */
180typedef struct acpi_xsdt {
181 acpi_header_t header;
182 u64 entry[MAX_ACPI_TABLES];
183} __packed acpi_xsdt_t;
184
185/* HPET timers */
186typedef struct acpi_hpet {
187 acpi_header_t header;
188 u32 id;
189 acpi_addr_t addr;
190 u8 number;
191 u16 min_tick;
192 u8 attributes;
193} __packed acpi_hpet_t;
194
195/* MCFG (PCI Express MMIO config space BAR description table) */
196typedef struct acpi_mcfg {
197 acpi_header_t header;
198 u8 reserved[8];
199} __packed acpi_mcfg_t;
200
201typedef struct acpi_tcpa {
202 acpi_header_t header;
203 u16 platform_class;
204 u32 laml;
205 u64 lasa;
206} __packed acpi_tcpa_t;
207
208typedef struct acpi_tpm2 {
209 acpi_header_t header;
210 u16 platform_class;
211 u8 reserved[2];
212 u64 control_area;
213 u32 start_method;
214 u8 msp[12];
215 u32 laml;
216 u64 lasa;
217} __packed acpi_tpm2_t;
218
219typedef struct acpi_mcfg_mmconfig {
220 u32 base_address;
221 u32 base_reserved;
222 u16 pci_segment_group_number;
223 u8 start_bus_number;
224 u8 end_bus_number;
225 u8 reserved[4];
226} __packed acpi_mcfg_mmconfig_t;
227
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700228/*
Jonathan Zhang3dcafa82022-05-11 13:11:20 -0700229 * CEDT (CXL Early Discovery Table)
230 * CXL spec 2.0 section 9.14.1
231 */
232typedef struct acpi_cedt {
233 acpi_header_t header;
234 /* Followed by CEDT structures[n] */
235} __packed acpi_cedt_t;
236
237#define ACPI_CEDT_STRUCTURE_CHBS 0
238#define ACPI_CEDT_STRUCTURE_CFMWS 1
239
240#define ACPI_CEDT_CHBS_CXL_VER_1_1 0x00
241#define ACPI_CEDT_CHBS_CXL_VER_2_0 0x01
242
243/* CHBS: CXL Host Bridge Structure */
244typedef struct acpi_cedt_chbs {
245 u8 type; /* Always 0, other values reserved */
246 u8 resv1;
247 u16 length; /* Length in bytes (32) */
248 u32 uid; /* CXL Host Bridge Unique ID */
249 u32 cxl_ver;
250 u32 resv2;
251 /*
252 * For CXL 1.1, the base is Downstream Port Root Complex Resource Block;
253 * For CXL 2.0, the base is CXL Host Bridge Component Registers.
254 */
255 u64 base;
256 u64 len;
257} __packed acpi_cedt_chbs_t;
258
259#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_2_MEM (1 << 0)
260#define ACPI_CEDT_CFMWS_RESTRICTION_TYPE_3_MEM (1 << 1)
261#define ACPI_CEDT_CFMWS_RESTRICTION_VOLATIL (1 << 2)
262#define ACPI_CEDT_CFMWS_RESTRICTION_PERSISTENT (1 << 3)
263#define ACPI_CEDT_CFMWS_RESTRICTION_FIXED (1 << 4)
264
265/* CFMWS: CXL Fixed Memory Window Structure */
266typedef struct acpi_cedt_cfmws {
267 u8 type; /* Type (0) */
268 u8 resv1;
269 u16 length; /* Length in bytes (32) */
270 u32 resv2;
271 u64 base_hpa; /* Base of the HPA range, 256MB aligned */
272 u64 window_size; /* Number of bytes this window represents */
273 u8 eniw; /* Encoded Number of Interleave Ways */
274 u8 interleave_arithmetic; /* Standard Modulo arithmetic (0) */
275 u16 resv3;
276 u32 hbig; /* Host Bridge Interleave Granularity */
277 u16 restriction;
278 u16 qtg_id;
279 u32 interleave_target[]; /* Interleave Target List */
280} __packed acpi_cedt_cfmws_t;
281
282/*
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -0700283 * HMAT (Heterogeneous Memory Attribute Table)
284 * ACPI spec 6.4 section 5.2.27
285 */
286typedef struct acpi_hmat {
287 acpi_header_t header;
288 u32 resv;
289 /* Followed by HMAT table structure[n] */
290} __packed acpi_hmat_t;
291
292/* HMAT: Memory Proximity Domain Attributes structure */
293typedef struct acpi_hmat_mpda {
294 u16 type; /* Type (0) */
295 u16 resv;
296 u32 length; /* Length in bytes (40) */
297 u16 flags;
298 u16 resv1;
299 u32 proximity_domain_initiator;
300 u32 proximity_domain_memory;
301 u32 resv2;
302 u64 resv3;
303 u64 resv4;
304} __packed acpi_hmat_mpda_t;
305
306/* HMAT: System Locality Latency and Bandwidth Information structure */
307typedef struct acpi_hmat_sllbi {
308 u16 type; /* Type (1) */
309 u16 resv;
310 u32 length; /* Length in bytes */
311 u8 flags;
312 u8 data_type;
313 /*
314 * Transfer size defined as a 5-biased power of 2 exponent,
315 * when the bandwidth/latency value is achieved.
316 */
317 u8 min_transfer_size;
318 u8 resv1;
319 u32 num_initiator_domains;
320 u32 num_target_domains;
321 u32 resv2;
322 u64 entry_base_unit;
323 /* Followed by initiator proximity domain list */
324 /* Followed by target proximity domain list */
325 /* Followed by latency / bandwidth values */
326} __packed acpi_hmat_sllbi_t;
327
328/* HMAT: Memory Side Cache Information structure */
329typedef struct acpi_hmat_msci {
330 u16 type; /* Type (2) */
331 u16 resv;
332 u32 length; /* Length in bytes */
333 u32 domain; /* Proximity domain for the memory */
334 u32 resv1;
335 u64 cache_size;
336 /* Describes level, associativity, write policy, cache line size */
337 u32 cache_attributes;
338 u16 resv2;
339 /*
340 * Number of SMBIOS handlers that contribute to the
341 * memory side cache physical devices
342 */
343 u16 num_handlers;
344 /* Followed by SMBIOS handlers*/
345} __packed acpi_hmat_msci_t;
346
Furquan Shaikhe0844632020-05-02 10:23:37 -0700347/* SRAT (System Resource Affinity Table) */
348typedef struct acpi_srat {
349 acpi_header_t header;
350 u32 resv;
351 u64 resv1;
352 /* Followed by static resource allocation structure[n] */
353} __packed acpi_srat_t;
354
Jonathan Zhang3164b642021-04-21 17:51:31 -0700355#define ACPI_SRAT_STRUCTURE_LAPIC 0
356#define ACPI_SRAT_STRUCTURE_MEM 1
357#define ACPI_SRAT_STRUCTURE_GIA 5
358
Naresh Solanki76835cc2023-01-20 19:13:02 +0100359/* SRAT: Processor x2APIC Structure */
360typedef struct acpi_srat_x2apic {
361 u8 type; /* Type (0) */
362 u8 length; /* Length in bytes (16) */
363 u16 reserved; /* Reserved - Must be zero */
364 u32 proximity_domain; /* Proximity domain */
365 u32 x2apic_id; /* x2APIC ID */
366 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
367 u32 clock_domain; /* _CDM Clock Domain */
368 u32 reserved1; /* Reserved */
369} __packed acpi_srat_x2apic_t;
370
Furquan Shaikhe0844632020-05-02 10:23:37 -0700371/* SRAT: Processor Local APIC/SAPIC Affinity Structure */
372typedef struct acpi_srat_lapic {
373 u8 type; /* Type (0) */
374 u8 length; /* Length in bytes (16) */
375 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
376 u8 apic_id; /* Local APIC ID */
377 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
378 u8 local_sapic_eid; /* Local SAPIC EID */
379 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
380 u32 clock_domain; /* _CDM Clock Domain */
381} __packed acpi_srat_lapic_t;
382
383/* SRAT: Memory Affinity Structure */
384typedef struct acpi_srat_mem {
385 u8 type; /* Type (1) */
386 u8 length; /* Length in bytes (40) */
387 u32 proximity_domain; /* Proximity domain */
388 u16 resv;
389 u32 base_address_low; /* Mem range base address, low */
390 u32 base_address_high; /* Mem range base address, high */
391 u32 length_low; /* Mem range length, low */
392 u32 length_high; /* Mem range length, high */
393 u32 resv1;
394 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2,
395 * other bits reserved to 0
396 */
397 u32 resv2[2];
398} __packed acpi_srat_mem_t;
399
Jonathan Zhang3164b642021-04-21 17:51:31 -0700400/* SRAT: Generic Initiator Affinity Structure (ACPI spec 6.4 section 5.2.16.6) */
401typedef struct acpi_srat_gia {
402 u8 type; /* Type (5) */
403 u8 length; /* Length in bytes (32) */
404 u8 resv;
405 u8 dev_handle_type; /* Device handle type */
406 u32 proximity_domain; /*Proximity domain */
407 u8 dev_handle[16]; /* Device handle */
408 u32 flags;
409 u32 resv1;
410} __packed acpi_srat_gia_t;
411
412#define ACPI_SRAT_GIA_DEV_HANDLE_ACPI 0
413#define ACPI_SRAT_GIA_DEV_HANDLE_PCI 1
414
Furquan Shaikhe0844632020-05-02 10:23:37 -0700415/* SLIT (System Locality Distance Information Table) */
416typedef struct acpi_slit {
417 acpi_header_t header;
418 /* Followed by static resource allocation 8+byte[num*num] */
419} __packed acpi_slit_t;
420
421/* MADT (Multiple APIC Description Table) */
422typedef struct acpi_madt {
423 acpi_header_t header;
424 u32 lapic_addr; /* Local APIC address */
425 u32 flags; /* Multiple APIC flags */
426} __packed acpi_madt_t;
427
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100428/*
429 * LPIT (Low Power Idle Table)
430 * Conforms to "Intel Low Power S0 Idle" specification, rev 002 from July 2017.
431 */
432typedef struct acpi_lpit {
433 acpi_header_t header;
434} __packed acpi_lpit_t;
435
436/* LPIT: LPI descriptor flags */
437typedef struct acpi_lpi_flags {
438 uint32_t disabled : 1;
439 uint32_t counter_not_available : 1;
440 uint32_t reserved : 30;
441} __packed acpi_lpi_desc_flags_t;
442
443/* LPIT: LPI descriptor types */
444enum acpi_lpi_desc_type {
445 ACPI_LPI_DESC_TYPE_NATIVE_CSTATE = 0x00,
446 /* type >= 1 reserved */
447};
448
449/* LPIT: LPI descriptor header */
450typedef struct acpi_lpi_desc_hdr {
451 uint32_t type;
452 uint32_t length;
453 uint16_t uid;
454 uint16_t reserved;
455} __packed acpi_lpi_desc_hdr_t;
456
457#define ACPI_LPIT_CTR_FREQ_TSC 0
458
459/* LPIT: Native C-state instruction based LPI structure */
460typedef struct acpi_lpi_desc_ncst {
461 acpi_lpi_desc_hdr_t header;
462 acpi_lpi_desc_flags_t flags;
463 acpi_addr_t entry_trigger; /* Entry trigger C-state */
464 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
465 uint32_t max_latency; /* Worst case exit latency in microseconds */
466 acpi_addr_t residency_counter;
467 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
468} __packed acpi_lpi_desc_ncst_t;
469
Furquan Shaikhe0844632020-05-02 10:23:37 -0700470/* VFCT image header */
471typedef struct acpi_vfct_image_hdr {
472 u32 PCIBus;
473 u32 PCIDevice;
474 u32 PCIFunction;
475 u16 VendorID;
476 u16 DeviceID;
477 u16 SSVID;
478 u16 SSID;
479 u32 Revision;
480 u32 ImageLength;
481 u8 VbiosContent; // dummy - copy VBIOS here
482} __packed acpi_vfct_image_hdr_t;
483
484/* VFCT (VBIOS Fetch Table) */
485typedef struct acpi_vfct {
486 acpi_header_t header;
487 u8 TableUUID[16];
488 u32 VBIOSImageOffset;
489 u32 Lib1ImageOffset;
490 u32 Reserved[4];
491 acpi_vfct_image_hdr_t image_hdr;
492} __packed acpi_vfct_t;
493
494typedef struct acpi_ivrs_info {
495} __packed acpi_ivrs_info_t;
496
497/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
498typedef struct acpi_ivrs_ivhd {
499 uint8_t type;
500 uint8_t flags;
501 uint16_t length;
502 uint16_t device_id;
503 uint16_t capability_offset;
504 uint32_t iommu_base_low;
505 uint32_t iommu_base_high;
506 uint16_t pci_segment_group;
507 uint16_t iommu_info;
508 uint32_t iommu_feature_info;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200509 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700510} __packed acpi_ivrs_ivhd_t;
511
512/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
513typedef struct acpi_ivrs {
514 acpi_header_t header;
515 uint32_t iv_info;
516 uint32_t reserved[2];
517 struct acpi_ivrs_ivhd ivhd;
518} __packed acpi_ivrs_t;
519
Jason Glenesk61624b22020-11-02 20:06:23 -0800520/* CRAT (Component Resource Affinity Table Structure) */
521struct acpi_crat_header {
522 acpi_header_t header;
523 uint32_t total_entries;
524 uint16_t num_nodes;
525 uint8_t reserved[6];
526} __packed;
527
Furquan Shaikhe0844632020-05-02 10:23:37 -0700528/* IVHD Type 11h IOMMU Attributes */
529typedef struct ivhd11_iommu_attr {
530 uint32_t reserved1 : 13;
531 uint32_t perf_counters : 4;
532 uint32_t perf_counter_banks : 6;
533 uint32_t msi_num_ppr : 5;
534 uint32_t reserved2 : 4;
535} __packed ivhd11_iommu_attr_t;
536
537/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
538typedef struct acpi_ivrs_ivhd_11 {
539 uint8_t type;
540 uint8_t flags;
541 uint16_t length;
542 uint16_t device_id;
543 uint16_t capability_offset;
544 uint32_t iommu_base_low;
545 uint32_t iommu_base_high;
546 uint16_t pci_segment_group;
547 uint16_t iommu_info;
548 struct ivhd11_iommu_attr iommu_attributes;
549 uint32_t efr_reg_image_low;
550 uint32_t efr_reg_image_high;
551 uint32_t reserved[2];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200552 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700553} __packed acpi_ivrs_ivhd11_t;
554
555enum dev_scope_type {
556 SCOPE_PCI_ENDPOINT = 1,
557 SCOPE_PCI_SUB = 2,
558 SCOPE_IOAPIC = 3,
559 SCOPE_MSI_HPET = 4,
560 SCOPE_ACPI_NAMESPACE_DEVICE = 5
561};
562
563typedef struct dev_scope {
564 u8 type;
565 u8 length;
566 u8 reserved[2];
567 u8 enumeration;
568 u8 start_bus;
569 struct {
570 u8 dev;
571 u8 fn;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200572 } __packed path[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700573} __packed dev_scope_t;
574
575enum dmar_type {
576 DMAR_DRHD = 0,
577 DMAR_RMRR = 1,
578 DMAR_ATSR = 2,
579 DMAR_RHSA = 3,
John Zhao6edbb182021-03-24 11:55:09 -0700580 DMAR_ANDD = 4,
581 DMAR_SATC = 5
Furquan Shaikhe0844632020-05-02 10:23:37 -0700582};
583
584enum {
585 DRHD_INCLUDE_PCI_ALL = 1
586};
587
John Zhao091532d2021-04-17 16:03:21 -0700588enum {
589 ATC_REQUIRED = 1
590};
591
Furquan Shaikhe0844632020-05-02 10:23:37 -0700592enum dmar_flags {
593 DMAR_INTR_REMAP = 1 << 0,
594 DMAR_X2APIC_OPT_OUT = 1 << 1,
595 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
596};
597
598typedef struct dmar_entry {
599 u16 type;
600 u16 length;
601 u8 flags;
602 u8 reserved;
603 u16 segment;
604 u64 bar;
605} __packed dmar_entry_t;
606
607typedef struct dmar_rmrr_entry {
608 u16 type;
609 u16 length;
610 u16 reserved;
611 u16 segment;
612 u64 bar;
613 u64 limit;
614} __packed dmar_rmrr_entry_t;
615
616typedef struct dmar_atsr_entry {
617 u16 type;
618 u16 length;
619 u8 flags;
620 u8 reserved;
621 u16 segment;
622} __packed dmar_atsr_entry_t;
623
624typedef struct dmar_rhsa_entry {
625 u16 type;
626 u16 length;
627 u32 reserved;
628 u64 base_address;
629 u32 proximity_domain;
630} __packed dmar_rhsa_entry_t;
631
632typedef struct dmar_andd_entry {
633 u16 type;
634 u16 length;
635 u8 reserved[3];
636 u8 device_number;
637 u8 device_name[];
638} __packed dmar_andd_entry_t;
639
John Zhao6edbb182021-03-24 11:55:09 -0700640typedef struct dmar_satc_entry {
641 u16 type;
642 u16 length;
643 u8 flags;
644 u8 reserved;
645 u16 segment_number;
John Zhao6edbb182021-03-24 11:55:09 -0700646} __packed dmar_satc_entry_t;
647
Furquan Shaikhe0844632020-05-02 10:23:37 -0700648/* DMAR (DMA Remapping Reporting Structure) */
649typedef struct acpi_dmar {
650 acpi_header_t header;
651 u8 host_address_width;
652 u8 flags;
653 u8 reserved[10];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200654 dmar_entry_t structure[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700655} __packed acpi_dmar_t;
656
657/* MADT: APIC Structure Types */
658enum acpi_apic_types {
659 LOCAL_APIC, /* Processor local APIC */
660 IO_APIC, /* I/O APIC */
661 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
662 NMI_TYPE, /* NMI source */
663 LOCAL_APIC_NMI, /* Local APIC NMI */
664 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
665 IO_SAPIC, /* I/O SAPIC */
666 LOCAL_SAPIC, /* Local SAPIC */
667 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
668 LOCAL_X2APIC, /* Processor local x2APIC */
669 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
670 GICC, /* GIC CPU Interface */
671 GICD, /* GIC Distributor */
672 GIC_MSI_FRAME, /* GIC MSI Frame */
673 GICR, /* GIC Redistributor */
674 GIC_ITS, /* Interrupt Translation Service */
675 /* 0x10-0x7f: Reserved */
676 /* 0x80-0xff: Reserved for OEM use */
677};
678
679/* MADT: Processor Local APIC Structure */
680typedef struct acpi_madt_lapic {
681 u8 type; /* Type (0) */
682 u8 length; /* Length in bytes (8) */
683 u8 processor_id; /* ACPI processor ID */
684 u8 apic_id; /* Local APIC ID */
685 u32 flags; /* Local APIC flags */
686} __packed acpi_madt_lapic_t;
687
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300688#define ACPI_MADT_MAX_LAPIC_ID 0xfe
689
Furquan Shaikhe0844632020-05-02 10:23:37 -0700690/* MADT: Local APIC NMI Structure */
691typedef struct acpi_madt_lapic_nmi {
692 u8 type; /* Type (4) */
693 u8 length; /* Length in bytes (6) */
694 u8 processor_id; /* ACPI processor ID */
695 u16 flags; /* MPS INTI flags */
696 u8 lint; /* Local APIC LINT# */
697} __packed acpi_madt_lapic_nmi_t;
698
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200699#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
700#define ACPI_MADT_LX2APIC_NMI_ALL_PROCESSORS ((u32)-1)
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700701
Furquan Shaikhe0844632020-05-02 10:23:37 -0700702/* MADT: I/O APIC Structure */
703typedef struct acpi_madt_ioapic {
704 u8 type; /* Type (1) */
705 u8 length; /* Length in bytes (12) */
706 u8 ioapic_id; /* I/O APIC ID */
707 u8 reserved;
708 u32 ioapic_addr; /* I/O APIC address */
709 u32 gsi_base; /* Global system interrupt base */
710} __packed acpi_madt_ioapic_t;
711
Raul E Rangel169302a2022-04-25 14:59:05 -0600712#define MP_IRQ_POLARITY_DEFAULT 0x0
713#define MP_IRQ_POLARITY_HIGH 0x1
714#define MP_IRQ_POLARITY_LOW 0x3
715#define MP_IRQ_POLARITY_MASK 0x3
716#define MP_IRQ_TRIGGER_DEFAULT 0x0
717#define MP_IRQ_TRIGGER_EDGE 0x4
718#define MP_IRQ_TRIGGER_LEVEL 0xc
719#define MP_IRQ_TRIGGER_MASK 0xc
720
Furquan Shaikhe0844632020-05-02 10:23:37 -0700721/* MADT: Interrupt Source Override Structure */
722typedef struct acpi_madt_irqoverride {
723 u8 type; /* Type (2) */
724 u8 length; /* Length in bytes (10) */
725 u8 bus; /* ISA (0) */
726 u8 source; /* Bus-relative int. source (IRQ) */
727 u32 gsirq; /* Global system interrupt */
728 u16 flags; /* MPS INTI flags */
729} __packed acpi_madt_irqoverride_t;
730
731/* MADT: Processor Local x2APIC Structure */
732typedef struct acpi_madt_lx2apic {
733 u8 type; /* Type (9) */
734 u8 length; /* Length in bytes (16) */
735 u16 reserved;
736 u32 x2apic_id; /* Local x2APIC ID */
737 u32 flags; /* Same as Local APIC flags */
738 u32 processor_id; /* ACPI processor ID */
739} __packed acpi_madt_lx2apic_t;
740
741/* MADT: Processor Local x2APIC NMI Structure */
742typedef struct acpi_madt_lx2apic_nmi {
743 u8 type; /* Type (10) */
744 u8 length; /* Length in bytes (12) */
745 u16 flags; /* Same as MPS INTI flags */
746 u32 processor_id; /* ACPI processor ID */
747 u8 lint; /* Local APIC LINT# */
748 u8 reserved[3];
749} __packed acpi_madt_lx2apic_nmi_t;
750
Arthur Heymans51d94c72023-06-27 15:37:37 +0200751/* MADT: GIC CPU Interface (GICC) Structure 6.5 */
752struct gicc_flags {
753 uint32_t enabled : 1;
754 /* 0 - Level-triggered | 1 - Edge-Triggered */
755 uint32_t performance_interrupt_mode : 1;
756 uint32_t vgic_maintenance_interrupt_mode : 1;
757 uint32_t online_capable : 1;
758 uint32_t reserved : 28;
759};
760_Static_assert(sizeof(struct gicc_flags) == sizeof(uint32_t), "Wrong gicc_flags size\n");
761
762typedef struct acpi_gicc {
763 uint8_t type;
764 uint8_t length;
765 uint16_t reserved;
766 uint32_t cpu_interface_number;
767 uint32_t acpi_processor_uid;
768 struct gicc_flags flags;
769 uint32_t parking_protocol_version;
770 uint32_t performance_interrupt_gsiv;
771 uint64_t parked_address;
772 uint64_t physical_base_address; /* GIC v1/v2 or GIC v3/v4 in v2 compat mode */
773 uint64_t gicv;
774 uint64_t gich;
775 uint32_t vgic_maintenance_interrupt;
776 uint64_t gicr_base_address; /* Only GIC v3 and above */
777 uint64_t mpidr;
778 uint8_t processor_power_efficiency_class;
779 uint8_t reserved1;
780 uint16_t spe_overflow_interrupt;
781 uint16_t trbe_interrupt;
782} __packed acpi_madt_gicc_t;
783_Static_assert(sizeof(acpi_madt_gicc_t) == 82, "Wrong acpi_madt_gicc_t size\n");
784
785/* MADT: GIC Distributor (GICD) Structure */
786typedef struct acpi_gicd {
787 uint8_t type;
788 uint8_t length;
789 uint16_t reserved1;
790 uint32_t gic_id;
791 uint64_t physical_base_address;
792 uint32_t system_vector_base;
793 uint8_t gic_version;
794 uint8_t reserved2[3];
795} __packed acpi_madt_gicd_t;
796_Static_assert(sizeof(acpi_madt_gicd_t) == 24, "Wrong acpi_madt_gicd_t size\n");
797
798/* MADT: GIC MSI Frame Structure */
799struct gic_msi_flags {
800 uint32_t spi_count_select : 1;
801 uint32_t reserved : 31;
802};
803_Static_assert(sizeof(struct gic_msi_flags) == sizeof(uint32_t), "Wrong gic_msi_flags size\n");
804
805typedef struct acpi_gic_msi {
806 uint8_t type;
807 uint8_t length;
808 uint16_t reserved;
809 uint32_t gic_msi_frame_id;
810 uint64_t physical_base_address;
811 struct gic_msi_flags flags;
812 uint16_t spi_count;
813 uint16_t spi_base;
814} __packed acpi_gic_msi_t;
815_Static_assert(sizeof(acpi_gic_msi_t) == 24, "Wrong acpi_gic_msi_t size\n");
816
817/* MADT: GIC Redistributor (GICR) Structure */
818typedef struct acpi_girr {
819 uint8_t type;
820 uint8_t length;
821 uint16_t reserved;
822 uint64_t discovery_range_base_address;
823 uint32_t discovery_range_length;
824} __packed acpi_madt_gicr_t;
825_Static_assert(sizeof(acpi_madt_gicr_t) == 16, "Wrong acpi_madt_gicr_t size\n");
826
827/* MADT: GIC Interrupt Translation Service (ITS) Structure */
828typedef struct acpi_gic_its {
829 uint8_t type;
830 uint8_t length;
831 uint16_t reserved;
832 uint32_t gic_its_id;
833 uint64_t physical_base_address;
834 uint32_t reserved2;
835} __packed acpi_madt_gic_its_t;
836_Static_assert(sizeof(acpi_madt_gic_its_t) == 20, "Wrong MADT acpi_madt_gic_its_t size\n");
837
Furquan Shaikhe0844632020-05-02 10:23:37 -0700838#define ACPI_DBG2_PORT_SERIAL 0x8000
839#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
840#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
841#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
842#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
843#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
844#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
845#define ACPI_DBG2_PORT_IEEE1394 0x8001
846#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
847#define ACPI_DBG2_PORT_USB 0x8002
848#define ACPI_DBG2_PORT_USB_XHCI 0x0000
849#define ACPI_DBG2_PORT_USB_EHCI 0x0001
850#define ACPI_DBG2_PORT_NET 0x8003
851
852/* DBG2: Microsoft Debug Port Table 2 header */
853typedef struct acpi_dbg2_header {
854 acpi_header_t header;
855 uint32_t devices_offset;
856 uint32_t devices_count;
857} __attribute__((packed)) acpi_dbg2_header_t;
858
859/* DBG2: Microsoft Debug Port Table 2 device entry */
860typedef struct acpi_dbg2_device {
861 uint8_t revision;
862 uint16_t length;
863 uint8_t address_count;
864 uint16_t namespace_string_length;
865 uint16_t namespace_string_offset;
866 uint16_t oem_data_length;
867 uint16_t oem_data_offset;
868 uint16_t port_type;
869 uint16_t port_subtype;
870 uint8_t reserved[2];
871 uint16_t base_address_offset;
872 uint16_t address_size_offset;
873} __attribute__((packed)) acpi_dbg2_device_t;
874
875/* FADT (Fixed ACPI Description Table) */
876typedef struct acpi_fadt {
877 acpi_header_t header;
878 u32 firmware_ctrl;
879 u32 dsdt;
880 u8 reserved; /* Should be 0 */
881 u8 preferred_pm_profile;
882 u16 sci_int;
883 u32 smi_cmd;
884 u8 acpi_enable;
885 u8 acpi_disable;
886 u8 s4bios_req;
887 u8 pstate_cnt;
888 u32 pm1a_evt_blk;
889 u32 pm1b_evt_blk;
890 u32 pm1a_cnt_blk;
891 u32 pm1b_cnt_blk;
892 u32 pm2_cnt_blk;
893 u32 pm_tmr_blk;
894 u32 gpe0_blk;
895 u32 gpe1_blk;
896 u8 pm1_evt_len;
897 u8 pm1_cnt_len;
898 u8 pm2_cnt_len;
899 u8 pm_tmr_len;
900 u8 gpe0_blk_len;
901 u8 gpe1_blk_len;
902 u8 gpe1_base;
903 u8 cst_cnt;
904 u16 p_lvl2_lat;
905 u16 p_lvl3_lat;
906 u16 flush_size;
907 u16 flush_stride;
908 u8 duty_offset;
909 u8 duty_width;
910 u8 day_alrm;
911 u8 mon_alrm;
912 u8 century;
913 u16 iapc_boot_arch;
914 u8 res2;
915 u32 flags;
916 acpi_addr_t reset_reg;
917 u8 reset_value;
Elyes Haouasb55ac092022-02-16 14:42:19 +0100918 u16 ARM_boot_arch; /* Must be zero if ACPI Revision <= 5.0 */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100919 u8 FADT_MinorVersion; /* Must be zero if ACPI Revision <= 5.0 */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700920 u32 x_firmware_ctl_l;
921 u32 x_firmware_ctl_h;
922 u32 x_dsdt_l;
923 u32 x_dsdt_h;
924 acpi_addr_t x_pm1a_evt_blk;
925 acpi_addr_t x_pm1b_evt_blk;
926 acpi_addr_t x_pm1a_cnt_blk;
927 acpi_addr_t x_pm1b_cnt_blk;
928 acpi_addr_t x_pm2_cnt_blk;
929 acpi_addr_t x_pm_tmr_blk;
930 acpi_addr_t x_gpe0_blk;
931 acpi_addr_t x_gpe1_blk;
932 /* Revision 5 */
933 acpi_addr_t sleep_control_reg;
934 acpi_addr_t sleep_status_reg;
935 /* Revision 6 */
936 u64 hypervisor_vendor_identity;
937} __packed acpi_fadt_t;
938
939/* FADT TABLE Revision values */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100940#define ACPI_FADT_REV_ACPI_1 1
941#define ACPI_FADT_REV_ACPI_2 3
942#define ACPI_FADT_REV_ACPI_3 4
943#define ACPI_FADT_REV_ACPI_4 4
944#define ACPI_FADT_REV_ACPI_5 5
945#define ACPI_FADT_REV_ACPI_6 6
946
947/* FADT Minor Version value:
948 * Bits 0-3: minor version
949 * Bits 4-7: Errata
950 * value of 1 means this is compatible with Errata A,
951 * value of 2 would be compatible with Errata B, and so on
952 * Version 6.3 Errata A would be: (1 << 4) | 3
953 */
954#define ACPI_FADT_MINOR_VERSION_0 0 /* coreboot currently use this version */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700955
956/* Flags for p_lvl2_lat and p_lvl3_lat */
957#define ACPI_FADT_C2_NOT_SUPPORTED 101
958#define ACPI_FADT_C3_NOT_SUPPORTED 1001
959
960/* FADT Feature Flags */
961#define ACPI_FADT_WBINVD (1 << 0)
962#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
963#define ACPI_FADT_C1_SUPPORTED (1 << 2)
964#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
965#define ACPI_FADT_POWER_BUTTON (1 << 4)
966#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
967#define ACPI_FADT_FIXED_RTC (1 << 6)
968#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
969#define ACPI_FADT_32BIT_TIMER (1 << 8)
970#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
971#define ACPI_FADT_RESET_REGISTER (1 << 10)
972#define ACPI_FADT_SEALED_CASE (1 << 11)
973#define ACPI_FADT_HEADLESS (1 << 12)
974#define ACPI_FADT_SLEEP_TYPE (1 << 13)
975#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
976#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
977#define ACPI_FADT_S4_RTC_VALID (1 << 16)
978#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
979#define ACPI_FADT_APIC_CLUSTER (1 << 18)
980#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
981/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
982#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
983#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
984/* bits 22-31: reserved since ACPI 5.0 */
985
986/* FADT Boot Architecture Flags */
987#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
988#define ACPI_FADT_8042 (1 << 1)
989#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
990#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
991#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
992#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
993#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
994
995/* FADT ARM Boot Architecture Flags */
996#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
997#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
998/* bits 2-16: reserved since ACPI 5.1 */
999
1000/* FADT Preferred Power Management Profile */
1001enum acpi_preferred_pm_profiles {
1002 PM_UNSPECIFIED = 0,
1003 PM_DESKTOP = 1,
1004 PM_MOBILE = 2,
1005 PM_WORKSTATION = 3,
1006 PM_ENTERPRISE_SERVER = 4,
1007 PM_SOHO_SERVER = 5,
1008 PM_APPLIANCE_PC = 6,
1009 PM_PERFORMANCE_SERVER = 7,
1010 PM_TABLET = 8, /* ACPI 5.0 & greater */
1011};
1012
1013/* FACS (Firmware ACPI Control Structure) */
1014typedef struct acpi_facs {
1015 char signature[4]; /* "FACS" */
1016 u32 length; /* Length in bytes (>= 64) */
1017 u32 hardware_signature; /* Hardware signature */
1018 u32 firmware_waking_vector; /* Firmware waking vector */
1019 u32 global_lock; /* Global lock */
1020 u32 flags; /* FACS flags */
1021 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
1022 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
1023 u8 version; /* FACS version */
1024 u8 resv1[3]; /* This value is 0 */
1025 u32 ospm_flags; /* 64BIT_WAKE_F */
1026 u8 resv2[24]; /* This value is 0 */
1027} __packed acpi_facs_t;
1028
1029/* FACS flags */
1030#define ACPI_FACS_S4BIOS_F (1 << 0)
1031#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
1032/* Bits 31..2: reserved */
1033
1034/* ECDT (Embedded Controller Boot Resources Table) */
1035typedef struct acpi_ecdt {
1036 acpi_header_t header;
1037 acpi_addr_t ec_control; /* EC control register */
1038 acpi_addr_t ec_data; /* EC data register */
1039 u32 uid; /* UID */
1040 u8 gpe_bit; /* GPE bit */
1041 u8 ec_id[]; /* EC ID */
1042} __packed acpi_ecdt_t;
1043
1044/* HEST (Hardware Error Source Table) */
1045typedef struct acpi_hest {
1046 acpi_header_t header;
1047 u32 error_source_count;
1048 /* error_source_struct(s) */
1049} __packed acpi_hest_t;
1050
1051/* Error Source Descriptors */
1052typedef struct acpi_hest_esd {
1053 u16 type;
1054 u16 source_id;
1055 u16 resv;
1056 u8 flags;
1057 u8 enabled;
1058 u32 prealloc_erecords; /* The number of error records to
1059 * pre-allocate for this error source.
1060 */
1061 u32 max_section_per_record;
1062} __packed acpi_hest_esd_t;
1063
1064/* Hardware Error Notification */
1065typedef struct acpi_hest_hen {
1066 u8 type;
1067 u8 length;
1068 u16 conf_we; /* Configuration Write Enable */
1069 u32 poll_interval;
1070 u32 vector;
1071 u32 sw2poll_threshold_val;
1072 u32 sw2poll_threshold_win;
1073 u32 error_threshold_val;
1074 u32 error_threshold_win;
1075} __packed acpi_hest_hen_t;
1076
1077/* BERT (Boot Error Record Table) */
1078typedef struct acpi_bert {
1079 acpi_header_t header;
1080 u32 region_length;
1081 u64 error_region;
1082} __packed acpi_bert_t;
1083
1084/* Generic Error Data Entry */
1085typedef struct acpi_hest_generic_data {
1086 guid_t section_type;
1087 u32 error_severity;
1088 u16 revision;
1089 u8 validation_bits;
1090 u8 flags;
1091 u32 data_length;
1092 guid_t fru_id;
1093 u8 fru_text[20];
1094 /* error data */
1095} __packed acpi_hest_generic_data_t;
1096
1097/* Generic Error Data Entry v300 */
1098typedef struct acpi_hest_generic_data_v300 {
1099 guid_t section_type;
1100 u32 error_severity;
1101 u16 revision;
1102 u8 validation_bits;
1103 u8 flags; /* see CPER Section Descriptor, Flags field */
1104 u32 data_length;
1105 guid_t fru_id;
1106 u8 fru_text[20];
1107 cper_timestamp_t timestamp;
1108 /* error data */
1109} __packed acpi_hest_generic_data_v300_t;
1110#define HEST_GENERIC_ENTRY_V300 0x300
1111
1112/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
1113#define ACPI_GENERROR_SEV_RECOVERABLE 0
1114#define ACPI_GENERROR_SEV_FATAL 1
1115#define ACPI_GENERROR_SEV_CORRECTED 2
1116#define ACPI_GENERROR_SEV_NONE 3
1117
1118/* Generic Error Data Entry, Validation Bits field */
1119#define ACPI_GENERROR_VALID_FRUID BIT(0)
1120#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
1121#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
1122
Felix Held403fa862021-07-26 22:43:00 +02001123/*
1124 * Generic Error Status Block
1125 *
1126 * If there is a raw data section at the end of the generic error status block after the
1127 * zero or more generic error data entries, raw_data_length indicates the length of the raw
1128 * section and raw_data_offset is the offset of the beginning of the raw data section from
1129 * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length
1130 * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t).
1131 */
Furquan Shaikhe0844632020-05-02 10:23:37 -07001132typedef struct acpi_generic_error_status {
1133 u32 block_status;
1134 u32 raw_data_offset; /* must follow any generic entries */
1135 u32 raw_data_length;
1136 u32 data_length; /* generic data */
1137 u32 error_severity;
1138 /* Generic Error Data structures, zero or more entries */
1139} __packed acpi_generic_error_status_t;
1140
1141/* Generic Status Block, Block Status values */
1142#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
1143#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
1144#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
1145#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
1146#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
1147#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
1148#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
1149 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
1150 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
1151
1152typedef struct acpi_cstate {
1153 u8 ctype;
1154 u16 latency;
1155 u32 power;
1156 acpi_addr_t resource;
1157} __packed acpi_cstate_t;
1158
Jason Gleneskca36aed2020-09-15 21:01:57 -07001159struct acpi_sw_pstate {
1160 u32 core_freq;
1161 u32 power;
1162 u32 transition_latency;
1163 u32 bus_master_latency;
1164 u32 control_value;
1165 u32 status_value;
1166} __packed;
1167
1168struct acpi_xpss_sw_pstate {
1169 u64 core_freq;
1170 u64 power;
1171 u64 transition_latency;
1172 u64 bus_master_latency;
1173 u64 control_value;
1174 u64 status_value;
1175 u64 control_mask;
1176 u64 status_mask;
1177} __packed;
1178
Furquan Shaikhe0844632020-05-02 10:23:37 -07001179typedef struct acpi_tstate {
1180 u32 percent;
1181 u32 power;
1182 u32 latency;
1183 u32 control;
1184 u32 status;
1185} __packed acpi_tstate_t;
1186
Raul E Rangelc7048322021-04-19 15:58:25 -06001187enum acpi_lpi_state_flags {
1188 ACPI_LPI_STATE_DISABLED = 0,
1189 ACPI_LPI_STATE_ENABLED
1190};
1191
1192/* Low Power Idle State */
1193struct acpi_lpi_state {
1194 u32 min_residency_us;
1195 u32 worst_case_wakeup_latency_us;
1196 u32 flags;
1197 u32 arch_context_lost_flags;
1198 u32 residency_counter_frequency_hz;
1199 u32 enabled_parent_state;
1200 acpi_addr_t entry_method;
1201 acpi_addr_t residency_counter_register;
1202 acpi_addr_t usage_counter_register;
1203 const char *state_name;
1204};
1205
Furquan Shaikhe0844632020-05-02 10:23:37 -07001206/* Port types for ACPI _UPC object */
1207enum acpi_upc_type {
1208 UPC_TYPE_A,
1209 UPC_TYPE_MINI_AB,
1210 UPC_TYPE_EXPRESSCARD,
1211 UPC_TYPE_USB3_A,
1212 UPC_TYPE_USB3_B,
1213 UPC_TYPE_USB3_MICRO_B,
1214 UPC_TYPE_USB3_MICRO_AB,
1215 UPC_TYPE_USB3_POWER_B,
1216 UPC_TYPE_C_USB2_ONLY,
1217 UPC_TYPE_C_USB2_SS_SWITCH,
1218 UPC_TYPE_C_USB2_SS,
1219 UPC_TYPE_PROPRIETARY = 0xff,
1220 /*
1221 * The following types are not directly defined in the ACPI
1222 * spec but are used by coreboot to identify a USB device type.
1223 */
1224 UPC_TYPE_INTERNAL = 0xff,
1225 UPC_TYPE_UNUSED,
1226 UPC_TYPE_HUB
1227};
1228
1229enum acpi_ipmi_interface_type {
1230 IPMI_INTERFACE_RESERVED = 0,
1231 IPMI_INTERFACE_KCS,
1232 IPMI_INTERFACE_SMIC,
1233 IPMI_INTERFACE_BT,
1234 IPMI_INTERFACE_SSIF,
1235};
1236
1237#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
1238#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
1239#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
1240
1241/* ACPI IPMI 2.0 */
1242struct acpi_spmi {
1243 acpi_header_t header;
1244 u8 interface_type;
1245 u8 reserved;
1246 u16 specification_revision;
1247 u8 interrupt_type;
1248 u8 gpe;
1249 u8 reserved2;
1250 u8 pci_device_flag;
1251
1252 u32 global_system_interrupt;
1253 acpi_addr_t base_address;
1254 union {
1255 struct {
1256 u8 pci_segment_group;
1257 u8 pci_bus;
1258 u8 pci_device;
1259 u8 pci_function;
1260 };
1261 u8 uid[4];
1262 };
1263 u8 reserved3;
1264} __packed;
1265
Rocky Phaguraeff07132021-01-10 15:42:50 -08001266/* EINJ APEI Standard Definitions */
1267/* EINJ Error Types
1268 Refer to the ACPI spec, EINJ section, for more info on bit definitions
1269*/
1270#define ACPI_EINJ_CPU_CE (1 << 0)
1271#define ACPI_EINJ_CPU_UCE (1 << 1)
1272#define ACPI_EINJ_CPU_UCE_FATAL (1 << 2)
1273#define ACPI_EINJ_MEM_CE (1 << 3)
1274#define ACPI_EINJ_MEM_UCE (1 << 4)
1275#define ACPI_EINJ_MEM_UCE_FATAL (1 << 5)
1276#define ACPI_EINJ_PCIE_CE (1 << 6)
1277#define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7)
1278#define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8)
1279#define ACPI_EINJ_PLATFORM_CE (1 << 9)
1280#define ACPI_EINJ_PLATFORM_UCE (1 << 10)
1281#define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11)
1282#define ACPI_EINJ_VENDOR_DEFINED (1 << 31)
1283#define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \
1284 ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL)
1285
1286/* EINJ actions */
1287#define ACTION_COUNT 9
1288#define BEGIN_INJECT_OP 0x00
1289#define GET_TRIGGER_ACTION_TABLE 0x01
1290#define SET_ERROR_TYPE 0x02
1291#define GET_ERROR_TYPE 0x03
1292#define END_INJECT_OP 0x04
1293#define EXECUTE_INJECT_OP 0x05
1294#define CHECK_BUSY_STATUS 0x06
1295#define GET_CMD_STATUS 0x07
1296#define SET_ERROR_TYPE_WITH_ADDRESS 0x08
1297#define TRIGGER_ERROR 0xFF
1298
1299/* EINJ Instructions */
1300#define READ_REGISTER 0x00
1301#define READ_REGISTER_VALUE 0x01
1302#define WRITE_REGISTER 0x02
1303#define WRITE_REGISTER_VALUE 0x03
1304#define NO_OP 0x04
1305
1306/* EINJ (Error Injection Table) */
1307typedef struct acpi_gen_regaddr1 {
1308 u8 space_id; /* Address space ID */
1309 u8 bit_width; /* Register size in bits */
1310 u8 bit_offset; /* Register bit offset */
1311 u8 access_size; /* Access size since ACPI 2.0c */
1312 u64 addr; /* Register address */
1313} __packed acpi_addr64_t;
1314
1315/* Instruction entry */
1316typedef struct acpi_einj_action_table {
1317 u8 action;
1318 u8 instruction;
1319 u16 flags;
1320 acpi_addr64_t reg;
1321 u64 value;
1322 u64 mask;
1323} __packed acpi_einj_action_table_t;
1324
1325typedef struct acpi_injection_header {
1326 u32 einj_header_size;
1327 u32 flags;
1328 u32 entry_count;
1329} __packed acpi_injection_header_t;
1330
1331typedef struct acpi_einj_trigger_table {
1332 u32 header_size;
1333 u32 revision;
1334 u32 table_size;
1335 u32 entry_count;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +02001336 acpi_einj_action_table_t trigger_action[];
Rocky Phaguraeff07132021-01-10 15:42:50 -08001337} __packed acpi_einj_trigger_table_t;
1338
1339typedef struct set_error_type {
1340 u32 errtype;
1341 u32 vendorerrortype;
1342 u32 flags;
1343 u32 apicid;
1344 u64 memaddr;
1345 u64 memrange;
1346 u32 pciesbdf;
1347} __packed set_error_type_t;
1348
1349#define EINJ_PARAM_NUM 6
1350typedef struct acpi_einj_smi {
1351 u64 op_state;
1352 u64 err_inject[EINJ_PARAM_NUM];
1353 u64 trigger_action_table;
1354 u64 err_inj_cap;
1355 u64 op_status;
1356 u64 cmd_sts;
1357 u64 einj_addr;
1358 u64 einj_addr_msk;
1359 set_error_type_t setaddrtable;
1360 u64 reserved[50];
1361} __packed acpi_einj_smi_t;
1362
1363/* EINJ Flags */
1364#define EINJ_DEF_TRIGGER_PORT 0xb2
1365#define FLAG_PRESERVE 0x01
1366#define FLAG_IGNORE 0x00
1367
1368/* EINJ Registers */
1369#define EINJ_REG_MEMORY(address) \
1370 { \
1371 .space_id = ACPI_ADDRESS_SPACE_MEMORY, \
1372 .bit_width = 64, \
1373 .bit_offset = 0, \
1374 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
1375 .addr = address}
1376
1377#define EINJ_REG_IO() \
1378 { \
1379 .space_id = ACPI_ADDRESS_SPACE_IO, \
1380 .bit_width = 0x10, \
1381 .bit_offset = 0, \
1382 .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \
1383 .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */
1384
1385typedef struct acpi_einj {
1386 acpi_header_t header;
1387 acpi_injection_header_t inj_header;
1388 acpi_einj_action_table_t action_table[ACTION_COUNT];
1389} __packed acpi_einj_t;
1390
Arthur Heymanse7aaf042023-06-07 12:12:45 +02001391/* SPCR (Serial Port Console Redirection Table) */
1392typedef struct acpi_spcr {
1393 acpi_header_t header;
1394 uint8_t interface_type;
1395 uint8_t reserved[3];
1396 acpi_addr_t base_address;
1397 uint8_t interrupt_type;
1398 uint8_t irq;
1399 uint32_t global_system_interrupt;
1400 uint8_t configured_baudrate;
1401 uint8_t parity;
1402 uint8_t stop_bits;
1403 uint8_t flow_control;
1404 uint8_t terminal_type;
1405 uint8_t language;
1406 uint16_t pci_did;
1407 uint16_t pci_vid;
1408 uint8_t pci_bus;
1409 uint8_t pci_dev;
1410 uint8_t pci_fun;
1411 uint32_t pci_flags;
1412 uint8_t pci_segment;
1413 uint32_t uart_clock;
1414 uint32_t precise_baud_rate;
1415 uint16_t namespace_string_length;
1416 uint16_t namespace_string_offset;
1417 char namespacestring[];
1418} __packed acpi_spcr_t;
1419_Static_assert(sizeof(acpi_spcr_t) == 88, "acpi_spcr_t must have an 88 byte size\n");
1420
Arthur Heymans90464072023-06-07 12:53:50 +02001421#define PC_AT_COMPATIBLE_INTERRUPT (1 << 0)
1422#define IO_APIC_COMPATIBLE_INTERRUPT (1 << 1)
1423#define IO_SAPIC_COMPATIBLE_INTERRUPT (1 << 2)
1424#define ARMH_GIC_COMPATIBLE_INTERRUPT (1 << 3)
1425#define RISCV_PLIC_COMPATIBLE_INTERRUPT (1 << 4)
1426
Arthur Heymans8193eab2023-06-20 10:17:23 +02001427/* GTDT - Generic Timer Description Table (ACPI 5.1) Version 2 */
1428typedef struct acpi_table_gtdt {
1429 acpi_header_t header; /* Common ACPI table header */
1430 u64 counter_block_addresss;
1431 u32 reserved;
1432 u32 secure_el1_interrupt;
1433 u32 secure_el1_flags;
1434 u32 non_secure_el1_interrupt;
1435 u32 non_secure_el1_flags;
1436 u32 virtual_timer_interrupt;
1437 u32 virtual_timer_flags;
1438 u32 non_secure_el2_interrupt;
1439 u32 non_secure_el2_flags;
1440 u64 counter_read_block_address;
1441 u32 platform_timer_count;
1442 u32 platform_timer_offset;
1443} __packed acpi_gtdt_t;
1444
1445/* Flag Definitions: Timer Block Physical Timers and Virtual timers */
1446
1447#define ACPI_GTDT_INTERRUPT_MODE (1)
1448#define ACPI_GTDT_INTERRUPT_POLARITY (1<<1)
1449#define ACPI_GTDT_ALWAYS_ON (1<<2)
1450
1451struct acpi_gtdt_el2 {
1452 u32 virtual_el2_timer_gsiv;
1453 u32 virtual_el2_timer_flags;
1454};
1455
1456/* Common GTDT subtable header */
1457
1458struct acpi_gtdt_header {
1459 u8 type;
1460 u16 length;
1461} __packed;
1462
1463/* Values for GTDT subtable type above */
1464
1465enum acpi_gtdt_type {
1466 ACPI_GTDT_TYPE_TIMER_BLOCK = 0,
1467 ACPI_GTDT_TYPE_WATCHDOG = 1,
1468 ACPI_GTDT_TYPE_RESERVED = 2 /* 2 and greater are reserved */
1469};
1470
1471/* GTDT Subtables, correspond to Type in struct acpi_gtdt_header */
1472
1473/* 0: Generic Timer Block */
1474
1475struct acpi_gtdt_timer_block {
1476 struct acpi_gtdt_header header;
1477 u8 reserved;
1478 u64 block_address;
1479 u32 timer_count;
1480 u32 timer_offset;
1481} __packed;
1482
1483/* Timer Sub-Structure, one per timer */
1484
1485struct acpi_gtdt_timer_entry {
1486 u8 frame_number;
1487 u8 reserved[3];
1488 u64 base_address;
1489 u64 el0_base_address;
1490 u32 timer_interrupt;
1491 u32 timer_flags;
1492 u32 virtual_timer_interrupt;
1493 u32 virtual_timer_flags;
1494 u32 common_flags;
1495} __packed;
1496
1497/* Flag Definitions: timer_flags and virtual_timer_flags above */
1498
1499#define ACPI_GTDT_GT_IRQ_MODE (1)
1500#define ACPI_GTDT_GT_IRQ_POLARITY (1<<1)
1501
1502/* Flag Definitions: common_flags above */
1503
1504#define ACPI_GTDT_GT_IS_SECURE_TIMER (1)
1505#define ACPI_GTDT_GT_ALWAYS_ON (1<<1)
1506
1507/* 1: SBSA Generic Watchdog Structure */
1508
1509struct acpi_gtdt_watchdog {
1510 struct acpi_gtdt_header header;
1511 u8 reserved;
1512 u64 refresh_frame_address;
1513 u64 control_frame_address;
1514 u32 timer_interrupt;
1515 u32 timer_flags;
1516} __packed;
1517
1518/* Flag Definitions: timer_flags above */
1519
1520#define ACPI_GTDT_WATCHDOG_IRQ_MODE (1)
1521#define ACPI_GTDT_WATCHDOG_IRQ_POLARITY (1<<1)
1522#define ACPI_GTDT_WATCHDOG_SECURE (1<<2)
1523
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01001524uintptr_t get_coreboot_rsdp(void);
Rocky Phaguraeff07132021-01-10 15:42:50 -08001525void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);
1526
Furquan Shaikhe0844632020-05-02 10:23:37 -07001527unsigned long fw_cfg_acpi_tables(unsigned long start);
1528
1529/* These are implemented by the target port or north/southbridge. */
Raul E Rangel6b446b92021-11-19 11:38:35 -07001530void preload_acpi_dsdt(void);
Arthur Heymans7ebebf72023-06-17 14:08:46 +02001531unsigned long write_acpi_tables(const unsigned long addr);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001532unsigned long acpi_fill_madt(unsigned long current);
Arthur Heymanscd46e5f2023-06-22 21:34:16 +02001533unsigned long acpi_arch_fill_madt(acpi_madt_t *madt, unsigned long current);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001534
Furquan Shaikhe0844632020-05-02 10:23:37 -07001535void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +02001536void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001537void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001538void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001539
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001540void acpi_fill_gnvs(void);
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02001541void acpi_fill_cnvs(void);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001542
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001543unsigned long acpi_fill_lpit(unsigned long current);
1544
Furquan Shaikhe0844632020-05-02 10:23:37 -07001545/* These can be used by the target port. */
1546u8 acpi_checksum(u8 *table, u32 length);
1547
1548void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
1549
Jonathan Zhang3dcafa82022-05-11 13:11:20 -07001550/* Create CXL Early Discovery Table */
1551void acpi_create_cedt(acpi_cedt_t *cedt,
1552 unsigned long (*acpi_fill_cedt)(unsigned long current));
1553/* Create a CXL Host Bridge Structure for CEDT */
1554int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base);
1555/* Create a CXL Fixed Memory Window Structure for CEDT */
1556int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size,
1557 u8 eniw, u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target);
1558
Arthur Heymans92a3b672023-06-22 21:30:58 +02001559
Kyösti Mälkkic7da0272021-06-08 11:37:08 +03001560int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001561
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +03001562unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 cpu, u32 apic);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001563
1564unsigned long acpi_create_madt_lapic_nmis(unsigned long current);
1565
Furquan Shaikhe0844632020-05-02 10:23:37 -07001566int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
Naresh Solanki76835cc2023-01-20 19:13:02 +01001567int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001568int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
1569 u32 flags);
Jonathan Zhang3164b642021-04-21 17:51:31 -07001570/*
1571 * Given the Generic Initiator device's BDF, the proximity domain's ID
1572 * and flag, create Generic Initiator Affinity structure in SRAT.
1573 */
1574int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
1575 u16 seg, u8 bus, u8 dev, u8 func, u32 flags);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001576unsigned long acpi_create_srat_lapics(unsigned long current);
1577void acpi_create_srat(acpi_srat_t *srat,
1578 unsigned long (*acpi_fill_srat)(unsigned long current));
1579
1580void acpi_create_slit(acpi_slit_t *slit,
1581 unsigned long (*acpi_fill_slit)(unsigned long current));
1582
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001583/*
1584 * Create a Memory Proximity Domain Attributes structure for HMAT,
1585 * given proximity domain for the attached initiaor, and
1586 * proximimity domain for the memory.
1587 */
1588int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory);
Martin Roth0949e732021-10-01 14:28:22 -06001589/* Create Heterogeneous Memory Attribute Table */
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001590void acpi_create_hmat(acpi_hmat_t *hmat,
1591 unsigned long (*acpi_fill_hmat)(unsigned long current));
1592
Furquan Shaikhe0844632020-05-02 10:23:37 -07001593void acpi_create_vfct(const struct device *device,
1594 acpi_vfct_t *vfct,
1595 unsigned long (*acpi_fill_vfct)(const struct device *device,
1596 acpi_vfct_t *vfct_struct,
1597 unsigned long current));
1598
1599void acpi_create_ipmi(const struct device *device,
1600 struct acpi_spmi *spmi,
1601 const u16 ipmi_revision,
1602 const acpi_addr_t *addr,
1603 const enum acpi_ipmi_interface_type type,
1604 const s8 gpe_interrupt,
1605 const u32 apic_interrupt,
1606 const u32 uid);
1607
1608void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1609 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1610 unsigned long current));
1611
Jason Glenesk61624b22020-11-02 20:06:23 -08001612void acpi_create_crat(struct acpi_crat_header *crat,
1613 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1614 unsigned long current));
1615
Furquan Shaikhe0844632020-05-02 10:23:37 -07001616unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1617 acpi_rsdp_t *rsdp);
1618
1619/* cpu/intel/speedstep/acpi.c */
1620void generate_cpu_entries(const struct device *device);
1621
Furquan Shaikhe0844632020-05-02 10:23:37 -07001622unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
1623 const struct device *dev, uint8_t access_size);
1624void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1625 unsigned long (*acpi_fill_dmar)(unsigned long));
1626unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1627 u16 segment, u64 bar);
1628unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1629 u64 bar, u64 limit);
1630unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1631 u16 segment);
1632unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1633 u32 proximity_domain);
1634unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1635 const char *device_name);
John Zhao6edbb182021-03-24 11:55:09 -07001636unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags,
John Zhao091532d2021-04-17 16:03:21 -07001637 u16 segment);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001638void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1639void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1640void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
John Zhao6edbb182021-03-24 11:55:09 -07001641void acpi_dmar_satc_fixup(unsigned long base, unsigned long current);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001642unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1643 u8 bus, u8 dev, u8 fn);
1644unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1645 u8 bus, u8 dev, u8 fn);
1646unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1647 u8 enumeration_id,
1648 u8 bus, u8 dev, u8 fn);
Arthur Heymansbc8f8592022-12-02 13:17:39 +01001649unsigned long acpi_create_dmar_ds_ioapic_from_hw(unsigned long current,
1650 u32 addr, u8 bus, u8 dev, u8 fn);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001651unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1652 u8 enumeration_id,
1653 u8 bus, u8 dev, u8 fn);
1654void acpi_write_hest(acpi_hest_t *hest,
1655 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1656
1657unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1658 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1659
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001660unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1661
Felix Heldf7dbf4a2021-06-07 16:56:04 +02001662/* chipsets that select ACPI_BERT must implement this function */
Felix Held29405482021-05-28 16:01:57 +02001663enum cb_err acpi_soc_get_bert_region(void **region, size_t *length);
Francois Toguo522e0db2021-01-21 09:55:19 -08001664
Arthur Heymans2e3cb632023-06-30 15:01:08 +02001665void acpi_soc_fill_gtdt(acpi_gtdt_t *gtdt);
1666unsigned long acpi_soc_gtdt_add_timers(uint32_t *count, unsigned long current);
1667unsigned long acpi_gtdt_add_timer_block(unsigned long current, const uint64_t address,
1668 struct acpi_gtdt_timer_entry *timers, size_t number);
1669unsigned long acpi_gtdt_add_watchdog(unsigned long current, uint64_t refresh_frame,
1670 uint64_t control_frame, uint32_t gsiv, uint32_t flags);
1671
Furquan Shaikhe0844632020-05-02 10:23:37 -07001672/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001673void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001674void mainboard_suspend_resume(void);
1675void *acpi_find_wakeup_vector(void);
1676
1677/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1678enum {
1679 ACPI_S0 = 0,
1680 ACPI_S1 = 1,
1681 ACPI_S2 = 2,
1682 ACPI_S3 = 3,
1683 ACPI_S4 = 4,
1684 ACPI_S5 = 5,
1685};
1686
1687#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1688 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1689/* Given the provided PM1 control register return the ACPI sleep type. */
1690static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1691{
1692 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1693 case SLP_TYP_S0: return ACPI_S0;
1694 case SLP_TYP_S1: return ACPI_S1;
1695 case SLP_TYP_S3: return ACPI_S3;
1696 case SLP_TYP_S4: return ACPI_S4;
1697 case SLP_TYP_S5: return ACPI_S5;
1698 }
1699 return -1;
1700}
1701#endif
1702
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001703uint8_t acpi_get_preferred_pm_profile(void);
1704
Furquan Shaikhe0844632020-05-02 10:23:37 -07001705/* Returns ACPI_Sx values. */
1706int acpi_get_sleep_type(void);
1707
1708/* Read and clear GPE status */
1709int acpi_get_gpe(int gpe);
1710
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001711/* Once we enter payload, is SMI handler installed and capable of
1712 responding to APM_CNT Advanced Power Management Control commands. */
1713static inline int permanent_smi_handler(void)
1714{
1715 return CONFIG(HAVE_SMI_HANDLER);
1716}
1717
Furquan Shaikhe0844632020-05-02 10:23:37 -07001718static inline int acpi_s3_resume_allowed(void)
1719{
1720 return CONFIG(HAVE_ACPI_RESUME);
1721}
1722
Furquan Shaikhe0844632020-05-02 10:23:37 -07001723static inline int acpi_is_wakeup_s3(void)
1724{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001725 if (!acpi_s3_resume_allowed())
1726 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001727
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001728 if (ENV_ROMSTAGE_OR_BEFORE)
1729 return (acpi_get_sleep_type() == ACPI_S3);
1730
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001731 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001732}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001733
1734static inline uintptr_t acpi_align_current(uintptr_t current)
1735{
1736 return ALIGN_UP(current, 16);
1737}
1738
1739/* ACPI table revisions should match the revision of the ACPI spec
1740 * supported. This function keeps the table versions synced. This could
1741 * be made into a weak function if there is ever a need to override the
1742 * coreboot default ACPI spec version supported. */
1743int get_acpi_table_revision(enum acpi_tables table);
Elyes Haouas8b950f42022-02-16 12:08:16 +01001744u8 get_acpi_fadt_minor_version(void);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001745
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001746#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001747
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001748#endif /* __ACPI_ACPI_H__ */