blob: c6f4d8941c911c1b61811891e4e3dad96839a9c1 [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>
Saket Sinha867bcb62015-08-22 12:20:55 +053018#include <asm/lapic.h>
19#include <asm/tables.h>
Bin Meng79c2c252016-06-17 02:13:16 -070020#include <asm/arch/global_nvs.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053021
22/*
Bin Mengdfbb18b2016-05-07 07:46:24 -070023 * IASL compiles the dsdt entries and writes the hex values
24 * to a C array AmlCode[] (see dsdt.c).
Saket Sinha867bcb62015-08-22 12:20:55 +053025 */
26extern const unsigned char AmlCode[];
27
Bin Mengab5efd52016-05-07 07:46:25 -070028static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
29 struct acpi_xsdt *xsdt)
Saket Sinha867bcb62015-08-22 12:20:55 +053030{
Bin Mengab5efd52016-05-07 07:46:25 -070031 memset(rsdp, 0, sizeof(struct acpi_rsdp));
Saket Sinha867bcb62015-08-22 12:20:55 +053032
Bin Mengab5efd52016-05-07 07:46:25 -070033 memcpy(rsdp->signature, RSDP_SIG, 8);
34 memcpy(rsdp->oem_id, OEM_ID, 6);
Saket Sinha867bcb62015-08-22 12:20:55 +053035
Bin Mengab5efd52016-05-07 07:46:25 -070036 rsdp->length = sizeof(struct acpi_rsdp);
37 rsdp->rsdt_address = (u32)rsdt;
Saket Sinha867bcb62015-08-22 12:20:55 +053038
39 /*
Bin Mengab5efd52016-05-07 07:46:25 -070040 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2
41 *
42 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
43 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
44 * revision 0)
Saket Sinha867bcb62015-08-22 12:20:55 +053045 */
Bin Mengab5efd52016-05-07 07:46:25 -070046 if (xsdt == NULL) {
47 rsdp->revision = ACPI_RSDP_REV_ACPI_1_0;
48 } else {
49 rsdp->xsdt_address = (u64)(u32)xsdt;
50 rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
Saket Sinha867bcb62015-08-22 12:20:55 +053051 }
Saket Sinha867bcb62015-08-22 12:20:55 +053052
Bin Mengab5efd52016-05-07 07:46:25 -070053 /* Calculate checksums */
54 rsdp->checksum = table_compute_checksum((void *)rsdp, 20);
55 rsdp->ext_checksum = table_compute_checksum((void *)rsdp,
56 sizeof(struct acpi_rsdp));
Saket Sinha867bcb62015-08-22 12:20:55 +053057}
58
Bin Mengdfbb18b2016-05-07 07:46:24 -070059void acpi_fill_header(struct acpi_table_header *header, char *signature)
Saket Sinha867bcb62015-08-22 12:20:55 +053060{
Bin Mengdfbb18b2016-05-07 07:46:24 -070061 memcpy(header->signature, signature, 4);
Saket Sinha867bcb62015-08-22 12:20:55 +053062 memcpy(header->oem_id, OEM_ID, 6);
Bin Meng8a8c0352016-05-07 07:46:21 -070063 memcpy(header->oem_table_id, OEM_TABLE_ID, 8);
Andy Shevchenko684c4cd2017-07-21 22:32:02 +030064 header->oem_revision = U_BOOT_BUILD_DATE;
Bin Meng8a8c0352016-05-07 07:46:21 -070065 memcpy(header->aslc_id, ASLC_ID, 4);
Saket Sinha867bcb62015-08-22 12:20:55 +053066}
67
Saket Sinha867bcb62015-08-22 12:20:55 +053068static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
69{
Bin Meng8a8c0352016-05-07 07:46:21 -070070 struct acpi_table_header *header = &(rsdt->header);
Saket Sinha867bcb62015-08-22 12:20:55 +053071
72 /* Fill out header fields */
Bin Mengdfbb18b2016-05-07 07:46:24 -070073 acpi_fill_header(header, "RSDT");
Saket Sinha867bcb62015-08-22 12:20:55 +053074 header->length = sizeof(struct acpi_rsdt);
Bin Meng7e6343e2016-05-07 07:46:28 -070075 header->revision = 1;
Saket Sinha867bcb62015-08-22 12:20:55 +053076
77 /* Entries are filled in later, we come with an empty set */
78
79 /* Fix checksum */
80 header->checksum = table_compute_checksum((void *)rsdt,
81 sizeof(struct acpi_rsdt));
82}
83
84static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
85{
Bin Meng8a8c0352016-05-07 07:46:21 -070086 struct acpi_table_header *header = &(xsdt->header);
Saket Sinha867bcb62015-08-22 12:20:55 +053087
88 /* Fill out header fields */
Bin Mengdfbb18b2016-05-07 07:46:24 -070089 acpi_fill_header(header, "XSDT");
Saket Sinha867bcb62015-08-22 12:20:55 +053090 header->length = sizeof(struct acpi_xsdt);
Bin Meng7e6343e2016-05-07 07:46:28 -070091 header->revision = 1;
Saket Sinha867bcb62015-08-22 12:20:55 +053092
93 /* Entries are filled in later, we come with an empty set */
94
95 /* Fix checksum */
96 header->checksum = table_compute_checksum((void *)xsdt,
97 sizeof(struct acpi_xsdt));
98}
99
Bin Mengab5efd52016-05-07 07:46:25 -0700100/**
101 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
102 * and checksum.
103 */
104static void acpi_add_table(struct acpi_rsdp *rsdp, void *table)
Saket Sinha867bcb62015-08-22 12:20:55 +0530105{
Bin Mengab5efd52016-05-07 07:46:25 -0700106 int i, entries_num;
107 struct acpi_rsdt *rsdt;
108 struct acpi_xsdt *xsdt = NULL;
Saket Sinha867bcb62015-08-22 12:20:55 +0530109
Bin Mengab5efd52016-05-07 07:46:25 -0700110 /* The RSDT is mandatory while the XSDT is not */
111 rsdt = (struct acpi_rsdt *)rsdp->rsdt_address;
Saket Sinha867bcb62015-08-22 12:20:55 +0530112
Bin Mengab5efd52016-05-07 07:46:25 -0700113 if (rsdp->xsdt_address)
114 xsdt = (struct acpi_xsdt *)((u32)rsdp->xsdt_address);
Saket Sinha867bcb62015-08-22 12:20:55 +0530115
Bin Mengab5efd52016-05-07 07:46:25 -0700116 /* This should always be MAX_ACPI_TABLES */
117 entries_num = ARRAY_SIZE(rsdt->entry);
118
119 for (i = 0; i < entries_num; i++) {
120 if (rsdt->entry[i] == 0)
121 break;
Saket Sinha867bcb62015-08-22 12:20:55 +0530122 }
123
Bin Mengab5efd52016-05-07 07:46:25 -0700124 if (i >= entries_num) {
125 debug("ACPI: Error: too many tables\n");
126 return;
127 }
128
129 /* Add table to the RSDT */
130 rsdt->entry[i] = (u32)table;
131
132 /* Fix RSDT length or the kernel will assume invalid entries */
133 rsdt->header.length = sizeof(struct acpi_table_header) +
134 (sizeof(u32) * (i + 1));
135
136 /* Re-calculate checksum */
137 rsdt->header.checksum = 0;
138 rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
139 rsdt->header.length);
140
141 /*
142 * And now the same thing for the XSDT. We use the same index as for
143 * now we want the XSDT and RSDT to always be in sync in U-Boot
144 */
145 if (xsdt) {
146 /* Add table to the XSDT */
147 xsdt->entry[i] = (u64)(u32)table;
148
149 /* Fix XSDT length */
150 xsdt->header.length = sizeof(struct acpi_table_header) +
151 (sizeof(u64) * (i + 1));
152
153 /* Re-calculate checksum */
154 xsdt->header.checksum = 0;
155 xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
156 xsdt->header.length);
157 }
158}
159
160static void acpi_create_facs(struct acpi_facs *facs)
161{
162 memset((void *)facs, 0, sizeof(struct acpi_facs));
163
164 memcpy(facs->signature, "FACS", 4);
165 facs->length = sizeof(struct acpi_facs);
166 facs->hardware_signature = 0;
167 facs->firmware_waking_vector = 0;
168 facs->global_lock = 0;
169 facs->flags = 0;
170 facs->x_firmware_waking_vector_l = 0;
171 facs->x_firmware_waking_vector_h = 0;
172 facs->version = 1;
173}
174
175static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic,
176 u8 cpu, u8 apic)
177{
178 lapic->type = ACPI_APIC_LAPIC;
179 lapic->length = sizeof(struct acpi_madt_lapic);
180 lapic->flags = LOCAL_APIC_FLAG_ENABLED;
181 lapic->processor_id = cpu;
182 lapic->apic_id = apic;
183
184 return lapic->length;
185}
186
Bin Mengfc4f5cc2016-05-07 07:46:30 -0700187int acpi_create_madt_lapics(u32 current)
Bin Mengab5efd52016-05-07 07:46:25 -0700188{
189 struct udevice *dev;
George McCollister8a1a7592016-06-07 13:40:18 -0500190 int total_length = 0;
Bin Mengab5efd52016-05-07 07:46:25 -0700191
192 for (uclass_find_first_device(UCLASS_CPU, &dev);
193 dev;
194 uclass_find_next_device(&dev)) {
195 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
George McCollister8a1a7592016-06-07 13:40:18 -0500196 int length = acpi_create_madt_lapic(
197 (struct acpi_madt_lapic *)current,
198 plat->cpu_id, plat->cpu_id);
Bin Mengfc4f5cc2016-05-07 07:46:30 -0700199 current += length;
George McCollister8a1a7592016-06-07 13:40:18 -0500200 total_length += length;
Bin Mengab5efd52016-05-07 07:46:25 -0700201 }
202
George McCollister8a1a7592016-06-07 13:40:18 -0500203 return total_length;
Bin Mengab5efd52016-05-07 07:46:25 -0700204}
205
206int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id,
207 u32 addr, u32 gsi_base)
208{
209 ioapic->type = ACPI_APIC_IOAPIC;
210 ioapic->length = sizeof(struct acpi_madt_ioapic);
211 ioapic->reserved = 0x00;
212 ioapic->gsi_base = gsi_base;
213 ioapic->ioapic_id = id;
214 ioapic->ioapic_addr = addr;
215
216 return ioapic->length;
217}
218
219int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
220 u8 bus, u8 source, u32 gsirq, u16 flags)
221{
222 irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE;
223 irqoverride->length = sizeof(struct acpi_madt_irqoverride);
224 irqoverride->bus = bus;
225 irqoverride->source = source;
226 irqoverride->gsirq = gsirq;
227 irqoverride->flags = flags;
228
229 return irqoverride->length;
230}
231
232int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
233 u8 cpu, u16 flags, u8 lint)
234{
235 lapic_nmi->type = ACPI_APIC_LAPIC_NMI;
236 lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi);
237 lapic_nmi->flags = flags;
238 lapic_nmi->processor_id = cpu;
239 lapic_nmi->lint = lint;
240
241 return lapic_nmi->length;
242}
243
244static void acpi_create_madt(struct acpi_madt *madt)
245{
246 struct acpi_table_header *header = &(madt->header);
Bin Meng7e79a6b2016-05-07 07:46:26 -0700247 u32 current = (u32)madt + sizeof(struct acpi_madt);
Bin Mengab5efd52016-05-07 07:46:25 -0700248
249 memset((void *)madt, 0, sizeof(struct acpi_madt));
250
251 /* Fill out header fields */
252 acpi_fill_header(header, "APIC");
253 header->length = sizeof(struct acpi_madt);
Bin Meng7e6343e2016-05-07 07:46:28 -0700254 header->revision = 4;
Bin Mengab5efd52016-05-07 07:46:25 -0700255
256 madt->lapic_addr = LAPIC_DEFAULT_BASE;
257 madt->flags = ACPI_MADT_PCAT_COMPAT;
258
259 current = acpi_fill_madt(current);
260
261 /* (Re)calculate length and checksum */
Bin Meng7e79a6b2016-05-07 07:46:26 -0700262 header->length = current - (u32)madt;
Bin Mengab5efd52016-05-07 07:46:25 -0700263
264 header->checksum = table_compute_checksum((void *)madt, header->length);
265}
266
267static int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig,
268 u32 base, u16 seg_nr, u8 start, u8 end)
269{
270 memset(mmconfig, 0, sizeof(*mmconfig));
271 mmconfig->base_address_l = base;
272 mmconfig->base_address_h = 0;
273 mmconfig->pci_segment_group_number = seg_nr;
274 mmconfig->start_bus_number = start;
275 mmconfig->end_bus_number = end;
276
277 return sizeof(struct acpi_mcfg_mmconfig);
278}
279
Bin Meng7e79a6b2016-05-07 07:46:26 -0700280static u32 acpi_fill_mcfg(u32 current)
Bin Mengab5efd52016-05-07 07:46:25 -0700281{
282 current += acpi_create_mcfg_mmconfig
283 ((struct acpi_mcfg_mmconfig *)current,
284 CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255);
285
286 return current;
287}
288
289/* MCFG is defined in the PCI Firmware Specification 3.0 */
290static void acpi_create_mcfg(struct acpi_mcfg *mcfg)
291{
292 struct acpi_table_header *header = &(mcfg->header);
Bin Meng7e79a6b2016-05-07 07:46:26 -0700293 u32 current = (u32)mcfg + sizeof(struct acpi_mcfg);
Bin Mengab5efd52016-05-07 07:46:25 -0700294
295 memset((void *)mcfg, 0, sizeof(struct acpi_mcfg));
296
297 /* Fill out header fields */
298 acpi_fill_header(header, "MCFG");
299 header->length = sizeof(struct acpi_mcfg);
Bin Meng7e6343e2016-05-07 07:46:28 -0700300 header->revision = 1;
Bin Mengab5efd52016-05-07 07:46:25 -0700301
302 current = acpi_fill_mcfg(current);
303
304 /* (Re)calculate length and checksum */
Bin Meng7e79a6b2016-05-07 07:46:26 -0700305 header->length = current - (u32)mcfg;
Bin Mengab5efd52016-05-07 07:46:25 -0700306 header->checksum = table_compute_checksum((void *)mcfg, header->length);
Saket Sinha867bcb62015-08-22 12:20:55 +0530307}
308
Bin Meng99572782017-04-21 07:24:43 -0700309void enter_acpi_mode(int pm1_cnt)
Bin Meng6aef68d2016-05-11 07:45:03 -0700310{
Bin Mengb208d192017-04-21 07:24:42 -0700311 u16 val = inw(pm1_cnt);
312
Bin Meng6aef68d2016-05-11 07:45:03 -0700313 /*
314 * PM1_CNT register bit0 selects the power management event to be
315 * either an SCI or SMI interrupt. When this bit is set, then power
316 * management events will generate an SCI interrupt. When this bit
317 * is reset power management events will generate an SMI interrupt.
318 *
319 * Per ACPI spec, it is the responsibility of the hardware to set
320 * or reset this bit. OSPM always preserves this bit position.
321 *
322 * U-Boot does not support SMI. And we don't have plan to support
323 * anything running in SMM within U-Boot. To create a legacy-free
324 * system, and expose ourselves to OSPM as working under ACPI mode
325 * already, turn this bit on.
326 */
Bin Mengb208d192017-04-21 07:24:42 -0700327 outw(val | PM1_CNT_SCI_EN, pm1_cnt);
Bin Meng6aef68d2016-05-11 07:45:03 -0700328}
329
Miao Yanfa287b12016-01-20 01:57:06 -0800330/*
331 * QEMU's version of write_acpi_tables is defined in
Tom Rinidd6f3ab2016-05-06 10:40:22 -0400332 * arch/x86/cpu/qemu/acpi_table.c
Miao Yanfa287b12016-01-20 01:57:06 -0800333 */
Simon Glass42fd8c12017-01-16 07:03:35 -0700334ulong write_acpi_tables(ulong start)
Saket Sinha867bcb62015-08-22 12:20:55 +0530335{
Bin Meng358bb3f2016-02-27 22:58:00 -0800336 u32 current;
Saket Sinha867bcb62015-08-22 12:20:55 +0530337 struct acpi_rsdp *rsdp;
338 struct acpi_rsdt *rsdt;
339 struct acpi_xsdt *xsdt;
340 struct acpi_facs *facs;
Bin Meng8a8c0352016-05-07 07:46:21 -0700341 struct acpi_table_header *dsdt;
Saket Sinha867bcb62015-08-22 12:20:55 +0530342 struct acpi_fadt *fadt;
343 struct acpi_mcfg *mcfg;
344 struct acpi_madt *madt;
Bin Meng79c2c252016-06-17 02:13:16 -0700345 int i;
Saket Sinha867bcb62015-08-22 12:20:55 +0530346
347 current = start;
348
Bin Mengab5efd52016-05-07 07:46:25 -0700349 /* Align ACPI tables to 16 byte */
Saket Sinha867bcb62015-08-22 12:20:55 +0530350 current = ALIGN(current, 16);
351
Simon Glass42fd8c12017-01-16 07:03:35 -0700352 debug("ACPI: Writing ACPI tables at %lx\n", start);
Saket Sinha867bcb62015-08-22 12:20:55 +0530353
354 /* We need at least an RSDP and an RSDT Table */
355 rsdp = (struct acpi_rsdp *)current;
356 current += sizeof(struct acpi_rsdp);
357 current = ALIGN(current, 16);
358 rsdt = (struct acpi_rsdt *)current;
359 current += sizeof(struct acpi_rsdt);
360 current = ALIGN(current, 16);
361 xsdt = (struct acpi_xsdt *)current;
362 current += sizeof(struct acpi_xsdt);
Bin Meng25e133e2016-05-07 07:46:27 -0700363 /*
364 * Per ACPI spec, the FACS table address must be aligned to a 64 byte
365 * boundary (Windows checks this, but Linux does not).
366 */
367 current = ALIGN(current, 64);
Saket Sinha867bcb62015-08-22 12:20:55 +0530368
369 /* clear all table memory */
370 memset((void *)start, 0, current - start);
371
372 acpi_write_rsdp(rsdp, rsdt, xsdt);
373 acpi_write_rsdt(rsdt);
374 acpi_write_xsdt(xsdt);
375
376 debug("ACPI: * FACS\n");
377 facs = (struct acpi_facs *)current;
378 current += sizeof(struct acpi_facs);
379 current = ALIGN(current, 16);
380
381 acpi_create_facs(facs);
382
383 debug("ACPI: * DSDT\n");
Bin Meng8a8c0352016-05-07 07:46:21 -0700384 dsdt = (struct acpi_table_header *)current;
385 memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header));
Bin Meng10fcabe2016-05-11 07:45:05 -0700386 current += sizeof(struct acpi_table_header);
387 memcpy((char *)current,
388 (char *)&AmlCode + sizeof(struct acpi_table_header),
389 dsdt->length - sizeof(struct acpi_table_header));
390 current += dsdt->length - sizeof(struct acpi_table_header);
Saket Sinha867bcb62015-08-22 12:20:55 +0530391 current = ALIGN(current, 16);
392
Bin Meng79c2c252016-06-17 02:13:16 -0700393 /* Pack GNVS into the ACPI table area */
394 for (i = 0; i < dsdt->length; i++) {
395 u32 *gnvs = (u32 *)((u32)dsdt + i);
396 if (*gnvs == ACPI_GNVS_ADDR) {
397 debug("Fix up global NVS in DSDT to 0x%08x\n", current);
398 *gnvs = current;
399 break;
400 }
401 }
402
403 /* Update DSDT checksum since we patched the GNVS address */
404 dsdt->checksum = 0;
405 dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length);
406
407 /* Fill in platform-specific global NVS variables */
408 acpi_create_gnvs((struct acpi_global_nvs *)current);
409 current += sizeof(struct acpi_global_nvs);
410 current = ALIGN(current, 16);
411
Saket Sinha867bcb62015-08-22 12:20:55 +0530412 debug("ACPI: * FADT\n");
413 fadt = (struct acpi_fadt *)current;
414 current += sizeof(struct acpi_fadt);
415 current = ALIGN(current, 16);
416 acpi_create_fadt(fadt, facs, dsdt);
417 acpi_add_table(rsdp, fadt);
418
Saket Sinha867bcb62015-08-22 12:20:55 +0530419 debug("ACPI: * MADT\n");
420 madt = (struct acpi_madt *)current;
421 acpi_create_madt(madt);
Bin Meng10fcabe2016-05-11 07:45:05 -0700422 current += madt->header.length;
423 acpi_add_table(rsdp, madt);
Saket Sinha867bcb62015-08-22 12:20:55 +0530424 current = ALIGN(current, 16);
425
Bin Mengab5efd52016-05-07 07:46:25 -0700426 debug("ACPI: * MCFG\n");
427 mcfg = (struct acpi_mcfg *)current;
428 acpi_create_mcfg(mcfg);
Bin Meng10fcabe2016-05-11 07:45:05 -0700429 current += mcfg->header.length;
430 acpi_add_table(rsdp, mcfg);
431 current = ALIGN(current, 16);
Bin Mengab5efd52016-05-07 07:46:25 -0700432
Bin Mengdca4d1a2016-05-07 07:46:12 -0700433 debug("current = %x\n", current);
Saket Sinha867bcb62015-08-22 12:20:55 +0530434
Bin Mengdca4d1a2016-05-07 07:46:12 -0700435 debug("ACPI: done\n");
Saket Sinha867bcb62015-08-22 12:20:55 +0530436
Bin Meng6aef68d2016-05-11 07:45:03 -0700437 /*
438 * Other than waiting for OSPM to request us to switch to ACPI mode,
439 * do it by ourselves, since SMI will not be triggered.
440 */
441 enter_acpi_mode(fadt->pm1a_cnt_blk);
442
Saket Sinha867bcb62015-08-22 12:20:55 +0530443 return current;
444}
Bin Menge76bf382017-04-21 07:24:36 -0700445
446static struct acpi_rsdp *acpi_valid_rsdp(struct acpi_rsdp *rsdp)
447{
448 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
449 return NULL;
450
451 debug("Looking on %p for valid checksum\n", rsdp);
452
453 if (table_compute_checksum((void *)rsdp, 20) != 0)
454 return NULL;
455 debug("acpi rsdp checksum 1 passed\n");
456
457 if ((rsdp->revision > 1) &&
458 (table_compute_checksum((void *)rsdp, rsdp->length) != 0))
459 return NULL;
460 debug("acpi rsdp checksum 2 passed\n");
461
462 return rsdp;
463}
464
Bin Meng0f4e2582017-04-21 07:24:44 -0700465struct acpi_fadt *acpi_find_fadt(void)
Bin Menge76bf382017-04-21 07:24:36 -0700466{
467 char *p, *end;
468 struct acpi_rsdp *rsdp = NULL;
469 struct acpi_rsdt *rsdt;
470 struct acpi_fadt *fadt = NULL;
Bin Menge76bf382017-04-21 07:24:36 -0700471 int i;
472
Bin Menge76bf382017-04-21 07:24:36 -0700473 /* Find RSDP */
474 for (p = (char *)ROM_TABLE_ADDR; p < (char *)ROM_TABLE_END; p += 16) {
475 rsdp = acpi_valid_rsdp((struct acpi_rsdp *)p);
476 if (rsdp)
477 break;
478 }
479
480 if (rsdp == NULL)
481 return NULL;
482
483 debug("RSDP found at %p\n", rsdp);
484 rsdt = (struct acpi_rsdt *)rsdp->rsdt_address;
485
486 end = (char *)rsdt + rsdt->header.length;
487 debug("RSDT found at %p ends at %p\n", rsdt, end);
488
489 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
490 fadt = (struct acpi_fadt *)rsdt->entry[i];
491 if (strncmp((char *)fadt, "FACP", 4) == 0)
492 break;
493 fadt = NULL;
494 }
495
496 if (fadt == NULL)
497 return NULL;
498
499 debug("FADT found at %p\n", fadt);
Bin Meng0f4e2582017-04-21 07:24:44 -0700500 return fadt;
501}
502
503void *acpi_find_wakeup_vector(struct acpi_fadt *fadt)
504{
505 struct acpi_facs *facs;
506 void *wake_vec;
507
508 debug("Trying to find the wakeup vector...\n");
509
Bin Menge76bf382017-04-21 07:24:36 -0700510 facs = (struct acpi_facs *)fadt->firmware_ctrl;
511
512 if (facs == NULL) {
513 debug("No FACS found, wake up from S3 not possible.\n");
514 return NULL;
515 }
516
517 debug("FACS found at %p\n", facs);
518 wake_vec = (void *)facs->firmware_waking_vector;
519 debug("OS waking vector is %p\n", wake_vec);
520
521 return wake_vec;
522}