x86: Move acpi_table header to main include/ directory
[oweals/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 /*
25  * RSDP (Root System Description Pointer)
26  * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
27  */
28 struct acpi_rsdp {
29         char signature[8];      /* RSDP signature */
30         u8 checksum;            /* Checksum of the first 20 bytes */
31         char oem_id[6];         /* OEM ID */
32         u8 revision;            /* 0 for ACPI 1.0, others 2 */
33         u32 rsdt_address;       /* Physical address of RSDT (32 bits) */
34         u32 length;             /* Total RSDP length (incl. extended part) */
35         u64 xsdt_address;       /* Physical address of XSDT (64 bits) */
36         u8 ext_checksum;        /* Checksum of the whole table */
37         u8 reserved[3];
38 };
39
40 /* Generic ACPI header, provided by (almost) all tables */
41 struct __packed acpi_table_header {
42         char signature[4];      /* ACPI signature (4 ASCII characters) */
43         u32 length;             /* Table length in bytes (incl. header) */
44         u8 revision;            /* Table version (not ACPI version!) */
45         volatile u8 checksum;   /* To make sum of entire table == 0 */
46         char oem_id[6];         /* OEM identification */
47         char oem_table_id[8];   /* OEM table identification */
48         u32 oem_revision;       /* OEM revision number */
49         char aslc_id[4];        /* ASL compiler vendor ID */
50         u32 aslc_revision;      /* ASL compiler revision number */
51 };
52
53 /* A maximum number of 32 ACPI tables ought to be enough for now */
54 #define MAX_ACPI_TABLES         32
55
56 /* RSDT (Root System Description Table) */
57 struct acpi_rsdt {
58         struct acpi_table_header header;
59         u32 entry[MAX_ACPI_TABLES];
60 };
61
62 /* XSDT (Extended System Description Table) */
63 struct acpi_xsdt {
64         struct acpi_table_header header;
65         u64 entry[MAX_ACPI_TABLES];
66 };
67
68 /* FADT Preferred Power Management Profile */
69 enum acpi_pm_profile {
70         ACPI_PM_UNSPECIFIED = 0,
71         ACPI_PM_DESKTOP,
72         ACPI_PM_MOBILE,
73         ACPI_PM_WORKSTATION,
74         ACPI_PM_ENTERPRISE_SERVER,
75         ACPI_PM_SOHO_SERVER,
76         ACPI_PM_APPLIANCE_PC,
77         ACPI_PM_PERFORMANCE_SERVER,
78         ACPI_PM_TABLET
79 };
80
81 /* FADT flags for p_lvl2_lat and p_lvl3_lat */
82 #define ACPI_FADT_C2_NOT_SUPPORTED      101
83 #define ACPI_FADT_C3_NOT_SUPPORTED      1001
84
85 /* FADT Boot Architecture Flags */
86 #define ACPI_FADT_LEGACY_FREE           0x00
87 #define ACPI_FADT_LEGACY_DEVICES        BIT(0)
88 #define ACPI_FADT_8042                  BIT(1)
89 #define ACPI_FADT_VGA_NOT_PRESENT       BIT(2)
90 #define ACPI_FADT_MSI_NOT_SUPPORTED     BIT(3)
91 #define ACPI_FADT_NO_PCIE_ASPM_CONTROL  BIT(4)
92
93 /* FADT Feature Flags */
94 #define ACPI_FADT_WBINVD                BIT(0)
95 #define ACPI_FADT_WBINVD_FLUSH          BIT(1)
96 #define ACPI_FADT_C1_SUPPORTED          BIT(2)
97 #define ACPI_FADT_C2_MP_SUPPORTED       BIT(3)
98 #define ACPI_FADT_POWER_BUTTON          BIT(4)
99 #define ACPI_FADT_SLEEP_BUTTON          BIT(5)
100 #define ACPI_FADT_FIXED_RTC             BIT(6)
101 #define ACPI_FADT_S4_RTC_WAKE           BIT(7)
102 #define ACPI_FADT_32BIT_TIMER           BIT(8)
103 #define ACPI_FADT_DOCKING_SUPPORTED     BIT(9)
104 #define ACPI_FADT_RESET_REGISTER        BIT(10)
105 #define ACPI_FADT_SEALED_CASE           BIT(11)
106 #define ACPI_FADT_HEADLESS              BIT(12)
107 #define ACPI_FADT_SLEEP_TYPE            BIT(13)
108 #define ACPI_FADT_PCI_EXPRESS_WAKE      BIT(14)
109 #define ACPI_FADT_PLATFORM_CLOCK        BIT(15)
110 #define ACPI_FADT_S4_RTC_VALID          BIT(16)
111 #define ACPI_FADT_REMOTE_POWER_ON       BIT(17)
112 #define ACPI_FADT_APIC_CLUSTER          BIT(18)
113 #define ACPI_FADT_APIC_PHYSICAL         BIT(19)
114 #define ACPI_FADT_HW_REDUCED_ACPI       BIT(20)
115 #define ACPI_FADT_LOW_PWR_IDLE_S0       BIT(21)
116
117 enum acpi_address_space_type {
118         ACPI_ADDRESS_SPACE_MEMORY = 0,  /* System memory */
119         ACPI_ADDRESS_SPACE_IO,          /* System I/O */
120         ACPI_ADDRESS_SPACE_PCI,         /* PCI config space */
121         ACPI_ADDRESS_SPACE_EC,          /* Embedded controller */
122         ACPI_ADDRESS_SPACE_SMBUS,       /* SMBus */
123         ACPI_ADDRESS_SPACE_PCC = 0x0a,  /* Platform Comm. Channel */
124         ACPI_ADDRESS_SPACE_FIXED = 0x7f /* Functional fixed hardware */
125 };
126
127 enum acpi_address_space_size {
128         ACPI_ACCESS_SIZE_UNDEFINED = 0,
129         ACPI_ACCESS_SIZE_BYTE_ACCESS,
130         ACPI_ACCESS_SIZE_WORD_ACCESS,
131         ACPI_ACCESS_SIZE_DWORD_ACCESS,
132         ACPI_ACCESS_SIZE_QWORD_ACCESS
133 };
134
135 struct acpi_gen_regaddr {
136         u8 space_id;    /* Address space ID */
137         u8 bit_width;   /* Register size in bits */
138         u8 bit_offset;  /* Register bit offset */
139         u8 access_size; /* Access size */
140         u32 addrl;      /* Register address, low 32 bits */
141         u32 addrh;      /* Register address, high 32 bits */
142 };
143
144 /* FADT (Fixed ACPI Description Table) */
145 struct __packed acpi_fadt {
146         struct acpi_table_header header;
147         u32 firmware_ctrl;
148         u32 dsdt;
149         u8 res1;
150         u8 preferred_pm_profile;
151         u16 sci_int;
152         u32 smi_cmd;
153         u8 acpi_enable;
154         u8 acpi_disable;
155         u8 s4bios_req;
156         u8 pstate_cnt;
157         u32 pm1a_evt_blk;
158         u32 pm1b_evt_blk;
159         u32 pm1a_cnt_blk;
160         u32 pm1b_cnt_blk;
161         u32 pm2_cnt_blk;
162         u32 pm_tmr_blk;
163         u32 gpe0_blk;
164         u32 gpe1_blk;
165         u8 pm1_evt_len;
166         u8 pm1_cnt_len;
167         u8 pm2_cnt_len;
168         u8 pm_tmr_len;
169         u8 gpe0_blk_len;
170         u8 gpe1_blk_len;
171         u8 gpe1_base;
172         u8 cst_cnt;
173         u16 p_lvl2_lat;
174         u16 p_lvl3_lat;
175         u16 flush_size;
176         u16 flush_stride;
177         u8 duty_offset;
178         u8 duty_width;
179         u8 day_alrm;
180         u8 mon_alrm;
181         u8 century;
182         u16 iapc_boot_arch;
183         u8 res2;
184         u32 flags;
185         struct acpi_gen_regaddr reset_reg;
186         u8 reset_value;
187         u16 arm_boot_arch;
188         u8 minor_revision;
189         u32 x_firmware_ctl_l;
190         u32 x_firmware_ctl_h;
191         u32 x_dsdt_l;
192         u32 x_dsdt_h;
193         struct acpi_gen_regaddr x_pm1a_evt_blk;
194         struct acpi_gen_regaddr x_pm1b_evt_blk;
195         struct acpi_gen_regaddr x_pm1a_cnt_blk;
196         struct acpi_gen_regaddr x_pm1b_cnt_blk;
197         struct acpi_gen_regaddr x_pm2_cnt_blk;
198         struct acpi_gen_regaddr x_pm_tmr_blk;
199         struct acpi_gen_regaddr x_gpe0_blk;
200         struct acpi_gen_regaddr x_gpe1_blk;
201 };
202
203 /* FACS flags */
204 #define ACPI_FACS_S4BIOS_F              BIT(0)
205 #define ACPI_FACS_64BIT_WAKE_F          BIT(1)
206
207 /* FACS (Firmware ACPI Control Structure) */
208 struct acpi_facs {
209         char signature[4];              /* "FACS" */
210         u32 length;                     /* Length in bytes (>= 64) */
211         u32 hardware_signature;         /* Hardware signature */
212         u32 firmware_waking_vector;     /* Firmware waking vector */
213         u32 global_lock;                /* Global lock */
214         u32 flags;                      /* FACS flags */
215         u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
216         u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
217         u8 version;                     /* Version 2 */
218         u8 res1[3];
219         u32 ospm_flags;                 /* OSPM enabled flags */
220         u8 res2[24];
221 };
222
223 /* MADT flags */
224 #define ACPI_MADT_PCAT_COMPAT   BIT(0)
225
226 /* MADT (Multiple APIC Description Table) */
227 struct acpi_madt {
228         struct acpi_table_header header;
229         u32 lapic_addr;                 /* Local APIC address */
230         u32 flags;                      /* Multiple APIC flags */
231 };
232
233 /* MADT: APIC Structure Type*/
234 enum acpi_apic_types {
235         ACPI_APIC_LAPIC = 0,            /* Processor local APIC */
236         ACPI_APIC_IOAPIC,               /* I/O APIC */
237         ACPI_APIC_IRQ_SRC_OVERRIDE,     /* Interrupt source override */
238         ACPI_APIC_NMI_SRC,              /* NMI source */
239         ACPI_APIC_LAPIC_NMI,            /* Local APIC NMI */
240         ACPI_APIC_LAPIC_ADDR_OVERRIDE,  /* Local APIC address override */
241         ACPI_APIC_IOSAPIC,              /* I/O SAPIC */
242         ACPI_APIC_LSAPIC,               /* Local SAPIC */
243         ACPI_APIC_PLATFORM_IRQ_SRC,     /* Platform interrupt sources */
244         ACPI_APIC_LX2APIC,              /* Processor local x2APIC */
245         ACPI_APIC_LX2APIC_NMI,          /* Local x2APIC NMI */
246 };
247
248 /* MADT: Processor Local APIC Structure */
249
250 #define LOCAL_APIC_FLAG_ENABLED         BIT(0)
251
252 struct acpi_madt_lapic {
253         u8 type;                /* Type (0) */
254         u8 length;              /* Length in bytes (8) */
255         u8 processor_id;        /* ACPI processor ID */
256         u8 apic_id;             /* Local APIC ID */
257         u32 flags;              /* Local APIC flags */
258 };
259
260 /* MADT: I/O APIC Structure */
261 struct acpi_madt_ioapic {
262         u8 type;                /* Type (1) */
263         u8 length;              /* Length in bytes (12) */
264         u8 ioapic_id;           /* I/O APIC ID */
265         u8 reserved;
266         u32 ioapic_addr;        /* I/O APIC address */
267         u32 gsi_base;           /* Global system interrupt base */
268 };
269
270 /* MADT: Interrupt Source Override Structure */
271 struct __packed acpi_madt_irqoverride {
272         u8 type;                /* Type (2) */
273         u8 length;              /* Length in bytes (10) */
274         u8 bus;                 /* ISA (0) */
275         u8 source;              /* Bus-relative int. source (IRQ) */
276         u32 gsirq;              /* Global system interrupt */
277         u16 flags;              /* MPS INTI flags */
278 };
279
280 /* MADT: Local APIC NMI Structure */
281 struct __packed acpi_madt_lapic_nmi {
282         u8 type;                /* Type (4) */
283         u8 length;              /* Length in bytes (6) */
284         u8 processor_id;        /* ACPI processor ID */
285         u16 flags;              /* MPS INTI flags */
286         u8 lint;                /* Local APIC LINT# */
287 };
288
289 /* MCFG (PCI Express MMIO config space BAR description table) */
290 struct acpi_mcfg {
291         struct acpi_table_header header;
292         u8 reserved[8];
293 };
294
295 struct acpi_mcfg_mmconfig {
296         u32 base_address_l;
297         u32 base_address_h;
298         u16 pci_segment_group_number;
299         u8 start_bus_number;
300         u8 end_bus_number;
301         u8 reserved[4];
302 };
303
304 /* PM1_CNT bit defines */
305 #define PM1_CNT_SCI_EN          BIT(0)
306
307 /* ACPI global NVS structure */
308 struct acpi_global_nvs;
309
310 /* CSRT (Core System Resource Table) */
311 struct acpi_csrt {
312         struct acpi_table_header header;
313 };
314
315 struct acpi_csrt_group {
316         u32 length;
317         u32 vendor_id;
318         u32 subvendor_id;
319         u16 device_id;
320         u16 subdevice_id;
321         u16 revision;
322         u16 reserved;
323         u32 shared_info_length;
324 };
325
326 struct acpi_csrt_shared_info {
327         u16 major_version;
328         u16 minor_version;
329         u32 mmio_base_low;
330         u32 mmio_base_high;
331         u32 gsi_interrupt;
332         u8 interrupt_polarity;
333         u8 interrupt_mode;
334         u8 num_channels;
335         u8 dma_address_width;
336         u16 base_request_line;
337         u16 num_handshake_signals;
338         u32 max_block_size;
339 };
340
341 /* DBG2 definitions are partially used for SPCR interface_type */
342
343 /* Types for port_type field */
344
345 #define ACPI_DBG2_SERIAL_PORT           0x8000
346 #define ACPI_DBG2_1394_PORT             0x8001
347 #define ACPI_DBG2_USB_PORT              0x8002
348 #define ACPI_DBG2_NET_PORT              0x8003
349
350 /* Subtypes for port_subtype field */
351
352 #define ACPI_DBG2_16550_COMPATIBLE      0x0000
353 #define ACPI_DBG2_16550_SUBSET          0x0001
354 #define ACPI_DBG2_ARM_PL011             0x0003
355 #define ACPI_DBG2_ARM_SBSA_32BIT        0x000D
356 #define ACPI_DBG2_ARM_SBSA_GENERIC      0x000E
357 #define ACPI_DBG2_ARM_DCC               0x000F
358 #define ACPI_DBG2_BCM2835               0x0010
359
360 #define ACPI_DBG2_1394_STANDARD         0x0000
361
362 #define ACPI_DBG2_USB_XHCI              0x0000
363 #define ACPI_DBG2_USB_EHCI              0x0001
364
365 #define ACPI_DBG2_UNKNOWN               0x00FF
366
367 /* SPCR (Serial Port Console Redirection table) */
368 struct __packed acpi_spcr {
369         struct acpi_table_header header;
370         u8 interface_type;
371         u8 reserved[3];
372         struct acpi_gen_regaddr serial_port;
373         u8 interrupt_type;
374         u8 pc_interrupt;
375         u32 interrupt;          /* Global system interrupt */
376         u8 baud_rate;
377         u8 parity;
378         u8 stop_bits;
379         u8 flow_control;
380         u8 terminal_type;
381         u8 reserved1;
382         u16 pci_device_id;      /* Must be 0xffff if not PCI device */
383         u16 pci_vendor_id;      /* Must be 0xffff if not PCI device */
384         u8 pci_bus;
385         u8 pci_device;
386         u8 pci_function;
387         u32 pci_flags;
388         u8 pci_segment;
389         u32 reserved2;
390 };
391
392 #include <asm/acpi_table.h>
393
394 #endif /* __ACPI_TABLE_H__ */