blob: fe7e5fd829c263ef39d65ac3d6b381eee2b3f1ec [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 */
CoolStarce84a342023-10-15 16:51:54 -070073 COREBOOT_ACPI_ID_AMDGFX_ACP = 0x0003, /* BOOT0003 */
Furquan Shaikhe0844632020-05-02 10:23:37 -070074 COREBOOT_ACPI_ID_MAX = 0xFFFF, /* BOOTFFFF */
75};
76
77enum acpi_tables {
78 /* Tables defined by ACPI and used by coreboot */
Jonathan Zhang3dcafa82022-05-11 13:11:20 -070079 BERT, CEDT, DBG2, DMAR, DSDT, EINJ, FACS, FADT, HEST, HMAT, HPET, IVRS,
80 MADT, MCFG, RSDP, RSDT, SLIT, SRAT, SSDT, TCPA, TPM2, XSDT, ECDT, LPIT,
Arthur Heymans2e3cb632023-06-30 15:01:08 +020081 SPCR, GTDT,
Furquan Shaikhe0844632020-05-02 10:23:37 -070082 /* Additional proprietary tables used by coreboot */
Jason Glenesk61624b22020-11-02 20:06:23 -080083 VFCT, NHLT, SPMI, CRAT
Furquan Shaikhe0844632020-05-02 10:23:37 -070084};
85
86/* RSDP (Root System Description Pointer) */
87typedef struct acpi_rsdp {
88 char signature[8]; /* RSDP signature */
89 u8 checksum; /* Checksum of the first 20 bytes */
90 char oem_id[6]; /* OEM ID */
91 u8 revision; /* RSDP revision */
92 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
93 u32 length; /* Total RSDP length (incl. extended part) */
94 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
95 u8 ext_checksum; /* Checksum of the whole table */
96 u8 reserved[3];
97} __packed acpi_rsdp_t;
98
99/* GAS (Generic Address Structure) */
100typedef struct acpi_gen_regaddr {
101 u8 space_id; /* Address space ID */
102 u8 bit_width; /* Register size in bits */
103 u8 bit_offset; /* Register bit offset */
104 u8 access_size; /* Access size since ACPI 2.0c */
105 u32 addrl; /* Register address, low 32 bits */
106 u32 addrh; /* Register address, high 32 bits */
107} __packed acpi_addr_t;
108
Elyes HAOUAS5f5fd852020-10-15 12:24:00 +0200109#define ACPI_ADDRESS_SPACE_MEMORY 0 /* System memory */
110#define ACPI_ADDRESS_SPACE_IO 1 /* System I/O */
111#define ACPI_ADDRESS_SPACE_PCI 2 /* PCI config space */
112#define ACPI_ADDRESS_SPACE_EC 3 /* Embedded controller */
113#define ACPI_ADDRESS_SPACE_SMBUS 4 /* SMBus */
114#define ACPI_ADDRESS_SPACE_CMOS 5 /* SystemCMOS */
115#define ACPI_ADDRESS_SPACE_PCI_BAR_TARGET 6 /* PciBarTarget */
116#define ACPI_ADDRESS_SPACE_IPMI 7 /* IPMI */
117#define ACPI_ADDRESS_SPACE_GENERAL_PURPOSE_IO 8 /* GeneralPurposeIO */
118#define ACPI_ADDRESS_SPACE_GENERIC_SERIAL_BUS 9 /* GenericSerialBus */
119#define ACPI_ADDRESS_SPACE_PCC 0x0A /* Platform Comm. Channel */
120#define ACPI_ADDRESS_SPACE_FIXED 0x7f /* Functional fixed hardware */
121#define ACPI_FFIXEDHW_VENDOR_INTEL 1 /* Intel */
122#define ACPI_FFIXEDHW_CLASS_HLT 0 /* C1 Halt */
123#define ACPI_FFIXEDHW_CLASS_IO_HLT 1 /* C1 I/O then Halt */
124#define ACPI_FFIXEDHW_CLASS_MWAIT 2 /* MWAIT Native C-state */
125#define ACPI_FFIXEDHW_FLAG_HW_COORD 1 /* Hardware Coordination bit */
126#define ACPI_FFIXEDHW_FLAG_BM_STS 2 /* BM_STS avoidance bit */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700127/* 0x80-0xbf: Reserved */
128/* 0xc0-0xff: OEM defined */
129
130/* Access size definitions for Generic address structure */
131#define ACPI_ACCESS_SIZE_UNDEFINED 0 /* Undefined (legacy reasons) */
132#define ACPI_ACCESS_SIZE_BYTE_ACCESS 1
133#define ACPI_ACCESS_SIZE_WORD_ACCESS 2
134#define ACPI_ACCESS_SIZE_DWORD_ACCESS 3
135#define ACPI_ACCESS_SIZE_QWORD_ACCESS 4
136
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200137/* Macros for common resource types */
138#define ACPI_REG_MSR(address, offset, width) \
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200139 (acpi_addr_t){ \
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200140 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
141 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
142 .addrl = address, \
143 .bit_offset = offset, \
144 .bit_width = width, \
145 }
146
Michael Niewöhnerf72c7b12021-10-05 21:42:57 +0200147#define ACPI_REG_UNSUPPORTED (acpi_addr_t){0}
Michael Niewöhnerab088c92021-09-23 17:04:35 +0200148
Furquan Shaikhe0844632020-05-02 10:23:37 -0700149/* Common ACPI HIDs */
150#define ACPI_HID_FDC "PNP0700"
151#define ACPI_HID_KEYBOARD "PNP0303"
152#define ACPI_HID_MOUSE "PNP0F03"
153#define ACPI_HID_COM "PNP0501"
154#define ACPI_HID_LPT "PNP0400"
155#define ACPI_HID_PNP "PNP0C02"
156#define ACPI_HID_CONTAINER "PNP0A05"
157
158/* Generic ACPI header, provided by (almost) all tables */
159typedef struct acpi_table_header {
160 char signature[4]; /* ACPI signature (4 ASCII characters) */
161 u32 length; /* Table length in bytes (incl. header) */
162 u8 revision; /* Table version (not ACPI version!) */
163 u8 checksum; /* To make sum of entire table == 0 */
164 char oem_id[6]; /* OEM identification */
165 char oem_table_id[8]; /* OEM table identification */
166 u32 oem_revision; /* OEM revision number */
167 char asl_compiler_id[4]; /* ASL compiler vendor ID */
168 u32 asl_compiler_revision; /* ASL compiler revision number */
169} __packed acpi_header_t;
170
171/* A maximum number of 32 ACPI tables ought to be enough for now. */
172#define MAX_ACPI_TABLES 32
173
174/* RSDT (Root System Description Table) */
175typedef struct acpi_rsdt {
176 acpi_header_t header;
177 u32 entry[MAX_ACPI_TABLES];
178} __packed acpi_rsdt_t;
179
180/* XSDT (Extended System Description Table) */
181typedef struct acpi_xsdt {
182 acpi_header_t header;
183 u64 entry[MAX_ACPI_TABLES];
184} __packed acpi_xsdt_t;
185
186/* HPET timers */
187typedef struct acpi_hpet {
188 acpi_header_t header;
189 u32 id;
190 acpi_addr_t addr;
191 u8 number;
192 u16 min_tick;
193 u8 attributes;
194} __packed acpi_hpet_t;
195
196/* MCFG (PCI Express MMIO config space BAR description table) */
197typedef struct acpi_mcfg {
198 acpi_header_t header;
199 u8 reserved[8];
200} __packed acpi_mcfg_t;
201
202typedef struct acpi_tcpa {
203 acpi_header_t header;
204 u16 platform_class;
205 u32 laml;
206 u64 lasa;
207} __packed acpi_tcpa_t;
208
209typedef struct acpi_tpm2 {
210 acpi_header_t header;
211 u16 platform_class;
212 u8 reserved[2];
213 u64 control_area;
214 u32 start_method;
215 u8 msp[12];
216 u32 laml;
217 u64 lasa;
218} __packed acpi_tpm2_t;
219
220typedef struct acpi_mcfg_mmconfig {
Naresh Solanki4d0b1842023-08-25 12:58:11 +0200221 u64 base_address;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700222 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
Sukumar Ghoraied1c03a2023-09-28 23:44:30 -0700457#define ACPI_LPIT_CTR_FREQ_TSC 0
Sukumar Ghoraibd9c5622023-10-07 23:19:34 -0700458
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +0100459
460/* LPIT: Native C-state instruction based LPI structure */
461typedef struct acpi_lpi_desc_ncst {
462 acpi_lpi_desc_hdr_t header;
463 acpi_lpi_desc_flags_t flags;
464 acpi_addr_t entry_trigger; /* Entry trigger C-state */
465 uint32_t min_residency; /* Minimum residency or "break-even" in microseconds */
466 uint32_t max_latency; /* Worst case exit latency in microseconds */
467 acpi_addr_t residency_counter;
468 uint64_t counter_frequency; /* Frequency in cycles per second - 0 means TSC freq */
469} __packed acpi_lpi_desc_ncst_t;
470
Matt DeVillier7c04d0e2023-09-03 12:51:58 -0500471#define VFCT_VBIOS_CHECKSUM_OFFSET 0x21
472
Furquan Shaikhe0844632020-05-02 10:23:37 -0700473/* VFCT image header */
474typedef struct acpi_vfct_image_hdr {
475 u32 PCIBus;
476 u32 PCIDevice;
477 u32 PCIFunction;
478 u16 VendorID;
479 u16 DeviceID;
480 u16 SSVID;
481 u16 SSID;
482 u32 Revision;
483 u32 ImageLength;
Matt DeVillier7c04d0e2023-09-03 12:51:58 -0500484 u8 VbiosContent[]; // dummy - copy VBIOS here
Furquan Shaikhe0844632020-05-02 10:23:37 -0700485} __packed acpi_vfct_image_hdr_t;
486
487/* VFCT (VBIOS Fetch Table) */
488typedef struct acpi_vfct {
489 acpi_header_t header;
490 u8 TableUUID[16];
491 u32 VBIOSImageOffset;
492 u32 Lib1ImageOffset;
493 u32 Reserved[4];
494 acpi_vfct_image_hdr_t image_hdr;
495} __packed acpi_vfct_t;
496
497typedef struct acpi_ivrs_info {
498} __packed acpi_ivrs_info_t;
499
500/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 10h */
501typedef struct acpi_ivrs_ivhd {
502 uint8_t type;
503 uint8_t flags;
504 uint16_t length;
505 uint16_t device_id;
506 uint16_t capability_offset;
507 uint32_t iommu_base_low;
508 uint32_t iommu_base_high;
509 uint16_t pci_segment_group;
510 uint16_t iommu_info;
511 uint32_t iommu_feature_info;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200512 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700513} __packed acpi_ivrs_ivhd_t;
514
515/* IVRS (I/O Virtualization Reporting Structure) Type 10h */
516typedef struct acpi_ivrs {
517 acpi_header_t header;
518 uint32_t iv_info;
519 uint32_t reserved[2];
520 struct acpi_ivrs_ivhd ivhd;
521} __packed acpi_ivrs_t;
522
Jason Glenesk61624b22020-11-02 20:06:23 -0800523/* CRAT (Component Resource Affinity Table Structure) */
524struct acpi_crat_header {
525 acpi_header_t header;
526 uint32_t total_entries;
527 uint16_t num_nodes;
528 uint8_t reserved[6];
529} __packed;
530
Furquan Shaikhe0844632020-05-02 10:23:37 -0700531/* IVHD Type 11h IOMMU Attributes */
532typedef struct ivhd11_iommu_attr {
533 uint32_t reserved1 : 13;
534 uint32_t perf_counters : 4;
535 uint32_t perf_counter_banks : 6;
536 uint32_t msi_num_ppr : 5;
537 uint32_t reserved2 : 4;
538} __packed ivhd11_iommu_attr_t;
539
540/* IVRS IVHD (I/O Virtualization Hardware Definition Block) Type 11h */
541typedef struct acpi_ivrs_ivhd_11 {
542 uint8_t type;
543 uint8_t flags;
544 uint16_t length;
545 uint16_t device_id;
546 uint16_t capability_offset;
547 uint32_t iommu_base_low;
548 uint32_t iommu_base_high;
549 uint16_t pci_segment_group;
550 uint16_t iommu_info;
551 struct ivhd11_iommu_attr iommu_attributes;
552 uint32_t efr_reg_image_low;
553 uint32_t efr_reg_image_high;
554 uint32_t reserved[2];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200555 uint8_t entry[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700556} __packed acpi_ivrs_ivhd11_t;
557
558enum dev_scope_type {
559 SCOPE_PCI_ENDPOINT = 1,
560 SCOPE_PCI_SUB = 2,
561 SCOPE_IOAPIC = 3,
562 SCOPE_MSI_HPET = 4,
563 SCOPE_ACPI_NAMESPACE_DEVICE = 5
564};
565
566typedef struct dev_scope {
567 u8 type;
568 u8 length;
569 u8 reserved[2];
570 u8 enumeration;
571 u8 start_bus;
572 struct {
573 u8 dev;
574 u8 fn;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200575 } __packed path[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700576} __packed dev_scope_t;
577
578enum dmar_type {
579 DMAR_DRHD = 0,
580 DMAR_RMRR = 1,
581 DMAR_ATSR = 2,
582 DMAR_RHSA = 3,
John Zhao6edbb182021-03-24 11:55:09 -0700583 DMAR_ANDD = 4,
584 DMAR_SATC = 5
Furquan Shaikhe0844632020-05-02 10:23:37 -0700585};
586
587enum {
588 DRHD_INCLUDE_PCI_ALL = 1
589};
590
John Zhao091532d2021-04-17 16:03:21 -0700591enum {
592 ATC_REQUIRED = 1
593};
594
Furquan Shaikhe0844632020-05-02 10:23:37 -0700595enum dmar_flags {
596 DMAR_INTR_REMAP = 1 << 0,
597 DMAR_X2APIC_OPT_OUT = 1 << 1,
598 DMA_CTRL_PLATFORM_OPT_IN_FLAG = 1 << 2,
599};
600
601typedef struct dmar_entry {
602 u16 type;
603 u16 length;
604 u8 flags;
605 u8 reserved;
606 u16 segment;
607 u64 bar;
608} __packed dmar_entry_t;
609
610typedef struct dmar_rmrr_entry {
611 u16 type;
612 u16 length;
613 u16 reserved;
614 u16 segment;
615 u64 bar;
616 u64 limit;
617} __packed dmar_rmrr_entry_t;
618
619typedef struct dmar_atsr_entry {
620 u16 type;
621 u16 length;
622 u8 flags;
623 u8 reserved;
624 u16 segment;
625} __packed dmar_atsr_entry_t;
626
627typedef struct dmar_rhsa_entry {
628 u16 type;
629 u16 length;
630 u32 reserved;
631 u64 base_address;
632 u32 proximity_domain;
633} __packed dmar_rhsa_entry_t;
634
635typedef struct dmar_andd_entry {
636 u16 type;
637 u16 length;
638 u8 reserved[3];
639 u8 device_number;
640 u8 device_name[];
641} __packed dmar_andd_entry_t;
642
John Zhao6edbb182021-03-24 11:55:09 -0700643typedef struct dmar_satc_entry {
644 u16 type;
645 u16 length;
646 u8 flags;
647 u8 reserved;
648 u16 segment_number;
John Zhao6edbb182021-03-24 11:55:09 -0700649} __packed dmar_satc_entry_t;
650
Furquan Shaikhe0844632020-05-02 10:23:37 -0700651/* DMAR (DMA Remapping Reporting Structure) */
652typedef struct acpi_dmar {
653 acpi_header_t header;
654 u8 host_address_width;
655 u8 flags;
656 u8 reserved[10];
Elyes Haouasa4aa169a2023-07-30 12:59:50 +0200657 dmar_entry_t structure[];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700658} __packed acpi_dmar_t;
659
660/* MADT: APIC Structure Types */
661enum acpi_apic_types {
662 LOCAL_APIC, /* Processor local APIC */
663 IO_APIC, /* I/O APIC */
664 IRQ_SOURCE_OVERRIDE, /* Interrupt source override */
665 NMI_TYPE, /* NMI source */
666 LOCAL_APIC_NMI, /* Local APIC NMI */
667 LAPIC_ADDRESS_OVERRIDE, /* Local APIC address override */
668 IO_SAPIC, /* I/O SAPIC */
669 LOCAL_SAPIC, /* Local SAPIC */
670 PLATFORM_IRQ_SOURCES, /* Platform interrupt sources */
671 LOCAL_X2APIC, /* Processor local x2APIC */
672 LOCAL_X2APIC_NMI, /* Local x2APIC NMI */
673 GICC, /* GIC CPU Interface */
674 GICD, /* GIC Distributor */
675 GIC_MSI_FRAME, /* GIC MSI Frame */
676 GICR, /* GIC Redistributor */
677 GIC_ITS, /* Interrupt Translation Service */
678 /* 0x10-0x7f: Reserved */
679 /* 0x80-0xff: Reserved for OEM use */
680};
681
682/* MADT: Processor Local APIC Structure */
683typedef struct acpi_madt_lapic {
684 u8 type; /* Type (0) */
685 u8 length; /* Length in bytes (8) */
686 u8 processor_id; /* ACPI processor ID */
687 u8 apic_id; /* Local APIC ID */
688 u32 flags; /* Local APIC flags */
689} __packed acpi_madt_lapic_t;
690
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +0300691#define ACPI_MADT_MAX_LAPIC_ID 0xfe
692
Furquan Shaikhe0844632020-05-02 10:23:37 -0700693/* MADT: Local APIC NMI Structure */
694typedef struct acpi_madt_lapic_nmi {
695 u8 type; /* Type (4) */
696 u8 length; /* Length in bytes (6) */
697 u8 processor_id; /* ACPI processor ID */
698 u16 flags; /* MPS INTI flags */
699 u8 lint; /* Local APIC LINT# */
700} __packed acpi_madt_lapic_nmi_t;
701
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +0200702#define ACPI_MADT_LAPIC_NMI_ALL_PROCESSORS 0xff
703#define ACPI_MADT_LX2APIC_NMI_ALL_PROCESSORS ((u32)-1)
Raul E Rangelf5552ce2021-02-11 11:27:56 -0700704
Furquan Shaikhe0844632020-05-02 10:23:37 -0700705/* MADT: I/O APIC Structure */
706typedef struct acpi_madt_ioapic {
707 u8 type; /* Type (1) */
708 u8 length; /* Length in bytes (12) */
709 u8 ioapic_id; /* I/O APIC ID */
710 u8 reserved;
711 u32 ioapic_addr; /* I/O APIC address */
712 u32 gsi_base; /* Global system interrupt base */
713} __packed acpi_madt_ioapic_t;
714
Raul E Rangel169302a2022-04-25 14:59:05 -0600715#define MP_IRQ_POLARITY_DEFAULT 0x0
716#define MP_IRQ_POLARITY_HIGH 0x1
717#define MP_IRQ_POLARITY_LOW 0x3
718#define MP_IRQ_POLARITY_MASK 0x3
719#define MP_IRQ_TRIGGER_DEFAULT 0x0
720#define MP_IRQ_TRIGGER_EDGE 0x4
721#define MP_IRQ_TRIGGER_LEVEL 0xc
722#define MP_IRQ_TRIGGER_MASK 0xc
723
Furquan Shaikhe0844632020-05-02 10:23:37 -0700724/* MADT: Interrupt Source Override Structure */
725typedef struct acpi_madt_irqoverride {
726 u8 type; /* Type (2) */
727 u8 length; /* Length in bytes (10) */
728 u8 bus; /* ISA (0) */
729 u8 source; /* Bus-relative int. source (IRQ) */
730 u32 gsirq; /* Global system interrupt */
731 u16 flags; /* MPS INTI flags */
732} __packed acpi_madt_irqoverride_t;
733
734/* MADT: Processor Local x2APIC Structure */
735typedef struct acpi_madt_lx2apic {
736 u8 type; /* Type (9) */
737 u8 length; /* Length in bytes (16) */
738 u16 reserved;
739 u32 x2apic_id; /* Local x2APIC ID */
740 u32 flags; /* Same as Local APIC flags */
741 u32 processor_id; /* ACPI processor ID */
742} __packed acpi_madt_lx2apic_t;
743
744/* MADT: Processor Local x2APIC NMI Structure */
745typedef struct acpi_madt_lx2apic_nmi {
746 u8 type; /* Type (10) */
747 u8 length; /* Length in bytes (12) */
748 u16 flags; /* Same as MPS INTI flags */
749 u32 processor_id; /* ACPI processor ID */
750 u8 lint; /* Local APIC LINT# */
751 u8 reserved[3];
752} __packed acpi_madt_lx2apic_nmi_t;
753
Arthur Heymans51d94c72023-06-27 15:37:37 +0200754/* MADT: GIC CPU Interface (GICC) Structure 6.5 */
755struct gicc_flags {
756 uint32_t enabled : 1;
757 /* 0 - Level-triggered | 1 - Edge-Triggered */
758 uint32_t performance_interrupt_mode : 1;
759 uint32_t vgic_maintenance_interrupt_mode : 1;
760 uint32_t online_capable : 1;
761 uint32_t reserved : 28;
762};
763_Static_assert(sizeof(struct gicc_flags) == sizeof(uint32_t), "Wrong gicc_flags size\n");
764
765typedef struct acpi_gicc {
766 uint8_t type;
767 uint8_t length;
768 uint16_t reserved;
769 uint32_t cpu_interface_number;
770 uint32_t acpi_processor_uid;
771 struct gicc_flags flags;
772 uint32_t parking_protocol_version;
773 uint32_t performance_interrupt_gsiv;
774 uint64_t parked_address;
775 uint64_t physical_base_address; /* GIC v1/v2 or GIC v3/v4 in v2 compat mode */
776 uint64_t gicv;
777 uint64_t gich;
778 uint32_t vgic_maintenance_interrupt;
779 uint64_t gicr_base_address; /* Only GIC v3 and above */
780 uint64_t mpidr;
781 uint8_t processor_power_efficiency_class;
782 uint8_t reserved1;
783 uint16_t spe_overflow_interrupt;
784 uint16_t trbe_interrupt;
785} __packed acpi_madt_gicc_t;
786_Static_assert(sizeof(acpi_madt_gicc_t) == 82, "Wrong acpi_madt_gicc_t size\n");
787
788/* MADT: GIC Distributor (GICD) Structure */
789typedef struct acpi_gicd {
790 uint8_t type;
791 uint8_t length;
792 uint16_t reserved1;
793 uint32_t gic_id;
794 uint64_t physical_base_address;
795 uint32_t system_vector_base;
796 uint8_t gic_version;
797 uint8_t reserved2[3];
798} __packed acpi_madt_gicd_t;
799_Static_assert(sizeof(acpi_madt_gicd_t) == 24, "Wrong acpi_madt_gicd_t size\n");
800
801/* MADT: GIC MSI Frame Structure */
802struct gic_msi_flags {
803 uint32_t spi_count_select : 1;
804 uint32_t reserved : 31;
805};
806_Static_assert(sizeof(struct gic_msi_flags) == sizeof(uint32_t), "Wrong gic_msi_flags size\n");
807
808typedef struct acpi_gic_msi {
809 uint8_t type;
810 uint8_t length;
811 uint16_t reserved;
812 uint32_t gic_msi_frame_id;
813 uint64_t physical_base_address;
814 struct gic_msi_flags flags;
815 uint16_t spi_count;
816 uint16_t spi_base;
817} __packed acpi_gic_msi_t;
818_Static_assert(sizeof(acpi_gic_msi_t) == 24, "Wrong acpi_gic_msi_t size\n");
819
820/* MADT: GIC Redistributor (GICR) Structure */
821typedef struct acpi_girr {
822 uint8_t type;
823 uint8_t length;
824 uint16_t reserved;
825 uint64_t discovery_range_base_address;
826 uint32_t discovery_range_length;
827} __packed acpi_madt_gicr_t;
828_Static_assert(sizeof(acpi_madt_gicr_t) == 16, "Wrong acpi_madt_gicr_t size\n");
829
830/* MADT: GIC Interrupt Translation Service (ITS) Structure */
831typedef struct acpi_gic_its {
832 uint8_t type;
833 uint8_t length;
834 uint16_t reserved;
835 uint32_t gic_its_id;
836 uint64_t physical_base_address;
837 uint32_t reserved2;
838} __packed acpi_madt_gic_its_t;
839_Static_assert(sizeof(acpi_madt_gic_its_t) == 20, "Wrong MADT acpi_madt_gic_its_t size\n");
840
Furquan Shaikhe0844632020-05-02 10:23:37 -0700841#define ACPI_DBG2_PORT_SERIAL 0x8000
842#define ACPI_DBG2_PORT_SERIAL_16550 0x0000
843#define ACPI_DBG2_PORT_SERIAL_16550_DBGP 0x0001
844#define ACPI_DBG2_PORT_SERIAL_ARM_PL011 0x0003
845#define ACPI_DBG2_PORT_SERIAL_ARM_SBSA 0x000e
846#define ACPI_DBG2_PORT_SERIAL_ARM_DDC 0x000f
847#define ACPI_DBG2_PORT_SERIAL_BCM2835 0x0010
848#define ACPI_DBG2_PORT_IEEE1394 0x8001
849#define ACPI_DBG2_PORT_IEEE1394_STANDARD 0x0000
850#define ACPI_DBG2_PORT_USB 0x8002
851#define ACPI_DBG2_PORT_USB_XHCI 0x0000
852#define ACPI_DBG2_PORT_USB_EHCI 0x0001
853#define ACPI_DBG2_PORT_NET 0x8003
854
855/* DBG2: Microsoft Debug Port Table 2 header */
856typedef struct acpi_dbg2_header {
857 acpi_header_t header;
858 uint32_t devices_offset;
859 uint32_t devices_count;
Elyes Haouas139cb062023-08-26 17:04:21 +0200860} __packed acpi_dbg2_header_t;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700861
862/* DBG2: Microsoft Debug Port Table 2 device entry */
863typedef struct acpi_dbg2_device {
864 uint8_t revision;
865 uint16_t length;
866 uint8_t address_count;
867 uint16_t namespace_string_length;
868 uint16_t namespace_string_offset;
869 uint16_t oem_data_length;
870 uint16_t oem_data_offset;
871 uint16_t port_type;
872 uint16_t port_subtype;
873 uint8_t reserved[2];
874 uint16_t base_address_offset;
875 uint16_t address_size_offset;
Elyes Haouas139cb062023-08-26 17:04:21 +0200876} __packed acpi_dbg2_device_t;
Furquan Shaikhe0844632020-05-02 10:23:37 -0700877
878/* FADT (Fixed ACPI Description Table) */
879typedef struct acpi_fadt {
880 acpi_header_t header;
881 u32 firmware_ctrl;
882 u32 dsdt;
883 u8 reserved; /* Should be 0 */
884 u8 preferred_pm_profile;
885 u16 sci_int;
886 u32 smi_cmd;
887 u8 acpi_enable;
888 u8 acpi_disable;
889 u8 s4bios_req;
890 u8 pstate_cnt;
891 u32 pm1a_evt_blk;
892 u32 pm1b_evt_blk;
893 u32 pm1a_cnt_blk;
894 u32 pm1b_cnt_blk;
895 u32 pm2_cnt_blk;
896 u32 pm_tmr_blk;
897 u32 gpe0_blk;
898 u32 gpe1_blk;
899 u8 pm1_evt_len;
900 u8 pm1_cnt_len;
901 u8 pm2_cnt_len;
902 u8 pm_tmr_len;
903 u8 gpe0_blk_len;
904 u8 gpe1_blk_len;
905 u8 gpe1_base;
906 u8 cst_cnt;
907 u16 p_lvl2_lat;
908 u16 p_lvl3_lat;
909 u16 flush_size;
910 u16 flush_stride;
911 u8 duty_offset;
912 u8 duty_width;
913 u8 day_alrm;
914 u8 mon_alrm;
915 u8 century;
916 u16 iapc_boot_arch;
917 u8 res2;
918 u32 flags;
919 acpi_addr_t reset_reg;
920 u8 reset_value;
Elyes Haouasb55ac092022-02-16 14:42:19 +0100921 u16 ARM_boot_arch; /* Must be zero if ACPI Revision <= 5.0 */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100922 u8 FADT_MinorVersion; /* Must be zero if ACPI Revision <= 5.0 */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700923 u32 x_firmware_ctl_l;
924 u32 x_firmware_ctl_h;
925 u32 x_dsdt_l;
926 u32 x_dsdt_h;
927 acpi_addr_t x_pm1a_evt_blk;
928 acpi_addr_t x_pm1b_evt_blk;
929 acpi_addr_t x_pm1a_cnt_blk;
930 acpi_addr_t x_pm1b_cnt_blk;
931 acpi_addr_t x_pm2_cnt_blk;
932 acpi_addr_t x_pm_tmr_blk;
933 acpi_addr_t x_gpe0_blk;
934 acpi_addr_t x_gpe1_blk;
935 /* Revision 5 */
936 acpi_addr_t sleep_control_reg;
937 acpi_addr_t sleep_status_reg;
938 /* Revision 6 */
939 u64 hypervisor_vendor_identity;
940} __packed acpi_fadt_t;
941
942/* FADT TABLE Revision values */
Elyes Haouas8b950f42022-02-16 12:08:16 +0100943#define ACPI_FADT_REV_ACPI_1 1
944#define ACPI_FADT_REV_ACPI_2 3
945#define ACPI_FADT_REV_ACPI_3 4
946#define ACPI_FADT_REV_ACPI_4 4
947#define ACPI_FADT_REV_ACPI_5 5
948#define ACPI_FADT_REV_ACPI_6 6
949
950/* FADT Minor Version value:
951 * Bits 0-3: minor version
952 * Bits 4-7: Errata
953 * value of 1 means this is compatible with Errata A,
954 * value of 2 would be compatible with Errata B, and so on
955 * Version 6.3 Errata A would be: (1 << 4) | 3
956 */
957#define ACPI_FADT_MINOR_VERSION_0 0 /* coreboot currently use this version */
Furquan Shaikhe0844632020-05-02 10:23:37 -0700958
959/* Flags for p_lvl2_lat and p_lvl3_lat */
960#define ACPI_FADT_C2_NOT_SUPPORTED 101
961#define ACPI_FADT_C3_NOT_SUPPORTED 1001
962
963/* FADT Feature Flags */
964#define ACPI_FADT_WBINVD (1 << 0)
965#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
966#define ACPI_FADT_C1_SUPPORTED (1 << 2)
967#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
968#define ACPI_FADT_POWER_BUTTON (1 << 4)
969#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
970#define ACPI_FADT_FIXED_RTC (1 << 6)
971#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
972#define ACPI_FADT_32BIT_TIMER (1 << 8)
973#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
974#define ACPI_FADT_RESET_REGISTER (1 << 10)
975#define ACPI_FADT_SEALED_CASE (1 << 11)
976#define ACPI_FADT_HEADLESS (1 << 12)
977#define ACPI_FADT_SLEEP_TYPE (1 << 13)
978#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
979#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
980#define ACPI_FADT_S4_RTC_VALID (1 << 16)
981#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
982#define ACPI_FADT_APIC_CLUSTER (1 << 18)
983#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
984/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
985#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
986#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
987/* bits 22-31: reserved since ACPI 5.0 */
988
989/* FADT Boot Architecture Flags */
990#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
991#define ACPI_FADT_8042 (1 << 1)
992#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
993#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
994#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
995#define ACPI_FADT_NO_CMOS_RTC (1 << 5)
996#define ACPI_FADT_LEGACY_FREE 0x00 /* No legacy devices (including 8042) */
997
998/* FADT ARM Boot Architecture Flags */
999#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
1000#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
1001/* bits 2-16: reserved since ACPI 5.1 */
1002
1003/* FADT Preferred Power Management Profile */
1004enum acpi_preferred_pm_profiles {
1005 PM_UNSPECIFIED = 0,
1006 PM_DESKTOP = 1,
1007 PM_MOBILE = 2,
1008 PM_WORKSTATION = 3,
1009 PM_ENTERPRISE_SERVER = 4,
1010 PM_SOHO_SERVER = 5,
1011 PM_APPLIANCE_PC = 6,
1012 PM_PERFORMANCE_SERVER = 7,
1013 PM_TABLET = 8, /* ACPI 5.0 & greater */
1014};
1015
1016/* FACS (Firmware ACPI Control Structure) */
1017typedef struct acpi_facs {
1018 char signature[4]; /* "FACS" */
1019 u32 length; /* Length in bytes (>= 64) */
1020 u32 hardware_signature; /* Hardware signature */
1021 u32 firmware_waking_vector; /* Firmware waking vector */
1022 u32 global_lock; /* Global lock */
1023 u32 flags; /* FACS flags */
1024 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
1025 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
1026 u8 version; /* FACS version */
1027 u8 resv1[3]; /* This value is 0 */
1028 u32 ospm_flags; /* 64BIT_WAKE_F */
1029 u8 resv2[24]; /* This value is 0 */
1030} __packed acpi_facs_t;
1031
1032/* FACS flags */
1033#define ACPI_FACS_S4BIOS_F (1 << 0)
1034#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
1035/* Bits 31..2: reserved */
1036
1037/* ECDT (Embedded Controller Boot Resources Table) */
1038typedef struct acpi_ecdt {
1039 acpi_header_t header;
1040 acpi_addr_t ec_control; /* EC control register */
1041 acpi_addr_t ec_data; /* EC data register */
1042 u32 uid; /* UID */
1043 u8 gpe_bit; /* GPE bit */
1044 u8 ec_id[]; /* EC ID */
1045} __packed acpi_ecdt_t;
1046
1047/* HEST (Hardware Error Source Table) */
1048typedef struct acpi_hest {
1049 acpi_header_t header;
1050 u32 error_source_count;
1051 /* error_source_struct(s) */
1052} __packed acpi_hest_t;
1053
1054/* Error Source Descriptors */
1055typedef struct acpi_hest_esd {
1056 u16 type;
1057 u16 source_id;
1058 u16 resv;
1059 u8 flags;
1060 u8 enabled;
1061 u32 prealloc_erecords; /* The number of error records to
1062 * pre-allocate for this error source.
1063 */
1064 u32 max_section_per_record;
1065} __packed acpi_hest_esd_t;
1066
1067/* Hardware Error Notification */
1068typedef struct acpi_hest_hen {
1069 u8 type;
1070 u8 length;
1071 u16 conf_we; /* Configuration Write Enable */
1072 u32 poll_interval;
1073 u32 vector;
1074 u32 sw2poll_threshold_val;
1075 u32 sw2poll_threshold_win;
1076 u32 error_threshold_val;
1077 u32 error_threshold_win;
1078} __packed acpi_hest_hen_t;
1079
1080/* BERT (Boot Error Record Table) */
1081typedef struct acpi_bert {
1082 acpi_header_t header;
1083 u32 region_length;
1084 u64 error_region;
1085} __packed acpi_bert_t;
1086
1087/* Generic Error Data Entry */
1088typedef struct acpi_hest_generic_data {
1089 guid_t section_type;
1090 u32 error_severity;
1091 u16 revision;
1092 u8 validation_bits;
1093 u8 flags;
1094 u32 data_length;
1095 guid_t fru_id;
1096 u8 fru_text[20];
1097 /* error data */
1098} __packed acpi_hest_generic_data_t;
1099
1100/* Generic Error Data Entry v300 */
1101typedef struct acpi_hest_generic_data_v300 {
1102 guid_t section_type;
1103 u32 error_severity;
1104 u16 revision;
1105 u8 validation_bits;
1106 u8 flags; /* see CPER Section Descriptor, Flags field */
1107 u32 data_length;
1108 guid_t fru_id;
1109 u8 fru_text[20];
1110 cper_timestamp_t timestamp;
1111 /* error data */
1112} __packed acpi_hest_generic_data_v300_t;
1113#define HEST_GENERIC_ENTRY_V300 0x300
1114
1115/* Both Generic Error Status & Generic Error Data Entry, Error Severity field */
1116#define ACPI_GENERROR_SEV_RECOVERABLE 0
1117#define ACPI_GENERROR_SEV_FATAL 1
1118#define ACPI_GENERROR_SEV_CORRECTED 2
1119#define ACPI_GENERROR_SEV_NONE 3
1120
1121/* Generic Error Data Entry, Validation Bits field */
1122#define ACPI_GENERROR_VALID_FRUID BIT(0)
1123#define ACPI_GENERROR_VALID_FRUID_TEXT BIT(1)
1124#define ACPI_GENERROR_VALID_TIMESTAMP BIT(2)
1125
Felix Held403fa862021-07-26 22:43:00 +02001126/*
1127 * Generic Error Status Block
1128 *
1129 * If there is a raw data section at the end of the generic error status block after the
1130 * zero or more generic error data entries, raw_data_length indicates the length of the raw
1131 * section and raw_data_offset is the offset of the beginning of the raw data section from
1132 * the start of the acpi_generic_error_status block it is contained in. So if raw_data_length
1133 * is non-zero, raw_data_offset must be at least sizeof(acpi_generic_error_status_t).
1134 */
Furquan Shaikhe0844632020-05-02 10:23:37 -07001135typedef struct acpi_generic_error_status {
1136 u32 block_status;
1137 u32 raw_data_offset; /* must follow any generic entries */
1138 u32 raw_data_length;
1139 u32 data_length; /* generic data */
1140 u32 error_severity;
1141 /* Generic Error Data structures, zero or more entries */
1142} __packed acpi_generic_error_status_t;
1143
1144/* Generic Status Block, Block Status values */
1145#define GENERIC_ERR_STS_UNCORRECTABLE_VALID BIT(0)
1146#define GENERIC_ERR_STS_CORRECTABLE_VALID BIT(1)
1147#define GENERIC_ERR_STS_MULT_UNCORRECTABLE BIT(2)
1148#define GENERIC_ERR_STS_MULT_CORRECTABLE BIT(3)
1149#define GENERIC_ERR_STS_ENTRY_COUNT_SHIFT 4
1150#define GENERIC_ERR_STS_ENTRY_COUNT_MAX 0x3ff
1151#define GENERIC_ERR_STS_ENTRY_COUNT_MASK \
1152 (GENERIC_ERR_STS_ENTRY_COUNT_MAX \
1153 << GENERIC_ERR_STS_ENTRY_COUNT_SHIFT)
1154
1155typedef struct acpi_cstate {
1156 u8 ctype;
1157 u16 latency;
1158 u32 power;
1159 acpi_addr_t resource;
1160} __packed acpi_cstate_t;
1161
Jason Gleneskca36aed2020-09-15 21:01:57 -07001162struct acpi_sw_pstate {
1163 u32 core_freq;
1164 u32 power;
1165 u32 transition_latency;
1166 u32 bus_master_latency;
1167 u32 control_value;
1168 u32 status_value;
1169} __packed;
1170
1171struct acpi_xpss_sw_pstate {
1172 u64 core_freq;
1173 u64 power;
1174 u64 transition_latency;
1175 u64 bus_master_latency;
1176 u64 control_value;
1177 u64 status_value;
1178 u64 control_mask;
1179 u64 status_mask;
1180} __packed;
1181
Furquan Shaikhe0844632020-05-02 10:23:37 -07001182typedef struct acpi_tstate {
1183 u32 percent;
1184 u32 power;
1185 u32 latency;
1186 u32 control;
1187 u32 status;
1188} __packed acpi_tstate_t;
1189
Raul E Rangelc7048322021-04-19 15:58:25 -06001190enum acpi_lpi_state_flags {
1191 ACPI_LPI_STATE_DISABLED = 0,
1192 ACPI_LPI_STATE_ENABLED
1193};
1194
1195/* Low Power Idle State */
1196struct acpi_lpi_state {
1197 u32 min_residency_us;
1198 u32 worst_case_wakeup_latency_us;
1199 u32 flags;
1200 u32 arch_context_lost_flags;
1201 u32 residency_counter_frequency_hz;
1202 u32 enabled_parent_state;
1203 acpi_addr_t entry_method;
1204 acpi_addr_t residency_counter_register;
1205 acpi_addr_t usage_counter_register;
1206 const char *state_name;
1207};
1208
Furquan Shaikhe0844632020-05-02 10:23:37 -07001209/* Port types for ACPI _UPC object */
1210enum acpi_upc_type {
1211 UPC_TYPE_A,
1212 UPC_TYPE_MINI_AB,
1213 UPC_TYPE_EXPRESSCARD,
1214 UPC_TYPE_USB3_A,
1215 UPC_TYPE_USB3_B,
1216 UPC_TYPE_USB3_MICRO_B,
1217 UPC_TYPE_USB3_MICRO_AB,
1218 UPC_TYPE_USB3_POWER_B,
1219 UPC_TYPE_C_USB2_ONLY,
1220 UPC_TYPE_C_USB2_SS_SWITCH,
1221 UPC_TYPE_C_USB2_SS,
1222 UPC_TYPE_PROPRIETARY = 0xff,
1223 /*
1224 * The following types are not directly defined in the ACPI
1225 * spec but are used by coreboot to identify a USB device type.
1226 */
1227 UPC_TYPE_INTERNAL = 0xff,
1228 UPC_TYPE_UNUSED,
1229 UPC_TYPE_HUB
1230};
1231
1232enum acpi_ipmi_interface_type {
1233 IPMI_INTERFACE_RESERVED = 0,
1234 IPMI_INTERFACE_KCS,
1235 IPMI_INTERFACE_SMIC,
1236 IPMI_INTERFACE_BT,
1237 IPMI_INTERFACE_SSIF,
1238};
1239
1240#define ACPI_IPMI_PCI_DEVICE_FLAG (1 << 0)
1241#define ACPI_IPMI_INT_TYPE_SCI (1 << 0)
1242#define ACPI_IPMI_INT_TYPE_APIC (1 << 1)
1243
1244/* ACPI IPMI 2.0 */
1245struct acpi_spmi {
1246 acpi_header_t header;
1247 u8 interface_type;
1248 u8 reserved;
1249 u16 specification_revision;
1250 u8 interrupt_type;
1251 u8 gpe;
1252 u8 reserved2;
1253 u8 pci_device_flag;
1254
1255 u32 global_system_interrupt;
1256 acpi_addr_t base_address;
1257 union {
1258 struct {
1259 u8 pci_segment_group;
1260 u8 pci_bus;
1261 u8 pci_device;
1262 u8 pci_function;
1263 };
1264 u8 uid[4];
1265 };
1266 u8 reserved3;
1267} __packed;
1268
Rocky Phaguraeff07132021-01-10 15:42:50 -08001269/* EINJ APEI Standard Definitions */
1270/* EINJ Error Types
1271 Refer to the ACPI spec, EINJ section, for more info on bit definitions
1272*/
1273#define ACPI_EINJ_CPU_CE (1 << 0)
1274#define ACPI_EINJ_CPU_UCE (1 << 1)
1275#define ACPI_EINJ_CPU_UCE_FATAL (1 << 2)
1276#define ACPI_EINJ_MEM_CE (1 << 3)
1277#define ACPI_EINJ_MEM_UCE (1 << 4)
1278#define ACPI_EINJ_MEM_UCE_FATAL (1 << 5)
1279#define ACPI_EINJ_PCIE_CE (1 << 6)
1280#define ACPI_EINJ_PCIE_UCE_NON_FATAL (1 << 7)
1281#define ACPI_EINJ_PCIE_UCE_FATAL (1 << 8)
1282#define ACPI_EINJ_PLATFORM_CE (1 << 9)
1283#define ACPI_EINJ_PLATFORM_UCE (1 << 10)
1284#define ACPI_EINJ_PLATFORM_UCE_FATAL (1 << 11)
1285#define ACPI_EINJ_VENDOR_DEFINED (1 << 31)
1286#define ACPI_EINJ_DEFAULT_CAP (ACPI_EINJ_MEM_CE | ACPI_EINJ_MEM_UCE | \
1287 ACPI_EINJ_PCIE_CE | ACPI_EINJ_PCIE_UCE_FATAL)
1288
1289/* EINJ actions */
1290#define ACTION_COUNT 9
1291#define BEGIN_INJECT_OP 0x00
1292#define GET_TRIGGER_ACTION_TABLE 0x01
1293#define SET_ERROR_TYPE 0x02
1294#define GET_ERROR_TYPE 0x03
1295#define END_INJECT_OP 0x04
1296#define EXECUTE_INJECT_OP 0x05
1297#define CHECK_BUSY_STATUS 0x06
1298#define GET_CMD_STATUS 0x07
1299#define SET_ERROR_TYPE_WITH_ADDRESS 0x08
1300#define TRIGGER_ERROR 0xFF
1301
1302/* EINJ Instructions */
1303#define READ_REGISTER 0x00
1304#define READ_REGISTER_VALUE 0x01
1305#define WRITE_REGISTER 0x02
1306#define WRITE_REGISTER_VALUE 0x03
1307#define NO_OP 0x04
1308
1309/* EINJ (Error Injection Table) */
1310typedef struct acpi_gen_regaddr1 {
1311 u8 space_id; /* Address space ID */
1312 u8 bit_width; /* Register size in bits */
1313 u8 bit_offset; /* Register bit offset */
1314 u8 access_size; /* Access size since ACPI 2.0c */
1315 u64 addr; /* Register address */
1316} __packed acpi_addr64_t;
1317
1318/* Instruction entry */
1319typedef struct acpi_einj_action_table {
1320 u8 action;
1321 u8 instruction;
1322 u16 flags;
1323 acpi_addr64_t reg;
1324 u64 value;
1325 u64 mask;
1326} __packed acpi_einj_action_table_t;
1327
1328typedef struct acpi_injection_header {
1329 u32 einj_header_size;
1330 u32 flags;
1331 u32 entry_count;
1332} __packed acpi_injection_header_t;
1333
1334typedef struct acpi_einj_trigger_table {
1335 u32 header_size;
1336 u32 revision;
1337 u32 table_size;
1338 u32 entry_count;
Elyes Haouasa4aa169a2023-07-30 12:59:50 +02001339 acpi_einj_action_table_t trigger_action[];
Rocky Phaguraeff07132021-01-10 15:42:50 -08001340} __packed acpi_einj_trigger_table_t;
1341
1342typedef struct set_error_type {
1343 u32 errtype;
1344 u32 vendorerrortype;
1345 u32 flags;
1346 u32 apicid;
1347 u64 memaddr;
1348 u64 memrange;
1349 u32 pciesbdf;
1350} __packed set_error_type_t;
1351
1352#define EINJ_PARAM_NUM 6
1353typedef struct acpi_einj_smi {
1354 u64 op_state;
1355 u64 err_inject[EINJ_PARAM_NUM];
1356 u64 trigger_action_table;
1357 u64 err_inj_cap;
1358 u64 op_status;
1359 u64 cmd_sts;
1360 u64 einj_addr;
1361 u64 einj_addr_msk;
1362 set_error_type_t setaddrtable;
1363 u64 reserved[50];
1364} __packed acpi_einj_smi_t;
1365
1366/* EINJ Flags */
1367#define EINJ_DEF_TRIGGER_PORT 0xb2
1368#define FLAG_PRESERVE 0x01
1369#define FLAG_IGNORE 0x00
1370
1371/* EINJ Registers */
1372#define EINJ_REG_MEMORY(address) \
1373 { \
1374 .space_id = ACPI_ADDRESS_SPACE_MEMORY, \
1375 .bit_width = 64, \
1376 .bit_offset = 0, \
1377 .access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS, \
1378 .addr = address}
1379
1380#define EINJ_REG_IO() \
1381 { \
1382 .space_id = ACPI_ADDRESS_SPACE_IO, \
1383 .bit_width = 0x10, \
1384 .bit_offset = 0, \
1385 .access_size = ACPI_ACCESS_SIZE_WORD_ACCESS, \
1386 .addr = EINJ_DEF_TRIGGER_PORT} /* HW dependent code can override this also */
1387
1388typedef struct acpi_einj {
1389 acpi_header_t header;
1390 acpi_injection_header_t inj_header;
1391 acpi_einj_action_table_t action_table[ACTION_COUNT];
1392} __packed acpi_einj_t;
1393
Arthur Heymanse7aaf042023-06-07 12:12:45 +02001394/* SPCR (Serial Port Console Redirection Table) */
1395typedef struct acpi_spcr {
1396 acpi_header_t header;
1397 uint8_t interface_type;
1398 uint8_t reserved[3];
1399 acpi_addr_t base_address;
1400 uint8_t interrupt_type;
1401 uint8_t irq;
1402 uint32_t global_system_interrupt;
1403 uint8_t configured_baudrate;
1404 uint8_t parity;
1405 uint8_t stop_bits;
1406 uint8_t flow_control;
1407 uint8_t terminal_type;
1408 uint8_t language;
1409 uint16_t pci_did;
1410 uint16_t pci_vid;
1411 uint8_t pci_bus;
1412 uint8_t pci_dev;
1413 uint8_t pci_fun;
1414 uint32_t pci_flags;
1415 uint8_t pci_segment;
1416 uint32_t uart_clock;
1417 uint32_t precise_baud_rate;
1418 uint16_t namespace_string_length;
1419 uint16_t namespace_string_offset;
1420 char namespacestring[];
1421} __packed acpi_spcr_t;
1422_Static_assert(sizeof(acpi_spcr_t) == 88, "acpi_spcr_t must have an 88 byte size\n");
1423
Arthur Heymans90464072023-06-07 12:53:50 +02001424#define PC_AT_COMPATIBLE_INTERRUPT (1 << 0)
1425#define IO_APIC_COMPATIBLE_INTERRUPT (1 << 1)
1426#define IO_SAPIC_COMPATIBLE_INTERRUPT (1 << 2)
1427#define ARMH_GIC_COMPATIBLE_INTERRUPT (1 << 3)
1428#define RISCV_PLIC_COMPATIBLE_INTERRUPT (1 << 4)
1429
Arthur Heymans8193eab2023-06-20 10:17:23 +02001430/* GTDT - Generic Timer Description Table (ACPI 5.1) Version 2 */
1431typedef struct acpi_table_gtdt {
1432 acpi_header_t header; /* Common ACPI table header */
Naresh Solanki75f0b602023-09-25 13:59:25 +02001433 u64 counter_block_address;
Arthur Heymans8193eab2023-06-20 10:17:23 +02001434 u32 reserved;
1435 u32 secure_el1_interrupt;
1436 u32 secure_el1_flags;
1437 u32 non_secure_el1_interrupt;
1438 u32 non_secure_el1_flags;
1439 u32 virtual_timer_interrupt;
1440 u32 virtual_timer_flags;
1441 u32 non_secure_el2_interrupt;
1442 u32 non_secure_el2_flags;
1443 u64 counter_read_block_address;
1444 u32 platform_timer_count;
1445 u32 platform_timer_offset;
1446} __packed acpi_gtdt_t;
1447
1448/* Flag Definitions: Timer Block Physical Timers and Virtual timers */
1449
1450#define ACPI_GTDT_INTERRUPT_MODE (1)
1451#define ACPI_GTDT_INTERRUPT_POLARITY (1<<1)
1452#define ACPI_GTDT_ALWAYS_ON (1<<2)
1453
1454struct acpi_gtdt_el2 {
1455 u32 virtual_el2_timer_gsiv;
1456 u32 virtual_el2_timer_flags;
1457};
1458
1459/* Common GTDT subtable header */
1460
1461struct acpi_gtdt_header {
1462 u8 type;
1463 u16 length;
1464} __packed;
1465
1466/* Values for GTDT subtable type above */
1467
1468enum acpi_gtdt_type {
1469 ACPI_GTDT_TYPE_TIMER_BLOCK = 0,
1470 ACPI_GTDT_TYPE_WATCHDOG = 1,
1471 ACPI_GTDT_TYPE_RESERVED = 2 /* 2 and greater are reserved */
1472};
1473
1474/* GTDT Subtables, correspond to Type in struct acpi_gtdt_header */
1475
1476/* 0: Generic Timer Block */
1477
1478struct acpi_gtdt_timer_block {
1479 struct acpi_gtdt_header header;
1480 u8 reserved;
1481 u64 block_address;
1482 u32 timer_count;
1483 u32 timer_offset;
1484} __packed;
1485
1486/* Timer Sub-Structure, one per timer */
1487
1488struct acpi_gtdt_timer_entry {
1489 u8 frame_number;
1490 u8 reserved[3];
1491 u64 base_address;
1492 u64 el0_base_address;
1493 u32 timer_interrupt;
1494 u32 timer_flags;
1495 u32 virtual_timer_interrupt;
1496 u32 virtual_timer_flags;
1497 u32 common_flags;
1498} __packed;
1499
1500/* Flag Definitions: timer_flags and virtual_timer_flags above */
1501
1502#define ACPI_GTDT_GT_IRQ_MODE (1)
1503#define ACPI_GTDT_GT_IRQ_POLARITY (1<<1)
1504
1505/* Flag Definitions: common_flags above */
1506
1507#define ACPI_GTDT_GT_IS_SECURE_TIMER (1)
1508#define ACPI_GTDT_GT_ALWAYS_ON (1<<1)
1509
1510/* 1: SBSA Generic Watchdog Structure */
1511
1512struct acpi_gtdt_watchdog {
1513 struct acpi_gtdt_header header;
1514 u8 reserved;
1515 u64 refresh_frame_address;
1516 u64 control_frame_address;
1517 u32 timer_interrupt;
1518 u32 timer_flags;
1519} __packed;
1520
1521/* Flag Definitions: timer_flags above */
1522
1523#define ACPI_GTDT_WATCHDOG_IRQ_MODE (1)
1524#define ACPI_GTDT_WATCHDOG_IRQ_POLARITY (1<<1)
1525#define ACPI_GTDT_WATCHDOG_SECURE (1<<2)
1526
Arthur Heymans2e7e2d92022-03-03 22:28:27 +01001527uintptr_t get_coreboot_rsdp(void);
Rocky Phaguraeff07132021-01-10 15:42:50 -08001528void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);
1529
Furquan Shaikhe0844632020-05-02 10:23:37 -07001530unsigned long fw_cfg_acpi_tables(unsigned long start);
1531
1532/* These are implemented by the target port or north/southbridge. */
Raul E Rangel6b446b92021-11-19 11:38:35 -07001533void preload_acpi_dsdt(void);
Arthur Heymans7ebebf72023-06-17 14:08:46 +02001534unsigned long write_acpi_tables(const unsigned long addr);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001535unsigned long acpi_fill_madt(unsigned long current);
Arthur Heymanscd46e5f2023-06-22 21:34:16 +02001536unsigned long acpi_arch_fill_madt(acpi_madt_t *madt, unsigned long current);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001537
Furquan Shaikhe0844632020-05-02 10:23:37 -07001538void acpi_fill_fadt(acpi_fadt_t *fadt);
Angel Pons79572e42020-07-13 00:17:43 +02001539void arch_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkkif9aac922020-05-30 16:16:28 +03001540void soc_fill_fadt(acpi_fadt_t *fadt);
Kyösti Mälkki02fd15d2020-06-02 03:34:43 +03001541void mainboard_fill_fadt(acpi_fadt_t *fadt);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001542
Kyösti Mälkki88decca2023-04-28 07:04:34 +03001543void fill_fadt_extended_pm_io(acpi_fadt_t *fadt);
1544
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001545void acpi_fill_gnvs(void);
Kyösti Mälkki3dc17922021-03-16 19:01:48 +02001546void acpi_fill_cnvs(void);
Kyösti Mälkki2ab4a962020-06-30 11:41:47 +03001547
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001548unsigned long acpi_fill_lpit(unsigned long current);
1549
Furquan Shaikhe0844632020-05-02 10:23:37 -07001550/* These can be used by the target port. */
1551u8 acpi_checksum(u8 *table, u32 length);
1552
1553void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
1554
Jonathan Zhang3dcafa82022-05-11 13:11:20 -07001555/* Create CXL Early Discovery Table */
1556void acpi_create_cedt(acpi_cedt_t *cedt,
1557 unsigned long (*acpi_fill_cedt)(unsigned long current));
1558/* Create a CXL Host Bridge Structure for CEDT */
1559int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base);
1560/* Create a CXL Fixed Memory Window Structure for CEDT */
1561int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size,
1562 u8 eniw, u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target);
1563
Arthur Heymans92a3b672023-06-22 21:30:58 +02001564
Kyösti Mälkkic7da0272021-06-08 11:37:08 +03001565int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001566
Kyösti Mälkki2e9f0d32023-04-07 23:05:46 +03001567unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 cpu, u32 apic);
Kyösti Mälkki9ac1fb72023-04-07 22:39:53 +03001568
1569unsigned long acpi_create_madt_lapic_nmis(unsigned long current);
1570
Arthur Heymans3df6cc92023-06-27 16:44:59 +02001571uintptr_t platform_get_gicd_base(void);
1572uintptr_t platform_get_gicr_base(void);
1573
Furquan Shaikhe0844632020-05-02 10:23:37 -07001574int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
Naresh Solanki76835cc2023-01-20 19:13:02 +01001575int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001576int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
1577 u32 flags);
Jonathan Zhang3164b642021-04-21 17:51:31 -07001578/*
1579 * Given the Generic Initiator device's BDF, the proximity domain's ID
1580 * and flag, create Generic Initiator Affinity structure in SRAT.
1581 */
1582int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
1583 u16 seg, u8 bus, u8 dev, u8 func, u32 flags);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001584unsigned long acpi_create_srat_lapics(unsigned long current);
1585void acpi_create_srat(acpi_srat_t *srat,
1586 unsigned long (*acpi_fill_srat)(unsigned long current));
1587
1588void acpi_create_slit(acpi_slit_t *slit,
1589 unsigned long (*acpi_fill_slit)(unsigned long current));
1590
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001591/*
1592 * Create a Memory Proximity Domain Attributes structure for HMAT,
1593 * given proximity domain for the attached initiaor, and
1594 * proximimity domain for the memory.
1595 */
1596int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory);
Martin Roth0949e732021-10-01 14:28:22 -06001597/* Create Heterogeneous Memory Attribute Table */
Jonathan Zhang2a4e1f42021-04-01 11:43:37 -07001598void acpi_create_hmat(acpi_hmat_t *hmat,
1599 unsigned long (*acpi_fill_hmat)(unsigned long current));
1600
Furquan Shaikhe0844632020-05-02 10:23:37 -07001601void acpi_create_vfct(const struct device *device,
1602 acpi_vfct_t *vfct,
1603 unsigned long (*acpi_fill_vfct)(const struct device *device,
1604 acpi_vfct_t *vfct_struct,
1605 unsigned long current));
1606
1607void acpi_create_ipmi(const struct device *device,
1608 struct acpi_spmi *spmi,
1609 const u16 ipmi_revision,
1610 const acpi_addr_t *addr,
1611 const enum acpi_ipmi_interface_type type,
1612 const s8 gpe_interrupt,
1613 const u32 apic_interrupt,
1614 const u32 uid);
1615
1616void acpi_create_ivrs(acpi_ivrs_t *ivrs,
1617 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1618 unsigned long current));
1619
Jason Glenesk61624b22020-11-02 20:06:23 -08001620void acpi_create_crat(struct acpi_crat_header *crat,
1621 unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1622 unsigned long current));
1623
Furquan Shaikhe0844632020-05-02 10:23:37 -07001624unsigned long acpi_write_hpet(const struct device *device, unsigned long start,
1625 acpi_rsdp_t *rsdp);
1626
1627/* cpu/intel/speedstep/acpi.c */
1628void generate_cpu_entries(const struct device *device);
1629
Furquan Shaikhe0844632020-05-02 10:23:37 -07001630unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
Arthur Heymans736d4d22023-06-30 15:37:38 +02001631 const struct device *dev, uint8_t access_size);
1632unsigned long acpi_pl011_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current,
1633 uint64_t base, const char *name);
1634
Furquan Shaikhe0844632020-05-02 10:23:37 -07001635void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
1636 unsigned long (*acpi_fill_dmar)(unsigned long));
1637unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
1638 u16 segment, u64 bar);
1639unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
1640 u64 bar, u64 limit);
1641unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
1642 u16 segment);
1643unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
1644 u32 proximity_domain);
1645unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
1646 const char *device_name);
John Zhao6edbb182021-03-24 11:55:09 -07001647unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags,
John Zhao091532d2021-04-17 16:03:21 -07001648 u16 segment);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001649void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current);
1650void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current);
1651void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current);
John Zhao6edbb182021-03-24 11:55:09 -07001652void acpi_dmar_satc_fixup(unsigned long base, unsigned long current);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001653unsigned long acpi_create_dmar_ds_pci_br(unsigned long current,
1654 u8 bus, u8 dev, u8 fn);
1655unsigned long acpi_create_dmar_ds_pci(unsigned long current,
1656 u8 bus, u8 dev, u8 fn);
1657unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
1658 u8 enumeration_id,
1659 u8 bus, u8 dev, u8 fn);
Arthur Heymansbc8f8592022-12-02 13:17:39 +01001660unsigned long acpi_create_dmar_ds_ioapic_from_hw(unsigned long current,
1661 u32 addr, u8 bus, u8 dev, u8 fn);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001662unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
1663 u8 enumeration_id,
1664 u8 bus, u8 dev, u8 fn);
1665void acpi_write_hest(acpi_hest_t *hest,
1666 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest));
1667
1668unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1669 acpi_hest_esd_t *esd, u16 type, void *data, u16 len);
1670
Michael Niewöhnerf0a44ae2021-01-01 21:04:09 +01001671unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid);
1672
Felix Heldf7dbf4a2021-06-07 16:56:04 +02001673/* chipsets that select ACPI_BERT must implement this function */
Felix Held29405482021-05-28 16:01:57 +02001674enum cb_err acpi_soc_get_bert_region(void **region, size_t *length);
Francois Toguo522e0db2021-01-21 09:55:19 -08001675
Arthur Heymans2e3cb632023-06-30 15:01:08 +02001676void acpi_soc_fill_gtdt(acpi_gtdt_t *gtdt);
1677unsigned long acpi_soc_gtdt_add_timers(uint32_t *count, unsigned long current);
1678unsigned long acpi_gtdt_add_timer_block(unsigned long current, const uint64_t address,
1679 struct acpi_gtdt_timer_entry *timers, size_t number);
1680unsigned long acpi_gtdt_add_watchdog(unsigned long current, uint64_t refresh_frame,
1681 uint64_t control_frame, uint32_t gsiv, uint32_t flags);
1682
Furquan Shaikhe0844632020-05-02 10:23:37 -07001683/* For ACPI S3 support. */
Kyösti Mälkkia4c0e1a2020-06-18 08:28:12 +03001684void __noreturn acpi_resume(void *wake_vec);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001685void mainboard_suspend_resume(void);
1686void *acpi_find_wakeup_vector(void);
1687
1688/* ACPI_Sn assignments are defined to always equal the sleep state numbers */
1689enum {
1690 ACPI_S0 = 0,
1691 ACPI_S1 = 1,
1692 ACPI_S2 = 2,
1693 ACPI_S3 = 3,
1694 ACPI_S4 = 4,
1695 ACPI_S5 = 5,
1696};
1697
1698#if CONFIG(ACPI_INTEL_HARDWARE_SLEEP_VALUES) \
1699 || CONFIG(ACPI_AMD_HARDWARE_SLEEP_VALUES)
1700/* Given the provided PM1 control register return the ACPI sleep type. */
1701static inline int acpi_sleep_from_pm1(uint32_t pm1_cnt)
1702{
1703 switch (((pm1_cnt) & SLP_TYP) >> SLP_TYP_SHIFT) {
1704 case SLP_TYP_S0: return ACPI_S0;
1705 case SLP_TYP_S1: return ACPI_S1;
1706 case SLP_TYP_S3: return ACPI_S3;
1707 case SLP_TYP_S4: return ACPI_S4;
1708 case SLP_TYP_S5: return ACPI_S5;
1709 }
1710 return -1;
1711}
1712#endif
1713
Kyösti Mälkkie0d38682020-06-07 12:01:58 +03001714uint8_t acpi_get_preferred_pm_profile(void);
1715
Furquan Shaikhe0844632020-05-02 10:23:37 -07001716/* Returns ACPI_Sx values. */
1717int acpi_get_sleep_type(void);
1718
1719/* Read and clear GPE status */
1720int acpi_get_gpe(int gpe);
1721
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +03001722/* Once we enter payload, is SMI handler installed and capable of
1723 responding to APM_CNT Advanced Power Management Control commands. */
1724static inline int permanent_smi_handler(void)
1725{
1726 return CONFIG(HAVE_SMI_HANDLER);
1727}
1728
Furquan Shaikhe0844632020-05-02 10:23:37 -07001729static inline int acpi_s3_resume_allowed(void)
1730{
1731 return CONFIG(HAVE_ACPI_RESUME);
1732}
1733
Furquan Shaikhe0844632020-05-02 10:23:37 -07001734static inline int acpi_is_wakeup_s3(void)
1735{
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001736 if (!acpi_s3_resume_allowed())
1737 return 0;
Furquan Shaikhe0844632020-05-02 10:23:37 -07001738
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001739 if (ENV_ROMSTAGE_OR_BEFORE)
1740 return (acpi_get_sleep_type() == ACPI_S3);
1741
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +02001742 return romstage_handoff_is_resume();
Kyösti Mälkki4a3f67a2020-06-18 13:44:29 +03001743}
Furquan Shaikhe0844632020-05-02 10:23:37 -07001744
1745static inline uintptr_t acpi_align_current(uintptr_t current)
1746{
1747 return ALIGN_UP(current, 16);
1748}
1749
1750/* ACPI table revisions should match the revision of the ACPI spec
1751 * supported. This function keeps the table versions synced. This could
1752 * be made into a weak function if there is ever a need to override the
1753 * coreboot default ACPI spec version supported. */
1754int get_acpi_table_revision(enum acpi_tables table);
Elyes Haouas8b950f42022-02-16 12:08:16 +01001755u8 get_acpi_fadt_minor_version(void);
Furquan Shaikhe0844632020-05-02 10:23:37 -07001756
Kyösti Mälkki94e04652020-06-01 13:26:22 +03001757#endif // !defined(__ASSEMBLER__) && !defined(__ACPI__)
Furquan Shaikhe0844632020-05-02 10:23:37 -07001758
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07001759#endif /* __ACPI_ACPI_H__ */