blob: fdcbcd3fb593a0c7e6cb7f2d9d75646e8a1358d7 [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
Lee Leahy6f80ccc2017-03-16 15:18:22 -07009 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>,
10 * Raptor Engineering
Werner Zehdb561e62019-02-19 13:39:56 +010011 * Copyright (C) 2016-2019 Siemens AG
Stefan Reinauer777224c2005-01-19 14:06:41 +000012 *
Stefan Reinauer14e22772010-04-27 06:56:47 +000013 * ACPI FADT, FACS, and DSDT table support added by
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000014 * Nick Barker <nick.barker9@btinternet.com>, and those portions
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000015 * Copyright (C) 2004 Nick Barker
Stefan Reinauerf622d592005-11-26 16:56:05 +000016 *
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000017 * Copyright (C) 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
Stefan Reinauerd6edf7a2006-01-05 00:19:52 +000018 * 2005.9 yhlu add SRAT table generation
Martin Roth9df9e9392016-01-12 15:55:28 -070019 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; version 2 of the License.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
Stefan Reinauer777224c2005-01-19 14:06:41 +000028 */
29
Stefan Reinauer14e22772010-04-27 06:56:47 +000030/*
Stefan Reinauer777224c2005-01-19 14:06:41 +000031 * Each system port implementing ACPI has to provide two functions:
Stefan Reinauer14e22772010-04-27 06:56:47 +000032 *
Stefan Reinauer777224c2005-01-19 14:06:41 +000033 * write_acpi_tables()
34 * acpi_dump_apics()
Stefan Reinauer14e22772010-04-27 06:56:47 +000035 *
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000036 * See Kontron 986LCD-M port for a good example of an ACPI implementation
37 * in coreboot.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000038 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000039
40#include <console/console.h>
41#include <string.h>
42#include <arch/acpi.h>
Martin Rotha66df492016-09-06 10:22:34 -060043#include <arch/acpi_ivrs.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000044#include <arch/acpigen.h>
Stefan Reinauer777224c2005-01-19 14:06:41 +000045#include <device/pci.h>
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000046#include <cbmem.h>
Elyes HAOUASe2d152c2019-06-21 07:06:50 +020047#include <commonlib/helpers.h>
Patrick Georgic8feedd2012-02-16 18:43:25 +010048#include <cpu/x86/lapic_def.h>
Duncan Laurie11290c42012-10-03 19:07:05 -070049#include <cpu/cpu.h>
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +010050#include <cbfs.h>
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010051#include <version.h>
Werner Zehdb561e62019-02-19 13:39:56 +010052#include <commonlib/sort.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000053
54u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000055{
Uwe Hermann622824c2010-11-19 15:14:42 +000056 u8 ret = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +000057 while (length--) {
58 ret += *table;
59 table++;
60 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000061 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000062}
63
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000064/**
Uwe Hermann622824c2010-11-19 15:14:42 +000065 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
66 * and checksum.
Stefan Reinauer06feb882004-02-03 16:11:35 +000067 */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000068void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000069{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000070 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000071 acpi_rsdt_t *rsdt;
72 acpi_xsdt_t *xsdt = NULL;
73
Uwe Hermann622824c2010-11-19 15:14:42 +000074 /* The RSDT is mandatory... */
Stefan Reinauerdefee172015-06-18 01:11:19 -070075 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000076
Uwe Hermann622824c2010-11-19 15:14:42 +000077 /* ...while the XSDT is not. */
78 if (rsdp->xsdt_address)
Stefan Reinauerdefee172015-06-18 01:11:19 -070079 xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address);
Stefan Reinauer14e22772010-04-27 06:56:47 +000080
Uwe Hermann622824c2010-11-19 15:14:42 +000081 /* This should always be MAX_ACPI_TABLES. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000082 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauer14e22772010-04-27 06:56:47 +000083
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000084 for (i = 0; i < entries_num; i++) {
Uwe Hermann622824c2010-11-19 15:14:42 +000085 if (rsdt->entry[i] == 0)
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000086 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000087 }
88
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000089 if (i >= entries_num) {
Uwe Hermann622824c2010-11-19 15:14:42 +000090 printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +030091 "too many tables.\n");
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000092 return;
93 }
94
Uwe Hermann622824c2010-11-19 15:14:42 +000095 /* Add table to the RSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070096 rsdt->entry[i] = (uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000097
Uwe Hermann622824c2010-11-19 15:14:42 +000098 /* Fix RSDT length or the kernel will assume invalid entries. */
99 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000100
Uwe Hermann622824c2010-11-19 15:14:42 +0000101 /* Re-calculate checksum. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000102 rsdt->header.checksum = 0; /* Hope this won't get optimized away */
Uwe Hermann622824c2010-11-19 15:14:42 +0000103 rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000104
Uwe Hermann622824c2010-11-19 15:14:42 +0000105 /*
106 * And now the same thing for the XSDT. We use the same index as for
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000107 * now we want the XSDT and RSDT to always be in sync in coreboot.
108 */
109 if (xsdt) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000110 /* Add table to the XSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -0700111 xsdt->entry[i] = (u64)(uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000112
Uwe Hermann622824c2010-11-19 15:14:42 +0000113 /* Fix XSDT length. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000114 xsdt->header.length = sizeof(acpi_header_t) +
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300115 (sizeof(u64) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000116
Uwe Hermann622824c2010-11-19 15:14:42 +0000117 /* Re-calculate checksum. */
118 xsdt->header.checksum = 0;
119 xsdt->header.checksum = acpi_checksum((u8 *)xsdt,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300120 xsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000121 }
122
Uwe Hermann622824c2010-11-19 15:14:42 +0000123 printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300124 i + 1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000125}
126
Uwe Hermann622824c2010-11-19 15:14:42 +0000127int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300128 u16 seg_nr, u8 start, u8 end)
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000129{
Vladimir Serbinenko60fccdc2014-10-05 11:05:16 +0200130 memset(mmconfig, 0, sizeof(*mmconfig));
Rudolf Mareke6409f22007-11-03 12:50:26 +0000131 mmconfig->base_address = base;
132 mmconfig->base_reserved = 0;
133 mmconfig->pci_segment_group_number = seg_nr;
134 mmconfig->start_bus_number = start;
135 mmconfig->end_bus_number = end;
Uwe Hermann622824c2010-11-19 15:14:42 +0000136
137 return sizeof(acpi_mcfg_mmconfig_t);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000138}
139
Stefan Reinauer777224c2005-01-19 14:06:41 +0000140int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000141{
Uwe Hermann622824c2010-11-19 15:14:42 +0000142 lapic->type = 0; /* Local APIC structure */
143 lapic->length = sizeof(acpi_madt_lapic_t);
144 lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
145 lapic->processor_id = cpu;
146 lapic->apic_id = apic;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000147
Uwe Hermann622824c2010-11-19 15:14:42 +0000148 return lapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000149}
150
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000151unsigned long acpi_create_madt_lapics(unsigned long current)
152{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100153 struct device *cpu;
Werner Zeh423adfb2019-03-06 09:31:02 +0100154 int index, apic_ids[CONFIG_MAX_CPUS] = {0}, num_cpus = 0;
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000155
Uwe Hermann622824c2010-11-19 15:14:42 +0000156 for (cpu = all_devices; cpu; cpu = cpu->next) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000157 if ((cpu->path.type != DEVICE_PATH_APIC) ||
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800158 (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000159 continue;
160 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000161 if (!cpu->enabled)
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000162 continue;
Werner Zehdb561e62019-02-19 13:39:56 +0100163 if (num_cpus >= ARRAY_SIZE(apic_ids))
164 break;
165 apic_ids[num_cpus++] = cpu->path.apic.apic_id;
166 }
Werner Zehfedb36e2019-03-12 07:07:50 +0100167 if (num_cpus > 1)
168 bubblesort(apic_ids, num_cpus, NUM_ASCENDING);
Werner Zehdb561e62019-02-19 13:39:56 +0100169 for (index = 0; index < num_cpus; index++) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000170 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
Werner Zehdb561e62019-02-19 13:39:56 +0100171 index, apic_ids[index]);
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000172 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000173
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000174 return current;
175}
176
Uwe Hermann622824c2010-11-19 15:14:42 +0000177int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300178 u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000179{
Uwe Hermann622824c2010-11-19 15:14:42 +0000180 ioapic->type = 1; /* I/O APIC structure */
181 ioapic->length = sizeof(acpi_madt_ioapic_t);
182 ioapic->reserved = 0x00;
183 ioapic->gsi_base = gsi_base;
184 ioapic->ioapic_id = id;
185 ioapic->ioapic_addr = addr;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000186
Uwe Hermann622824c2010-11-19 15:14:42 +0000187 return ioapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000188}
189
Stefan Reinauer777224c2005-01-19 14:06:41 +0000190int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000191 u8 bus, u8 source, u32 gsirq, u16 flags)
192{
Uwe Hermann622824c2010-11-19 15:14:42 +0000193 irqoverride->type = 2; /* Interrupt source override */
194 irqoverride->length = sizeof(acpi_madt_irqoverride_t);
195 irqoverride->bus = bus;
196 irqoverride->source = source;
197 irqoverride->gsirq = gsirq;
198 irqoverride->flags = flags;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000199
Uwe Hermann622824c2010-11-19 15:14:42 +0000200 return irqoverride->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000201}
202
Stefan Reinauer777224c2005-01-19 14:06:41 +0000203int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300204 u16 flags, u8 lint)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000205{
Uwe Hermann622824c2010-11-19 15:14:42 +0000206 lapic_nmi->type = 4; /* Local APIC NMI structure */
207 lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
208 lapic_nmi->flags = flags;
209 lapic_nmi->processor_id = cpu;
210 lapic_nmi->lint = lint;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000211
Uwe Hermann622824c2010-11-19 15:14:42 +0000212 return lapic_nmi->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000213}
214
Stefan Reinauer777224c2005-01-19 14:06:41 +0000215void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000216{
Uwe Hermann622824c2010-11-19 15:14:42 +0000217 acpi_header_t *header = &(madt->header);
218 unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000219
Stefan Reinauer06feb882004-02-03 16:11:35 +0000220 memset((void *)madt, 0, sizeof(acpi_madt_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000221
John Zhao2ba303e2019-05-28 16:48:14 -0700222 if (!header)
223 return;
224
Uwe Hermann622824c2010-11-19 15:14:42 +0000225 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000226 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000227 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000228 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000229 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000230
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100231 header->asl_compiler_revision = asl_revision;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000232 header->length = sizeof(acpi_madt_t);
Marc Jones93a51762018-08-22 18:57:24 -0600233 header->revision = get_acpi_table_revision(MADT);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000234
Uwe Hermann622824c2010-11-19 15:14:42 +0000235 madt->lapic_addr = LOCAL_APIC_ADDR;
Nico Huber9df72e02018-11-24 18:25:50 +0100236 if (CONFIG(ACPI_HAVE_PCAT_8259))
237 madt->flags |= 1;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000238
Stefan Reinauerf622d592005-11-26 16:56:05 +0000239 current = acpi_fill_madt(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000240
Uwe Hermann622824c2010-11-19 15:14:42 +0000241 /* (Re)calculate length and checksum. */
242 header->length = current - (unsigned long)madt;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000243
Uwe Hermann622824c2010-11-19 15:14:42 +0000244 header->checksum = acpi_checksum((void *)madt, header->length);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000245}
246
Uwe Hermann622824c2010-11-19 15:14:42 +0000247/* MCFG is defined in the PCI Firmware Specification 3.0. */
Rudolf Mareke6409f22007-11-03 12:50:26 +0000248void acpi_create_mcfg(acpi_mcfg_t *mcfg)
249{
Uwe Hermann622824c2010-11-19 15:14:42 +0000250 acpi_header_t *header = &(mcfg->header);
251 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000252
Rudolf Mareke6409f22007-11-03 12:50:26 +0000253 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000254
John Zhao2ba303e2019-05-28 16:48:14 -0700255 if (!header)
256 return;
257
Uwe Hermann622824c2010-11-19 15:14:42 +0000258 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000259 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000260 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000261 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000262 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000263
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100264 header->asl_compiler_revision = asl_revision;
Rudolf Mareke6409f22007-11-03 12:50:26 +0000265 header->length = sizeof(acpi_mcfg_t);
Marc Jones93a51762018-08-22 18:57:24 -0600266 header->revision = get_acpi_table_revision(MCFG);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000267
268 current = acpi_fill_mcfg(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000269
Uwe Hermann622824c2010-11-19 15:14:42 +0000270 /* (Re)calculate length and checksum. */
271 header->length = current - (unsigned long)mcfg;
272 header->checksum = acpi_checksum((void *)mcfg, header->length);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000273}
274
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200275static void *get_tcpa_log(u32 *size)
276{
277 const struct cbmem_entry *ce;
278 const u32 tcpa_default_log_len = 0x10000;
279 void *lasa;
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200280 ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200281 if (ce) {
282 lasa = cbmem_entry_start(ce);
283 *size = cbmem_entry_size(ce);
284 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
285 return lasa;
286 }
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200287 lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200288 if (!lasa) {
289 printk(BIOS_ERR, "TCPA log creation failed\n");
290 return NULL;
291 }
292
293 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
Lee Leahy024b13d2017-03-16 13:41:11 -0700294 memset(lasa, 0, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200295
296 *size = tcpa_default_log_len;
297 return lasa;
298}
299
300static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
301{
302 acpi_header_t *header = &(tcpa->header);
303 u32 tcpa_log_len;
304 void *lasa;
305
306 memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
307
308 lasa = get_tcpa_log(&tcpa_log_len);
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700309 if (!lasa)
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200310 return;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200311
John Zhao2ba303e2019-05-28 16:48:14 -0700312 if (!header)
313 return;
314
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200315 /* Fill out header fields. */
316 memcpy(header->signature, "TCPA", 4);
317 memcpy(header->oem_id, OEM_ID, 6);
318 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
319 memcpy(header->asl_compiler_id, ASLC, 4);
320
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100321 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200322 header->length = sizeof(acpi_tcpa_t);
Marc Jones93a51762018-08-22 18:57:24 -0600323 header->revision = get_acpi_table_revision(TCPA);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200324
325 tcpa->platform_class = 0;
326 tcpa->laml = tcpa_log_len;
Stefan Reinauerdefee172015-06-18 01:11:19 -0700327 tcpa->lasa = (uintptr_t) lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200328
329 /* Calculate checksum. */
330 header->checksum = acpi_checksum((void *)tcpa, header->length);
331}
332
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100333static void *get_tpm2_log(u32 *size)
334{
335 const struct cbmem_entry *ce;
336 const u32 tpm2_default_log_len = 0x10000;
337 void *lasa;
338 ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG);
339 if (ce) {
340 lasa = cbmem_entry_start(ce);
341 *size = cbmem_entry_size(ce);
342 printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa);
343 return lasa;
344 }
345 lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len);
346 if (!lasa) {
347 printk(BIOS_ERR, "TPM2 log creation failed\n");
348 return NULL;
349 }
350
351 printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa);
352 memset(lasa, 0, tpm2_default_log_len);
353
354 *size = tpm2_default_log_len;
355 return lasa;
356}
357
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200358static void acpi_create_tpm2(acpi_tpm2_t *tpm2)
359{
360 acpi_header_t *header = &(tpm2->header);
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100361 u32 tpm2_log_len;
362 void *lasa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200363
364 memset((void *)tpm2, 0, sizeof(acpi_tpm2_t));
365
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100366 /*
367 * Some payloads like SeaBIOS depend on log area to use TPM2.
368 * Get the memory size and address of TPM2 log area or initialize it.
369 */
370 lasa = get_tpm2_log(&tpm2_log_len);
371 if (!lasa)
372 tpm2_log_len = 0;
373
John Zhao2ba303e2019-05-28 16:48:14 -0700374 if (!header)
375 return;
376
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200377 /* Fill out header fields. */
378 memcpy(header->signature, "TPM2", 4);
379 memcpy(header->oem_id, OEM_ID, 6);
380 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
381 memcpy(header->asl_compiler_id, ASLC, 4);
382
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100383 header->asl_compiler_revision = asl_revision;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200384 header->length = sizeof(acpi_tpm2_t);
385 header->revision = get_acpi_table_revision(TPM2);
386
387 /* Hard to detect for coreboot. Just set it to 0 */
388 tpm2->platform_class = 0;
Christian Walter26e0d4c2019-07-14 15:47:23 +0200389 if (CONFIG(CRB_TPM)) {
390 /* Must be set to 7 for CRB Support */
391 tpm2->control_area = CONFIG_CRB_TPM_BASE_ADDRESS + 0x40;
392 tpm2->start_method = 7;
393 } else {
394 /* Must be set to 0 for FIFO interface support */
395 tpm2->control_area = 0;
396 tpm2->start_method = 6;
397 }
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200398 memset(tpm2->msp, 0, sizeof(tpm2->msp));
399
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100400 /* Fill the log area size and start address fields. */
401 tpm2->laml = tpm2_log_len;
402 tpm2->lasa = (uintptr_t) lasa;
403
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200404 /* Calculate checksum. */
405 header->checksum = acpi_checksum((void *)tpm2, header->length);
406}
407
Duncan Laurie37319032016-05-26 12:47:05 -0700408static void acpi_ssdt_write_cbtable(void)
409{
410 const struct cbmem_entry *cbtable;
411 uintptr_t base;
412 uint32_t size;
413
414 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
415 if (!cbtable)
416 return;
417 base = (uintptr_t)cbmem_entry_start(cbtable);
418 size = cbmem_entry_size(cbtable);
419
420 acpigen_write_device("CTBL");
421 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
422 acpigen_write_name_integer("_UID", 0);
David Wu5dff3962018-03-21 16:48:53 +0800423 acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON);
Duncan Laurie37319032016-05-26 12:47:05 -0700424 acpigen_write_name("_CRS");
425 acpigen_write_resourcetemplate_header();
426 acpigen_write_mem32fixed(0, base, size);
427 acpigen_write_resourcetemplate_footer();
428 acpigen_pop_len();
429}
430
Myles Watson3fe6b702009-10-09 20:13:43 +0000431void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000432{
Uwe Hermann622824c2010-11-19 15:14:42 +0000433 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
434
Rudolf Marek293b5f52009-02-01 18:35:15 +0000435 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000436
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000437 memcpy(&ssdt->signature, "SSDT", 4);
Marc Jones93a51762018-08-22 18:57:24 -0600438 ssdt->revision = get_acpi_table_revision(SSDT);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000439 memcpy(&ssdt->oem_id, OEM_ID, 6);
440 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
441 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000442 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +0100443 ssdt->asl_compiler_revision = asl_revision;
Rudolf Marek293b5f52009-02-01 18:35:15 +0000444 ssdt->length = sizeof(acpi_header_t);
445
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000446 acpigen_set_current((char *) current);
Duncan Laurie37319032016-05-26 12:47:05 -0700447
448 /* Write object to declare coreboot tables */
449 acpi_ssdt_write_cbtable();
450
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200451 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100452 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200453 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700454 if (dev->ops && dev->ops->acpi_fill_ssdt_generator)
Alexander Couzens5eea4582015-04-12 22:18:55 +0200455 dev->ops->acpi_fill_ssdt_generator(dev);
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200456 current = (unsigned long) acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200457 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000458
Uwe Hermann622824c2010-11-19 15:14:42 +0000459 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000460 ssdt->length = current - (unsigned long)ssdt;
461 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
462}
463
Stefan Reinauerf622d592005-11-26 16:56:05 +0000464int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
465{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000466 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000467
Uwe Hermann622824c2010-11-19 15:14:42 +0000468 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
469 lapic->length = sizeof(acpi_srat_lapic_t);
470 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
471 lapic->proximity_domain_7_0 = node;
472 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
473 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000474
Uwe Hermann622824c2010-11-19 15:14:42 +0000475 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000476}
477
Uwe Hermann622824c2010-11-19 15:14:42 +0000478int 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 +0300479 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000480{
Uwe Hermann622824c2010-11-19 15:14:42 +0000481 mem->type = 1; /* Memory affinity structure */
482 mem->length = sizeof(acpi_srat_mem_t);
483 mem->base_address_low = (basek << 10);
484 mem->base_address_high = (basek >> (32 - 10));
485 mem->length_low = (sizek << 10);
486 mem->length_high = (sizek >> (32 - 10));
487 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000488 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000489
Uwe Hermann622824c2010-11-19 15:14:42 +0000490 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000491}
492
Uwe Hermann622824c2010-11-19 15:14:42 +0000493/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200494void acpi_create_srat(acpi_srat_t *srat,
495 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000496{
Uwe Hermann622824c2010-11-19 15:14:42 +0000497 acpi_header_t *header = &(srat->header);
498 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000499
Uwe Hermann622824c2010-11-19 15:14:42 +0000500 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000501
John Zhao2ba303e2019-05-28 16:48:14 -0700502 if (!header)
503 return;
504
Uwe Hermann622824c2010-11-19 15:14:42 +0000505 /* Fill out header fields. */
506 memcpy(header->signature, "SRAT", 4);
507 memcpy(header->oem_id, OEM_ID, 6);
508 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
509 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000510
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100511 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000512 header->length = sizeof(acpi_srat_t);
Marc Jones93a51762018-08-22 18:57:24 -0600513 header->revision = get_acpi_table_revision(SRAT);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000514
Uwe Hermann622824c2010-11-19 15:14:42 +0000515 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000516
Uwe Hermann622824c2010-11-19 15:14:42 +0000517 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000518
Uwe Hermann622824c2010-11-19 15:14:42 +0000519 /* (Re)calculate length and checksum. */
520 header->length = current - (unsigned long)srat;
521 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000522}
523
Nico Hubere561f352015-10-26 11:51:25 +0100524void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Lee Leahy024b13d2017-03-16 13:41:11 -0700525 unsigned long (*acpi_fill_dmar)(unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200526{
527 acpi_header_t *header = &(dmar->header);
528 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
529
530 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
531
John Zhao2ba303e2019-05-28 16:48:14 -0700532 if (!header)
533 return;
534
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200535 /* Fill out header fields. */
536 memcpy(header->signature, "DMAR", 4);
537 memcpy(header->oem_id, OEM_ID, 6);
538 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
539 memcpy(header->asl_compiler_id, ASLC, 4);
540
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100541 header->asl_compiler_revision = asl_revision;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200542 header->length = sizeof(acpi_dmar_t);
Marc Jones93a51762018-08-22 18:57:24 -0600543 header->revision = get_acpi_table_revision(DMAR);
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200544
Jacob Laskaf3f654d2016-03-15 21:53:27 -0500545 dmar->host_address_width = cpu_phys_address_size() - 1;
Nico Hubere561f352015-10-26 11:51:25 +0100546 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200547
548 current = acpi_fill_dmar(current);
549
550 /* (Re)calculate length and checksum. */
551 header->length = current - (unsigned long)dmar;
552 header->checksum = acpi_checksum((void *)dmar, header->length);
553}
554
555unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
Matt DeVillier7866d492018-03-29 14:59:57 +0200556 u16 segment, u64 bar)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200557{
558 dmar_entry_t *drhd = (dmar_entry_t *)current;
559 memset(drhd, 0, sizeof(*drhd));
560 drhd->type = DMAR_DRHD;
561 drhd->length = sizeof(*drhd); /* will be fixed up later */
562 drhd->flags = flags;
563 drhd->segment = segment;
564 drhd->bar = bar;
565
566 return drhd->length;
567}
568
Matt DeVillier7866d492018-03-29 14:59:57 +0200569unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
570 u64 bar, u64 limit)
571{
572 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current;
573 memset(rmrr, 0, sizeof(*rmrr));
574 rmrr->type = DMAR_RMRR;
575 rmrr->length = sizeof(*rmrr); /* will be fixed up later */
576 rmrr->segment = segment;
577 rmrr->bar = bar;
578 rmrr->limit = limit;
579
580 return rmrr->length;
581}
582
Werner Zehd4d76952016-07-27 06:56:36 +0200583unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
584 u16 segment)
585{
586 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
587 memset(atsr, 0, sizeof(*atsr));
588 atsr->type = DMAR_ATSR;
589 atsr->length = sizeof(*atsr); /* will be fixed up later */
590 atsr->flags = flags;
591 atsr->segment = segment;
592
593 return atsr->length;
594}
595
John Zhao76e70672019-04-04 11:03:28 -0700596unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
597 u32 proximity_domain)
598{
599 dmar_rhsa_entry_t *rhsa = (dmar_rhsa_entry_t *)current;
600 memset(rhsa, 0, sizeof(*rhsa));
601 rhsa->type = DMAR_RHSA;
602 rhsa->length = sizeof(*rhsa);
603 rhsa->base_address = base_addr;
604 rhsa->proximity_domain = proximity_domain;
605
606 return rhsa->length;
607}
608
609unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
610 const char *device_name)
611{
612 dmar_andd_entry_t *andd = (dmar_andd_entry_t *)current;
613 int andd_len = sizeof(dmar_andd_entry_t) + strlen(device_name) + 1;
614 memset(andd, 0, andd_len);
615 andd->type = DMAR_ANDD;
616 andd->length = andd_len;
617 andd->device_number = device_number;
618 memcpy(&andd->device_name, device_name, strlen(device_name));
619
620 return andd->length;
621}
622
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200623void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
624{
625 dmar_entry_t *drhd = (dmar_entry_t *)base;
626 drhd->length = current - base;
627}
628
Matt DeVillier7866d492018-03-29 14:59:57 +0200629void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
630{
631 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)base;
632 rmrr->length = current - base;
633}
634
Werner Zehd4d76952016-07-27 06:56:36 +0200635void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
636{
637 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base;
638 atsr->length = current - base;
639}
640
Matt DeVillier7866d492018-03-29 14:59:57 +0200641static unsigned long acpi_create_dmar_ds(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100642 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200643{
Nico Huber6c4751d2015-10-26 12:03:54 +0100644 /* we don't support longer paths yet */
645 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
646
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200647 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100648 memset(ds, 0, dev_scope_length);
649 ds->type = type;
650 ds->length = dev_scope_length;
651 ds->enumeration = enumeration_id;
652 ds->start_bus = bus;
653 ds->path[0].dev = dev;
654 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200655
656 return ds->length;
657}
658
Matt DeVillier7866d492018-03-29 14:59:57 +0200659unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200660 u8 dev, u8 fn)
661{
Matt DeVillier7866d492018-03-29 14:59:57 +0200662 return acpi_create_dmar_ds(current,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200663 SCOPE_PCI_SUB, 0, bus, dev, fn);
664}
665
Matt DeVillier7866d492018-03-29 14:59:57 +0200666unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus,
Nico Huber6c4751d2015-10-26 12:03:54 +0100667 u8 dev, u8 fn)
668{
Matt DeVillier7866d492018-03-29 14:59:57 +0200669 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100670 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
671}
672
Matt DeVillier7866d492018-03-29 14:59:57 +0200673unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100674 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
675{
Matt DeVillier7866d492018-03-29 14:59:57 +0200676 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100677 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
678}
679
Matt DeVillier7866d492018-03-29 14:59:57 +0200680unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100681 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
682{
Matt DeVillier7866d492018-03-29 14:59:57 +0200683 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100684 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
685}
686
Uwe Hermann622824c2010-11-19 15:14:42 +0000687/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200688void acpi_create_slit(acpi_slit_t *slit,
689 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000690{
Uwe Hermann622824c2010-11-19 15:14:42 +0000691 acpi_header_t *header = &(slit->header);
692 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000693
Uwe Hermann622824c2010-11-19 15:14:42 +0000694 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000695
John Zhao2ba303e2019-05-28 16:48:14 -0700696 if (!header)
697 return;
698
Uwe Hermann622824c2010-11-19 15:14:42 +0000699 /* Fill out header fields. */
700 memcpy(header->signature, "SLIT", 4);
701 memcpy(header->oem_id, OEM_ID, 6);
702 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
703 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000704
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100705 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000706 header->length = sizeof(acpi_slit_t);
Marc Jones93a51762018-08-22 18:57:24 -0600707 header->revision = get_acpi_table_revision(SLIT);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000708
Uwe Hermann622824c2010-11-19 15:14:42 +0000709 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000710
Uwe Hermann622824c2010-11-19 15:14:42 +0000711 /* (Re)calculate length and checksum. */
712 header->length = current - (unsigned long)slit;
713 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000714}
715
Uwe Hermann622824c2010-11-19 15:14:42 +0000716/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000717void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000718{
Uwe Hermann622824c2010-11-19 15:14:42 +0000719 acpi_header_t *header = &(hpet->header);
720 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000721
Stefan Reinauera7648c22004-01-29 17:31:34 +0000722 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000723
John Zhao2ba303e2019-05-28 16:48:14 -0700724 if (!header)
725 return;
726
Uwe Hermann622824c2010-11-19 15:14:42 +0000727 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000728 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000729 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000730 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000731 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000732
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100733 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000734 header->length = sizeof(acpi_hpet_t);
Marc Jones93a51762018-08-22 18:57:24 -0600735 header->revision = get_acpi_table_revision(HPET);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000736
Uwe Hermann622824c2010-11-19 15:14:42 +0000737 /* Fill out HPET address. */
738 addr->space_id = 0; /* Memory */
739 addr->bit_width = 64;
740 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200741 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
742 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000743
Lee Leahy024b13d2017-03-16 13:41:11 -0700744 hpet->id = *(unsigned int *)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000745 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200746 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000747
Uwe Hermann622824c2010-11-19 15:14:42 +0000748 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000749}
Uwe Hermann622824c2010-11-19 15:14:42 +0000750
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200751void acpi_create_vfct(struct device *device,
752 struct acpi_vfct *vfct,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700753 unsigned long (*acpi_fill_vfct)(struct device *device,
754 struct acpi_vfct *vfct_struct, unsigned long current))
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200755{
756 acpi_header_t *header = &(vfct->header);
757 unsigned long current = (unsigned long)vfct + sizeof(struct acpi_vfct);
758
759 memset((void *)vfct, 0, sizeof(struct acpi_vfct));
760
John Zhao2ba303e2019-05-28 16:48:14 -0700761 if (!header)
762 return;
763
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200764 /* Fill out header fields. */
765 memcpy(header->signature, "VFCT", 4);
766 memcpy(header->oem_id, OEM_ID, 6);
767 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
768 memcpy(header->asl_compiler_id, ASLC, 4);
769
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100770 header->asl_compiler_revision = asl_revision;
Marc Jones93a51762018-08-22 18:57:24 -0600771 header->revision = get_acpi_table_revision(VFCT);
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200772
773 current = acpi_fill_vfct(device, vfct, current);
774
Kyösti Mälkkifb493792019-06-30 06:29:52 +0300775 /* If no BIOS image, return with header->length == 0. */
776 if (!vfct->VBIOSImageOffset)
777 return;
778
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200779 /* (Re)calculate length and checksum. */
780 header->length = current - (unsigned long)vfct;
781 header->checksum = acpi_checksum((void *)vfct, header->length);
782}
783
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +0200784void acpi_create_ipmi(struct device *device,
785 struct acpi_spmi *spmi,
786 const u16 ipmi_revision,
787 const acpi_addr_t *addr,
788 const enum acpi_ipmi_interface_type type,
789 const s8 gpe_interrupt,
790 const u32 apic_interrupt,
791 const u32 uid)
792{
793 acpi_header_t *header = &(spmi->header);
794 memset((void *)spmi, 0, sizeof(struct acpi_spmi));
795
796 /* Fill out header fields. */
797 memcpy(header->signature, "SPMI", 4);
798 memcpy(header->oem_id, OEM_ID, 6);
799 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
800 memcpy(header->asl_compiler_id, ASLC, 4);
801
802 header->asl_compiler_revision = asl_revision;
803 header->length = sizeof(struct acpi_spmi);
804 header->revision = get_acpi_table_revision(SPMI);
805
806 spmi->reserved = 1;
807
808 if (device->path.type == DEVICE_PATH_PCI) {
809 spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG;
810 spmi->pci_bus = device->bus->secondary;
811 spmi->pci_device = device->path.pci.devfn >> 3;
812 spmi->pci_function = device->path.pci.devfn & 0x7;
813 } else if (type != IPMI_INTERFACE_SSIF) {
814 memcpy(spmi->uid, &uid, sizeof(spmi->uid));
815 }
816
817 spmi->base_address = *addr;
818 spmi->specification_revision = ipmi_revision;
819
820 spmi->interface_type = type;
821
822 if (gpe_interrupt >= 0 && gpe_interrupt < 32) {
823 spmi->gpe = gpe_interrupt;
824 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_SCI;
825 }
826 if (apic_interrupt > 0) {
827 spmi->global_system_interrupt = apic_interrupt;
828 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_APIC;
829 }
830
831 /* Calculate checksum. */
832 header->checksum = acpi_checksum((void *)spmi, header->length);
833}
834
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500835void acpi_create_ivrs(acpi_ivrs_t *ivrs,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700836 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
837 unsigned long current))
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500838{
839 acpi_header_t *header = &(ivrs->header);
840 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
841
842 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
843
John Zhao2ba303e2019-05-28 16:48:14 -0700844 if (!header)
845 return;
846
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500847 /* Fill out header fields. */
848 memcpy(header->signature, "IVRS", 4);
849 memcpy(header->oem_id, OEM_ID, 6);
850 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
851 memcpy(header->asl_compiler_id, ASLC, 4);
852
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100853 header->asl_compiler_revision = asl_revision;
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500854 header->length = sizeof(acpi_ivrs_t);
Marc Jones93a51762018-08-22 18:57:24 -0600855 header->revision = get_acpi_table_revision(IVRS);
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500856
857 current = acpi_fill_ivrs(ivrs, current);
858
859 /* (Re)calculate length and checksum. */
860 header->length = current - (unsigned long)ivrs;
861 header->checksum = acpi_checksum((void *)ivrs, header->length);
862}
863
Elyes HAOUAS9dd89cd2018-05-04 17:56:47 +0200864unsigned long acpi_write_hpet(struct device *device, unsigned long current,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700865 acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200866{
867 acpi_hpet_t *hpet;
868
869 /*
870 * We explicitly add these tables later on:
871 */
872 printk(BIOS_DEBUG, "ACPI: * HPET\n");
873
874 hpet = (acpi_hpet_t *) current;
875 current += sizeof(acpi_hpet_t);
Felix Heldc4697122019-06-20 13:50:17 +0200876 current = ALIGN_UP(current, 16);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200877 acpi_create_hpet(hpet);
878 acpi_add_table(rsdp, hpet);
879
880 return current;
881}
882
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800883void acpi_create_dbg2(acpi_dbg2_header_t *dbg2,
884 int port_type, int port_subtype,
885 acpi_addr_t *address, uint32_t address_size,
886 const char *device_path)
887{
888 uintptr_t current;
889 acpi_dbg2_device_t *device;
890 uint32_t *dbg2_addr_size;
891 acpi_header_t *header;
892 size_t path_len;
893 const char *path;
894 char *namespace;
895
896 /* Fill out header fields. */
897 current = (uintptr_t)dbg2;
898 memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
899 header = &(dbg2->header);
John Zhao2ba303e2019-05-28 16:48:14 -0700900
901 if (!header)
902 return;
903
Marc Jones93a51762018-08-22 18:57:24 -0600904 header->revision = get_acpi_table_revision(DBG2);
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800905 memcpy(header->signature, "DBG2", 4);
906 memcpy(header->oem_id, OEM_ID, 6);
907 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
908 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100909 header->asl_compiler_revision = asl_revision;
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800910
911 /* One debug device defined */
912 dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
913 dbg2->devices_count = 1;
914 current += sizeof(acpi_dbg2_header_t);
915
916 /* Device comes after the header */
917 device = (acpi_dbg2_device_t *)current;
918 memset(device, 0, sizeof(acpi_dbg2_device_t));
919 current += sizeof(acpi_dbg2_device_t);
920
921 device->revision = 0;
922 device->address_count = 1;
923 device->port_type = port_type;
924 device->port_subtype = port_subtype;
925
926 /* Base Address comes after device structure */
927 memcpy((void *)current, address, sizeof(acpi_addr_t));
928 device->base_address_offset = current - (uintptr_t)device;
929 current += sizeof(acpi_addr_t);
930
931 /* Address Size comes after address structure */
932 dbg2_addr_size = (uint32_t *)current;
933 device->address_size_offset = current - (uintptr_t)device;
934 *dbg2_addr_size = address_size;
935 current += sizeof(uint32_t);
936
937 /* Namespace string comes last, use '.' if not provided */
938 path = device_path ? : ".";
939 /* Namespace string length includes NULL terminator */
940 path_len = strlen(path) + 1;
941 namespace = (char *)current;
942 device->namespace_string_length = path_len;
943 device->namespace_string_offset = current - (uintptr_t)device;
944 strncpy(namespace, path, path_len);
945 current += path_len;
946
947 /* Update structure lengths and checksum */
948 device->length = current - (uintptr_t)device;
949 header->length = current - (uintptr_t)dbg2;
950 header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
951}
952
953unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
Aamir Bohrae825d3f2019-07-30 10:11:41 +0530954 const struct device *dev, uint8_t access_size)
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800955{
956 acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
957 struct resource *res;
958 acpi_addr_t address;
959
960 if (!dev) {
961 printk(BIOS_ERR, "%s: Device not found\n", __func__);
962 return current;
963 }
Mario Scheithauerf1eb0ea2017-11-21 13:52:53 +0100964 if (!dev->enabled) {
965 printk(BIOS_INFO, "%s: Device not enabled\n", __func__);
966 return current;
967 }
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800968 res = find_resource(dev, PCI_BASE_ADDRESS_0);
969 if (!res) {
970 printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
971 __func__, dev_path(dev));
972 return current;
973 }
974
975 memset(&address, 0, sizeof(address));
976 if (res->flags & IORESOURCE_IO)
977 address.space_id = ACPI_ADDRESS_SPACE_IO;
978 else if (res->flags & IORESOURCE_MEM)
979 address.space_id = ACPI_ADDRESS_SPACE_MEMORY;
980 else {
981 printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
982 return current;
983 }
984
985 address.addrl = (uint32_t)res->base;
986 address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff);
987 address.access_size = access_size;
988
989 acpi_create_dbg2(dbg2,
990 ACPI_DBG2_PORT_SERIAL,
991 ACPI_DBG2_PORT_SERIAL_16550,
992 &address, res->size,
993 acpi_device_path(dev));
994
995 if (dbg2->header.length) {
996 current += dbg2->header.length;
997 current = acpi_align_current(current);
998 acpi_add_table(rsdp, dbg2);
999 }
1000
1001 return current;
1002}
1003
Stefan Reinauer777224c2005-01-19 14:06:41 +00001004void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001005{
Uwe Hermann622824c2010-11-19 15:14:42 +00001006 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001007
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001008 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001009 facs->length = sizeof(acpi_facs_t);
1010 facs->hardware_signature = 0;
1011 facs->firmware_waking_vector = 0;
1012 facs->global_lock = 0;
1013 facs->flags = 0;
1014 facs->x_firmware_waking_vector_l = 0;
1015 facs->x_firmware_waking_vector_h = 0;
Marc Jones93a51762018-08-22 18:57:24 -06001016 facs->version = get_acpi_table_revision(FACS);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001017}
Stefan Reinauer777224c2005-01-19 14:06:41 +00001018
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001019static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001020{
Uwe Hermann622824c2010-11-19 15:14:42 +00001021 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001022
John Zhao2ba303e2019-05-28 16:48:14 -07001023 if (!header)
1024 return;
1025
Uwe Hermann622824c2010-11-19 15:14:42 +00001026 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001027 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001028 memcpy(header->oem_id, oem_id, 6);
1029 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +00001030 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001031
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001032 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +00001033 header->length = sizeof(acpi_rsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001034 header->revision = get_acpi_table_revision(RSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001035
Uwe Hermann622824c2010-11-19 15:14:42 +00001036 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +00001037
Uwe Hermann622824c2010-11-19 15:14:42 +00001038 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001039 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001040}
1041
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001042static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001043{
Uwe Hermann622824c2010-11-19 15:14:42 +00001044 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001045
John Zhao2ba303e2019-05-28 16:48:14 -07001046 if (!header)
1047 return;
1048
Uwe Hermann622824c2010-11-19 15:14:42 +00001049 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001050 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001051 memcpy(header->oem_id, oem_id, 6);
1052 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001053 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001054
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001055 header->asl_compiler_revision = asl_revision;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001056 header->length = sizeof(acpi_xsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001057 header->revision = get_acpi_table_revision(XSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001058
Uwe Hermann622824c2010-11-19 15:14:42 +00001059 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001060
Uwe Hermann622824c2010-11-19 15:14:42 +00001061 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001062 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
1063}
1064
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001065static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
1066 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +00001067{
Stefan Reinauerd18faac2009-11-05 18:06:43 +00001068 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +00001069
Stefan Reinauer688b3852004-01-28 16:56:14 +00001070 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001071 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +00001072
1073 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -07001074 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +00001075
1076 /*
1077 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
1078 *
1079 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
1080 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
1081 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001082 */
1083 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001084 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001085 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -07001086 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Marc Jones93a51762018-08-22 18:57:24 -06001087 rsdp->revision = get_acpi_table_revision(RSDP);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001088 }
Uwe Hermann622824c2010-11-19 15:14:42 +00001089
1090 /* Calculate checksums. */
1091 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
1092 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001093}
1094
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001095unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1096 acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
zbaocaf494c82012-04-13 13:57:14 +08001097{
1098 acpi_header_t *header = &(hest->header);
1099 acpi_hest_hen_t *hen;
1100 void *pos;
1101 u16 len;
1102
1103 pos = esd;
1104 memset(pos, 0, sizeof(acpi_hest_esd_t));
1105 len = 0;
1106 esd->type = type; /* MCE */
1107 esd->source_id = hest->error_source_count;
1108 esd->flags = 0; /* FIRMWARE_FIRST */
1109 esd->enabled = 1;
1110 esd->prealloc_erecords = 1;
1111 esd->max_section_per_record = 0x1;
1112
1113 len += sizeof(acpi_hest_esd_t);
1114 pos = esd + 1;
1115
1116 switch (type) {
1117 case 0: /* MCE */
1118 break;
1119 case 1: /* CMC */
1120 hen = (acpi_hest_hen_t *) (pos);
1121 memset(pos, 0, sizeof(acpi_hest_hen_t));
1122 hen->type = 3; /* SCI? */
1123 hen->length = sizeof(acpi_hest_hen_t);
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001124 hen->conf_we = 0; /* Configuration Write Enable. */
zbaocaf494c82012-04-13 13:57:14 +08001125 hen->poll_interval = 0;
1126 hen->vector = 0;
1127 hen->sw2poll_threshold_val = 0;
1128 hen->sw2poll_threshold_win = 0;
1129 hen->error_threshold_val = 0;
1130 hen->error_threshold_win = 0;
1131 len += sizeof(acpi_hest_hen_t);
1132 pos = hen + 1;
1133 break;
1134 case 2: /* NMI */
1135 case 6: /* AER Root Port */
1136 case 7: /* AER Endpoint */
1137 case 8: /* AER Bridge */
1138 case 9: /* Generic Hardware Error Source. */
1139 /* TODO: */
1140 break;
1141 default:
1142 printk(BIOS_DEBUG, "Invalid type of Error Source.");
1143 break;
1144 }
Lee Leahy024b13d2017-03-16 13:41:11 -07001145 hest->error_source_count++;
zbaocaf494c82012-04-13 13:57:14 +08001146
1147 memcpy(pos, data, data_len);
1148 len += data_len;
John Zhao2ba303e2019-05-28 16:48:14 -07001149 if (header)
1150 header->length += len;
zbaocaf494c82012-04-13 13:57:14 +08001151
1152 return len;
1153}
1154
1155/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +01001156void acpi_write_hest(acpi_hest_t *hest,
1157 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +08001158{
1159 acpi_header_t *header = &(hest->header);
1160
1161 memset(hest, 0, sizeof(acpi_hest_t));
1162
John Zhao2ba303e2019-05-28 16:48:14 -07001163 if (!header)
1164 return;
1165
zbaocaf494c82012-04-13 13:57:14 +08001166 memcpy(header->signature, "HEST", 4);
1167 memcpy(header->oem_id, OEM_ID, 6);
1168 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1169 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001170 header->asl_compiler_revision = asl_revision;
zbaocaf494c82012-04-13 13:57:14 +08001171 header->length += sizeof(acpi_hest_t);
Marc Jones93a51762018-08-22 18:57:24 -06001172 header->revision = get_acpi_table_revision(HEST);
zbaocaf494c82012-04-13 13:57:14 +08001173
1174 acpi_fill_hest(hest);
1175
1176 /* Calculate checksums. */
1177 header->checksum = acpi_checksum((void *)hest, header->length);
1178}
1179
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001180/* ACPI 3.0b */
1181void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length)
1182{
1183 acpi_header_t *header = &(bert->header);
1184
1185 memset(bert, 0, sizeof(acpi_bert_t));
1186
John Zhao2ba303e2019-05-28 16:48:14 -07001187 if (!header)
1188 return;
1189
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001190 memcpy(header->signature, "BERT", 4);
1191 memcpy(header->oem_id, OEM_ID, 6);
1192 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1193 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001194 header->asl_compiler_revision = asl_revision;
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001195 header->length += sizeof(acpi_bert_t);
1196 header->revision = get_acpi_table_revision(BERT);
1197
1198 bert->error_region = region;
1199 bert->region_length = length;
1200
1201 /* Calculate checksums. */
1202 header->checksum = acpi_checksum((void *)bert, header->length);
1203}
1204
Julius Wernercd49cce2019-03-05 16:53:33 -08001205#if CONFIG(COMMON_FADT)
Lee Leahy024b13d2017-03-16 13:41:11 -07001206void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001207{
1208 acpi_header_t *header = &(fadt->header);
1209
1210 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
John Zhao2ba303e2019-05-28 16:48:14 -07001211
1212 if (!header)
1213 return;
1214
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001215 memcpy(header->signature, "FACP", 4);
1216 header->length = sizeof(acpi_fadt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001217 header->revision = get_acpi_table_revision(FADT);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001218 memcpy(header->oem_id, OEM_ID, 6);
1219 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1220 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +01001221 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001222
1223 fadt->firmware_ctrl = (unsigned long) facs;
1224 fadt->dsdt = (unsigned long) dsdt;
1225
1226 fadt->x_firmware_ctl_l = (unsigned long)facs;
1227 fadt->x_firmware_ctl_h = 0;
1228 fadt->x_dsdt_l = (unsigned long)dsdt;
1229 fadt->x_dsdt_h = 0;
1230
Julius Wernercd49cce2019-03-05 16:53:33 -08001231 if (CONFIG(SYSTEM_TYPE_CONVERTIBLE) ||
1232 CONFIG(SYSTEM_TYPE_LAPTOP))
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001233 fadt->preferred_pm_profile = PM_MOBILE;
Julius Wernercd49cce2019-03-05 16:53:33 -08001234 else if (CONFIG(SYSTEM_TYPE_DETACHABLE) ||
1235 CONFIG(SYSTEM_TYPE_TABLET))
Duncan Lauriefa9c6f12019-02-07 11:30:06 -08001236 fadt->preferred_pm_profile = PM_TABLET;
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001237 else
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001238 fadt->preferred_pm_profile = PM_DESKTOP;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001239
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +02001240 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001241
1242 header->checksum =
1243 acpi_checksum((void *) fadt, header->length);
1244}
1245#endif
1246
Aaron Durbin64031672018-04-21 14:45:32 -06001247unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001248{
1249 return 0;
1250}
1251
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001252unsigned long write_acpi_tables(unsigned long start)
1253{
1254 unsigned long current;
1255 acpi_rsdp_t *rsdp;
1256 acpi_rsdt_t *rsdt;
1257 acpi_xsdt_t *xsdt;
1258 acpi_fadt_t *fadt;
1259 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001260 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001261 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001262 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001263 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001264 acpi_tcpa_t *tcpa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001265 acpi_tpm2_t *tpm2;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001266 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +11001267 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001268 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001269 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001270 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001271
1272 current = start;
1273
1274 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -06001275 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001276
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001277 fw = fw_cfg_acpi_tables(current);
1278 if (fw)
1279 return fw;
1280
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +02001281 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001282 CONFIG_CBFS_PREFIX "/dsdt.aml",
1283 CBFS_TYPE_RAW, &dsdt_size);
1284 if (!dsdt_file) {
1285 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
1286 return current;
1287 }
1288
1289 if (dsdt_file->length > dsdt_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001290 || dsdt_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001291 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
1292 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
1293 return current;
1294 }
1295
Aaron Durbin899d13d2015-05-15 23:39:23 -05001296 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001297 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001298 if (slic_file
1299 && (slic_file->length > slic_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001300 || slic_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001301 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001302 slic_file = 0;
1303 }
1304
1305 if (slic_file) {
1306 memcpy(oem_id, slic_file->oem_id, 6);
1307 memcpy(oem_table_id, slic_file->oem_table_id, 8);
1308 } else {
1309 memcpy(oem_id, OEM_ID, 6);
1310 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
1311 }
1312
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001313 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
1314
1315 /* We need at least an RSDP and an RSDT Table */
1316 rsdp = (acpi_rsdp_t *) current;
1317 current += sizeof(acpi_rsdp_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001318 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001319 rsdt = (acpi_rsdt_t *) current;
1320 current += sizeof(acpi_rsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001321 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001322 xsdt = (acpi_xsdt_t *) current;
1323 current += sizeof(acpi_xsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001324 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001325
1326 /* clear all table memory */
1327 memset((void *) start, 0, current - start);
1328
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001329 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
1330 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
1331 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001332
1333 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Felix Heldc4697122019-06-20 13:50:17 +02001334 current = ALIGN_UP(current, 64);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001335 facs = (acpi_facs_t *) current;
1336 current += sizeof(acpi_facs_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001337 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001338 acpi_create_facs(facs);
1339
1340 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
1341 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001342 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001343 if (dsdt->length >= sizeof(acpi_header_t)) {
1344 current += sizeof(acpi_header_t);
1345
1346 acpigen_set_current((char *) current);
1347 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001348 if (dev->ops && dev->ops->acpi_inject_dsdt_generator)
Alexander Couzensa90dad12015-04-12 21:49:46 +02001349 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001350 current = (unsigned long) acpigen_get_current();
1351 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001352 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001353 dsdt->length - sizeof(acpi_header_t));
1354 current += dsdt->length - sizeof(acpi_header_t);
1355
1356 /* (Re)calculate length and checksum. */
1357 dsdt->length = current - (unsigned long)dsdt;
1358 dsdt->checksum = 0;
1359 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
1360 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001361
Aaron Durbin07a1b282015-12-10 17:07:38 -06001362 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001363
1364 printk(BIOS_DEBUG, "ACPI: * FADT\n");
1365 fadt = (acpi_fadt_t *) current;
1366 current += sizeof(acpi_fadt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001367 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001368
1369 acpi_create_fadt(fadt, facs, dsdt);
1370 acpi_add_table(rsdp, fadt);
1371
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001372 if (slic_file) {
1373 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
1374 slic = (acpi_header_t *)current;
1375 memcpy(slic, slic_file, slic_file->length);
1376 current += slic_file->length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001377 current = acpi_align_current(current);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001378 acpi_add_table(rsdp, slic);
1379 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001380
1381 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1382 ssdt = (acpi_header_t *)current;
1383 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001384 if (ssdt->length > sizeof(acpi_header_t)) {
1385 current += ssdt->length;
1386 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001387 current = acpi_align_current(current);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001388 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001389
1390 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
1391 mcfg = (acpi_mcfg_t *) current;
1392 acpi_create_mcfg(mcfg);
1393 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
1394 current += mcfg->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001395 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001396 acpi_add_table(rsdp, mcfg);
1397 }
1398
Julius Wernercd49cce2019-03-05 16:53:33 -08001399 if (CONFIG(TPM1)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001400 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
1401 tcpa = (acpi_tcpa_t *) current;
1402 acpi_create_tcpa(tcpa);
1403 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
1404 current += tcpa->header.length;
1405 current = acpi_align_current(current);
1406 acpi_add_table(rsdp, tcpa);
1407 }
1408 }
1409
Julius Wernercd49cce2019-03-05 16:53:33 -08001410 if (CONFIG(TPM2)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001411 printk(BIOS_DEBUG, "ACPI: * TPM2\n");
1412 tpm2 = (acpi_tpm2_t *) current;
1413 acpi_create_tpm2(tpm2);
1414 if (tpm2->header.length >= sizeof(acpi_tpm2_t)) {
1415 current += tpm2->header.length;
1416 current = acpi_align_current(current);
1417 acpi_add_table(rsdp, tpm2);
1418 }
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001419 }
1420
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001421 printk(BIOS_DEBUG, "ACPI: * MADT\n");
1422
1423 madt = (acpi_madt_t *) current;
1424 acpi_create_madt(madt);
1425 if (madt->header.length > sizeof(acpi_madt_t)) {
Lee Leahy024b13d2017-03-16 13:41:11 -07001426 current += madt->header.length;
1427 acpi_add_table(rsdp, madt);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001428 }
Aaron Durbin07a1b282015-12-10 17:07:38 -06001429 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001430
1431 printk(BIOS_DEBUG, "current = %lx\n", current);
1432
1433 for (dev = all_devices; dev; dev = dev->next) {
1434 if (dev->ops && dev->ops->write_acpi_tables) {
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001435 current = dev->ops->write_acpi_tables(dev, current,
1436 rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001437 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001438 }
1439 }
1440
1441 printk(BIOS_INFO, "ACPI: done.\n");
1442 return current;
1443}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001444
Rudolf Marek33cafe52009-04-13 18:07:02 +00001445static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1446{
1447 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1448 return NULL;
1449
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001450 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001451
1452 if (acpi_checksum((void *)rsdp, 20) != 0)
1453 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001454 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001455
1456 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1457 rsdp->length) != 0))
1458 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001459 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001460
1461 return rsdp;
1462}
1463
Rudolf Marek33cafe52009-04-13 18:07:02 +00001464void *acpi_find_wakeup_vector(void)
1465{
1466 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001467 acpi_rsdt_t *rsdt;
1468 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001469 acpi_fadt_t *fadt = NULL;
Kyösti Mälkki072d436b2016-06-17 08:44:40 +03001470 acpi_rsdp_t *rsdp = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001471 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001472 int i;
1473
Rudolf Marek33cafe52009-04-13 18:07:02 +00001474 if (!acpi_is_wakeup())
1475 return NULL;
1476
Uwe Hermann622824c2010-11-19 15:14:42 +00001477 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001478
Uwe Hermann622824c2010-11-19 15:14:42 +00001479 /* Find RSDP. */
1480 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
Lee Leahy0b5678f2017-03-16 16:01:40 -07001481 rsdp = valid_rsdp((acpi_rsdp_t *)p);
1482 if (rsdp)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001483 break;
1484 }
1485
Angel Pons98a68ad2018-11-04 12:25:25 +01001486 if (rsdp == NULL) {
1487 printk(BIOS_ALERT,
1488 "No RSDP found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001489 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001490 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001491
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001492 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001493 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001494
Uwe Hermann622824c2010-11-19 15:14:42 +00001495 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001496 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001497
Uwe Hermann622824c2010-11-19 15:14:42 +00001498 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001499 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001500 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001501 break;
1502 fadt = NULL;
1503 }
1504
Angel Pons98a68ad2018-11-04 12:25:25 +01001505 if (fadt == NULL) {
1506 printk(BIOS_ALERT,
1507 "No FADT found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001508 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001509 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001510
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001511 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001512 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001513
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001514 if (facs == NULL) {
Angel Pons98a68ad2018-11-04 12:25:25 +01001515 printk(BIOS_ALERT,
1516 "No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001517 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001518 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001519
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001520 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001521 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001522 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001523
Rudolf Marek33cafe52009-04-13 18:07:02 +00001524 return wake_vec;
1525}
1526
Aaron Durbin64031672018-04-21 14:45:32 -06001527__weak int acpi_get_gpe(int gpe)
Duncan Laurie1f6e6812016-09-19 12:04:19 -07001528{
1529 return -1; /* implemented by SOC */
1530}
Marc Jones93a51762018-08-22 18:57:24 -06001531
1532int get_acpi_table_revision(enum acpi_tables table)
1533{
1534 switch (table) {
1535 case FADT:
1536 return ACPI_FADT_REV_ACPI_3_0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001537 case MADT: /* ACPI 3.0: 2, ACPI 4.0/5.0: 3, ACPI 6.2b/6.3: 5 */
Marc Jones4ddd4762018-08-21 10:50:57 -06001538 return 2;
Marc Jones93a51762018-08-22 18:57:24 -06001539 case MCFG:
1540 return 1;
1541 case TCPA:
1542 return 2;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001543 case TPM2:
1544 return 4;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001545 case SSDT: /* ACPI 3.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001546 return 2;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001547 case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 upto 6.3: 3 */
Marc Jones93a51762018-08-22 18:57:24 -06001548 return 1; /* TODO Should probably be upgraded to 2 */
1549 case DMAR:
1550 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001551 case SLIT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001552 return 1;
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +02001553 case SPMI: /* IMPI 2.0 */
1554 return 5;
Marc Jones93a51762018-08-22 18:57:24 -06001555 case HPET: /* Currently 1. Table added in ACPI 2.0. */
1556 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001557 case VFCT: /* ACPI 2.0/3.0/4.0: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001558 return 1;
1559 case IVRS:
1560 return IVRS_FORMAT_FIXED;
1561 case DBG2:
1562 return 0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001563 case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001564 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001565 case RSDT: /* ACPI 1.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001566 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001567 case XSDT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001568 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001569 case RSDP: /* ACPI 2.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001570 return 2;
1571 case HEST:
1572 return 1;
1573 case NHLT:
1574 return 5;
Marshall Dawson44705c62018-09-04 13:47:15 -06001575 case BERT:
1576 return 1;
Marc Jones93a51762018-08-22 18:57:24 -06001577 default:
1578 return -1;
1579 }
1580 return -1;
1581}