]> git.ipfire.org Git - thirdparty/u-boot.git/blob - include/acpi/acpi_table.h
Merge tag 'u-boot-rockchip-20200501' of https://gitlab.denx.de/u-boot/custodians...
[thirdparty/u-boot.git] / include / acpi / acpi_table.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3 * Helpers for ACPI table generation
4 *
5 * Based on acpi.c from coreboot
6 *
7 * Copyright 2019 Google LLC
8 *
9 * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com>
10 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
11 */
12
13 #ifndef __ACPI_TABLE_H__
14 #define __ACPI_TABLE_H__
15
16 #define RSDP_SIG "RSD PTR " /* RSDP pointer signature */
17 #define OEM_ID "U-BOOT" /* U-Boot */
18 #define OEM_TABLE_ID "U-BOOTBL" /* U-Boot Table */
19 #define ASLC_ID "INTL" /* Intel ASL Compiler */
20
21 #define ACPI_RSDP_REV_ACPI_1_0 0
22 #define ACPI_RSDP_REV_ACPI_2_0 2
23
24 #if !defined(__ACPI__)
25
26 struct acpi_ctx;
27
28 /*
29 * RSDP (Root System Description Pointer)
30 * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
31 */
32 struct acpi_rsdp {
33 char signature[8]; /* RSDP signature */
34 u8 checksum; /* Checksum of the first 20 bytes */
35 char oem_id[6]; /* OEM ID */
36 u8 revision; /* 0 for ACPI 1.0, others 2 */
37 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
38 u32 length; /* Total RSDP length (incl. extended part) */
39 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
40 u8 ext_checksum; /* Checksum of the whole table */
41 u8 reserved[3];
42 };
43
44 /* Generic ACPI header, provided by (almost) all tables */
45 struct __packed acpi_table_header {
46 char signature[4]; /* ACPI signature (4 ASCII characters) */
47 u32 length; /* Table length in bytes (incl. header) */
48 u8 revision; /* Table version (not ACPI version!) */
49 volatile u8 checksum; /* To make sum of entire table == 0 */
50 char oem_id[6]; /* OEM identification */
51 char oem_table_id[8]; /* OEM table identification */
52 u32 oem_revision; /* OEM revision number */
53 char aslc_id[4]; /* ASL compiler vendor ID */
54 u32 aslc_revision; /* ASL compiler revision number */
55 };
56
57 /* A maximum number of 32 ACPI tables ought to be enough for now */
58 #define MAX_ACPI_TABLES 32
59
60 /* RSDT (Root System Description Table) */
61 struct acpi_rsdt {
62 struct acpi_table_header header;
63 u32 entry[MAX_ACPI_TABLES];
64 };
65
66 /* XSDT (Extended System Description Table) */
67 struct acpi_xsdt {
68 struct acpi_table_header header;
69 u64 entry[MAX_ACPI_TABLES];
70 };
71
72 /* FADT Preferred Power Management Profile */
73 enum acpi_pm_profile {
74 ACPI_PM_UNSPECIFIED = 0,
75 ACPI_PM_DESKTOP,
76 ACPI_PM_MOBILE,
77 ACPI_PM_WORKSTATION,
78 ACPI_PM_ENTERPRISE_SERVER,
79 ACPI_PM_SOHO_SERVER,
80 ACPI_PM_APPLIANCE_PC,
81 ACPI_PM_PERFORMANCE_SERVER,
82 ACPI_PM_TABLET
83 };
84
85 /* FADT flags for p_lvl2_lat and p_lvl3_lat */
86 #define ACPI_FADT_C2_NOT_SUPPORTED 101
87 #define ACPI_FADT_C3_NOT_SUPPORTED 1001
88
89 /* FADT Boot Architecture Flags */
90 #define ACPI_FADT_LEGACY_FREE 0x00
91 #define ACPI_FADT_LEGACY_DEVICES BIT(0)
92 #define ACPI_FADT_8042 BIT(1)
93 #define ACPI_FADT_VGA_NOT_PRESENT BIT(2)
94 #define ACPI_FADT_MSI_NOT_SUPPORTED BIT(3)
95 #define ACPI_FADT_NO_PCIE_ASPM_CONTROL BIT(4)
96
97 /* FADT Feature Flags */
98 #define ACPI_FADT_WBINVD BIT(0)
99 #define ACPI_FADT_WBINVD_FLUSH BIT(1)
100 #define ACPI_FADT_C1_SUPPORTED BIT(2)
101 #define ACPI_FADT_C2_MP_SUPPORTED BIT(3)
102 #define ACPI_FADT_POWER_BUTTON BIT(4)
103 #define ACPI_FADT_SLEEP_BUTTON BIT(5)
104 #define ACPI_FADT_FIXED_RTC BIT(6)
105 #define ACPI_FADT_S4_RTC_WAKE BIT(7)
106 #define ACPI_FADT_32BIT_TIMER BIT(8)
107 #define ACPI_FADT_DOCKING_SUPPORTED BIT(9)
108 #define ACPI_FADT_RESET_REGISTER BIT(10)
109 #define ACPI_FADT_SEALED_CASE BIT(11)
110 #define ACPI_FADT_HEADLESS BIT(12)
111 #define ACPI_FADT_SLEEP_TYPE BIT(13)
112 #define ACPI_FADT_PCI_EXPRESS_WAKE BIT(14)
113 #define ACPI_FADT_PLATFORM_CLOCK BIT(15)
114 #define ACPI_FADT_S4_RTC_VALID BIT(16)
115 #define ACPI_FADT_REMOTE_POWER_ON BIT(17)
116 #define ACPI_FADT_APIC_CLUSTER BIT(18)
117 #define ACPI_FADT_APIC_PHYSICAL BIT(19)
118 #define ACPI_FADT_HW_REDUCED_ACPI BIT(20)
119 #define ACPI_FADT_LOW_PWR_IDLE_S0 BIT(21)
120
121 enum acpi_address_space_type {
122 ACPI_ADDRESS_SPACE_MEMORY = 0, /* System memory */
123 ACPI_ADDRESS_SPACE_IO, /* System I/O */
124 ACPI_ADDRESS_SPACE_PCI, /* PCI config space */
125 ACPI_ADDRESS_SPACE_EC, /* Embedded controller */
126 ACPI_ADDRESS_SPACE_SMBUS, /* SMBus */
127 ACPI_ADDRESS_SPACE_PCC = 0x0a, /* Platform Comm. Channel */
128 ACPI_ADDRESS_SPACE_FIXED = 0x7f /* Functional fixed hardware */
129 };
130
131 enum acpi_address_space_size {
132 ACPI_ACCESS_SIZE_UNDEFINED = 0,
133 ACPI_ACCESS_SIZE_BYTE_ACCESS,
134 ACPI_ACCESS_SIZE_WORD_ACCESS,
135 ACPI_ACCESS_SIZE_DWORD_ACCESS,
136 ACPI_ACCESS_SIZE_QWORD_ACCESS
137 };
138
139 struct acpi_gen_regaddr {
140 u8 space_id; /* Address space ID */
141 u8 bit_width; /* Register size in bits */
142 u8 bit_offset; /* Register bit offset */
143 u8 access_size; /* Access size */
144 u32 addrl; /* Register address, low 32 bits */
145 u32 addrh; /* Register address, high 32 bits */
146 };
147
148 /* FADT (Fixed ACPI Description Table) */
149 struct __packed acpi_fadt {
150 struct acpi_table_header header;
151 u32 firmware_ctrl;
152 u32 dsdt;
153 u8 res1;
154 u8 preferred_pm_profile;
155 u16 sci_int;
156 u32 smi_cmd;
157 u8 acpi_enable;
158 u8 acpi_disable;
159 u8 s4bios_req;
160 u8 pstate_cnt;
161 u32 pm1a_evt_blk;
162 u32 pm1b_evt_blk;
163 u32 pm1a_cnt_blk;
164 u32 pm1b_cnt_blk;
165 u32 pm2_cnt_blk;
166 u32 pm_tmr_blk;
167 u32 gpe0_blk;
168 u32 gpe1_blk;
169 u8 pm1_evt_len;
170 u8 pm1_cnt_len;
171 u8 pm2_cnt_len;
172 u8 pm_tmr_len;
173 u8 gpe0_blk_len;
174 u8 gpe1_blk_len;
175 u8 gpe1_base;
176 u8 cst_cnt;
177 u16 p_lvl2_lat;
178 u16 p_lvl3_lat;
179 u16 flush_size;
180 u16 flush_stride;
181 u8 duty_offset;
182 u8 duty_width;
183 u8 day_alrm;
184 u8 mon_alrm;
185 u8 century;
186 u16 iapc_boot_arch;
187 u8 res2;
188 u32 flags;
189 struct acpi_gen_regaddr reset_reg;
190 u8 reset_value;
191 u16 arm_boot_arch;
192 u8 minor_revision;
193 u32 x_firmware_ctl_l;
194 u32 x_firmware_ctl_h;
195 u32 x_dsdt_l;
196 u32 x_dsdt_h;
197 struct acpi_gen_regaddr x_pm1a_evt_blk;
198 struct acpi_gen_regaddr x_pm1b_evt_blk;
199 struct acpi_gen_regaddr x_pm1a_cnt_blk;
200 struct acpi_gen_regaddr x_pm1b_cnt_blk;
201 struct acpi_gen_regaddr x_pm2_cnt_blk;
202 struct acpi_gen_regaddr x_pm_tmr_blk;
203 struct acpi_gen_regaddr x_gpe0_blk;
204 struct acpi_gen_regaddr x_gpe1_blk;
205 };
206
207 /* FADT TABLE Revision values - note these do not match the ACPI revision */
208 #define ACPI_FADT_REV_ACPI_1_0 1
209 #define ACPI_FADT_REV_ACPI_2_0 3
210 #define ACPI_FADT_REV_ACPI_3_0 4
211 #define ACPI_FADT_REV_ACPI_4_0 4
212 #define ACPI_FADT_REV_ACPI_5_0 5
213 #define ACPI_FADT_REV_ACPI_6_0 6
214
215 /* MADT TABLE Revision values - note these do not match the ACPI revision */
216 #define ACPI_MADT_REV_ACPI_3_0 2
217 #define ACPI_MADT_REV_ACPI_4_0 3
218 #define ACPI_MADT_REV_ACPI_5_0 3
219 #define ACPI_MADT_REV_ACPI_6_0 5
220
221 #define ACPI_MCFG_REV_ACPI_3_0 1
222
223 /* IVRS Revision Field */
224 #define IVRS_FORMAT_FIXED 0x01 /* Type 10h & 11h only */
225 #define IVRS_FORMAT_MIXED 0x02 /* Type 10h, 11h, & 40h */
226
227 /* FACS flags */
228 #define ACPI_FACS_S4BIOS_F BIT(0)
229 #define ACPI_FACS_64BIT_WAKE_F BIT(1)
230
231 /* FACS (Firmware ACPI Control Structure) */
232 struct acpi_facs {
233 char signature[4]; /* "FACS" */
234 u32 length; /* Length in bytes (>= 64) */
235 u32 hardware_signature; /* Hardware signature */
236 u32 firmware_waking_vector; /* Firmware waking vector */
237 u32 global_lock; /* Global lock */
238 u32 flags; /* FACS flags */
239 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
240 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
241 u8 version; /* Version 2 */
242 u8 res1[3];
243 u32 ospm_flags; /* OSPM enabled flags */
244 u8 res2[24];
245 };
246
247 /* MADT flags */
248 #define ACPI_MADT_PCAT_COMPAT BIT(0)
249
250 /* MADT (Multiple APIC Description Table) */
251 struct acpi_madt {
252 struct acpi_table_header header;
253 u32 lapic_addr; /* Local APIC address */
254 u32 flags; /* Multiple APIC flags */
255 };
256
257 /* MADT: APIC Structure Type*/
258 enum acpi_apic_types {
259 ACPI_APIC_LAPIC = 0, /* Processor local APIC */
260 ACPI_APIC_IOAPIC, /* I/O APIC */
261 ACPI_APIC_IRQ_SRC_OVERRIDE, /* Interrupt source override */
262 ACPI_APIC_NMI_SRC, /* NMI source */
263 ACPI_APIC_LAPIC_NMI, /* Local APIC NMI */
264 ACPI_APIC_LAPIC_ADDR_OVERRIDE, /* Local APIC address override */
265 ACPI_APIC_IOSAPIC, /* I/O SAPIC */
266 ACPI_APIC_LSAPIC, /* Local SAPIC */
267 ACPI_APIC_PLATFORM_IRQ_SRC, /* Platform interrupt sources */
268 ACPI_APIC_LX2APIC, /* Processor local x2APIC */
269 ACPI_APIC_LX2APIC_NMI, /* Local x2APIC NMI */
270 };
271
272 /* MADT: Processor Local APIC Structure */
273
274 #define LOCAL_APIC_FLAG_ENABLED BIT(0)
275
276 struct acpi_madt_lapic {
277 u8 type; /* Type (0) */
278 u8 length; /* Length in bytes (8) */
279 u8 processor_id; /* ACPI processor ID */
280 u8 apic_id; /* Local APIC ID */
281 u32 flags; /* Local APIC flags */
282 };
283
284 /* MADT: I/O APIC Structure */
285 struct acpi_madt_ioapic {
286 u8 type; /* Type (1) */
287 u8 length; /* Length in bytes (12) */
288 u8 ioapic_id; /* I/O APIC ID */
289 u8 reserved;
290 u32 ioapic_addr; /* I/O APIC address */
291 u32 gsi_base; /* Global system interrupt base */
292 };
293
294 /* MADT: Interrupt Source Override Structure */
295 struct __packed acpi_madt_irqoverride {
296 u8 type; /* Type (2) */
297 u8 length; /* Length in bytes (10) */
298 u8 bus; /* ISA (0) */
299 u8 source; /* Bus-relative int. source (IRQ) */
300 u32 gsirq; /* Global system interrupt */
301 u16 flags; /* MPS INTI flags */
302 };
303
304 /* MADT: Local APIC NMI Structure */
305 struct __packed acpi_madt_lapic_nmi {
306 u8 type; /* Type (4) */
307 u8 length; /* Length in bytes (6) */
308 u8 processor_id; /* ACPI processor ID */
309 u16 flags; /* MPS INTI flags */
310 u8 lint; /* Local APIC LINT# */
311 };
312
313 /* MCFG (PCI Express MMIO config space BAR description table) */
314 struct acpi_mcfg {
315 struct acpi_table_header header;
316 u8 reserved[8];
317 };
318
319 struct acpi_mcfg_mmconfig {
320 u32 base_address_l;
321 u32 base_address_h;
322 u16 pci_segment_group_number;
323 u8 start_bus_number;
324 u8 end_bus_number;
325 u8 reserved[4];
326 };
327
328 /* PM1_CNT bit defines */
329 #define PM1_CNT_SCI_EN BIT(0)
330
331 /* ACPI global NVS structure */
332 struct acpi_global_nvs;
333
334 /* CSRT (Core System Resource Table) */
335 struct acpi_csrt {
336 struct acpi_table_header header;
337 };
338
339 struct acpi_csrt_group {
340 u32 length;
341 u32 vendor_id;
342 u32 subvendor_id;
343 u16 device_id;
344 u16 subdevice_id;
345 u16 revision;
346 u16 reserved;
347 u32 shared_info_length;
348 };
349
350 struct acpi_csrt_shared_info {
351 u16 major_version;
352 u16 minor_version;
353 u32 mmio_base_low;
354 u32 mmio_base_high;
355 u32 gsi_interrupt;
356 u8 interrupt_polarity;
357 u8 interrupt_mode;
358 u8 num_channels;
359 u8 dma_address_width;
360 u16 base_request_line;
361 u16 num_handshake_signals;
362 u32 max_block_size;
363 };
364
365 enum dmar_type {
366 DMAR_DRHD = 0,
367 DMAR_RMRR = 1,
368 DMAR_ATSR = 2,
369 DMAR_RHSA = 3,
370 DMAR_ANDD = 4
371 };
372
373 enum {
374 DRHD_INCLUDE_PCI_ALL = BIT(0)
375 };
376
377 enum dmar_flags {
378 DMAR_INTR_REMAP = BIT(0),
379 DMAR_X2APIC_OPT_OUT = BIT(1),
380 DMAR_CTRL_PLATFORM_OPT_IN_FLAG = BIT(2),
381 };
382
383 struct dmar_entry {
384 u16 type;
385 u16 length;
386 u8 flags;
387 u8 reserved;
388 u16 segment;
389 u64 bar;
390 };
391
392 struct dmar_rmrr_entry {
393 u16 type;
394 u16 length;
395 u16 reserved;
396 u16 segment;
397 u64 bar;
398 u64 limit;
399 };
400
401 /* DMAR (DMA Remapping Reporting Structure) */
402 struct __packed acpi_dmar {
403 struct acpi_table_header header;
404 u8 host_address_width;
405 u8 flags;
406 u8 reserved[10];
407 struct dmar_entry structure[0];
408 };
409
410 /* DBG2 definitions are partially used for SPCR interface_type */
411
412 /* Types for port_type field */
413
414 #define ACPI_DBG2_SERIAL_PORT 0x8000
415 #define ACPI_DBG2_1394_PORT 0x8001
416 #define ACPI_DBG2_USB_PORT 0x8002
417 #define ACPI_DBG2_NET_PORT 0x8003
418
419 /* Subtypes for port_subtype field */
420
421 #define ACPI_DBG2_16550_COMPATIBLE 0x0000
422 #define ACPI_DBG2_16550_SUBSET 0x0001
423 #define ACPI_DBG2_ARM_PL011 0x0003
424 #define ACPI_DBG2_ARM_SBSA_32BIT 0x000D
425 #define ACPI_DBG2_ARM_SBSA_GENERIC 0x000E
426 #define ACPI_DBG2_ARM_DCC 0x000F
427 #define ACPI_DBG2_BCM2835 0x0010
428
429 #define ACPI_DBG2_1394_STANDARD 0x0000
430
431 #define ACPI_DBG2_USB_XHCI 0x0000
432 #define ACPI_DBG2_USB_EHCI 0x0001
433
434 #define ACPI_DBG2_UNKNOWN 0x00FF
435
436 /* SPCR (Serial Port Console Redirection table) */
437 struct __packed acpi_spcr {
438 struct acpi_table_header header;
439 u8 interface_type;
440 u8 reserved[3];
441 struct acpi_gen_regaddr serial_port;
442 u8 interrupt_type;
443 u8 pc_interrupt;
444 u32 interrupt; /* Global system interrupt */
445 u8 baud_rate;
446 u8 parity;
447 u8 stop_bits;
448 u8 flow_control;
449 u8 terminal_type;
450 u8 reserved1;
451 u16 pci_device_id; /* Must be 0xffff if not PCI device */
452 u16 pci_vendor_id; /* Must be 0xffff if not PCI device */
453 u8 pci_bus;
454 u8 pci_device;
455 u8 pci_function;
456 u32 pci_flags;
457 u8 pci_segment;
458 u32 reserved2;
459 };
460
461 /* Tables defined/reserved by ACPI and generated by U-Boot */
462 enum acpi_tables {
463 ACPITAB_BERT,
464 ACPITAB_DBG2,
465 ACPITAB_DMAR,
466 ACPITAB_DSDT,
467 ACPITAB_ECDT,
468 ACPITAB_FACS,
469 ACPITAB_FADT,
470 ACPITAB_HEST,
471 ACPITAB_HPET,
472 ACPITAB_IVRS,
473 ACPITAB_MADT,
474 ACPITAB_MCFG,
475 ACPITAB_NHLT,
476 ACPITAB_RSDP,
477 ACPITAB_RSDT,
478 ACPITAB_SLIT,
479 ACPITAB_SPCR,
480 ACPITAB_SPMI,
481 ACPITAB_SRAT,
482 ACPITAB_SSDT,
483 ACPITAB_TCPA,
484 ACPITAB_TPM2,
485 ACPITAB_VFCT,
486 ACPITAB_XSDT,
487
488 ACPITAB_COUNT,
489 };
490
491 /**
492 * acpi_get_table_revision() - Get the revision number generated for a table
493 *
494 * This keeps the version-number information in one place
495 *
496 * @table: ACPI table to check
497 * @return version number that U-Boot generates
498 */
499 int acpi_get_table_revision(enum acpi_tables table);
500
501 /**
502 * acpi_create_dmar() - Create a DMA Remapping Reporting (DMAR) table
503 *
504 * @dmar: Place to put the table
505 * @flags: DMAR flags to use
506 * @return 0 if OK, -ve on error
507 */
508 int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);
509
510 /**
511 * acpi_fill_header() - Set up a new table header
512 *
513 * This sets all fields except length, revision, checksum and aslc_revision
514 *
515 * @header: ACPI header to update
516 * @signature: Table signature to use (4 characters)
517 */
518 void acpi_fill_header(struct acpi_table_header *header, char *signature);
519
520 /**
521 * acpi_align() - Align the ACPI output pointer to a 16-byte boundary
522 *
523 * @ctx: ACPI context
524 */
525 void acpi_align(struct acpi_ctx *ctx);
526
527 /**
528 * acpi_align64() - Align the ACPI output pointer to a 64-byte boundary
529 *
530 * @ctx: ACPI context
531 */
532 void acpi_align64(struct acpi_ctx *ctx);
533
534 /**
535 * acpi_inc() - Increment the ACPI output pointer by a bit
536 *
537 * The pointer is NOT aligned afterwards.
538 *
539 * @ctx: ACPI context
540 * @amount: Amount to increment by
541 */
542 void acpi_inc(struct acpi_ctx *ctx, uint amount);
543
544 /**
545 * acpi_inc_align() - Increment the ACPI output pointer by a bit and align
546 *
547 * The pointer is aligned afterwards to a 16-byte boundary
548 *
549 * @ctx: ACPI context
550 * @amount: Amount to increment by
551 */
552 void acpi_inc_align(struct acpi_ctx *ctx, uint amount);
553
554 /**
555 * acpi_add_table() - Add a new table to the RSDP and XSDT
556 *
557 * @ctx: ACPI context
558 * @table: Table to add
559 * @return 0 if OK, -E2BIG if too many tables
560 */
561 int acpi_add_table(struct acpi_ctx *ctx, void *table);
562
563 /**
564 * acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XSDT
565 *
566 * Set up the context with the given start position. Some basic tables are
567 * always needed, so set them up as well.
568 *
569 * @ctx: Context to set up
570 */
571 void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start);
572
573 #endif /* !__ACPI__*/
574
575 #include <asm/acpi_table.h>
576
577 #endif /* __ACPI_TABLE_H__ */