blob: 1b8aaae64b895b505ae4a34844805d4a81c8b832 [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>
Patrick Georgic8feedd2012-02-16 18:43:25 +010047#include <cpu/x86/lapic_def.h>
Duncan Laurie11290c42012-10-03 19:07:05 -070048#include <cpu/cpu.h>
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +010049#include <cbfs.h>
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010050#include <version.h>
Werner Zehdb561e62019-02-19 13:39:56 +010051#include <commonlib/sort.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000052
53u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000054{
Uwe Hermann622824c2010-11-19 15:14:42 +000055 u8 ret = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +000056 while (length--) {
57 ret += *table;
58 table++;
59 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000060 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000061}
62
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000063/**
Uwe Hermann622824c2010-11-19 15:14:42 +000064 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
65 * and checksum.
Stefan Reinauer06feb882004-02-03 16:11:35 +000066 */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000067void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000068{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000069 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000070 acpi_rsdt_t *rsdt;
71 acpi_xsdt_t *xsdt = NULL;
72
Uwe Hermann622824c2010-11-19 15:14:42 +000073 /* The RSDT is mandatory... */
Stefan Reinauerdefee172015-06-18 01:11:19 -070074 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000075
Uwe Hermann622824c2010-11-19 15:14:42 +000076 /* ...while the XSDT is not. */
77 if (rsdp->xsdt_address)
Stefan Reinauerdefee172015-06-18 01:11:19 -070078 xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address);
Stefan Reinauer14e22772010-04-27 06:56:47 +000079
Uwe Hermann622824c2010-11-19 15:14:42 +000080 /* This should always be MAX_ACPI_TABLES. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000081 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauer14e22772010-04-27 06:56:47 +000082
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000083 for (i = 0; i < entries_num; i++) {
Uwe Hermann622824c2010-11-19 15:14:42 +000084 if (rsdt->entry[i] == 0)
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000085 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000086 }
87
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000088 if (i >= entries_num) {
Uwe Hermann622824c2010-11-19 15:14:42 +000089 printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +030090 "too many tables.\n");
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000091 return;
92 }
93
Uwe Hermann622824c2010-11-19 15:14:42 +000094 /* Add table to the RSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070095 rsdt->entry[i] = (uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000096
Uwe Hermann622824c2010-11-19 15:14:42 +000097 /* Fix RSDT length or the kernel will assume invalid entries. */
98 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000099
Uwe Hermann622824c2010-11-19 15:14:42 +0000100 /* Re-calculate checksum. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000101 rsdt->header.checksum = 0; /* Hope this won't get optimized away */
Uwe Hermann622824c2010-11-19 15:14:42 +0000102 rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000103
Uwe Hermann622824c2010-11-19 15:14:42 +0000104 /*
105 * And now the same thing for the XSDT. We use the same index as for
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000106 * now we want the XSDT and RSDT to always be in sync in coreboot.
107 */
108 if (xsdt) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000109 /* Add table to the XSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -0700110 xsdt->entry[i] = (u64)(uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000111
Uwe Hermann622824c2010-11-19 15:14:42 +0000112 /* Fix XSDT length. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000113 xsdt->header.length = sizeof(acpi_header_t) +
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300114 (sizeof(u64) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000115
Uwe Hermann622824c2010-11-19 15:14:42 +0000116 /* Re-calculate checksum. */
117 xsdt->header.checksum = 0;
118 xsdt->header.checksum = acpi_checksum((u8 *)xsdt,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300119 xsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000120 }
121
Uwe Hermann622824c2010-11-19 15:14:42 +0000122 printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300123 i + 1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000124}
125
Uwe Hermann622824c2010-11-19 15:14:42 +0000126int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300127 u16 seg_nr, u8 start, u8 end)
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000128{
Vladimir Serbinenko60fccdc2014-10-05 11:05:16 +0200129 memset(mmconfig, 0, sizeof(*mmconfig));
Rudolf Mareke6409f22007-11-03 12:50:26 +0000130 mmconfig->base_address = base;
131 mmconfig->base_reserved = 0;
132 mmconfig->pci_segment_group_number = seg_nr;
133 mmconfig->start_bus_number = start;
134 mmconfig->end_bus_number = end;
Uwe Hermann622824c2010-11-19 15:14:42 +0000135
136 return sizeof(acpi_mcfg_mmconfig_t);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000137}
138
Stefan Reinauer777224c2005-01-19 14:06:41 +0000139int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000140{
Uwe Hermann622824c2010-11-19 15:14:42 +0000141 lapic->type = 0; /* Local APIC structure */
142 lapic->length = sizeof(acpi_madt_lapic_t);
143 lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
144 lapic->processor_id = cpu;
145 lapic->apic_id = apic;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000146
Uwe Hermann622824c2010-11-19 15:14:42 +0000147 return lapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000148}
149
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000150unsigned long acpi_create_madt_lapics(unsigned long current)
151{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100152 struct device *cpu;
Werner Zeh423adfb2019-03-06 09:31:02 +0100153 int index, apic_ids[CONFIG_MAX_CPUS] = {0}, num_cpus = 0;
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000154
Uwe Hermann622824c2010-11-19 15:14:42 +0000155 for (cpu = all_devices; cpu; cpu = cpu->next) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000156 if ((cpu->path.type != DEVICE_PATH_APIC) ||
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800157 (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000158 continue;
159 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000160 if (!cpu->enabled)
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000161 continue;
Werner Zehdb561e62019-02-19 13:39:56 +0100162 if (num_cpus >= ARRAY_SIZE(apic_ids))
163 break;
164 apic_ids[num_cpus++] = cpu->path.apic.apic_id;
165 }
Werner Zehfedb36e2019-03-12 07:07:50 +0100166 if (num_cpus > 1)
167 bubblesort(apic_ids, num_cpus, NUM_ASCENDING);
Werner Zehdb561e62019-02-19 13:39:56 +0100168 for (index = 0; index < num_cpus; index++) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000169 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
Werner Zehdb561e62019-02-19 13:39:56 +0100170 index, apic_ids[index]);
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000171 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000172
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000173 return current;
174}
175
Uwe Hermann622824c2010-11-19 15:14:42 +0000176int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300177 u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000178{
Uwe Hermann622824c2010-11-19 15:14:42 +0000179 ioapic->type = 1; /* I/O APIC structure */
180 ioapic->length = sizeof(acpi_madt_ioapic_t);
181 ioapic->reserved = 0x00;
182 ioapic->gsi_base = gsi_base;
183 ioapic->ioapic_id = id;
184 ioapic->ioapic_addr = addr;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000185
Uwe Hermann622824c2010-11-19 15:14:42 +0000186 return ioapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000187}
188
Stefan Reinauer777224c2005-01-19 14:06:41 +0000189int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000190 u8 bus, u8 source, u32 gsirq, u16 flags)
191{
Uwe Hermann622824c2010-11-19 15:14:42 +0000192 irqoverride->type = 2; /* Interrupt source override */
193 irqoverride->length = sizeof(acpi_madt_irqoverride_t);
194 irqoverride->bus = bus;
195 irqoverride->source = source;
196 irqoverride->gsirq = gsirq;
197 irqoverride->flags = flags;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000198
Uwe Hermann622824c2010-11-19 15:14:42 +0000199 return irqoverride->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000200}
201
Stefan Reinauer777224c2005-01-19 14:06:41 +0000202int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300203 u16 flags, u8 lint)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000204{
Uwe Hermann622824c2010-11-19 15:14:42 +0000205 lapic_nmi->type = 4; /* Local APIC NMI structure */
206 lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
207 lapic_nmi->flags = flags;
208 lapic_nmi->processor_id = cpu;
209 lapic_nmi->lint = lint;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000210
Uwe Hermann622824c2010-11-19 15:14:42 +0000211 return lapic_nmi->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000212}
213
Stefan Reinauer777224c2005-01-19 14:06:41 +0000214void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000215{
Uwe Hermann622824c2010-11-19 15:14:42 +0000216 acpi_header_t *header = &(madt->header);
217 unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000218
Stefan Reinauer06feb882004-02-03 16:11:35 +0000219 memset((void *)madt, 0, sizeof(acpi_madt_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000220
John Zhao2ba303e2019-05-28 16:48:14 -0700221 if (!header)
222 return;
223
Uwe Hermann622824c2010-11-19 15:14:42 +0000224 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000225 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000226 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000227 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000228 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000229
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100230 header->asl_compiler_revision = asl_revision;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000231 header->length = sizeof(acpi_madt_t);
Marc Jones93a51762018-08-22 18:57:24 -0600232 header->revision = get_acpi_table_revision(MADT);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000233
Uwe Hermann622824c2010-11-19 15:14:42 +0000234 madt->lapic_addr = LOCAL_APIC_ADDR;
Nico Huber9df72e02018-11-24 18:25:50 +0100235 if (CONFIG(ACPI_HAVE_PCAT_8259))
236 madt->flags |= 1;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000237
Stefan Reinauerf622d592005-11-26 16:56:05 +0000238 current = acpi_fill_madt(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000239
Uwe Hermann622824c2010-11-19 15:14:42 +0000240 /* (Re)calculate length and checksum. */
241 header->length = current - (unsigned long)madt;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000242
Uwe Hermann622824c2010-11-19 15:14:42 +0000243 header->checksum = acpi_checksum((void *)madt, header->length);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000244}
245
Uwe Hermann622824c2010-11-19 15:14:42 +0000246/* MCFG is defined in the PCI Firmware Specification 3.0. */
Rudolf Mareke6409f22007-11-03 12:50:26 +0000247void acpi_create_mcfg(acpi_mcfg_t *mcfg)
248{
Uwe Hermann622824c2010-11-19 15:14:42 +0000249 acpi_header_t *header = &(mcfg->header);
250 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000251
Rudolf Mareke6409f22007-11-03 12:50:26 +0000252 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000253
John Zhao2ba303e2019-05-28 16:48:14 -0700254 if (!header)
255 return;
256
Uwe Hermann622824c2010-11-19 15:14:42 +0000257 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000258 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000259 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000260 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000261 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000262
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100263 header->asl_compiler_revision = asl_revision;
Rudolf Mareke6409f22007-11-03 12:50:26 +0000264 header->length = sizeof(acpi_mcfg_t);
Marc Jones93a51762018-08-22 18:57:24 -0600265 header->revision = get_acpi_table_revision(MCFG);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000266
267 current = acpi_fill_mcfg(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000268
Uwe Hermann622824c2010-11-19 15:14:42 +0000269 /* (Re)calculate length and checksum. */
270 header->length = current - (unsigned long)mcfg;
271 header->checksum = acpi_checksum((void *)mcfg, header->length);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000272}
273
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200274static void *get_tcpa_log(u32 *size)
275{
276 const struct cbmem_entry *ce;
277 const u32 tcpa_default_log_len = 0x10000;
278 void *lasa;
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200279 ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200280 if (ce) {
281 lasa = cbmem_entry_start(ce);
282 *size = cbmem_entry_size(ce);
283 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
284 return lasa;
285 }
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200286 lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200287 if (!lasa) {
288 printk(BIOS_ERR, "TCPA log creation failed\n");
289 return NULL;
290 }
291
292 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
Lee Leahy024b13d2017-03-16 13:41:11 -0700293 memset(lasa, 0, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200294
295 *size = tcpa_default_log_len;
296 return lasa;
297}
298
299static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
300{
301 acpi_header_t *header = &(tcpa->header);
302 u32 tcpa_log_len;
303 void *lasa;
304
305 memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
306
307 lasa = get_tcpa_log(&tcpa_log_len);
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700308 if (!lasa)
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200309 return;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200310
John Zhao2ba303e2019-05-28 16:48:14 -0700311 if (!header)
312 return;
313
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200314 /* Fill out header fields. */
315 memcpy(header->signature, "TCPA", 4);
316 memcpy(header->oem_id, OEM_ID, 6);
317 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
318 memcpy(header->asl_compiler_id, ASLC, 4);
319
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100320 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200321 header->length = sizeof(acpi_tcpa_t);
Marc Jones93a51762018-08-22 18:57:24 -0600322 header->revision = get_acpi_table_revision(TCPA);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200323
324 tcpa->platform_class = 0;
325 tcpa->laml = tcpa_log_len;
Stefan Reinauerdefee172015-06-18 01:11:19 -0700326 tcpa->lasa = (uintptr_t) lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200327
328 /* Calculate checksum. */
329 header->checksum = acpi_checksum((void *)tcpa, header->length);
330}
331
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100332static void *get_tpm2_log(u32 *size)
333{
334 const struct cbmem_entry *ce;
335 const u32 tpm2_default_log_len = 0x10000;
336 void *lasa;
337 ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG);
338 if (ce) {
339 lasa = cbmem_entry_start(ce);
340 *size = cbmem_entry_size(ce);
341 printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa);
342 return lasa;
343 }
344 lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len);
345 if (!lasa) {
346 printk(BIOS_ERR, "TPM2 log creation failed\n");
347 return NULL;
348 }
349
350 printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa);
351 memset(lasa, 0, tpm2_default_log_len);
352
353 *size = tpm2_default_log_len;
354 return lasa;
355}
356
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200357static void acpi_create_tpm2(acpi_tpm2_t *tpm2)
358{
359 acpi_header_t *header = &(tpm2->header);
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100360 u32 tpm2_log_len;
361 void *lasa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200362
363 memset((void *)tpm2, 0, sizeof(acpi_tpm2_t));
364
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100365 /*
366 * Some payloads like SeaBIOS depend on log area to use TPM2.
367 * Get the memory size and address of TPM2 log area or initialize it.
368 */
369 lasa = get_tpm2_log(&tpm2_log_len);
370 if (!lasa)
371 tpm2_log_len = 0;
372
John Zhao2ba303e2019-05-28 16:48:14 -0700373 if (!header)
374 return;
375
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200376 /* Fill out header fields. */
377 memcpy(header->signature, "TPM2", 4);
378 memcpy(header->oem_id, OEM_ID, 6);
379 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
380 memcpy(header->asl_compiler_id, ASLC, 4);
381
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100382 header->asl_compiler_revision = asl_revision;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200383 header->length = sizeof(acpi_tpm2_t);
384 header->revision = get_acpi_table_revision(TPM2);
385
386 /* Hard to detect for coreboot. Just set it to 0 */
387 tpm2->platform_class = 0;
388 /* Must be set to 0 for TIS interface support */
389 tpm2->control_area = 0;
390 /* coreboot only supports the TIS interface driver. */
391 tpm2->start_method = 6;
392 memset(tpm2->msp, 0, sizeof(tpm2->msp));
393
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100394 /* Fill the log area size and start address fields. */
395 tpm2->laml = tpm2_log_len;
396 tpm2->lasa = (uintptr_t) lasa;
397
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200398 /* Calculate checksum. */
399 header->checksum = acpi_checksum((void *)tpm2, header->length);
400}
401
Duncan Laurie37319032016-05-26 12:47:05 -0700402static void acpi_ssdt_write_cbtable(void)
403{
404 const struct cbmem_entry *cbtable;
405 uintptr_t base;
406 uint32_t size;
407
408 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
409 if (!cbtable)
410 return;
411 base = (uintptr_t)cbmem_entry_start(cbtable);
412 size = cbmem_entry_size(cbtable);
413
414 acpigen_write_device("CTBL");
415 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
416 acpigen_write_name_integer("_UID", 0);
David Wu5dff3962018-03-21 16:48:53 +0800417 acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON);
Duncan Laurie37319032016-05-26 12:47:05 -0700418 acpigen_write_name("_CRS");
419 acpigen_write_resourcetemplate_header();
420 acpigen_write_mem32fixed(0, base, size);
421 acpigen_write_resourcetemplate_footer();
422 acpigen_pop_len();
423}
424
Myles Watson3fe6b702009-10-09 20:13:43 +0000425void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000426{
Uwe Hermann622824c2010-11-19 15:14:42 +0000427 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
428
Rudolf Marek293b5f52009-02-01 18:35:15 +0000429 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000430
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000431 memcpy(&ssdt->signature, "SSDT", 4);
Marc Jones93a51762018-08-22 18:57:24 -0600432 ssdt->revision = get_acpi_table_revision(SSDT);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000433 memcpy(&ssdt->oem_id, OEM_ID, 6);
434 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
435 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000436 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +0100437 ssdt->asl_compiler_revision = asl_revision;
Rudolf Marek293b5f52009-02-01 18:35:15 +0000438 ssdt->length = sizeof(acpi_header_t);
439
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000440 acpigen_set_current((char *) current);
Duncan Laurie37319032016-05-26 12:47:05 -0700441
442 /* Write object to declare coreboot tables */
443 acpi_ssdt_write_cbtable();
444
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200445 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100446 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200447 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700448 if (dev->ops && dev->ops->acpi_fill_ssdt_generator)
Alexander Couzens5eea4582015-04-12 22:18:55 +0200449 dev->ops->acpi_fill_ssdt_generator(dev);
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200450 current = (unsigned long) acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200451 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000452
Uwe Hermann622824c2010-11-19 15:14:42 +0000453 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000454 ssdt->length = current - (unsigned long)ssdt;
455 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
456}
457
Stefan Reinauerf622d592005-11-26 16:56:05 +0000458int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
459{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000460 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000461
Uwe Hermann622824c2010-11-19 15:14:42 +0000462 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
463 lapic->length = sizeof(acpi_srat_lapic_t);
464 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
465 lapic->proximity_domain_7_0 = node;
466 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
467 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000468
Uwe Hermann622824c2010-11-19 15:14:42 +0000469 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000470}
471
Uwe Hermann622824c2010-11-19 15:14:42 +0000472int 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 +0300473 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000474{
Uwe Hermann622824c2010-11-19 15:14:42 +0000475 mem->type = 1; /* Memory affinity structure */
476 mem->length = sizeof(acpi_srat_mem_t);
477 mem->base_address_low = (basek << 10);
478 mem->base_address_high = (basek >> (32 - 10));
479 mem->length_low = (sizek << 10);
480 mem->length_high = (sizek >> (32 - 10));
481 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000482 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000483
Uwe Hermann622824c2010-11-19 15:14:42 +0000484 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000485}
486
Uwe Hermann622824c2010-11-19 15:14:42 +0000487/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200488void acpi_create_srat(acpi_srat_t *srat,
489 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000490{
Uwe Hermann622824c2010-11-19 15:14:42 +0000491 acpi_header_t *header = &(srat->header);
492 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000493
Uwe Hermann622824c2010-11-19 15:14:42 +0000494 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000495
John Zhao2ba303e2019-05-28 16:48:14 -0700496 if (!header)
497 return;
498
Uwe Hermann622824c2010-11-19 15:14:42 +0000499 /* Fill out header fields. */
500 memcpy(header->signature, "SRAT", 4);
501 memcpy(header->oem_id, OEM_ID, 6);
502 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
503 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000504
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100505 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000506 header->length = sizeof(acpi_srat_t);
Marc Jones93a51762018-08-22 18:57:24 -0600507 header->revision = get_acpi_table_revision(SRAT);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000508
Uwe Hermann622824c2010-11-19 15:14:42 +0000509 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000510
Uwe Hermann622824c2010-11-19 15:14:42 +0000511 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000512
Uwe Hermann622824c2010-11-19 15:14:42 +0000513 /* (Re)calculate length and checksum. */
514 header->length = current - (unsigned long)srat;
515 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000516}
517
Nico Hubere561f352015-10-26 11:51:25 +0100518void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Lee Leahy024b13d2017-03-16 13:41:11 -0700519 unsigned long (*acpi_fill_dmar)(unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200520{
521 acpi_header_t *header = &(dmar->header);
522 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
523
524 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
525
John Zhao2ba303e2019-05-28 16:48:14 -0700526 if (!header)
527 return;
528
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200529 /* Fill out header fields. */
530 memcpy(header->signature, "DMAR", 4);
531 memcpy(header->oem_id, OEM_ID, 6);
532 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
533 memcpy(header->asl_compiler_id, ASLC, 4);
534
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100535 header->asl_compiler_revision = asl_revision;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200536 header->length = sizeof(acpi_dmar_t);
Marc Jones93a51762018-08-22 18:57:24 -0600537 header->revision = get_acpi_table_revision(DMAR);
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200538
Jacob Laskaf3f654d2016-03-15 21:53:27 -0500539 dmar->host_address_width = cpu_phys_address_size() - 1;
Nico Hubere561f352015-10-26 11:51:25 +0100540 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200541
542 current = acpi_fill_dmar(current);
543
544 /* (Re)calculate length and checksum. */
545 header->length = current - (unsigned long)dmar;
546 header->checksum = acpi_checksum((void *)dmar, header->length);
547}
548
549unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
Matt DeVillier7866d492018-03-29 14:59:57 +0200550 u16 segment, u64 bar)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200551{
552 dmar_entry_t *drhd = (dmar_entry_t *)current;
553 memset(drhd, 0, sizeof(*drhd));
554 drhd->type = DMAR_DRHD;
555 drhd->length = sizeof(*drhd); /* will be fixed up later */
556 drhd->flags = flags;
557 drhd->segment = segment;
558 drhd->bar = bar;
559
560 return drhd->length;
561}
562
Matt DeVillier7866d492018-03-29 14:59:57 +0200563unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
564 u64 bar, u64 limit)
565{
566 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current;
567 memset(rmrr, 0, sizeof(*rmrr));
568 rmrr->type = DMAR_RMRR;
569 rmrr->length = sizeof(*rmrr); /* will be fixed up later */
570 rmrr->segment = segment;
571 rmrr->bar = bar;
572 rmrr->limit = limit;
573
574 return rmrr->length;
575}
576
Werner Zehd4d76952016-07-27 06:56:36 +0200577unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
578 u16 segment)
579{
580 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
581 memset(atsr, 0, sizeof(*atsr));
582 atsr->type = DMAR_ATSR;
583 atsr->length = sizeof(*atsr); /* will be fixed up later */
584 atsr->flags = flags;
585 atsr->segment = segment;
586
587 return atsr->length;
588}
589
John Zhao76e70672019-04-04 11:03:28 -0700590unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
591 u32 proximity_domain)
592{
593 dmar_rhsa_entry_t *rhsa = (dmar_rhsa_entry_t *)current;
594 memset(rhsa, 0, sizeof(*rhsa));
595 rhsa->type = DMAR_RHSA;
596 rhsa->length = sizeof(*rhsa);
597 rhsa->base_address = base_addr;
598 rhsa->proximity_domain = proximity_domain;
599
600 return rhsa->length;
601}
602
603unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
604 const char *device_name)
605{
606 dmar_andd_entry_t *andd = (dmar_andd_entry_t *)current;
607 int andd_len = sizeof(dmar_andd_entry_t) + strlen(device_name) + 1;
608 memset(andd, 0, andd_len);
609 andd->type = DMAR_ANDD;
610 andd->length = andd_len;
611 andd->device_number = device_number;
612 memcpy(&andd->device_name, device_name, strlen(device_name));
613
614 return andd->length;
615}
616
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200617void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
618{
619 dmar_entry_t *drhd = (dmar_entry_t *)base;
620 drhd->length = current - base;
621}
622
Matt DeVillier7866d492018-03-29 14:59:57 +0200623void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
624{
625 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)base;
626 rmrr->length = current - base;
627}
628
Werner Zehd4d76952016-07-27 06:56:36 +0200629void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
630{
631 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base;
632 atsr->length = current - base;
633}
634
Matt DeVillier7866d492018-03-29 14:59:57 +0200635static unsigned long acpi_create_dmar_ds(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100636 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200637{
Nico Huber6c4751d2015-10-26 12:03:54 +0100638 /* we don't support longer paths yet */
639 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
640
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200641 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100642 memset(ds, 0, dev_scope_length);
643 ds->type = type;
644 ds->length = dev_scope_length;
645 ds->enumeration = enumeration_id;
646 ds->start_bus = bus;
647 ds->path[0].dev = dev;
648 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200649
650 return ds->length;
651}
652
Matt DeVillier7866d492018-03-29 14:59:57 +0200653unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200654 u8 dev, u8 fn)
655{
Matt DeVillier7866d492018-03-29 14:59:57 +0200656 return acpi_create_dmar_ds(current,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200657 SCOPE_PCI_SUB, 0, bus, dev, fn);
658}
659
Matt DeVillier7866d492018-03-29 14:59:57 +0200660unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus,
Nico Huber6c4751d2015-10-26 12:03:54 +0100661 u8 dev, u8 fn)
662{
Matt DeVillier7866d492018-03-29 14:59:57 +0200663 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100664 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
665}
666
Matt DeVillier7866d492018-03-29 14:59:57 +0200667unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100668 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
669{
Matt DeVillier7866d492018-03-29 14:59:57 +0200670 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100671 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
672}
673
Matt DeVillier7866d492018-03-29 14:59:57 +0200674unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100675 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
676{
Matt DeVillier7866d492018-03-29 14:59:57 +0200677 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100678 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
679}
680
Uwe Hermann622824c2010-11-19 15:14:42 +0000681/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200682void acpi_create_slit(acpi_slit_t *slit,
683 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000684{
Uwe Hermann622824c2010-11-19 15:14:42 +0000685 acpi_header_t *header = &(slit->header);
686 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000687
Uwe Hermann622824c2010-11-19 15:14:42 +0000688 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000689
John Zhao2ba303e2019-05-28 16:48:14 -0700690 if (!header)
691 return;
692
Uwe Hermann622824c2010-11-19 15:14:42 +0000693 /* Fill out header fields. */
694 memcpy(header->signature, "SLIT", 4);
695 memcpy(header->oem_id, OEM_ID, 6);
696 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
697 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000698
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100699 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000700 header->length = sizeof(acpi_slit_t);
Marc Jones93a51762018-08-22 18:57:24 -0600701 header->revision = get_acpi_table_revision(SLIT);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000702
Uwe Hermann622824c2010-11-19 15:14:42 +0000703 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000704
Uwe Hermann622824c2010-11-19 15:14:42 +0000705 /* (Re)calculate length and checksum. */
706 header->length = current - (unsigned long)slit;
707 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000708}
709
Uwe Hermann622824c2010-11-19 15:14:42 +0000710/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000711void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000712{
Uwe Hermann622824c2010-11-19 15:14:42 +0000713 acpi_header_t *header = &(hpet->header);
714 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000715
Stefan Reinauera7648c22004-01-29 17:31:34 +0000716 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000717
John Zhao2ba303e2019-05-28 16:48:14 -0700718 if (!header)
719 return;
720
Uwe Hermann622824c2010-11-19 15:14:42 +0000721 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000722 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000723 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000724 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000725 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000726
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100727 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000728 header->length = sizeof(acpi_hpet_t);
Marc Jones93a51762018-08-22 18:57:24 -0600729 header->revision = get_acpi_table_revision(HPET);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000730
Uwe Hermann622824c2010-11-19 15:14:42 +0000731 /* Fill out HPET address. */
732 addr->space_id = 0; /* Memory */
733 addr->bit_width = 64;
734 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200735 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
736 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000737
Lee Leahy024b13d2017-03-16 13:41:11 -0700738 hpet->id = *(unsigned int *)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000739 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200740 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000741
Uwe Hermann622824c2010-11-19 15:14:42 +0000742 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000743}
Uwe Hermann622824c2010-11-19 15:14:42 +0000744
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200745void acpi_create_vfct(struct device *device,
746 struct acpi_vfct *vfct,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700747 unsigned long (*acpi_fill_vfct)(struct device *device,
748 struct acpi_vfct *vfct_struct, unsigned long current))
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200749{
750 acpi_header_t *header = &(vfct->header);
751 unsigned long current = (unsigned long)vfct + sizeof(struct acpi_vfct);
752
753 memset((void *)vfct, 0, sizeof(struct acpi_vfct));
754
John Zhao2ba303e2019-05-28 16:48:14 -0700755 if (!header)
756 return;
757
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200758 /* Fill out header fields. */
759 memcpy(header->signature, "VFCT", 4);
760 memcpy(header->oem_id, OEM_ID, 6);
761 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
762 memcpy(header->asl_compiler_id, ASLC, 4);
763
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100764 header->asl_compiler_revision = asl_revision;
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200765 header->length = sizeof(struct acpi_vfct);
Marc Jones93a51762018-08-22 18:57:24 -0600766 header->revision = get_acpi_table_revision(VFCT);
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200767
768 current = acpi_fill_vfct(device, vfct, current);
769
770 /* (Re)calculate length and checksum. */
771 header->length = current - (unsigned long)vfct;
772 header->checksum = acpi_checksum((void *)vfct, header->length);
773}
774
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +0200775void acpi_create_ipmi(struct device *device,
776 struct acpi_spmi *spmi,
777 const u16 ipmi_revision,
778 const acpi_addr_t *addr,
779 const enum acpi_ipmi_interface_type type,
780 const s8 gpe_interrupt,
781 const u32 apic_interrupt,
782 const u32 uid)
783{
784 acpi_header_t *header = &(spmi->header);
785 memset((void *)spmi, 0, sizeof(struct acpi_spmi));
786
787 /* Fill out header fields. */
788 memcpy(header->signature, "SPMI", 4);
789 memcpy(header->oem_id, OEM_ID, 6);
790 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
791 memcpy(header->asl_compiler_id, ASLC, 4);
792
793 header->asl_compiler_revision = asl_revision;
794 header->length = sizeof(struct acpi_spmi);
795 header->revision = get_acpi_table_revision(SPMI);
796
797 spmi->reserved = 1;
798
799 if (device->path.type == DEVICE_PATH_PCI) {
800 spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG;
801 spmi->pci_bus = device->bus->secondary;
802 spmi->pci_device = device->path.pci.devfn >> 3;
803 spmi->pci_function = device->path.pci.devfn & 0x7;
804 } else if (type != IPMI_INTERFACE_SSIF) {
805 memcpy(spmi->uid, &uid, sizeof(spmi->uid));
806 }
807
808 spmi->base_address = *addr;
809 spmi->specification_revision = ipmi_revision;
810
811 spmi->interface_type = type;
812
813 if (gpe_interrupt >= 0 && gpe_interrupt < 32) {
814 spmi->gpe = gpe_interrupt;
815 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_SCI;
816 }
817 if (apic_interrupt > 0) {
818 spmi->global_system_interrupt = apic_interrupt;
819 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_APIC;
820 }
821
822 /* Calculate checksum. */
823 header->checksum = acpi_checksum((void *)spmi, header->length);
824}
825
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500826void acpi_create_ivrs(acpi_ivrs_t *ivrs,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700827 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
828 unsigned long current))
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500829{
830 acpi_header_t *header = &(ivrs->header);
831 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
832
833 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
834
John Zhao2ba303e2019-05-28 16:48:14 -0700835 if (!header)
836 return;
837
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500838 /* Fill out header fields. */
839 memcpy(header->signature, "IVRS", 4);
840 memcpy(header->oem_id, OEM_ID, 6);
841 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
842 memcpy(header->asl_compiler_id, ASLC, 4);
843
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100844 header->asl_compiler_revision = asl_revision;
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500845 header->length = sizeof(acpi_ivrs_t);
Marc Jones93a51762018-08-22 18:57:24 -0600846 header->revision = get_acpi_table_revision(IVRS);
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500847
848 current = acpi_fill_ivrs(ivrs, current);
849
850 /* (Re)calculate length and checksum. */
851 header->length = current - (unsigned long)ivrs;
852 header->checksum = acpi_checksum((void *)ivrs, header->length);
853}
854
Elyes HAOUAS9dd89cd2018-05-04 17:56:47 +0200855unsigned long acpi_write_hpet(struct device *device, unsigned long current,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700856 acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200857{
858 acpi_hpet_t *hpet;
859
860 /*
861 * We explicitly add these tables later on:
862 */
863 printk(BIOS_DEBUG, "ACPI: * HPET\n");
864
865 hpet = (acpi_hpet_t *) current;
866 current += sizeof(acpi_hpet_t);
867 current = ALIGN(current, 16);
868 acpi_create_hpet(hpet);
869 acpi_add_table(rsdp, hpet);
870
871 return current;
872}
873
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800874void acpi_create_dbg2(acpi_dbg2_header_t *dbg2,
875 int port_type, int port_subtype,
876 acpi_addr_t *address, uint32_t address_size,
877 const char *device_path)
878{
879 uintptr_t current;
880 acpi_dbg2_device_t *device;
881 uint32_t *dbg2_addr_size;
882 acpi_header_t *header;
883 size_t path_len;
884 const char *path;
885 char *namespace;
886
887 /* Fill out header fields. */
888 current = (uintptr_t)dbg2;
889 memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
890 header = &(dbg2->header);
John Zhao2ba303e2019-05-28 16:48:14 -0700891
892 if (!header)
893 return;
894
Marc Jones93a51762018-08-22 18:57:24 -0600895 header->revision = get_acpi_table_revision(DBG2);
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800896 memcpy(header->signature, "DBG2", 4);
897 memcpy(header->oem_id, OEM_ID, 6);
898 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
899 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100900 header->asl_compiler_revision = asl_revision;
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800901
902 /* One debug device defined */
903 dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
904 dbg2->devices_count = 1;
905 current += sizeof(acpi_dbg2_header_t);
906
907 /* Device comes after the header */
908 device = (acpi_dbg2_device_t *)current;
909 memset(device, 0, sizeof(acpi_dbg2_device_t));
910 current += sizeof(acpi_dbg2_device_t);
911
912 device->revision = 0;
913 device->address_count = 1;
914 device->port_type = port_type;
915 device->port_subtype = port_subtype;
916
917 /* Base Address comes after device structure */
918 memcpy((void *)current, address, sizeof(acpi_addr_t));
919 device->base_address_offset = current - (uintptr_t)device;
920 current += sizeof(acpi_addr_t);
921
922 /* Address Size comes after address structure */
923 dbg2_addr_size = (uint32_t *)current;
924 device->address_size_offset = current - (uintptr_t)device;
925 *dbg2_addr_size = address_size;
926 current += sizeof(uint32_t);
927
928 /* Namespace string comes last, use '.' if not provided */
929 path = device_path ? : ".";
930 /* Namespace string length includes NULL terminator */
931 path_len = strlen(path) + 1;
932 namespace = (char *)current;
933 device->namespace_string_length = path_len;
934 device->namespace_string_offset = current - (uintptr_t)device;
935 strncpy(namespace, path, path_len);
936 current += path_len;
937
938 /* Update structure lengths and checksum */
939 device->length = current - (uintptr_t)device;
940 header->length = current - (uintptr_t)dbg2;
941 header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
942}
943
944unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
945 struct device *dev, uint8_t access_size)
946{
947 acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
948 struct resource *res;
949 acpi_addr_t address;
950
951 if (!dev) {
952 printk(BIOS_ERR, "%s: Device not found\n", __func__);
953 return current;
954 }
Mario Scheithauerf1eb0ea2017-11-21 13:52:53 +0100955 if (!dev->enabled) {
956 printk(BIOS_INFO, "%s: Device not enabled\n", __func__);
957 return current;
958 }
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800959 res = find_resource(dev, PCI_BASE_ADDRESS_0);
960 if (!res) {
961 printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
962 __func__, dev_path(dev));
963 return current;
964 }
965
966 memset(&address, 0, sizeof(address));
967 if (res->flags & IORESOURCE_IO)
968 address.space_id = ACPI_ADDRESS_SPACE_IO;
969 else if (res->flags & IORESOURCE_MEM)
970 address.space_id = ACPI_ADDRESS_SPACE_MEMORY;
971 else {
972 printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
973 return current;
974 }
975
976 address.addrl = (uint32_t)res->base;
977 address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff);
978 address.access_size = access_size;
979
980 acpi_create_dbg2(dbg2,
981 ACPI_DBG2_PORT_SERIAL,
982 ACPI_DBG2_PORT_SERIAL_16550,
983 &address, res->size,
984 acpi_device_path(dev));
985
986 if (dbg2->header.length) {
987 current += dbg2->header.length;
988 current = acpi_align_current(current);
989 acpi_add_table(rsdp, dbg2);
990 }
991
992 return current;
993}
994
Stefan Reinauer777224c2005-01-19 14:06:41 +0000995void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000996{
Uwe Hermann622824c2010-11-19 15:14:42 +0000997 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000998
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000999 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001000 facs->length = sizeof(acpi_facs_t);
1001 facs->hardware_signature = 0;
1002 facs->firmware_waking_vector = 0;
1003 facs->global_lock = 0;
1004 facs->flags = 0;
1005 facs->x_firmware_waking_vector_l = 0;
1006 facs->x_firmware_waking_vector_h = 0;
Marc Jones93a51762018-08-22 18:57:24 -06001007 facs->version = get_acpi_table_revision(FACS);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001008}
Stefan Reinauer777224c2005-01-19 14:06:41 +00001009
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001010static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001011{
Uwe Hermann622824c2010-11-19 15:14:42 +00001012 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001013
John Zhao2ba303e2019-05-28 16:48:14 -07001014 if (!header)
1015 return;
1016
Uwe Hermann622824c2010-11-19 15:14:42 +00001017 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001018 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001019 memcpy(header->oem_id, oem_id, 6);
1020 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +00001021 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001022
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001023 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +00001024 header->length = sizeof(acpi_rsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001025 header->revision = get_acpi_table_revision(RSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001026
Uwe Hermann622824c2010-11-19 15:14:42 +00001027 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +00001028
Uwe Hermann622824c2010-11-19 15:14:42 +00001029 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001030 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001031}
1032
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001033static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001034{
Uwe Hermann622824c2010-11-19 15:14:42 +00001035 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001036
John Zhao2ba303e2019-05-28 16:48:14 -07001037 if (!header)
1038 return;
1039
Uwe Hermann622824c2010-11-19 15:14:42 +00001040 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001041 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001042 memcpy(header->oem_id, oem_id, 6);
1043 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001044 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001045
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001046 header->asl_compiler_revision = asl_revision;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001047 header->length = sizeof(acpi_xsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001048 header->revision = get_acpi_table_revision(XSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001049
Uwe Hermann622824c2010-11-19 15:14:42 +00001050 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001051
Uwe Hermann622824c2010-11-19 15:14:42 +00001052 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001053 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
1054}
1055
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001056static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
1057 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +00001058{
Stefan Reinauerd18faac2009-11-05 18:06:43 +00001059 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +00001060
Stefan Reinauer688b3852004-01-28 16:56:14 +00001061 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001062 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +00001063
1064 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -07001065 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +00001066
1067 /*
1068 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
1069 *
1070 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
1071 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
1072 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001073 */
1074 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001075 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001076 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -07001077 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Marc Jones93a51762018-08-22 18:57:24 -06001078 rsdp->revision = get_acpi_table_revision(RSDP);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001079 }
Uwe Hermann622824c2010-11-19 15:14:42 +00001080
1081 /* Calculate checksums. */
1082 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
1083 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001084}
1085
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001086unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1087 acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
zbaocaf494c82012-04-13 13:57:14 +08001088{
1089 acpi_header_t *header = &(hest->header);
1090 acpi_hest_hen_t *hen;
1091 void *pos;
1092 u16 len;
1093
1094 pos = esd;
1095 memset(pos, 0, sizeof(acpi_hest_esd_t));
1096 len = 0;
1097 esd->type = type; /* MCE */
1098 esd->source_id = hest->error_source_count;
1099 esd->flags = 0; /* FIRMWARE_FIRST */
1100 esd->enabled = 1;
1101 esd->prealloc_erecords = 1;
1102 esd->max_section_per_record = 0x1;
1103
1104 len += sizeof(acpi_hest_esd_t);
1105 pos = esd + 1;
1106
1107 switch (type) {
1108 case 0: /* MCE */
1109 break;
1110 case 1: /* CMC */
1111 hen = (acpi_hest_hen_t *) (pos);
1112 memset(pos, 0, sizeof(acpi_hest_hen_t));
1113 hen->type = 3; /* SCI? */
1114 hen->length = sizeof(acpi_hest_hen_t);
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001115 hen->conf_we = 0; /* Configuration Write Enable. */
zbaocaf494c82012-04-13 13:57:14 +08001116 hen->poll_interval = 0;
1117 hen->vector = 0;
1118 hen->sw2poll_threshold_val = 0;
1119 hen->sw2poll_threshold_win = 0;
1120 hen->error_threshold_val = 0;
1121 hen->error_threshold_win = 0;
1122 len += sizeof(acpi_hest_hen_t);
1123 pos = hen + 1;
1124 break;
1125 case 2: /* NMI */
1126 case 6: /* AER Root Port */
1127 case 7: /* AER Endpoint */
1128 case 8: /* AER Bridge */
1129 case 9: /* Generic Hardware Error Source. */
1130 /* TODO: */
1131 break;
1132 default:
1133 printk(BIOS_DEBUG, "Invalid type of Error Source.");
1134 break;
1135 }
Lee Leahy024b13d2017-03-16 13:41:11 -07001136 hest->error_source_count++;
zbaocaf494c82012-04-13 13:57:14 +08001137
1138 memcpy(pos, data, data_len);
1139 len += data_len;
John Zhao2ba303e2019-05-28 16:48:14 -07001140 if (header)
1141 header->length += len;
zbaocaf494c82012-04-13 13:57:14 +08001142
1143 return len;
1144}
1145
1146/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +01001147void acpi_write_hest(acpi_hest_t *hest,
1148 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +08001149{
1150 acpi_header_t *header = &(hest->header);
1151
1152 memset(hest, 0, sizeof(acpi_hest_t));
1153
John Zhao2ba303e2019-05-28 16:48:14 -07001154 if (!header)
1155 return;
1156
zbaocaf494c82012-04-13 13:57:14 +08001157 memcpy(header->signature, "HEST", 4);
1158 memcpy(header->oem_id, OEM_ID, 6);
1159 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1160 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001161 header->asl_compiler_revision = asl_revision;
zbaocaf494c82012-04-13 13:57:14 +08001162 header->length += sizeof(acpi_hest_t);
Marc Jones93a51762018-08-22 18:57:24 -06001163 header->revision = get_acpi_table_revision(HEST);
zbaocaf494c82012-04-13 13:57:14 +08001164
1165 acpi_fill_hest(hest);
1166
1167 /* Calculate checksums. */
1168 header->checksum = acpi_checksum((void *)hest, header->length);
1169}
1170
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001171/* ACPI 3.0b */
1172void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length)
1173{
1174 acpi_header_t *header = &(bert->header);
1175
1176 memset(bert, 0, sizeof(acpi_bert_t));
1177
John Zhao2ba303e2019-05-28 16:48:14 -07001178 if (!header)
1179 return;
1180
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001181 memcpy(header->signature, "BERT", 4);
1182 memcpy(header->oem_id, OEM_ID, 6);
1183 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1184 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001185 header->asl_compiler_revision = asl_revision;
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001186 header->length += sizeof(acpi_bert_t);
1187 header->revision = get_acpi_table_revision(BERT);
1188
1189 bert->error_region = region;
1190 bert->region_length = length;
1191
1192 /* Calculate checksums. */
1193 header->checksum = acpi_checksum((void *)bert, header->length);
1194}
1195
Julius Wernercd49cce2019-03-05 16:53:33 -08001196#if CONFIG(COMMON_FADT)
Lee Leahy024b13d2017-03-16 13:41:11 -07001197void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001198{
1199 acpi_header_t *header = &(fadt->header);
1200
1201 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
John Zhao2ba303e2019-05-28 16:48:14 -07001202
1203 if (!header)
1204 return;
1205
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001206 memcpy(header->signature, "FACP", 4);
1207 header->length = sizeof(acpi_fadt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001208 header->revision = get_acpi_table_revision(FADT);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001209 memcpy(header->oem_id, OEM_ID, 6);
1210 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1211 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +01001212 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001213
1214 fadt->firmware_ctrl = (unsigned long) facs;
1215 fadt->dsdt = (unsigned long) dsdt;
1216
1217 fadt->x_firmware_ctl_l = (unsigned long)facs;
1218 fadt->x_firmware_ctl_h = 0;
1219 fadt->x_dsdt_l = (unsigned long)dsdt;
1220 fadt->x_dsdt_h = 0;
1221
Julius Wernercd49cce2019-03-05 16:53:33 -08001222 if (CONFIG(SYSTEM_TYPE_CONVERTIBLE) ||
1223 CONFIG(SYSTEM_TYPE_LAPTOP))
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001224 fadt->preferred_pm_profile = PM_MOBILE;
Julius Wernercd49cce2019-03-05 16:53:33 -08001225 else if (CONFIG(SYSTEM_TYPE_DETACHABLE) ||
1226 CONFIG(SYSTEM_TYPE_TABLET))
Duncan Lauriefa9c6f12019-02-07 11:30:06 -08001227 fadt->preferred_pm_profile = PM_TABLET;
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001228 else
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001229 fadt->preferred_pm_profile = PM_DESKTOP;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001230
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +02001231 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001232
1233 header->checksum =
1234 acpi_checksum((void *) fadt, header->length);
1235}
1236#endif
1237
Aaron Durbin64031672018-04-21 14:45:32 -06001238unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001239{
1240 return 0;
1241}
1242
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001243unsigned long write_acpi_tables(unsigned long start)
1244{
1245 unsigned long current;
1246 acpi_rsdp_t *rsdp;
1247 acpi_rsdt_t *rsdt;
1248 acpi_xsdt_t *xsdt;
1249 acpi_fadt_t *fadt;
1250 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001251 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001252 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001253 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001254 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001255 acpi_tcpa_t *tcpa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001256 acpi_tpm2_t *tpm2;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001257 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +11001258 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001259 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001260 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001261 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001262
1263 current = start;
1264
1265 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -06001266 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001267
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001268 fw = fw_cfg_acpi_tables(current);
1269 if (fw)
1270 return fw;
1271
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +02001272 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001273 CONFIG_CBFS_PREFIX "/dsdt.aml",
1274 CBFS_TYPE_RAW, &dsdt_size);
1275 if (!dsdt_file) {
1276 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
1277 return current;
1278 }
1279
1280 if (dsdt_file->length > dsdt_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001281 || dsdt_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001282 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
1283 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
1284 return current;
1285 }
1286
Aaron Durbin899d13d2015-05-15 23:39:23 -05001287 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001288 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001289 if (slic_file
1290 && (slic_file->length > slic_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001291 || slic_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001292 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001293 slic_file = 0;
1294 }
1295
1296 if (slic_file) {
1297 memcpy(oem_id, slic_file->oem_id, 6);
1298 memcpy(oem_table_id, slic_file->oem_table_id, 8);
1299 } else {
1300 memcpy(oem_id, OEM_ID, 6);
1301 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
1302 }
1303
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001304 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
1305
1306 /* We need at least an RSDP and an RSDT Table */
1307 rsdp = (acpi_rsdp_t *) current;
1308 current += sizeof(acpi_rsdp_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001309 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001310 rsdt = (acpi_rsdt_t *) current;
1311 current += sizeof(acpi_rsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001312 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001313 xsdt = (acpi_xsdt_t *) current;
1314 current += sizeof(acpi_xsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001315 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001316
1317 /* clear all table memory */
1318 memset((void *) start, 0, current - start);
1319
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001320 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
1321 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
1322 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001323
1324 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Patrick Georgi133108a2015-08-08 23:20:58 +02001325 current = (ALIGN(current, 64));
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001326 facs = (acpi_facs_t *) current;
1327 current += sizeof(acpi_facs_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001328 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001329 acpi_create_facs(facs);
1330
1331 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
1332 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001333 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001334 if (dsdt->length >= sizeof(acpi_header_t)) {
1335 current += sizeof(acpi_header_t);
1336
1337 acpigen_set_current((char *) current);
1338 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001339 if (dev->ops && dev->ops->acpi_inject_dsdt_generator)
Alexander Couzensa90dad12015-04-12 21:49:46 +02001340 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001341 current = (unsigned long) acpigen_get_current();
1342 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001343 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001344 dsdt->length - sizeof(acpi_header_t));
1345 current += dsdt->length - sizeof(acpi_header_t);
1346
1347 /* (Re)calculate length and checksum. */
1348 dsdt->length = current - (unsigned long)dsdt;
1349 dsdt->checksum = 0;
1350 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
1351 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001352
Aaron Durbin07a1b282015-12-10 17:07:38 -06001353 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001354
1355 printk(BIOS_DEBUG, "ACPI: * FADT\n");
1356 fadt = (acpi_fadt_t *) current;
1357 current += sizeof(acpi_fadt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001358 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001359
1360 acpi_create_fadt(fadt, facs, dsdt);
1361 acpi_add_table(rsdp, fadt);
1362
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001363 if (slic_file) {
1364 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
1365 slic = (acpi_header_t *)current;
1366 memcpy(slic, slic_file, slic_file->length);
1367 current += slic_file->length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001368 current = acpi_align_current(current);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001369 acpi_add_table(rsdp, slic);
1370 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001371
1372 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1373 ssdt = (acpi_header_t *)current;
1374 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001375 if (ssdt->length > sizeof(acpi_header_t)) {
1376 current += ssdt->length;
1377 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001378 current = acpi_align_current(current);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001379 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001380
1381 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
1382 mcfg = (acpi_mcfg_t *) current;
1383 acpi_create_mcfg(mcfg);
1384 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
1385 current += mcfg->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001386 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001387 acpi_add_table(rsdp, mcfg);
1388 }
1389
Julius Wernercd49cce2019-03-05 16:53:33 -08001390 if (CONFIG(TPM1)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001391 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
1392 tcpa = (acpi_tcpa_t *) current;
1393 acpi_create_tcpa(tcpa);
1394 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
1395 current += tcpa->header.length;
1396 current = acpi_align_current(current);
1397 acpi_add_table(rsdp, tcpa);
1398 }
1399 }
1400
Julius Wernercd49cce2019-03-05 16:53:33 -08001401 if (CONFIG(TPM2)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001402 printk(BIOS_DEBUG, "ACPI: * TPM2\n");
1403 tpm2 = (acpi_tpm2_t *) current;
1404 acpi_create_tpm2(tpm2);
1405 if (tpm2->header.length >= sizeof(acpi_tpm2_t)) {
1406 current += tpm2->header.length;
1407 current = acpi_align_current(current);
1408 acpi_add_table(rsdp, tpm2);
1409 }
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001410 }
1411
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001412 printk(BIOS_DEBUG, "ACPI: * MADT\n");
1413
1414 madt = (acpi_madt_t *) current;
1415 acpi_create_madt(madt);
1416 if (madt->header.length > sizeof(acpi_madt_t)) {
Lee Leahy024b13d2017-03-16 13:41:11 -07001417 current += madt->header.length;
1418 acpi_add_table(rsdp, madt);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001419 }
Aaron Durbin07a1b282015-12-10 17:07:38 -06001420 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001421
1422 printk(BIOS_DEBUG, "current = %lx\n", current);
1423
1424 for (dev = all_devices; dev; dev = dev->next) {
1425 if (dev->ops && dev->ops->write_acpi_tables) {
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001426 current = dev->ops->write_acpi_tables(dev, current,
1427 rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001428 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001429 }
1430 }
1431
1432 printk(BIOS_INFO, "ACPI: done.\n");
1433 return current;
1434}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001435
Rudolf Marek33cafe52009-04-13 18:07:02 +00001436static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1437{
1438 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1439 return NULL;
1440
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001441 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001442
1443 if (acpi_checksum((void *)rsdp, 20) != 0)
1444 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001445 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001446
1447 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1448 rsdp->length) != 0))
1449 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001450 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001451
1452 return rsdp;
1453}
1454
Rudolf Marek33cafe52009-04-13 18:07:02 +00001455void *acpi_find_wakeup_vector(void)
1456{
1457 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001458 acpi_rsdt_t *rsdt;
1459 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001460 acpi_fadt_t *fadt = NULL;
Kyösti Mälkki072d436b2016-06-17 08:44:40 +03001461 acpi_rsdp_t *rsdp = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001462 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001463 int i;
1464
Rudolf Marek33cafe52009-04-13 18:07:02 +00001465 if (!acpi_is_wakeup())
1466 return NULL;
1467
Uwe Hermann622824c2010-11-19 15:14:42 +00001468 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001469
Uwe Hermann622824c2010-11-19 15:14:42 +00001470 /* Find RSDP. */
1471 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
Lee Leahy0b5678f2017-03-16 16:01:40 -07001472 rsdp = valid_rsdp((acpi_rsdp_t *)p);
1473 if (rsdp)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001474 break;
1475 }
1476
Angel Pons98a68ad2018-11-04 12:25:25 +01001477 if (rsdp == NULL) {
1478 printk(BIOS_ALERT,
1479 "No RSDP found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001480 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001481 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001482
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001483 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001484 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001485
Uwe Hermann622824c2010-11-19 15:14:42 +00001486 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001487 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001488
Uwe Hermann622824c2010-11-19 15:14:42 +00001489 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001490 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001491 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001492 break;
1493 fadt = NULL;
1494 }
1495
Angel Pons98a68ad2018-11-04 12:25:25 +01001496 if (fadt == NULL) {
1497 printk(BIOS_ALERT,
1498 "No FADT found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001499 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001500 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001501
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001502 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001503 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001504
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001505 if (facs == NULL) {
Angel Pons98a68ad2018-11-04 12:25:25 +01001506 printk(BIOS_ALERT,
1507 "No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001508 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001509 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001510
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001511 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001512 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001513 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001514
Rudolf Marek33cafe52009-04-13 18:07:02 +00001515 return wake_vec;
1516}
1517
Aaron Durbin64031672018-04-21 14:45:32 -06001518__weak int acpi_get_gpe(int gpe)
Duncan Laurie1f6e6812016-09-19 12:04:19 -07001519{
1520 return -1; /* implemented by SOC */
1521}
Marc Jones93a51762018-08-22 18:57:24 -06001522
1523int get_acpi_table_revision(enum acpi_tables table)
1524{
1525 switch (table) {
1526 case FADT:
1527 return ACPI_FADT_REV_ACPI_3_0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001528 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 -06001529 return 2;
Marc Jones93a51762018-08-22 18:57:24 -06001530 case MCFG:
1531 return 1;
1532 case TCPA:
1533 return 2;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001534 case TPM2:
1535 return 4;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001536 case SSDT: /* ACPI 3.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001537 return 2;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001538 case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 upto 6.3: 3 */
Marc Jones93a51762018-08-22 18:57:24 -06001539 return 1; /* TODO Should probably be upgraded to 2 */
1540 case DMAR:
1541 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001542 case SLIT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001543 return 1;
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +02001544 case SPMI: /* IMPI 2.0 */
1545 return 5;
Marc Jones93a51762018-08-22 18:57:24 -06001546 case HPET: /* Currently 1. Table added in ACPI 2.0. */
1547 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001548 case VFCT: /* ACPI 2.0/3.0/4.0: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001549 return 1;
1550 case IVRS:
1551 return IVRS_FORMAT_FIXED;
1552 case DBG2:
1553 return 0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001554 case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001555 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001556 case RSDT: /* ACPI 1.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001557 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001558 case XSDT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001559 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001560 case RSDP: /* ACPI 2.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001561 return 2;
1562 case HEST:
1563 return 1;
1564 case NHLT:
1565 return 5;
Marshall Dawson44705c62018-09-04 13:47:15 -06001566 case BERT:
1567 return 1;
Marc Jones93a51762018-08-22 18:57:24 -06001568 default:
1569 return -1;
1570 }
1571 return -1;
1572}