blob: b48640901c8293b17bc9724bd89d2b0ad78e7a1d [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 *
Martin Roth9df9e9392016-01-12 15:55:28 -07004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Martin Roth20bbd812019-08-30 21:09:37 -060012 *
13 * coreboot ACPI Table support
Stefan Reinauer777224c2005-01-19 14:06:41 +000014 */
15
Stefan Reinauer14e22772010-04-27 06:56:47 +000016/*
Stefan Reinauer777224c2005-01-19 14:06:41 +000017 * Each system port implementing ACPI has to provide two functions:
Stefan Reinauer14e22772010-04-27 06:56:47 +000018 *
Stefan Reinauer777224c2005-01-19 14:06:41 +000019 * write_acpi_tables()
20 * acpi_dump_apics()
Stefan Reinauer14e22772010-04-27 06:56:47 +000021 *
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000022 * See Kontron 986LCD-M port for a good example of an ACPI implementation
23 * in coreboot.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000024 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000025
26#include <console/console.h>
27#include <string.h>
28#include <arch/acpi.h>
Martin Rotha66df492016-09-06 10:22:34 -060029#include <arch/acpi_ivrs.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000030#include <arch/acpigen.h>
Stefan Reinauer777224c2005-01-19 14:06:41 +000031#include <device/pci.h>
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000032#include <cbmem.h>
Elyes HAOUASe2d152c2019-06-21 07:06:50 +020033#include <commonlib/helpers.h>
Patrick Georgic8feedd2012-02-16 18:43:25 +010034#include <cpu/x86/lapic_def.h>
Duncan Laurie11290c42012-10-03 19:07:05 -070035#include <cpu/cpu.h>
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +010036#include <cbfs.h>
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010037#include <version.h>
Werner Zehdb561e62019-02-19 13:39:56 +010038#include <commonlib/sort.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000039
40u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000041{
Uwe Hermann622824c2010-11-19 15:14:42 +000042 u8 ret = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +000043 while (length--) {
44 ret += *table;
45 table++;
46 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000047 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000048}
49
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000050/**
Uwe Hermann622824c2010-11-19 15:14:42 +000051 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
52 * and checksum.
Stefan Reinauer06feb882004-02-03 16:11:35 +000053 */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000054void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000055{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000056 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000057 acpi_rsdt_t *rsdt;
58 acpi_xsdt_t *xsdt = NULL;
59
Uwe Hermann622824c2010-11-19 15:14:42 +000060 /* The RSDT is mandatory... */
Stefan Reinauerdefee172015-06-18 01:11:19 -070061 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000062
Uwe Hermann622824c2010-11-19 15:14:42 +000063 /* ...while the XSDT is not. */
64 if (rsdp->xsdt_address)
Stefan Reinauerdefee172015-06-18 01:11:19 -070065 xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address);
Stefan Reinauer14e22772010-04-27 06:56:47 +000066
Uwe Hermann622824c2010-11-19 15:14:42 +000067 /* This should always be MAX_ACPI_TABLES. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000068 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauer14e22772010-04-27 06:56:47 +000069
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000070 for (i = 0; i < entries_num; i++) {
Uwe Hermann622824c2010-11-19 15:14:42 +000071 if (rsdt->entry[i] == 0)
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000072 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000073 }
74
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000075 if (i >= entries_num) {
Uwe Hermann622824c2010-11-19 15:14:42 +000076 printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +030077 "too many tables.\n");
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000078 return;
79 }
80
Uwe Hermann622824c2010-11-19 15:14:42 +000081 /* Add table to the RSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070082 rsdt->entry[i] = (uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000083
Uwe Hermann622824c2010-11-19 15:14:42 +000084 /* Fix RSDT length or the kernel will assume invalid entries. */
85 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000086
Uwe Hermann622824c2010-11-19 15:14:42 +000087 /* Re-calculate checksum. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000088 rsdt->header.checksum = 0; /* Hope this won't get optimized away */
Uwe Hermann622824c2010-11-19 15:14:42 +000089 rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000090
Uwe Hermann622824c2010-11-19 15:14:42 +000091 /*
92 * And now the same thing for the XSDT. We use the same index as for
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000093 * now we want the XSDT and RSDT to always be in sync in coreboot.
94 */
95 if (xsdt) {
Uwe Hermann622824c2010-11-19 15:14:42 +000096 /* Add table to the XSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070097 xsdt->entry[i] = (u64)(uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000098
Uwe Hermann622824c2010-11-19 15:14:42 +000099 /* Fix XSDT length. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000100 xsdt->header.length = sizeof(acpi_header_t) +
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300101 (sizeof(u64) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000102
Uwe Hermann622824c2010-11-19 15:14:42 +0000103 /* Re-calculate checksum. */
104 xsdt->header.checksum = 0;
105 xsdt->header.checksum = acpi_checksum((u8 *)xsdt,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300106 xsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000107 }
108
Uwe Hermann622824c2010-11-19 15:14:42 +0000109 printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300110 i + 1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000111}
112
Uwe Hermann622824c2010-11-19 15:14:42 +0000113int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300114 u16 seg_nr, u8 start, u8 end)
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000115{
Vladimir Serbinenko60fccdc2014-10-05 11:05:16 +0200116 memset(mmconfig, 0, sizeof(*mmconfig));
Rudolf Mareke6409f22007-11-03 12:50:26 +0000117 mmconfig->base_address = base;
118 mmconfig->base_reserved = 0;
119 mmconfig->pci_segment_group_number = seg_nr;
120 mmconfig->start_bus_number = start;
121 mmconfig->end_bus_number = end;
Uwe Hermann622824c2010-11-19 15:14:42 +0000122
123 return sizeof(acpi_mcfg_mmconfig_t);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000124}
125
Stefan Reinauer777224c2005-01-19 14:06:41 +0000126int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000127{
Uwe Hermann622824c2010-11-19 15:14:42 +0000128 lapic->type = 0; /* Local APIC structure */
129 lapic->length = sizeof(acpi_madt_lapic_t);
130 lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
131 lapic->processor_id = cpu;
132 lapic->apic_id = apic;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000133
Uwe Hermann622824c2010-11-19 15:14:42 +0000134 return lapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000135}
136
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000137unsigned long acpi_create_madt_lapics(unsigned long current)
138{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100139 struct device *cpu;
Werner Zeh423adfb2019-03-06 09:31:02 +0100140 int index, apic_ids[CONFIG_MAX_CPUS] = {0}, num_cpus = 0;
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000141
Uwe Hermann622824c2010-11-19 15:14:42 +0000142 for (cpu = all_devices; cpu; cpu = cpu->next) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000143 if ((cpu->path.type != DEVICE_PATH_APIC) ||
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800144 (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000145 continue;
146 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000147 if (!cpu->enabled)
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000148 continue;
Werner Zehdb561e62019-02-19 13:39:56 +0100149 if (num_cpus >= ARRAY_SIZE(apic_ids))
150 break;
151 apic_ids[num_cpus++] = cpu->path.apic.apic_id;
152 }
Werner Zehfedb36e2019-03-12 07:07:50 +0100153 if (num_cpus > 1)
154 bubblesort(apic_ids, num_cpus, NUM_ASCENDING);
Werner Zehdb561e62019-02-19 13:39:56 +0100155 for (index = 0; index < num_cpus; index++) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000156 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
Werner Zehdb561e62019-02-19 13:39:56 +0100157 index, apic_ids[index]);
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000158 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000159
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000160 return current;
161}
162
Uwe Hermann622824c2010-11-19 15:14:42 +0000163int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300164 u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000165{
Uwe Hermann622824c2010-11-19 15:14:42 +0000166 ioapic->type = 1; /* I/O APIC structure */
167 ioapic->length = sizeof(acpi_madt_ioapic_t);
168 ioapic->reserved = 0x00;
169 ioapic->gsi_base = gsi_base;
170 ioapic->ioapic_id = id;
171 ioapic->ioapic_addr = addr;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000172
Uwe Hermann622824c2010-11-19 15:14:42 +0000173 return ioapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000174}
175
Stefan Reinauer777224c2005-01-19 14:06:41 +0000176int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000177 u8 bus, u8 source, u32 gsirq, u16 flags)
178{
Uwe Hermann622824c2010-11-19 15:14:42 +0000179 irqoverride->type = 2; /* Interrupt source override */
180 irqoverride->length = sizeof(acpi_madt_irqoverride_t);
181 irqoverride->bus = bus;
182 irqoverride->source = source;
183 irqoverride->gsirq = gsirq;
184 irqoverride->flags = flags;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000185
Uwe Hermann622824c2010-11-19 15:14:42 +0000186 return irqoverride->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000187}
188
Stefan Reinauer777224c2005-01-19 14:06:41 +0000189int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300190 u16 flags, u8 lint)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000191{
Uwe Hermann622824c2010-11-19 15:14:42 +0000192 lapic_nmi->type = 4; /* Local APIC NMI structure */
193 lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
194 lapic_nmi->flags = flags;
195 lapic_nmi->processor_id = cpu;
196 lapic_nmi->lint = lint;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000197
Uwe Hermann622824c2010-11-19 15:14:42 +0000198 return lapic_nmi->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000199}
200
Stefan Reinauer777224c2005-01-19 14:06:41 +0000201void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000202{
Uwe Hermann622824c2010-11-19 15:14:42 +0000203 acpi_header_t *header = &(madt->header);
204 unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000205
Stefan Reinauer06feb882004-02-03 16:11:35 +0000206 memset((void *)madt, 0, sizeof(acpi_madt_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000207
John Zhao2ba303e2019-05-28 16:48:14 -0700208 if (!header)
209 return;
210
Uwe Hermann622824c2010-11-19 15:14:42 +0000211 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000212 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000213 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000214 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000215 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000216
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100217 header->asl_compiler_revision = asl_revision;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000218 header->length = sizeof(acpi_madt_t);
Marc Jones93a51762018-08-22 18:57:24 -0600219 header->revision = get_acpi_table_revision(MADT);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000220
Uwe Hermann622824c2010-11-19 15:14:42 +0000221 madt->lapic_addr = LOCAL_APIC_ADDR;
Nico Huber9df72e02018-11-24 18:25:50 +0100222 if (CONFIG(ACPI_HAVE_PCAT_8259))
223 madt->flags |= 1;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000224
Stefan Reinauerf622d592005-11-26 16:56:05 +0000225 current = acpi_fill_madt(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000226
Uwe Hermann622824c2010-11-19 15:14:42 +0000227 /* (Re)calculate length and checksum. */
228 header->length = current - (unsigned long)madt;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000229
Uwe Hermann622824c2010-11-19 15:14:42 +0000230 header->checksum = acpi_checksum((void *)madt, header->length);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000231}
232
Uwe Hermann622824c2010-11-19 15:14:42 +0000233/* MCFG is defined in the PCI Firmware Specification 3.0. */
Rudolf Mareke6409f22007-11-03 12:50:26 +0000234void acpi_create_mcfg(acpi_mcfg_t *mcfg)
235{
Uwe Hermann622824c2010-11-19 15:14:42 +0000236 acpi_header_t *header = &(mcfg->header);
237 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000238
Rudolf Mareke6409f22007-11-03 12:50:26 +0000239 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000240
John Zhao2ba303e2019-05-28 16:48:14 -0700241 if (!header)
242 return;
243
Uwe Hermann622824c2010-11-19 15:14:42 +0000244 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000245 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000246 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000247 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000248 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000249
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100250 header->asl_compiler_revision = asl_revision;
Rudolf Mareke6409f22007-11-03 12:50:26 +0000251 header->length = sizeof(acpi_mcfg_t);
Marc Jones93a51762018-08-22 18:57:24 -0600252 header->revision = get_acpi_table_revision(MCFG);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000253
254 current = acpi_fill_mcfg(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000255
Uwe Hermann622824c2010-11-19 15:14:42 +0000256 /* (Re)calculate length and checksum. */
257 header->length = current - (unsigned long)mcfg;
258 header->checksum = acpi_checksum((void *)mcfg, header->length);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000259}
260
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200261static void *get_tcpa_log(u32 *size)
262{
263 const struct cbmem_entry *ce;
264 const u32 tcpa_default_log_len = 0x10000;
265 void *lasa;
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200266 ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200267 if (ce) {
268 lasa = cbmem_entry_start(ce);
269 *size = cbmem_entry_size(ce);
270 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
271 return lasa;
272 }
Philipp Deppenwiese791ba972018-07-30 01:15:20 +0200273 lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200274 if (!lasa) {
275 printk(BIOS_ERR, "TCPA log creation failed\n");
276 return NULL;
277 }
278
279 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
Lee Leahy024b13d2017-03-16 13:41:11 -0700280 memset(lasa, 0, tcpa_default_log_len);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200281
282 *size = tcpa_default_log_len;
283 return lasa;
284}
285
286static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
287{
288 acpi_header_t *header = &(tcpa->header);
289 u32 tcpa_log_len;
290 void *lasa;
291
292 memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
293
294 lasa = get_tcpa_log(&tcpa_log_len);
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700295 if (!lasa)
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200296 return;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200297
John Zhao2ba303e2019-05-28 16:48:14 -0700298 if (!header)
299 return;
300
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200301 /* Fill out header fields. */
302 memcpy(header->signature, "TCPA", 4);
303 memcpy(header->oem_id, OEM_ID, 6);
304 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
305 memcpy(header->asl_compiler_id, ASLC, 4);
306
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100307 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200308 header->length = sizeof(acpi_tcpa_t);
Marc Jones93a51762018-08-22 18:57:24 -0600309 header->revision = get_acpi_table_revision(TCPA);
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200310
311 tcpa->platform_class = 0;
312 tcpa->laml = tcpa_log_len;
Stefan Reinauerdefee172015-06-18 01:11:19 -0700313 tcpa->lasa = (uintptr_t) lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200314
315 /* Calculate checksum. */
316 header->checksum = acpi_checksum((void *)tcpa, header->length);
317}
318
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100319static void *get_tpm2_log(u32 *size)
320{
321 const struct cbmem_entry *ce;
322 const u32 tpm2_default_log_len = 0x10000;
323 void *lasa;
324 ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG);
325 if (ce) {
326 lasa = cbmem_entry_start(ce);
327 *size = cbmem_entry_size(ce);
328 printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa);
329 return lasa;
330 }
331 lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len);
332 if (!lasa) {
333 printk(BIOS_ERR, "TPM2 log creation failed\n");
334 return NULL;
335 }
336
337 printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa);
338 memset(lasa, 0, tpm2_default_log_len);
339
340 *size = tpm2_default_log_len;
341 return lasa;
342}
343
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200344static void acpi_create_tpm2(acpi_tpm2_t *tpm2)
345{
346 acpi_header_t *header = &(tpm2->header);
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100347 u32 tpm2_log_len;
348 void *lasa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200349
350 memset((void *)tpm2, 0, sizeof(acpi_tpm2_t));
351
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100352 /*
353 * Some payloads like SeaBIOS depend on log area to use TPM2.
354 * Get the memory size and address of TPM2 log area or initialize it.
355 */
356 lasa = get_tpm2_log(&tpm2_log_len);
357 if (!lasa)
358 tpm2_log_len = 0;
359
John Zhao2ba303e2019-05-28 16:48:14 -0700360 if (!header)
361 return;
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;
Christian Walter26e0d4c2019-07-14 15:47:23 +0200375 if (CONFIG(CRB_TPM)) {
376 /* Must be set to 7 for CRB Support */
377 tpm2->control_area = CONFIG_CRB_TPM_BASE_ADDRESS + 0x40;
378 tpm2->start_method = 7;
379 } else {
380 /* Must be set to 0 for FIFO interface support */
381 tpm2->control_area = 0;
382 tpm2->start_method = 6;
383 }
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200384 memset(tpm2->msp, 0, sizeof(tpm2->msp));
385
Michał Żygowski6e8692e2018-11-22 16:57:50 +0100386 /* Fill the log area size and start address fields. */
387 tpm2->laml = tpm2_log_len;
388 tpm2->lasa = (uintptr_t) lasa;
389
Philipp Deppenwiese296164e02018-10-18 15:39:34 +0200390 /* Calculate checksum. */
391 header->checksum = acpi_checksum((void *)tpm2, header->length);
392}
393
Duncan Laurie37319032016-05-26 12:47:05 -0700394static void acpi_ssdt_write_cbtable(void)
395{
396 const struct cbmem_entry *cbtable;
397 uintptr_t base;
398 uint32_t size;
399
400 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
401 if (!cbtable)
402 return;
403 base = (uintptr_t)cbmem_entry_start(cbtable);
404 size = cbmem_entry_size(cbtable);
405
406 acpigen_write_device("CTBL");
407 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
408 acpigen_write_name_integer("_UID", 0);
David Wu5dff3962018-03-21 16:48:53 +0800409 acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON);
Duncan Laurie37319032016-05-26 12:47:05 -0700410 acpigen_write_name("_CRS");
411 acpigen_write_resourcetemplate_header();
412 acpigen_write_mem32fixed(0, base, size);
413 acpigen_write_resourcetemplate_footer();
414 acpigen_pop_len();
415}
416
Myles Watson3fe6b702009-10-09 20:13:43 +0000417void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000418{
Uwe Hermann622824c2010-11-19 15:14:42 +0000419 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
420
Rudolf Marek293b5f52009-02-01 18:35:15 +0000421 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000422
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000423 memcpy(&ssdt->signature, "SSDT", 4);
Marc Jones93a51762018-08-22 18:57:24 -0600424 ssdt->revision = get_acpi_table_revision(SSDT);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000425 memcpy(&ssdt->oem_id, OEM_ID, 6);
426 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
427 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000428 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +0100429 ssdt->asl_compiler_revision = asl_revision;
Rudolf Marek293b5f52009-02-01 18:35:15 +0000430 ssdt->length = sizeof(acpi_header_t);
431
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000432 acpigen_set_current((char *) current);
Duncan Laurie37319032016-05-26 12:47:05 -0700433
434 /* Write object to declare coreboot tables */
435 acpi_ssdt_write_cbtable();
436
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200437 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100438 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200439 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700440 if (dev->ops && dev->ops->acpi_fill_ssdt_generator)
Alexander Couzens5eea4582015-04-12 22:18:55 +0200441 dev->ops->acpi_fill_ssdt_generator(dev);
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200442 current = (unsigned long) acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200443 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000444
Uwe Hermann622824c2010-11-19 15:14:42 +0000445 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000446 ssdt->length = current - (unsigned long)ssdt;
447 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
448}
449
Stefan Reinauerf622d592005-11-26 16:56:05 +0000450int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
451{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000452 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000453
Uwe Hermann622824c2010-11-19 15:14:42 +0000454 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
455 lapic->length = sizeof(acpi_srat_lapic_t);
456 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
457 lapic->proximity_domain_7_0 = node;
458 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
459 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000460
Uwe Hermann622824c2010-11-19 15:14:42 +0000461 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000462}
463
Uwe Hermann622824c2010-11-19 15:14:42 +0000464int 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 +0300465 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000466{
Uwe Hermann622824c2010-11-19 15:14:42 +0000467 mem->type = 1; /* Memory affinity structure */
468 mem->length = sizeof(acpi_srat_mem_t);
469 mem->base_address_low = (basek << 10);
470 mem->base_address_high = (basek >> (32 - 10));
471 mem->length_low = (sizek << 10);
472 mem->length_high = (sizek >> (32 - 10));
473 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000474 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000475
Uwe Hermann622824c2010-11-19 15:14:42 +0000476 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000477}
478
Uwe Hermann622824c2010-11-19 15:14:42 +0000479/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200480void acpi_create_srat(acpi_srat_t *srat,
481 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000482{
Uwe Hermann622824c2010-11-19 15:14:42 +0000483 acpi_header_t *header = &(srat->header);
484 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000485
Uwe Hermann622824c2010-11-19 15:14:42 +0000486 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000487
John Zhao2ba303e2019-05-28 16:48:14 -0700488 if (!header)
489 return;
490
Uwe Hermann622824c2010-11-19 15:14:42 +0000491 /* Fill out header fields. */
492 memcpy(header->signature, "SRAT", 4);
493 memcpy(header->oem_id, OEM_ID, 6);
494 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
495 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000496
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100497 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000498 header->length = sizeof(acpi_srat_t);
Marc Jones93a51762018-08-22 18:57:24 -0600499 header->revision = get_acpi_table_revision(SRAT);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000500
Uwe Hermann622824c2010-11-19 15:14:42 +0000501 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000502
Uwe Hermann622824c2010-11-19 15:14:42 +0000503 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000504
Uwe Hermann622824c2010-11-19 15:14:42 +0000505 /* (Re)calculate length and checksum. */
506 header->length = current - (unsigned long)srat;
507 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000508}
509
Nico Hubere561f352015-10-26 11:51:25 +0100510void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Lee Leahy024b13d2017-03-16 13:41:11 -0700511 unsigned long (*acpi_fill_dmar)(unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200512{
513 acpi_header_t *header = &(dmar->header);
514 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
515
516 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
517
John Zhao2ba303e2019-05-28 16:48:14 -0700518 if (!header)
519 return;
520
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200521 /* Fill out header fields. */
522 memcpy(header->signature, "DMAR", 4);
523 memcpy(header->oem_id, OEM_ID, 6);
524 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
525 memcpy(header->asl_compiler_id, ASLC, 4);
526
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100527 header->asl_compiler_revision = asl_revision;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200528 header->length = sizeof(acpi_dmar_t);
Marc Jones93a51762018-08-22 18:57:24 -0600529 header->revision = get_acpi_table_revision(DMAR);
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200530
Jacob Laskaf3f654d2016-03-15 21:53:27 -0500531 dmar->host_address_width = cpu_phys_address_size() - 1;
Nico Hubere561f352015-10-26 11:51:25 +0100532 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200533
534 current = acpi_fill_dmar(current);
535
536 /* (Re)calculate length and checksum. */
537 header->length = current - (unsigned long)dmar;
538 header->checksum = acpi_checksum((void *)dmar, header->length);
539}
540
541unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
Matt DeVillier7866d492018-03-29 14:59:57 +0200542 u16 segment, u64 bar)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200543{
544 dmar_entry_t *drhd = (dmar_entry_t *)current;
545 memset(drhd, 0, sizeof(*drhd));
546 drhd->type = DMAR_DRHD;
547 drhd->length = sizeof(*drhd); /* will be fixed up later */
548 drhd->flags = flags;
549 drhd->segment = segment;
550 drhd->bar = bar;
551
552 return drhd->length;
553}
554
Matt DeVillier7866d492018-03-29 14:59:57 +0200555unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
556 u64 bar, u64 limit)
557{
558 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current;
559 memset(rmrr, 0, sizeof(*rmrr));
560 rmrr->type = DMAR_RMRR;
561 rmrr->length = sizeof(*rmrr); /* will be fixed up later */
562 rmrr->segment = segment;
563 rmrr->bar = bar;
564 rmrr->limit = limit;
565
566 return rmrr->length;
567}
568
Werner Zehd4d76952016-07-27 06:56:36 +0200569unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
570 u16 segment)
571{
572 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
573 memset(atsr, 0, sizeof(*atsr));
574 atsr->type = DMAR_ATSR;
575 atsr->length = sizeof(*atsr); /* will be fixed up later */
576 atsr->flags = flags;
577 atsr->segment = segment;
578
579 return atsr->length;
580}
581
John Zhao76e70672019-04-04 11:03:28 -0700582unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
583 u32 proximity_domain)
584{
585 dmar_rhsa_entry_t *rhsa = (dmar_rhsa_entry_t *)current;
586 memset(rhsa, 0, sizeof(*rhsa));
587 rhsa->type = DMAR_RHSA;
588 rhsa->length = sizeof(*rhsa);
589 rhsa->base_address = base_addr;
590 rhsa->proximity_domain = proximity_domain;
591
592 return rhsa->length;
593}
594
595unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
596 const char *device_name)
597{
598 dmar_andd_entry_t *andd = (dmar_andd_entry_t *)current;
599 int andd_len = sizeof(dmar_andd_entry_t) + strlen(device_name) + 1;
600 memset(andd, 0, andd_len);
601 andd->type = DMAR_ANDD;
602 andd->length = andd_len;
603 andd->device_number = device_number;
604 memcpy(&andd->device_name, device_name, strlen(device_name));
605
606 return andd->length;
607}
608
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200609void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
610{
611 dmar_entry_t *drhd = (dmar_entry_t *)base;
612 drhd->length = current - base;
613}
614
Matt DeVillier7866d492018-03-29 14:59:57 +0200615void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
616{
617 dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)base;
618 rmrr->length = current - base;
619}
620
Werner Zehd4d76952016-07-27 06:56:36 +0200621void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
622{
623 dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base;
624 atsr->length = current - base;
625}
626
Matt DeVillier7866d492018-03-29 14:59:57 +0200627static unsigned long acpi_create_dmar_ds(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100628 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200629{
Nico Huber6c4751d2015-10-26 12:03:54 +0100630 /* we don't support longer paths yet */
631 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
632
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200633 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100634 memset(ds, 0, dev_scope_length);
635 ds->type = type;
636 ds->length = dev_scope_length;
637 ds->enumeration = enumeration_id;
638 ds->start_bus = bus;
639 ds->path[0].dev = dev;
640 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200641
642 return ds->length;
643}
644
Matt DeVillier7866d492018-03-29 14:59:57 +0200645unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200646 u8 dev, u8 fn)
647{
Matt DeVillier7866d492018-03-29 14:59:57 +0200648 return acpi_create_dmar_ds(current,
Werner Zeh21a5bff2016-07-27 07:07:20 +0200649 SCOPE_PCI_SUB, 0, bus, dev, fn);
650}
651
Matt DeVillier7866d492018-03-29 14:59:57 +0200652unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus,
Nico Huber6c4751d2015-10-26 12:03:54 +0100653 u8 dev, u8 fn)
654{
Matt DeVillier7866d492018-03-29 14:59:57 +0200655 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100656 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
657}
658
Matt DeVillier7866d492018-03-29 14:59:57 +0200659unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100660 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
661{
Matt DeVillier7866d492018-03-29 14:59:57 +0200662 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100663 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
664}
665
Matt DeVillier7866d492018-03-29 14:59:57 +0200666unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100667 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
668{
Matt DeVillier7866d492018-03-29 14:59:57 +0200669 return acpi_create_dmar_ds(current,
Nico Huber6c4751d2015-10-26 12:03:54 +0100670 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
671}
672
Uwe Hermann622824c2010-11-19 15:14:42 +0000673/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200674void acpi_create_slit(acpi_slit_t *slit,
675 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000676{
Uwe Hermann622824c2010-11-19 15:14:42 +0000677 acpi_header_t *header = &(slit->header);
678 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000679
Uwe Hermann622824c2010-11-19 15:14:42 +0000680 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000681
John Zhao2ba303e2019-05-28 16:48:14 -0700682 if (!header)
683 return;
684
Uwe Hermann622824c2010-11-19 15:14:42 +0000685 /* Fill out header fields. */
686 memcpy(header->signature, "SLIT", 4);
687 memcpy(header->oem_id, OEM_ID, 6);
688 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
689 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000690
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100691 header->asl_compiler_revision = asl_revision;
Uwe Hermann622824c2010-11-19 15:14:42 +0000692 header->length = sizeof(acpi_slit_t);
Marc Jones93a51762018-08-22 18:57:24 -0600693 header->revision = get_acpi_table_revision(SLIT);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000694
Uwe Hermann622824c2010-11-19 15:14:42 +0000695 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000696
Uwe Hermann622824c2010-11-19 15:14:42 +0000697 /* (Re)calculate length and checksum. */
698 header->length = current - (unsigned long)slit;
699 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000700}
701
Uwe Hermann622824c2010-11-19 15:14:42 +0000702/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000703void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000704{
Uwe Hermann622824c2010-11-19 15:14:42 +0000705 acpi_header_t *header = &(hpet->header);
706 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000707
Stefan Reinauera7648c22004-01-29 17:31:34 +0000708 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000709
John Zhao2ba303e2019-05-28 16:48:14 -0700710 if (!header)
711 return;
712
Uwe Hermann622824c2010-11-19 15:14:42 +0000713 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000714 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000715 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000716 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000717 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000718
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100719 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000720 header->length = sizeof(acpi_hpet_t);
Marc Jones93a51762018-08-22 18:57:24 -0600721 header->revision = get_acpi_table_revision(HPET);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000722
Uwe Hermann622824c2010-11-19 15:14:42 +0000723 /* Fill out HPET address. */
724 addr->space_id = 0; /* Memory */
725 addr->bit_width = 64;
726 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200727 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
728 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000729
Lee Leahy024b13d2017-03-16 13:41:11 -0700730 hpet->id = *(unsigned int *)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000731 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200732 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000733
Uwe Hermann622824c2010-11-19 15:14:42 +0000734 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000735}
Uwe Hermann622824c2010-11-19 15:14:42 +0000736
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200737void acpi_create_vfct(struct device *device,
738 struct acpi_vfct *vfct,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700739 unsigned long (*acpi_fill_vfct)(struct device *device,
740 struct acpi_vfct *vfct_struct, unsigned long current))
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200741{
742 acpi_header_t *header = &(vfct->header);
743 unsigned long current = (unsigned long)vfct + sizeof(struct acpi_vfct);
744
745 memset((void *)vfct, 0, sizeof(struct acpi_vfct));
746
John Zhao2ba303e2019-05-28 16:48:14 -0700747 if (!header)
748 return;
749
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200750 /* Fill out header fields. */
751 memcpy(header->signature, "VFCT", 4);
752 memcpy(header->oem_id, OEM_ID, 6);
753 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
754 memcpy(header->asl_compiler_id, ASLC, 4);
755
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100756 header->asl_compiler_revision = asl_revision;
Marc Jones93a51762018-08-22 18:57:24 -0600757 header->revision = get_acpi_table_revision(VFCT);
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200758
759 current = acpi_fill_vfct(device, vfct, current);
760
Kyösti Mälkkifb493792019-06-30 06:29:52 +0300761 /* If no BIOS image, return with header->length == 0. */
762 if (!vfct->VBIOSImageOffset)
763 return;
764
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200765 /* (Re)calculate length and checksum. */
766 header->length = current - (unsigned long)vfct;
767 header->checksum = acpi_checksum((void *)vfct, header->length);
768}
769
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +0200770void acpi_create_ipmi(struct device *device,
771 struct acpi_spmi *spmi,
772 const u16 ipmi_revision,
773 const acpi_addr_t *addr,
774 const enum acpi_ipmi_interface_type type,
775 const s8 gpe_interrupt,
776 const u32 apic_interrupt,
777 const u32 uid)
778{
779 acpi_header_t *header = &(spmi->header);
780 memset((void *)spmi, 0, sizeof(struct acpi_spmi));
781
782 /* Fill out header fields. */
783 memcpy(header->signature, "SPMI", 4);
784 memcpy(header->oem_id, OEM_ID, 6);
785 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
786 memcpy(header->asl_compiler_id, ASLC, 4);
787
788 header->asl_compiler_revision = asl_revision;
789 header->length = sizeof(struct acpi_spmi);
790 header->revision = get_acpi_table_revision(SPMI);
791
792 spmi->reserved = 1;
793
794 if (device->path.type == DEVICE_PATH_PCI) {
795 spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG;
796 spmi->pci_bus = device->bus->secondary;
797 spmi->pci_device = device->path.pci.devfn >> 3;
798 spmi->pci_function = device->path.pci.devfn & 0x7;
799 } else if (type != IPMI_INTERFACE_SSIF) {
800 memcpy(spmi->uid, &uid, sizeof(spmi->uid));
801 }
802
803 spmi->base_address = *addr;
804 spmi->specification_revision = ipmi_revision;
805
806 spmi->interface_type = type;
807
808 if (gpe_interrupt >= 0 && gpe_interrupt < 32) {
809 spmi->gpe = gpe_interrupt;
810 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_SCI;
811 }
812 if (apic_interrupt > 0) {
813 spmi->global_system_interrupt = apic_interrupt;
814 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_APIC;
815 }
816
817 /* Calculate checksum. */
818 header->checksum = acpi_checksum((void *)spmi, header->length);
819}
820
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500821void acpi_create_ivrs(acpi_ivrs_t *ivrs,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700822 unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
823 unsigned long current))
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500824{
825 acpi_header_t *header = &(ivrs->header);
826 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
827
828 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
829
John Zhao2ba303e2019-05-28 16:48:14 -0700830 if (!header)
831 return;
832
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500833 /* Fill out header fields. */
834 memcpy(header->signature, "IVRS", 4);
835 memcpy(header->oem_id, OEM_ID, 6);
836 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
837 memcpy(header->asl_compiler_id, ASLC, 4);
838
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100839 header->asl_compiler_revision = asl_revision;
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500840 header->length = sizeof(acpi_ivrs_t);
Marc Jones93a51762018-08-22 18:57:24 -0600841 header->revision = get_acpi_table_revision(IVRS);
Timothy Pearsonff8ccf02015-08-11 17:48:32 -0500842
843 current = acpi_fill_ivrs(ivrs, current);
844
845 /* (Re)calculate length and checksum. */
846 header->length = current - (unsigned long)ivrs;
847 header->checksum = acpi_checksum((void *)ivrs, header->length);
848}
849
Elyes HAOUAS9dd89cd2018-05-04 17:56:47 +0200850unsigned long acpi_write_hpet(struct device *device, unsigned long current,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700851 acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200852{
853 acpi_hpet_t *hpet;
854
855 /*
856 * We explicitly add these tables later on:
857 */
858 printk(BIOS_DEBUG, "ACPI: * HPET\n");
859
860 hpet = (acpi_hpet_t *) current;
861 current += sizeof(acpi_hpet_t);
Felix Heldc4697122019-06-20 13:50:17 +0200862 current = ALIGN_UP(current, 16);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200863 acpi_create_hpet(hpet);
864 acpi_add_table(rsdp, hpet);
865
866 return current;
867}
868
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800869void acpi_create_dbg2(acpi_dbg2_header_t *dbg2,
870 int port_type, int port_subtype,
871 acpi_addr_t *address, uint32_t address_size,
872 const char *device_path)
873{
874 uintptr_t current;
875 acpi_dbg2_device_t *device;
876 uint32_t *dbg2_addr_size;
877 acpi_header_t *header;
878 size_t path_len;
879 const char *path;
880 char *namespace;
881
882 /* Fill out header fields. */
883 current = (uintptr_t)dbg2;
884 memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
885 header = &(dbg2->header);
John Zhao2ba303e2019-05-28 16:48:14 -0700886
887 if (!header)
888 return;
889
Marc Jones93a51762018-08-22 18:57:24 -0600890 header->revision = get_acpi_table_revision(DBG2);
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800891 memcpy(header->signature, "DBG2", 4);
892 memcpy(header->oem_id, OEM_ID, 6);
893 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
894 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +0100895 header->asl_compiler_revision = asl_revision;
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800896
897 /* One debug device defined */
898 dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
899 dbg2->devices_count = 1;
900 current += sizeof(acpi_dbg2_header_t);
901
902 /* Device comes after the header */
903 device = (acpi_dbg2_device_t *)current;
904 memset(device, 0, sizeof(acpi_dbg2_device_t));
905 current += sizeof(acpi_dbg2_device_t);
906
907 device->revision = 0;
908 device->address_count = 1;
909 device->port_type = port_type;
910 device->port_subtype = port_subtype;
911
912 /* Base Address comes after device structure */
913 memcpy((void *)current, address, sizeof(acpi_addr_t));
914 device->base_address_offset = current - (uintptr_t)device;
915 current += sizeof(acpi_addr_t);
916
917 /* Address Size comes after address structure */
918 dbg2_addr_size = (uint32_t *)current;
919 device->address_size_offset = current - (uintptr_t)device;
920 *dbg2_addr_size = address_size;
921 current += sizeof(uint32_t);
922
923 /* Namespace string comes last, use '.' if not provided */
924 path = device_path ? : ".";
925 /* Namespace string length includes NULL terminator */
926 path_len = strlen(path) + 1;
927 namespace = (char *)current;
928 device->namespace_string_length = path_len;
929 device->namespace_string_offset = current - (uintptr_t)device;
930 strncpy(namespace, path, path_len);
931 current += path_len;
932
933 /* Update structure lengths and checksum */
934 device->length = current - (uintptr_t)device;
935 header->length = current - (uintptr_t)dbg2;
936 header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
937}
938
939unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
Aamir Bohrae825d3f2019-07-30 10:11:41 +0530940 const struct device *dev, uint8_t access_size)
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800941{
942 acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
943 struct resource *res;
944 acpi_addr_t address;
945
946 if (!dev) {
947 printk(BIOS_ERR, "%s: Device not found\n", __func__);
948 return current;
949 }
Mario Scheithauerf1eb0ea2017-11-21 13:52:53 +0100950 if (!dev->enabled) {
951 printk(BIOS_INFO, "%s: Device not enabled\n", __func__);
952 return current;
953 }
Duncan Lauriee4a36c72017-11-11 19:33:25 -0800954 res = find_resource(dev, PCI_BASE_ADDRESS_0);
955 if (!res) {
956 printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
957 __func__, dev_path(dev));
958 return current;
959 }
960
961 memset(&address, 0, sizeof(address));
962 if (res->flags & IORESOURCE_IO)
963 address.space_id = ACPI_ADDRESS_SPACE_IO;
964 else if (res->flags & IORESOURCE_MEM)
965 address.space_id = ACPI_ADDRESS_SPACE_MEMORY;
966 else {
967 printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
968 return current;
969 }
970
971 address.addrl = (uint32_t)res->base;
972 address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff);
973 address.access_size = access_size;
974
975 acpi_create_dbg2(dbg2,
976 ACPI_DBG2_PORT_SERIAL,
977 ACPI_DBG2_PORT_SERIAL_16550,
978 &address, res->size,
979 acpi_device_path(dev));
980
981 if (dbg2->header.length) {
982 current += dbg2->header.length;
983 current = acpi_align_current(current);
984 acpi_add_table(rsdp, dbg2);
985 }
986
987 return current;
988}
989
Stefan Reinauer777224c2005-01-19 14:06:41 +0000990void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000991{
Uwe Hermann622824c2010-11-19 15:14:42 +0000992 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000993
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000994 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000995 facs->length = sizeof(acpi_facs_t);
996 facs->hardware_signature = 0;
997 facs->firmware_waking_vector = 0;
998 facs->global_lock = 0;
999 facs->flags = 0;
1000 facs->x_firmware_waking_vector_l = 0;
1001 facs->x_firmware_waking_vector_h = 0;
Marc Jones93a51762018-08-22 18:57:24 -06001002 facs->version = get_acpi_table_revision(FACS);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00001003}
Stefan Reinauer777224c2005-01-19 14:06:41 +00001004
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001005static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001006{
Uwe Hermann622824c2010-11-19 15:14:42 +00001007 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001008
John Zhao2ba303e2019-05-28 16:48:14 -07001009 if (!header)
1010 return;
1011
Uwe Hermann622824c2010-11-19 15:14:42 +00001012 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001013 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001014 memcpy(header->oem_id, oem_id, 6);
1015 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +00001016 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001017
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001018 header->asl_compiler_revision = asl_revision;
Stefan Reinauer688b3852004-01-28 16:56:14 +00001019 header->length = sizeof(acpi_rsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001020 header->revision = get_acpi_table_revision(RSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001021
Uwe Hermann622824c2010-11-19 15:14:42 +00001022 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +00001023
Uwe Hermann622824c2010-11-19 15:14:42 +00001024 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001025 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001026}
1027
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001028static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001029{
Uwe Hermann622824c2010-11-19 15:14:42 +00001030 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001031
John Zhao2ba303e2019-05-28 16:48:14 -07001032 if (!header)
1033 return;
1034
Uwe Hermann622824c2010-11-19 15:14:42 +00001035 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001036 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001037 memcpy(header->oem_id, oem_id, 6);
1038 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001039 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001040
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001041 header->asl_compiler_revision = asl_revision;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001042 header->length = sizeof(acpi_xsdt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001043 header->revision = get_acpi_table_revision(XSDT);
Stefan Reinauer14e22772010-04-27 06:56:47 +00001044
Uwe Hermann622824c2010-11-19 15:14:42 +00001045 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001046
Uwe Hermann622824c2010-11-19 15:14:42 +00001047 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001048 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
1049}
1050
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001051static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
1052 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +00001053{
Stefan Reinauerd18faac2009-11-05 18:06:43 +00001054 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +00001055
Stefan Reinauer688b3852004-01-28 16:56:14 +00001056 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001057 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +00001058
1059 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -07001060 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +00001061
1062 /*
1063 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
1064 *
1065 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
1066 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
1067 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001068 */
1069 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001070 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001071 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -07001072 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Marc Jones93a51762018-08-22 18:57:24 -06001073 rsdp->revision = get_acpi_table_revision(RSDP);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +00001074 }
Uwe Hermann622824c2010-11-19 15:14:42 +00001075
1076 /* Calculate checksums. */
1077 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
1078 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +00001079}
1080
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001081unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1082 acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
zbaocaf494c82012-04-13 13:57:14 +08001083{
1084 acpi_header_t *header = &(hest->header);
1085 acpi_hest_hen_t *hen;
1086 void *pos;
1087 u16 len;
1088
1089 pos = esd;
1090 memset(pos, 0, sizeof(acpi_hest_esd_t));
1091 len = 0;
1092 esd->type = type; /* MCE */
1093 esd->source_id = hest->error_source_count;
1094 esd->flags = 0; /* FIRMWARE_FIRST */
1095 esd->enabled = 1;
1096 esd->prealloc_erecords = 1;
1097 esd->max_section_per_record = 0x1;
1098
1099 len += sizeof(acpi_hest_esd_t);
1100 pos = esd + 1;
1101
1102 switch (type) {
1103 case 0: /* MCE */
1104 break;
1105 case 1: /* CMC */
1106 hen = (acpi_hest_hen_t *) (pos);
1107 memset(pos, 0, sizeof(acpi_hest_hen_t));
1108 hen->type = 3; /* SCI? */
1109 hen->length = sizeof(acpi_hest_hen_t);
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001110 hen->conf_we = 0; /* Configuration Write Enable. */
zbaocaf494c82012-04-13 13:57:14 +08001111 hen->poll_interval = 0;
1112 hen->vector = 0;
1113 hen->sw2poll_threshold_val = 0;
1114 hen->sw2poll_threshold_win = 0;
1115 hen->error_threshold_val = 0;
1116 hen->error_threshold_win = 0;
1117 len += sizeof(acpi_hest_hen_t);
1118 pos = hen + 1;
1119 break;
1120 case 2: /* NMI */
1121 case 6: /* AER Root Port */
1122 case 7: /* AER Endpoint */
1123 case 8: /* AER Bridge */
1124 case 9: /* Generic Hardware Error Source. */
1125 /* TODO: */
1126 break;
1127 default:
1128 printk(BIOS_DEBUG, "Invalid type of Error Source.");
1129 break;
1130 }
Lee Leahy024b13d2017-03-16 13:41:11 -07001131 hest->error_source_count++;
zbaocaf494c82012-04-13 13:57:14 +08001132
1133 memcpy(pos, data, data_len);
1134 len += data_len;
John Zhao2ba303e2019-05-28 16:48:14 -07001135 if (header)
1136 header->length += len;
zbaocaf494c82012-04-13 13:57:14 +08001137
1138 return len;
1139}
1140
1141/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +01001142void acpi_write_hest(acpi_hest_t *hest,
1143 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +08001144{
1145 acpi_header_t *header = &(hest->header);
1146
1147 memset(hest, 0, sizeof(acpi_hest_t));
1148
John Zhao2ba303e2019-05-28 16:48:14 -07001149 if (!header)
1150 return;
1151
zbaocaf494c82012-04-13 13:57:14 +08001152 memcpy(header->signature, "HEST", 4);
1153 memcpy(header->oem_id, OEM_ID, 6);
1154 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1155 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001156 header->asl_compiler_revision = asl_revision;
zbaocaf494c82012-04-13 13:57:14 +08001157 header->length += sizeof(acpi_hest_t);
Marc Jones93a51762018-08-22 18:57:24 -06001158 header->revision = get_acpi_table_revision(HEST);
zbaocaf494c82012-04-13 13:57:14 +08001159
1160 acpi_fill_hest(hest);
1161
1162 /* Calculate checksums. */
1163 header->checksum = acpi_checksum((void *)hest, header->length);
1164}
1165
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001166/* ACPI 3.0b */
1167void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length)
1168{
1169 acpi_header_t *header = &(bert->header);
1170
1171 memset(bert, 0, sizeof(acpi_bert_t));
1172
John Zhao2ba303e2019-05-28 16:48:14 -07001173 if (!header)
1174 return;
1175
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001176 memcpy(header->signature, "BERT", 4);
1177 memcpy(header->oem_id, OEM_ID, 6);
1178 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1179 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUASf8f2e8c2019-02-25 15:42:07 +01001180 header->asl_compiler_revision = asl_revision;
Marshall Dawson1d8d3692018-09-04 13:45:26 -06001181 header->length += sizeof(acpi_bert_t);
1182 header->revision = get_acpi_table_revision(BERT);
1183
1184 bert->error_region = region;
1185 bert->region_length = length;
1186
1187 /* Calculate checksums. */
1188 header->checksum = acpi_checksum((void *)bert, header->length);
1189}
1190
Julius Wernercd49cce2019-03-05 16:53:33 -08001191#if CONFIG(COMMON_FADT)
Lee Leahy024b13d2017-03-16 13:41:11 -07001192void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001193{
1194 acpi_header_t *header = &(fadt->header);
1195
1196 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
John Zhao2ba303e2019-05-28 16:48:14 -07001197
1198 if (!header)
1199 return;
1200
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001201 memcpy(header->signature, "FACP", 4);
1202 header->length = sizeof(acpi_fadt_t);
Marc Jones93a51762018-08-22 18:57:24 -06001203 header->revision = get_acpi_table_revision(FADT);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001204 memcpy(header->oem_id, OEM_ID, 6);
1205 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1206 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +01001207 header->asl_compiler_revision = asl_revision;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001208
1209 fadt->firmware_ctrl = (unsigned long) facs;
1210 fadt->dsdt = (unsigned long) dsdt;
1211
1212 fadt->x_firmware_ctl_l = (unsigned long)facs;
1213 fadt->x_firmware_ctl_h = 0;
1214 fadt->x_dsdt_l = (unsigned long)dsdt;
1215 fadt->x_dsdt_h = 0;
1216
Julius Wernercd49cce2019-03-05 16:53:33 -08001217 if (CONFIG(SYSTEM_TYPE_CONVERTIBLE) ||
1218 CONFIG(SYSTEM_TYPE_LAPTOP))
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001219 fadt->preferred_pm_profile = PM_MOBILE;
Julius Wernercd49cce2019-03-05 16:53:33 -08001220 else if (CONFIG(SYSTEM_TYPE_DETACHABLE) ||
1221 CONFIG(SYSTEM_TYPE_TABLET))
Duncan Lauriefa9c6f12019-02-07 11:30:06 -08001222 fadt->preferred_pm_profile = PM_TABLET;
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001223 else
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001224 fadt->preferred_pm_profile = PM_DESKTOP;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001225
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +02001226 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +02001227
1228 header->checksum =
1229 acpi_checksum((void *) fadt, header->length);
1230}
1231#endif
1232
Aaron Durbin64031672018-04-21 14:45:32 -06001233unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001234{
1235 return 0;
1236}
1237
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001238unsigned long write_acpi_tables(unsigned long start)
1239{
1240 unsigned long current;
1241 acpi_rsdp_t *rsdp;
1242 acpi_rsdt_t *rsdt;
1243 acpi_xsdt_t *xsdt;
1244 acpi_fadt_t *fadt;
1245 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001246 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001247 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001248 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001249 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001250 acpi_tcpa_t *tcpa;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001251 acpi_tpm2_t *tpm2;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001252 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +11001253 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001254 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001255 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001256 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001257
1258 current = start;
1259
1260 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -06001261 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001262
Vladimir Serbinenko41877d82014-09-01 22:18:01 +02001263 fw = fw_cfg_acpi_tables(current);
1264 if (fw)
1265 return fw;
1266
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +02001267 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001268 CONFIG_CBFS_PREFIX "/dsdt.aml",
1269 CBFS_TYPE_RAW, &dsdt_size);
1270 if (!dsdt_file) {
1271 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
1272 return current;
1273 }
1274
1275 if (dsdt_file->length > dsdt_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001276 || dsdt_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001277 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
1278 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
1279 return current;
1280 }
1281
Aaron Durbin899d13d2015-05-15 23:39:23 -05001282 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001283 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001284 if (slic_file
1285 && (slic_file->length > slic_size
Elyes HAOUAS7d87e762016-10-03 22:11:07 +02001286 || slic_file->length < sizeof(acpi_header_t)
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +02001287 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001288 slic_file = 0;
1289 }
1290
1291 if (slic_file) {
1292 memcpy(oem_id, slic_file->oem_id, 6);
1293 memcpy(oem_table_id, slic_file->oem_table_id, 8);
1294 } else {
1295 memcpy(oem_id, OEM_ID, 6);
1296 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
1297 }
1298
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001299 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
1300
1301 /* We need at least an RSDP and an RSDT Table */
1302 rsdp = (acpi_rsdp_t *) current;
1303 current += sizeof(acpi_rsdp_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001304 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001305 rsdt = (acpi_rsdt_t *) current;
1306 current += sizeof(acpi_rsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001307 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001308 xsdt = (acpi_xsdt_t *) current;
1309 current += sizeof(acpi_xsdt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001310 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001311
1312 /* clear all table memory */
1313 memset((void *) start, 0, current - start);
1314
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001315 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
1316 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
1317 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001318
1319 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Felix Heldc4697122019-06-20 13:50:17 +02001320 current = ALIGN_UP(current, 64);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001321 facs = (acpi_facs_t *) current;
1322 current += sizeof(acpi_facs_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001323 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001324 acpi_create_facs(facs);
1325
1326 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
1327 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001328 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001329 if (dsdt->length >= sizeof(acpi_header_t)) {
1330 current += sizeof(acpi_header_t);
1331
1332 acpigen_set_current((char *) current);
1333 for (dev = all_devices; dev; dev = dev->next)
Lee Leahy9c7c6f72017-03-16 11:24:09 -07001334 if (dev->ops && dev->ops->acpi_inject_dsdt_generator)
Alexander Couzensa90dad12015-04-12 21:49:46 +02001335 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001336 current = (unsigned long) acpigen_get_current();
1337 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +02001338 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +02001339 dsdt->length - sizeof(acpi_header_t));
1340 current += dsdt->length - sizeof(acpi_header_t);
1341
1342 /* (Re)calculate length and checksum. */
1343 dsdt->length = current - (unsigned long)dsdt;
1344 dsdt->checksum = 0;
1345 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
1346 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001347
Aaron Durbin07a1b282015-12-10 17:07:38 -06001348 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001349
1350 printk(BIOS_DEBUG, "ACPI: * FADT\n");
1351 fadt = (acpi_fadt_t *) current;
1352 current += sizeof(acpi_fadt_t);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001353 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001354
1355 acpi_create_fadt(fadt, facs, dsdt);
1356 acpi_add_table(rsdp, fadt);
1357
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001358 if (slic_file) {
1359 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
1360 slic = (acpi_header_t *)current;
1361 memcpy(slic, slic_file, slic_file->length);
1362 current += slic_file->length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001363 current = acpi_align_current(current);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +01001364 acpi_add_table(rsdp, slic);
1365 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001366
1367 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1368 ssdt = (acpi_header_t *)current;
1369 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001370 if (ssdt->length > sizeof(acpi_header_t)) {
1371 current += ssdt->length;
1372 acpi_add_table(rsdp, ssdt);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001373 current = acpi_align_current(current);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +02001374 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001375
1376 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
1377 mcfg = (acpi_mcfg_t *) current;
1378 acpi_create_mcfg(mcfg);
1379 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
1380 current += mcfg->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -06001381 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001382 acpi_add_table(rsdp, mcfg);
1383 }
1384
Julius Wernercd49cce2019-03-05 16:53:33 -08001385 if (CONFIG(TPM1)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001386 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
1387 tcpa = (acpi_tcpa_t *) current;
1388 acpi_create_tcpa(tcpa);
1389 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
1390 current += tcpa->header.length;
1391 current = acpi_align_current(current);
1392 acpi_add_table(rsdp, tcpa);
1393 }
1394 }
1395
Julius Wernercd49cce2019-03-05 16:53:33 -08001396 if (CONFIG(TPM2)) {
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001397 printk(BIOS_DEBUG, "ACPI: * TPM2\n");
1398 tpm2 = (acpi_tpm2_t *) current;
1399 acpi_create_tpm2(tpm2);
1400 if (tpm2->header.length >= sizeof(acpi_tpm2_t)) {
1401 current += tpm2->header.length;
1402 current = acpi_align_current(current);
1403 acpi_add_table(rsdp, tpm2);
1404 }
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +02001405 }
1406
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001407 printk(BIOS_DEBUG, "ACPI: * MADT\n");
1408
1409 madt = (acpi_madt_t *) current;
1410 acpi_create_madt(madt);
1411 if (madt->header.length > sizeof(acpi_madt_t)) {
Lee Leahy024b13d2017-03-16 13:41:11 -07001412 current += madt->header.length;
1413 acpi_add_table(rsdp, madt);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001414 }
Aaron Durbin07a1b282015-12-10 17:07:38 -06001415 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001416
1417 printk(BIOS_DEBUG, "current = %lx\n", current);
1418
1419 for (dev = all_devices; dev; dev = dev->next) {
1420 if (dev->ops && dev->ops->write_acpi_tables) {
Lee Leahy6f80ccc2017-03-16 15:18:22 -07001421 current = dev->ops->write_acpi_tables(dev, current,
1422 rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -06001423 current = acpi_align_current(current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001424 }
1425 }
1426
1427 printk(BIOS_INFO, "ACPI: done.\n");
1428 return current;
1429}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +02001430
Rudolf Marek33cafe52009-04-13 18:07:02 +00001431static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1432{
1433 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1434 return NULL;
1435
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001436 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001437
1438 if (acpi_checksum((void *)rsdp, 20) != 0)
1439 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001440 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001441
1442 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1443 rsdp->length) != 0))
1444 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001445 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001446
1447 return rsdp;
1448}
1449
Rudolf Marek33cafe52009-04-13 18:07:02 +00001450void *acpi_find_wakeup_vector(void)
1451{
1452 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001453 acpi_rsdt_t *rsdt;
1454 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001455 acpi_fadt_t *fadt = NULL;
Kyösti Mälkki072d436b2016-06-17 08:44:40 +03001456 acpi_rsdp_t *rsdp = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001457 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001458 int i;
1459
Rudolf Marek33cafe52009-04-13 18:07:02 +00001460 if (!acpi_is_wakeup())
1461 return NULL;
1462
Uwe Hermann622824c2010-11-19 15:14:42 +00001463 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001464
Uwe Hermann622824c2010-11-19 15:14:42 +00001465 /* Find RSDP. */
1466 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
Lee Leahy0b5678f2017-03-16 16:01:40 -07001467 rsdp = valid_rsdp((acpi_rsdp_t *)p);
1468 if (rsdp)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001469 break;
1470 }
1471
Angel Pons98a68ad2018-11-04 12:25:25 +01001472 if (rsdp == NULL) {
1473 printk(BIOS_ALERT,
1474 "No RSDP found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001475 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001476 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001477
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001478 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001479 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001480
Uwe Hermann622824c2010-11-19 15:14:42 +00001481 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001482 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001483
Uwe Hermann622824c2010-11-19 15:14:42 +00001484 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001485 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001486 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001487 break;
1488 fadt = NULL;
1489 }
1490
Angel Pons98a68ad2018-11-04 12:25:25 +01001491 if (fadt == NULL) {
1492 printk(BIOS_ALERT,
1493 "No FADT found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001494 return NULL;
Angel Pons98a68ad2018-11-04 12:25:25 +01001495 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001496
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001497 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001498 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001499
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001500 if (facs == NULL) {
Angel Pons98a68ad2018-11-04 12:25:25 +01001501 printk(BIOS_ALERT,
1502 "No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001503 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001504 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001505
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001506 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001507 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001508 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001509
Rudolf Marek33cafe52009-04-13 18:07:02 +00001510 return wake_vec;
1511}
1512
Aaron Durbin64031672018-04-21 14:45:32 -06001513__weak int acpi_get_gpe(int gpe)
Duncan Laurie1f6e6812016-09-19 12:04:19 -07001514{
1515 return -1; /* implemented by SOC */
1516}
Marc Jones93a51762018-08-22 18:57:24 -06001517
1518int get_acpi_table_revision(enum acpi_tables table)
1519{
1520 switch (table) {
1521 case FADT:
1522 return ACPI_FADT_REV_ACPI_3_0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001523 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 -06001524 return 2;
Marc Jones93a51762018-08-22 18:57:24 -06001525 case MCFG:
1526 return 1;
1527 case TCPA:
1528 return 2;
Philipp Deppenwiese296164e02018-10-18 15:39:34 +02001529 case TPM2:
1530 return 4;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001531 case SSDT: /* ACPI 3.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001532 return 2;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001533 case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 upto 6.3: 3 */
Marc Jones93a51762018-08-22 18:57:24 -06001534 return 1; /* TODO Should probably be upgraded to 2 */
1535 case DMAR:
1536 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001537 case SLIT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001538 return 1;
Patrick Rudolph9d98e5a2019-06-14 19:00:04 +02001539 case SPMI: /* IMPI 2.0 */
1540 return 5;
Marc Jones93a51762018-08-22 18:57:24 -06001541 case HPET: /* Currently 1. Table added in ACPI 2.0. */
1542 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001543 case VFCT: /* ACPI 2.0/3.0/4.0: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001544 return 1;
1545 case IVRS:
1546 return IVRS_FORMAT_FIXED;
1547 case DBG2:
1548 return 0;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001549 case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001550 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001551 case RSDT: /* ACPI 1.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001552 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001553 case XSDT: /* ACPI 2.0 upto 6.3: 1 */
Marc Jones93a51762018-08-22 18:57:24 -06001554 return 1;
Elyes HAOUASf288b392018-11-11 15:22:30 +01001555 case RSDP: /* ACPI 2.0 upto 6.3: 2 */
Marc Jones93a51762018-08-22 18:57:24 -06001556 return 2;
1557 case HEST:
1558 return 1;
1559 case NHLT:
1560 return 5;
Marshall Dawson44705c62018-09-04 13:47:15 -06001561 case BERT:
1562 return 1;
Marc Jones93a51762018-08-22 18:57:24 -06001563 default:
1564 return -1;
1565 }
1566 return -1;
1567}