blob: edb6835dc8849fc441613b5ba642c9f1d29b3816 [file] [log] [blame]
Stefan Reinauer688b3852004-01-28 16:56:14 +00001/*
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00002 * This file is part of the coreboot project.
3 *
Stefan Reinauerf8ee1802008-01-18 15:08:58 +00004 * coreboot ACPI Table support
Stefan Reinauer688b3852004-01-28 16:56:14 +00005 * written by Stefan Reinauer <stepan@openbios.org>
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00006 *
7 * Copyright (C) 2004 SUSE LINUX AG
8 * Copyright (C) 2005-2009 coresystems GmbH
Timothy Pearsonff8ccf02015-08-11 17:48:32 -05009 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Werner Zehd4d76952016-07-27 06:56:36 +020010 * Copyright (C) 2016 Siemens AG
Stefan Reinauer777224c2005-01-19 14:06:41 +000011 *
Stefan Reinauer14e22772010-04-27 06:56:47 +000012 * ACPI FADT, FACS, and DSDT table support added by
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000013 * Nick Barker <nick.barker9@btinternet.com>, and those portions
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000014 * Copyright (C) 2004 Nick Barker
Stefan Reinauerf622d592005-11-26 16:56:05 +000015 *
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000016 * Copyright (C) 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
Stefan Reinauerd6edf7a2006-01-05 00:19:52 +000017 * 2005.9 yhlu add SRAT table generation
Martin Roth9df9e9392016-01-12 15:55:28 -070018 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; version 2 of the License.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
Stefan Reinauer777224c2005-01-19 14:06:41 +000027 */
28
Stefan Reinauer14e22772010-04-27 06:56:47 +000029/*
Stefan Reinauer777224c2005-01-19 14:06:41 +000030 * Each system port implementing ACPI has to provide two functions:
Stefan Reinauer14e22772010-04-27 06:56:47 +000031 *
Stefan Reinauer777224c2005-01-19 14:06:41 +000032 * write_acpi_tables()
33 * acpi_dump_apics()
Stefan Reinauer14e22772010-04-27 06:56:47 +000034 *
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000035 * See Kontron 986LCD-M port for a good example of an ACPI implementation
36 * in coreboot.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000037 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000038
39#include <console/console.h>
40#include <string.h>
41#include <arch/acpi.h>
Martin Rotha66df492016-09-06 10:22:34 -060042#include <arch/acpi_ivrs.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000043#include <arch/acpigen.h>
Stefan Reinauer777224c2005-01-19 14:06:41 +000044#include <device/pci.h>
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000045#include <cbmem.h>
Patrick Georgic8feedd2012-02-16 18:43:25 +010046#include <cpu/x86/lapic_def.h>
Duncan Laurie11290c42012-10-03 19:07:05 -070047#include <cpu/cpu.h>
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +010048#include <cbfs.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000049
50u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000051{
Uwe Hermann622824c2010-11-19 15:14:42 +000052 u8 ret = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +000053 while (length--) {
54 ret += *table;
55 table++;
56 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000057 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000058}
59
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000060/**
Uwe Hermann622824c2010-11-19 15:14:42 +000061 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
62 * and checksum.
Stefan Reinauer06feb882004-02-03 16:11:35 +000063 */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000064void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000065{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000066 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000067 acpi_rsdt_t *rsdt;
68 acpi_xsdt_t *xsdt = NULL;
69
Uwe Hermann622824c2010-11-19 15:14:42 +000070 /* The RSDT is mandatory... */
Stefan Reinauerdefee172015-06-18 01:11:19 -070071 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000072
Uwe Hermann622824c2010-11-19 15:14:42 +000073 /* ...while the XSDT is not. */
74 if (rsdp->xsdt_address)
Stefan Reinauerdefee172015-06-18 01:11:19 -070075 xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address);
Stefan Reinauer14e22772010-04-27 06:56:47 +000076
Uwe Hermann622824c2010-11-19 15:14:42 +000077 /* This should always be MAX_ACPI_TABLES. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000078 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauer14e22772010-04-27 06:56:47 +000079
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000080 for (i = 0; i < entries_num; i++) {
Uwe Hermann622824c2010-11-19 15:14:42 +000081 if (rsdt->entry[i] == 0)
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000082 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000083 }
84
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000085 if (i >= entries_num) {
Uwe Hermann622824c2010-11-19 15:14:42 +000086 printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +030087 "too many tables.\n");
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000088 return;
89 }
90
Uwe Hermann622824c2010-11-19 15:14:42 +000091 /* Add table to the RSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070092 rsdt->entry[i] = (uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000093
Uwe Hermann622824c2010-11-19 15:14:42 +000094 /* Fix RSDT length or the kernel will assume invalid entries. */
95 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000096
Uwe Hermann622824c2010-11-19 15:14:42 +000097 /* Re-calculate checksum. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000098 rsdt->header.checksum = 0; /* Hope this won't get optimized away */
Uwe Hermann622824c2010-11-19 15:14:42 +000099 rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000100
Uwe Hermann622824c2010-11-19 15:14:42 +0000101 /*
102 * And now the same thing for the XSDT. We use the same index as for
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000103 * now we want the XSDT and RSDT to always be in sync in coreboot.
104 */
105 if (xsdt) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000106 /* Add table to the XSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -0700107 xsdt->entry[i] = (u64)(uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000108
Uwe Hermann622824c2010-11-19 15:14:42 +0000109 /* Fix XSDT length. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000110 xsdt->header.length = sizeof(acpi_header_t) +
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300111 (sizeof(u64) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000112
Uwe Hermann622824c2010-11-19 15:14:42 +0000113 /* Re-calculate checksum. */
114 xsdt->header.checksum = 0;
115 xsdt->header.checksum = acpi_checksum((u8 *)xsdt,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300116 xsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000117 }
118
Uwe Hermann622824c2010-11-19 15:14:42 +0000119 printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300120 i + 1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000121}
122
Uwe Hermann622824c2010-11-19 15:14:42 +0000123int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300124 u16 seg_nr, u8 start, u8 end)
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000125{
Vladimir Serbinenko60fccdc2014-10-05 11:05:16 +0200126 memset(mmconfig, 0, sizeof(*mmconfig));
Rudolf Mareke6409f22007-11-03 12:50:26 +0000127 mmconfig->base_address = base;
128 mmconfig->base_reserved = 0;
129 mmconfig->pci_segment_group_number = seg_nr;
130 mmconfig->start_bus_number = start;
131 mmconfig->end_bus_number = end;
Uwe Hermann622824c2010-11-19 15:14:42 +0000132
133 return sizeof(acpi_mcfg_mmconfig_t);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000134}
135
Stefan Reinauer777224c2005-01-19 14:06:41 +0000136int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000137{
Uwe Hermann622824c2010-11-19 15:14:42 +0000138 lapic->type = 0; /* Local APIC structure */
139 lapic->length = sizeof(acpi_madt_lapic_t);
140 lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
141 lapic->processor_id = cpu;
142 lapic->apic_id = apic;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000143
Uwe Hermann622824c2010-11-19 15:14:42 +0000144 return lapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000145}
146
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000147unsigned long acpi_create_madt_lapics(unsigned long current)
148{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100149 struct device *cpu;
Duncan Laurie11290c42012-10-03 19:07:05 -0700150 int index = 0;
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000151
Uwe Hermann622824c2010-11-19 15:14:42 +0000152 for (cpu = all_devices; cpu; cpu = cpu->next) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000153 if ((cpu->path.type != DEVICE_PATH_APIC) ||
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800154 (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000155 continue;
156 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000157 if (!cpu->enabled)
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000158 continue;
Uwe Hermann622824c2010-11-19 15:14:42 +0000159 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
Duncan Laurie11290c42012-10-03 19:07:05 -0700160 index, cpu->path.apic.apic_id);
161 index++;
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000162 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000163
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000164 return current;
165}
166
Uwe Hermann622824c2010-11-19 15:14:42 +0000167int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300168 u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000169{
Uwe Hermann622824c2010-11-19 15:14:42 +0000170 ioapic->type = 1; /* I/O APIC structure */
171 ioapic->length = sizeof(acpi_madt_ioapic_t);
172 ioapic->reserved = 0x00;
173 ioapic->gsi_base = gsi_base;
174 ioapic->ioapic_id = id;
175 ioapic->ioapic_addr = addr;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000176
Uwe Hermann622824c2010-11-19 15:14:42 +0000177 return ioapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000178}
179
Stefan Reinauer777224c2005-01-19 14:06:41 +0000180int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000181 u8 bus, u8 source, u32 gsirq, u16 flags)
182{
Uwe Hermann622824c2010-11-19 15:14:42 +0000183 irqoverride->type = 2; /* Interrupt source override */
184 irqoverride->length = sizeof(acpi_madt_irqoverride_t);
185 irqoverride->bus = bus;
186 irqoverride->source = source;
187 irqoverride->gsirq = gsirq;
188 irqoverride->flags = flags;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000189
Uwe Hermann622824c2010-11-19 15:14:42 +0000190 return irqoverride->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000191}
192
Stefan Reinauer777224c2005-01-19 14:06:41 +0000193int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300194 u16 flags, u8 lint)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000195{
Uwe Hermann622824c2010-11-19 15:14:42 +0000196 lapic_nmi->type = 4; /* Local APIC NMI structure */
197 lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
198 lapic_nmi->flags = flags;
199 lapic_nmi->processor_id = cpu;
200 lapic_nmi->lint = lint;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000201
Uwe Hermann622824c2010-11-19 15:14:42 +0000202 return lapic_nmi->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000203}
204
Stefan Reinauer777224c2005-01-19 14:06:41 +0000205void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000206{
Uwe Hermann622824c2010-11-19 15:14:42 +0000207 acpi_header_t *header = &(madt->header);
208 unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000209
Stefan Reinauer06feb882004-02-03 16:11:35 +0000210 memset((void *)madt, 0, sizeof(acpi_madt_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000211
Uwe Hermann622824c2010-11-19 15:14:42 +0000212 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000213 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000214 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000215 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000216 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000217
Stefan Reinauer06feb882004-02-03 16:11:35 +0000218 header->length = sizeof(acpi_madt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000219 header->revision = 1; /* ACPI 1.0/2.0: 1, ACPI 3.0: 2, ACPI 4.0: 3 */
Stefan Reinauer06feb882004-02-03 16:11:35 +0000220
Uwe Hermann622824c2010-11-19 15:14:42 +0000221 madt->lapic_addr = LOCAL_APIC_ADDR;
222 madt->flags = 0x1; /* PCAT_COMPAT */
Stefan Reinauer06feb882004-02-03 16:11:35 +0000223
Stefan Reinauerf622d592005-11-26 16:56:05 +0000224 current = acpi_fill_madt(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000225
Uwe Hermann622824c2010-11-19 15:14:42 +0000226 /* (Re)calculate length and checksum. */
227 header->length = current - (unsigned long)madt;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000228
Uwe Hermann622824c2010-11-19 15:14:42 +0000229 header->checksum = acpi_checksum((void *)madt, header->length);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000230}
231
Uwe Hermann622824c2010-11-19 15:14:42 +0000232/* MCFG is defined in the PCI Firmware Specification 3.0. */
Rudolf Mareke6409f22007-11-03 12:50:26 +0000233void acpi_create_mcfg(acpi_mcfg_t *mcfg)
234{
Uwe Hermann622824c2010-11-19 15:14:42 +0000235 acpi_header_t *header = &(mcfg->header);
236 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000237
Rudolf Mareke6409f22007-11-03 12:50:26 +0000238 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000239
Uwe Hermann622824c2010-11-19 15:14:42 +0000240 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000241 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000242 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000243 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000244 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000245
Rudolf Mareke6409f22007-11-03 12:50:26 +0000246 header->length = sizeof(acpi_mcfg_t);
247 header->revision = 1;
248
249 current = acpi_fill_mcfg(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000250
Uwe Hermann622824c2010-11-19 15:14:42 +0000251 /* (Re)calculate length and checksum. */
252 header->length = current - (unsigned long)mcfg;
253 header->checksum = acpi_checksum((void *)mcfg, header->length);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000254}
255
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200256static void *get_tcpa_log(u32 *size)
257{
258 const struct cbmem_entry *ce;
259 const u32 tcpa_default_log_len = 0x10000;
260 void *lasa;
261 ce = cbmem_entry_find(CBMEM_ID_TCPA_LOG);
262 if (ce) {
263 lasa = cbmem_entry_start(ce);
264 *size = cbmem_entry_size(ce);
265 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
266 return lasa;
267 }
268 lasa = cbmem_add(CBMEM_ID_TCPA_LOG, tcpa_default_log_len);
269 if (!lasa) {
270 printk(BIOS_ERR, "TCPA log creation failed\n");
271 return NULL;
272 }
273
274 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
275 memset (lasa, 0, tcpa_default_log_len);
276
277 *size = tcpa_default_log_len;
278 return lasa;
279}
280
281static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
282{
283 acpi_header_t *header = &(tcpa->header);
284 u32 tcpa_log_len;
285 void *lasa;
286
287 memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
288
289 lasa = get_tcpa_log(&tcpa_log_len);
290 if (!lasa) {
291 return;
292 }
293
294 /* Fill out header fields. */
295 memcpy(header->signature, "TCPA", 4);
296 memcpy(header->oem_id, OEM_ID, 6);
297 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
298 memcpy(header->asl_compiler_id, ASLC, 4);
299
300 header->length = sizeof(acpi_tcpa_t);
301 header->revision = 2;
302
303 tcpa->platform_class = 0;
304 tcpa->laml = tcpa_log_len;
Stefan Reinauerdefee172015-06-18 01:11:19 -0700305 tcpa->lasa = (uintptr_t) lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200306
307 /* Calculate checksum. */
308 header->checksum = acpi_checksum((void *)tcpa, header->length);
309}
310
Duncan Laurie37319032016-05-26 12:47:05 -0700311static void acpi_ssdt_write_cbtable(void)
312{
313 const struct cbmem_entry *cbtable;
314 uintptr_t base;
315 uint32_t size;
316
317 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
318 if (!cbtable)
319 return;
320 base = (uintptr_t)cbmem_entry_start(cbtable);
321 size = cbmem_entry_size(cbtable);
322
323 acpigen_write_device("CTBL");
324 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
325 acpigen_write_name_integer("_UID", 0);
326 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
327 acpigen_write_name("_CRS");
328 acpigen_write_resourcetemplate_header();
329 acpigen_write_mem32fixed(0, base, size);
330 acpigen_write_resourcetemplate_footer();
331 acpigen_pop_len();
332}
333
Myles Watson3fe6b702009-10-09 20:13:43 +0000334void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000335{
Uwe Hermann622824c2010-11-19 15:14:42 +0000336 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
337
Rudolf Marek293b5f52009-02-01 18:35:15 +0000338 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000339
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000340 memcpy(&ssdt->signature, "SSDT", 4);
Uwe Hermann622824c2010-11-19 15:14:42 +0000341 ssdt->revision = 2; /* ACPI 1.0/2.0: ?, ACPI 3.0/4.0: 2 */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000342 memcpy(&ssdt->oem_id, OEM_ID, 6);
343 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
344 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000345 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000346 ssdt->asl_compiler_revision = 42;
347 ssdt->length = sizeof(acpi_header_t);
348
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000349 acpigen_set_current((char *) current);
Duncan Laurie37319032016-05-26 12:47:05 -0700350
351 /* Write object to declare coreboot tables */
352 acpi_ssdt_write_cbtable();
353
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200354 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100355 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200356 for (dev = all_devices; dev; dev = dev->next)
357 if (dev->ops && dev->ops->acpi_fill_ssdt_generator) {
Alexander Couzens5eea4582015-04-12 22:18:55 +0200358 dev->ops->acpi_fill_ssdt_generator(dev);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200359 }
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200360 current = (unsigned long) acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200361 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000362
Uwe Hermann622824c2010-11-19 15:14:42 +0000363 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000364 ssdt->length = current - (unsigned long)ssdt;
365 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
366}
367
Stefan Reinauerf622d592005-11-26 16:56:05 +0000368int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
369{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000370 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000371
Uwe Hermann622824c2010-11-19 15:14:42 +0000372 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
373 lapic->length = sizeof(acpi_srat_lapic_t);
374 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
375 lapic->proximity_domain_7_0 = node;
376 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
377 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000378
Uwe Hermann622824c2010-11-19 15:14:42 +0000379 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000380}
381
Uwe Hermann622824c2010-11-19 15:14:42 +0000382int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300383 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000384{
Uwe Hermann622824c2010-11-19 15:14:42 +0000385 mem->type = 1; /* Memory affinity structure */
386 mem->length = sizeof(acpi_srat_mem_t);
387 mem->base_address_low = (basek << 10);
388 mem->base_address_high = (basek >> (32 - 10));
389 mem->length_low = (sizek << 10);
390 mem->length_high = (sizek >> (32 - 10));
391 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000392 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000393
Uwe Hermann622824c2010-11-19 15:14:42 +0000394 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000395}
396
Uwe Hermann622824c2010-11-19 15:14:42 +0000397/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200398void acpi_create_srat(acpi_srat_t *srat,
399 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000400{
Uwe Hermann622824c2010-11-19 15:14:42 +0000401 acpi_header_t *header = &(srat->header);
402 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000403
Uwe Hermann622824c2010-11-19 15:14:42 +0000404 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000405
Uwe Hermann622824c2010-11-19 15:14:42 +0000406 /* Fill out header fields. */
407 memcpy(header->signature, "SRAT", 4);
408 memcpy(header->oem_id, OEM_ID, 6);
409 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
410 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000411
Uwe Hermann622824c2010-11-19 15:14:42 +0000412 header->length = sizeof(acpi_srat_t);
413 header->revision = 1; /* ACPI 1.0: N/A, 2.0: 1, 3.0: 2, 4.0: 3 */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000414
Uwe Hermann622824c2010-11-19 15:14:42 +0000415 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000416
Uwe Hermann622824c2010-11-19 15:14:42 +0000417 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000418
Uwe Hermann622824c2010-11-19 15:14:42 +0000419 /* (Re)calculate length and checksum. */
420 header->length = current - (unsigned long)srat;
421 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000422}
423
Nico Hubere561f352015-10-26 11:51:25 +0100424void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +0100425 unsigned long (*acpi_fill_dmar) (unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200426{
427 acpi_header_t *header = &(dmar->header);
428 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
429
430 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
431
432 /* Fill out header fields. */
433 memcpy(header->signature, "DMAR", 4);
434 memcpy(header->oem_id, OEM_ID, 6);
435 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
436 memcpy(header->asl_compiler_id, ASLC, 4);
437
438 header->length = sizeof(acpi_dmar_t);
439 header->revision = 1;
440
Jacob Laskaf3f654d2016-03-15 21:53:27 -0500441 dmar->host_address_width = cpu_phys_address_size() - 1;
Nico Hubere561f352015-10-26 11:51:25 +0100442 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200443
444 current = acpi_fill_dmar(current);
445
446 /* (Re)calculate length and checksum. */
447 header->length = current - (unsigned long)dmar;
448 header->checksum = acpi_checksum((void *)dmar, header->length);
449}
450
451unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
452 u16 segment, u32 bar)
453{
454 dmar_entry_t *drhd = (dmar_entry_t *)current;
455 memset(drhd, 0, sizeof(*drhd));
456 drhd->type = DMAR_DRHD;
457 drhd->length = sizeof(*drhd); /* will be fixed up later */
458 drhd->flags = flags;
459 drhd->segment = segment;
460 drhd->bar = bar;
461
462 return drhd->length;
463}
464
Werner Zehd4d76952016-07-27 06:56:36 +0200465unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
466 u16 segment)
467{
468 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
469 memset(atsr, 0, sizeof(*atsr));
470 atsr->type = DMAR_ATSR;
471 atsr->length = sizeof(*atsr); /* will be fixed up later */
472 atsr->flags = flags;
473 atsr->segment = segment;
474
475 return atsr->length;
476}
477
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200478void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
479{
480 dmar_entry_t *drhd = (dmar_entry_t *)base;
481 drhd->length = current - base;
482}
483
Werner Zehd4d76952016-07-27 06:56:36 +0200484void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
485{
486 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base;
487 atsr->length = current - base;
488}
489
Nico Huber6c4751d2015-10-26 12:03:54 +0100490static unsigned long acpi_create_dmar_drhd_ds(unsigned long current,
491 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200492{
Nico Huber6c4751d2015-10-26 12:03:54 +0100493 /* we don't support longer paths yet */
494 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
495
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200496 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100497 memset(ds, 0, dev_scope_length);
498 ds->type = type;
499 ds->length = dev_scope_length;
500 ds->enumeration = enumeration_id;
501 ds->start_bus = bus;
502 ds->path[0].dev = dev;
503 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200504
505 return ds->length;
506}
507
Werner Zeh21a5bff2016-07-27 07:07:20 +0200508unsigned long acpi_create_dmar_drhd_ds_pci_br(unsigned long current, u8 bus,
509 u8 dev, u8 fn)
510{
511 return acpi_create_dmar_drhd_ds(current,
512 SCOPE_PCI_SUB, 0, bus, dev, fn);
513}
514
Nico Huber6c4751d2015-10-26 12:03:54 +0100515unsigned long acpi_create_dmar_drhd_ds_pci(unsigned long current, u8 bus,
516 u8 dev, u8 fn)
517{
518 return acpi_create_dmar_drhd_ds(current,
519 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
520}
521
522unsigned long acpi_create_dmar_drhd_ds_ioapic(unsigned long current,
523 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
524{
525 return acpi_create_dmar_drhd_ds(current,
526 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
527}
528
529unsigned long acpi_create_dmar_drhd_ds_msi_hpet(unsigned long current,
530 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
531{
532 return acpi_create_dmar_drhd_ds(current,
533 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
534}
535
Uwe Hermann622824c2010-11-19 15:14:42 +0000536/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200537void acpi_create_slit(acpi_slit_t *slit,
538 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000539{
Uwe Hermann622824c2010-11-19 15:14:42 +0000540 acpi_header_t *header = &(slit->header);
541 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000542
Uwe Hermann622824c2010-11-19 15:14:42 +0000543 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000544
Uwe Hermann622824c2010-11-19 15:14:42 +0000545 /* Fill out header fields. */
546 memcpy(header->signature, "SLIT", 4);
547 memcpy(header->oem_id, OEM_ID, 6);
548 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
549 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000550
Uwe Hermann622824c2010-11-19 15:14:42 +0000551 header->length = sizeof(acpi_slit_t);
552 header->revision = 1; /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000553
Uwe Hermann622824c2010-11-19 15:14:42 +0000554 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000555
Uwe Hermann622824c2010-11-19 15:14:42 +0000556 /* (Re)calculate length and checksum. */
557 header->length = current - (unsigned long)slit;
558 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000559}
560
Uwe Hermann622824c2010-11-19 15:14:42 +0000561/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000562void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000563{
Uwe Hermann622824c2010-11-19 15:14:42 +0000564 acpi_header_t *header = &(hpet->header);
565 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000566
Stefan Reinauera7648c22004-01-29 17:31:34 +0000567 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000568
Uwe Hermann622824c2010-11-19 15:14:42 +0000569 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000570 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000571 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000572 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000573 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000574
Stefan Reinauer688b3852004-01-28 16:56:14 +0000575 header->length = sizeof(acpi_hpet_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000576 header->revision = 1; /* Currently 1. Table added in ACPI 2.0. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000577
Uwe Hermann622824c2010-11-19 15:14:42 +0000578 /* Fill out HPET address. */
579 addr->space_id = 0; /* Memory */
580 addr->bit_width = 64;
581 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200582 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
583 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000584
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200585 hpet->id = *(unsigned int*)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000586 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200587 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000588
Uwe Hermann622824c2010-11-19 15:14:42 +0000589 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000590}
Uwe Hermann622824c2010-11-19 15:14:42 +0000591
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500592void acpi_create_ivrs(acpi_ivrs_t *ivrs,
593 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t* ivrs_struct, unsigned long current))
594{
595 acpi_header_t *header = &(ivrs->header);
596 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
597
598 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
599
600 /* Fill out header fields. */
601 memcpy(header->signature, "IVRS", 4);
602 memcpy(header->oem_id, OEM_ID, 6);
603 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
604 memcpy(header->asl_compiler_id, ASLC, 4);
605
606 header->length = sizeof(acpi_ivrs_t);
Martin Rotha66df492016-09-06 10:22:34 -0600607 header->revision = IVRS_FORMAT_FIXED;
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500608
609 current = acpi_fill_ivrs(ivrs, current);
610
611 /* (Re)calculate length and checksum. */
612 header->length = current - (unsigned long)ivrs;
613 header->checksum = acpi_checksum((void *)ivrs, header->length);
614}
615
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200616unsigned long acpi_write_hpet(device_t device, unsigned long current, acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200617{
618 acpi_hpet_t *hpet;
619
620 /*
621 * We explicitly add these tables later on:
622 */
623 printk(BIOS_DEBUG, "ACPI: * HPET\n");
624
625 hpet = (acpi_hpet_t *) current;
626 current += sizeof(acpi_hpet_t);
627 current = ALIGN(current, 16);
628 acpi_create_hpet(hpet);
629 acpi_add_table(rsdp, hpet);
630
631 return current;
632}
633
Stefan Reinauer777224c2005-01-19 14:06:41 +0000634void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000635{
Uwe Hermann622824c2010-11-19 15:14:42 +0000636 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000637
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000638 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000639 facs->length = sizeof(acpi_facs_t);
640 facs->hardware_signature = 0;
641 facs->firmware_waking_vector = 0;
642 facs->global_lock = 0;
643 facs->flags = 0;
644 facs->x_firmware_waking_vector_l = 0;
645 facs->x_firmware_waking_vector_h = 0;
Uwe Hermann622824c2010-11-19 15:14:42 +0000646 facs->version = 1; /* ACPI 1.0: 0, ACPI 2.0/3.0: 1, ACPI 4.0: 2 */
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000647}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000648
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100649static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000650{
Uwe Hermann622824c2010-11-19 15:14:42 +0000651 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000652
Uwe Hermann622824c2010-11-19 15:14:42 +0000653 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000654 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100655 memcpy(header->oem_id, oem_id, 6);
656 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000657 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000658
Stefan Reinauer688b3852004-01-28 16:56:14 +0000659 header->length = sizeof(acpi_rsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000660 header->revision = 1; /* ACPI 1.0/2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000661
Uwe Hermann622824c2010-11-19 15:14:42 +0000662 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000663
Uwe Hermann622824c2010-11-19 15:14:42 +0000664 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000665 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000666}
667
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100668static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000669{
Uwe Hermann622824c2010-11-19 15:14:42 +0000670 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000671
Uwe Hermann622824c2010-11-19 15:14:42 +0000672 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000673 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100674 memcpy(header->oem_id, oem_id, 6);
675 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000676 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000677
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000678 header->length = sizeof(acpi_xsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000679 header->revision = 1; /* ACPI 1.0: N/A, 2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000680
Uwe Hermann622824c2010-11-19 15:14:42 +0000681 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000682
Uwe Hermann622824c2010-11-19 15:14:42 +0000683 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000684 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
685}
686
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100687static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
688 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000689{
Stefan Reinauerd18faac2009-11-05 18:06:43 +0000690 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000691
Stefan Reinauer688b3852004-01-28 16:56:14 +0000692 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100693 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +0000694
695 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -0700696 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000697
698 /*
699 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
700 *
701 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
702 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
703 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000704 */
705 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000706 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000707 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -0700708 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000709 rsdp->revision = 2;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000710 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000711
712 /* Calculate checksums. */
713 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
714 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000715}
716
zbaocaf494c82012-04-13 13:57:14 +0800717unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
718{
719 acpi_header_t *header = &(hest->header);
720 acpi_hest_hen_t *hen;
721 void *pos;
722 u16 len;
723
724 pos = esd;
725 memset(pos, 0, sizeof(acpi_hest_esd_t));
726 len = 0;
727 esd->type = type; /* MCE */
728 esd->source_id = hest->error_source_count;
729 esd->flags = 0; /* FIRMWARE_FIRST */
730 esd->enabled = 1;
731 esd->prealloc_erecords = 1;
732 esd->max_section_per_record = 0x1;
733
734 len += sizeof(acpi_hest_esd_t);
735 pos = esd + 1;
736
737 switch (type) {
738 case 0: /* MCE */
739 break;
740 case 1: /* CMC */
741 hen = (acpi_hest_hen_t *) (pos);
742 memset(pos, 0, sizeof(acpi_hest_hen_t));
743 hen->type = 3; /* SCI? */
744 hen->length = sizeof(acpi_hest_hen_t);
745 hen->conf_we = 0; /* Configuration Write Enable. */
746 hen->poll_interval = 0;
747 hen->vector = 0;
748 hen->sw2poll_threshold_val = 0;
749 hen->sw2poll_threshold_win = 0;
750 hen->error_threshold_val = 0;
751 hen->error_threshold_win = 0;
752 len += sizeof(acpi_hest_hen_t);
753 pos = hen + 1;
754 break;
755 case 2: /* NMI */
756 case 6: /* AER Root Port */
757 case 7: /* AER Endpoint */
758 case 8: /* AER Bridge */
759 case 9: /* Generic Hardware Error Source. */
760 /* TODO: */
761 break;
762 default:
763 printk(BIOS_DEBUG, "Invalid type of Error Source.");
764 break;
765 }
766 hest->error_source_count ++;
767
768 memcpy(pos, data, data_len);
769 len += data_len;
770 header->length += len;
771
772 return len;
773}
774
775/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100776void acpi_write_hest(acpi_hest_t *hest,
777 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +0800778{
779 acpi_header_t *header = &(hest->header);
780
781 memset(hest, 0, sizeof(acpi_hest_t));
782
783 memcpy(header->signature, "HEST", 4);
784 memcpy(header->oem_id, OEM_ID, 6);
785 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
786 memcpy(header->asl_compiler_id, ASLC, 4);
787 header->length += sizeof(acpi_hest_t);
788 header->revision = 1;
789
790 acpi_fill_hest(hest);
791
792 /* Calculate checksums. */
793 header->checksum = acpi_checksum((void *)hest, header->length);
794}
795
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200796#if IS_ENABLED(CONFIG_COMMON_FADT)
797void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt)
798{
799 acpi_header_t *header = &(fadt->header);
800
801 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
802 memcpy(header->signature, "FACP", 4);
803 header->length = sizeof(acpi_fadt_t);
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200804 header->revision = 4;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200805 memcpy(header->oem_id, OEM_ID, 6);
806 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
807 memcpy(header->asl_compiler_id, ASLC, 4);
808 header->asl_compiler_revision = 0;
809
810 fadt->firmware_ctrl = (unsigned long) facs;
811 fadt->dsdt = (unsigned long) dsdt;
812
813 fadt->x_firmware_ctl_l = (unsigned long)facs;
814 fadt->x_firmware_ctl_h = 0;
815 fadt->x_dsdt_l = (unsigned long)dsdt;
816 fadt->x_dsdt_h = 0;
817
Elyes HAOUASdbf30672016-08-21 17:37:15 +0200818 if (IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) {
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200819 fadt->preferred_pm_profile = PM_MOBILE;
820 } else {
821 fadt->preferred_pm_profile = PM_DESKTOP;
822 }
823
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200824 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200825
826 header->checksum =
827 acpi_checksum((void *) fadt, header->length);
828}
829#endif
830
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200831unsigned long __attribute__ ((weak)) fw_cfg_acpi_tables(unsigned long start)
832{
833 return 0;
834}
835
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200836unsigned long write_acpi_tables(unsigned long start)
837{
838 unsigned long current;
839 acpi_rsdp_t *rsdp;
840 acpi_rsdt_t *rsdt;
841 acpi_xsdt_t *xsdt;
842 acpi_fadt_t *fadt;
843 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100844 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200845 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200846 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200847 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200848 acpi_tcpa_t *tcpa;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200849 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100850 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200851 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200852 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100853 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200854
855 current = start;
856
857 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -0600858 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200859
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200860 fw = fw_cfg_acpi_tables(current);
861 if (fw)
862 return fw;
863
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +0200864 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200865 CONFIG_CBFS_PREFIX "/dsdt.aml",
866 CBFS_TYPE_RAW, &dsdt_size);
867 if (!dsdt_file) {
868 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
869 return current;
870 }
871
872 if (dsdt_file->length > dsdt_size
873 || dsdt_file->length < sizeof (acpi_header_t)
874 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
875 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
876 return current;
877 }
878
Aaron Durbin899d13d2015-05-15 23:39:23 -0500879 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100880 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +0200881 if (slic_file
882 && (slic_file->length > slic_size
883 || slic_file->length < sizeof (acpi_header_t)
884 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100885 slic_file = 0;
886 }
887
888 if (slic_file) {
889 memcpy(oem_id, slic_file->oem_id, 6);
890 memcpy(oem_table_id, slic_file->oem_table_id, 8);
891 } else {
892 memcpy(oem_id, OEM_ID, 6);
893 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
894 }
895
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200896 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
897
898 /* We need at least an RSDP and an RSDT Table */
899 rsdp = (acpi_rsdp_t *) current;
900 current += sizeof(acpi_rsdp_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600901 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200902 rsdt = (acpi_rsdt_t *) current;
903 current += sizeof(acpi_rsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600904 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200905 xsdt = (acpi_xsdt_t *) current;
906 current += sizeof(acpi_xsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600907 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200908
909 /* clear all table memory */
910 memset((void *) start, 0, current - start);
911
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100912 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
913 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
914 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200915
916 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Patrick Georgi133108a2015-08-08 23:20:58 +0200917 current = (ALIGN(current, 64));
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200918 facs = (acpi_facs_t *) current;
919 current += sizeof(acpi_facs_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600920 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200921 acpi_create_facs(facs);
922
923 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
924 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200925 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200926 if (dsdt->length >= sizeof(acpi_header_t)) {
927 current += sizeof(acpi_header_t);
928
929 acpigen_set_current((char *) current);
930 for (dev = all_devices; dev; dev = dev->next)
931 if (dev->ops && dev->ops->acpi_inject_dsdt_generator) {
Alexander Couzensa90dad12015-04-12 21:49:46 +0200932 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200933 }
934 current = (unsigned long) acpigen_get_current();
935 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200936 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200937 dsdt->length - sizeof(acpi_header_t));
938 current += dsdt->length - sizeof(acpi_header_t);
939
940 /* (Re)calculate length and checksum. */
941 dsdt->length = current - (unsigned long)dsdt;
942 dsdt->checksum = 0;
943 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
944 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200945
Aaron Durbin07a1b282015-12-10 17:07:38 -0600946 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200947
948 printk(BIOS_DEBUG, "ACPI: * FADT\n");
949 fadt = (acpi_fadt_t *) current;
950 current += sizeof(acpi_fadt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600951 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200952
953 acpi_create_fadt(fadt, facs, dsdt);
954 acpi_add_table(rsdp, fadt);
955
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100956 if (slic_file) {
957 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
958 slic = (acpi_header_t *)current;
959 memcpy(slic, slic_file, slic_file->length);
960 current += slic_file->length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600961 current = acpi_align_current(current);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100962 acpi_add_table(rsdp, slic);
963 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200964
965 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
966 ssdt = (acpi_header_t *)current;
967 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +0200968 if (ssdt->length > sizeof(acpi_header_t)) {
969 current += ssdt->length;
970 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600971 current = acpi_align_current(current);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +0200972 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200973
974 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
975 mcfg = (acpi_mcfg_t *) current;
976 acpi_create_mcfg(mcfg);
977 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
978 current += mcfg->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600979 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200980 acpi_add_table(rsdp, mcfg);
981 }
982
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200983 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
984 tcpa = (acpi_tcpa_t *) current;
985 acpi_create_tcpa(tcpa);
986 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
987 current += tcpa->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600988 current = acpi_align_current(current);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200989 acpi_add_table(rsdp, tcpa);
990 }
991
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200992 printk(BIOS_DEBUG, "ACPI: * MADT\n");
993
994 madt = (acpi_madt_t *) current;
995 acpi_create_madt(madt);
996 if (madt->header.length > sizeof(acpi_madt_t)) {
997 current+=madt->header.length;
998 acpi_add_table(rsdp,madt);
999 }
Aaron Durbin07a1b282015-12-10 17:07:38 -06001000 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001001
1002 printk(BIOS_DEBUG, "current = %lx\n", current);
1003
1004 for (dev = all_devices; dev; dev = dev->next) {
1005 if (dev->ops && dev->ops->write_acpi_tables) {
Alexander Couzens83fc32f2015-04-12 22:28:37 +02001006 current = dev->ops->write_acpi_tables(dev, current, rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001007 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001008 }
1009 }
1010
1011 printk(BIOS_INFO, "ACPI: done.\n");
1012 return current;
1013}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001014
Rudolf Marek33cafe52009-04-13 18:07:02 +00001015static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1016{
1017 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1018 return NULL;
1019
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001020 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001021
1022 if (acpi_checksum((void *)rsdp, 20) != 0)
1023 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001024 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001025
1026 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1027 rsdp->length) != 0))
1028 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001029 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001030
1031 return rsdp;
1032}
1033
Rudolf Marek33cafe52009-04-13 18:07:02 +00001034void *acpi_find_wakeup_vector(void)
1035{
1036 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001037 acpi_rsdt_t *rsdt;
1038 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001039 acpi_fadt_t *fadt = NULL;
Kyösti Mälkki072d436b2016-06-17 08:44:40 +03001040 acpi_rsdp_t *rsdp = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001041 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001042 int i;
1043
Rudolf Marek33cafe52009-04-13 18:07:02 +00001044 if (!acpi_is_wakeup())
1045 return NULL;
1046
Uwe Hermann622824c2010-11-19 15:14:42 +00001047 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001048
Uwe Hermann622824c2010-11-19 15:14:42 +00001049 /* Find RSDP. */
1050 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
1051 if ((rsdp = valid_rsdp((acpi_rsdp_t *)p)))
Rudolf Marek33cafe52009-04-13 18:07:02 +00001052 break;
1053 }
1054
1055 if (rsdp == NULL)
1056 return NULL;
1057
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001058 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001059 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001060
Uwe Hermann622824c2010-11-19 15:14:42 +00001061 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001062 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001063
Uwe Hermann622824c2010-11-19 15:14:42 +00001064 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001065 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001066 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001067 break;
1068 fadt = NULL;
1069 }
1070
1071 if (fadt == NULL)
1072 return NULL;
1073
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001074 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001075 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001076
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001077 if (facs == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001078 printk(BIOS_DEBUG, "No FACS found, wake up from S3 not "
1079 "possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001080 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001081 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001082
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001083 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001084 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001085 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001086
Rudolf Marek33cafe52009-04-13 18:07:02 +00001087 return wake_vec;
1088}
1089
Duncan Laurie11290c42012-10-03 19:07:05 -07001090void acpi_save_gnvs(u32 gnvs_address)
1091{
Duncan Laurie9c07c8f2013-03-22 11:08:39 -07001092 u32 *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS_PTR, sizeof(*gnvs));
Duncan Laurie11290c42012-10-03 19:07:05 -07001093 if (gnvs)
1094 *gnvs = gnvs_address;
1095}
Duncan Laurie1f6e6812016-09-19 12:04:19 -07001096
1097__attribute__ ((weak)) int acpi_get_gpe(int gpe)
1098{
1099 return -1; /* implemented by SOC */
1100}