blob: f08a401a6e4734d66dc24470575dde953c2ee3ad [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
Uwe Hermann622824c2010-11-19 15:14:42 +0000221 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000222 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000223 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000224 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000225 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000226
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100227 header->asl_compiler_revision = asl_revision;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000228 header->length = sizeof(acpi_madt_t);
Marc Jones93a51762018-08-22 18:57:24 -0600229 header->revision = get_acpi_table_revision(MADT);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000230
Uwe Hermann622824c2010-11-19 15:14:42 +0000231 madt->lapic_addr = LOCAL_APIC_ADDR;
232 madt->flags = 0x1; /* PCAT_COMPAT */
Stefan Reinauer06feb882004-02-03 16:11:35 +0000233
Stefan Reinauerf622d592005-11-26 16:56:05 +0000234 current = acpi_fill_madt(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000235
Uwe Hermann622824c2010-11-19 15:14:42 +0000236 /* (Re)calculate length and checksum. */
237 header->length = current - (unsigned long)madt;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000238
Uwe Hermann622824c2010-11-19 15:14:42 +0000239 header->checksum = acpi_checksum((void *)madt, header->length);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000240}
241
Uwe Hermann622824c2010-11-19 15:14:42 +0000242/* MCFG is defined in the PCI Firmware Specification 3.0. */
Rudolf Mareke6409f22007-11-03 12:50:26 +0000243void acpi_create_mcfg(acpi_mcfg_t *mcfg)
244{
Uwe Hermann622824c2010-11-19 15:14:42 +0000245 acpi_header_t *header = &(mcfg->header);
246 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000247
Rudolf Mareke6409f22007-11-03 12:50:26 +0000248 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000249
Uwe Hermann622824c2010-11-19 15:14:42 +0000250 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000251 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000252 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000253 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000254 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000255
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100256 header->asl_compiler_revision = asl_revision;
Rudolf Mareke6409f22007-11-03 12:50:26 +0000257 header->length = sizeof(acpi_mcfg_t);
Marc Jones93a51762018-08-22 18:57:24 -0600258 header->revision = get_acpi_table_revision(MCFG);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000259
260 current = acpi_fill_mcfg(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000261
Uwe Hermann622824c2010-11-19 15:14:42 +0000262 /* (Re)calculate length and checksum. */
263 header->length = current - (unsigned long)mcfg;
264 header->checksum = acpi_checksum((void *)mcfg, header->length);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000265}
266
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200267static void *get_tcpa_log(u32 *size)
268{
269 const struct cbmem_entry *ce;
270 const u32 tcpa_default_log_len = 0x10000;
271 void *lasa;
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200272 ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200273 if (ce) {
274 lasa = cbmem_entry_start(ce);
275 *size = cbmem_entry_size(ce);
276 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
277 return lasa;
278 }
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200279 lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200280 if (!lasa) {
281 printk(BIOS_ERR, "TCPA log creation failed\n");
282 return NULL;
283 }
284
285 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
Lee Leahy024b13d2017-03-16 13:41:11 -0700286 memset(lasa, 0, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200287
288 *size = tcpa_default_log_len;
289 return lasa;
290}
291
292static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
293{
294 acpi_header_t *header = &(tcpa->header);
295 u32 tcpa_log_len;
296 void *lasa;
297
298 memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
299
300 lasa = get_tcpa_log(&tcpa_log_len);
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700301 if (!lasa)
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200302 return;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200303
304 /* Fill out header fields. */
305 memcpy(header->signature, "TCPA", 4);
306 memcpy(header->oem_id, OEM_ID, 6);
307 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
308 memcpy(header->asl_compiler_id, ASLC, 4);
309
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100310 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200311 header->length = sizeof(acpi_tcpa_t);
Marc Jones93a51762018-08-22 18:57:24 -0600312 header->revision = get_acpi_table_revision(TCPA);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200313
314 tcpa->platform_class = 0;
315 tcpa->laml = tcpa_log_len;
Stefan Reinauerdefee172015-06-18 01:11:19 -0700316 tcpa->lasa = (uintptr_t) lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200317
318 /* Calculate checksum. */
319 header->checksum = acpi_checksum((void *)tcpa, header->length);
320}
321
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100322static void *get_tpm2_log(u32 *size)
323{
324 const struct cbmem_entry *ce;
325 const u32 tpm2_default_log_len = 0x10000;
326 void *lasa;
327 ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG);
328 if (ce) {
329 lasa = cbmem_entry_start(ce);
330 *size = cbmem_entry_size(ce);
331 printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa);
332 return lasa;
333 }
334 lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len);
335 if (!lasa) {
336 printk(BIOS_ERR, "TPM2 log creation failed\n");
337 return NULL;
338 }
339
340 printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa);
341 memset(lasa, 0, tpm2_default_log_len);
342
343 *size = tpm2_default_log_len;
344 return lasa;
345}
346
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200347static void acpi_create_tpm2(acpi_tpm2_t *tpm2)
348{
349 acpi_header_t *header = &(tpm2->header);
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100350 u32 tpm2_log_len;
351 void *lasa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200352
353 memset((void *)tpm2, 0, sizeof(acpi_tpm2_t));
354
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100355 /*
356 * Some payloads like SeaBIOS depend on log area to use TPM2.
357 * Get the memory size and address of TPM2 log area or initialize it.
358 */
359 lasa = get_tpm2_log(&tpm2_log_len);
360 if (!lasa)
361 tpm2_log_len = 0;
362
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200363 /* Fill out header fields. */
364 memcpy(header->signature, "TPM2", 4);
365 memcpy(header->oem_id, OEM_ID, 6);
366 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
367 memcpy(header->asl_compiler_id, ASLC, 4);
368
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100369 header->asl_compiler_revision = asl_revision;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200370 header->length = sizeof(acpi_tpm2_t);
371 header->revision = get_acpi_table_revision(TPM2);
372
373 /* Hard to detect for coreboot. Just set it to 0 */
374 tpm2->platform_class = 0;
375 /* Must be set to 0 for TIS interface support */
376 tpm2->control_area = 0;
377 /* coreboot only supports the TIS interface driver. */
378 tpm2->start_method = 6;
379 memset(tpm2->msp, 0, sizeof(tpm2->msp));
380
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100381 /* Fill the log area size and start address fields. */
382 tpm2->laml = tpm2_log_len;
383 tpm2->lasa = (uintptr_t) lasa;
384
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200385 /* Calculate checksum. */
386 header->checksum = acpi_checksum((void *)tpm2, header->length);
387}
388
Duncan Laurie37319032016-05-26 12:47:05 -0700389static void acpi_ssdt_write_cbtable(void)
390{
391 const struct cbmem_entry *cbtable;
392 uintptr_t base;
393 uint32_t size;
394
395 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
396 if (!cbtable)
397 return;
398 base = (uintptr_t)cbmem_entry_start(cbtable);
399 size = cbmem_entry_size(cbtable);
400
401 acpigen_write_device("CTBL");
402 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
403 acpigen_write_name_integer("_UID", 0);
David Wu5dff3962018-03-21 16:48:53 +0800404 acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON);
Duncan Laurie37319032016-05-26 12:47:05 -0700405 acpigen_write_name("_CRS");
406 acpigen_write_resourcetemplate_header();
407 acpigen_write_mem32fixed(0, base, size);
408 acpigen_write_resourcetemplate_footer();
409 acpigen_pop_len();
410}
411
Myles Watson3fe6b702009-10-09 20:13:43 +0000412void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000413{
Uwe Hermann622824c2010-11-19 15:14:42 +0000414 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
415
Rudolf Marek293b5f52009-02-01 18:35:15 +0000416 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000417
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000418 memcpy(&ssdt->signature, "SSDT", 4);
Marc Jones93a51762018-08-22 18:57:24 -0600419 ssdt->revision = get_acpi_table_revision(SSDT);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000420 memcpy(&ssdt->oem_id, OEM_ID, 6);
421 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
422 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000423 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +0100424 ssdt->asl_compiler_revision = asl_revision;
Rudolf Marek293b5f52009-02-01 18:35:15 +0000425 ssdt->length = sizeof(acpi_header_t);
426
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000427 acpigen_set_current((char *) current);
Duncan Laurie37319032016-05-26 12:47:05 -0700428
429 /* Write object to declare coreboot tables */
430 acpi_ssdt_write_cbtable();
431
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200432 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100433 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200434 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700435 if (dev->ops && dev->ops->acpi_fill_ssdt_generator)
Alexander Couzens5eea4582015-04-12 22:18:55 +0200436 dev->ops->acpi_fill_ssdt_generator(dev);
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200437 current = (unsigned long) acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200438 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000439
Uwe Hermann622824c2010-11-19 15:14:42 +0000440 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000441 ssdt->length = current - (unsigned long)ssdt;
442 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
443}
444
Stefan Reinauerf622d592005-11-26 16:56:05 +0000445int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
446{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000447 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000448
Uwe Hermann622824c2010-11-19 15:14:42 +0000449 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
450 lapic->length = sizeof(acpi_srat_lapic_t);
451 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
452 lapic->proximity_domain_7_0 = node;
453 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
454 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000455
Uwe Hermann622824c2010-11-19 15:14:42 +0000456 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000457}
458
Uwe Hermann622824c2010-11-19 15:14:42 +0000459int 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 +0300460 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000461{
Uwe Hermann622824c2010-11-19 15:14:42 +0000462 mem->type = 1; /* Memory affinity structure */
463 mem->length = sizeof(acpi_srat_mem_t);
464 mem->base_address_low = (basek << 10);
465 mem->base_address_high = (basek >> (32 - 10));
466 mem->length_low = (sizek << 10);
467 mem->length_high = (sizek >> (32 - 10));
468 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000469 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000470
Uwe Hermann622824c2010-11-19 15:14:42 +0000471 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000472}
473
Uwe Hermann622824c2010-11-19 15:14:42 +0000474/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200475void acpi_create_srat(acpi_srat_t *srat,
476 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000477{
Uwe Hermann622824c2010-11-19 15:14:42 +0000478 acpi_header_t *header = &(srat->header);
479 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000480
Uwe Hermann622824c2010-11-19 15:14:42 +0000481 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000482
Uwe Hermann622824c2010-11-19 15:14:42 +0000483 /* Fill out header fields. */
484 memcpy(header->signature, "SRAT", 4);
485 memcpy(header->oem_id, OEM_ID, 6);
486 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
487 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000488
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100489 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000490 header->length = sizeof(acpi_srat_t);
Marc Jones93a51762018-08-22 18:57:24 -0600491 header->revision = get_acpi_table_revision(SRAT);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000492
Uwe Hermann622824c2010-11-19 15:14:42 +0000493 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000494
Uwe Hermann622824c2010-11-19 15:14:42 +0000495 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000496
Uwe Hermann622824c2010-11-19 15:14:42 +0000497 /* (Re)calculate length and checksum. */
498 header->length = current - (unsigned long)srat;
499 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000500}
501
Nico Hubere561f352015-10-26 11:51:25 +0100502void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Lee Leahy024b13d2017-03-16 13:41:11 -0700503 unsigned long (*acpi_fill_dmar)(unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200504{
505 acpi_header_t *header = &(dmar->header);
506 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
507
508 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
509
510 /* Fill out header fields. */
511 memcpy(header->signature, "DMAR", 4);
512 memcpy(header->oem_id, OEM_ID, 6);
513 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
514 memcpy(header->asl_compiler_id, ASLC, 4);
515
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100516 header->asl_compiler_revision = asl_revision;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200517 header->length = sizeof(acpi_dmar_t);
Marc Jones93a51762018-08-22 18:57:24 -0600518 header->revision = get_acpi_table_revision(DMAR);
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200519
Jacob Laskaf3f654d2016-03-15 21:53:27 -0500520 dmar->host_address_width = cpu_phys_address_size() - 1;
Nico Hubere561f352015-10-26 11:51:25 +0100521 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200522
523 current = acpi_fill_dmar(current);
524
525 /* (Re)calculate length and checksum. */
526 header->length = current - (unsigned long)dmar;
527 header->checksum = acpi_checksum((void *)dmar, header->length);
528}
529
530unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
Matt DeVillier7866d492018-03-29 14:59:57 +0200531 u16 segment, u64 bar)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200532{
533 dmar_entry_t *drhd = (dmar_entry_t *)current;
534 memset(drhd, 0, sizeof(*drhd));
535 drhd->type = DMAR_DRHD;
536 drhd->length = sizeof(*drhd); /* will be fixed up later */
537 drhd->flags = flags;
538 drhd->segment = segment;
539 drhd->bar = bar;
540
541 return drhd->length;
542}
543
Matt DeVillier7866d492018-03-29 14:59:57 +0200544unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
545 u64 bar, u64 limit)
546{
547 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current;
548 memset(rmrr, 0, sizeof(*rmrr));
549 rmrr->type = DMAR_RMRR;
550 rmrr->length = sizeof(*rmrr); /* will be fixed up later */
551 rmrr->segment = segment;
552 rmrr->bar = bar;
553 rmrr->limit = limit;
554
555 return rmrr->length;
556}
557
Werner Zehd4d76952016-07-27 06:56:36 +0200558unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
559 u16 segment)
560{
561 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
562 memset(atsr, 0, sizeof(*atsr));
563 atsr->type = DMAR_ATSR;
564 atsr->length = sizeof(*atsr); /* will be fixed up later */
565 atsr->flags = flags;
566 atsr->segment = segment;
567
568 return atsr->length;
569}
570
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200571void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
572{
573 dmar_entry_t *drhd = (dmar_entry_t *)base;
574 drhd->length = current - base;
575}
576
Matt DeVillier7866d492018-03-29 14:59:57 +0200577void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
578{
579 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)base;
580 rmrr->length = current - base;
581}
582
Werner Zehd4d76952016-07-27 06:56:36 +0200583void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
584{
585 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base;
586 atsr->length = current - base;
587}
588
Matt DeVillier7866d492018-03-29 14:59:57 +0200589static unsigned long acpi_create_dmar_ds(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100590 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200591{
Nico Huber6c4751d2015-10-26 12:03:54 +0100592 /* we don't support longer paths yet */
593 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
594
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200595 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100596 memset(ds, 0, dev_scope_length);
597 ds->type = type;
598 ds->length = dev_scope_length;
599 ds->enumeration = enumeration_id;
600 ds->start_bus = bus;
601 ds->path[0].dev = dev;
602 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200603
604 return ds->length;
605}
606
Matt DeVillier7866d492018-03-29 14:59:57 +0200607unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200608 u8 dev, u8 fn)
609{
Matt DeVillier7866d492018-03-29 14:59:57 +0200610 return acpi_create_dmar_ds(current,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200611 SCOPE_PCI_SUB, 0, bus, dev, fn);
612}
613
Matt DeVillier7866d492018-03-29 14:59:57 +0200614unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus,
Nico Huber6c4751d2015-10-26 12:03:54 +0100615 u8 dev, u8 fn)
616{
Matt DeVillier7866d492018-03-29 14:59:57 +0200617 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100618 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
619}
620
Matt DeVillier7866d492018-03-29 14:59:57 +0200621unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100622 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
623{
Matt DeVillier7866d492018-03-29 14:59:57 +0200624 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100625 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
626}
627
Matt DeVillier7866d492018-03-29 14:59:57 +0200628unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100629 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
630{
Matt DeVillier7866d492018-03-29 14:59:57 +0200631 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100632 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
633}
634
Uwe Hermann622824c2010-11-19 15:14:42 +0000635/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200636void acpi_create_slit(acpi_slit_t *slit,
637 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000638{
Uwe Hermann622824c2010-11-19 15:14:42 +0000639 acpi_header_t *header = &(slit->header);
640 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000641
Uwe Hermann622824c2010-11-19 15:14:42 +0000642 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000643
Uwe Hermann622824c2010-11-19 15:14:42 +0000644 /* Fill out header fields. */
645 memcpy(header->signature, "SLIT", 4);
646 memcpy(header->oem_id, OEM_ID, 6);
647 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
648 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000649
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100650 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000651 header->length = sizeof(acpi_slit_t);
Marc Jones93a51762018-08-22 18:57:24 -0600652 header->revision = get_acpi_table_revision(SLIT);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000653
Uwe Hermann622824c2010-11-19 15:14:42 +0000654 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000655
Uwe Hermann622824c2010-11-19 15:14:42 +0000656 /* (Re)calculate length and checksum. */
657 header->length = current - (unsigned long)slit;
658 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000659}
660
Uwe Hermann622824c2010-11-19 15:14:42 +0000661/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000662void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000663{
Uwe Hermann622824c2010-11-19 15:14:42 +0000664 acpi_header_t *header = &(hpet->header);
665 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000666
Stefan Reinauera7648c22004-01-29 17:31:34 +0000667 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000668
Uwe Hermann622824c2010-11-19 15:14:42 +0000669 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000670 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000671 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000672 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000673 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000674
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100675 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000676 header->length = sizeof(acpi_hpet_t);
Marc Jones93a51762018-08-22 18:57:24 -0600677 header->revision = get_acpi_table_revision(HPET);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000678
Uwe Hermann622824c2010-11-19 15:14:42 +0000679 /* Fill out HPET address. */
680 addr->space_id = 0; /* Memory */
681 addr->bit_width = 64;
682 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200683 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
684 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000685
Lee Leahy024b13d2017-03-16 13:41:11 -0700686 hpet->id = *(unsigned int *)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000687 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200688 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000689
Uwe Hermann622824c2010-11-19 15:14:42 +0000690 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000691}
Uwe Hermann622824c2010-11-19 15:14:42 +0000692
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200693void acpi_create_vfct(struct device *device,
694 struct acpi_vfct *vfct,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700695 unsigned long (*acpi_fill_vfct)(struct device *device,
696 struct acpi_vfct *vfct_struct, unsigned long current))
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200697{
698 acpi_header_t *header = &(vfct->header);
699 unsigned long current = (unsigned long)vfct + sizeof(struct acpi_vfct);
700
701 memset((void *)vfct, 0, sizeof(struct acpi_vfct));
702
703 /* Fill out header fields. */
704 memcpy(header->signature, "VFCT", 4);
705 memcpy(header->oem_id, OEM_ID, 6);
706 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
707 memcpy(header->asl_compiler_id, ASLC, 4);
708
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100709 header->asl_compiler_revision = asl_revision;
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200710 header->length = sizeof(struct acpi_vfct);
Marc Jones93a51762018-08-22 18:57:24 -0600711 header->revision = get_acpi_table_revision(VFCT);
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200712
713 current = acpi_fill_vfct(device, vfct, current);
714
715 /* (Re)calculate length and checksum. */
716 header->length = current - (unsigned long)vfct;
717 header->checksum = acpi_checksum((void *)vfct, header->length);
718}
719
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500720void acpi_create_ivrs(acpi_ivrs_t *ivrs,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700721 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
722 unsigned long current))
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500723{
724 acpi_header_t *header = &(ivrs->header);
725 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
726
727 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
728
729 /* Fill out header fields. */
730 memcpy(header->signature, "IVRS", 4);
731 memcpy(header->oem_id, OEM_ID, 6);
732 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
733 memcpy(header->asl_compiler_id, ASLC, 4);
734
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100735 header->asl_compiler_revision = asl_revision;
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500736 header->length = sizeof(acpi_ivrs_t);
Marc Jones93a51762018-08-22 18:57:24 -0600737 header->revision = get_acpi_table_revision(IVRS);
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500738
739 current = acpi_fill_ivrs(ivrs, current);
740
741 /* (Re)calculate length and checksum. */
742 header->length = current - (unsigned long)ivrs;
743 header->checksum = acpi_checksum((void *)ivrs, header->length);
744}
745
Elyes HAOUAS9dd89cd2018-05-04 17:56:47 +0200746unsigned long acpi_write_hpet(struct device *device, unsigned long current,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700747 acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200748{
749 acpi_hpet_t *hpet;
750
751 /*
752 * We explicitly add these tables later on:
753 */
754 printk(BIOS_DEBUG, "ACPI: * HPET\n");
755
756 hpet = (acpi_hpet_t *) current;
757 current += sizeof(acpi_hpet_t);
758 current = ALIGN(current, 16);
759 acpi_create_hpet(hpet);
760 acpi_add_table(rsdp, hpet);
761
762 return current;
763}
764
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800765void acpi_create_dbg2(acpi_dbg2_header_t *dbg2,
766 int port_type, int port_subtype,
767 acpi_addr_t *address, uint32_t address_size,
768 const char *device_path)
769{
770 uintptr_t current;
771 acpi_dbg2_device_t *device;
772 uint32_t *dbg2_addr_size;
773 acpi_header_t *header;
774 size_t path_len;
775 const char *path;
776 char *namespace;
777
778 /* Fill out header fields. */
779 current = (uintptr_t)dbg2;
780 memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
781 header = &(dbg2->header);
Marc Jones93a51762018-08-22 18:57:24 -0600782 header->revision = get_acpi_table_revision(DBG2);
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800783 memcpy(header->signature, "DBG2", 4);
784 memcpy(header->oem_id, OEM_ID, 6);
785 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
786 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100787 header->asl_compiler_revision = asl_revision;
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800788
789 /* One debug device defined */
790 dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
791 dbg2->devices_count = 1;
792 current += sizeof(acpi_dbg2_header_t);
793
794 /* Device comes after the header */
795 device = (acpi_dbg2_device_t *)current;
796 memset(device, 0, sizeof(acpi_dbg2_device_t));
797 current += sizeof(acpi_dbg2_device_t);
798
799 device->revision = 0;
800 device->address_count = 1;
801 device->port_type = port_type;
802 device->port_subtype = port_subtype;
803
804 /* Base Address comes after device structure */
805 memcpy((void *)current, address, sizeof(acpi_addr_t));
806 device->base_address_offset = current - (uintptr_t)device;
807 current += sizeof(acpi_addr_t);
808
809 /* Address Size comes after address structure */
810 dbg2_addr_size = (uint32_t *)current;
811 device->address_size_offset = current - (uintptr_t)device;
812 *dbg2_addr_size = address_size;
813 current += sizeof(uint32_t);
814
815 /* Namespace string comes last, use '.' if not provided */
816 path = device_path ? : ".";
817 /* Namespace string length includes NULL terminator */
818 path_len = strlen(path) + 1;
819 namespace = (char *)current;
820 device->namespace_string_length = path_len;
821 device->namespace_string_offset = current - (uintptr_t)device;
822 strncpy(namespace, path, path_len);
823 current += path_len;
824
825 /* Update structure lengths and checksum */
826 device->length = current - (uintptr_t)device;
827 header->length = current - (uintptr_t)dbg2;
828 header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
829}
830
831unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
832 struct device *dev, uint8_t access_size)
833{
834 acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
835 struct resource *res;
836 acpi_addr_t address;
837
838 if (!dev) {
839 printk(BIOS_ERR, "%s: Device not found\n", __func__);
840 return current;
841 }
Mario Scheithauerf1eb0ea2017-11-21 13:52:53 +0100842 if (!dev->enabled) {
843 printk(BIOS_INFO, "%s: Device not enabled\n", __func__);
844 return current;
845 }
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800846 res = find_resource(dev, PCI_BASE_ADDRESS_0);
847 if (!res) {
848 printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
849 __func__, dev_path(dev));
850 return current;
851 }
852
853 memset(&address, 0, sizeof(address));
854 if (res->flags & IORESOURCE_IO)
855 address.space_id = ACPI_ADDRESS_SPACE_IO;
856 else if (res->flags & IORESOURCE_MEM)
857 address.space_id = ACPI_ADDRESS_SPACE_MEMORY;
858 else {
859 printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
860 return current;
861 }
862
863 address.addrl = (uint32_t)res->base;
864 address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff);
865 address.access_size = access_size;
866
867 acpi_create_dbg2(dbg2,
868 ACPI_DBG2_PORT_SERIAL,
869 ACPI_DBG2_PORT_SERIAL_16550,
870 &address, res->size,
871 acpi_device_path(dev));
872
873 if (dbg2->header.length) {
874 current += dbg2->header.length;
875 current = acpi_align_current(current);
876 acpi_add_table(rsdp, dbg2);
877 }
878
879 return current;
880}
881
Stefan Reinauer777224c2005-01-19 14:06:41 +0000882void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000883{
Uwe Hermann622824c2010-11-19 15:14:42 +0000884 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000885
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000886 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000887 facs->length = sizeof(acpi_facs_t);
888 facs->hardware_signature = 0;
889 facs->firmware_waking_vector = 0;
890 facs->global_lock = 0;
891 facs->flags = 0;
892 facs->x_firmware_waking_vector_l = 0;
893 facs->x_firmware_waking_vector_h = 0;
Marc Jones93a51762018-08-22 18:57:24 -0600894 facs->version = get_acpi_table_revision(FACS);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000895}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000896
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100897static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000898{
Uwe Hermann622824c2010-11-19 15:14:42 +0000899 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000900
Uwe Hermann622824c2010-11-19 15:14:42 +0000901 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000902 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100903 memcpy(header->oem_id, oem_id, 6);
904 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000905 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000906
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100907 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000908 header->length = sizeof(acpi_rsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -0600909 header->revision = get_acpi_table_revision(RSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000910
Uwe Hermann622824c2010-11-19 15:14:42 +0000911 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000912
Uwe Hermann622824c2010-11-19 15:14:42 +0000913 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000914 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000915}
916
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100917static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000918{
Uwe Hermann622824c2010-11-19 15:14:42 +0000919 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000920
Uwe Hermann622824c2010-11-19 15:14:42 +0000921 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000922 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100923 memcpy(header->oem_id, oem_id, 6);
924 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000925 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000926
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100927 header->asl_compiler_revision = asl_revision;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000928 header->length = sizeof(acpi_xsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -0600929 header->revision = get_acpi_table_revision(XSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000930
Uwe Hermann622824c2010-11-19 15:14:42 +0000931 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000932
Uwe Hermann622824c2010-11-19 15:14:42 +0000933 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000934 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
935}
936
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100937static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
938 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000939{
Stefan Reinauerd18faac2009-11-05 18:06:43 +0000940 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000941
Stefan Reinauer688b3852004-01-28 16:56:14 +0000942 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100943 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +0000944
945 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -0700946 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000947
948 /*
949 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
950 *
951 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
952 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
953 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000954 */
955 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000956 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000957 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -0700958 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Marc Jones93a51762018-08-22 18:57:24 -0600959 rsdp->revision = get_acpi_table_revision(RSDP);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000960 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000961
962 /* Calculate checksums. */
963 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
964 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000965}
966
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700967unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
968 acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
zbaocaf494c82012-04-13 13:57:14 +0800969{
970 acpi_header_t *header = &(hest->header);
971 acpi_hest_hen_t *hen;
972 void *pos;
973 u16 len;
974
975 pos = esd;
976 memset(pos, 0, sizeof(acpi_hest_esd_t));
977 len = 0;
978 esd->type = type; /* MCE */
979 esd->source_id = hest->error_source_count;
980 esd->flags = 0; /* FIRMWARE_FIRST */
981 esd->enabled = 1;
982 esd->prealloc_erecords = 1;
983 esd->max_section_per_record = 0x1;
984
985 len += sizeof(acpi_hest_esd_t);
986 pos = esd + 1;
987
988 switch (type) {
989 case 0: /* MCE */
990 break;
991 case 1: /* CMC */
992 hen = (acpi_hest_hen_t *) (pos);
993 memset(pos, 0, sizeof(acpi_hest_hen_t));
994 hen->type = 3; /* SCI? */
995 hen->length = sizeof(acpi_hest_hen_t);
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700996 hen->conf_we = 0; /* Configuration Write Enable. */
zbaocaf494c82012-04-13 13:57:14 +0800997 hen->poll_interval = 0;
998 hen->vector = 0;
999 hen->sw2poll_threshold_val = 0;
1000 hen->sw2poll_threshold_win = 0;
1001 hen->error_threshold_val = 0;
1002 hen->error_threshold_win = 0;
1003 len += sizeof(acpi_hest_hen_t);
1004 pos = hen + 1;
1005 break;
1006 case 2: /* NMI */
1007 case 6: /* AER Root Port */
1008 case 7: /* AER Endpoint */
1009 case 8: /* AER Bridge */
1010 case 9: /* Generic Hardware Error Source. */
1011 /* TODO: */
1012 break;
1013 default:
1014 printk(BIOS_DEBUG, "Invalid type of Error Source.");
1015 break;
1016 }
Lee Leahy024b13d2017-03-16 13:41:11 -07001017 hest->error_source_count++;
zbaocaf494c82012-04-13 13:57:14 +08001018
1019 memcpy(pos, data, data_len);
1020 len += data_len;
1021 header->length += len;
1022
1023 return len;
1024}
1025
1026/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +01001027void acpi_write_hest(acpi_hest_t *hest,
1028 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +08001029{
1030 acpi_header_t *header = &(hest->header);
1031
1032 memset(hest, 0, sizeof(acpi_hest_t));
1033
1034 memcpy(header->signature, "HEST", 4);
1035 memcpy(header->oem_id, OEM_ID, 6);
1036 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1037 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001038 header->asl_compiler_revision = asl_revision;
zbaocaf494c82012-04-13 13:57:14 +08001039 header->length += sizeof(acpi_hest_t);
Marc Jones93a51762018-08-22 18:57:24 -06001040 header->revision = get_acpi_table_revision(HEST);
zbaocaf494c82012-04-13 13:57:14 +08001041
1042 acpi_fill_hest(hest);
1043
1044 /* Calculate checksums. */
1045 header->checksum = acpi_checksum((void *)hest, header->length);
1046}
1047
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001048/* ACPI 3.0b */
1049void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length)
1050{
1051 acpi_header_t *header = &(bert->header);
1052
1053 memset(bert, 0, sizeof(acpi_bert_t));
1054
1055 memcpy(header->signature, "BERT", 4);
1056 memcpy(header->oem_id, OEM_ID, 6);
1057 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1058 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001059 header->asl_compiler_revision = asl_revision;
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001060 header->length += sizeof(acpi_bert_t);
1061 header->revision = get_acpi_table_revision(BERT);
1062
1063 bert->error_region = region;
1064 bert->region_length = length;
1065
1066 /* Calculate checksums. */
1067 header->checksum = acpi_checksum((void *)bert, header->length);
1068}
1069
Julius Wernercd49cce2019-03-05 16:53:33 -08001070#if CONFIG(COMMON_FADT)
Lee Leahy024b13d2017-03-16 13:41:11 -07001071void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001072{
1073 acpi_header_t *header = &(fadt->header);
1074
1075 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
1076 memcpy(header->signature, "FACP", 4);
1077 header->length = sizeof(acpi_fadt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001078 header->revision = get_acpi_table_revision(FADT);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001079 memcpy(header->oem_id, OEM_ID, 6);
1080 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1081 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +01001082 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001083
1084 fadt->firmware_ctrl = (unsigned long) facs;
1085 fadt->dsdt = (unsigned long) dsdt;
1086
1087 fadt->x_firmware_ctl_l = (unsigned long)facs;
1088 fadt->x_firmware_ctl_h = 0;
1089 fadt->x_dsdt_l = (unsigned long)dsdt;
1090 fadt->x_dsdt_h = 0;
1091
Julius Wernercd49cce2019-03-05 16:53:33 -08001092 if (CONFIG(SYSTEM_TYPE_CONVERTIBLE) ||
1093 CONFIG(SYSTEM_TYPE_LAPTOP))
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001094 fadt->preferred_pm_profile = PM_MOBILE;
Julius Wernercd49cce2019-03-05 16:53:33 -08001095 else if (CONFIG(SYSTEM_TYPE_DETACHABLE) ||
1096 CONFIG(SYSTEM_TYPE_TABLET))
Duncan Lauriefa9c6f12019-02-07 11:30:06 -08001097 fadt->preferred_pm_profile = PM_TABLET;
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001098 else
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001099 fadt->preferred_pm_profile = PM_DESKTOP;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001100
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +02001101 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001102
1103 header->checksum =
1104 acpi_checksum((void *) fadt, header->length);
1105}
1106#endif
1107
Aaron Durbin64031672018-04-21 14:45:32 -06001108unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001109{
1110 return 0;
1111}
1112
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001113unsigned long write_acpi_tables(unsigned long start)
1114{
1115 unsigned long current;
1116 acpi_rsdp_t *rsdp;
1117 acpi_rsdt_t *rsdt;
1118 acpi_xsdt_t *xsdt;
1119 acpi_fadt_t *fadt;
1120 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001121 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001122 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001123 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001124 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001125 acpi_tcpa_t *tcpa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001126 acpi_tpm2_t *tpm2;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001127 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +11001128 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001129 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001130 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001131 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001132
1133 current = start;
1134
1135 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -06001136 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001137
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001138 fw = fw_cfg_acpi_tables(current);
1139 if (fw)
1140 return fw;
1141
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +02001142 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001143 CONFIG_CBFS_PREFIX "/dsdt.aml",
1144 CBFS_TYPE_RAW, &dsdt_size);
1145 if (!dsdt_file) {
1146 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
1147 return current;
1148 }
1149
1150 if (dsdt_file->length > dsdt_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001151 || dsdt_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001152 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
1153 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
1154 return current;
1155 }
1156
Aaron Durbin899d13d2015-05-15 23:39:23 -05001157 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001158 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001159 if (slic_file
1160 && (slic_file->length > slic_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001161 || slic_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001162 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001163 slic_file = 0;
1164 }
1165
1166 if (slic_file) {
1167 memcpy(oem_id, slic_file->oem_id, 6);
1168 memcpy(oem_table_id, slic_file->oem_table_id, 8);
1169 } else {
1170 memcpy(oem_id, OEM_ID, 6);
1171 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
1172 }
1173
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001174 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
1175
1176 /* We need at least an RSDP and an RSDT Table */
1177 rsdp = (acpi_rsdp_t *) current;
1178 current += sizeof(acpi_rsdp_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001179 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001180 rsdt = (acpi_rsdt_t *) current;
1181 current += sizeof(acpi_rsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001182 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001183 xsdt = (acpi_xsdt_t *) current;
1184 current += sizeof(acpi_xsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001185 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001186
1187 /* clear all table memory */
1188 memset((void *) start, 0, current - start);
1189
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001190 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
1191 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
1192 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001193
1194 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Patrick Georgi133108a2015-08-08 23:20:58 +02001195 current = (ALIGN(current, 64));
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001196 facs = (acpi_facs_t *) current;
1197 current += sizeof(acpi_facs_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001198 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001199 acpi_create_facs(facs);
1200
1201 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
1202 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001203 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001204 if (dsdt->length >= sizeof(acpi_header_t)) {
1205 current += sizeof(acpi_header_t);
1206
1207 acpigen_set_current((char *) current);
1208 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001209 if (dev->ops && dev->ops->acpi_inject_dsdt_generator)
Alexander Couzensa90dad12015-04-12 21:49:46 +02001210 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001211 current = (unsigned long) acpigen_get_current();
1212 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001213 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001214 dsdt->length - sizeof(acpi_header_t));
1215 current += dsdt->length - sizeof(acpi_header_t);
1216
1217 /* (Re)calculate length and checksum. */
1218 dsdt->length = current - (unsigned long)dsdt;
1219 dsdt->checksum = 0;
1220 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
1221 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001222
Aaron Durbin07a1b282015-12-10 17:07:38 -06001223 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001224
1225 printk(BIOS_DEBUG, "ACPI: * FADT\n");
1226 fadt = (acpi_fadt_t *) current;
1227 current += sizeof(acpi_fadt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001228 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001229
1230 acpi_create_fadt(fadt, facs, dsdt);
1231 acpi_add_table(rsdp, fadt);
1232
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001233 if (slic_file) {
1234 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
1235 slic = (acpi_header_t *)current;
1236 memcpy(slic, slic_file, slic_file->length);
1237 current += slic_file->length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001238 current = acpi_align_current(current);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001239 acpi_add_table(rsdp, slic);
1240 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001241
1242 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1243 ssdt = (acpi_header_t *)current;
1244 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001245 if (ssdt->length > sizeof(acpi_header_t)) {
1246 current += ssdt->length;
1247 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001248 current = acpi_align_current(current);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001249 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001250
1251 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
1252 mcfg = (acpi_mcfg_t *) current;
1253 acpi_create_mcfg(mcfg);
1254 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
1255 current += mcfg->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001256 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001257 acpi_add_table(rsdp, mcfg);
1258 }
1259
Julius Wernercd49cce2019-03-05 16:53:33 -08001260 if (CONFIG(TPM1)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001261 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
1262 tcpa = (acpi_tcpa_t *) current;
1263 acpi_create_tcpa(tcpa);
1264 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
1265 current += tcpa->header.length;
1266 current = acpi_align_current(current);
1267 acpi_add_table(rsdp, tcpa);
1268 }
1269 }
1270
Julius Wernercd49cce2019-03-05 16:53:33 -08001271 if (CONFIG(TPM2)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001272 printk(BIOS_DEBUG, "ACPI: * TPM2\n");
1273 tpm2 = (acpi_tpm2_t *) current;
1274 acpi_create_tpm2(tpm2);
1275 if (tpm2->header.length >= sizeof(acpi_tpm2_t)) {
1276 current += tpm2->header.length;
1277 current = acpi_align_current(current);
1278 acpi_add_table(rsdp, tpm2);
1279 }
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001280 }
1281
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001282 printk(BIOS_DEBUG, "ACPI: * MADT\n");
1283
1284 madt = (acpi_madt_t *) current;
1285 acpi_create_madt(madt);
1286 if (madt->header.length > sizeof(acpi_madt_t)) {
Lee Leahy024b13d2017-03-16 13:41:11 -07001287 current += madt->header.length;
1288 acpi_add_table(rsdp, madt);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001289 }
Aaron Durbin07a1b282015-12-10 17:07:38 -06001290 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001291
1292 printk(BIOS_DEBUG, "current = %lx\n", current);
1293
1294 for (dev = all_devices; dev; dev = dev->next) {
1295 if (dev->ops && dev->ops->write_acpi_tables) {
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001296 current = dev->ops->write_acpi_tables(dev, current,
1297 rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001298 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001299 }
1300 }
1301
1302 printk(BIOS_INFO, "ACPI: done.\n");
1303 return current;
1304}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001305
Rudolf Marek33cafe52009-04-13 18:07:02 +00001306static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1307{
1308 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1309 return NULL;
1310
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001311 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001312
1313 if (acpi_checksum((void *)rsdp, 20) != 0)
1314 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001315 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001316
1317 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1318 rsdp->length) != 0))
1319 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001320 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001321
1322 return rsdp;
1323}
1324
Rudolf Marek33cafe52009-04-13 18:07:02 +00001325void *acpi_find_wakeup_vector(void)
1326{
1327 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001328 acpi_rsdt_t *rsdt;
1329 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001330 acpi_fadt_t *fadt = NULL;
Kyösti Mälkki072d436b2016-06-17 08:44:40 +03001331 acpi_rsdp_t *rsdp = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001332 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001333 int i;
1334
Rudolf Marek33cafe52009-04-13 18:07:02 +00001335 if (!acpi_is_wakeup())
1336 return NULL;
1337
Uwe Hermann622824c2010-11-19 15:14:42 +00001338 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001339
Uwe Hermann622824c2010-11-19 15:14:42 +00001340 /* Find RSDP. */
1341 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
Lee Leahy0b5678f2017-03-16 16:01:40 -07001342 rsdp = valid_rsdp((acpi_rsdp_t *)p);
1343 if (rsdp)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001344 break;
1345 }
1346
Angel Pons98a68ad2018-11-04 12:25:25 +01001347 if (rsdp == NULL) {
1348 printk(BIOS_ALERT,
1349 "No RSDP found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001350 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001351 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001352
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001353 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001354 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001355
Uwe Hermann622824c2010-11-19 15:14:42 +00001356 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001357 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001358
Uwe Hermann622824c2010-11-19 15:14:42 +00001359 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001360 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001361 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001362 break;
1363 fadt = NULL;
1364 }
1365
Angel Pons98a68ad2018-11-04 12:25:25 +01001366 if (fadt == NULL) {
1367 printk(BIOS_ALERT,
1368 "No FADT found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001369 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001370 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001371
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001372 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001373 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001374
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001375 if (facs == NULL) {
Angel Pons98a68ad2018-11-04 12:25:25 +01001376 printk(BIOS_ALERT,
1377 "No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001378 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001379 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001380
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001381 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001382 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001383 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001384
Rudolf Marek33cafe52009-04-13 18:07:02 +00001385 return wake_vec;
1386}
1387
Aaron Durbin64031672018-04-21 14:45:32 -06001388__weak int acpi_get_gpe(int gpe)
Duncan Laurie1f6e6812016-09-19 12:04:19 -07001389{
1390 return -1; /* implemented by SOC */
1391}
Marc Jones93a51762018-08-22 18:57:24 -06001392
1393int get_acpi_table_revision(enum acpi_tables table)
1394{
1395 switch (table) {
1396 case FADT:
1397 return ACPI_FADT_REV_ACPI_3_0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001398 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 -06001399 return 2;
Marc Jones93a51762018-08-22 18:57:24 -06001400 case MCFG:
1401 return 1;
1402 case TCPA:
1403 return 2;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001404 case TPM2:
1405 return 4;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001406 case SSDT: /* ACPI 3.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001407 return 2;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001408 case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 upto 6.3: 3 */
Marc Jones93a51762018-08-22 18:57:24 -06001409 return 1; /* TODO Should probably be upgraded to 2 */
1410 case DMAR:
1411 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001412 case SLIT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001413 return 1;
1414 case HPET: /* Currently 1. Table added in ACPI 2.0. */
1415 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001416 case VFCT: /* ACPI 2.0/3.0/4.0: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001417 return 1;
1418 case IVRS:
1419 return IVRS_FORMAT_FIXED;
1420 case DBG2:
1421 return 0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001422 case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001423 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001424 case RSDT: /* ACPI 1.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001425 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001426 case XSDT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001427 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001428 case RSDP: /* ACPI 2.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001429 return 2;
1430 case HEST:
1431 return 1;
1432 case NHLT:
1433 return 5;
Marshall Dawson44705c62018-09-04 13:47:15 -06001434 case BERT:
1435 return 1;
Marc Jones93a51762018-08-22 18:57:24 -06001436 default:
1437 return -1;
1438 }
1439 return -1;
1440}