blob: 4109ec4fae716ec497bbb6f833cabc51a9963c8b [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);
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700290 if (!lasa)
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200291 return;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200292
293 /* Fill out header fields. */
294 memcpy(header->signature, "TCPA", 4);
295 memcpy(header->oem_id, OEM_ID, 6);
296 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
297 memcpy(header->asl_compiler_id, ASLC, 4);
298
299 header->length = sizeof(acpi_tcpa_t);
300 header->revision = 2;
301
302 tcpa->platform_class = 0;
303 tcpa->laml = tcpa_log_len;
Stefan Reinauerdefee172015-06-18 01:11:19 -0700304 tcpa->lasa = (uintptr_t) lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200305
306 /* Calculate checksum. */
307 header->checksum = acpi_checksum((void *)tcpa, header->length);
308}
309
Duncan Laurie37319032016-05-26 12:47:05 -0700310static void acpi_ssdt_write_cbtable(void)
311{
312 const struct cbmem_entry *cbtable;
313 uintptr_t base;
314 uint32_t size;
315
316 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
317 if (!cbtable)
318 return;
319 base = (uintptr_t)cbmem_entry_start(cbtable);
320 size = cbmem_entry_size(cbtable);
321
322 acpigen_write_device("CTBL");
323 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
324 acpigen_write_name_integer("_UID", 0);
325 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
326 acpigen_write_name("_CRS");
327 acpigen_write_resourcetemplate_header();
328 acpigen_write_mem32fixed(0, base, size);
329 acpigen_write_resourcetemplate_footer();
330 acpigen_pop_len();
331}
332
Myles Watson3fe6b702009-10-09 20:13:43 +0000333void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000334{
Uwe Hermann622824c2010-11-19 15:14:42 +0000335 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
336
Rudolf Marek293b5f52009-02-01 18:35:15 +0000337 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000338
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000339 memcpy(&ssdt->signature, "SSDT", 4);
Uwe Hermann622824c2010-11-19 15:14:42 +0000340 ssdt->revision = 2; /* ACPI 1.0/2.0: ?, ACPI 3.0/4.0: 2 */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000341 memcpy(&ssdt->oem_id, OEM_ID, 6);
342 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
343 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000344 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000345 ssdt->asl_compiler_revision = 42;
346 ssdt->length = sizeof(acpi_header_t);
347
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000348 acpigen_set_current((char *) current);
Duncan Laurie37319032016-05-26 12:47:05 -0700349
350 /* Write object to declare coreboot tables */
351 acpi_ssdt_write_cbtable();
352
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200353 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100354 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200355 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700356 if (dev->ops && dev->ops->acpi_fill_ssdt_generator)
Alexander Couzens5eea4582015-04-12 22:18:55 +0200357 dev->ops->acpi_fill_ssdt_generator(dev);
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200358 current = (unsigned long) acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200359 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000360
Uwe Hermann622824c2010-11-19 15:14:42 +0000361 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000362 ssdt->length = current - (unsigned long)ssdt;
363 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
364}
365
Stefan Reinauerf622d592005-11-26 16:56:05 +0000366int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
367{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000368 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000369
Uwe Hermann622824c2010-11-19 15:14:42 +0000370 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
371 lapic->length = sizeof(acpi_srat_lapic_t);
372 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
373 lapic->proximity_domain_7_0 = node;
374 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
375 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000376
Uwe Hermann622824c2010-11-19 15:14:42 +0000377 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000378}
379
Uwe Hermann622824c2010-11-19 15:14:42 +0000380int 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 +0300381 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000382{
Uwe Hermann622824c2010-11-19 15:14:42 +0000383 mem->type = 1; /* Memory affinity structure */
384 mem->length = sizeof(acpi_srat_mem_t);
385 mem->base_address_low = (basek << 10);
386 mem->base_address_high = (basek >> (32 - 10));
387 mem->length_low = (sizek << 10);
388 mem->length_high = (sizek >> (32 - 10));
389 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000390 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000391
Uwe Hermann622824c2010-11-19 15:14:42 +0000392 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000393}
394
Uwe Hermann622824c2010-11-19 15:14:42 +0000395/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200396void acpi_create_srat(acpi_srat_t *srat,
397 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000398{
Uwe Hermann622824c2010-11-19 15:14:42 +0000399 acpi_header_t *header = &(srat->header);
400 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000401
Uwe Hermann622824c2010-11-19 15:14:42 +0000402 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000403
Uwe Hermann622824c2010-11-19 15:14:42 +0000404 /* Fill out header fields. */
405 memcpy(header->signature, "SRAT", 4);
406 memcpy(header->oem_id, OEM_ID, 6);
407 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
408 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000409
Uwe Hermann622824c2010-11-19 15:14:42 +0000410 header->length = sizeof(acpi_srat_t);
411 header->revision = 1; /* ACPI 1.0: N/A, 2.0: 1, 3.0: 2, 4.0: 3 */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000412
Uwe Hermann622824c2010-11-19 15:14:42 +0000413 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000414
Uwe Hermann622824c2010-11-19 15:14:42 +0000415 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000416
Uwe Hermann622824c2010-11-19 15:14:42 +0000417 /* (Re)calculate length and checksum. */
418 header->length = current - (unsigned long)srat;
419 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000420}
421
Nico Hubere561f352015-10-26 11:51:25 +0100422void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +0100423 unsigned long (*acpi_fill_dmar) (unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200424{
425 acpi_header_t *header = &(dmar->header);
426 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
427
428 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
429
430 /* Fill out header fields. */
431 memcpy(header->signature, "DMAR", 4);
432 memcpy(header->oem_id, OEM_ID, 6);
433 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
434 memcpy(header->asl_compiler_id, ASLC, 4);
435
436 header->length = sizeof(acpi_dmar_t);
437 header->revision = 1;
438
Jacob Laskaf3f654d2016-03-15 21:53:27 -0500439 dmar->host_address_width = cpu_phys_address_size() - 1;
Nico Hubere561f352015-10-26 11:51:25 +0100440 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200441
442 current = acpi_fill_dmar(current);
443
444 /* (Re)calculate length and checksum. */
445 header->length = current - (unsigned long)dmar;
446 header->checksum = acpi_checksum((void *)dmar, header->length);
447}
448
449unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
450 u16 segment, u32 bar)
451{
452 dmar_entry_t *drhd = (dmar_entry_t *)current;
453 memset(drhd, 0, sizeof(*drhd));
454 drhd->type = DMAR_DRHD;
455 drhd->length = sizeof(*drhd); /* will be fixed up later */
456 drhd->flags = flags;
457 drhd->segment = segment;
458 drhd->bar = bar;
459
460 return drhd->length;
461}
462
Werner Zehd4d76952016-07-27 06:56:36 +0200463unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
464 u16 segment)
465{
466 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
467 memset(atsr, 0, sizeof(*atsr));
468 atsr->type = DMAR_ATSR;
469 atsr->length = sizeof(*atsr); /* will be fixed up later */
470 atsr->flags = flags;
471 atsr->segment = segment;
472
473 return atsr->length;
474}
475
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200476void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
477{
478 dmar_entry_t *drhd = (dmar_entry_t *)base;
479 drhd->length = current - base;
480}
481
Werner Zehd4d76952016-07-27 06:56:36 +0200482void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
483{
484 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base;
485 atsr->length = current - base;
486}
487
Nico Huber6c4751d2015-10-26 12:03:54 +0100488static unsigned long acpi_create_dmar_drhd_ds(unsigned long current,
489 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200490{
Nico Huber6c4751d2015-10-26 12:03:54 +0100491 /* we don't support longer paths yet */
492 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
493
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200494 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100495 memset(ds, 0, dev_scope_length);
496 ds->type = type;
497 ds->length = dev_scope_length;
498 ds->enumeration = enumeration_id;
499 ds->start_bus = bus;
500 ds->path[0].dev = dev;
501 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200502
503 return ds->length;
504}
505
Werner Zeh21a5bff2016-07-27 07:07:20 +0200506unsigned long acpi_create_dmar_drhd_ds_pci_br(unsigned long current, u8 bus,
507 u8 dev, u8 fn)
508{
509 return acpi_create_dmar_drhd_ds(current,
510 SCOPE_PCI_SUB, 0, bus, dev, fn);
511}
512
Nico Huber6c4751d2015-10-26 12:03:54 +0100513unsigned long acpi_create_dmar_drhd_ds_pci(unsigned long current, u8 bus,
514 u8 dev, u8 fn)
515{
516 return acpi_create_dmar_drhd_ds(current,
517 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
518}
519
520unsigned long acpi_create_dmar_drhd_ds_ioapic(unsigned long current,
521 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
522{
523 return acpi_create_dmar_drhd_ds(current,
524 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
525}
526
527unsigned long acpi_create_dmar_drhd_ds_msi_hpet(unsigned long current,
528 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
529{
530 return acpi_create_dmar_drhd_ds(current,
531 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
532}
533
Uwe Hermann622824c2010-11-19 15:14:42 +0000534/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200535void acpi_create_slit(acpi_slit_t *slit,
536 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000537{
Uwe Hermann622824c2010-11-19 15:14:42 +0000538 acpi_header_t *header = &(slit->header);
539 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000540
Uwe Hermann622824c2010-11-19 15:14:42 +0000541 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000542
Uwe Hermann622824c2010-11-19 15:14:42 +0000543 /* Fill out header fields. */
544 memcpy(header->signature, "SLIT", 4);
545 memcpy(header->oem_id, OEM_ID, 6);
546 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
547 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000548
Uwe Hermann622824c2010-11-19 15:14:42 +0000549 header->length = sizeof(acpi_slit_t);
550 header->revision = 1; /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000551
Uwe Hermann622824c2010-11-19 15:14:42 +0000552 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000553
Uwe Hermann622824c2010-11-19 15:14:42 +0000554 /* (Re)calculate length and checksum. */
555 header->length = current - (unsigned long)slit;
556 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000557}
558
Uwe Hermann622824c2010-11-19 15:14:42 +0000559/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000560void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000561{
Uwe Hermann622824c2010-11-19 15:14:42 +0000562 acpi_header_t *header = &(hpet->header);
563 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000564
Stefan Reinauera7648c22004-01-29 17:31:34 +0000565 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000566
Uwe Hermann622824c2010-11-19 15:14:42 +0000567 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000568 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000569 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000570 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000571 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000572
Stefan Reinauer688b3852004-01-28 16:56:14 +0000573 header->length = sizeof(acpi_hpet_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000574 header->revision = 1; /* Currently 1. Table added in ACPI 2.0. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000575
Uwe Hermann622824c2010-11-19 15:14:42 +0000576 /* Fill out HPET address. */
577 addr->space_id = 0; /* Memory */
578 addr->bit_width = 64;
579 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200580 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
581 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000582
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200583 hpet->id = *(unsigned int*)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000584 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200585 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000586
Uwe Hermann622824c2010-11-19 15:14:42 +0000587 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000588}
Uwe Hermann622824c2010-11-19 15:14:42 +0000589
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200590void acpi_create_vfct(struct device *device,
591 struct acpi_vfct *vfct,
592 unsigned long (*acpi_fill_vfct)(struct device *device, struct acpi_vfct *vfct_struct, unsigned long current))
593{
594 acpi_header_t *header = &(vfct->header);
595 unsigned long current = (unsigned long)vfct + sizeof(struct acpi_vfct);
596
597 memset((void *)vfct, 0, sizeof(struct acpi_vfct));
598
599 /* Fill out header fields. */
600 memcpy(header->signature, "VFCT", 4);
601 memcpy(header->oem_id, OEM_ID, 6);
602 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
603 memcpy(header->asl_compiler_id, ASLC, 4);
604
605 header->length = sizeof(struct acpi_vfct);
606 header->revision = 1; /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */
607
608 current = acpi_fill_vfct(device, vfct, current);
609
610 /* (Re)calculate length and checksum. */
611 header->length = current - (unsigned long)vfct;
612 header->checksum = acpi_checksum((void *)vfct, header->length);
613}
614
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500615void acpi_create_ivrs(acpi_ivrs_t *ivrs,
616 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t* ivrs_struct, unsigned long current))
617{
618 acpi_header_t *header = &(ivrs->header);
619 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
620
621 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
622
623 /* Fill out header fields. */
624 memcpy(header->signature, "IVRS", 4);
625 memcpy(header->oem_id, OEM_ID, 6);
626 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
627 memcpy(header->asl_compiler_id, ASLC, 4);
628
629 header->length = sizeof(acpi_ivrs_t);
Martin Rotha66df492016-09-06 10:22:34 -0600630 header->revision = IVRS_FORMAT_FIXED;
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500631
632 current = acpi_fill_ivrs(ivrs, current);
633
634 /* (Re)calculate length and checksum. */
635 header->length = current - (unsigned long)ivrs;
636 header->checksum = acpi_checksum((void *)ivrs, header->length);
637}
638
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200639unsigned long acpi_write_hpet(device_t device, unsigned long current, acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200640{
641 acpi_hpet_t *hpet;
642
643 /*
644 * We explicitly add these tables later on:
645 */
646 printk(BIOS_DEBUG, "ACPI: * HPET\n");
647
648 hpet = (acpi_hpet_t *) current;
649 current += sizeof(acpi_hpet_t);
650 current = ALIGN(current, 16);
651 acpi_create_hpet(hpet);
652 acpi_add_table(rsdp, hpet);
653
654 return current;
655}
656
Stefan Reinauer777224c2005-01-19 14:06:41 +0000657void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000658{
Uwe Hermann622824c2010-11-19 15:14:42 +0000659 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000660
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000661 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000662 facs->length = sizeof(acpi_facs_t);
663 facs->hardware_signature = 0;
664 facs->firmware_waking_vector = 0;
665 facs->global_lock = 0;
666 facs->flags = 0;
667 facs->x_firmware_waking_vector_l = 0;
668 facs->x_firmware_waking_vector_h = 0;
Uwe Hermann622824c2010-11-19 15:14:42 +0000669 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 +0000670}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000671
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100672static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000673{
Uwe Hermann622824c2010-11-19 15:14:42 +0000674 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000675
Uwe Hermann622824c2010-11-19 15:14:42 +0000676 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000677 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100678 memcpy(header->oem_id, oem_id, 6);
679 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000680 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000681
Stefan Reinauer688b3852004-01-28 16:56:14 +0000682 header->length = sizeof(acpi_rsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000683 header->revision = 1; /* ACPI 1.0/2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000684
Uwe Hermann622824c2010-11-19 15:14:42 +0000685 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000686
Uwe Hermann622824c2010-11-19 15:14:42 +0000687 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000688 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000689}
690
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100691static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000692{
Uwe Hermann622824c2010-11-19 15:14:42 +0000693 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000694
Uwe Hermann622824c2010-11-19 15:14:42 +0000695 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000696 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100697 memcpy(header->oem_id, oem_id, 6);
698 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000699 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000700
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000701 header->length = sizeof(acpi_xsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000702 header->revision = 1; /* ACPI 1.0: N/A, 2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000703
Uwe Hermann622824c2010-11-19 15:14:42 +0000704 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000705
Uwe Hermann622824c2010-11-19 15:14:42 +0000706 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000707 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
708}
709
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100710static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
711 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000712{
Stefan Reinauerd18faac2009-11-05 18:06:43 +0000713 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000714
Stefan Reinauer688b3852004-01-28 16:56:14 +0000715 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100716 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +0000717
718 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -0700719 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000720
721 /*
722 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
723 *
724 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
725 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
726 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000727 */
728 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000729 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000730 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -0700731 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000732 rsdp->revision = 2;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000733 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000734
735 /* Calculate checksums. */
736 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
737 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000738}
739
zbaocaf494c82012-04-13 13:57:14 +0800740unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
741{
742 acpi_header_t *header = &(hest->header);
743 acpi_hest_hen_t *hen;
744 void *pos;
745 u16 len;
746
747 pos = esd;
748 memset(pos, 0, sizeof(acpi_hest_esd_t));
749 len = 0;
750 esd->type = type; /* MCE */
751 esd->source_id = hest->error_source_count;
752 esd->flags = 0; /* FIRMWARE_FIRST */
753 esd->enabled = 1;
754 esd->prealloc_erecords = 1;
755 esd->max_section_per_record = 0x1;
756
757 len += sizeof(acpi_hest_esd_t);
758 pos = esd + 1;
759
760 switch (type) {
761 case 0: /* MCE */
762 break;
763 case 1: /* CMC */
764 hen = (acpi_hest_hen_t *) (pos);
765 memset(pos, 0, sizeof(acpi_hest_hen_t));
766 hen->type = 3; /* SCI? */
767 hen->length = sizeof(acpi_hest_hen_t);
768 hen->conf_we = 0; /* Configuration Write Enable. */
769 hen->poll_interval = 0;
770 hen->vector = 0;
771 hen->sw2poll_threshold_val = 0;
772 hen->sw2poll_threshold_win = 0;
773 hen->error_threshold_val = 0;
774 hen->error_threshold_win = 0;
775 len += sizeof(acpi_hest_hen_t);
776 pos = hen + 1;
777 break;
778 case 2: /* NMI */
779 case 6: /* AER Root Port */
780 case 7: /* AER Endpoint */
781 case 8: /* AER Bridge */
782 case 9: /* Generic Hardware Error Source. */
783 /* TODO: */
784 break;
785 default:
786 printk(BIOS_DEBUG, "Invalid type of Error Source.");
787 break;
788 }
789 hest->error_source_count ++;
790
791 memcpy(pos, data, data_len);
792 len += data_len;
793 header->length += len;
794
795 return len;
796}
797
798/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100799void acpi_write_hest(acpi_hest_t *hest,
800 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +0800801{
802 acpi_header_t *header = &(hest->header);
803
804 memset(hest, 0, sizeof(acpi_hest_t));
805
806 memcpy(header->signature, "HEST", 4);
807 memcpy(header->oem_id, OEM_ID, 6);
808 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
809 memcpy(header->asl_compiler_id, ASLC, 4);
810 header->length += sizeof(acpi_hest_t);
811 header->revision = 1;
812
813 acpi_fill_hest(hest);
814
815 /* Calculate checksums. */
816 header->checksum = acpi_checksum((void *)hest, header->length);
817}
818
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200819#if IS_ENABLED(CONFIG_COMMON_FADT)
820void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt)
821{
822 acpi_header_t *header = &(fadt->header);
823
824 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
825 memcpy(header->signature, "FACP", 4);
826 header->length = sizeof(acpi_fadt_t);
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200827 header->revision = 4;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200828 memcpy(header->oem_id, OEM_ID, 6);
829 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
830 memcpy(header->asl_compiler_id, ASLC, 4);
831 header->asl_compiler_revision = 0;
832
833 fadt->firmware_ctrl = (unsigned long) facs;
834 fadt->dsdt = (unsigned long) dsdt;
835
836 fadt->x_firmware_ctl_l = (unsigned long)facs;
837 fadt->x_firmware_ctl_h = 0;
838 fadt->x_dsdt_l = (unsigned long)dsdt;
839 fadt->x_dsdt_h = 0;
840
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700841 if (IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP))
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200842 fadt->preferred_pm_profile = PM_MOBILE;
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700843 else
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200844 fadt->preferred_pm_profile = PM_DESKTOP;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200845
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200846 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200847
848 header->checksum =
849 acpi_checksum((void *) fadt, header->length);
850}
851#endif
852
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200853unsigned long __attribute__ ((weak)) fw_cfg_acpi_tables(unsigned long start)
854{
855 return 0;
856}
857
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200858unsigned long write_acpi_tables(unsigned long start)
859{
860 unsigned long current;
861 acpi_rsdp_t *rsdp;
862 acpi_rsdt_t *rsdt;
863 acpi_xsdt_t *xsdt;
864 acpi_fadt_t *fadt;
865 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100866 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200867 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200868 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200869 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200870 acpi_tcpa_t *tcpa;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200871 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100872 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200873 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200874 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100875 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200876
877 current = start;
878
879 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -0600880 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200881
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200882 fw = fw_cfg_acpi_tables(current);
883 if (fw)
884 return fw;
885
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +0200886 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200887 CONFIG_CBFS_PREFIX "/dsdt.aml",
888 CBFS_TYPE_RAW, &dsdt_size);
889 if (!dsdt_file) {
890 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
891 return current;
892 }
893
894 if (dsdt_file->length > dsdt_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +0200895 || dsdt_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200896 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
897 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
898 return current;
899 }
900
Aaron Durbin899d13d2015-05-15 23:39:23 -0500901 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100902 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +0200903 if (slic_file
904 && (slic_file->length > slic_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +0200905 || slic_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +0200906 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100907 slic_file = 0;
908 }
909
910 if (slic_file) {
911 memcpy(oem_id, slic_file->oem_id, 6);
912 memcpy(oem_table_id, slic_file->oem_table_id, 8);
913 } else {
914 memcpy(oem_id, OEM_ID, 6);
915 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
916 }
917
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200918 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
919
920 /* We need at least an RSDP and an RSDT Table */
921 rsdp = (acpi_rsdp_t *) current;
922 current += sizeof(acpi_rsdp_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600923 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200924 rsdt = (acpi_rsdt_t *) current;
925 current += sizeof(acpi_rsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600926 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200927 xsdt = (acpi_xsdt_t *) current;
928 current += sizeof(acpi_xsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600929 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200930
931 /* clear all table memory */
932 memset((void *) start, 0, current - start);
933
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100934 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
935 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
936 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200937
938 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Patrick Georgi133108a2015-08-08 23:20:58 +0200939 current = (ALIGN(current, 64));
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200940 facs = (acpi_facs_t *) current;
941 current += sizeof(acpi_facs_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600942 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200943 acpi_create_facs(facs);
944
945 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
946 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200947 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200948 if (dsdt->length >= sizeof(acpi_header_t)) {
949 current += sizeof(acpi_header_t);
950
951 acpigen_set_current((char *) current);
952 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700953 if (dev->ops && dev->ops->acpi_inject_dsdt_generator)
Alexander Couzensa90dad12015-04-12 21:49:46 +0200954 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200955 current = (unsigned long) acpigen_get_current();
956 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200957 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200958 dsdt->length - sizeof(acpi_header_t));
959 current += dsdt->length - sizeof(acpi_header_t);
960
961 /* (Re)calculate length and checksum. */
962 dsdt->length = current - (unsigned long)dsdt;
963 dsdt->checksum = 0;
964 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
965 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200966
Aaron Durbin07a1b282015-12-10 17:07:38 -0600967 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200968
969 printk(BIOS_DEBUG, "ACPI: * FADT\n");
970 fadt = (acpi_fadt_t *) current;
971 current += sizeof(acpi_fadt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600972 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200973
974 acpi_create_fadt(fadt, facs, dsdt);
975 acpi_add_table(rsdp, fadt);
976
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100977 if (slic_file) {
978 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
979 slic = (acpi_header_t *)current;
980 memcpy(slic, slic_file, slic_file->length);
981 current += slic_file->length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600982 current = acpi_align_current(current);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100983 acpi_add_table(rsdp, slic);
984 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200985
986 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
987 ssdt = (acpi_header_t *)current;
988 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +0200989 if (ssdt->length > sizeof(acpi_header_t)) {
990 current += ssdt->length;
991 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600992 current = acpi_align_current(current);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +0200993 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200994
995 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
996 mcfg = (acpi_mcfg_t *) current;
997 acpi_create_mcfg(mcfg);
998 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
999 current += mcfg->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001000 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001001 acpi_add_table(rsdp, mcfg);
1002 }
1003
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001004 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
1005 tcpa = (acpi_tcpa_t *) current;
1006 acpi_create_tcpa(tcpa);
1007 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
1008 current += tcpa->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001009 current = acpi_align_current(current);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001010 acpi_add_table(rsdp, tcpa);
1011 }
1012
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001013 printk(BIOS_DEBUG, "ACPI: * MADT\n");
1014
1015 madt = (acpi_madt_t *) current;
1016 acpi_create_madt(madt);
1017 if (madt->header.length > sizeof(acpi_madt_t)) {
1018 current+=madt->header.length;
1019 acpi_add_table(rsdp,madt);
1020 }
Aaron Durbin07a1b282015-12-10 17:07:38 -06001021 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001022
1023 printk(BIOS_DEBUG, "current = %lx\n", current);
1024
1025 for (dev = all_devices; dev; dev = dev->next) {
1026 if (dev->ops && dev->ops->write_acpi_tables) {
Alexander Couzens83fc32f2015-04-12 22:28:37 +02001027 current = dev->ops->write_acpi_tables(dev, current, rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001028 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001029 }
1030 }
1031
1032 printk(BIOS_INFO, "ACPI: done.\n");
1033 return current;
1034}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001035
Rudolf Marek33cafe52009-04-13 18:07:02 +00001036static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1037{
1038 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1039 return NULL;
1040
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001041 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001042
1043 if (acpi_checksum((void *)rsdp, 20) != 0)
1044 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001045 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001046
1047 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1048 rsdp->length) != 0))
1049 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001050 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001051
1052 return rsdp;
1053}
1054
Rudolf Marek33cafe52009-04-13 18:07:02 +00001055void *acpi_find_wakeup_vector(void)
1056{
1057 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001058 acpi_rsdt_t *rsdt;
1059 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001060 acpi_fadt_t *fadt = NULL;
Kyösti Mälkki072d436b2016-06-17 08:44:40 +03001061 acpi_rsdp_t *rsdp = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001062 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001063 int i;
1064
Rudolf Marek33cafe52009-04-13 18:07:02 +00001065 if (!acpi_is_wakeup())
1066 return NULL;
1067
Uwe Hermann622824c2010-11-19 15:14:42 +00001068 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001069
Uwe Hermann622824c2010-11-19 15:14:42 +00001070 /* Find RSDP. */
1071 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
1072 if ((rsdp = valid_rsdp((acpi_rsdp_t *)p)))
Rudolf Marek33cafe52009-04-13 18:07:02 +00001073 break;
1074 }
1075
1076 if (rsdp == NULL)
1077 return NULL;
1078
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001079 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001080 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001081
Uwe Hermann622824c2010-11-19 15:14:42 +00001082 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001083 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001084
Uwe Hermann622824c2010-11-19 15:14:42 +00001085 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001086 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001087 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001088 break;
1089 fadt = NULL;
1090 }
1091
1092 if (fadt == NULL)
1093 return NULL;
1094
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001095 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001096 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001097
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001098 if (facs == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001099 printk(BIOS_DEBUG, "No FACS found, wake up from S3 not "
1100 "possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001101 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001102 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001103
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001104 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001105 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001106 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001107
Rudolf Marek33cafe52009-04-13 18:07:02 +00001108 return wake_vec;
1109}
1110
Duncan Laurie11290c42012-10-03 19:07:05 -07001111void acpi_save_gnvs(u32 gnvs_address)
1112{
Duncan Laurie9c07c8f2013-03-22 11:08:39 -07001113 u32 *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS_PTR, sizeof(*gnvs));
Duncan Laurie11290c42012-10-03 19:07:05 -07001114 if (gnvs)
1115 *gnvs = gnvs_address;
1116}
Duncan Laurie1f6e6812016-09-19 12:04:19 -07001117
1118__attribute__ ((weak)) int acpi_get_gpe(int gpe)
1119{
1120 return -1; /* implemented by SOC */
1121}