blob: 7b33cd371eb28f54a95479aa0428c1cfd6b5dd46 [file] [log] [blame]
Saket Sinha867bcb62015-08-22 12:20:55 +05301/*
2 * Based on acpi.c from coreboot
3 *
4 * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com>
Bin Mengab5efd52016-05-07 07:46:25 -07005 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
Saket Sinha867bcb62015-08-22 12:20:55 +05306 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
11#include <cpu.h>
12#include <dm.h>
13#include <dm/uclass-internal.h>
Andy Shevchenko684c4cd2017-07-21 22:32:02 +030014#include <version.h>
Bin Meng79c2c252016-06-17 02:13:16 -070015#include <asm/acpi/global_nvs.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053016#include <asm/acpi_table.h>
Bin Meng6aef68d2016-05-11 07:45:03 -070017#include <asm/io.h>
Andy Shevchenkob156da92017-07-21 22:32:04 +030018#include <asm/ioapic.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053019#include <asm/lapic.h>
Andy Shevchenkob156da92017-07-21 22:32:04 +030020#include <asm/mpspec.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053021#include <asm/tables.h>
Bin Meng79c2c252016-06-17 02:13:16 -070022#include <asm/arch/global_nvs.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053023
24/*
Bin Mengdfbb18b2016-05-07 07:46:24 -070025 * IASL compiles the dsdt entries and writes the hex values
26 * to a C array AmlCode[] (see dsdt.c).
Saket Sinha867bcb62015-08-22 12:20:55 +053027 */
28extern const unsigned char AmlCode[];
29
Bin Mengab5efd52016-05-07 07:46:25 -070030static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
31 struct acpi_xsdt *xsdt)
Saket Sinha867bcb62015-08-22 12:20:55 +053032{
Bin Mengab5efd52016-05-07 07:46:25 -070033 memset(rsdp, 0, sizeof(struct acpi_rsdp));
Saket Sinha867bcb62015-08-22 12:20:55 +053034
Bin Mengab5efd52016-05-07 07:46:25 -070035 memcpy(rsdp->signature, RSDP_SIG, 8);
36 memcpy(rsdp->oem_id, OEM_ID, 6);
Saket Sinha867bcb62015-08-22 12:20:55 +053037
Bin Mengab5efd52016-05-07 07:46:25 -070038 rsdp->length = sizeof(struct acpi_rsdp);
39 rsdp->rsdt_address = (u32)rsdt;
Saket Sinha867bcb62015-08-22 12:20:55 +053040
41 /*
Bin Mengab5efd52016-05-07 07:46:25 -070042 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2
43 *
44 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
45 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
46 * revision 0)
Saket Sinha867bcb62015-08-22 12:20:55 +053047 */
Bin Mengab5efd52016-05-07 07:46:25 -070048 if (xsdt == NULL) {
49 rsdp->revision = ACPI_RSDP_REV_ACPI_1_0;
50 } else {
51 rsdp->xsdt_address = (u64)(u32)xsdt;
52 rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
Saket Sinha867bcb62015-08-22 12:20:55 +053053 }
Saket Sinha867bcb62015-08-22 12:20:55 +053054
Bin Mengab5efd52016-05-07 07:46:25 -070055 /* Calculate checksums */
56 rsdp->checksum = table_compute_checksum((void *)rsdp, 20);
57 rsdp->ext_checksum = table_compute_checksum((void *)rsdp,
58 sizeof(struct acpi_rsdp));
Saket Sinha867bcb62015-08-22 12:20:55 +053059}
60
Bin Mengdfbb18b2016-05-07 07:46:24 -070061void acpi_fill_header(struct acpi_table_header *header, char *signature)
Saket Sinha867bcb62015-08-22 12:20:55 +053062{
Bin Mengdfbb18b2016-05-07 07:46:24 -070063 memcpy(header->signature, signature, 4);
Saket Sinha867bcb62015-08-22 12:20:55 +053064 memcpy(header->oem_id, OEM_ID, 6);
Bin Meng8a8c0352016-05-07 07:46:21 -070065 memcpy(header->oem_table_id, OEM_TABLE_ID, 8);
Andy Shevchenko684c4cd2017-07-21 22:32:02 +030066 header->oem_revision = U_BOOT_BUILD_DATE;
Bin Meng8a8c0352016-05-07 07:46:21 -070067 memcpy(header->aslc_id, ASLC_ID, 4);
Saket Sinha867bcb62015-08-22 12:20:55 +053068}
69
Saket Sinha867bcb62015-08-22 12:20:55 +053070static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
71{
Bin Meng8a8c0352016-05-07 07:46:21 -070072 struct acpi_table_header *header = &(rsdt->header);
Saket Sinha867bcb62015-08-22 12:20:55 +053073
74 /* Fill out header fields */
Bin Mengdfbb18b2016-05-07 07:46:24 -070075 acpi_fill_header(header, "RSDT");
Saket Sinha867bcb62015-08-22 12:20:55 +053076 header->length = sizeof(struct acpi_rsdt);
Bin Meng7e6343e2016-05-07 07:46:28 -070077 header->revision = 1;
Saket Sinha867bcb62015-08-22 12:20:55 +053078
79 /* Entries are filled in later, we come with an empty set */
80
81 /* Fix checksum */
82 header->checksum = table_compute_checksum((void *)rsdt,
83 sizeof(struct acpi_rsdt));
84}
85
86static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
87{
Bin Meng8a8c0352016-05-07 07:46:21 -070088 struct acpi_table_header *header = &(xsdt->header);
Saket Sinha867bcb62015-08-22 12:20:55 +053089
90 /* Fill out header fields */
Bin Mengdfbb18b2016-05-07 07:46:24 -070091 acpi_fill_header(header, "XSDT");
Saket Sinha867bcb62015-08-22 12:20:55 +053092 header->length = sizeof(struct acpi_xsdt);
Bin Meng7e6343e2016-05-07 07:46:28 -070093 header->revision = 1;
Saket Sinha867bcb62015-08-22 12:20:55 +053094
95 /* Entries are filled in later, we come with an empty set */
96
97 /* Fix checksum */
98 header->checksum = table_compute_checksum((void *)xsdt,
99 sizeof(struct acpi_xsdt));
100}
101
Bin Mengab5efd52016-05-07 07:46:25 -0700102/**
103 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
104 * and checksum.
105 */
106static void acpi_add_table(struct acpi_rsdp *rsdp, void *table)
Saket Sinha867bcb62015-08-22 12:20:55 +0530107{
Bin Mengab5efd52016-05-07 07:46:25 -0700108 int i, entries_num;
109 struct acpi_rsdt *rsdt;
110 struct acpi_xsdt *xsdt = NULL;
Saket Sinha867bcb62015-08-22 12:20:55 +0530111
Bin Mengab5efd52016-05-07 07:46:25 -0700112 /* The RSDT is mandatory while the XSDT is not */
113 rsdt = (struct acpi_rsdt *)rsdp->rsdt_address;
Saket Sinha867bcb62015-08-22 12:20:55 +0530114
Bin Mengab5efd52016-05-07 07:46:25 -0700115 if (rsdp->xsdt_address)
116 xsdt = (struct acpi_xsdt *)((u32)rsdp->xsdt_address);
Saket Sinha867bcb62015-08-22 12:20:55 +0530117
Bin Mengab5efd52016-05-07 07:46:25 -0700118 /* This should always be MAX_ACPI_TABLES */
119 entries_num = ARRAY_SIZE(rsdt->entry);
120
121 for (i = 0; i < entries_num; i++) {
122 if (rsdt->entry[i] == 0)
123 break;
Saket Sinha867bcb62015-08-22 12:20:55 +0530124 }
125
Bin Mengab5efd52016-05-07 07:46:25 -0700126 if (i >= entries_num) {
127 debug("ACPI: Error: too many tables\n");
128 return;
129 }
130
131 /* Add table to the RSDT */
132 rsdt->entry[i] = (u32)table;
133
134 /* Fix RSDT length or the kernel will assume invalid entries */
135 rsdt->header.length = sizeof(struct acpi_table_header) +
136 (sizeof(u32) * (i + 1));
137
138 /* Re-calculate checksum */
139 rsdt->header.checksum = 0;
140 rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
141 rsdt->header.length);
142
143 /*
144 * And now the same thing for the XSDT. We use the same index as for
145 * now we want the XSDT and RSDT to always be in sync in U-Boot
146 */
147 if (xsdt) {
148 /* Add table to the XSDT */
149 xsdt->entry[i] = (u64)(u32)table;
150
151 /* Fix XSDT length */
152 xsdt->header.length = sizeof(struct acpi_table_header) +
153 (sizeof(u64) * (i + 1));
154
155 /* Re-calculate checksum */
156 xsdt->header.checksum = 0;
157 xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
158 xsdt->header.length);
159 }
160}
161
162static void acpi_create_facs(struct acpi_facs *facs)
163{
164 memset((void *)facs, 0, sizeof(struct acpi_facs));
165
166 memcpy(facs->signature, "FACS", 4);
167 facs->length = sizeof(struct acpi_facs);
168 facs->hardware_signature = 0;
169 facs->firmware_waking_vector = 0;
170 facs->global_lock = 0;
171 facs->flags = 0;
172 facs->x_firmware_waking_vector_l = 0;
173 facs->x_firmware_waking_vector_h = 0;
174 facs->version = 1;
175}
176
177static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic,
178 u8 cpu, u8 apic)
179{
180 lapic->type = ACPI_APIC_LAPIC;
181 lapic->length = sizeof(struct acpi_madt_lapic);
182 lapic->flags = LOCAL_APIC_FLAG_ENABLED;
183 lapic->processor_id = cpu;
184 lapic->apic_id = apic;
185
186 return lapic->length;
187}
188
Bin Mengfc4f5cc2016-05-07 07:46:30 -0700189int acpi_create_madt_lapics(u32 current)
Bin Mengab5efd52016-05-07 07:46:25 -0700190{
191 struct udevice *dev;
George McCollister8a1a7592016-06-07 13:40:18 -0500192 int total_length = 0;
Bin Mengab5efd52016-05-07 07:46:25 -0700193
194 for (uclass_find_first_device(UCLASS_CPU, &dev);
195 dev;
196 uclass_find_next_device(&dev)) {
197 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
George McCollister8a1a7592016-06-07 13:40:18 -0500198 int length = acpi_create_madt_lapic(
199 (struct acpi_madt_lapic *)current,
200 plat->cpu_id, plat->cpu_id);
Bin Mengfc4f5cc2016-05-07 07:46:30 -0700201 current += length;
George McCollister8a1a7592016-06-07 13:40:18 -0500202 total_length += length;
Bin Mengab5efd52016-05-07 07:46:25 -0700203 }
204
George McCollister8a1a7592016-06-07 13:40:18 -0500205 return total_length;
Bin Mengab5efd52016-05-07 07:46:25 -0700206}
207
208int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id,
209 u32 addr, u32 gsi_base)
210{
211 ioapic->type = ACPI_APIC_IOAPIC;
212 ioapic->length = sizeof(struct acpi_madt_ioapic);
213 ioapic->reserved = 0x00;
214 ioapic->gsi_base = gsi_base;
215 ioapic->ioapic_id = id;
216 ioapic->ioapic_addr = addr;
217
218 return ioapic->length;
219}
220
221int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
222 u8 bus, u8 source, u32 gsirq, u16 flags)
223{
224 irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE;
225 irqoverride->length = sizeof(struct acpi_madt_irqoverride);
226 irqoverride->bus = bus;
227 irqoverride->source = source;
228 irqoverride->gsirq = gsirq;
229 irqoverride->flags = flags;
230
231 return irqoverride->length;
232}
233
234int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
235 u8 cpu, u16 flags, u8 lint)
236{
237 lapic_nmi->type = ACPI_APIC_LAPIC_NMI;
238 lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi);
239 lapic_nmi->flags = flags;
240 lapic_nmi->processor_id = cpu;
241 lapic_nmi->lint = lint;
242
243 return lapic_nmi->length;
244}
245
Andy Shevchenkob156da92017-07-21 22:32:04 +0300246static int acpi_create_madt_irq_overrides(u32 current)
247{
248 struct acpi_madt_irqoverride *irqovr;
249 u16 sci_flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH;
250 int length = 0;
251
252 irqovr = (void *)current;
253 length += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
254
255 irqovr = (void *)(current + length);
256 length += acpi_create_madt_irqoverride(irqovr, 0, 9, 9, sci_flags);
257
258 return length;
259}
260
261__weak u32 acpi_fill_madt(u32 current)
262{
263 current += acpi_create_madt_lapics(current);
264
265 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
266 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
267
268 current += acpi_create_madt_irq_overrides(current);
269
270 return current;
271}
272
Bin Mengab5efd52016-05-07 07:46:25 -0700273static void acpi_create_madt(struct acpi_madt *madt)
274{
275 struct acpi_table_header *header = &(madt->header);
Bin Meng7e79a6b2016-05-07 07:46:26 -0700276 u32 current = (u32)madt + sizeof(struct acpi_madt);
Bin Mengab5efd52016-05-07 07:46:25 -0700277
278 memset((void *)madt, 0, sizeof(struct acpi_madt));
279
280 /* Fill out header fields */
281 acpi_fill_header(header, "APIC");
282 header->length = sizeof(struct acpi_madt);
Bin Meng7e6343e2016-05-07 07:46:28 -0700283 header->revision = 4;
Bin Mengab5efd52016-05-07 07:46:25 -0700284
285 madt->lapic_addr = LAPIC_DEFAULT_BASE;
286 madt->flags = ACPI_MADT_PCAT_COMPAT;
287
288 current = acpi_fill_madt(current);
289
290 /* (Re)calculate length and checksum */
Bin Meng7e79a6b2016-05-07 07:46:26 -0700291 header->length = current - (u32)madt;
Bin Mengab5efd52016-05-07 07:46:25 -0700292
293 header->checksum = table_compute_checksum((void *)madt, header->length);
294}
295
Andy Shevchenkoace77622017-07-21 22:32:05 +0300296int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
297 u16 seg_nr, u8 start, u8 end)
Bin Mengab5efd52016-05-07 07:46:25 -0700298{
299 memset(mmconfig, 0, sizeof(*mmconfig));
300 mmconfig->base_address_l = base;
301 mmconfig->base_address_h = 0;
302 mmconfig->pci_segment_group_number = seg_nr;
303 mmconfig->start_bus_number = start;
304 mmconfig->end_bus_number = end;
305
306 return sizeof(struct acpi_mcfg_mmconfig);
307}
308
Andy Shevchenkoace77622017-07-21 22:32:05 +0300309__weak u32 acpi_fill_mcfg(u32 current)
Bin Mengab5efd52016-05-07 07:46:25 -0700310{
311 current += acpi_create_mcfg_mmconfig
312 ((struct acpi_mcfg_mmconfig *)current,
313 CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255);
314
315 return current;
316}
317
318/* MCFG is defined in the PCI Firmware Specification 3.0 */
319static void acpi_create_mcfg(struct acpi_mcfg *mcfg)
320{
321 struct acpi_table_header *header = &(mcfg->header);
Bin Meng7e79a6b2016-05-07 07:46:26 -0700322 u32 current = (u32)mcfg + sizeof(struct acpi_mcfg);
Bin Mengab5efd52016-05-07 07:46:25 -0700323
324 memset((void *)mcfg, 0, sizeof(struct acpi_mcfg));
325
326 /* Fill out header fields */
327 acpi_fill_header(header, "MCFG");
328 header->length = sizeof(struct acpi_mcfg);
Bin Meng7e6343e2016-05-07 07:46:28 -0700329 header->revision = 1;
Bin Mengab5efd52016-05-07 07:46:25 -0700330
331 current = acpi_fill_mcfg(current);
332
333 /* (Re)calculate length and checksum */
Bin Meng7e79a6b2016-05-07 07:46:26 -0700334 header->length = current - (u32)mcfg;
Bin Mengab5efd52016-05-07 07:46:25 -0700335 header->checksum = table_compute_checksum((void *)mcfg, header->length);
Saket Sinha867bcb62015-08-22 12:20:55 +0530336}
337
Bin Meng99572782017-04-21 07:24:43 -0700338void enter_acpi_mode(int pm1_cnt)
Bin Meng6aef68d2016-05-11 07:45:03 -0700339{
Bin Mengb208d192017-04-21 07:24:42 -0700340 u16 val = inw(pm1_cnt);
341
Bin Meng6aef68d2016-05-11 07:45:03 -0700342 /*
343 * PM1_CNT register bit0 selects the power management event to be
344 * either an SCI or SMI interrupt. When this bit is set, then power
345 * management events will generate an SCI interrupt. When this bit
346 * is reset power management events will generate an SMI interrupt.
347 *
348 * Per ACPI spec, it is the responsibility of the hardware to set
349 * or reset this bit. OSPM always preserves this bit position.
350 *
351 * U-Boot does not support SMI. And we don't have plan to support
352 * anything running in SMM within U-Boot. To create a legacy-free
353 * system, and expose ourselves to OSPM as working under ACPI mode
354 * already, turn this bit on.
355 */
Bin Mengb208d192017-04-21 07:24:42 -0700356 outw(val | PM1_CNT_SCI_EN, pm1_cnt);
Bin Meng6aef68d2016-05-11 07:45:03 -0700357}
358
Miao Yanfa287b12016-01-20 01:57:06 -0800359/*
Andy Shevchenko7b36dbd2018-01-10 19:33:10 +0200360 * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
Miao Yanfa287b12016-01-20 01:57:06 -0800361 */
Simon Glass42fd8c12017-01-16 07:03:35 -0700362ulong write_acpi_tables(ulong start)
Saket Sinha867bcb62015-08-22 12:20:55 +0530363{
Bin Meng358bb3f2016-02-27 22:58:00 -0800364 u32 current;
Saket Sinha867bcb62015-08-22 12:20:55 +0530365 struct acpi_rsdp *rsdp;
366 struct acpi_rsdt *rsdt;
367 struct acpi_xsdt *xsdt;
368 struct acpi_facs *facs;
Bin Meng8a8c0352016-05-07 07:46:21 -0700369 struct acpi_table_header *dsdt;
Saket Sinha867bcb62015-08-22 12:20:55 +0530370 struct acpi_fadt *fadt;
371 struct acpi_mcfg *mcfg;
372 struct acpi_madt *madt;
Bin Meng79c2c252016-06-17 02:13:16 -0700373 int i;
Saket Sinha867bcb62015-08-22 12:20:55 +0530374
375 current = start;
376
Bin Mengab5efd52016-05-07 07:46:25 -0700377 /* Align ACPI tables to 16 byte */
Saket Sinha867bcb62015-08-22 12:20:55 +0530378 current = ALIGN(current, 16);
379
Simon Glass42fd8c12017-01-16 07:03:35 -0700380 debug("ACPI: Writing ACPI tables at %lx\n", start);
Saket Sinha867bcb62015-08-22 12:20:55 +0530381
382 /* We need at least an RSDP and an RSDT Table */
383 rsdp = (struct acpi_rsdp *)current;
384 current += sizeof(struct acpi_rsdp);
385 current = ALIGN(current, 16);
386 rsdt = (struct acpi_rsdt *)current;
387 current += sizeof(struct acpi_rsdt);
388 current = ALIGN(current, 16);
389 xsdt = (struct acpi_xsdt *)current;
390 current += sizeof(struct acpi_xsdt);
Bin Meng25e133e2016-05-07 07:46:27 -0700391 /*
392 * Per ACPI spec, the FACS table address must be aligned to a 64 byte
393 * boundary (Windows checks this, but Linux does not).
394 */
395 current = ALIGN(current, 64);
Saket Sinha867bcb62015-08-22 12:20:55 +0530396
397 /* clear all table memory */
398 memset((void *)start, 0, current - start);
399
400 acpi_write_rsdp(rsdp, rsdt, xsdt);
401 acpi_write_rsdt(rsdt);
402 acpi_write_xsdt(xsdt);
403
404 debug("ACPI: * FACS\n");
405 facs = (struct acpi_facs *)current;
406 current += sizeof(struct acpi_facs);
407 current = ALIGN(current, 16);
408
409 acpi_create_facs(facs);
410
411 debug("ACPI: * DSDT\n");
Bin Meng8a8c0352016-05-07 07:46:21 -0700412 dsdt = (struct acpi_table_header *)current;
413 memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header));
Bin Meng10fcabe2016-05-11 07:45:05 -0700414 current += sizeof(struct acpi_table_header);
415 memcpy((char *)current,
416 (char *)&AmlCode + sizeof(struct acpi_table_header),
417 dsdt->length - sizeof(struct acpi_table_header));
418 current += dsdt->length - sizeof(struct acpi_table_header);
Saket Sinha867bcb62015-08-22 12:20:55 +0530419 current = ALIGN(current, 16);
420
Bin Meng79c2c252016-06-17 02:13:16 -0700421 /* Pack GNVS into the ACPI table area */
422 for (i = 0; i < dsdt->length; i++) {
423 u32 *gnvs = (u32 *)((u32)dsdt + i);
424 if (*gnvs == ACPI_GNVS_ADDR) {
425 debug("Fix up global NVS in DSDT to 0x%08x\n", current);
426 *gnvs = current;
427 break;
428 }
429 }
430
431 /* Update DSDT checksum since we patched the GNVS address */
432 dsdt->checksum = 0;
433 dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length);
434
435 /* Fill in platform-specific global NVS variables */
436 acpi_create_gnvs((struct acpi_global_nvs *)current);
437 current += sizeof(struct acpi_global_nvs);
438 current = ALIGN(current, 16);
439
Saket Sinha867bcb62015-08-22 12:20:55 +0530440 debug("ACPI: * FADT\n");
441 fadt = (struct acpi_fadt *)current;
442 current += sizeof(struct acpi_fadt);
443 current = ALIGN(current, 16);
444 acpi_create_fadt(fadt, facs, dsdt);
445 acpi_add_table(rsdp, fadt);
446
Saket Sinha867bcb62015-08-22 12:20:55 +0530447 debug("ACPI: * MADT\n");
448 madt = (struct acpi_madt *)current;
449 acpi_create_madt(madt);
Bin Meng10fcabe2016-05-11 07:45:05 -0700450 current += madt->header.length;
451 acpi_add_table(rsdp, madt);
Saket Sinha867bcb62015-08-22 12:20:55 +0530452 current = ALIGN(current, 16);
453
Bin Mengab5efd52016-05-07 07:46:25 -0700454 debug("ACPI: * MCFG\n");
455 mcfg = (struct acpi_mcfg *)current;
456 acpi_create_mcfg(mcfg);
Bin Meng10fcabe2016-05-11 07:45:05 -0700457 current += mcfg->header.length;
458 acpi_add_table(rsdp, mcfg);
459 current = ALIGN(current, 16);
Bin Mengab5efd52016-05-07 07:46:25 -0700460
Bin Mengdca4d1a2016-05-07 07:46:12 -0700461 debug("current = %x\n", current);
Saket Sinha867bcb62015-08-22 12:20:55 +0530462
Bin Mengdca4d1a2016-05-07 07:46:12 -0700463 debug("ACPI: done\n");
Saket Sinha867bcb62015-08-22 12:20:55 +0530464
Andy Shevchenko382fabb2017-07-21 22:32:06 +0300465 /* Don't touch ACPI hardware on HW reduced platforms */
466 if (fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)
467 return current;
468
Bin Meng6aef68d2016-05-11 07:45:03 -0700469 /*
470 * Other than waiting for OSPM to request us to switch to ACPI mode,
471 * do it by ourselves, since SMI will not be triggered.
472 */
473 enter_acpi_mode(fadt->pm1a_cnt_blk);
474
Saket Sinha867bcb62015-08-22 12:20:55 +0530475 return current;
476}
Bin Menge76bf382017-04-21 07:24:36 -0700477
478static struct acpi_rsdp *acpi_valid_rsdp(struct acpi_rsdp *rsdp)
479{
480 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
481 return NULL;
482
483 debug("Looking on %p for valid checksum\n", rsdp);
484
485 if (table_compute_checksum((void *)rsdp, 20) != 0)
486 return NULL;
487 debug("acpi rsdp checksum 1 passed\n");
488
489 if ((rsdp->revision > 1) &&
490 (table_compute_checksum((void *)rsdp, rsdp->length) != 0))
491 return NULL;
492 debug("acpi rsdp checksum 2 passed\n");
493
494 return rsdp;
495}
496
Bin Meng0f4e2582017-04-21 07:24:44 -0700497struct acpi_fadt *acpi_find_fadt(void)
Bin Menge76bf382017-04-21 07:24:36 -0700498{
499 char *p, *end;
500 struct acpi_rsdp *rsdp = NULL;
501 struct acpi_rsdt *rsdt;
502 struct acpi_fadt *fadt = NULL;
Bin Menge76bf382017-04-21 07:24:36 -0700503 int i;
504
Bin Menge76bf382017-04-21 07:24:36 -0700505 /* Find RSDP */
506 for (p = (char *)ROM_TABLE_ADDR; p < (char *)ROM_TABLE_END; p += 16) {
507 rsdp = acpi_valid_rsdp((struct acpi_rsdp *)p);
508 if (rsdp)
509 break;
510 }
511
512 if (rsdp == NULL)
513 return NULL;
514
515 debug("RSDP found at %p\n", rsdp);
516 rsdt = (struct acpi_rsdt *)rsdp->rsdt_address;
517
518 end = (char *)rsdt + rsdt->header.length;
519 debug("RSDT found at %p ends at %p\n", rsdt, end);
520
521 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
522 fadt = (struct acpi_fadt *)rsdt->entry[i];
523 if (strncmp((char *)fadt, "FACP", 4) == 0)
524 break;
525 fadt = NULL;
526 }
527
528 if (fadt == NULL)
529 return NULL;
530
531 debug("FADT found at %p\n", fadt);
Bin Meng0f4e2582017-04-21 07:24:44 -0700532 return fadt;
533}
534
535void *acpi_find_wakeup_vector(struct acpi_fadt *fadt)
536{
537 struct acpi_facs *facs;
538 void *wake_vec;
539
540 debug("Trying to find the wakeup vector...\n");
541
Bin Menge76bf382017-04-21 07:24:36 -0700542 facs = (struct acpi_facs *)fadt->firmware_ctrl;
543
544 if (facs == NULL) {
545 debug("No FACS found, wake up from S3 not possible.\n");
546 return NULL;
547 }
548
549 debug("FACS found at %p\n", facs);
550 wake_vec = (void *)facs->firmware_waking_vector;
551 debug("OS waking vector is %p\n", wake_vec);
552
553 return wake_vec;
554}