blob: 55995c95425deab02e5a70a3482ab3313fc8cbb4 [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
Stefan Reinauer777224c2005-01-19 14:06:41 +00009 *
Stefan Reinauer14e22772010-04-27 06:56:47 +000010 * ACPI FADT, FACS, and DSDT table support added by
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000011 * Nick Barker <nick.barker9@btinternet.com>, and those portions
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000012 * Copyright (C) 2004 Nick Barker
Stefan Reinauerf622d592005-11-26 16:56:05 +000013 *
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000014 * Copyright (C) 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
Stefan Reinauerd6edf7a2006-01-05 00:19:52 +000015 * 2005.9 yhlu add SRAT table generation
Stefan Reinauer777224c2005-01-19 14:06:41 +000016 */
17
Stefan Reinauer14e22772010-04-27 06:56:47 +000018/*
Stefan Reinauer777224c2005-01-19 14:06:41 +000019 * Each system port implementing ACPI has to provide two functions:
Stefan Reinauer14e22772010-04-27 06:56:47 +000020 *
Stefan Reinauer777224c2005-01-19 14:06:41 +000021 * write_acpi_tables()
22 * acpi_dump_apics()
Stefan Reinauer14e22772010-04-27 06:56:47 +000023 *
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000024 * See Kontron 986LCD-M port for a good example of an ACPI implementation
25 * in coreboot.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000026 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000027
28#include <console/console.h>
29#include <string.h>
30#include <arch/acpi.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000031#include <arch/acpigen.h>
Stefan Reinauer777224c2005-01-19 14:06:41 +000032#include <device/pci.h>
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000033#include <cbmem.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>
Duncan Lauriecde78012011-10-19 15:32:39 -070037#include <timestamp.h>
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +020038#include <romstage_handoff.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000039
Patrick Georgi9aeb6942012-10-05 21:54:38 +020040/* FIXME: Kconfig doesn't support overridable defaults :-( */
41#ifndef CONFIG_HPET_MIN_TICKS
42#define CONFIG_HPET_MIN_TICKS 0x1000
43#endif
44
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000045u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000046{
Uwe Hermann622824c2010-11-19 15:14:42 +000047 u8 ret = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +000048 while (length--) {
49 ret += *table;
50 table++;
51 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000052 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000053}
54
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000055/**
Uwe Hermann622824c2010-11-19 15:14:42 +000056 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
57 * and checksum.
Stefan Reinauer06feb882004-02-03 16:11:35 +000058 */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000059void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000060{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000061 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000062 acpi_rsdt_t *rsdt;
63 acpi_xsdt_t *xsdt = NULL;
64
Uwe Hermann622824c2010-11-19 15:14:42 +000065 /* The RSDT is mandatory... */
Stefan Reinauerdefee172015-06-18 01:11:19 -070066 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000067
Uwe Hermann622824c2010-11-19 15:14:42 +000068 /* ...while the XSDT is not. */
69 if (rsdp->xsdt_address)
Stefan Reinauerdefee172015-06-18 01:11:19 -070070 xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address);
Stefan Reinauer14e22772010-04-27 06:56:47 +000071
Uwe Hermann622824c2010-11-19 15:14:42 +000072 /* This should always be MAX_ACPI_TABLES. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000073 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauer14e22772010-04-27 06:56:47 +000074
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000075 for (i = 0; i < entries_num; i++) {
Uwe Hermann622824c2010-11-19 15:14:42 +000076 if (rsdt->entry[i] == 0)
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000077 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000078 }
79
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000080 if (i >= entries_num) {
Uwe Hermann622824c2010-11-19 15:14:42 +000081 printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +030082 "too many tables.\n");
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000083 return;
84 }
85
Uwe Hermann622824c2010-11-19 15:14:42 +000086 /* Add table to the RSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -070087 rsdt->entry[i] = (uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000088
Uwe Hermann622824c2010-11-19 15:14:42 +000089 /* Fix RSDT length or the kernel will assume invalid entries. */
90 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000091
Uwe Hermann622824c2010-11-19 15:14:42 +000092 /* Re-calculate checksum. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000093 rsdt->header.checksum = 0; /* Hope this won't get optimized away */
Uwe Hermann622824c2010-11-19 15:14:42 +000094 rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000095
Uwe Hermann622824c2010-11-19 15:14:42 +000096 /*
97 * And now the same thing for the XSDT. We use the same index as for
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000098 * now we want the XSDT and RSDT to always be in sync in coreboot.
99 */
100 if (xsdt) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000101 /* Add table to the XSDT. */
Stefan Reinauerdefee172015-06-18 01:11:19 -0700102 xsdt->entry[i] = (u64)(uintptr_t)table;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000103
Uwe Hermann622824c2010-11-19 15:14:42 +0000104 /* Fix XSDT length. */
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000105 xsdt->header.length = sizeof(acpi_header_t) +
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300106 (sizeof(u64) * (i + 1));
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000107
Uwe Hermann622824c2010-11-19 15:14:42 +0000108 /* Re-calculate checksum. */
109 xsdt->header.checksum = 0;
110 xsdt->header.checksum = acpi_checksum((u8 *)xsdt,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300111 xsdt->header.length);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000112 }
113
Uwe Hermann622824c2010-11-19 15:14:42 +0000114 printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300115 i + 1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000116}
117
Uwe Hermann622824c2010-11-19 15:14:42 +0000118int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300119 u16 seg_nr, u8 start, u8 end)
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000120{
Vladimir Serbinenko60fccdc2014-10-05 11:05:16 +0200121 memset(mmconfig, 0, sizeof(*mmconfig));
Rudolf Mareke6409f22007-11-03 12:50:26 +0000122 mmconfig->base_address = base;
123 mmconfig->base_reserved = 0;
124 mmconfig->pci_segment_group_number = seg_nr;
125 mmconfig->start_bus_number = start;
126 mmconfig->end_bus_number = end;
Uwe Hermann622824c2010-11-19 15:14:42 +0000127
128 return sizeof(acpi_mcfg_mmconfig_t);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000129}
130
Stefan Reinauer777224c2005-01-19 14:06:41 +0000131int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000132{
Uwe Hermann622824c2010-11-19 15:14:42 +0000133 lapic->type = 0; /* Local APIC structure */
134 lapic->length = sizeof(acpi_madt_lapic_t);
135 lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
136 lapic->processor_id = cpu;
137 lapic->apic_id = apic;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000138
Uwe Hermann622824c2010-11-19 15:14:42 +0000139 return lapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000140}
141
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000142unsigned long acpi_create_madt_lapics(unsigned long current)
143{
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100144 struct device *cpu;
Duncan Laurie11290c42012-10-03 19:07:05 -0700145 int index = 0;
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000146
Uwe Hermann622824c2010-11-19 15:14:42 +0000147 for (cpu = all_devices; cpu; cpu = cpu->next) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000148 if ((cpu->path.type != DEVICE_PATH_APIC) ||
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800149 (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000150 continue;
151 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000152 if (!cpu->enabled)
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000153 continue;
Uwe Hermann622824c2010-11-19 15:14:42 +0000154 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
Duncan Laurie11290c42012-10-03 19:07:05 -0700155 index, cpu->path.apic.apic_id);
156 index++;
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000157 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000158
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000159 return current;
160}
161
Uwe Hermann622824c2010-11-19 15:14:42 +0000162int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300163 u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000164{
Uwe Hermann622824c2010-11-19 15:14:42 +0000165 ioapic->type = 1; /* I/O APIC structure */
166 ioapic->length = sizeof(acpi_madt_ioapic_t);
167 ioapic->reserved = 0x00;
168 ioapic->gsi_base = gsi_base;
169 ioapic->ioapic_id = id;
170 ioapic->ioapic_addr = addr;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000171
Uwe Hermann622824c2010-11-19 15:14:42 +0000172 return ioapic->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000173}
174
Stefan Reinauer777224c2005-01-19 14:06:41 +0000175int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000176 u8 bus, u8 source, u32 gsirq, u16 flags)
177{
Uwe Hermann622824c2010-11-19 15:14:42 +0000178 irqoverride->type = 2; /* Interrupt source override */
179 irqoverride->length = sizeof(acpi_madt_irqoverride_t);
180 irqoverride->bus = bus;
181 irqoverride->source = source;
182 irqoverride->gsirq = gsirq;
183 irqoverride->flags = flags;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000184
Uwe Hermann622824c2010-11-19 15:14:42 +0000185 return irqoverride->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000186}
187
Stefan Reinauer777224c2005-01-19 14:06:41 +0000188int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Cristian Măgherușan-Stanciuba482812011-07-02 00:57:07 +0300189 u16 flags, u8 lint)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000190{
Uwe Hermann622824c2010-11-19 15:14:42 +0000191 lapic_nmi->type = 4; /* Local APIC NMI structure */
192 lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
193 lapic_nmi->flags = flags;
194 lapic_nmi->processor_id = cpu;
195 lapic_nmi->lint = lint;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000196
Uwe Hermann622824c2010-11-19 15:14:42 +0000197 return lapic_nmi->length;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000198}
199
Stefan Reinauer777224c2005-01-19 14:06:41 +0000200void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000201{
Uwe Hermann622824c2010-11-19 15:14:42 +0000202 acpi_header_t *header = &(madt->header);
203 unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000204
Stefan Reinauer06feb882004-02-03 16:11:35 +0000205 memset((void *)madt, 0, sizeof(acpi_madt_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000206
Uwe Hermann622824c2010-11-19 15:14:42 +0000207 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000208 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000209 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000210 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000211 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000212
Stefan Reinauer06feb882004-02-03 16:11:35 +0000213 header->length = sizeof(acpi_madt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000214 header->revision = 1; /* ACPI 1.0/2.0: 1, ACPI 3.0: 2, ACPI 4.0: 3 */
Stefan Reinauer06feb882004-02-03 16:11:35 +0000215
Uwe Hermann622824c2010-11-19 15:14:42 +0000216 madt->lapic_addr = LOCAL_APIC_ADDR;
217 madt->flags = 0x1; /* PCAT_COMPAT */
Stefan Reinauer06feb882004-02-03 16:11:35 +0000218
Stefan Reinauerf622d592005-11-26 16:56:05 +0000219 current = acpi_fill_madt(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000220
Uwe Hermann622824c2010-11-19 15:14:42 +0000221 /* (Re)calculate length and checksum. */
222 header->length = current - (unsigned long)madt;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000223
Uwe Hermann622824c2010-11-19 15:14:42 +0000224 header->checksum = acpi_checksum((void *)madt, header->length);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000225}
226
Uwe Hermann622824c2010-11-19 15:14:42 +0000227/* MCFG is defined in the PCI Firmware Specification 3.0. */
Rudolf Mareke6409f22007-11-03 12:50:26 +0000228void acpi_create_mcfg(acpi_mcfg_t *mcfg)
229{
Uwe Hermann622824c2010-11-19 15:14:42 +0000230 acpi_header_t *header = &(mcfg->header);
231 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000232
Rudolf Mareke6409f22007-11-03 12:50:26 +0000233 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000234
Uwe Hermann622824c2010-11-19 15:14:42 +0000235 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000236 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000237 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000238 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000239 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000240
Rudolf Mareke6409f22007-11-03 12:50:26 +0000241 header->length = sizeof(acpi_mcfg_t);
242 header->revision = 1;
243
244 current = acpi_fill_mcfg(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000245
Uwe Hermann622824c2010-11-19 15:14:42 +0000246 /* (Re)calculate length and checksum. */
247 header->length = current - (unsigned long)mcfg;
248 header->checksum = acpi_checksum((void *)mcfg, header->length);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000249}
250
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200251static void *get_tcpa_log(u32 *size)
252{
253 const struct cbmem_entry *ce;
254 const u32 tcpa_default_log_len = 0x10000;
255 void *lasa;
256 ce = cbmem_entry_find(CBMEM_ID_TCPA_LOG);
257 if (ce) {
258 lasa = cbmem_entry_start(ce);
259 *size = cbmem_entry_size(ce);
260 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
261 return lasa;
262 }
263 lasa = cbmem_add(CBMEM_ID_TCPA_LOG, tcpa_default_log_len);
264 if (!lasa) {
265 printk(BIOS_ERR, "TCPA log creation failed\n");
266 return NULL;
267 }
268
269 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
270 memset (lasa, 0, tcpa_default_log_len);
271
272 *size = tcpa_default_log_len;
273 return lasa;
274}
275
276static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
277{
278 acpi_header_t *header = &(tcpa->header);
279 u32 tcpa_log_len;
280 void *lasa;
281
282 memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
283
284 lasa = get_tcpa_log(&tcpa_log_len);
285 if (!lasa) {
286 return;
287 }
288
289 /* Fill out header fields. */
290 memcpy(header->signature, "TCPA", 4);
291 memcpy(header->oem_id, OEM_ID, 6);
292 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
293 memcpy(header->asl_compiler_id, ASLC, 4);
294
295 header->length = sizeof(acpi_tcpa_t);
296 header->revision = 2;
297
298 tcpa->platform_class = 0;
299 tcpa->laml = tcpa_log_len;
Stefan Reinauerdefee172015-06-18 01:11:19 -0700300 tcpa->lasa = (uintptr_t) lasa;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200301
302 /* Calculate checksum. */
303 header->checksum = acpi_checksum((void *)tcpa, header->length);
304}
305
Myles Watson3fe6b702009-10-09 20:13:43 +0000306void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000307{
Uwe Hermann622824c2010-11-19 15:14:42 +0000308 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
309
Rudolf Marek293b5f52009-02-01 18:35:15 +0000310 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000311
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000312 memcpy(&ssdt->signature, "SSDT", 4);
Uwe Hermann622824c2010-11-19 15:14:42 +0000313 ssdt->revision = 2; /* ACPI 1.0/2.0: ?, ACPI 3.0/4.0: 2 */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000314 memcpy(&ssdt->oem_id, OEM_ID, 6);
315 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
316 ssdt->oem_revision = 42;
Uwe Hermann622824c2010-11-19 15:14:42 +0000317 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000318 ssdt->asl_compiler_revision = 42;
319 ssdt->length = sizeof(acpi_header_t);
320
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000321 acpigen_set_current((char *) current);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200322 {
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100323 struct device *dev;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200324 for (dev = all_devices; dev; dev = dev->next)
325 if (dev->ops && dev->ops->acpi_fill_ssdt_generator) {
Alexander Couzens5eea4582015-04-12 22:18:55 +0200326 dev->ops->acpi_fill_ssdt_generator(dev);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200327 }
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200328 current = (unsigned long) acpigen_get_current();
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200329 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000330
Uwe Hermann622824c2010-11-19 15:14:42 +0000331 /* (Re)calculate length and checksum. */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000332 ssdt->length = current - (unsigned long)ssdt;
333 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
334}
335
Stefan Reinauerf622d592005-11-26 16:56:05 +0000336int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
337{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000338 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000339
Uwe Hermann622824c2010-11-19 15:14:42 +0000340 lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
341 lapic->length = sizeof(acpi_srat_lapic_t);
342 lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
343 lapic->proximity_domain_7_0 = node;
344 /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
345 lapic->apic_id = apic;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000346
Uwe Hermann622824c2010-11-19 15:14:42 +0000347 return lapic->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000348}
349
Uwe Hermann622824c2010-11-19 15:14:42 +0000350int 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 +0300351 u32 flags)
Stefan Reinauerf622d592005-11-26 16:56:05 +0000352{
Uwe Hermann622824c2010-11-19 15:14:42 +0000353 mem->type = 1; /* Memory affinity structure */
354 mem->length = sizeof(acpi_srat_mem_t);
355 mem->base_address_low = (basek << 10);
356 mem->base_address_high = (basek >> (32 - 10));
357 mem->length_low = (sizek << 10);
358 mem->length_high = (sizek >> (32 - 10));
359 mem->proximity_domain = node;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000360 mem->flags = flags;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000361
Uwe Hermann622824c2010-11-19 15:14:42 +0000362 return mem->length;
Stefan Reinauerf622d592005-11-26 16:56:05 +0000363}
364
Uwe Hermann622824c2010-11-19 15:14:42 +0000365/* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200366void acpi_create_srat(acpi_srat_t *srat,
367 unsigned long (*acpi_fill_srat)(unsigned long current))
Stefan Reinauerf622d592005-11-26 16:56:05 +0000368{
Uwe Hermann622824c2010-11-19 15:14:42 +0000369 acpi_header_t *header = &(srat->header);
370 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000371
Uwe Hermann622824c2010-11-19 15:14:42 +0000372 memset((void *)srat, 0, sizeof(acpi_srat_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000373
Uwe Hermann622824c2010-11-19 15:14:42 +0000374 /* Fill out header fields. */
375 memcpy(header->signature, "SRAT", 4);
376 memcpy(header->oem_id, OEM_ID, 6);
377 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
378 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000379
Uwe Hermann622824c2010-11-19 15:14:42 +0000380 header->length = sizeof(acpi_srat_t);
381 header->revision = 1; /* ACPI 1.0: N/A, 2.0: 1, 3.0: 2, 4.0: 3 */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000382
Uwe Hermann622824c2010-11-19 15:14:42 +0000383 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
Stefan Reinauerf622d592005-11-26 16:56:05 +0000384
Uwe Hermann622824c2010-11-19 15:14:42 +0000385 current = acpi_fill_srat(current);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000386
Uwe Hermann622824c2010-11-19 15:14:42 +0000387 /* (Re)calculate length and checksum. */
388 header->length = current - (unsigned long)srat;
389 header->checksum = acpi_checksum((void *)srat, header->length);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000390}
391
Nico Hubere561f352015-10-26 11:51:25 +0100392void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +0100393 unsigned long (*acpi_fill_dmar) (unsigned long))
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200394{
395 acpi_header_t *header = &(dmar->header);
396 unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
397
398 memset((void *)dmar, 0, sizeof(acpi_dmar_t));
399
400 /* Fill out header fields. */
401 memcpy(header->signature, "DMAR", 4);
402 memcpy(header->oem_id, OEM_ID, 6);
403 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
404 memcpy(header->asl_compiler_id, ASLC, 4);
405
406 header->length = sizeof(acpi_dmar_t);
407 header->revision = 1;
408
409 dmar->host_address_width = 40 - 1; /* FIXME: == MTRR size? */
Nico Hubere561f352015-10-26 11:51:25 +0100410 dmar->flags = flags;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200411
412 current = acpi_fill_dmar(current);
413
414 /* (Re)calculate length and checksum. */
415 header->length = current - (unsigned long)dmar;
416 header->checksum = acpi_checksum((void *)dmar, header->length);
417}
418
419unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
420 u16 segment, u32 bar)
421{
422 dmar_entry_t *drhd = (dmar_entry_t *)current;
423 memset(drhd, 0, sizeof(*drhd));
424 drhd->type = DMAR_DRHD;
425 drhd->length = sizeof(*drhd); /* will be fixed up later */
426 drhd->flags = flags;
427 drhd->segment = segment;
428 drhd->bar = bar;
429
430 return drhd->length;
431}
432
433void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
434{
435 dmar_entry_t *drhd = (dmar_entry_t *)base;
436 drhd->length = current - base;
437}
438
Nico Huber6c4751d2015-10-26 12:03:54 +0100439static unsigned long acpi_create_dmar_drhd_ds(unsigned long current,
440 enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200441{
Nico Huber6c4751d2015-10-26 12:03:54 +0100442 /* we don't support longer paths yet */
443 const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
444
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200445 dev_scope_t *ds = (dev_scope_t *)current;
Nico Huber6c4751d2015-10-26 12:03:54 +0100446 memset(ds, 0, dev_scope_length);
447 ds->type = type;
448 ds->length = dev_scope_length;
449 ds->enumeration = enumeration_id;
450 ds->start_bus = bus;
451 ds->path[0].dev = dev;
452 ds->path[0].fn = fn;
Patrick Georgi3b590ff2012-09-11 15:21:01 +0200453
454 return ds->length;
455}
456
Nico Huber6c4751d2015-10-26 12:03:54 +0100457unsigned long acpi_create_dmar_drhd_ds_pci(unsigned long current, u8 bus,
458 u8 dev, u8 fn)
459{
460 return acpi_create_dmar_drhd_ds(current,
461 SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
462}
463
464unsigned long acpi_create_dmar_drhd_ds_ioapic(unsigned long current,
465 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
466{
467 return acpi_create_dmar_drhd_ds(current,
468 SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
469}
470
471unsigned long acpi_create_dmar_drhd_ds_msi_hpet(unsigned long current,
472 u8 enumeration_id, u8 bus, u8 dev, u8 fn)
473{
474 return acpi_create_dmar_drhd_ds(current,
475 SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
476}
477
Uwe Hermann622824c2010-11-19 15:14:42 +0000478/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200479void acpi_create_slit(acpi_slit_t *slit,
480 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000481{
Uwe Hermann622824c2010-11-19 15:14:42 +0000482 acpi_header_t *header = &(slit->header);
483 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000484
Uwe Hermann622824c2010-11-19 15:14:42 +0000485 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000486
Uwe Hermann622824c2010-11-19 15:14:42 +0000487 /* Fill out header fields. */
488 memcpy(header->signature, "SLIT", 4);
489 memcpy(header->oem_id, OEM_ID, 6);
490 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
491 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000492
Uwe Hermann622824c2010-11-19 15:14:42 +0000493 header->length = sizeof(acpi_slit_t);
494 header->revision = 1; /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000495
Uwe Hermann622824c2010-11-19 15:14:42 +0000496 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000497
Uwe Hermann622824c2010-11-19 15:14:42 +0000498 /* (Re)calculate length and checksum. */
499 header->length = current - (unsigned long)slit;
500 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000501}
502
Uwe Hermann622824c2010-11-19 15:14:42 +0000503/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000504void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000505{
Uwe Hermann622824c2010-11-19 15:14:42 +0000506 acpi_header_t *header = &(hpet->header);
507 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000508
Stefan Reinauera7648c22004-01-29 17:31:34 +0000509 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000510
Uwe Hermann622824c2010-11-19 15:14:42 +0000511 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000512 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000513 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000514 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000515 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000516
Stefan Reinauer688b3852004-01-28 16:56:14 +0000517 header->length = sizeof(acpi_hpet_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000518 header->revision = 1; /* Currently 1. Table added in ACPI 2.0. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000519
Uwe Hermann622824c2010-11-19 15:14:42 +0000520 /* Fill out HPET address. */
521 addr->space_id = 0; /* Memory */
522 addr->bit_width = 64;
523 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200524 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
525 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000526
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200527 hpet->id = *(unsigned int*)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000528 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200529 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000530
Uwe Hermann622824c2010-11-19 15:14:42 +0000531 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000532}
Uwe Hermann622824c2010-11-19 15:14:42 +0000533
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200534unsigned long acpi_write_hpet(device_t device, unsigned long current, acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200535{
536 acpi_hpet_t *hpet;
537
538 /*
539 * We explicitly add these tables later on:
540 */
541 printk(BIOS_DEBUG, "ACPI: * HPET\n");
542
543 hpet = (acpi_hpet_t *) current;
544 current += sizeof(acpi_hpet_t);
545 current = ALIGN(current, 16);
546 acpi_create_hpet(hpet);
547 acpi_add_table(rsdp, hpet);
548
549 return current;
550}
551
Stefan Reinauer777224c2005-01-19 14:06:41 +0000552void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000553{
Uwe Hermann622824c2010-11-19 15:14:42 +0000554 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000555
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000556 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000557 facs->length = sizeof(acpi_facs_t);
558 facs->hardware_signature = 0;
559 facs->firmware_waking_vector = 0;
560 facs->global_lock = 0;
561 facs->flags = 0;
562 facs->x_firmware_waking_vector_l = 0;
563 facs->x_firmware_waking_vector_h = 0;
Uwe Hermann622824c2010-11-19 15:14:42 +0000564 facs->version = 1; /* ACPI 1.0: 0, ACPI 2.0/3.0: 1, ACPI 4.0: 2 */
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000565}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000566
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100567static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000568{
Uwe Hermann622824c2010-11-19 15:14:42 +0000569 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000570
Uwe Hermann622824c2010-11-19 15:14:42 +0000571 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000572 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100573 memcpy(header->oem_id, oem_id, 6);
574 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000575 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000576
Stefan Reinauer688b3852004-01-28 16:56:14 +0000577 header->length = sizeof(acpi_rsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000578 header->revision = 1; /* ACPI 1.0/2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000579
Uwe Hermann622824c2010-11-19 15:14:42 +0000580 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000581
Uwe Hermann622824c2010-11-19 15:14:42 +0000582 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000583 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000584}
585
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100586static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000587{
Uwe Hermann622824c2010-11-19 15:14:42 +0000588 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000589
Uwe Hermann622824c2010-11-19 15:14:42 +0000590 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000591 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100592 memcpy(header->oem_id, oem_id, 6);
593 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000594 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000595
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000596 header->length = sizeof(acpi_xsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000597 header->revision = 1; /* ACPI 1.0: N/A, 2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000598
Uwe Hermann622824c2010-11-19 15:14:42 +0000599 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000600
Uwe Hermann622824c2010-11-19 15:14:42 +0000601 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000602 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
603}
604
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100605static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
606 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000607{
Stefan Reinauerd18faac2009-11-05 18:06:43 +0000608 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000609
Stefan Reinauer688b3852004-01-28 16:56:14 +0000610 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100611 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +0000612
613 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -0700614 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000615
616 /*
617 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
618 *
619 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
620 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
621 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000622 */
623 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000624 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000625 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -0700626 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000627 rsdp->revision = 2;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000628 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000629
630 /* Calculate checksums. */
631 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
632 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000633}
634
zbaocaf494c82012-04-13 13:57:14 +0800635unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
636{
637 acpi_header_t *header = &(hest->header);
638 acpi_hest_hen_t *hen;
639 void *pos;
640 u16 len;
641
642 pos = esd;
643 memset(pos, 0, sizeof(acpi_hest_esd_t));
644 len = 0;
645 esd->type = type; /* MCE */
646 esd->source_id = hest->error_source_count;
647 esd->flags = 0; /* FIRMWARE_FIRST */
648 esd->enabled = 1;
649 esd->prealloc_erecords = 1;
650 esd->max_section_per_record = 0x1;
651
652 len += sizeof(acpi_hest_esd_t);
653 pos = esd + 1;
654
655 switch (type) {
656 case 0: /* MCE */
657 break;
658 case 1: /* CMC */
659 hen = (acpi_hest_hen_t *) (pos);
660 memset(pos, 0, sizeof(acpi_hest_hen_t));
661 hen->type = 3; /* SCI? */
662 hen->length = sizeof(acpi_hest_hen_t);
663 hen->conf_we = 0; /* Configuration Write Enable. */
664 hen->poll_interval = 0;
665 hen->vector = 0;
666 hen->sw2poll_threshold_val = 0;
667 hen->sw2poll_threshold_win = 0;
668 hen->error_threshold_val = 0;
669 hen->error_threshold_win = 0;
670 len += sizeof(acpi_hest_hen_t);
671 pos = hen + 1;
672 break;
673 case 2: /* NMI */
674 case 6: /* AER Root Port */
675 case 7: /* AER Endpoint */
676 case 8: /* AER Bridge */
677 case 9: /* Generic Hardware Error Source. */
678 /* TODO: */
679 break;
680 default:
681 printk(BIOS_DEBUG, "Invalid type of Error Source.");
682 break;
683 }
684 hest->error_source_count ++;
685
686 memcpy(pos, data, data_len);
687 len += data_len;
688 header->length += len;
689
690 return len;
691}
692
693/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100694void acpi_write_hest(acpi_hest_t *hest,
695 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +0800696{
697 acpi_header_t *header = &(hest->header);
698
699 memset(hest, 0, sizeof(acpi_hest_t));
700
701 memcpy(header->signature, "HEST", 4);
702 memcpy(header->oem_id, OEM_ID, 6);
703 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
704 memcpy(header->asl_compiler_id, ASLC, 4);
705 header->length += sizeof(acpi_hest_t);
706 header->revision = 1;
707
708 acpi_fill_hest(hest);
709
710 /* Calculate checksums. */
711 header->checksum = acpi_checksum((void *)hest, header->length);
712}
713
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200714#if IS_ENABLED(CONFIG_COMMON_FADT)
715void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt)
716{
717 acpi_header_t *header = &(fadt->header);
718
719 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
720 memcpy(header->signature, "FACP", 4);
721 header->length = sizeof(acpi_fadt_t);
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200722 header->revision = 4;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200723 memcpy(header->oem_id, OEM_ID, 6);
724 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
725 memcpy(header->asl_compiler_id, ASLC, 4);
726 header->asl_compiler_revision = 0;
727
728 fadt->firmware_ctrl = (unsigned long) facs;
729 fadt->dsdt = (unsigned long) dsdt;
730
731 fadt->x_firmware_ctl_l = (unsigned long)facs;
732 fadt->x_firmware_ctl_h = 0;
733 fadt->x_dsdt_l = (unsigned long)dsdt;
734 fadt->x_dsdt_h = 0;
735
736 if(IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) {
737 fadt->preferred_pm_profile = PM_MOBILE;
738 } else {
739 fadt->preferred_pm_profile = PM_DESKTOP;
740 }
741
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200742 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200743
744 header->checksum =
745 acpi_checksum((void *) fadt, header->length);
746}
747#endif
748
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200749unsigned long __attribute__ ((weak)) fw_cfg_acpi_tables(unsigned long start)
750{
751 return 0;
752}
753
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200754#define ALIGN_CURRENT current = (ALIGN(current, 16))
755unsigned long write_acpi_tables(unsigned long start)
756{
757 unsigned long current;
758 acpi_rsdp_t *rsdp;
759 acpi_rsdt_t *rsdt;
760 acpi_xsdt_t *xsdt;
761 acpi_fadt_t *fadt;
762 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100763 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200764 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200765 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200766 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200767 acpi_tcpa_t *tcpa;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200768 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100769 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200770 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200771 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100772 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200773
774 current = start;
775
776 /* Align ACPI tables to 16byte */
777 ALIGN_CURRENT;
778
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200779 fw = fw_cfg_acpi_tables(current);
780 if (fw)
781 return fw;
782
Patrick Georgic32a52c2015-06-22 21:10:34 +0200783#if CONFIG_COMPILE_IN_DSDT
784 extern char _binary_dsdt_aml_start;
785 extern char _binary_dsdt_aml_end;
786 dsdt_file = (acpi_header_t *)&_binary_dsdt_aml_start;
787 dsdt_size = (size_t)(&_binary_dsdt_aml_end - &_binary_dsdt_aml_start);
788#else
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +0200789 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200790 CONFIG_CBFS_PREFIX "/dsdt.aml",
791 CBFS_TYPE_RAW, &dsdt_size);
Patrick Georgic32a52c2015-06-22 21:10:34 +0200792#endif
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200793 if (!dsdt_file) {
794 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
795 return current;
796 }
797
798 if (dsdt_file->length > dsdt_size
799 || dsdt_file->length < sizeof (acpi_header_t)
800 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
801 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
802 return current;
803 }
804
Aaron Durbin899d13d2015-05-15 23:39:23 -0500805 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100806 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +0200807 if (slic_file
808 && (slic_file->length > slic_size
809 || slic_file->length < sizeof (acpi_header_t)
810 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100811 slic_file = 0;
812 }
813
814 if (slic_file) {
815 memcpy(oem_id, slic_file->oem_id, 6);
816 memcpy(oem_table_id, slic_file->oem_table_id, 8);
817 } else {
818 memcpy(oem_id, OEM_ID, 6);
819 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
820 }
821
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200822 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
823
824 /* We need at least an RSDP and an RSDT Table */
825 rsdp = (acpi_rsdp_t *) current;
826 current += sizeof(acpi_rsdp_t);
827 ALIGN_CURRENT;
828 rsdt = (acpi_rsdt_t *) current;
829 current += sizeof(acpi_rsdt_t);
830 ALIGN_CURRENT;
831 xsdt = (acpi_xsdt_t *) current;
832 current += sizeof(acpi_xsdt_t);
833 ALIGN_CURRENT;
834
835 /* clear all table memory */
836 memset((void *) start, 0, current - start);
837
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100838 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
839 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
840 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200841
842 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Patrick Georgi133108a2015-08-08 23:20:58 +0200843 current = (ALIGN(current, 64));
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200844 facs = (acpi_facs_t *) current;
845 current += sizeof(acpi_facs_t);
846 ALIGN_CURRENT;
847 acpi_create_facs(facs);
848
849 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
850 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200851 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200852 if (dsdt->length >= sizeof(acpi_header_t)) {
853 current += sizeof(acpi_header_t);
854
855 acpigen_set_current((char *) current);
856 for (dev = all_devices; dev; dev = dev->next)
857 if (dev->ops && dev->ops->acpi_inject_dsdt_generator) {
Alexander Couzensa90dad12015-04-12 21:49:46 +0200858 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200859 }
860 current = (unsigned long) acpigen_get_current();
861 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200862 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200863 dsdt->length - sizeof(acpi_header_t));
864 current += dsdt->length - sizeof(acpi_header_t);
865
866 /* (Re)calculate length and checksum. */
867 dsdt->length = current - (unsigned long)dsdt;
868 dsdt->checksum = 0;
869 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
870 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200871
872 ALIGN_CURRENT;
873
874 printk(BIOS_DEBUG, "ACPI: * FADT\n");
875 fadt = (acpi_fadt_t *) current;
876 current += sizeof(acpi_fadt_t);
877 ALIGN_CURRENT;
878
879 acpi_create_fadt(fadt, facs, dsdt);
880 acpi_add_table(rsdp, fadt);
881
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100882 if (slic_file) {
883 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
884 slic = (acpi_header_t *)current;
885 memcpy(slic, slic_file, slic_file->length);
886 current += slic_file->length;
887 ALIGN_CURRENT;
888 acpi_add_table(rsdp, slic);
889 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200890
891 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
892 ssdt = (acpi_header_t *)current;
893 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +0200894 if (ssdt->length > sizeof(acpi_header_t)) {
895 current += ssdt->length;
896 acpi_add_table(rsdp, ssdt);
897 ALIGN_CURRENT;
898 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200899
900 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
901 mcfg = (acpi_mcfg_t *) current;
902 acpi_create_mcfg(mcfg);
903 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
904 current += mcfg->header.length;
905 ALIGN_CURRENT;
906 acpi_add_table(rsdp, mcfg);
907 }
908
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200909 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
910 tcpa = (acpi_tcpa_t *) current;
911 acpi_create_tcpa(tcpa);
912 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
913 current += tcpa->header.length;
914 ALIGN_CURRENT;
915 acpi_add_table(rsdp, tcpa);
916 }
917
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200918 printk(BIOS_DEBUG, "ACPI: * MADT\n");
919
920 madt = (acpi_madt_t *) current;
921 acpi_create_madt(madt);
922 if (madt->header.length > sizeof(acpi_madt_t)) {
923 current+=madt->header.length;
924 acpi_add_table(rsdp,madt);
925 }
926 ALIGN_CURRENT;
927
928 printk(BIOS_DEBUG, "current = %lx\n", current);
929
930 for (dev = all_devices; dev; dev = dev->next) {
931 if (dev->ops && dev->ops->write_acpi_tables) {
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200932 current = dev->ops->write_acpi_tables(dev, current, rsdp);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200933 ALIGN_CURRENT;
934 }
935 }
936
937 printk(BIOS_INFO, "ACPI: done.\n");
938 return current;
939}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200940
Patrick Georgie1667822012-05-05 15:29:32 +0200941#if CONFIG_HAVE_ACPI_RESUME
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200942void __attribute__((weak)) mainboard_suspend_resume(void)
943{
944}
945
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500946void acpi_resume(void *wake_vec)
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000947{
Duncan Laurie11290c42012-10-03 19:07:05 -0700948#if CONFIG_HAVE_SMI_HANDLER
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500949 u32 *gnvs_address = cbmem_find(CBMEM_ID_ACPI_GNVS_PTR);
Duncan Laurie11290c42012-10-03 19:07:05 -0700950
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500951 /* Restore GNVS pointer in SMM if found */
952 if (gnvs_address && *gnvs_address) {
953 printk(BIOS_DEBUG, "Restore GNVS pointer to 0x%08x\n",
954 *gnvs_address);
955 smm_setup_structures((void *)*gnvs_address, NULL, NULL);
Stefan Reinauercb91e152012-04-03 23:28:22 +0200956 }
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500957#endif
958
959 /* Call mainboard resume handler first, if defined. */
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200960 mainboard_suspend_resume();
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500961
962 post_code(POST_OS_RESUME);
963 acpi_jump_to_wakeup(wake_vec);
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000964}
965
Kyösti Mälkki7a846e72015-01-09 23:55:09 +0200966/* This is filled with acpi_is_wakeup() call early in ramstage. */
967int acpi_slp_type = -1;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000968
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200969#if IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)
970int acpi_get_sleep_type(void)
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200971{
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200972 struct romstage_handoff *handoff;
973
974 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
975
976 if (handoff == NULL) {
977 printk(BIOS_DEBUG, "Unknown boot method, assuming normal.\n");
978 return 0;
979 } else if (handoff->s3_resume) {
980 printk(BIOS_DEBUG, "S3 Resume.\n");
981 return 3;
982 } else {
983 printk(BIOS_DEBUG, "Normal boot.\n");
984 return 0;
985 }
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200986}
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200987#endif
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200988
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300989static void acpi_handoff_wakeup(void)
990{
Kyösti Mälkki7a846e72015-01-09 23:55:09 +0200991 if (acpi_slp_type < 0)
992 acpi_slp_type = acpi_get_sleep_type();
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300993}
994
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +0200995int acpi_is_wakeup(void)
Rudolf Marek33cafe52009-04-13 18:07:02 +0000996{
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300997 acpi_handoff_wakeup();
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +0100998 /* Both resume from S2 and resume from S3 restart at CPU reset */
999 return (acpi_slp_type == 3 || acpi_slp_type == 2);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001000}
1001
Kyösti Mälkki4d9b7722014-06-19 19:45:40 +03001002int acpi_is_wakeup_s3(void)
1003{
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +03001004 acpi_handoff_wakeup();
Kyösti Mälkki4d9b7722014-06-19 19:45:40 +03001005 return (acpi_slp_type == 3);
1006}
1007
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +02001008void acpi_fail_wakeup(void)
1009{
1010 if (acpi_slp_type == 3 || acpi_slp_type == 2)
1011 acpi_slp_type = 0;
1012}
1013
Kyösti Mälkki7b14f082014-10-16 20:58:47 +03001014void acpi_prepare_resume_backup(void)
1015{
1016 if (!acpi_s3_resume_allowed())
1017 return;
1018
1019 /* Let's prepare the ACPI S3 Resume area now already, so we can rely on
1020 * it being there during reboot time. We don't need the pointer, nor
1021 * the result right now. If it fails, ACPI resume will be disabled.
1022 */
1023
1024 if (HIGH_MEMORY_SAVE)
1025 cbmem_add(CBMEM_ID_RESUME, HIGH_MEMORY_SAVE);
Kyösti Mälkki7b14f082014-10-16 20:58:47 +03001026}
1027
Rudolf Marek33cafe52009-04-13 18:07:02 +00001028static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1029{
1030 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1031 return NULL;
1032
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001033 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001034
1035 if (acpi_checksum((void *)rsdp, 20) != 0)
1036 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001037 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001038
1039 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1040 rsdp->length) != 0))
1041 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001042 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001043
1044 return rsdp;
1045}
1046
1047static acpi_rsdp_t *rsdp;
1048
1049void *acpi_get_wakeup_rsdp(void)
1050{
1051 return rsdp;
1052}
1053
1054void *acpi_find_wakeup_vector(void)
1055{
1056 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001057 acpi_rsdt_t *rsdt;
1058 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001059 acpi_fadt_t *fadt = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001060 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001061 int i;
1062
1063 rsdp = NULL;
1064
1065 if (!acpi_is_wakeup())
1066 return NULL;
1067
Uwe Hermann622824c2010-11-19 15:14:42 +00001068 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001069
Uwe Hermann622824c2010-11-19 15:14:42 +00001070 /* Find RSDP. */
1071 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
1072 if ((rsdp = valid_rsdp((acpi_rsdp_t *)p)))
Rudolf Marek33cafe52009-04-13 18:07:02 +00001073 break;
1074 }
1075
1076 if (rsdp == NULL)
1077 return NULL;
1078
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001079 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001080 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001081
Uwe Hermann622824c2010-11-19 15:14:42 +00001082 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001083 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001084
Uwe Hermann622824c2010-11-19 15:14:42 +00001085 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001086 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001087 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001088 break;
1089 fadt = NULL;
1090 }
1091
1092 if (fadt == NULL)
1093 return NULL;
1094
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001095 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001096 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001097
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001098 if (facs == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001099 printk(BIOS_DEBUG, "No FACS found, wake up from S3 not "
1100 "possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001101 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001102 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001103
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001104 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001105 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001106 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001107
Rudolf Marek33cafe52009-04-13 18:07:02 +00001108 return wake_vec;
1109}
1110
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001111#if CONFIG_SMP
Rudolf Marek33cafe52009-04-13 18:07:02 +00001112extern char *lowmem_backup;
1113extern char *lowmem_backup_ptr;
1114extern int lowmem_backup_size;
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001115#endif
Rudolf Marek33cafe52009-04-13 18:07:02 +00001116
Uwe Hermann622824c2010-11-19 15:14:42 +00001117#define WAKEUP_BASE 0x600
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001118
Stefan Reinauer71a30182015-07-30 16:28:13 -07001119void (*acpi_do_wakeup)(uintptr_t vector, u32 backup_source, u32 backup_target,
Stefan Reinauer399486e2012-12-06 13:54:29 -08001120 u32 backup_size) asmlinkage = (void *)WAKEUP_BASE;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001121
Aaron Durbina146d582013-02-08 16:56:51 -06001122extern unsigned char __wakeup;
1123extern unsigned int __wakeup_size;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001124
Rudolf Marek33cafe52009-04-13 18:07:02 +00001125void acpi_jump_to_wakeup(void *vector)
1126{
Stefan Reinauer71a30182015-07-30 16:28:13 -07001127 uintptr_t acpi_backup_memory = 0;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001128
Kyösti Mälkki2ca2afe2014-06-17 15:41:37 +03001129 if (HIGH_MEMORY_SAVE && acpi_s3_resume_allowed()) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001130 acpi_backup_memory = (uintptr_t)cbmem_find(CBMEM_ID_RESUME);
Kyösti Mälkki2ca2afe2014-06-17 15:41:37 +03001131
1132 if (!acpi_backup_memory) {
1133 printk(BIOS_WARNING, "ACPI: Backup memory missing. "
1134 "No S3 resume.\n");
1135 return;
1136 }
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001137 }
1138
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001139#if CONFIG_SMP
Martin Roth7b5f8ef2013-07-08 16:22:10 -06001140 // FIXME: This should go into the ACPI backup memory, too. No pork sausages.
Uwe Hermann622824c2010-11-19 15:14:42 +00001141 /*
1142 * Just restore the SMP trampoline and continue with wakeup on
1143 * assembly level.
1144 */
Rudolf Marek33cafe52009-04-13 18:07:02 +00001145 memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size);
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001146#endif
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001147
Uwe Hermann622824c2010-11-19 15:14:42 +00001148 /* Copy wakeup trampoline in place. */
Aaron Durbina146d582013-02-08 16:56:51 -06001149 memcpy((void *)WAKEUP_BASE, &__wakeup, __wakeup_size);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001150
Duncan Lauriecde78012011-10-19 15:32:39 -07001151 timestamp_add_now(TS_ACPI_WAKE_JUMP);
Duncan Lauriecde78012011-10-19 15:32:39 -07001152
Stefan Reinauer71a30182015-07-30 16:28:13 -07001153 acpi_do_wakeup((uintptr_t)vector, acpi_backup_memory, CONFIG_RAMBASE,
Uwe Hermann622824c2010-11-19 15:14:42 +00001154 HIGH_MEMORY_SAVE);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001155}
1156#endif
Duncan Laurie11290c42012-10-03 19:07:05 -07001157
1158void acpi_save_gnvs(u32 gnvs_address)
1159{
Duncan Laurie9c07c8f2013-03-22 11:08:39 -07001160 u32 *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS_PTR, sizeof(*gnvs));
Duncan Laurie11290c42012-10-03 19:07:05 -07001161 if (gnvs)
1162 *gnvs = gnvs_address;
1163}