blob: 01d5b6fff09329bf6a741d50a1e4fcde1d7f7a20 [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>
Bin Meng79c2c252016-06-17 02:13:16 -070014#include <asm/acpi/global_nvs.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053015#include <asm/acpi_table.h>
Bin Meng6aef68d2016-05-11 07:45:03 -070016#include <asm/io.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053017#include <asm/lapic.h>
18#include <asm/tables.h>
Bin Meng79c2c252016-06-17 02:13:16 -070019#include <asm/arch/global_nvs.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053020
21/*
Bin Mengdfbb18b2016-05-07 07:46:24 -070022 * IASL compiles the dsdt entries and writes the hex values
23 * to a C array AmlCode[] (see dsdt.c).
Saket Sinha867bcb62015-08-22 12:20:55 +053024 */
25extern const unsigned char AmlCode[];
26
Bin Mengab5efd52016-05-07 07:46:25 -070027static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
28 struct acpi_xsdt *xsdt)
Saket Sinha867bcb62015-08-22 12:20:55 +053029{
Bin Mengab5efd52016-05-07 07:46:25 -070030 memset(rsdp, 0, sizeof(struct acpi_rsdp));
Saket Sinha867bcb62015-08-22 12:20:55 +053031
Bin Mengab5efd52016-05-07 07:46:25 -070032 memcpy(rsdp->signature, RSDP_SIG, 8);
33 memcpy(rsdp->oem_id, OEM_ID, 6);
Saket Sinha867bcb62015-08-22 12:20:55 +053034
Bin Mengab5efd52016-05-07 07:46:25 -070035 rsdp->length = sizeof(struct acpi_rsdp);
36 rsdp->rsdt_address = (u32)rsdt;
Saket Sinha867bcb62015-08-22 12:20:55 +053037
38 /*
Bin Mengab5efd52016-05-07 07:46:25 -070039 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2
40 *
41 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
42 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
43 * revision 0)
Saket Sinha867bcb62015-08-22 12:20:55 +053044 */
Bin Mengab5efd52016-05-07 07:46:25 -070045 if (xsdt == NULL) {
46 rsdp->revision = ACPI_RSDP_REV_ACPI_1_0;
47 } else {
48 rsdp->xsdt_address = (u64)(u32)xsdt;
49 rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
Saket Sinha867bcb62015-08-22 12:20:55 +053050 }
Saket Sinha867bcb62015-08-22 12:20:55 +053051
Bin Mengab5efd52016-05-07 07:46:25 -070052 /* Calculate checksums */
53 rsdp->checksum = table_compute_checksum((void *)rsdp, 20);
54 rsdp->ext_checksum = table_compute_checksum((void *)rsdp,
55 sizeof(struct acpi_rsdp));
Saket Sinha867bcb62015-08-22 12:20:55 +053056}
57
Bin Mengdfbb18b2016-05-07 07:46:24 -070058void acpi_fill_header(struct acpi_table_header *header, char *signature)
Saket Sinha867bcb62015-08-22 12:20:55 +053059{
Bin Mengdfbb18b2016-05-07 07:46:24 -070060 memcpy(header->signature, signature, 4);
Saket Sinha867bcb62015-08-22 12:20:55 +053061 memcpy(header->oem_id, OEM_ID, 6);
Bin Meng8a8c0352016-05-07 07:46:21 -070062 memcpy(header->oem_table_id, OEM_TABLE_ID, 8);
63 memcpy(header->aslc_id, ASLC_ID, 4);
Saket Sinha867bcb62015-08-22 12:20:55 +053064}
65
Saket Sinha867bcb62015-08-22 12:20:55 +053066static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
67{
Bin Meng8a8c0352016-05-07 07:46:21 -070068 struct acpi_table_header *header = &(rsdt->header);
Saket Sinha867bcb62015-08-22 12:20:55 +053069
70 /* Fill out header fields */
Bin Mengdfbb18b2016-05-07 07:46:24 -070071 acpi_fill_header(header, "RSDT");
Saket Sinha867bcb62015-08-22 12:20:55 +053072 header->length = sizeof(struct acpi_rsdt);
Bin Meng7e6343e2016-05-07 07:46:28 -070073 header->revision = 1;
Saket Sinha867bcb62015-08-22 12:20:55 +053074
75 /* Entries are filled in later, we come with an empty set */
76
77 /* Fix checksum */
78 header->checksum = table_compute_checksum((void *)rsdt,
79 sizeof(struct acpi_rsdt));
80}
81
82static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
83{
Bin Meng8a8c0352016-05-07 07:46:21 -070084 struct acpi_table_header *header = &(xsdt->header);
Saket Sinha867bcb62015-08-22 12:20:55 +053085
86 /* Fill out header fields */
Bin Mengdfbb18b2016-05-07 07:46:24 -070087 acpi_fill_header(header, "XSDT");
Saket Sinha867bcb62015-08-22 12:20:55 +053088 header->length = sizeof(struct acpi_xsdt);
Bin Meng7e6343e2016-05-07 07:46:28 -070089 header->revision = 1;
Saket Sinha867bcb62015-08-22 12:20:55 +053090
91 /* Entries are filled in later, we come with an empty set */
92
93 /* Fix checksum */
94 header->checksum = table_compute_checksum((void *)xsdt,
95 sizeof(struct acpi_xsdt));
96}
97
Bin Mengab5efd52016-05-07 07:46:25 -070098/**
99 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
100 * and checksum.
101 */
102static void acpi_add_table(struct acpi_rsdp *rsdp, void *table)
Saket Sinha867bcb62015-08-22 12:20:55 +0530103{
Bin Mengab5efd52016-05-07 07:46:25 -0700104 int i, entries_num;
105 struct acpi_rsdt *rsdt;
106 struct acpi_xsdt *xsdt = NULL;
Saket Sinha867bcb62015-08-22 12:20:55 +0530107
Bin Mengab5efd52016-05-07 07:46:25 -0700108 /* The RSDT is mandatory while the XSDT is not */
109 rsdt = (struct acpi_rsdt *)rsdp->rsdt_address;
Saket Sinha867bcb62015-08-22 12:20:55 +0530110
Bin Mengab5efd52016-05-07 07:46:25 -0700111 if (rsdp->xsdt_address)
112 xsdt = (struct acpi_xsdt *)((u32)rsdp->xsdt_address);
Saket Sinha867bcb62015-08-22 12:20:55 +0530113
Bin Mengab5efd52016-05-07 07:46:25 -0700114 /* This should always be MAX_ACPI_TABLES */
115 entries_num = ARRAY_SIZE(rsdt->entry);
116
117 for (i = 0; i < entries_num; i++) {
118 if (rsdt->entry[i] == 0)
119 break;
Saket Sinha867bcb62015-08-22 12:20:55 +0530120 }
121
Bin Mengab5efd52016-05-07 07:46:25 -0700122 if (i >= entries_num) {
123 debug("ACPI: Error: too many tables\n");
124 return;
125 }
126
127 /* Add table to the RSDT */
128 rsdt->entry[i] = (u32)table;
129
130 /* Fix RSDT length or the kernel will assume invalid entries */
131 rsdt->header.length = sizeof(struct acpi_table_header) +
132 (sizeof(u32) * (i + 1));
133
134 /* Re-calculate checksum */
135 rsdt->header.checksum = 0;
136 rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
137 rsdt->header.length);
138
139 /*
140 * And now the same thing for the XSDT. We use the same index as for
141 * now we want the XSDT and RSDT to always be in sync in U-Boot
142 */
143 if (xsdt) {
144 /* Add table to the XSDT */
145 xsdt->entry[i] = (u64)(u32)table;
146
147 /* Fix XSDT length */
148 xsdt->header.length = sizeof(struct acpi_table_header) +
149 (sizeof(u64) * (i + 1));
150
151 /* Re-calculate checksum */
152 xsdt->header.checksum = 0;
153 xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
154 xsdt->header.length);
155 }
156}
157
158static void acpi_create_facs(struct acpi_facs *facs)
159{
160 memset((void *)facs, 0, sizeof(struct acpi_facs));
161
162 memcpy(facs->signature, "FACS", 4);
163 facs->length = sizeof(struct acpi_facs);
164 facs->hardware_signature = 0;
165 facs->firmware_waking_vector = 0;
166 facs->global_lock = 0;
167 facs->flags = 0;
168 facs->x_firmware_waking_vector_l = 0;
169 facs->x_firmware_waking_vector_h = 0;
170 facs->version = 1;
171}
172
173static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic,
174 u8 cpu, u8 apic)
175{
176 lapic->type = ACPI_APIC_LAPIC;
177 lapic->length = sizeof(struct acpi_madt_lapic);
178 lapic->flags = LOCAL_APIC_FLAG_ENABLED;
179 lapic->processor_id = cpu;
180 lapic->apic_id = apic;
181
182 return lapic->length;
183}
184
Bin Mengfc4f5cc2016-05-07 07:46:30 -0700185int acpi_create_madt_lapics(u32 current)
Bin Mengab5efd52016-05-07 07:46:25 -0700186{
187 struct udevice *dev;
George McCollister8a1a7592016-06-07 13:40:18 -0500188 int total_length = 0;
Bin Mengab5efd52016-05-07 07:46:25 -0700189
190 for (uclass_find_first_device(UCLASS_CPU, &dev);
191 dev;
192 uclass_find_next_device(&dev)) {
193 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
George McCollister8a1a7592016-06-07 13:40:18 -0500194 int length = acpi_create_madt_lapic(
195 (struct acpi_madt_lapic *)current,
196 plat->cpu_id, plat->cpu_id);
Bin Mengfc4f5cc2016-05-07 07:46:30 -0700197 current += length;
George McCollister8a1a7592016-06-07 13:40:18 -0500198 total_length += length;
Bin Mengab5efd52016-05-07 07:46:25 -0700199 }
200
George McCollister8a1a7592016-06-07 13:40:18 -0500201 return total_length;
Bin Mengab5efd52016-05-07 07:46:25 -0700202}
203
204int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id,
205 u32 addr, u32 gsi_base)
206{
207 ioapic->type = ACPI_APIC_IOAPIC;
208 ioapic->length = sizeof(struct acpi_madt_ioapic);
209 ioapic->reserved = 0x00;
210 ioapic->gsi_base = gsi_base;
211 ioapic->ioapic_id = id;
212 ioapic->ioapic_addr = addr;
213
214 return ioapic->length;
215}
216
217int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
218 u8 bus, u8 source, u32 gsirq, u16 flags)
219{
220 irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE;
221 irqoverride->length = sizeof(struct acpi_madt_irqoverride);
222 irqoverride->bus = bus;
223 irqoverride->source = source;
224 irqoverride->gsirq = gsirq;
225 irqoverride->flags = flags;
226
227 return irqoverride->length;
228}
229
230int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
231 u8 cpu, u16 flags, u8 lint)
232{
233 lapic_nmi->type = ACPI_APIC_LAPIC_NMI;
234 lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi);
235 lapic_nmi->flags = flags;
236 lapic_nmi->processor_id = cpu;
237 lapic_nmi->lint = lint;
238
239 return lapic_nmi->length;
240}
241
242static void acpi_create_madt(struct acpi_madt *madt)
243{
244 struct acpi_table_header *header = &(madt->header);
Bin Meng7e79a6b2016-05-07 07:46:26 -0700245 u32 current = (u32)madt + sizeof(struct acpi_madt);
Bin Mengab5efd52016-05-07 07:46:25 -0700246
247 memset((void *)madt, 0, sizeof(struct acpi_madt));
248
249 /* Fill out header fields */
250 acpi_fill_header(header, "APIC");
251 header->length = sizeof(struct acpi_madt);
Bin Meng7e6343e2016-05-07 07:46:28 -0700252 header->revision = 4;
Bin Mengab5efd52016-05-07 07:46:25 -0700253
254 madt->lapic_addr = LAPIC_DEFAULT_BASE;
255 madt->flags = ACPI_MADT_PCAT_COMPAT;
256
257 current = acpi_fill_madt(current);
258
259 /* (Re)calculate length and checksum */
Bin Meng7e79a6b2016-05-07 07:46:26 -0700260 header->length = current - (u32)madt;
Bin Mengab5efd52016-05-07 07:46:25 -0700261
262 header->checksum = table_compute_checksum((void *)madt, header->length);
263}
264
265static int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig,
266 u32 base, u16 seg_nr, u8 start, u8 end)
267{
268 memset(mmconfig, 0, sizeof(*mmconfig));
269 mmconfig->base_address_l = base;
270 mmconfig->base_address_h = 0;
271 mmconfig->pci_segment_group_number = seg_nr;
272 mmconfig->start_bus_number = start;
273 mmconfig->end_bus_number = end;
274
275 return sizeof(struct acpi_mcfg_mmconfig);
276}
277
Bin Meng7e79a6b2016-05-07 07:46:26 -0700278static u32 acpi_fill_mcfg(u32 current)
Bin Mengab5efd52016-05-07 07:46:25 -0700279{
280 current += acpi_create_mcfg_mmconfig
281 ((struct acpi_mcfg_mmconfig *)current,
282 CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255);
283
284 return current;
285}
286
287/* MCFG is defined in the PCI Firmware Specification 3.0 */
288static void acpi_create_mcfg(struct acpi_mcfg *mcfg)
289{
290 struct acpi_table_header *header = &(mcfg->header);
Bin Meng7e79a6b2016-05-07 07:46:26 -0700291 u32 current = (u32)mcfg + sizeof(struct acpi_mcfg);
Bin Mengab5efd52016-05-07 07:46:25 -0700292
293 memset((void *)mcfg, 0, sizeof(struct acpi_mcfg));
294
295 /* Fill out header fields */
296 acpi_fill_header(header, "MCFG");
297 header->length = sizeof(struct acpi_mcfg);
Bin Meng7e6343e2016-05-07 07:46:28 -0700298 header->revision = 1;
Bin Mengab5efd52016-05-07 07:46:25 -0700299
300 current = acpi_fill_mcfg(current);
301
302 /* (Re)calculate length and checksum */
Bin Meng7e79a6b2016-05-07 07:46:26 -0700303 header->length = current - (u32)mcfg;
Bin Mengab5efd52016-05-07 07:46:25 -0700304 header->checksum = table_compute_checksum((void *)mcfg, header->length);
Saket Sinha867bcb62015-08-22 12:20:55 +0530305}
306
Bin Meng99572782017-04-21 07:24:43 -0700307void enter_acpi_mode(int pm1_cnt)
Bin Meng6aef68d2016-05-11 07:45:03 -0700308{
Bin Mengb208d192017-04-21 07:24:42 -0700309 u16 val = inw(pm1_cnt);
310
Bin Meng6aef68d2016-05-11 07:45:03 -0700311 /*
312 * PM1_CNT register bit0 selects the power management event to be
313 * either an SCI or SMI interrupt. When this bit is set, then power
314 * management events will generate an SCI interrupt. When this bit
315 * is reset power management events will generate an SMI interrupt.
316 *
317 * Per ACPI spec, it is the responsibility of the hardware to set
318 * or reset this bit. OSPM always preserves this bit position.
319 *
320 * U-Boot does not support SMI. And we don't have plan to support
321 * anything running in SMM within U-Boot. To create a legacy-free
322 * system, and expose ourselves to OSPM as working under ACPI mode
323 * already, turn this bit on.
324 */
Bin Mengb208d192017-04-21 07:24:42 -0700325 outw(val | PM1_CNT_SCI_EN, pm1_cnt);
Bin Meng6aef68d2016-05-11 07:45:03 -0700326}
327
Miao Yanfa287b12016-01-20 01:57:06 -0800328/*
329 * QEMU's version of write_acpi_tables is defined in
Tom Rinidd6f3ab2016-05-06 10:40:22 -0400330 * arch/x86/cpu/qemu/acpi_table.c
Miao Yanfa287b12016-01-20 01:57:06 -0800331 */
Simon Glass42fd8c12017-01-16 07:03:35 -0700332ulong write_acpi_tables(ulong start)
Saket Sinha867bcb62015-08-22 12:20:55 +0530333{
Bin Meng358bb3f2016-02-27 22:58:00 -0800334 u32 current;
Saket Sinha867bcb62015-08-22 12:20:55 +0530335 struct acpi_rsdp *rsdp;
336 struct acpi_rsdt *rsdt;
337 struct acpi_xsdt *xsdt;
338 struct acpi_facs *facs;
Bin Meng8a8c0352016-05-07 07:46:21 -0700339 struct acpi_table_header *dsdt;
Saket Sinha867bcb62015-08-22 12:20:55 +0530340 struct acpi_fadt *fadt;
341 struct acpi_mcfg *mcfg;
342 struct acpi_madt *madt;
Bin Meng79c2c252016-06-17 02:13:16 -0700343 int i;
Saket Sinha867bcb62015-08-22 12:20:55 +0530344
345 current = start;
346
Bin Mengab5efd52016-05-07 07:46:25 -0700347 /* Align ACPI tables to 16 byte */
Saket Sinha867bcb62015-08-22 12:20:55 +0530348 current = ALIGN(current, 16);
349
Simon Glass42fd8c12017-01-16 07:03:35 -0700350 debug("ACPI: Writing ACPI tables at %lx\n", start);
Saket Sinha867bcb62015-08-22 12:20:55 +0530351
352 /* We need at least an RSDP and an RSDT Table */
353 rsdp = (struct acpi_rsdp *)current;
354 current += sizeof(struct acpi_rsdp);
355 current = ALIGN(current, 16);
356 rsdt = (struct acpi_rsdt *)current;
357 current += sizeof(struct acpi_rsdt);
358 current = ALIGN(current, 16);
359 xsdt = (struct acpi_xsdt *)current;
360 current += sizeof(struct acpi_xsdt);
Bin Meng25e133e2016-05-07 07:46:27 -0700361 /*
362 * Per ACPI spec, the FACS table address must be aligned to a 64 byte
363 * boundary (Windows checks this, but Linux does not).
364 */
365 current = ALIGN(current, 64);
Saket Sinha867bcb62015-08-22 12:20:55 +0530366
367 /* clear all table memory */
368 memset((void *)start, 0, current - start);
369
370 acpi_write_rsdp(rsdp, rsdt, xsdt);
371 acpi_write_rsdt(rsdt);
372 acpi_write_xsdt(xsdt);
373
374 debug("ACPI: * FACS\n");
375 facs = (struct acpi_facs *)current;
376 current += sizeof(struct acpi_facs);
377 current = ALIGN(current, 16);
378
379 acpi_create_facs(facs);
380
381 debug("ACPI: * DSDT\n");
Bin Meng8a8c0352016-05-07 07:46:21 -0700382 dsdt = (struct acpi_table_header *)current;
383 memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header));
Bin Meng10fcabe2016-05-11 07:45:05 -0700384 current += sizeof(struct acpi_table_header);
385 memcpy((char *)current,
386 (char *)&AmlCode + sizeof(struct acpi_table_header),
387 dsdt->length - sizeof(struct acpi_table_header));
388 current += dsdt->length - sizeof(struct acpi_table_header);
Saket Sinha867bcb62015-08-22 12:20:55 +0530389 current = ALIGN(current, 16);
390
Bin Meng79c2c252016-06-17 02:13:16 -0700391 /* Pack GNVS into the ACPI table area */
392 for (i = 0; i < dsdt->length; i++) {
393 u32 *gnvs = (u32 *)((u32)dsdt + i);
394 if (*gnvs == ACPI_GNVS_ADDR) {
395 debug("Fix up global NVS in DSDT to 0x%08x\n", current);
396 *gnvs = current;
397 break;
398 }
399 }
400
401 /* Update DSDT checksum since we patched the GNVS address */
402 dsdt->checksum = 0;
403 dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length);
404
405 /* Fill in platform-specific global NVS variables */
406 acpi_create_gnvs((struct acpi_global_nvs *)current);
407 current += sizeof(struct acpi_global_nvs);
408 current = ALIGN(current, 16);
409
Saket Sinha867bcb62015-08-22 12:20:55 +0530410 debug("ACPI: * FADT\n");
411 fadt = (struct acpi_fadt *)current;
412 current += sizeof(struct acpi_fadt);
413 current = ALIGN(current, 16);
414 acpi_create_fadt(fadt, facs, dsdt);
415 acpi_add_table(rsdp, fadt);
416
Saket Sinha867bcb62015-08-22 12:20:55 +0530417 debug("ACPI: * MADT\n");
418 madt = (struct acpi_madt *)current;
419 acpi_create_madt(madt);
Bin Meng10fcabe2016-05-11 07:45:05 -0700420 current += madt->header.length;
421 acpi_add_table(rsdp, madt);
Saket Sinha867bcb62015-08-22 12:20:55 +0530422 current = ALIGN(current, 16);
423
Bin Mengab5efd52016-05-07 07:46:25 -0700424 debug("ACPI: * MCFG\n");
425 mcfg = (struct acpi_mcfg *)current;
426 acpi_create_mcfg(mcfg);
Bin Meng10fcabe2016-05-11 07:45:05 -0700427 current += mcfg->header.length;
428 acpi_add_table(rsdp, mcfg);
429 current = ALIGN(current, 16);
Bin Mengab5efd52016-05-07 07:46:25 -0700430
Bin Mengdca4d1a2016-05-07 07:46:12 -0700431 debug("current = %x\n", current);
Saket Sinha867bcb62015-08-22 12:20:55 +0530432
Bin Mengdca4d1a2016-05-07 07:46:12 -0700433 debug("ACPI: done\n");
Saket Sinha867bcb62015-08-22 12:20:55 +0530434
Bin Meng6aef68d2016-05-11 07:45:03 -0700435 /*
436 * Other than waiting for OSPM to request us to switch to ACPI mode,
437 * do it by ourselves, since SMI will not be triggered.
438 */
439 enter_acpi_mode(fadt->pm1a_cnt_blk);
440
Saket Sinha867bcb62015-08-22 12:20:55 +0530441 return current;
442}
Bin Menge76bf382017-04-21 07:24:36 -0700443
444static struct acpi_rsdp *acpi_valid_rsdp(struct acpi_rsdp *rsdp)
445{
446 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
447 return NULL;
448
449 debug("Looking on %p for valid checksum\n", rsdp);
450
451 if (table_compute_checksum((void *)rsdp, 20) != 0)
452 return NULL;
453 debug("acpi rsdp checksum 1 passed\n");
454
455 if ((rsdp->revision > 1) &&
456 (table_compute_checksum((void *)rsdp, rsdp->length) != 0))
457 return NULL;
458 debug("acpi rsdp checksum 2 passed\n");
459
460 return rsdp;
461}
462
Bin Meng0f4e2582017-04-21 07:24:44 -0700463struct acpi_fadt *acpi_find_fadt(void)
Bin Menge76bf382017-04-21 07:24:36 -0700464{
465 char *p, *end;
466 struct acpi_rsdp *rsdp = NULL;
467 struct acpi_rsdt *rsdt;
468 struct acpi_fadt *fadt = NULL;
Bin Menge76bf382017-04-21 07:24:36 -0700469 int i;
470
Bin Menge76bf382017-04-21 07:24:36 -0700471 /* Find RSDP */
472 for (p = (char *)ROM_TABLE_ADDR; p < (char *)ROM_TABLE_END; p += 16) {
473 rsdp = acpi_valid_rsdp((struct acpi_rsdp *)p);
474 if (rsdp)
475 break;
476 }
477
478 if (rsdp == NULL)
479 return NULL;
480
481 debug("RSDP found at %p\n", rsdp);
482 rsdt = (struct acpi_rsdt *)rsdp->rsdt_address;
483
484 end = (char *)rsdt + rsdt->header.length;
485 debug("RSDT found at %p ends at %p\n", rsdt, end);
486
487 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
488 fadt = (struct acpi_fadt *)rsdt->entry[i];
489 if (strncmp((char *)fadt, "FACP", 4) == 0)
490 break;
491 fadt = NULL;
492 }
493
494 if (fadt == NULL)
495 return NULL;
496
497 debug("FADT found at %p\n", fadt);
Bin Meng0f4e2582017-04-21 07:24:44 -0700498 return fadt;
499}
500
501void *acpi_find_wakeup_vector(struct acpi_fadt *fadt)
502{
503 struct acpi_facs *facs;
504 void *wake_vec;
505
506 debug("Trying to find the wakeup vector...\n");
507
Bin Menge76bf382017-04-21 07:24:36 -0700508 facs = (struct acpi_facs *)fadt->firmware_ctrl;
509
510 if (facs == NULL) {
511 debug("No FACS found, wake up from S3 not possible.\n");
512 return NULL;
513 }
514
515 debug("FACS found at %p\n", facs);
516 wake_vec = (void *)facs->firmware_waking_vector;
517 debug("OS waking vector is %p\n", wake_vec);
518
519 return wake_vec;
520}