blob: 418870e3b474023993ee3b1d8fc7e82fd86e8a46 [file] [log] [blame]
Saket Sinha331141a2015-08-22 12:20:55 +05301/*
2 * Based on acpi.c from coreboot
3 *
4 * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
Bin Meng6a421582016-05-07 07:46:21 -07009#define RSDP_SIG "RSD PTR " /* RSDP pointer signature */
10#define OEM_ID "U-BOOT" /* U-Boot */
11#define OEM_TABLE_ID "U-BOOTBL" /* U-Boot Table */
12#define ASLC_ID "INTL" /* Intel ASL Compiler */
Saket Sinha331141a2015-08-22 12:20:55 +053013
14#define OEM_REVISION 42
15#define ASL_COMPILER_REVISION 42
16
Saket Sinha331141a2015-08-22 12:20:55 +053017#define ACPI_REV_ACPI_1_0 1
18#define ACPI_REV_ACPI_2_0 1
19#define ACPI_REV_ACPI_3_0 2
20#define ACPI_REV_ACPI_4_0 3
21#define ACPI_REV_ACPI_5_0 5
22
23#define ACPI_RSDP_REV_ACPI_1_0 0
24#define ACPI_RSDP_REV_ACPI_2_0 2
25
26typedef struct acpi_gen_regaddr {
27 u8 space_id; /* Address space ID */
28 u8 bit_width; /* Register size in bits */
29 u8 bit_offset; /* Register bit offset */
30 union {
31 /* Reserved in ACPI 2.0 - 2.0b */
32 u8 resv;
33 /* Access size in ACPI 2.0c/3.0/4.0/5.0 */
34 u8 access_size;
35 };
36 u32 addrl; /* Register address, low 32 bits */
37 u32 addrh; /* Register address, high 32 bits */
38} acpi_addr_t;
39
40
41/*
42 * RSDP (Root System Description Pointer)
43 * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
44 */
45struct acpi_rsdp {
46 char signature[8]; /* RSDP signature */
47 u8 checksum; /* Checksum of the first 20 bytes */
48 char oem_id[6]; /* OEM ID */
49 u8 revision; /* 0 for ACPI 1.0, 2 for ACPI 2.0/3.0/4.0 */
50 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
51 u32 length; /* Total RSDP length (incl. extended part) */
52 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
53 u8 ext_checksum; /* Checksum of the whole table */
54 u8 reserved[3];
55};
56
57enum acpi_address_space_type {
58 ACPI_ADDRESS_SPACE_MEMORY = 0, /* System memory */
59 ACPI_ADDRESS_SPACE_IO, /* System I/O */
60 ACPI_ADDRESS_SPACE_PCI, /* PCI config space */
61 ACPI_ADDRESS_SPACE_EC, /* Embedded controller */
62 ACPI_ADDRESS_SPACE_SMBUS, /* SMBus */
63 ACPI_ADDRESS_SPACE_PCC = 0x0a, /* Platform Comm. Channel */
64 ACPI_ADDRESS_SPACE_FIXED = 0x7f /* Functional fixed hardware */
65};
66
Saket Sinha331141a2015-08-22 12:20:55 +053067/* Access size definitions for Generic address structure */
68enum acpi_address_space_size {
69 ACPI_ACCESS_SIZE_UNDEFINED = 0, /* Undefined (legacy reasons) */
70 ACPI_ACCESS_SIZE_BYTE_ACCESS = 1,
71 ACPI_ACCESS_SIZE_WORD_ACCESS = 2,
72 ACPI_ACCESS_SIZE_DWORD_ACCESS = 3,
73 ACPI_ACCESS_SIZE_QWORD_ACCESS = 4
74};
75
76/* Generic ACPI header, provided by (almost) all tables */
Bin Meng6a421582016-05-07 07:46:21 -070077struct acpi_table_header {
Saket Sinha331141a2015-08-22 12:20:55 +053078 char signature[4]; /* ACPI signature (4 ASCII characters) */
79 u32 length; /* Table length in bytes (incl. header) */
80 u8 revision; /* Table version (not ACPI version!) */
81 volatile u8 checksum; /* To make sum of entire table == 0 */
82 char oem_id[6]; /* OEM identification */
83 char oem_table_id[8]; /* OEM table identification */
84 u32 oem_revision; /* OEM revision number */
Bin Meng6a421582016-05-07 07:46:21 -070085 char aslc_id[4]; /* ASL compiler vendor ID */
86 u32 aslc_revision; /* ASL compiler revision number */
87};
Saket Sinha331141a2015-08-22 12:20:55 +053088
89/* A maximum number of 32 ACPI tables ought to be enough for now */
90#define MAX_ACPI_TABLES 32
91
92/* RSDT (Root System Description Table) */
93struct acpi_rsdt {
94 struct acpi_table_header header;
95 u32 entry[MAX_ACPI_TABLES];
96};
97
98/* XSDT (Extended System Description Table) */
99struct acpi_xsdt {
100 struct acpi_table_header header;
101 u64 entry[MAX_ACPI_TABLES];
102};
103
104/* MCFG (PCI Express MMIO config space BAR description table) */
105struct acpi_mcfg {
106 struct acpi_table_header header;
107 u8 reserved[8];
108};
109
110struct acpi_mcfg_mmconfig {
Bin Meng6a421582016-05-07 07:46:21 -0700111 u32 base_address_l;
112 u32 base_address_h;
Saket Sinha331141a2015-08-22 12:20:55 +0530113 u16 pci_segment_group_number;
114 u8 start_bus_number;
115 u8 end_bus_number;
116 u8 reserved[4];
117};
118
119/* MADT (Multiple APIC Description Table) */
120struct acpi_madt {
121 struct acpi_table_header header;
122 u32 lapic_addr; /* Local APIC address */
123 u32 flags; /* Multiple APIC flags */
124} acpi_madt_t;
125
Saket Sinha331141a2015-08-22 12:20:55 +0530126/* MADT: APIC Structure Type*/
127enum acpi_apic_types {
Bin Meng6a421582016-05-07 07:46:21 -0700128 ACPI_APIC_LAPIC = 0, /* Processor local APIC */
129 ACPI_APIC_IOAPIC, /* I/O APIC */
130 ACPI_APIC_IRQ_SRC_OVERRIDE, /* Interrupt source override */
131 ACPI_APIC_NMI_SRC, /* NMI source */
132 ACPI_APIC_LAPIC_NMI, /* Local APIC NMI */
133 ACPI_APIC_LAPIC_ADDR_OVERRIDE, /* Local APIC address override */
134 ACPI_APIC_IOSAPIC, /* I/O SAPIC */
135 ACPI_APIC_LSAPIC, /* Local SAPIC */
136 ACPI_APIC_PLATFORM_IRQ_SRC, /* Platform interrupt sources */
137 ACPI_APIC_LX2APIC, /* Processor local x2APIC */
138 ACPI_APIC_LX2APIC_NMI, /* Local x2APIC NMI */
Saket Sinha331141a2015-08-22 12:20:55 +0530139};
140
141/* MADT: Processor Local APIC Structure */
142struct acpi_madt_lapic {
143 u8 type; /* Type (0) */
144 u8 length; /* Length in bytes (8) */
145 u8 processor_id; /* ACPI processor ID */
146 u8 apic_id; /* Local APIC ID */
147 u32 flags; /* Local APIC flags */
148};
149
150#define LOCAL_APIC_FLAG_ENABLED (1 << 0)
151/* bits 1-31: reserved */
152#define PCAT_COMPAT (1 << 0)
153/* bits 1-31: reserved */
154
155/* MADT: Local APIC NMI Structure */
Bin Meng6a421582016-05-07 07:46:21 -0700156struct __packed acpi_madt_lapic_nmi {
Saket Sinha331141a2015-08-22 12:20:55 +0530157 u8 type; /* Type (4) */
158 u8 length; /* Length in bytes (6) */
159 u8 processor_id; /* ACPI processor ID */
160 u16 flags; /* MPS INTI flags */
161 u8 lint; /* Local APIC LINT# */
162};
163
164/* MADT: I/O APIC Structure */
165struct acpi_madt_ioapic {
166 u8 type; /* Type (1) */
167 u8 length; /* Length in bytes (12) */
168 u8 ioapic_id; /* I/O APIC ID */
169 u8 reserved;
170 u32 ioapic_addr; /* I/O APIC address */
171 u32 gsi_base; /* Global system interrupt base */
172};
173
174/* MADT: Interrupt Source Override Structure */
Bin Meng6a421582016-05-07 07:46:21 -0700175struct __packed acpi_madt_irqoverride {
Saket Sinha331141a2015-08-22 12:20:55 +0530176 u8 type; /* Type (2) */
177 u8 length; /* Length in bytes (10) */
178 u8 bus; /* ISA (0) */
179 u8 source; /* Bus-relative int. source (IRQ) */
180 u32 gsirq; /* Global system interrupt */
181 u16 flags; /* MPS INTI flags */
182};
183
184/* FADT (Fixed ACPI Description Table) */
185struct __packed acpi_fadt {
186 struct acpi_table_header header;
187 u32 firmware_ctrl;
188 u32 dsdt;
Bin Meng6a421582016-05-07 07:46:21 -0700189 u8 res1;
Saket Sinha331141a2015-08-22 12:20:55 +0530190 u8 preferred_pm_profile;
191 u16 sci_int;
192 u32 smi_cmd;
193 u8 acpi_enable;
194 u8 acpi_disable;
195 u8 s4bios_req;
196 u8 pstate_cnt;
197 u32 pm1a_evt_blk;
198 u32 pm1b_evt_blk;
199 u32 pm1a_cnt_blk;
200 u32 pm1b_cnt_blk;
201 u32 pm2_cnt_blk;
202 u32 pm_tmr_blk;
203 u32 gpe0_blk;
204 u32 gpe1_blk;
205 u8 pm1_evt_len;
206 u8 pm1_cnt_len;
207 u8 pm2_cnt_len;
208 u8 pm_tmr_len;
209 u8 gpe0_blk_len;
210 u8 gpe1_blk_len;
211 u8 gpe1_base;
212 u8 cst_cnt;
213 u16 p_lvl2_lat;
214 u16 p_lvl3_lat;
215 u16 flush_size;
216 u16 flush_stride;
217 u8 duty_offset;
218 u8 duty_width;
219 u8 day_alrm;
220 u8 mon_alrm;
221 u8 century;
222 u16 iapc_boot_arch;
223 u8 res2;
224 u32 flags;
225 struct acpi_gen_regaddr reset_reg;
226 u8 reset_value;
227 u8 res3;
228 u8 res4;
229 u8 res5;
230 u32 x_firmware_ctl_l;
231 u32 x_firmware_ctl_h;
232 u32 x_dsdt_l;
233 u32 x_dsdt_h;
234 struct acpi_gen_regaddr x_pm1a_evt_blk;
235 struct acpi_gen_regaddr x_pm1b_evt_blk;
236 struct acpi_gen_regaddr x_pm1a_cnt_blk;
237 struct acpi_gen_regaddr x_pm1b_cnt_blk;
238 struct acpi_gen_regaddr x_pm2_cnt_blk;
239 struct acpi_gen_regaddr x_pm_tmr_blk;
240 struct acpi_gen_regaddr x_gpe0_blk;
241 struct acpi_gen_regaddr x_gpe1_blk;
242};
243
244/* Flags for p_lvl2_lat and p_lvl3_lat */
245#define ACPI_FADT_C2_NOT_SUPPORTED 101
246#define ACPI_FADT_C3_NOT_SUPPORTED 1001
247
248/* FADT Feature Flags */
249#define ACPI_FADT_WBINVD (1 << 0)
250#define ACPI_FADT_WBINVD_FLUSH (1 << 1)
251#define ACPI_FADT_C1_SUPPORTED (1 << 2)
252#define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
253#define ACPI_FADT_POWER_BUTTON (1 << 4)
254#define ACPI_FADT_SLEEP_BUTTON (1 << 5)
255#define ACPI_FADT_FIXED_RTC (1 << 6)
256#define ACPI_FADT_S4_RTC_WAKE (1 << 7)
257#define ACPI_FADT_32BIT_TIMER (1 << 8)
258#define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
259#define ACPI_FADT_RESET_REGISTER (1 << 10)
260#define ACPI_FADT_SEALED_CASE (1 << 11)
261#define ACPI_FADT_HEADLESS (1 << 12)
262#define ACPI_FADT_SLEEP_TYPE (1 << 13)
263#define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
264#define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
265#define ACPI_FADT_S4_RTC_VALID (1 << 16)
266#define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
267#define ACPI_FADT_APIC_CLUSTER (1 << 18)
268#define ACPI_FADT_APIC_PHYSICAL (1 << 19)
269/* Bits 20-31: reserved ACPI 3.0 & 4.0 */
270#define ACPI_FADT_HW_REDUCED_ACPI (1 << 20)
271#define ACPI_FADT_LOW_PWR_IDLE_S0 (1 << 21)
272/* bits 22-31: reserved ACPI 5.0 */
273
274/* FADT Boot Architecture Flags */
275#define ACPI_FADT_LEGACY_DEVICES (1 << 0)
276#define ACPI_FADT_8042 (1 << 1)
277#define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
278#define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
279#define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
280/* No legacy devices (including 8042) */
281#define ACPI_FADT_LEGACY_FREE 0x00
282
283/* FADT Preferred Power Management Profile */
Bin Meng6a421582016-05-07 07:46:21 -0700284enum acpi_pm_profile {
285 ACPI_PM_UNSPECIFIED = 0,
286 ACPI_PM_DESKTOP,
287 ACPI_PM_MOBILE,
288 ACPI_PM_WORKSTATION,
289 ACPI_PM_ENTERPRISE_SERVER,
290 ACPI_PM_SOHO_SERVER,
291 ACPI_PM_APPLIANCE_PC,
292 ACPI_PM_PERFORMANCE_SERVER,
293 ACPI_PM_TABLET
294};
Saket Sinha331141a2015-08-22 12:20:55 +0530295
296/* FACS (Firmware ACPI Control Structure) */
297struct acpi_facs {
298 char signature[4]; /* "FACS" */
299 u32 length; /* Length in bytes (>= 64) */
300 u32 hardware_signature; /* Hardware signature */
301 u32 firmware_waking_vector; /* Firmware waking vector */
302 u32 global_lock; /* Global lock */
303 u32 flags; /* FACS flags */
304 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
305 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
306 u8 version; /* ACPI 4.0: 2 */
Bin Meng6a421582016-05-07 07:46:21 -0700307 u8 res1[3];
308 u32 ospm_flags; /* OSPM enabled flags */
309 u8 res2[24];
Saket Sinha331141a2015-08-22 12:20:55 +0530310};
311
312/* FACS flags */
313#define ACPI_FACS_S4BIOS_F (1 << 0)
314#define ACPI_FACS_64BIT_WAKE_F (1 << 1)
315/* Bits 31..2: reserved */
316
317/* These can be used by the target port */
318
319unsigned long acpi_create_madt_lapics(unsigned long current);
320int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id, u32 addr,
321 u32 gsi_base);
322int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
323 u8 bus, u8 source, u32 gsirq, u16 flags);
324unsigned long acpi_fill_madt(unsigned long current);
325void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
326 void *dsdt);
327int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi, u8 cpu,
328 u16 flags, u8 lint);
Bin Meng5c549102016-02-27 22:58:00 -0800329u32 write_acpi_tables(u32 start);